@confect/react 4.0.0 → 6.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 +22 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +36 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @confect/react
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- df95ce7: Add `Ref.OptionalArgs` type utility to `@confect/core` for conditionally optional function args. `QueryRunner`, `MutationRunner`, and `ActionRunner` now accept optional args for no-arg Confect functions. `useQuery`, `useMutation`, and `useAction` now accept optional args for no-arg Confect functions. `TestConfect` `query`/`mutation`/`action` helpers now accept optional args for no-arg Confect functions.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [df95ce7]
|
|
12
|
+
- Updated dependencies [a8083e8]
|
|
13
|
+
- @confect/core@6.0.0
|
|
14
|
+
|
|
15
|
+
## 5.0.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 5ddb437: Support passing `"skip"` as args to `useQuery` to disable query subscription.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- @confect/core@5.0.0
|
|
24
|
+
|
|
3
25
|
## 4.0.0
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Ref } from "@confect/core";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
|
-
|
|
5
|
-
declare const
|
|
6
|
-
declare const
|
|
4
|
+
type UseQueryArgs<Query extends Ref.AnyPublicQuery> = keyof Ref.Args<Query> extends never ? [args?: Ref.Args<Query> | "skip"] : [args: Ref.Args<Query> | "skip"];
|
|
5
|
+
declare const useQuery: <Query extends Ref.AnyPublicQuery>(ref: Query, ...rest: UseQueryArgs<Query>) => Ref.Returns<Query> | undefined;
|
|
6
|
+
declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (...args: Ref.OptionalArgs<Mutation>) => Promise<Ref.Returns<Mutation>>;
|
|
7
|
+
declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (...args: Ref.OptionalArgs<Action>) => Promise<Ref.Returns<Action>>;
|
|
7
8
|
//#endregion
|
|
8
9
|
export { useAction, useMutation, useQuery };
|
|
9
10
|
//# 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":";;;KAOK,YAAA,eAA2B,GAAA,CAAI,cAAA,UAC5B,GAAA,CAAI,IAAA,CAAK,KAAA,mBACV,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,KAAA,eAChB,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,KAAA;AAAA,cAET,QAAA,iBAA0B,GAAA,CAAI,cAAA,EACzC,GAAA,EAAK,KAAA,KACF,IAAA,EAAM,YAAA,CAAa,KAAA,MACrB,GAAA,CAAI,OAAA,CAAQ,KAAA;AAAA,cAoBF,WAAA,oBAAgC,GAAA,CAAI,iBAAA,EAC/C,GAAA,EAAK,QAAA,SAMA,IAAA,EAAM,GAAA,CAAI,YAAA,CAAa,QAAA,MACzB,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,QAAA;AAAA,cAWZ,SAAA,kBAA4B,GAAA,CAAI,eAAA,EAAiB,GAAA,EAAK,MAAA,SAItD,IAAA,EAAM,GAAA,CAAI,YAAA,CAAa,MAAA,MAAU,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,MAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
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 { Match, Schema } from "effect";
|
|
4
3
|
|
|
5
4
|
//#region src/index.ts
|
|
6
|
-
const useQuery = (ref,
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const useQuery = (ref, ...rest) => {
|
|
6
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
7
|
+
const args = rest[0];
|
|
8
|
+
const encodedReturnsOrUndefined = useQuery$1(functionReference, args === "skip" ? "skip" : Ref.encodeArgsSync(ref, args ?? {}));
|
|
9
9
|
if (encodedReturnsOrUndefined === void 0) return;
|
|
10
|
-
return
|
|
10
|
+
return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);
|
|
11
11
|
};
|
|
12
12
|
const useMutation = (ref) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}), Match.tag("Convex", () => actualMutation(args)), Match.exhaustive);
|
|
13
|
+
const actualMutation = useMutation$1(Ref.getFunctionReference(ref));
|
|
14
|
+
return (...args) => {
|
|
15
|
+
return actualMutation(Ref.encodeArgsSync(ref, args[0] ?? {})).then((result) => Ref.decodeReturnsSync(ref, result));
|
|
16
|
+
};
|
|
18
17
|
};
|
|
19
18
|
const useAction = (ref) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}), Match.tag("Convex", () => actualAction(args)), Match.exhaustive);
|
|
19
|
+
const actualAction = useAction$1(Ref.getFunctionReference(ref));
|
|
20
|
+
return (...args) => {
|
|
21
|
+
return actualAction(Ref.encodeArgsSync(ref, args[0] ?? {})).then((result) => Ref.decodeReturnsSync(ref, result));
|
|
22
|
+
};
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
//#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 { Ref } from \"@confect/core\";\nimport {\n useAction as useConvexAction,\n useMutation as useConvexMutation,\n useQuery as useConvexQuery,\n} from \"convex/react\";\
|
|
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\";\n\ntype UseQueryArgs<Query extends Ref.AnyPublicQuery> =\n keyof Ref.Args<Query> extends never\n ? [args?: Ref.Args<Query> | \"skip\"]\n : [args: Ref.Args<Query> | \"skip\"];\n\nexport const useQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n ...rest: UseQueryArgs<Query>\n): Ref.Returns<Query> | undefined => {\n const functionReference = Ref.getFunctionReference(ref);\n const args = rest[0];\n const encodedArgs =\n args === \"skip\"\n ? \"skip\"\n : Ref.encodeArgsSync(ref, (args ?? {}) as Ref.Args<Query>);\n\n const encodedReturnsOrUndefined = useConvexQuery(\n functionReference,\n encodedArgs,\n );\n\n if (encodedReturnsOrUndefined === undefined) {\n return undefined;\n }\n\n return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);\n};\n\nexport const useMutation = <Mutation extends Ref.AnyPublicMutation>(\n ref: Mutation,\n) => {\n const functionReference = Ref.getFunctionReference(ref);\n const actualMutation = useConvexMutation(functionReference);\n\n return (\n ...args: Ref.OptionalArgs<Mutation>\n ): Promise<Ref.Returns<Mutation>> => {\n const encodedArgs = Ref.encodeArgsSync(\n ref,\n (args[0] ?? {}) as Ref.Args<Mutation>,\n );\n return actualMutation(encodedArgs).then((result) =>\n Ref.decodeReturnsSync(ref, result),\n );\n };\n};\n\nexport const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {\n const functionReference = Ref.getFunctionReference(ref);\n const actualAction = useConvexAction(functionReference);\n\n return (...args: Ref.OptionalArgs<Action>): Promise<Ref.Returns<Action>> => {\n const encodedArgs = Ref.encodeArgsSync(\n ref,\n (args[0] ?? {}) as Ref.Args<Action>,\n );\n return actualAction(encodedArgs).then((result) =>\n Ref.decodeReturnsSync(ref, result),\n );\n };\n};\n"],"mappings":";;;;AAYA,MAAa,YACX,KACA,GAAG,SACgC;CACnC,MAAM,oBAAoB,IAAI,qBAAqB,IAAI;CACvD,MAAM,OAAO,KAAK;CAMlB,MAAM,4BAA4BA,WAChC,mBALA,SAAS,SACL,SACA,IAAI,eAAe,KAAM,QAAQ,EAAE,CAAqB,CAK7D;AAED,KAAI,8BAA8B,OAChC;AAGF,QAAO,IAAI,kBAAkB,KAAK,0BAA0B;;AAG9D,MAAa,eACX,QACG;CAEH,MAAM,iBAAiBC,cADG,IAAI,qBAAqB,IAAI,CACI;AAE3D,SACE,GAAG,SACgC;AAKnC,SAAO,eAJa,IAAI,eACtB,KACC,KAAK,MAAM,EAAE,CACf,CACiC,CAAC,MAAM,WACvC,IAAI,kBAAkB,KAAK,OAAO,CACnC;;;AAIL,MAAa,aAAiD,QAAgB;CAE5E,MAAM,eAAeC,YADK,IAAI,qBAAqB,IAAI,CACA;AAEvD,SAAQ,GAAG,SAAiE;AAK1E,SAAO,aAJa,IAAI,eACtB,KACC,KAAK,MAAM,EAAE,CACf,CAC+B,CAAC,MAAM,WACrC,IAAI,kBAAkB,KAAK,OAAO,CACnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@confect/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Client-side bindings for React apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"convex": "^1.30.0",
|
|
48
48
|
"effect": "^3.19.16",
|
|
49
49
|
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
-
"@confect/core": "
|
|
50
|
+
"@confect/core": "6.0.0"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=22",
|
package/src/index.ts
CHANGED
|
@@ -4,23 +4,25 @@ import {
|
|
|
4
4
|
useMutation as useConvexMutation,
|
|
5
5
|
useQuery as useConvexQuery,
|
|
6
6
|
} from "convex/react";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
type UseQueryArgs<Query extends Ref.AnyPublicQuery> =
|
|
9
|
+
keyof Ref.Args<Query> extends never
|
|
10
|
+
? [args?: Ref.Args<Query> | "skip"]
|
|
11
|
+
: [args: Ref.Args<Query> | "skip"];
|
|
8
12
|
|
|
9
13
|
export const useQuery = <Query extends Ref.AnyPublicQuery>(
|
|
10
14
|
ref: Query,
|
|
11
|
-
|
|
15
|
+
...rest: UseQueryArgs<Query>
|
|
12
16
|
): Ref.Returns<Query> | undefined => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Match.exhaustive,
|
|
20
|
-
);
|
|
17
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
18
|
+
const args = rest[0];
|
|
19
|
+
const encodedArgs =
|
|
20
|
+
args === "skip"
|
|
21
|
+
? "skip"
|
|
22
|
+
: Ref.encodeArgsSync(ref, (args ?? {}) as Ref.Args<Query>);
|
|
21
23
|
|
|
22
24
|
const encodedReturnsOrUndefined = useConvexQuery(
|
|
23
|
-
|
|
25
|
+
functionReference,
|
|
24
26
|
encodedArgs,
|
|
25
27
|
);
|
|
26
28
|
|
|
@@ -28,49 +30,39 @@ export const useQuery = <Query extends Ref.AnyPublicQuery>(
|
|
|
28
30
|
return undefined;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
return
|
|
32
|
-
Match.tag("Confect", (confect) =>
|
|
33
|
-
Schema.decodeSync(confect.returns)(encodedReturnsOrUndefined),
|
|
34
|
-
),
|
|
35
|
-
Match.tag("Convex", () => encodedReturnsOrUndefined),
|
|
36
|
-
Match.exhaustive,
|
|
37
|
-
);
|
|
33
|
+
return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
export const useMutation = <Mutation extends Ref.AnyPublicMutation>(
|
|
41
37
|
ref: Mutation,
|
|
42
38
|
) => {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const actualMutation = useConvexMutation(functionName as any);
|
|
39
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
40
|
+
const actualMutation = useConvexMutation(functionReference);
|
|
46
41
|
|
|
47
|
-
return (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
Match.exhaustive,
|
|
42
|
+
return (
|
|
43
|
+
...args: Ref.OptionalArgs<Mutation>
|
|
44
|
+
): Promise<Ref.Returns<Mutation>> => {
|
|
45
|
+
const encodedArgs = Ref.encodeArgsSync(
|
|
46
|
+
ref,
|
|
47
|
+
(args[0] ?? {}) as Ref.Args<Mutation>,
|
|
48
|
+
);
|
|
49
|
+
return actualMutation(encodedArgs).then((result) =>
|
|
50
|
+
Ref.decodeReturnsSync(ref, result),
|
|
57
51
|
);
|
|
52
|
+
};
|
|
58
53
|
};
|
|
59
54
|
|
|
60
55
|
export const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const actualAction = useConvexAction(functionName as any);
|
|
56
|
+
const functionReference = Ref.getFunctionReference(ref);
|
|
57
|
+
const actualAction = useConvexAction(functionReference);
|
|
64
58
|
|
|
65
|
-
return (args: Ref.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
73
|
-
Match.tag("Convex", () => actualAction(args as any)),
|
|
74
|
-
Match.exhaustive,
|
|
59
|
+
return (...args: Ref.OptionalArgs<Action>): Promise<Ref.Returns<Action>> => {
|
|
60
|
+
const encodedArgs = Ref.encodeArgsSync(
|
|
61
|
+
ref,
|
|
62
|
+
(args[0] ?? {}) as Ref.Args<Action>,
|
|
63
|
+
);
|
|
64
|
+
return actualAction(encodedArgs).then((result) =>
|
|
65
|
+
Ref.decodeReturnsSync(ref, result),
|
|
75
66
|
);
|
|
67
|
+
};
|
|
76
68
|
};
|