@confect/js 10.0.0-next.21 → 10.0.0-next.23
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/CHANGELOG.md +110 -41
- package/dist/HttpClient.d.ts +3 -1
- package/dist/HttpClient.d.ts.map +1 -1
- package/dist/HttpClient.js +3 -1
- package/dist/HttpClient.js.map +1 -1
- package/dist/WebSocketClient.d.ts +5 -1
- package/dist/WebSocketClient.d.ts.map +1 -1
- package/dist/WebSocketClient.js +5 -1
- package/dist/WebSocketClient.js.map +1 -1
- package/dist/internal/HttpClient.d.ts.map +1 -1
- package/dist/internal/HttpClient.js +6 -3
- package/dist/internal/HttpClient.js.map +1 -1
- package/dist/internal/WebSocketClient.d.ts.map +1 -1
- package/dist/internal/WebSocketClient.js +6 -3
- package/dist/internal/WebSocketClient.js.map +1 -1
- package/package.json +9 -8
- package/src/HttpClient.ts +3 -1
- package/src/WebSocketClient.ts +5 -1
- package/src/internal/HttpClient.ts +36 -18
- package/src/internal/WebSocketClient.ts +36 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# @confect/js
|
|
2
2
|
|
|
3
|
+
## 10.0.0-next.23
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 10.0.0-next.22
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 9f4e2c0: Require `effect@^4.0.0-rc.113` across `@confect/*` and raise `@confect/server`'s optional `@effect/platform-node` peer to the same range. Upgrade Effect alongside Confect; existing Confect call sites are unchanged.
|
|
12
|
+
|
|
13
|
+
Effect's own APIs include breaking renames: use `Config.String` instead of `Config.string`, and `LanguageModel.LanguageModel` instead of `LanguageModel.Service` when annotating the result of `AiGatewayLanguageModel.make`. See the [Effect RC 113 release notes](https://github.com/Effect-TS/effect/releases/tag/effect%404.0.0-rc.113) for the complete migration guidance.
|
|
14
|
+
|
|
15
|
+
- 90c80e9: Require `effect@^4.0.0-rc.115` across `@confect/*` and `@effect/platform-node@^4.0.0-rc.115` when using `@confect/server`'s optional Node integration. Upgrade these dependencies alongside Confect; existing Confect call sites are unchanged.
|
|
16
|
+
- 6cc5834: Add experimental stream querying with reactive pagination, configurable middleware policies, and broader tracing.
|
|
17
|
+
|
|
18
|
+
### Stream queries and pagination
|
|
19
|
+
|
|
20
|
+
Create composable Effect streams with `reader.table(...).stream(index, range?, order?)` and `QueryStream` from `@confect/server`. Merge, filter, map, join, deduplicate, narrow, and reverse queries without losing cursor pagination. Order keys and directions are checked by the type system. Joins support left-join placeholders through `onEmpty`, and effectful filters and maps support ordered concurrency. Reversing a distinct stream preserves its chosen representatives.
|
|
21
|
+
|
|
22
|
+
`QueryStream.paginate` resumes from indexed cursor bounds and supports pinned page ranges, automatic split recommendations, and `maximumRowsRead`/`maximumBytesRead` budgets that count underlying query-stream reads, including filtered documents. Byte counts are estimates. If a budget prevents safe progress or splitting, pagination fails with `ReadBudgetExceededError`; increase the budget or reduce the query's read requirements.
|
|
23
|
+
|
|
24
|
+
Use React's new `useStreamPaginatedQuery` for these queries:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { useStreamPaginatedQuery } from "@confect/react";
|
|
28
|
+
|
|
29
|
+
const { results, status, loadMore } = useStreamPaginatedQuery(
|
|
30
|
+
refs.public.notes.feed,
|
|
31
|
+
{},
|
|
32
|
+
{
|
|
33
|
+
initialNumItems: 10,
|
|
34
|
+
maximumRowsRead: 1000,
|
|
35
|
+
maximumBytesRead: 512 * 1024,
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The hook pins loaded pages to fixed ranges, splits oversized or budget-limited pages, and restarts pagination on invalid cursors. Foldkit's `PaginatedQuery` also supports stream queries and preserves page ranges when navigating back and forward, avoiding skipped or repeated documents as data changes.
|
|
41
|
+
|
|
42
|
+
Stream cursors expose their order-key values. Do not paginate publicly over sensitive indexed fields unless they are pinned with `eq`. All `QueryStream` APIs are experimental.
|
|
43
|
+
|
|
44
|
+
### Middleware options
|
|
45
|
+
|
|
46
|
+
Declare a lazy `options` schema on `MiddlewareSpec.MiddlewareSpec`, then pass typed values with `.middleware(Policy, options)` on functions or groups. Options are validated without coercion during codegen and server registration; keep schemas and values client-safe because generated refs carry them.
|
|
47
|
+
|
|
48
|
+
The same policy can be attached repeatedly with non-equivalent options. Every attachment runs, with group policies before function policies. Equivalent options and duplicate policies without options are rejected. Register implementations against the same spec used for attachments.
|
|
49
|
+
|
|
50
|
+
### Breaking changes
|
|
51
|
+
|
|
52
|
+
Middleware callbacks passed to `MiddlewareImpl.make` or `MiddlewareImpl.makeByFunctionType` receive invocation metadata under `invocation`. To migrate, nest destructuring of `name`, `functionType`, `functionVisibility`, and decoded `args`:
|
|
53
|
+
|
|
54
|
+
**Before:**
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
(effect, { name, args }) => effect;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**After:**
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
(effect, { invocation: { name, args } }) => effect;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Middleware with an options schema also receives `options` alongside `invocation`; middleware without one keeps its single-argument attachment API and receives only `{ invocation }`.
|
|
67
|
+
|
|
68
|
+
### Fixes and tracing
|
|
69
|
+
- Preserve `ConvexError.data` when a handler throws a `ConvexError` inside an Effect instead of returning it as a typed failure.
|
|
70
|
+
- Add named tracing spans for JavaScript client calls, server function execution, database writes and pagination, `QueryStream.unique`/`QueryStream.paginate`, and `confect codegen`/`confect dev` code-generation passes.
|
|
71
|
+
|
|
3
72
|
## 10.0.0-next.21
|
|
4
73
|
|
|
5
74
|
### Major Changes
|
|
@@ -9,7 +78,7 @@
|
|
|
9
78
|
### Breaking Changes
|
|
10
79
|
- `engines.node` is now `>=24` on every `@confect/*` package, raised from `>=22`.
|
|
11
80
|
|
|
12
|
-
Node 22 has entered maintenance, so Confect now targets Node 24, the active LTS line. To migrate, move the Node version your project builds and runs on to 24 or later
|
|
81
|
+
Node 22 has entered maintenance, so Confect now targets Node 24, the active LTS line. To migrate, move the Node version your project builds and runs on to 24 or later—on Node 22, installing `@confect/*` now fails your package manager's engine check. No API changes accompany the raise: code already running on Node 24 needs no edits.
|
|
13
82
|
|
|
14
83
|
## 10.0.0-next.20
|
|
15
84
|
|
|
@@ -17,7 +86,7 @@
|
|
|
17
86
|
|
|
18
87
|
### Minor Changes
|
|
19
88
|
|
|
20
|
-
- c1087eb: Add `@confect/foldkit
|
|
89
|
+
- c1087eb: Add `@confect/foldkit`—client-side bindings for [Foldkit](https://foldkit.dev) apps. The package maps Confect's client surface onto Foldkit's integration seams: `Client.layer` provides the scoped WebSocket client and pagination-session allocator through an application's `resources`, `Subscription.reactiveQuery` builds a subscription entry that opens, re-opens, and closes a reactive query as `Option`-wrapped args derived from the Model change, and `Command.query`/`Command.mutation`/`Command.action` build Command definitions whose args are the ref's args and whose Messages are declared with the same `messages` field Foldkit's own `Command.define` takes. Every failure is folded into a Message via the required `onError` handler, so Command and Subscription error channels stay `never` as Foldkit requires.
|
|
21
90
|
|
|
22
91
|
```ts
|
|
23
92
|
import * as Confect from "@confect/foldkit";
|
|
@@ -47,7 +116,7 @@
|
|
|
47
116
|
}));
|
|
48
117
|
```
|
|
49
118
|
|
|
50
|
-
The Command factories accept Foldkit's `interrupt` option
|
|
119
|
+
The Command factories accept Foldkit's `interrupt` option—`true` keys invocations by the Command name, `{ keyFields, toKey }` by a part derived from the ref's args—and the returned definition gains the `Interrupt` constructor for stopping in-flight invocations. Factory-built definitions instantiate Foldkit's own definition interfaces, so they are accepted wherever Foldkit accepts a Command definition—including Story/Scene `Command.resolve` and `expectExact` matchers. `Command.queryEffect`, `Command.mutationEffect`, and `Command.actionEffect` return execute bodies for hand-written `Command.define` calls (custom args schemas, multi-call Commands), and `Subscription.reactiveQueryStream` is the `dependenciesToStream` escape hatch for hand-written subscription entries.
|
|
51
120
|
|
|
52
121
|
`PaginatedQuery` navigates a paginated query one page at a time over Convex's cursor pagination. `PaginatedQuery.make(ref)` returns the Model and settlement schemas. Its states use Foldkit `AsyncData`'s vocabulary and semantics: `Idle`, `Loading`, `Refreshing`, `Success`, `Failure`, and `Stale`. Failed settlements preserve the complete error contract: declared function and middleware errors are wrapped as `FunctionError`, Convex's invalid-cursor pseudo-error is normalized to the new `@confect/core/PaginationError.InvalidCursor`, and `WebSocketClientError` and `SchemaError` are carried directly. `settle` accepts a request-bound `Result`, turns a failed refresh into `Stale`, automatically resets an invalid cursor, and ignores successes or failures from superseded requests. All machine operations (`init`, `reinitialize`, `reset`, `close`, `next`, `prev`, and `first`) remain pure.
|
|
53
122
|
|
|
@@ -94,14 +163,14 @@
|
|
|
94
163
|
Breaking changes for users:
|
|
95
164
|
|
|
96
165
|
- **Schemas** follow Effect v4's Schema API: `Schema.Union([a, b])` (array form), `Schema.Literals([...])` for literal unions, `Schema.optionalKey` in place of `optionalWith({ exact: true })`, and checks like `Schema.String.check(Schema.isMaxLength(...))` in place of piped filters.
|
|
97
|
-
- **Option-returning functions** must use a codec with a serializable encoded form, such as `Schema.OptionFromNullOr(...)
|
|
98
|
-
- **Table schemas** may now be transformations (`Schema.decodeTo` chains, `Schema.encodeKeys`), branded structs, suspended schemas, or unions of these
|
|
166
|
+
- **Option-returning functions** must use a codec with a serializable encoded form, such as `Schema.OptionFromNullOr(...)`—v4's `Schema.Option` encodes to an `Option` instance, which is not a Convex value.
|
|
167
|
+
- **Table schemas** may now be transformations (`Schema.decodeTo` chains, `Schema.encodeKeys`), branded structs, suspended schemas, or unions of these—Convex's system fields are carried through the whole encoding chain. Schemas that do not resolve to an object shape at every step (such as `Schema.Class`) are rejected with a descriptive error when the table is defined.
|
|
99
168
|
- **Clients**: decode failures surface as `SchemaError` rather than `ParseError` in `@confect/js` and `@confect/react`, and `@confect/react`'s `useMutation`/`useAction` handles with an `error` schema now resolve to `Result` (v4's replacement for `Either`).
|
|
100
|
-
- **HTTP** is now mounted through the renamed `HttpRouter` module (formerly `HttpApi`). `HttpRouter.make(routes)` takes a single route-registering `Layer` composed from Effect's own `effect/unstable/http` and `effect/unstable/httpapi` modules
|
|
169
|
+
- **HTTP** is now mounted through the renamed `HttpRouter` module (formerly `HttpApi`). `HttpRouter.make(routes)` takes a single route-registering `Layer` composed from Effect's own `effect/unstable/http` and `effect/unstable/httpapi` modules—`HttpApiBuilder.layer(api)` (with group handler layers supplied via `Layer.provide`; a missing group is a compile-time error), `HttpApiScalar.layer` for docs, `HttpRouter.add` for plain routes, and `HttpRouter.middleware(fn, { global: true })` for middleware, merged with `Layer.mergeAll`. The per-path-prefix record and its `api`/`apiLive`/`middleware`/`scalar` options are gone; Confect registers one catch-all Convex HTTP action at `/`, and plain Convex routes added to the returned router still take precedence. Handlers, middleware, and route-layer construction all run with Confect's Convex-aware `ConfigProvider` in context.
|
|
101
170
|
- **Node actions** use `effect/unstable/process` (`ChildProcessSpawner`) and `@effect/platform-node`'s `NodeServices` in place of `@effect/platform` `Command`/`NodeContext`.
|
|
102
171
|
- **Configuration**: Confect's Convex-aware `ConfigProvider` treats empty-string environment variables as missing values (matching Effect v4's built-in providers), so `Config.withDefault` and `Config.option` recover from them.
|
|
103
172
|
- **CLI**: a malformed `convex.json` now fails codegen with a descriptive error instead of being silently ignored.
|
|
104
|
-
- Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads
|
|
173
|
+
- Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads—`Clock.currentTimeMillis`/`currentTimeNanos` or a raw `Date.now()` call—opt the query out and evict as they honestly should.
|
|
105
174
|
|
|
106
175
|
### Patch Changes
|
|
107
176
|
|
|
@@ -116,9 +185,9 @@
|
|
|
116
185
|
- Raise the required `effect` peer version to `^4.0.0-beta.102` (from `^4.0.0-beta.101`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
117
186
|
- Raise the required `effect` peer version to `^4.0.0-beta.105` (from `^4.0.0-beta.102`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
118
187
|
|
|
119
|
-
`beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time
|
|
188
|
+
`beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time—`Effect.timed`, duration metrics, `Sink.withDuration`—read the monotonic accessors instead of the wall clock, and continue to report a zero duration inside queries and mutations, where Confect pins the unsafe accessors to constants to keep Convex's query cache from evicting on every logged span.
|
|
120
189
|
|
|
121
|
-
`beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load
|
|
190
|
+
`beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load—registration and schema-to-validator compilation—and relies on that scheduling instead. Neither the "Can't use `setTimeout` in queries and mutations" crash nor any other consumer-visible behavior changes, but this is the area to look at if module loading starts misbehaving.
|
|
122
191
|
|
|
123
192
|
`beta.104` renames Effect's schema error constructors to match their `Data` counterparts, which affects any error schema you declare for a Confect function:
|
|
124
193
|
|
|
@@ -140,7 +209,7 @@
|
|
|
140
209
|
) {}
|
|
141
210
|
```
|
|
142
211
|
|
|
143
|
-
`Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types
|
|
212
|
+
`Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types—`DocumentDecodeError`, `BlobNotFoundError`, and the rest—are unchanged in name, shape, and message.
|
|
144
213
|
|
|
145
214
|
`beta.105` restructures how schema validation failures are reported, but not on the path Confect puts you on: decode and encode failures still surface as `Schema.SchemaError` with a formatted `message`, so error text from `@confect/js`, `@confect/react`, and document decoding is unchanged.
|
|
146
215
|
|
|
@@ -168,13 +237,13 @@
|
|
|
168
237
|
|
|
169
238
|
- Raise the required `effect` peer version to `^4.0.0-beta.107` (from `^4.0.0-beta.106`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
170
239
|
|
|
171
|
-
`beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed
|
|
240
|
+
`beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed—upgrade `effect` alongside `@confect/*` and everything you have written keeps compiling. Your table, argument, and returns schemas still produce the same Convex validators.
|
|
172
241
|
|
|
173
|
-
Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short
|
|
242
|
+
Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short—because a parser limit was exceeded or the request body ended early—now fails instead of hanging. Separately, `Duration` values that are equal now hash equally, so a `Duration` used as a `HashMap` key or a `HashSet` member is found regardless of which constructor built it.
|
|
174
243
|
|
|
175
244
|
- Raise the required `effect` peer version to `^4.0.0-beta.98` (from `^4.0.0-beta.97`).
|
|
176
245
|
|
|
177
|
-
`effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError
|
|
246
|
+
`effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError`/`Schema.isSchemaError` usage is unaffected—this is purely a declaration-emit detail that consumers relying on generated types may notice.
|
|
178
247
|
|
|
179
248
|
- Raise the required `effect` peer version to `^4.0.0-beta.99` (from `^4.0.0-beta.98`).
|
|
180
249
|
|
|
@@ -198,7 +267,7 @@
|
|
|
198
267
|
|
|
199
268
|
Also worth knowing if you serve an `HttpApi`: a query parameter declared as an array now decodes correctly when a request supplies exactly one value for it.
|
|
200
269
|
|
|
201
|
-
One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change
|
|
270
|
+
One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change—but it is the thing to look at if a long-running query or mutation regresses on this release.
|
|
202
271
|
|
|
203
272
|
- Raise the required `effect` peer version to `^4.0.0-rc.109` (from `^4.0.0-rc.108`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
204
273
|
|
|
@@ -209,10 +278,10 @@
|
|
|
209
278
|
No Confect API changed, and no call-site edits are needed. `rc.110` is a patch release of Effect with nothing removed or renamed, so upgrading is a matter of installing it alongside `@confect/*`.
|
|
210
279
|
|
|
211
280
|
- 3f0255c: Build and test against `convex` 1.44.0. The published `convex` peer ranges are unchanged, so no consumer action is required.
|
|
212
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4
|
|
213
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5
|
|
214
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0
|
|
215
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0
|
|
281
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4—see those versions' changelog entries.
|
|
282
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5—see that version's changelog entries.
|
|
283
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0—see that version's changelog entries.
|
|
284
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0—see that version's changelog entries.
|
|
216
285
|
|
|
217
286
|
The `@effect/platform` and `@effect/cli` peer and dependency floors that 9.4.0 raises do not apply here: this line runs on Effect v4, where those packages are not dependencies at all.
|
|
218
287
|
|
|
@@ -248,7 +317,7 @@
|
|
|
248
317
|
|
|
249
318
|
Also worth knowing if you serve an `HttpApi`: a query parameter declared as an array now decodes correctly when a request supplies exactly one value for it.
|
|
250
319
|
|
|
251
|
-
One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change
|
|
320
|
+
One internal change rides along. Queries and mutations that run long enough to trigger a cooperative fiber yield now take that yield from Effect's own scheduler, which `rc.108` made usable inside Convex's isolate for the first time. The underlying microtask primitive is identical, so behavior should not change—but it is the thing to look at if a long-running query or mutation regresses on this release.
|
|
252
321
|
|
|
253
322
|
- a4054ab: The published type declarations are now emitted by TypeScript 7 rather than TypeScript 6. No API changed, but the declaration text differs in places, so an inferred type printed in your editor or in a type error may read slightly differently than before.
|
|
254
323
|
|
|
@@ -258,9 +327,9 @@
|
|
|
258
327
|
|
|
259
328
|
- 5a73763: Raise the required `effect` peer version to `^4.0.0-beta.107` (from `^4.0.0-beta.106`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
260
329
|
|
|
261
|
-
`beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed
|
|
330
|
+
`beta.107` is a patch-only Effect release, so no Confect API changes and no call-site edits are needed—upgrade `effect` alongside `@confect/*` and everything you have written keeps compiling. Your table, argument, and returns schemas still produce the same Convex validators.
|
|
262
331
|
|
|
263
|
-
Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short
|
|
332
|
+
Two Effect fixes are worth knowing about if they touch your code. HTTP actions written with `HttpRouter` now collect uploaded file contents far faster on large multipart bodies, and a file part whose stream is cut short—because a parser limit was exceeded or the request body ended early—now fails instead of hanging. Separately, `Duration` values that are equal now hash equally, so a `Duration` used as a `HashMap` key or a `HashSet` member is found regardless of which constructor built it.
|
|
264
333
|
|
|
265
334
|
## 10.0.0-next.12
|
|
266
335
|
|
|
@@ -294,9 +363,9 @@
|
|
|
294
363
|
|
|
295
364
|
- f782cdd: Raise the required `effect` peer version to `^4.0.0-beta.105` (from `^4.0.0-beta.102`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
296
365
|
|
|
297
|
-
`beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time
|
|
366
|
+
`beta.103` separates wall-clock time from monotonic elapsed time: `Clock.Clock` now also requires `monotonicTimeNanos` and `monotonicTimeNanosUnsafe`, so a custom `Clock` provided to a Confect function has to supply both. Effects that measure elapsed time—`Effect.timed`, duration metrics, `Sink.withDuration`—read the monotonic accessors instead of the wall clock, and continue to report a zero duration inside queries and mutations, where Confect pins the unsafe accessors to constants to keep Convex's query cache from evicting on every logged span.
|
|
298
367
|
|
|
299
|
-
`beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load
|
|
368
|
+
`beta.103` also moves synchronous Effect runs off `setImmediate`/`setTimeout` and onto the microtask queue, which Convex's query and mutation isolate permits. Confect no longer suppresses cooperative fiber yielding for the synchronous work it performs while your modules load—registration and schema-to-validator compilation—and relies on that scheduling instead. Neither the "Can't use `setTimeout` in queries and mutations" crash nor any other consumer-visible behavior changes, but this is the area to look at if module loading starts misbehaving.
|
|
300
369
|
|
|
301
370
|
`beta.104` renames Effect's schema error constructors to match their `Data` counterparts, which affects any error schema you declare for a Confect function:
|
|
302
371
|
|
|
@@ -318,11 +387,11 @@
|
|
|
318
387
|
) {}
|
|
319
388
|
```
|
|
320
389
|
|
|
321
|
-
`Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types
|
|
390
|
+
`Schema.ErrorClass` is likewise now `Schema.Error`; the schema for JavaScript `Error` instances that previously went by `Schema.Error` is now `Schema.ErrorInstance`, and `Schema.ErrorReviver` is now `Schema.ErrorInstanceReviver`. Confect's own error types—`DocumentDecodeError`, `BlobNotFoundError`, and the rest—are unchanged in name, shape, and message.
|
|
322
391
|
|
|
323
392
|
`beta.105` restructures how schema validation failures are reported, but not on the path Confect puts you on: decode and encode failures still surface as `Schema.SchemaError` with a formatted `message`, so error text from `@confect/js`, `@confect/react`, and document decoding is unchanged.
|
|
324
393
|
|
|
325
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0
|
|
394
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.4.0—see that version's changelog entries.
|
|
326
395
|
|
|
327
396
|
The `@effect/platform` and `@effect/cli` peer and dependency floors that 9.4.0 raises do not apply here: this line runs on Effect v4, where those packages are not dependencies at all.
|
|
328
397
|
|
|
@@ -330,14 +399,14 @@
|
|
|
330
399
|
|
|
331
400
|
### Patch Changes
|
|
332
401
|
|
|
333
|
-
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0
|
|
402
|
+
- Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.3.0—see that version's changelog entries.
|
|
334
403
|
|
|
335
404
|
## 10.0.0-next.9
|
|
336
405
|
|
|
337
406
|
### Patch Changes
|
|
338
407
|
|
|
339
408
|
- 0dcc0fb: Raise the required `effect` peer version to `^4.0.0-beta.102` (from `^4.0.0-beta.101`), and `@confect/server`'s optional `@effect/platform-node` peer version likewise.
|
|
340
|
-
- 25e8d19: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5
|
|
409
|
+
- 25e8d19: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.5—see that version's changelog entries.
|
|
341
410
|
|
|
342
411
|
## 10.0.0-next.8
|
|
343
412
|
|
|
@@ -371,7 +440,7 @@
|
|
|
371
440
|
|
|
372
441
|
This is a peer-range-only change with no consumer-visible API consequences. The `beta.99` release only touches `Graph`, CLI (`Command`/`CliConfig`/wizard mode), `Tool` cloning, Redis script eval, and multipart parser internals that Confect doesn't use.
|
|
373
442
|
|
|
374
|
-
- 2aa7541: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4
|
|
443
|
+
- 2aa7541: Sync with `main`: this prerelease line now includes all changes released in `@confect/*` 9.2.2–9.2.4—see those versions' changelog entries.
|
|
375
444
|
|
|
376
445
|
## 10.0.0-next.1
|
|
377
446
|
|
|
@@ -379,7 +448,7 @@
|
|
|
379
448
|
|
|
380
449
|
- 4d98ea8: Raise the required `effect` peer version to `^4.0.0-beta.98` (from `^4.0.0-beta.97`).
|
|
381
450
|
|
|
382
|
-
`effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError
|
|
451
|
+
`effect`'s `SchemaError` is now exposed as its own public module (`effect/SchemaError`), which changes the import path TypeScript picks when Confect emits `.d.ts` declarations that reference `Schema.SchemaError` (for example in generated `services.d.ts`). Existing `Schema.SchemaError`/`Schema.isSchemaError` usage is unaffected—this is purely a declaration-emit detail that consumers relying on generated types may notice.
|
|
383
452
|
|
|
384
453
|
- Updated dependencies [4d98ea8]
|
|
385
454
|
- @confect/core@10.0.0-next.1
|
|
@@ -392,14 +461,14 @@
|
|
|
392
461
|
|
|
393
462
|
Breaking changes for users:
|
|
394
463
|
- **Schemas** follow Effect v4's Schema API: `Schema.Union([a, b])` (array form), `Schema.Literals([...])` for literal unions, `Schema.optionalKey` in place of `optionalWith({ exact: true })`, `Schema.TaggedErrorClass` in place of `Schema.TaggedError`, and checks like `Schema.String.check(Schema.isMaxLength(...))` in place of piped filters.
|
|
395
|
-
- **Option-returning functions** must use a codec with a serializable encoded form, such as `Schema.OptionFromNullOr(...)
|
|
396
|
-
- **Table schemas** may now be transformations (`Schema.decodeTo` chains, `Schema.encodeKeys`), branded structs, suspended schemas, or unions of these
|
|
464
|
+
- **Option-returning functions** must use a codec with a serializable encoded form, such as `Schema.OptionFromNullOr(...)`—v4's `Schema.Option` encodes to an `Option` instance, which is not a Convex value.
|
|
465
|
+
- **Table schemas** may now be transformations (`Schema.decodeTo` chains, `Schema.encodeKeys`), branded structs, suspended schemas, or unions of these—Convex's system fields are carried through the whole encoding chain. Schemas that do not resolve to an object shape at every step (such as `Schema.Class`) are rejected with a descriptive error when the table is defined.
|
|
397
466
|
- **Clients**: decode failures surface as `SchemaError` rather than `ParseError` in `@confect/js` and `@confect/react`, and `@confect/react`'s `useMutation`/`useAction` handles with an `error` schema now resolve to `Result` (v4's replacement for `Either`).
|
|
398
|
-
- **HTTP** is now mounted through the renamed `HttpRouter` module (formerly `HttpApi`). `HttpRouter.make(routes)` takes a single route-registering `Layer` composed from Effect's own `effect/unstable/http` and `effect/unstable/httpapi` modules
|
|
467
|
+
- **HTTP** is now mounted through the renamed `HttpRouter` module (formerly `HttpApi`). `HttpRouter.make(routes)` takes a single route-registering `Layer` composed from Effect's own `effect/unstable/http` and `effect/unstable/httpapi` modules—`HttpApiBuilder.layer(api)` (with group handler layers supplied via `Layer.provide`; a missing group is a compile-time error), `HttpApiScalar.layer` for docs, `HttpRouter.add` for plain routes, and `HttpRouter.middleware(fn, { global: true })` for middleware, merged with `Layer.mergeAll`. The per-path-prefix record and its `api`/`apiLive`/`middleware`/`scalar` options are gone; Confect registers one catch-all Convex HTTP action at `/`, and plain Convex routes added to the returned router still take precedence. Handlers, middleware, and route-layer construction all run with Confect's Convex-aware `ConfigProvider` in context.
|
|
399
468
|
- **Node actions** use `effect/unstable/process` (`ChildProcessSpawner`) and `@effect/platform-node`'s `NodeServices` in place of `@effect/platform` `Command`/`NodeContext`.
|
|
400
469
|
- **Configuration**: Confect's Convex-aware `ConfigProvider` treats empty-string environment variables as missing values (matching Effect v4's built-in providers), so `Config.withDefault` and `Config.option` recover from them.
|
|
401
470
|
- **CLI**: a malformed `convex.json` now fails codegen with a descriptive error instead of being silently ignored.
|
|
402
|
-
- Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads
|
|
471
|
+
- Confect queries no longer stub the global `Date.now`. Queries run with a `Clock` whose unsafe accessors return constants, so Effect-internal reads (log timestamps, spans) never evict a query from Convex's cache; explicit time reads—`Clock.currentTimeMillis`/`currentTimeNanos` or a raw `Date.now()` call—opt the query out and evict as they honestly should.
|
|
403
472
|
|
|
404
473
|
### Patch Changes
|
|
405
474
|
|
|
@@ -496,7 +565,7 @@
|
|
|
496
565
|
|
|
497
566
|
- 445ea9b: Loosen and align dependency ranges across all packages:
|
|
498
567
|
- The `convex` peer dependency is now `^1.32.0` in every package (previously pinned exactly to `1.39.1`, or `^1.30.0` in `@confect/react`). The range is validated against convex 1.32.0 through 1.40.0.
|
|
499
|
-
- `@confect/server`'s `@effect/platform-node` peer dependency is now optional
|
|
568
|
+
- `@confect/server`'s `@effect/platform-node` peer dependency is now optional—it is only needed when using the `@confect/server/node` entrypoint.
|
|
500
569
|
- `@confect/cli` now uses caret ranges for its `@effect/platform` and `@effect/platform-node` dependencies so they can deduplicate with the versions resolved for `@confect/server`, and no longer declares an unused direct dependency on `@effect/platform-node-shared`.
|
|
501
570
|
- `@confect/test` now accepts any `convex-test` release in `>=0.0.50 <0.1.0` instead of exactly 0.0.50.
|
|
502
571
|
|
|
@@ -515,8 +584,8 @@
|
|
|
515
584
|
|
|
516
585
|
Your API is now authored as colocated `*.spec.ts`/`*.impl.ts` pairs, one pair per group, and **the file's path within `confect/` is the group's name** (its stem for top-level groups, the dot-joined directory path for nested groups). `GroupSpec.make()` and `GroupSpec.makeNode()` no longer take a name argument.
|
|
517
586
|
- Each `*.spec.ts` `export default`s its `GroupSpec` (named co-exports like error classes are still allowed).
|
|
518
|
-
- Each `*.impl.ts` default-imports its sibling spec, passes it to `FunctionImpl.make
|
|
519
|
-
- The root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, and `confect/nodeImpl.ts` files are gone, along with `Impl.make` and `Impl.finalize`. `confect codegen` deletes any of these (and the stale aggregate `_generated/registeredFunctions.ts
|
|
587
|
+
- Each `*.impl.ts` default-imports its sibling spec, passes it to `FunctionImpl.make`/`GroupImpl.make`, and ends the layer pipeline with `GroupImpl.finalize`—a compile-time completeness check that only typechecks once every function the spec declares has a `FunctionImpl` provided.
|
|
588
|
+
- The root `confect/spec.ts`, `confect/impl.ts`, `confect/nodeSpec.ts`, and `confect/nodeImpl.ts` files are gone, along with `Impl.make` and `Impl.finalize`. `confect codegen` deletes any of these (and the stale aggregate `_generated/registeredFunctions.ts`/`_generated/nodeRegisteredFunctions.ts`) on upgrade.
|
|
520
589
|
|
|
521
590
|
### Tables are the source of truth, named by their filename
|
|
522
591
|
|
|
@@ -547,7 +616,7 @@
|
|
|
547
616
|
|
|
548
617
|
### Specs and impls: lazy schemas, and impls take the `DatabaseSchema`
|
|
549
618
|
|
|
550
|
-
`FunctionSpec.*` constructors now take `args`, `returns`, and the optional `error` as `() => Schema` thunks, so importing a spec builds no schemas until a function is invoked. `FunctionImpl.make` and `GroupImpl.make` take the runtime `DatabaseSchema` (the default export of `_generated/schema`) as their first argument instead of the whole `Api`—which keeps the project-wide spec graph out of a function's cold-start module graph. The `Api` module (`Api.make`, the `Api` type) and the generated `_generated/api.ts
|
|
619
|
+
`FunctionSpec.*` constructors now take `args`, `returns`, and the optional `error` as `() => Schema` thunks, so importing a spec builds no schemas until a function is invoked. `FunctionImpl.make` and `GroupImpl.make` take the runtime `DatabaseSchema` (the default export of `_generated/schema`) as their first argument instead of the whole `Api`—which keeps the project-wide spec graph out of a function's cold-start module graph. The `Api` module (`Api.make`, the `Api` type) and the generated `_generated/api.ts`/`_generated/nodeApi.ts` files are removed.
|
|
551
620
|
|
|
552
621
|
**Before:**
|
|
553
622
|
|
|
@@ -595,7 +664,7 @@
|
|
|
595
664
|
|
|
596
665
|
A group's runtime is now declared solely by its spec—`GroupSpec.makeNode()` for a Node action group, `GroupSpec.make()` otherwise—mirroring vanilla Convex's per-file `"use node"` directive. The separate `node` namespace is gone: Node specs/impls are ordinary colocated pairs that can live anywhere in `confect/`, and codegen emits the `"use node"` directive based on the spec.
|
|
597
666
|
- A Node group at `confect/email.spec.ts` is now reached at `refs.public.email.send` instead of `refs.public.node.email.send`.
|
|
598
|
-
- `@confect/core` removes `Spec.makeNode`, `Spec.merge`, and `Spec.isConvexSpec
|
|
667
|
+
- `@confect/core` removes `Spec.makeNode`, `Spec.merge`, and `Spec.isConvexSpec`/`Spec.isNodeSpec`; `Spec.make()` is a single mixed-runtime container and `Refs.make(spec)` takes one argument. `GroupSpec.makeNode()`, `FunctionSpec.publicNodeAction()`/`internalNodeAction()` are unchanged.
|
|
599
668
|
|
|
600
669
|
### Less work at cold start
|
|
601
670
|
|
|
@@ -612,7 +681,7 @@
|
|
|
612
681
|
### Migration
|
|
613
682
|
1. **Tables.** Delete `confect/schema.ts`. Rename each table file to a valid JS identifier (e.g. `confect/tables/notes.ts`); the basename becomes the table name. Drop the name argument from `Table.make`, wrap the field struct in `() =>`, and replace `GenericId.GenericId("x")` with `Id("x")` from `_generated/id`. If you read `table.name` off a bound table, rename it to `table.tableName`.
|
|
614
683
|
2. **Specs.** Split each group into a colocated `*.spec.ts` that `export default`s `GroupSpec.make()` (no name). Wrap every `args`/`returns`/`error` in `() =>`. Import a table's `Doc`/`Fields` from its wrapper, `import notes from "./_generated/tables/notes"`.
|
|
615
|
-
3. **Impls.** In each `*.impl.ts`, default-import the sibling spec, import `databaseSchema` from `_generated/schema`, pass it to `FunctionImpl.make
|
|
684
|
+
3. **Impls.** In each `*.impl.ts`, default-import the sibling spec, import `databaseSchema` from `_generated/schema`, pass it to `FunctionImpl.make`/`GroupImpl.make` in place of `api`, end the pipeline with `GroupImpl.finalize`, and `export default` it. Delete the root `confect/spec.ts`, `impl.ts`, `nodeSpec.ts`, and `nodeImpl.ts` (codegen will also remove them).
|
|
616
685
|
4. **Node groups.** Move any `confect/node/<path>` files anywhere you like under `confect/`; the `node/` directory no longer has special meaning. Drop the `node` segment from call sites (`refs.public.node.<group>` → `refs.public.<group>`) and replace `Refs.make(spec, nodeSpec)` with `Refs.make(spec)`.
|
|
617
686
|
5. **Tests.** If you use `@confect/test`, import `confectSchema` from `_generated/schema`, import the generated `convexSchema` from `_generated/convexSchema`, and pass `convexSchema` as the new second argument to `TestConfect.layer`.
|
|
618
687
|
6. **Optional.** Adopt submodule Effect imports (`import * as Schema from "effect/Schema"`) in your own `confect/` files for the full cold-start savings.
|
|
@@ -656,11 +725,11 @@
|
|
|
656
725
|
|
|
657
726
|
### Why
|
|
658
727
|
|
|
659
|
-
A barrel import of a namespace re-export defeats esbuild's tree-shaking: accessing `Schema.X` from `import { Schema } from "effect"` retains the _entire_ `Schema` namespace, because the bundler can't prune property access on the barrel's `export * as Schema`. So every Convex function's cold-start bundle was pulling all of `effect/Schema` and `effect/Stream
|
|
728
|
+
A barrel import of a namespace re-export defeats esbuild's tree-shaking: accessing `Schema.X` from `import { Schema } from "effect"` retains the _entire_ `Schema` namespace, because the bundler can't prune property access on the barrel's `export * as Schema`. So every Convex function's cold-start bundle was pulling all of `effect/Schema` and `effect/Stream`—and, transitively through Schema's `Arbitrary`, `fast-check`—whether the function used them or not.
|
|
660
729
|
|
|
661
730
|
Importing from the submodule path tree-shakes normally. On a minimal function this cut the bundle esbuild produces by ~54% (the `effect/Schema` module alone by ~75%) and its cold-start module-evaluation time by ~35%, with `fast-check` dropped entirely. This is also the import style Effect v4 recommends, so it's forward-compatible. A `no-restricted-imports` ESLint rule now enforces it across the codebase (type-only imports and `@effect/vitest` are exempt).
|
|
662
731
|
|
|
663
|
-
No API changes
|
|
732
|
+
No API changes—your existing code keeps working.
|
|
664
733
|
|
|
665
734
|
### Getting the full win in your own code
|
|
666
735
|
|
package/dist/HttpClient.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ import * as Layer from "effect/Layer";
|
|
|
4
4
|
import * as InternalHttpClient from "./internal/HttpClient";
|
|
5
5
|
export { HttpClientError } from "./internal/HttpClient";
|
|
6
6
|
/**
|
|
7
|
-
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
7
|
+
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
8
|
+
* Works in any JS runtime that supports `fetch`. Wraps
|
|
9
|
+
* [ConvexHttpClient](https://docs.convex.dev/api/classes/browser.ConvexHttpClient).
|
|
8
10
|
*/
|
|
9
11
|
export declare const HttpClient: Context.Service<{
|
|
10
12
|
url: string;
|
package/dist/HttpClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../src/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAoBxD
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../src/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAoBxD;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;EAEtB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,UAAU,CAAC;AAEtD,eAAO,MAAM,KAAK,YACP,MAAM,YACL,qBAAqB,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC;;;;;;;gBACJ,CAAC"}
|
package/dist/HttpClient.js
CHANGED
|
@@ -21,7 +21,9 @@ const make = (address, options) => {
|
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
24
|
+
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
25
|
+
* Works in any JS runtime that supports `fetch`. Wraps
|
|
26
|
+
* [ConvexHttpClient](https://docs.convex.dev/api/classes/browser.ConvexHttpClient).
|
|
25
27
|
*/
|
|
26
28
|
const HttpClient = Context.Service("@confect/js/HttpClient");
|
|
27
29
|
const layer = (address, options) => Layer.sync(HttpClient, () => make(address, options));
|
package/dist/HttpClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.js","names":["InternalHttpClient.make"],"sources":["../src/HttpClient.ts"],"sourcesContent":["import { ConvexHttpClient } from \"convex/browser\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport * as InternalHttpClient from \"./internal/HttpClient\";\n\nexport { HttpClientError } from \"./internal/HttpClient\";\n\nconst make = (\n address: string,\n options?: ConstructorParameters<typeof ConvexHttpClient>[1],\n) => {\n const client = new ConvexHttpClient(address, options);\n return InternalHttpClient.make({\n url: client.url,\n setAuth: (token) => client.setAuth(token),\n clearAuth: () => client.clearAuth(),\n query: (functionReference, encodedArgs) =>\n client.query(functionReference, encodedArgs),\n mutation: (functionReference, encodedArgs) =>\n client.mutation(functionReference, encodedArgs),\n action: (functionReference, encodedArgs) =>\n client.action(functionReference, encodedArgs),\n });\n};\n\n/**\n * A Confect client which uses HTTP to communicate with your Convex backend
|
|
1
|
+
{"version":3,"file":"HttpClient.js","names":["InternalHttpClient.make"],"sources":["../src/HttpClient.ts"],"sourcesContent":["import { ConvexHttpClient } from \"convex/browser\";\nimport * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\nimport * as InternalHttpClient from \"./internal/HttpClient\";\n\nexport { HttpClientError } from \"./internal/HttpClient\";\n\nconst make = (\n address: string,\n options?: ConstructorParameters<typeof ConvexHttpClient>[1],\n) => {\n const client = new ConvexHttpClient(address, options);\n return InternalHttpClient.make({\n url: client.url,\n setAuth: (token) => client.setAuth(token),\n clearAuth: () => client.clearAuth(),\n query: (functionReference, encodedArgs) =>\n client.query(functionReference, encodedArgs),\n mutation: (functionReference, encodedArgs) =>\n client.mutation(functionReference, encodedArgs),\n action: (functionReference, encodedArgs) =>\n client.action(functionReference, encodedArgs),\n });\n};\n\n/**\n * A Confect client which uses HTTP to communicate with your Convex backend.\n * Works in any JS runtime that supports `fetch`. Wraps\n * [ConvexHttpClient](https://docs.convex.dev/api/classes/browser.ConvexHttpClient).\n */\nexport const HttpClient = Context.Service<ReturnType<typeof make>>(\n \"@confect/js/HttpClient\",\n);\n\nexport type HttpClient = typeof HttpClient.Identifier;\n\nexport const layer = (\n address: string,\n options?: ConstructorParameters<typeof ConvexHttpClient>[1],\n) => Layer.sync(HttpClient, () => make(address, options));\n"],"mappings":";;;;;;;;;;;AAOA,MAAM,QACJ,SACA,YACG;CACH,MAAM,SAAS,IAAI,iBAAiB,SAAS,OAAO;CACpD,OAAOA,OAAwB;EAC7B,KAAK,OAAO;EACZ,UAAU,UAAU,OAAO,QAAQ,KAAK;EACxC,iBAAiB,OAAO,UAAU;EAClC,QAAQ,mBAAmB,gBACzB,OAAO,MAAM,mBAAmB,WAAW;EAC7C,WAAW,mBAAmB,gBAC5B,OAAO,SAAS,mBAAmB,WAAW;EAChD,SAAS,mBAAmB,gBAC1B,OAAO,OAAO,mBAAmB,WAAW;CAChD,CAAC;AACH;;;;;;AAOA,MAAa,aAAa,QAAQ,QAChC,wBACF;AAIA,MAAa,SACX,SACA,YACG,MAAM,KAAK,kBAAkB,KAAK,SAAS,OAAO,CAAC"}
|
|
@@ -5,7 +5,11 @@ import * as Layer from "effect/Layer";
|
|
|
5
5
|
import * as InternalWebSocketClient from "./internal/WebSocketClient";
|
|
6
6
|
export { WebSocketClientError } from "./internal/WebSocketClient";
|
|
7
7
|
/**
|
|
8
|
-
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
8
|
+
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
9
|
+
* backend and supports reactive query subscriptions. The WebSocket connection
|
|
10
|
+
* is managed by the layer's scope and closed automatically when the scope ends.
|
|
11
|
+
* Wraps
|
|
12
|
+
* [ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient).
|
|
9
13
|
*/
|
|
10
14
|
export declare const WebSocketClient: Context.Service<{
|
|
11
15
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../src/WebSocketClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,uBAAuB,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAiClE
|
|
1
|
+
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../src/WebSocketClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,uBAAuB,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAiClE;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;EAEI,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,OAAO,eAAe,CAAC,UAAU,CAAC;AAEhE,eAAO,MAAM,KAAK,YACP,MAAM,YACL,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;gBACC,CAAC"}
|
package/dist/WebSocketClient.js
CHANGED
|
@@ -22,7 +22,11 @@ const make = (address, options) => makeScoped(address, Effect.sync(() => {
|
|
|
22
22
|
};
|
|
23
23
|
}));
|
|
24
24
|
/**
|
|
25
|
-
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
25
|
+
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
26
|
+
* backend and supports reactive query subscriptions. The WebSocket connection
|
|
27
|
+
* is managed by the layer's scope and closed automatically when the scope ends.
|
|
28
|
+
* Wraps
|
|
29
|
+
* [ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient).
|
|
26
30
|
*/
|
|
27
31
|
const WebSocketClient = Context.Service("@confect/js/WebSocketClient");
|
|
28
32
|
const layer = (address, options) => Layer.effect(WebSocketClient, make(address, options));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketClient.js","names":["InternalWebSocketClient.makeScoped"],"sources":["../src/WebSocketClient.ts"],"sourcesContent":["import { ConvexClient } from \"convex/browser\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as InternalWebSocketClient from \"./internal/WebSocketClient\";\n\nexport { WebSocketClientError } from \"./internal/WebSocketClient\";\n\nconst make = (\n address: string,\n options?: ConstructorParameters<typeof ConvexClient>[1],\n) =>\n InternalWebSocketClient.makeScoped(\n address,\n Effect.sync(() => {\n const convexClient = new ConvexClient(address, options);\n return {\n setAuth: (fetchToken, onChange) =>\n onChange === undefined\n ? convexClient.setAuth(fetchToken)\n : convexClient.setAuth(fetchToken, onChange),\n close: () => convexClient.close(),\n query: (functionReference, encodedArgs) =>\n convexClient.query(functionReference, encodedArgs),\n mutation: (functionReference, encodedArgs) =>\n convexClient.mutation(functionReference, encodedArgs),\n action: (functionReference, encodedArgs) =>\n convexClient.action(functionReference, encodedArgs),\n onUpdate: (functionReference, encodedArgs, onUpdate, onError) =>\n convexClient.onUpdate(\n functionReference,\n encodedArgs,\n onUpdate,\n onError,\n ),\n };\n }),\n );\n\n/**\n * A Confect client which uses a WebSocket to communicate with your Convex backend and supports reactive query subscriptions. The WebSocket connection is managed by the layer's scope and closed automatically when the scope ends
|
|
1
|
+
{"version":3,"file":"WebSocketClient.js","names":["InternalWebSocketClient.makeScoped"],"sources":["../src/WebSocketClient.ts"],"sourcesContent":["import { ConvexClient } from \"convex/browser\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as InternalWebSocketClient from \"./internal/WebSocketClient\";\n\nexport { WebSocketClientError } from \"./internal/WebSocketClient\";\n\nconst make = (\n address: string,\n options?: ConstructorParameters<typeof ConvexClient>[1],\n) =>\n InternalWebSocketClient.makeScoped(\n address,\n Effect.sync(() => {\n const convexClient = new ConvexClient(address, options);\n return {\n setAuth: (fetchToken, onChange) =>\n onChange === undefined\n ? convexClient.setAuth(fetchToken)\n : convexClient.setAuth(fetchToken, onChange),\n close: () => convexClient.close(),\n query: (functionReference, encodedArgs) =>\n convexClient.query(functionReference, encodedArgs),\n mutation: (functionReference, encodedArgs) =>\n convexClient.mutation(functionReference, encodedArgs),\n action: (functionReference, encodedArgs) =>\n convexClient.action(functionReference, encodedArgs),\n onUpdate: (functionReference, encodedArgs, onUpdate, onError) =>\n convexClient.onUpdate(\n functionReference,\n encodedArgs,\n onUpdate,\n onError,\n ),\n };\n }),\n );\n\n/**\n * A Confect client which uses a WebSocket to communicate with your Convex\n * backend and supports reactive query subscriptions. The WebSocket connection\n * is managed by the layer's scope and closed automatically when the scope ends.\n * Wraps\n * [ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient).\n */\nexport const WebSocketClient = Context.Service<\n Effect.Success<ReturnType<typeof make>>\n>(\"@confect/js/WebSocketClient\");\n\nexport type WebSocketClient = typeof WebSocketClient.Identifier;\n\nexport const layer = (\n address: string,\n options?: ConstructorParameters<typeof ConvexClient>[1],\n) => Layer.effect(WebSocketClient, make(address, options));\n"],"mappings":";;;;;;;;;;;;AAQA,MAAM,QACJ,SACA,YAEAA,WACE,SACA,OAAO,WAAW;CAChB,MAAM,eAAe,IAAI,aAAa,SAAS,OAAO;CACtD,OAAO;EACL,UAAU,YAAY,aACpB,aAAa,KAAA,IACT,aAAa,QAAQ,UAAU,IAC/B,aAAa,QAAQ,YAAY,QAAQ;EAC/C,aAAa,aAAa,MAAM;EAChC,QAAQ,mBAAmB,gBACzB,aAAa,MAAM,mBAAmB,WAAW;EACnD,WAAW,mBAAmB,gBAC5B,aAAa,SAAS,mBAAmB,WAAW;EACtD,SAAS,mBAAmB,gBAC1B,aAAa,OAAO,mBAAmB,WAAW;EACpD,WAAW,mBAAmB,aAAa,UAAU,YACnD,aAAa,SACX,mBACA,aACA,UACA,OACF;CACJ;AACF,CAAC,CACH;;;;;;;;AASF,MAAa,kBAAkB,QAAQ,QAErC,6BAA6B;AAI/B,MAAa,SACX,SACA,YACG,MAAM,OAAO,iBAAiB,KAAK,SAAS,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/internal/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;AAExC,qBAAa,eAAgB,SAAQ,oBAKpC;CAAG;AAEJ,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,CACd,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,EAC5D,WAAW,EAAE,OAAO,KACjB,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,CACjB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAC/D,WAAW,EAAE,OAAO,KACjB,WAAW,CAAC,OAAO,CAAC,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,CACf,iBAAiB,EAAE,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,eAAe,CAAC,EAC7D,WAAW,EAAE,OAAO,KACjB,WAAW,CAAC,OAAO,CAAC,CAAC;CAC3B;
|
|
1
|
+
{"version":3,"file":"HttpClient.d.ts","sourceRoot":"","sources":["../../src/internal/HttpClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG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AC,KAClC,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EACrB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,eAAe,GAAG,MAAM,CAAC,WAAW,CAC3D;aAae,MAAM,SAAS,GAAG,CAAC,eAAe,OAC3C,MAAM,WACF,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,KAChC,MAAM,CAAC,MAAM,CACd,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EACnB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,eAAe,GAAG,MAAM,CAAC,WAAW,CACzD;CAqBF,CAAC"}
|
|
@@ -3,6 +3,9 @@ import * as Ref from "@confect/core/Ref";
|
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
//#region src/internal/HttpClient.ts
|
|
5
5
|
var HttpClientError = class extends Schema.TaggedError()("HttpClientError", { cause: Schema.Unknown }) {};
|
|
6
|
+
const runQuery = Effect.fn("HttpClient.query")((effect) => effect);
|
|
7
|
+
const runMutation = Effect.fn("HttpClient.mutation")((effect) => effect);
|
|
8
|
+
const runAction = Effect.fn("HttpClient.action")((effect) => effect);
|
|
6
9
|
const make = (client) => {
|
|
7
10
|
const setAuth = (token) => Effect.sync(() => {
|
|
8
11
|
client.setAuth(token);
|
|
@@ -13,15 +16,15 @@ const make = (client) => {
|
|
|
13
16
|
const mapUnknownError = (cause) => new HttpClientError({ cause });
|
|
14
17
|
const query = (ref, ...rest) => {
|
|
15
18
|
const args = rest[0] ?? {};
|
|
16
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.query(functionReference, encodedArgs), mapUnknownError);
|
|
19
|
+
return runQuery(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.query(functionReference, encodedArgs), mapUnknownError));
|
|
17
20
|
};
|
|
18
21
|
const mutation = (ref, ...rest) => {
|
|
19
22
|
const args = rest[0] ?? {};
|
|
20
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.mutation(functionReference, encodedArgs), mapUnknownError);
|
|
23
|
+
return runMutation(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.mutation(functionReference, encodedArgs), mapUnknownError));
|
|
21
24
|
};
|
|
22
25
|
const action = (ref, ...rest) => {
|
|
23
26
|
const args = rest[0] ?? {};
|
|
24
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.action(functionReference, encodedArgs), mapUnknownError);
|
|
27
|
+
return runAction(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => client.action(functionReference, encodedArgs), mapUnknownError));
|
|
25
28
|
};
|
|
26
29
|
return {
|
|
27
30
|
url: client.url,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.js","names":[],"sources":["../../src/internal/HttpClient.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\n\nexport class HttpClientError extends Schema.TaggedError<HttpClientError>()(\n \"HttpClientError\",\n {\n cause: Schema.Unknown,\n },\n) {}\n\nexport interface Transport {\n readonly url: string;\n readonly setAuth: (token: string) => void;\n readonly clearAuth: () => void;\n readonly query: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly mutation: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicMutation>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly action: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicAction>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n}\n\nexport const make = (client: Transport) => {\n const setAuth = (token: string) =>\n Effect.sync(() => {\n client.setAuth(token);\n });\n\n const clearAuth = Effect.sync(() => {\n client.clearAuth();\n });\n\n const mapUnknownError = (cause: unknown) => new HttpClientError({ cause });\n\n const query = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Effect.Effect<\n Ref.Returns<Query>,\n Ref.Error<Query> | HttpClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Query>;\n return Ref.runWithCodec(\n
|
|
1
|
+
{"version":3,"file":"HttpClient.js","names":[],"sources":["../../src/internal/HttpClient.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\n\nexport class HttpClientError extends Schema.TaggedError<HttpClientError>()(\n \"HttpClientError\",\n {\n cause: Schema.Unknown,\n },\n) {}\n\nexport interface Transport {\n readonly url: string;\n readonly setAuth: (token: string) => void;\n readonly clearAuth: () => void;\n readonly query: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly mutation: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicMutation>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly action: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicAction>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n}\n\nconst runQuery = Effect.fn(\"HttpClient.query\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nconst runMutation = Effect.fn(\"HttpClient.mutation\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nconst runAction = Effect.fn(\"HttpClient.action\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nexport const make = (client: Transport) => {\n const setAuth = (token: string) =>\n Effect.sync(() => {\n client.setAuth(token);\n });\n\n const clearAuth = Effect.sync(() => {\n client.clearAuth();\n });\n\n const mapUnknownError = (cause: unknown) => new HttpClientError({ cause });\n\n const query = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Effect.Effect<\n Ref.Returns<Query>,\n Ref.Error<Query> | HttpClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Query>;\n return runQuery(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n client.query(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n const mutation = <Mutation extends Ref.AnyPublicMutation>(\n ref: Mutation,\n ...rest: Ref.OptionalArgs<Mutation>\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | HttpClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Mutation>;\n return runMutation(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n client.mutation(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n const action = <Action extends Ref.AnyPublicAction>(\n ref: Action,\n ...rest: Ref.OptionalArgs<Action>\n ): Effect.Effect<\n Ref.Returns<Action>,\n Ref.Error<Action> | HttpClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Action>;\n return runAction(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n client.action(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n return {\n url: client.url,\n setAuth,\n clearAuth,\n query,\n mutation,\n action,\n };\n};\n"],"mappings":";;;;AAIA,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CACxE,mBACA,EACE,OAAO,OAAO,QAChB,CACF,CAAC,CAAC,CAAC;AAoBH,MAAM,WAAW,OAAO,GAAG,kBAAkB,CAAC,EACrC,WAAqD,MAC9D;AAEA,MAAM,cAAc,OAAO,GAAG,qBAAqB,CAAC,EAC3C,WAAqD,MAC9D;AAEA,MAAM,YAAY,OAAO,GAAG,mBAAmB,CAAC,EACvC,WAAqD,MAC9D;AAEA,MAAa,QAAQ,WAAsB;CACzC,MAAM,WAAW,UACf,OAAO,WAAW;EAChB,OAAO,QAAQ,KAAK;CACtB,CAAC;CAEH,MAAM,YAAY,OAAO,WAAW;EAClC,OAAO,UAAU;CACnB,CAAC;CAED,MAAM,mBAAmB,UAAmB,IAAI,gBAAgB,EAAE,MAAM,CAAC;CAEzE,MAAM,SACJ,KACA,GAAG,SAIA;EACH,MAAM,OAAQ,KAAK,MAAM,CAAC;EAC1B,OAAO,SACL,IAAI,aACF,KACA,OACC,mBAAmB,gBAClB,OAAO,MAAM,mBAAmB,WAAW,GAC7C,eACF,CACF;CACF;CAEA,MAAM,YACJ,KACA,GAAG,SAIA;EACH,MAAM,OAAQ,KAAK,MAAM,CAAC;EAC1B,OAAO,YACL,IAAI,aACF,KACA,OACC,mBAAmB,gBAClB,OAAO,SAAS,mBAAmB,WAAW,GAChD,eACF,CACF;CACF;CAEA,MAAM,UACJ,KACA,GAAG,SAIA;EACH,MAAM,OAAQ,KAAK,MAAM,CAAC;EAC1B,OAAO,UACL,IAAI,aACF,KACA,OACC,mBAAmB,gBAClB,OAAO,OAAO,mBAAmB,WAAW,GAC9C,eACF,CACF;CACF;CAEA,OAAO;EACL,KAAK,OAAO;EACZ;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../../src/internal/WebSocketClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;;;;AAExC,qBAAa,oBAAqB,SAAQ,yBAKzC;CAAG;AAEJ,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,CAChB,UAAU,EAAE,CAAC,IAAI,EAAE;QACjB,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;KACrC,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS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MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,+DAA4B;0BAtDlC,KAAK,SAAS,GAAG,CAAC,cAAc,OACtD,KAAK,WACD,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,KAC/B,MAAM,CAAC,MAAM,CACd,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,+DAA4B,CAC7D;uCA4EgE,CAAC"}
|
|
@@ -6,6 +6,9 @@ import * as Schema from "effect/Schema";
|
|
|
6
6
|
import * as Stream from "effect/Stream";
|
|
7
7
|
//#region src/internal/WebSocketClient.ts
|
|
8
8
|
var WebSocketClientError = class extends Schema.TaggedError()("WebSocketClientError", { cause: Schema.Defect() }) {};
|
|
9
|
+
const runQuery = Effect.fn("WebSocketClient.query")((effect) => effect);
|
|
10
|
+
const runMutation = Effect.fn("WebSocketClient.mutation")((effect) => effect);
|
|
11
|
+
const runAction = Effect.fn("WebSocketClient.action")((effect) => effect);
|
|
9
12
|
const make = (address, convexClient) => {
|
|
10
13
|
const setAuth = (fetchToken, onChange) => Effect.sync(() => {
|
|
11
14
|
convexClient.setAuth((args) => Effect.runPromise(fetchToken(args)), ...onChange ? [(isAuthenticated) => Effect.runFork(onChange(isAuthenticated))] : []);
|
|
@@ -13,15 +16,15 @@ const make = (address, convexClient) => {
|
|
|
13
16
|
const mapUnknownError = (cause) => new WebSocketClientError({ cause });
|
|
14
17
|
const query = (ref, ...rest) => {
|
|
15
18
|
const args = rest[0] ?? {};
|
|
16
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.query(functionReference, encodedArgs), mapUnknownError);
|
|
19
|
+
return runQuery(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.query(functionReference, encodedArgs), mapUnknownError));
|
|
17
20
|
};
|
|
18
21
|
const mutation = (ref, ...rest) => {
|
|
19
22
|
const args = rest[0] ?? {};
|
|
20
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.mutation(functionReference, encodedArgs), mapUnknownError);
|
|
23
|
+
return runMutation(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.mutation(functionReference, encodedArgs), mapUnknownError));
|
|
21
24
|
};
|
|
22
25
|
const action = (ref, ...rest) => {
|
|
23
26
|
const args = rest[0] ?? {};
|
|
24
|
-
return Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.action(functionReference, encodedArgs), mapUnknownError);
|
|
27
|
+
return runAction(Ref.runWithCodec(ref, args, (functionReference, encodedArgs) => convexClient.action(functionReference, encodedArgs), mapUnknownError));
|
|
25
28
|
};
|
|
26
29
|
const reactiveQueryResult = (ref, ...rest) => {
|
|
27
30
|
const args = rest[0] ?? {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketClient.js","names":[],"sources":["../../src/internal/WebSocketClient.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\n\nexport class WebSocketClientError extends Schema.TaggedError<WebSocketClientError>()(\n \"WebSocketClientError\",\n {\n cause: Schema.Defect(),\n },\n) {}\n\nexport interface Transport {\n readonly setAuth: (\n fetchToken: (args: {\n readonly forceRefreshToken: boolean;\n }) => Promise<string | null | undefined>,\n onChange?: (isAuthenticated: boolean) => void,\n ) => void;\n readonly close: () => Promise<void>;\n readonly query: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly mutation: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicMutation>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly action: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicAction>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly onUpdate: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n onUpdate: (result: unknown) => void,\n onError: (error: Error) => void,\n ) => () => void;\n}\n\nexport const make = (address: string, convexClient: Transport) => {\n const setAuth = (\n fetchToken: (args: {\n forceRefreshToken: boolean;\n }) => Effect.Effect<string | null | undefined>,\n onChange?: (isAuthenticated: boolean) => Effect.Effect<void>,\n ) =>\n Effect.sync(() => {\n convexClient.setAuth(\n (args) => Effect.runPromise(fetchToken(args)),\n ...(onChange\n ? [\n (isAuthenticated: boolean) =>\n Effect.runFork(onChange(isAuthenticated)),\n ]\n : []),\n );\n });\n\n const mapUnknownError = (cause: unknown) =>\n new WebSocketClientError({ cause });\n\n const query = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Effect.Effect<\n Ref.Returns<Query>,\n Ref.Error<Query> | WebSocketClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Query>;\n return Ref.runWithCodec(\n
|
|
1
|
+
{"version":3,"file":"WebSocketClient.js","names":[],"sources":["../../src/internal/WebSocketClient.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\n\nexport class WebSocketClientError extends Schema.TaggedError<WebSocketClientError>()(\n \"WebSocketClientError\",\n {\n cause: Schema.Defect(),\n },\n) {}\n\nexport interface Transport {\n readonly setAuth: (\n fetchToken: (args: {\n readonly forceRefreshToken: boolean;\n }) => Promise<string | null | undefined>,\n onChange?: (isAuthenticated: boolean) => void,\n ) => void;\n readonly close: () => Promise<void>;\n readonly query: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly mutation: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicMutation>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly action: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicAction>,\n encodedArgs: unknown,\n ) => PromiseLike<unknown>;\n readonly onUpdate: (\n functionReference: Ref.FunctionReference<Ref.AnyPublicQuery>,\n encodedArgs: unknown,\n onUpdate: (result: unknown) => void,\n onError: (error: Error) => void,\n ) => () => void;\n}\n\nconst runQuery = Effect.fn(\"WebSocketClient.query\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nconst runMutation = Effect.fn(\"WebSocketClient.mutation\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nconst runAction = Effect.fn(\"WebSocketClient.action\")(\n <A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,\n);\n\nexport const make = (address: string, convexClient: Transport) => {\n const setAuth = (\n fetchToken: (args: {\n forceRefreshToken: boolean;\n }) => Effect.Effect<string | null | undefined>,\n onChange?: (isAuthenticated: boolean) => Effect.Effect<void>,\n ) =>\n Effect.sync(() => {\n convexClient.setAuth(\n (args) => Effect.runPromise(fetchToken(args)),\n ...(onChange\n ? [\n (isAuthenticated: boolean) =>\n Effect.runFork(onChange(isAuthenticated)),\n ]\n : []),\n );\n });\n\n const mapUnknownError = (cause: unknown) =>\n new WebSocketClientError({ cause });\n\n const query = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Effect.Effect<\n Ref.Returns<Query>,\n Ref.Error<Query> | WebSocketClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Query>;\n return runQuery(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n convexClient.query(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n const mutation = <Mutation extends Ref.AnyPublicMutation>(\n ref: Mutation,\n ...rest: Ref.OptionalArgs<Mutation>\n ): Effect.Effect<\n Ref.Returns<Mutation>,\n Ref.Error<Mutation> | WebSocketClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Mutation>;\n return runMutation(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n convexClient.mutation(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n const action = <Action extends Ref.AnyPublicAction>(\n ref: Action,\n ...rest: Ref.OptionalArgs<Action>\n ): Effect.Effect<\n Ref.Returns<Action>,\n Ref.Error<Action> | WebSocketClientError | Schema.SchemaError\n > => {\n const args = (rest[0] ?? {}) as Ref.Args<Action>;\n return runAction(\n Ref.runWithCodec(\n ref,\n args,\n (functionReference, encodedArgs) =>\n convexClient.action(functionReference, encodedArgs),\n mapUnknownError,\n ),\n );\n };\n\n type ReactiveQueryError<Query extends Ref.AnyPublicQuery> =\n | Ref.Error<Query>\n | WebSocketClientError\n | Schema.SchemaError;\n\n const reactiveQueryResult = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Stream.Stream<\n Result.Result<Ref.Returns<Query>, ReactiveQueryError<Query>>\n > => {\n type QueryResult = Result.Result<\n Ref.Returns<Query>,\n ReactiveQueryError<Query>\n >;\n const args = (rest[0] ?? {}) as Ref.Args<Query>;\n const functionReference = Ref.getFunctionReference(ref);\n const onError = Ref.decodeErrorOrElse(ref, mapUnknownError);\n\n return Stream.unwrap(\n Effect.match(Ref.encodeArgs(ref, args), {\n onFailure: (error) => Stream.succeed<QueryResult>(Result.fail(error)),\n onSuccess: (encodedArgs) =>\n Stream.callback<Result.Result<unknown, ReactiveQueryError<Query>>>(\n (queue) =>\n Effect.gen(function* () {\n const unsubscribe = convexClient.onUpdate(\n functionReference,\n encodedArgs,\n (result) => {\n Queue.offerUnsafe(queue, Result.succeed(result));\n },\n (error) => {\n Queue.offerUnsafe(queue, Result.fail(onError(error)));\n },\n );\n yield* Effect.addFinalizer(() =>\n Effect.sync(() => unsubscribe()),\n );\n }),\n ),\n }),\n ).pipe(\n Stream.mapEffect((result): Effect.Effect<QueryResult> =>\n Result.match(result, {\n onFailure: (error) => Effect.succeed(Result.fail(error)),\n onSuccess: (encodedReturns) =>\n Effect.match(Ref.decodeReturns(ref, encodedReturns), {\n onFailure: Result.fail,\n onSuccess: Result.succeed,\n }),\n }),\n ),\n );\n };\n\n const reactiveQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: Ref.OptionalArgs<Query>\n ): Stream.Stream<Ref.Returns<Query>, ReactiveQueryError<Query>> =>\n reactiveQueryResult(ref, ...rest).pipe(\n Stream.mapEffect(\n Result.match({\n onFailure: Effect.fail,\n onSuccess: Effect.succeed,\n }),\n ),\n );\n\n return {\n url: address,\n setAuth,\n query,\n mutation,\n action,\n reactiveQuery,\n reactiveQueryResult,\n };\n};\n\nexport const makeScoped = <E, R>(\n address: string,\n acquire: Effect.Effect<Transport, E, R>,\n) =>\n Effect.acquireRelease(acquire, (convexClient) =>\n Effect.promise(() => convexClient.close()),\n ).pipe(Effect.map((convexClient) => make(address, convexClient)));\n"],"mappings":";;;;;;;AAOA,IAAa,uBAAb,cAA0C,OAAO,YAAkC,CAAC,CAClF,wBACA,EACE,OAAO,OAAO,OAAO,EACvB,CACF,CAAC,CAAC,CAAC;AA8BH,MAAM,WAAW,OAAO,GAAG,uBAAuB,CAAC,EAC1C,WAAqD,MAC9D;AAEA,MAAM,cAAc,OAAO,GAAG,0BAA0B,CAAC,EAChD,WAAqD,MAC9D;AAEA,MAAM,YAAY,OAAO,GAAG,wBAAwB,CAAC,EAC5C,WAAqD,MAC9D;AAEA,MAAa,QAAQ,SAAiB,iBAA4B;CAChE,MAAM,WACJ,YAGA,aAEA,OAAO,WAAW;EAChB,aAAa,SACV,SAAS,OAAO,WAAW,WAAW,IAAI,CAAC,GAC5C,GAAI,WACA,EACG,oBACC,OAAO,QAAQ,SAAS,eAAe,CAAC,CAC5C,IACA,CAAC,CACP;CACF,CAAC;CAEH,MAAM,mBAAmB,UACv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AAO,QAAQ,OAAO,KAAK,KAAK,CAAC;GACvD,YAAY,mBACV,OAAO,MAAM,IAAI,cAAc,KAAK,cAAc,GAAG;IACnD,WAAW,OAAO;IAClB,WAAW,OAAO;GACpB,CAAC;EACL,CAAC,CACH,CACF;CACF;CAEA,MAAM,iBACJ,KACA,GAAG,SAEH,oBAAoB,KAAK,GAAG,IAAI,CAAC,CAAC,KAChC,OAAO,UACL,OAAO,MAAM;EACX,WAAW,OAAO;EAClB,WAAW,OAAO;CACpB,CAAC,CACH,CACF;CAEF,OAAO;EACL,KAAK;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAEA,MAAa,cACX,SACA,YAEA,OAAO,eAAe,UAAU,iBAC9B,OAAO,cAAc,aAAa,MAAM,CAAC,CAC3C,CAAC,CAAC,KAAK,OAAO,KAAK,iBAAiB,KAAK,SAAS,YAAY,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/js",
|
|
3
3
|
"description": "JavaScript client bindings for any JS runtime",
|
|
4
|
-
"version": "10.0.0-next.
|
|
4
|
+
"version": "10.0.0-next.23",
|
|
5
5
|
"author": "RJ Dellecese",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/rjdellecese/confect/issues"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@effect/vitest": "4.0.0-rc.
|
|
10
|
+
"@effect/vitest": "4.0.0-rc.115",
|
|
11
11
|
"@types/node": "24.13.3",
|
|
12
|
-
"effect": "4.0.0-rc.
|
|
13
|
-
"tsdown": "0.
|
|
12
|
+
"effect": "4.0.0-rc.115",
|
|
13
|
+
"tsdown": "0.23.0",
|
|
14
14
|
"typescript": "7.0.2",
|
|
15
15
|
"unrun": "0.3.1",
|
|
16
|
-
"vitest": "
|
|
16
|
+
"vitest": "5.0.0"
|
|
17
17
|
},
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=24"
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"main": "./dist/index.js",
|
|
48
48
|
"module": "./dist/index.js",
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@confect/core": "^10.0.0-next.
|
|
50
|
+
"@confect/core": "^10.0.0-next.23",
|
|
51
51
|
"convex": "^1.32.0",
|
|
52
|
-
"effect": "^4.0.0-rc.
|
|
52
|
+
"effect": "^4.0.0-rc.115"
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
|
55
55
|
"type": "git",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"clean": "shx rm -rf dist coverage node_modules",
|
|
63
63
|
"dev": "tsdown --watch --no-clean --config-loader unrun",
|
|
64
64
|
"test": "vitest run",
|
|
65
|
-
"typecheck": "tsc -b tsconfig.src.json"
|
|
65
|
+
"typecheck": "tsc -b tsconfig.src.json",
|
|
66
|
+
"typecheck:inexact": "tsc --noEmit --project tsconfig.json --exactOptionalPropertyTypes false"
|
|
66
67
|
}
|
|
67
68
|
}
|
package/src/HttpClient.ts
CHANGED
|
@@ -24,7 +24,9 @@ const make = (
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
27
|
+
* A Confect client which uses HTTP to communicate with your Convex backend.
|
|
28
|
+
* Works in any JS runtime that supports `fetch`. Wraps
|
|
29
|
+
* [ConvexHttpClient](https://docs.convex.dev/api/classes/browser.ConvexHttpClient).
|
|
28
30
|
*/
|
|
29
31
|
export const HttpClient = Context.Service<ReturnType<typeof make>>(
|
|
30
32
|
"@confect/js/HttpClient",
|
package/src/WebSocketClient.ts
CHANGED
|
@@ -38,7 +38,11 @@ const make = (
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
41
|
+
* A Confect client which uses a WebSocket to communicate with your Convex
|
|
42
|
+
* backend and supports reactive query subscriptions. The WebSocket connection
|
|
43
|
+
* is managed by the layer's scope and closed automatically when the scope ends.
|
|
44
|
+
* Wraps
|
|
45
|
+
* [ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient).
|
|
42
46
|
*/
|
|
43
47
|
export const WebSocketClient = Context.Service<
|
|
44
48
|
Effect.Success<ReturnType<typeof make>>
|
|
@@ -27,6 +27,18 @@ export interface Transport {
|
|
|
27
27
|
) => PromiseLike<unknown>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
const runQuery = Effect.fn("HttpClient.query")(
|
|
31
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const runMutation = Effect.fn("HttpClient.mutation")(
|
|
35
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const runAction = Effect.fn("HttpClient.action")(
|
|
39
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
40
|
+
);
|
|
41
|
+
|
|
30
42
|
export const make = (client: Transport) => {
|
|
31
43
|
const setAuth = (token: string) =>
|
|
32
44
|
Effect.sync(() => {
|
|
@@ -47,12 +59,14 @@ export const make = (client: Transport) => {
|
|
|
47
59
|
Ref.Error<Query> | HttpClientError | Schema.SchemaError
|
|
48
60
|
> => {
|
|
49
61
|
const args = (rest[0] ?? {}) as Ref.Args<Query>;
|
|
50
|
-
return
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
return runQuery(
|
|
63
|
+
Ref.runWithCodec(
|
|
64
|
+
ref,
|
|
65
|
+
args,
|
|
66
|
+
(functionReference, encodedArgs) =>
|
|
67
|
+
client.query(functionReference, encodedArgs),
|
|
68
|
+
mapUnknownError,
|
|
69
|
+
),
|
|
56
70
|
);
|
|
57
71
|
};
|
|
58
72
|
|
|
@@ -64,12 +78,14 @@ export const make = (client: Transport) => {
|
|
|
64
78
|
Ref.Error<Mutation> | HttpClientError | Schema.SchemaError
|
|
65
79
|
> => {
|
|
66
80
|
const args = (rest[0] ?? {}) as Ref.Args<Mutation>;
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
return runMutation(
|
|
82
|
+
Ref.runWithCodec(
|
|
83
|
+
ref,
|
|
84
|
+
args,
|
|
85
|
+
(functionReference, encodedArgs) =>
|
|
86
|
+
client.mutation(functionReference, encodedArgs),
|
|
87
|
+
mapUnknownError,
|
|
88
|
+
),
|
|
73
89
|
);
|
|
74
90
|
};
|
|
75
91
|
|
|
@@ -81,12 +97,14 @@ export const make = (client: Transport) => {
|
|
|
81
97
|
Ref.Error<Action> | HttpClientError | Schema.SchemaError
|
|
82
98
|
> => {
|
|
83
99
|
const args = (rest[0] ?? {}) as Ref.Args<Action>;
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
return runAction(
|
|
101
|
+
Ref.runWithCodec(
|
|
102
|
+
ref,
|
|
103
|
+
args,
|
|
104
|
+
(functionReference, encodedArgs) =>
|
|
105
|
+
client.action(functionReference, encodedArgs),
|
|
106
|
+
mapUnknownError,
|
|
107
|
+
),
|
|
90
108
|
);
|
|
91
109
|
};
|
|
92
110
|
|
|
@@ -40,6 +40,18 @@ export interface Transport {
|
|
|
40
40
|
) => () => void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const runQuery = Effect.fn("WebSocketClient.query")(
|
|
44
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const runMutation = Effect.fn("WebSocketClient.mutation")(
|
|
48
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const runAction = Effect.fn("WebSocketClient.action")(
|
|
52
|
+
<A, E>(effect: Effect.Effect<A, E>): Effect.Effect<A, E> => effect,
|
|
53
|
+
);
|
|
54
|
+
|
|
43
55
|
export const make = (address: string, convexClient: Transport) => {
|
|
44
56
|
const setAuth = (
|
|
45
57
|
fetchToken: (args: {
|
|
@@ -70,12 +82,14 @@ export const make = (address: string, convexClient: Transport) => {
|
|
|
70
82
|
Ref.Error<Query> | WebSocketClientError | Schema.SchemaError
|
|
71
83
|
> => {
|
|
72
84
|
const args = (rest[0] ?? {}) as Ref.Args<Query>;
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
return runQuery(
|
|
86
|
+
Ref.runWithCodec(
|
|
87
|
+
ref,
|
|
88
|
+
args,
|
|
89
|
+
(functionReference, encodedArgs) =>
|
|
90
|
+
convexClient.query(functionReference, encodedArgs),
|
|
91
|
+
mapUnknownError,
|
|
92
|
+
),
|
|
79
93
|
);
|
|
80
94
|
};
|
|
81
95
|
|
|
@@ -87,12 +101,14 @@ export const make = (address: string, convexClient: Transport) => {
|
|
|
87
101
|
Ref.Error<Mutation> | WebSocketClientError | Schema.SchemaError
|
|
88
102
|
> => {
|
|
89
103
|
const args = (rest[0] ?? {}) as Ref.Args<Mutation>;
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
104
|
+
return runMutation(
|
|
105
|
+
Ref.runWithCodec(
|
|
106
|
+
ref,
|
|
107
|
+
args,
|
|
108
|
+
(functionReference, encodedArgs) =>
|
|
109
|
+
convexClient.mutation(functionReference, encodedArgs),
|
|
110
|
+
mapUnknownError,
|
|
111
|
+
),
|
|
96
112
|
);
|
|
97
113
|
};
|
|
98
114
|
|
|
@@ -104,12 +120,14 @@ export const make = (address: string, convexClient: Transport) => {
|
|
|
104
120
|
Ref.Error<Action> | WebSocketClientError | Schema.SchemaError
|
|
105
121
|
> => {
|
|
106
122
|
const args = (rest[0] ?? {}) as Ref.Args<Action>;
|
|
107
|
-
return
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
123
|
+
return runAction(
|
|
124
|
+
Ref.runWithCodec(
|
|
125
|
+
ref,
|
|
126
|
+
args,
|
|
127
|
+
(functionReference, encodedArgs) =>
|
|
128
|
+
convexClient.action(functionReference, encodedArgs),
|
|
129
|
+
mapUnknownError,
|
|
130
|
+
),
|
|
113
131
|
);
|
|
114
132
|
};
|
|
115
133
|
|