@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 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
- 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>>;
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
@@ -1 +1 @@
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"}
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, args) => {
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));
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 Match.value(functionSpec.functionProvenance).pipe(Match.tag("Confect", (confect) => Schema.decodeSync(confect.returns)(encodedReturnsOrUndefined)), Match.tag("Convex", () => encodedReturnsOrUndefined), Match.exhaustive);
10
+ return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);
11
11
  };
12
12
  const useMutation = (ref) => {
13
- const functionSpec = Ref.getFunctionSpec(ref);
14
- const actualMutation = useMutation$1(Ref.getConvexFunctionName(ref));
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);
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 functionSpec = Ref.getFunctionSpec(ref);
21
- const actualAction = useAction$1(Ref.getConvexFunctionName(ref));
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);
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\";\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"}
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": "4.0.0",
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": "4.0.0"
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
- import { Match, Schema } from "effect";
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
- args: Ref.Args<Query>,
15
+ ...rest: UseQueryArgs<Query>
12
16
  ): Ref.Returns<Query> | undefined => {
13
- const functionSpec = Ref.getFunctionSpec(ref);
14
- const functionName = Ref.getConvexFunctionName(ref);
15
-
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
+ 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
- functionName as any,
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 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
- );
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 functionSpec = Ref.getFunctionSpec(ref);
44
- const functionName = Ref.getConvexFunctionName(ref);
45
- const actualMutation = useConvexMutation(functionName as any);
39
+ const functionReference = Ref.getFunctionReference(ref);
40
+ const actualMutation = useConvexMutation(functionReference);
46
41
 
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,
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 functionSpec = Ref.getFunctionSpec(ref);
62
- const functionName = Ref.getConvexFunctionName(ref);
63
- const actualAction = useConvexAction(functionName as any);
56
+ const functionReference = Ref.getFunctionReference(ref);
57
+ const actualAction = useConvexAction(functionReference);
64
58
 
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,
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
  };