@confect/react 1.0.3 → 3.0.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 +21 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -18
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/index.ts +43 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @confect/react
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5fb6a61: Add support for plain Convex functions. Plain Convex queries, mutations, and actions can now be included in your Confect spec and impl tree using new `FunctionSpec.convexPublic*` and `FunctionSpec.convexInternal*` constructors. This enables interop with Convex components and libraries (such as Workpool, Workflow, Migrations, and Better Auth) that require user-defined or -provided Convex functions.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5fb6a61]
|
|
12
|
+
- @confect/core@3.0.0
|
|
13
|
+
|
|
14
|
+
## 2.0.0
|
|
15
|
+
|
|
16
|
+
### Major Changes
|
|
17
|
+
|
|
18
|
+
- 7861159: Replace Effect-native return types with Convex-equivalent return types in React hooks. `useQuery` now returns `T | undefined` instead of `Option<T>`. `useMutation` and `useAction` now return `(args) => Promise<T>` instead of `(args) => Effect<T>`. The hooks still encode args and decode return values via the spec's Effect Schemas automatically.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- @confect/core@2.0.0
|
|
23
|
+
|
|
3
24
|
## 1.0.3
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Effect, Option } from "effect";
|
|
1
|
+
import { Ref } from "@confect/core";
|
|
3
2
|
|
|
4
3
|
//#region src/index.d.ts
|
|
5
|
-
declare const useQuery: <Query extends Ref.AnyPublicQuery>(ref: Query, args: Ref.Args<Query>
|
|
6
|
-
declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (args: Ref.Args<Mutation>
|
|
7
|
-
declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (args: Ref.Args<Action>
|
|
4
|
+
declare const useQuery: <Query extends Ref.AnyPublicQuery>(ref: Query, args: Ref.Args<Query>) => Ref.Returns<Query> | undefined;
|
|
5
|
+
declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (args: Ref.Args<Mutation>) => Promise<Ref.Returns<Mutation>>;
|
|
6
|
+
declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (args: Ref.Args<Action>) => Promise<Ref.Returns<Action>>;
|
|
8
7
|
//#endregion
|
|
9
8
|
export { useAction, useMutation, useQuery };
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAQa,QAAA,iBAA0B,GAAA,CAAI,cAAA,EACzC,GAAA,EAAK,KAAA,EACL,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,KAAA,MACd,GAAA,CAAI,OAAA,CAAQ,KAAA;AAAA,cA4BF,WAAA,oBAAgC,GAAA,CAAI,iBAAA,EAC/C,GAAA,EAAK,QAAA,MAMG,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,QAAA,MAAY,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,QAAA;AAAA,cAa5C,SAAA,kBAA4B,GAAA,CAAI,eAAA,EAAiB,GAAA,EAAK,MAAA,MAKzD,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,MAAA,MAAU,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,MAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "@confect/core";
|
|
2
2
|
import { useAction as useAction$1, useMutation as useMutation$1, useQuery as useQuery$1 } from "convex/react";
|
|
3
|
-
import {
|
|
3
|
+
import { Match, Schema } from "effect";
|
|
4
4
|
|
|
5
5
|
//#region src/index.ts
|
|
6
6
|
const useQuery = (ref, args) => {
|
|
7
|
-
const
|
|
8
|
-
const encodedReturnsOrUndefined = useQuery$1(Ref.getConvexFunctionName(ref), Schema.encodeSync(
|
|
9
|
-
if (encodedReturnsOrUndefined === void 0) return
|
|
10
|
-
|
|
7
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
8
|
+
const encodedReturnsOrUndefined = useQuery$1(Ref.getConvexFunctionName(ref), Match.value(functionSpec.functionProvenance).pipe(Match.tag("Confect", (confect) => Schema.encodeSync(confect.args)(args)), Match.tag("Convex", () => args), Match.exhaustive));
|
|
9
|
+
if (encodedReturnsOrUndefined === void 0) return;
|
|
10
|
+
return Match.value(functionSpec.functionProvenance).pipe(Match.tag("Confect", (confect) => Schema.decodeSync(confect.returns)(encodedReturnsOrUndefined)), Match.tag("Convex", () => encodedReturnsOrUndefined), Match.exhaustive);
|
|
11
11
|
};
|
|
12
12
|
const useMutation = (ref) => {
|
|
13
|
-
const
|
|
13
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
14
14
|
const actualMutation = useMutation$1(Ref.getConvexFunctionName(ref));
|
|
15
|
-
return (args) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return yield* Schema.decode(function_.returns)(actualReturns);
|
|
19
|
-
}).pipe(Effect.orDie);
|
|
15
|
+
return (args) => Match.value(functionSpec.functionProvenance).pipe(Match.tag("Confect", (confect) => {
|
|
16
|
+
return actualMutation(Schema.encodeSync(confect.args)(args)).then((result) => Schema.decodeSync(confect.returns)(result));
|
|
17
|
+
}), Match.tag("Convex", () => actualMutation(args)), Match.exhaustive);
|
|
20
18
|
};
|
|
21
19
|
const useAction = (ref) => {
|
|
22
|
-
const
|
|
20
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
23
21
|
const actualAction = useAction$1(Ref.getConvexFunctionName(ref));
|
|
24
|
-
return (args) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return yield* Schema.decode(function_.returns)(actualReturns);
|
|
28
|
-
}).pipe(Effect.orDie);
|
|
22
|
+
return (args) => Match.value(functionSpec.functionProvenance).pipe(Match.tag("Confect", (confect) => {
|
|
23
|
+
return actualAction(Schema.encodeSync(confect.args)(args)).then((result) => Schema.decodeSync(confect.returns)(result));
|
|
24
|
+
}), Match.tag("Convex", () => actualAction(args)), Match.exhaustive);
|
|
29
25
|
};
|
|
30
26
|
|
|
31
27
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useConvexQuery","useConvexMutation","useConvexAction"],"sources":["../src/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.js","names":["useConvexQuery","useConvexMutation","useConvexAction"],"sources":["../src/index.ts"],"sourcesContent":["import { Ref } from \"@confect/core\";\nimport {\n useAction as useConvexAction,\n useMutation as useConvexMutation,\n useQuery as useConvexQuery,\n} from \"convex/react\";\nimport { Match, Schema } from \"effect\";\n\nexport const useQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n args: Ref.Args<Query>,\n): Ref.Returns<Query> | undefined => {\n const functionSpec = Ref.getFunctionSpec(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n\n const encodedArgs = Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confect) => Schema.encodeSync(confect.args)(args)),\n Match.tag(\"Convex\", () => args),\n Match.exhaustive,\n );\n\n const encodedReturnsOrUndefined = useConvexQuery(\n functionName as any,\n encodedArgs,\n );\n\n if (encodedReturnsOrUndefined === undefined) {\n return undefined;\n }\n\n return Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confect) =>\n Schema.decodeSync(confect.returns)(encodedReturnsOrUndefined),\n ),\n Match.tag(\"Convex\", () => encodedReturnsOrUndefined),\n Match.exhaustive,\n );\n};\n\nexport const useMutation = <Mutation extends Ref.AnyPublicMutation>(\n ref: Mutation,\n) => {\n const functionSpec = Ref.getFunctionSpec(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n const actualMutation = useConvexMutation(functionName as any);\n\n return (args: Ref.Args<Mutation>): Promise<Ref.Returns<Mutation>> =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confect) => {\n const encodedArgs = Schema.encodeSync(confect.args)(args);\n return actualMutation(encodedArgs).then((result) =>\n Schema.decodeSync(confect.returns)(result),\n );\n }),\n Match.tag(\"Convex\", () => actualMutation(args as any)),\n Match.exhaustive,\n );\n};\n\nexport const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {\n const functionSpec = Ref.getFunctionSpec(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n const actualAction = useConvexAction(functionName as any);\n\n return (args: Ref.Args<Action>): Promise<Ref.Returns<Action>> =>\n Match.value(functionSpec.functionProvenance).pipe(\n Match.tag(\"Confect\", (confect) => {\n const encodedArgs = Schema.encodeSync(confect.args)(args);\n return actualAction(encodedArgs).then((result) =>\n Schema.decodeSync(confect.returns)(result),\n );\n }),\n Match.tag(\"Convex\", () => actualAction(args as any)),\n Match.exhaustive,\n );\n};\n"],"mappings":";;;;;AAQA,MAAa,YACX,KACA,SACmC;CACnC,MAAM,eAAe,IAAI,gBAAgB,IAAI;CAS7C,MAAM,4BAA4BA,WARb,IAAI,sBAAsB,IAAI,EAE/B,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC/D,MAAM,IAAI,YAAY,YAAY,OAAO,WAAW,QAAQ,KAAK,CAAC,KAAK,CAAC,EACxE,MAAM,IAAI,gBAAgB,KAAK,EAC/B,MAAM,WACP,CAKA;AAED,KAAI,8BAA8B,OAChC;AAGF,QAAO,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAClD,MAAM,IAAI,YAAY,YACpB,OAAO,WAAW,QAAQ,QAAQ,CAAC,0BAA0B,CAC9D,EACD,MAAM,IAAI,gBAAgB,0BAA0B,EACpD,MAAM,WACP;;AAGH,MAAa,eACX,QACG;CACH,MAAM,eAAe,IAAI,gBAAgB,IAAI;CAE7C,MAAM,iBAAiBC,cADF,IAAI,sBAAsB,IAAI,CACU;AAE7D,SAAQ,SACN,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,YAAY,YAAY;AAEhC,SAAO,eADa,OAAO,WAAW,QAAQ,KAAK,CAAC,KAAK,CACvB,CAAC,MAAM,WACvC,OAAO,WAAW,QAAQ,QAAQ,CAAC,OAAO,CAC3C;GACD,EACF,MAAM,IAAI,gBAAgB,eAAe,KAAY,CAAC,EACtD,MAAM,WACP;;AAGL,MAAa,aAAiD,QAAgB;CAC5E,MAAM,eAAe,IAAI,gBAAgB,IAAI;CAE7C,MAAM,eAAeC,YADA,IAAI,sBAAsB,IAAI,CACM;AAEzD,SAAQ,SACN,MAAM,MAAM,aAAa,mBAAmB,CAAC,KAC3C,MAAM,IAAI,YAAY,YAAY;AAEhC,SAAO,aADa,OAAO,WAAW,QAAQ,KAAK,CAAC,KAAK,CACzB,CAAC,MAAM,WACrC,OAAO,WAAW,QAAQ,QAAQ,CAAC,OAAO,CAC3C;GACD,EACF,MAAM,IAAI,gBAAgB,aAAa,KAAY,CAAC,EACpD,MAAM,WACP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Client-side bindings for React apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,20 +35,19 @@
|
|
|
35
35
|
"author": "RJ Dellecese",
|
|
36
36
|
"license": "ISC",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@
|
|
40
|
-
"
|
|
41
|
-
"eslint": "9.39.2",
|
|
38
|
+
"@eslint/js": "10.0.1",
|
|
39
|
+
"@types/node": "25.3.3",
|
|
40
|
+
"eslint": "10.0.2",
|
|
42
41
|
"prettier": "3.8.1",
|
|
43
42
|
"tsdown": "0.20.3",
|
|
44
43
|
"typescript": "5.9.3",
|
|
45
|
-
"typescript-eslint": "8.
|
|
44
|
+
"typescript-eslint": "8.56.1"
|
|
46
45
|
},
|
|
47
46
|
"peerDependencies": {
|
|
48
47
|
"convex": "^1.30.0",
|
|
49
48
|
"effect": "^3.19.16",
|
|
50
49
|
"react": "^18.0.0 || ^19.0.0",
|
|
51
|
-
"@confect/core": "
|
|
50
|
+
"@confect/core": "3.0.0"
|
|
52
51
|
},
|
|
53
52
|
"engines": {
|
|
54
53
|
"node": ">=22",
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Ref } from "@confect/core";
|
|
2
2
|
import {
|
|
3
3
|
useAction as useConvexAction,
|
|
4
4
|
useMutation as useConvexMutation,
|
|
5
5
|
useQuery as useConvexQuery,
|
|
6
6
|
} from "convex/react";
|
|
7
|
-
import {
|
|
7
|
+
import { Match, Schema } from "effect";
|
|
8
8
|
|
|
9
9
|
export const useQuery = <Query extends Ref.AnyPublicQuery>(
|
|
10
10
|
ref: Query,
|
|
11
|
-
args: Ref.Args<Query
|
|
12
|
-
):
|
|
13
|
-
const
|
|
11
|
+
args: Ref.Args<Query>,
|
|
12
|
+
): Ref.Returns<Query> | undefined => {
|
|
13
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
14
14
|
const functionName = Ref.getConvexFunctionName(ref);
|
|
15
15
|
|
|
16
|
-
const encodedArgs =
|
|
16
|
+
const encodedArgs = Match.value(functionSpec.functionProvenance).pipe(
|
|
17
|
+
Match.tag("Confect", (confect) => Schema.encodeSync(confect.args)(args)),
|
|
18
|
+
Match.tag("Convex", () => args),
|
|
19
|
+
Match.exhaustive,
|
|
20
|
+
);
|
|
17
21
|
|
|
18
22
|
const encodedReturnsOrUndefined = useConvexQuery(
|
|
19
23
|
functionName as any,
|
|
@@ -21,50 +25,52 @@ export const useQuery = <Query extends Ref.AnyPublicQuery>(
|
|
|
21
25
|
);
|
|
22
26
|
|
|
23
27
|
if (encodedReturnsOrUndefined === undefined) {
|
|
24
|
-
return
|
|
25
|
-
} else {
|
|
26
|
-
return Option.some(
|
|
27
|
-
Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined),
|
|
28
|
-
);
|
|
28
|
+
return undefined;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
return Match.value(functionSpec.functionProvenance).pipe(
|
|
32
|
+
Match.tag("Confect", (confect) =>
|
|
33
|
+
Schema.decodeSync(confect.returns)(encodedReturnsOrUndefined),
|
|
34
|
+
),
|
|
35
|
+
Match.tag("Convex", () => encodedReturnsOrUndefined),
|
|
36
|
+
Match.exhaustive,
|
|
37
|
+
);
|
|
30
38
|
};
|
|
31
39
|
|
|
32
40
|
export const useMutation = <Mutation extends Ref.AnyPublicMutation>(
|
|
33
41
|
ref: Mutation,
|
|
34
42
|
) => {
|
|
35
|
-
const
|
|
43
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
36
44
|
const functionName = Ref.getConvexFunctionName(ref);
|
|
37
45
|
const actualMutation = useConvexMutation(functionName as any);
|
|
38
46
|
|
|
39
|
-
return (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}).pipe(Effect.orDie);
|
|
47
|
+
return (args: Ref.Args<Mutation>): Promise<Ref.Returns<Mutation>> =>
|
|
48
|
+
Match.value(functionSpec.functionProvenance).pipe(
|
|
49
|
+
Match.tag("Confect", (confect) => {
|
|
50
|
+
const encodedArgs = Schema.encodeSync(confect.args)(args);
|
|
51
|
+
return actualMutation(encodedArgs).then((result) =>
|
|
52
|
+
Schema.decodeSync(confect.returns)(result),
|
|
53
|
+
);
|
|
54
|
+
}),
|
|
55
|
+
Match.tag("Convex", () => actualMutation(args as any)),
|
|
56
|
+
Match.exhaustive,
|
|
57
|
+
);
|
|
51
58
|
};
|
|
52
59
|
|
|
53
60
|
export const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {
|
|
54
|
-
const
|
|
61
|
+
const functionSpec = Ref.getFunctionSpec(ref);
|
|
55
62
|
const functionName = Ref.getConvexFunctionName(ref);
|
|
56
63
|
const actualAction = useConvexAction(functionName as any);
|
|
57
64
|
|
|
58
|
-
return (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}).pipe(Effect.orDie);
|
|
65
|
+
return (args: Ref.Args<Action>): Promise<Ref.Returns<Action>> =>
|
|
66
|
+
Match.value(functionSpec.functionProvenance).pipe(
|
|
67
|
+
Match.tag("Confect", (confect) => {
|
|
68
|
+
const encodedArgs = Schema.encodeSync(confect.args)(args);
|
|
69
|
+
return actualAction(encodedArgs).then((result) =>
|
|
70
|
+
Schema.decodeSync(confect.returns)(result),
|
|
71
|
+
);
|
|
72
|
+
}),
|
|
73
|
+
Match.tag("Convex", () => actualAction(args as any)),
|
|
74
|
+
Match.exhaustive,
|
|
75
|
+
);
|
|
70
76
|
};
|