@confect/js 9.2.2 → 10.0.0-next.0
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 +18 -2
- package/dist/HttpClient.d.ts +13 -16
- package/dist/HttpClient.d.ts.map +1 -1
- package/dist/HttpClient.js +2 -2
- package/dist/HttpClient.js.map +1 -1
- package/dist/WebSocketClient.d.ts +17 -19
- package/dist/WebSocketClient.d.ts.map +1 -1
- package/dist/WebSocketClient.js +9 -7
- package/dist/WebSocketClient.js.map +1 -1
- package/dist/tsconfig.src.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/HttpClient.ts +5 -6
- package/src/WebSocketClient.ts +15 -14
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/js",
|
|
3
3
|
"description": "JavaScript client bindings for any JS runtime",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "10.0.0-next.0",
|
|
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": "0.
|
|
10
|
+
"@effect/vitest": "4.0.0-beta.97",
|
|
11
11
|
"@types/node": "25.3.3",
|
|
12
|
-
"effect": "
|
|
12
|
+
"effect": "4.0.0-beta.97",
|
|
13
13
|
"tsdown": "0.20.3",
|
|
14
14
|
"typescript": "5.9.3",
|
|
15
15
|
"vitest": "3.2.4"
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"module": "./dist/index.js",
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"convex": "^1.32.0",
|
|
45
|
-
"effect": "^
|
|
46
|
-
"@confect/core": "^
|
|
45
|
+
"effect": "^4.0.0-beta.97",
|
|
46
|
+
"@confect/core": "^10.0.0-next.0"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|
|
49
49
|
"type": "git",
|
package/src/HttpClient.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { ConvexHttpClient } from "convex/browser";
|
|
3
|
-
import type { ParseResult } from "effect";
|
|
4
3
|
import * as Context from "effect/Context";
|
|
5
4
|
import * as Effect from "effect/Effect";
|
|
6
5
|
import * as Layer from "effect/Layer";
|
|
7
6
|
import * as Schema from "effect/Schema";
|
|
8
7
|
|
|
9
|
-
export class HttpClientError extends Schema.
|
|
8
|
+
export class HttpClientError extends Schema.TaggedErrorClass<HttpClientError>()(
|
|
10
9
|
"HttpClientError",
|
|
11
10
|
{
|
|
12
11
|
cause: Schema.Unknown,
|
|
@@ -37,7 +36,7 @@ const make = (
|
|
|
37
36
|
...rest: Ref.OptionalArgs<Query>
|
|
38
37
|
): Effect.Effect<
|
|
39
38
|
Ref.Returns<Query>,
|
|
40
|
-
Ref.Error<Query> | HttpClientError |
|
|
39
|
+
Ref.Error<Query> | HttpClientError | Schema.SchemaError
|
|
41
40
|
> => {
|
|
42
41
|
const args = (rest[0] ?? {}) as Ref.Args<Query>;
|
|
43
42
|
return Ref.runWithCodec(
|
|
@@ -54,7 +53,7 @@ const make = (
|
|
|
54
53
|
...rest: Ref.OptionalArgs<Mutation>
|
|
55
54
|
): Effect.Effect<
|
|
56
55
|
Ref.Returns<Mutation>,
|
|
57
|
-
Ref.Error<Mutation> | HttpClientError |
|
|
56
|
+
Ref.Error<Mutation> | HttpClientError | Schema.SchemaError
|
|
58
57
|
> => {
|
|
59
58
|
const args = (rest[0] ?? {}) as Ref.Args<Mutation>;
|
|
60
59
|
return Ref.runWithCodec(
|
|
@@ -71,7 +70,7 @@ const make = (
|
|
|
71
70
|
...rest: Ref.OptionalArgs<Action>
|
|
72
71
|
): Effect.Effect<
|
|
73
72
|
Ref.Returns<Action>,
|
|
74
|
-
Ref.Error<Action> | HttpClientError |
|
|
73
|
+
Ref.Error<Action> | HttpClientError | Schema.SchemaError
|
|
75
74
|
> => {
|
|
76
75
|
const args = (rest[0] ?? {}) as Ref.Args<Action>;
|
|
77
76
|
return Ref.runWithCodec(
|
|
@@ -96,7 +95,7 @@ const make = (
|
|
|
96
95
|
/**
|
|
97
96
|
* A Confect client which uses HTTP to communicate with your Convex backend. Works in any JS runtime that supports `fetch`. Wraps [ConvexHttpClient](https://docs.convex.dev/api/classes/browser.ConvexHttpClient).
|
|
98
97
|
*/
|
|
99
|
-
export const HttpClient = Context.
|
|
98
|
+
export const HttpClient = Context.Service<ReturnType<typeof make>>(
|
|
100
99
|
"@confect/js/HttpClient",
|
|
101
100
|
);
|
|
102
101
|
|
package/src/WebSocketClient.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as Ref from "@confect/core/Ref";
|
|
2
2
|
import { ConvexClient } from "convex/browser";
|
|
3
|
-
import
|
|
3
|
+
import * as Cause from "effect/Cause";
|
|
4
4
|
import * as Context from "effect/Context";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Queue from "effect/Queue";
|
|
7
8
|
import * as Schema from "effect/Schema";
|
|
8
9
|
import * as Stream from "effect/Stream";
|
|
9
10
|
|
|
10
|
-
export class WebSocketClientError extends Schema.
|
|
11
|
+
export class WebSocketClientError extends Schema.TaggedErrorClass<WebSocketClientError>()(
|
|
11
12
|
"WebSocketClientError",
|
|
12
13
|
{
|
|
13
14
|
cause: Schema.Unknown,
|
|
@@ -51,7 +52,7 @@ const make = (
|
|
|
51
52
|
...rest: Ref.OptionalArgs<Query>
|
|
52
53
|
): Effect.Effect<
|
|
53
54
|
Ref.Returns<Query>,
|
|
54
|
-
Ref.Error<Query> | WebSocketClientError |
|
|
55
|
+
Ref.Error<Query> | WebSocketClientError | Schema.SchemaError
|
|
55
56
|
> => {
|
|
56
57
|
const args = (rest[0] ?? {}) as Ref.Args<Query>;
|
|
57
58
|
return Ref.runWithCodec(
|
|
@@ -68,7 +69,7 @@ const make = (
|
|
|
68
69
|
...rest: Ref.OptionalArgs<Mutation>
|
|
69
70
|
): Effect.Effect<
|
|
70
71
|
Ref.Returns<Mutation>,
|
|
71
|
-
Ref.Error<Mutation> | WebSocketClientError |
|
|
72
|
+
Ref.Error<Mutation> | WebSocketClientError | Schema.SchemaError
|
|
72
73
|
> => {
|
|
73
74
|
const args = (rest[0] ?? {}) as Ref.Args<Mutation>;
|
|
74
75
|
return Ref.runWithCodec(
|
|
@@ -85,7 +86,7 @@ const make = (
|
|
|
85
86
|
...rest: Ref.OptionalArgs<Action>
|
|
86
87
|
): Effect.Effect<
|
|
87
88
|
Ref.Returns<Action>,
|
|
88
|
-
Ref.Error<Action> | WebSocketClientError |
|
|
89
|
+
Ref.Error<Action> | WebSocketClientError | Schema.SchemaError
|
|
89
90
|
> => {
|
|
90
91
|
const args = (rest[0] ?? {}) as Ref.Args<Action>;
|
|
91
92
|
return Ref.runWithCodec(
|
|
@@ -102,29 +103,29 @@ const make = (
|
|
|
102
103
|
...rest: Ref.OptionalArgs<Query>
|
|
103
104
|
): Stream.Stream<
|
|
104
105
|
Ref.Returns<Query>,
|
|
105
|
-
Ref.Error<Query> | WebSocketClientError |
|
|
106
|
+
Ref.Error<Query> | WebSocketClientError | Schema.SchemaError
|
|
106
107
|
> => {
|
|
107
108
|
const args = (rest[0] ?? {}) as Ref.Args<Query>;
|
|
108
109
|
const functionReference = Ref.getFunctionReference(ref);
|
|
109
110
|
const onError = Ref.decodeErrorOrElse(ref, mapUnknownError);
|
|
110
111
|
|
|
111
|
-
return Stream.
|
|
112
|
+
return Stream.unwrap(
|
|
112
113
|
Effect.gen(function* () {
|
|
113
114
|
const encodedArgs = yield* Ref.encodeArgs(ref, args);
|
|
114
115
|
|
|
115
|
-
return Stream.
|
|
116
|
+
return Stream.callback<
|
|
116
117
|
unknown,
|
|
117
118
|
Ref.Error<Query> | WebSocketClientError
|
|
118
|
-
>((
|
|
119
|
+
>((queue) =>
|
|
119
120
|
Effect.gen(function* () {
|
|
120
121
|
const unsubscribe = convexClient.onUpdate(
|
|
121
122
|
functionReference,
|
|
122
123
|
encodedArgs,
|
|
123
124
|
(result) => {
|
|
124
|
-
|
|
125
|
+
Queue.offerUnsafe(queue, result);
|
|
125
126
|
},
|
|
126
127
|
(error) => {
|
|
127
|
-
|
|
128
|
+
Queue.failCauseUnsafe(queue, Cause.fail(onError(error)));
|
|
128
129
|
},
|
|
129
130
|
);
|
|
130
131
|
yield* Effect.addFinalizer(() =>
|
|
@@ -154,8 +155,8 @@ const make = (
|
|
|
154
155
|
/**
|
|
155
156
|
* 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. Wraps [ConvexClient](https://docs.convex.dev/api/classes/browser.ConvexClient).
|
|
156
157
|
*/
|
|
157
|
-
export const WebSocketClient = Context.
|
|
158
|
-
Effect.
|
|
158
|
+
export const WebSocketClient = Context.Service<
|
|
159
|
+
Effect.Success<ReturnType<typeof make>>
|
|
159
160
|
>("@confect/js/WebSocketClient");
|
|
160
161
|
|
|
161
162
|
export type WebSocketClient = typeof WebSocketClient.Identifier;
|
|
@@ -163,4 +164,4 @@ export type WebSocketClient = typeof WebSocketClient.Identifier;
|
|
|
163
164
|
export const layer = (
|
|
164
165
|
address: string,
|
|
165
166
|
options?: ConstructorParameters<typeof ConvexClient>[1],
|
|
166
|
-
) => Layer.
|
|
167
|
+
) => Layer.effect(WebSocketClient, make(address, options));
|