@confect/react 2.0.0 → 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 CHANGED
@@ -1,5 +1,16 @@
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
+
3
14
  ## 2.0.0
4
15
 
5
16
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
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>["Type"]) => Ref.Returns<Query>["Type"] | undefined;
5
- declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (args: Ref.Args<Mutation>["Type"]) => Promise<Ref.Returns<Mutation>["Type"]>;
6
- declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (args: Ref.Args<Action>["Type"]) => Promise<Ref.Returns<Action>["Type"]>;
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>>;
7
7
  //#endregion
8
8
  export { useAction, useMutation, useQuery };
9
9
  //# 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,cACd,GAAA,CAAI,OAAA,CAAQ,KAAA;AAAA,cAkBF,WAAA,oBAAgC,GAAA,CAAI,iBAAA,EAC/C,GAAA,EAAK,QAAA,MAOH,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,QAAA,cACd,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,QAAA;AAAA,cAOZ,SAAA,kBAA4B,GAAA,CAAI,eAAA,EAAiB,GAAA,EAAK,MAAA,MAM/D,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,MAAA,cACd,OAAA,CAAQ,GAAA,CAAI,OAAA,CAAQ,MAAA"}
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,29 +1,27 @@
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 { Schema } from "effect";
3
+ import { Match, Schema } from "effect";
4
4
 
5
5
  //#region src/index.ts
6
6
  const useQuery = (ref, args) => {
7
- const function_ = Ref.getFunction(ref);
8
- const encodedReturnsOrUndefined = useQuery$1(Ref.getConvexFunctionName(ref), Schema.encodeSync(function_.args)(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));
9
9
  if (encodedReturnsOrUndefined === void 0) return;
10
- else return Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined);
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 function_ = Ref.getFunction(ref);
13
+ const functionSpec = Ref.getFunctionSpec(ref);
14
14
  const actualMutation = useMutation$1(Ref.getConvexFunctionName(ref));
15
- return async (args) => {
16
- const actualReturns = await actualMutation(Schema.encodeSync(function_.args)(args));
17
- return Schema.decodeSync(function_.returns)(actualReturns);
18
- };
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);
19
18
  };
20
19
  const useAction = (ref) => {
21
- const function_ = Ref.getFunction(ref);
20
+ const functionSpec = Ref.getFunctionSpec(ref);
22
21
  const actualAction = useAction$1(Ref.getConvexFunctionName(ref));
23
- return async (args) => {
24
- const actualReturns = await actualAction(Schema.encodeSync(function_.args)(args));
25
- return Schema.decodeSync(function_.returns)(actualReturns);
26
- };
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);
27
25
  };
28
26
 
29
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 { Ref } from \"@confect/core\";\nimport {\n useAction as useConvexAction,\n useMutation as useConvexMutation,\n useQuery as useConvexQuery,\n} from \"convex/react\";\nimport { Schema } from \"effect\";\n\nexport const useQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n args: Ref.Args<Query>[\"Type\"],\n): Ref.Returns<Query>[\"Type\"] | undefined => {\n const function_ = Ref.getFunction(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n\n const encodedArgs = Schema.encodeSync(function_.args)(args);\n\n const encodedReturnsOrUndefined = useConvexQuery(\n functionName as any,\n encodedArgs,\n );\n\n if (encodedReturnsOrUndefined === undefined) {\n return undefined;\n } else {\n return Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined);\n }\n};\n\nexport const useMutation = <Mutation extends Ref.AnyPublicMutation>(\n ref: Mutation,\n) => {\n const function_ = Ref.getFunction(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n const actualMutation = useConvexMutation(functionName as any);\n\n return async (\n args: Ref.Args<Mutation>[\"Type\"],\n ): Promise<Ref.Returns<Mutation>[\"Type\"]> => {\n const encodedArgs = Schema.encodeSync(function_.args)(args);\n const actualReturns = await actualMutation(encodedArgs);\n return Schema.decodeSync(function_.returns)(actualReturns);\n };\n};\n\nexport const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {\n const function_ = Ref.getFunction(ref);\n const functionName = Ref.getConvexFunctionName(ref);\n const actualAction = useConvexAction(functionName as any);\n\n return async (\n args: Ref.Args<Action>[\"Type\"],\n ): Promise<Ref.Returns<Action>[\"Type\"]> => {\n const encodedArgs = Schema.encodeSync(function_.args)(args);\n const actualReturns = await actualAction(encodedArgs);\n return Schema.decodeSync(function_.returns)(actualReturns);\n };\n};\n"],"mappings":";;;;;AAQA,MAAa,YACX,KACA,SAC2C;CAC3C,MAAM,YAAY,IAAI,YAAY,IAAI;CAKtC,MAAM,4BAA4BA,WAJb,IAAI,sBAAsB,IAAI,EAE/B,OAAO,WAAW,UAAU,KAAK,CAAC,KAAK,CAK1D;AAED,KAAI,8BAA8B,OAChC;KAEA,QAAO,OAAO,WAAW,UAAU,QAAQ,CAAC,0BAA0B;;AAI1E,MAAa,eACX,QACG;CACH,MAAM,YAAY,IAAI,YAAY,IAAI;CAEtC,MAAM,iBAAiBC,cADF,IAAI,sBAAsB,IAAI,CACU;AAE7D,QAAO,OACL,SAC2C;EAE3C,MAAM,gBAAgB,MAAM,eADR,OAAO,WAAW,UAAU,KAAK,CAAC,KAAK,CACJ;AACvD,SAAO,OAAO,WAAW,UAAU,QAAQ,CAAC,cAAc;;;AAI9D,MAAa,aAAiD,QAAgB;CAC5E,MAAM,YAAY,IAAI,YAAY,IAAI;CAEtC,MAAM,eAAeC,YADA,IAAI,sBAAsB,IAAI,CACM;AAEzD,QAAO,OACL,SACyC;EAEzC,MAAM,gBAAgB,MAAM,aADR,OAAO,WAAW,UAAU,KAAK,CAAC,KAAK,CACN;AACrD,SAAO,OAAO,WAAW,UAAU,QAAQ,CAAC,cAAc"}
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,gBAA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,6 @@
1
1
  {
2
2
  "name": "@confect/react",
3
- "version": "2.0.0",
3
+ "version": "3.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": "2.0.0"
50
+ "@confect/core": "3.0.0"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22",
package/src/index.ts CHANGED
@@ -4,16 +4,20 @@ import {
4
4
  useMutation as useConvexMutation,
5
5
  useQuery as useConvexQuery,
6
6
  } from "convex/react";
7
- import { Schema } from "effect";
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>["Type"],
12
- ): Ref.Returns<Query>["Type"] | undefined => {
13
- const function_ = Ref.getFunction(ref);
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 = Schema.encodeSync(function_.args)(args);
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,
@@ -22,37 +26,51 @@ export const useQuery = <Query extends Ref.AnyPublicQuery>(
22
26
 
23
27
  if (encodedReturnsOrUndefined === undefined) {
24
28
  return undefined;
25
- } else {
26
- return Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined);
27
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
+ );
28
38
  };
29
39
 
30
40
  export const useMutation = <Mutation extends Ref.AnyPublicMutation>(
31
41
  ref: Mutation,
32
42
  ) => {
33
- const function_ = Ref.getFunction(ref);
43
+ const functionSpec = Ref.getFunctionSpec(ref);
34
44
  const functionName = Ref.getConvexFunctionName(ref);
35
45
  const actualMutation = useConvexMutation(functionName as any);
36
46
 
37
- return async (
38
- args: Ref.Args<Mutation>["Type"],
39
- ): Promise<Ref.Returns<Mutation>["Type"]> => {
40
- const encodedArgs = Schema.encodeSync(function_.args)(args);
41
- const actualReturns = await actualMutation(encodedArgs);
42
- return Schema.decodeSync(function_.returns)(actualReturns);
43
- };
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
+ );
44
58
  };
45
59
 
46
60
  export const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {
47
- const function_ = Ref.getFunction(ref);
61
+ const functionSpec = Ref.getFunctionSpec(ref);
48
62
  const functionName = Ref.getConvexFunctionName(ref);
49
63
  const actualAction = useConvexAction(functionName as any);
50
64
 
51
- return async (
52
- args: Ref.Args<Action>["Type"],
53
- ): Promise<Ref.Returns<Action>["Type"]> => {
54
- const encodedArgs = Schema.encodeSync(function_.args)(args);
55
- const actualReturns = await actualAction(encodedArgs);
56
- return Schema.decodeSync(function_.returns)(actualReturns);
57
- };
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
+ );
58
76
  };