@confect/react 4.0.0 → 5.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,15 @@
1
1
  # @confect/react
2
2
 
3
+ ## 5.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5ddb437: Support passing `"skip"` as args to `useQuery` to disable query subscription.
8
+
9
+ ### Patch Changes
10
+
11
+ - @confect/core@5.0.0
12
+
3
13
  ## 4.0.0
4
14
 
5
15
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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;
4
+ declare const useQuery: <Query extends Ref.AnyPublicQuery>(ref: Query, args: Ref.Args<Query> | "skip") => Ref.Returns<Query> | undefined;
5
5
  declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (args: Ref.Args<Mutation>) => Promise<Ref.Returns<Mutation>>;
6
6
  declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (args: Ref.Args<Action>) => Promise<Ref.Returns<Action>>;
7
7
  //#endregion
@@ -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":";;;cAOa,QAAA,iBAA0B,GAAA,CAAI,cAAA,EACzC,GAAA,EAAK,KAAA,EACL,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,KAAA,eACd,GAAA,CAAI,OAAA,CAAQ,KAAA;AAAA,cAgBF,WAAA,oBAAgC,GAAA,CAAI,iBAAA,EAC/C,GAAA,EAAK,QAAA,MAKG,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,QAAA,MAAY,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,QAAA;AAAA,cAQ5C,SAAA,kBAA4B,GAAA,CAAI,eAAA,EAAiB,GAAA,EAAK,MAAA,MAIzD,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,MAAA,MAAU,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,MAAA"}
package/dist/index.js CHANGED
@@ -1,27 +1,23 @@
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
5
  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));
6
+ const encodedReturnsOrUndefined = useQuery$1(Ref.getFunctionReference(ref), args === "skip" ? "skip" : Ref.encodeArgsSync(ref, args));
9
7
  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);
8
+ return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);
11
9
  };
12
10
  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);
11
+ const actualMutation = useMutation$1(Ref.getFunctionReference(ref));
12
+ return (args) => {
13
+ return actualMutation(Ref.encodeArgsSync(ref, args)).then((result) => Ref.decodeReturnsSync(ref, result));
14
+ };
18
15
  };
19
16
  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);
17
+ const actualAction = useAction$1(Ref.getFunctionReference(ref));
18
+ return (args) => {
19
+ return actualAction(Ref.encodeArgsSync(ref, args)).then((result) => Ref.decodeReturnsSync(ref, result));
20
+ };
25
21
  };
26
22
 
27
23
  //#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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AI,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\nexport const useQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n args: Ref.Args<Query> | \"skip\",\n): Ref.Returns<Query> | undefined => {\n const functionReference = Ref.getFunctionReference(ref);\n const encodedArgs = args === \"skip\" ? \"skip\" : Ref.encodeArgsSync(ref, args);\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 (args: Ref.Args<Mutation>): Promise<Ref.Returns<Mutation>> => {\n const encodedArgs = Ref.encodeArgsSync(ref, args);\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.Args<Action>): Promise<Ref.Returns<Action>> => {\n const encodedArgs = Ref.encodeArgsSync(ref, args);\n return actualAction(encodedArgs).then((result) =>\n Ref.decodeReturnsSync(ref, result),\n );\n };\n};\n"],"mappings":";;;;AAOA,MAAa,YACX,KACA,SACmC;CAInC,MAAM,4BAA4BA,WAHR,IAAI,qBAAqB,IAAI,EACnC,SAAS,SAAS,SAAS,IAAI,eAAe,KAAK,KAAK,CAK3E;AAED,KAAI,8BAA8B,OAChC;AAGF,QAAO,IAAI,kBAAkB,KAAK,0BAA0B;;AAG9D,MAAa,eACX,QACG;CAEH,MAAM,iBAAiBC,cADG,IAAI,qBAAqB,IAAI,CACI;AAE3D,SAAQ,SAA6D;AAEnE,SAAO,eADa,IAAI,eAAe,KAAK,KAAK,CACf,CAAC,MAAM,WACvC,IAAI,kBAAkB,KAAK,OAAO,CACnC;;;AAIL,MAAa,aAAiD,QAAgB;CAE5E,MAAM,eAAeC,YADK,IAAI,qBAAqB,IAAI,CACA;AAEvD,SAAQ,SAAyD;AAE/D,SAAO,aADa,IAAI,eAAe,KAAK,KAAK,CACjB,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": "5.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": "5.0.0"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22",
package/src/index.ts CHANGED
@@ -4,23 +4,16 @@ import {
4
4
  useMutation as useConvexMutation,
5
5
  useQuery as useConvexQuery,
6
6
  } from "convex/react";
7
- import { Match, Schema } from "effect";
8
7
 
9
8
  export const useQuery = <Query extends Ref.AnyPublicQuery>(
10
9
  ref: Query,
11
- args: Ref.Args<Query>,
10
+ args: Ref.Args<Query> | "skip",
12
11
  ): 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
- );
12
+ const functionReference = Ref.getFunctionReference(ref);
13
+ const encodedArgs = args === "skip" ? "skip" : Ref.encodeArgsSync(ref, args);
21
14
 
22
15
  const encodedReturnsOrUndefined = useConvexQuery(
23
- functionName as any,
16
+ functionReference,
24
17
  encodedArgs,
25
18
  );
26
19
 
@@ -28,49 +21,31 @@ export const useQuery = <Query extends Ref.AnyPublicQuery>(
28
21
  return undefined;
29
22
  }
30
23
 
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
- );
24
+ return Ref.decodeReturnsSync(ref, encodedReturnsOrUndefined);
38
25
  };
39
26
 
40
27
  export const useMutation = <Mutation extends Ref.AnyPublicMutation>(
41
28
  ref: Mutation,
42
29
  ) => {
43
- const functionSpec = Ref.getFunctionSpec(ref);
44
- const functionName = Ref.getConvexFunctionName(ref);
45
- const actualMutation = useConvexMutation(functionName as any);
30
+ const functionReference = Ref.getFunctionReference(ref);
31
+ const actualMutation = useConvexMutation(functionReference);
46
32
 
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,
33
+ return (args: Ref.Args<Mutation>): Promise<Ref.Returns<Mutation>> => {
34
+ const encodedArgs = Ref.encodeArgsSync(ref, args);
35
+ return actualMutation(encodedArgs).then((result) =>
36
+ Ref.decodeReturnsSync(ref, result),
57
37
  );
38
+ };
58
39
  };
59
40
 
60
41
  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);
42
+ const functionReference = Ref.getFunctionReference(ref);
43
+ const actualAction = useConvexAction(functionReference);
64
44
 
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,
45
+ return (args: Ref.Args<Action>): Promise<Ref.Returns<Action>> => {
46
+ const encodedArgs = Ref.encodeArgsSync(ref, args);
47
+ return actualAction(encodedArgs).then((result) =>
48
+ Ref.decodeReturnsSync(ref, result),
75
49
  );
50
+ };
76
51
  };