@confect/react 1.0.0-next.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 ADDED
@@ -0,0 +1,12 @@
1
+ # @confect/react
2
+
3
+ ## 1.0.0-next.0
4
+
5
+ ### Major Changes
6
+
7
+ - 2ff70a7: Initial release.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [2ff70a7]
12
+ - @confect/core@1.0.0-next.0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ ISC License
2
+
3
+ Copyright 2024 RJ Dellecese
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,10 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import { Effect, Option } from "effect";
3
+
4
+ //#region src/index.d.ts
5
+ declare const useQuery: <Query extends Ref.AnyPublicQuery>(ref: Query, args: Ref.Args<Query>["Type"]) => Option.Option<Ref.Returns<Query>["Type"]>;
6
+ declare const useMutation: <Mutation extends Ref.AnyPublicMutation>(ref: Mutation) => (args: Ref.Args<Mutation>["Type"]) => Effect.Effect<Ref.Returns<Mutation>["Type"]>;
7
+ declare const useAction: <Action extends Ref.AnyPublicAction>(ref: Action) => (args: Ref.Args<Action>["Type"]) => Effect.Effect<Ref.Returns<Action>["Type"]>;
8
+ //#endregion
9
+ export { useAction, useMutation, useQuery };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;cAQa,yBAA0B,GAAA,CAAI,qBACpC,aACC,GAAA,CAAI,KAAK,mBACd,MAAA,CAAO,OAAO,GAAA,CAAI,QAAQ;cAoBhB,+BAAgC,GAAA,CAAI,wBAC1C,oBAOG,GAAA,CAAI,KAAK,sBACd,MAAA,CAAO,OAAO,GAAA,CAAI,QAAQ;AAhClB,cA4CA,SAvBZ,EAAA,CAAA,eAuBwC,GAAA,CAAI,eAvB5C,CAAA,CAAA,GAAA,EAuBkE,MAvBlE,EAAA,GAAA,CAAA,IAAA,EA6BS,GAAA,CAAI,IA7Bb,CA6BkB,MA7BlB,CAAA,CAAA,MAAA,CAAA,EAAA,GA8BI,MAAA,CAAO,MA9BX,CA8BkB,GAAA,CAAI,OA9BtB,CA8B8B,MA9B9B,CAAA,CAAA,MAAA,CAAA,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import { useAction as useAction$1, useMutation as useMutation$1, useQuery as useQuery$1 } from "convex/react";
3
+ import { Effect, Option, Schema } from "effect";
4
+
5
+ //#region src/index.ts
6
+ const useQuery = (ref, args) => {
7
+ const function_ = Ref.getFunction(ref);
8
+ const encodedReturnsOrUndefined = useQuery$1(Ref.getConvexFunctionName(ref), Schema.encodeSync(function_.args)(args));
9
+ if (encodedReturnsOrUndefined === void 0) return Option.none();
10
+ else return Option.some(Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined));
11
+ };
12
+ const useMutation = (ref) => {
13
+ const function_ = Ref.getFunction(ref);
14
+ const actualMutation = useMutation$1(Ref.getConvexFunctionName(ref));
15
+ return (args) => Effect.gen(function* () {
16
+ const encodedArgs = yield* Schema.encode(function_.args)(args);
17
+ const actualReturns = yield* Effect.promise(() => actualMutation(encodedArgs));
18
+ return yield* Schema.decode(function_.returns)(actualReturns);
19
+ }).pipe(Effect.orDie);
20
+ };
21
+ const useAction = (ref) => {
22
+ const function_ = Ref.getFunction(ref);
23
+ const actualAction = useAction$1(Ref.getConvexFunctionName(ref));
24
+ return (args) => Effect.gen(function* () {
25
+ const encodedArgs = yield* Schema.encode(function_.args)(args);
26
+ const actualReturns = yield* Effect.promise(() => actualAction(encodedArgs));
27
+ return yield* Schema.decode(function_.returns)(actualReturns);
28
+ }).pipe(Effect.orDie);
29
+ };
30
+
31
+ //#endregion
32
+ export { useAction, useMutation, useQuery };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["useConvexQuery","useConvexMutation","useConvexAction"],"sources":["../src/index.ts"],"sourcesContent":["import * as Ref from \"@confect/core/Ref\";\nimport {\n useAction as useConvexAction,\n useMutation as useConvexMutation,\n useQuery as useConvexQuery,\n} from \"convex/react\";\nimport { Effect, Option, Schema } from \"effect\";\n\nexport const useQuery = <Query extends Ref.AnyPublicQuery>(\n ref: Query,\n args: Ref.Args<Query>[\"Type\"],\n): Option.Option<Ref.Returns<Query>[\"Type\"]> => {\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 Option.none();\n } else {\n return Option.some(\n Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined),\n );\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 (\n args: Ref.Args<Mutation>[\"Type\"],\n ): Effect.Effect<Ref.Returns<Mutation>[\"Type\"]> =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(function_.args)(args);\n\n const actualReturns = yield* Effect.promise(() =>\n actualMutation(encodedArgs),\n );\n\n return yield* Schema.decode(function_.returns)(actualReturns);\n }).pipe(Effect.orDie);\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 (\n args: Ref.Args<Action>[\"Type\"],\n ): Effect.Effect<Ref.Returns<Action>[\"Type\"]> =>\n Effect.gen(function* () {\n const encodedArgs = yield* Schema.encode(function_.args)(args);\n\n const actualReturns = yield* Effect.promise(() =>\n actualAction(encodedArgs),\n );\n\n return yield* Schema.decode(function_.returns)(actualReturns);\n }).pipe(Effect.orDie);\n};\n"],"mappings":";;;;;AAQA,MAAa,YACX,KACA,SAC8C;CAC9C,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,QAAO,OAAO,MAAM;KAEpB,QAAO,OAAO,KACZ,OAAO,WAAW,UAAU,QAAQ,CAAC,0BAA0B,CAChE;;AAIL,MAAa,eACX,QACG;CACH,MAAM,YAAY,IAAI,YAAY,IAAI;CAEtC,MAAM,iBAAiBC,cADF,IAAI,sBAAsB,IAAI,CACU;AAE7D,SACE,SAEA,OAAO,IAAI,aAAa;EACtB,MAAM,cAAc,OAAO,OAAO,OAAO,UAAU,KAAK,CAAC,KAAK;EAE9D,MAAM,gBAAgB,OAAO,OAAO,cAClC,eAAe,YAAY,CAC5B;AAED,SAAO,OAAO,OAAO,OAAO,UAAU,QAAQ,CAAC,cAAc;GAC7D,CAAC,KAAK,OAAO,MAAM;;AAGzB,MAAa,aAAiD,QAAgB;CAC5E,MAAM,YAAY,IAAI,YAAY,IAAI;CAEtC,MAAM,eAAeC,YADA,IAAI,sBAAsB,IAAI,CACM;AAEzD,SACE,SAEA,OAAO,IAAI,aAAa;EACtB,MAAM,cAAc,OAAO,OAAO,OAAO,UAAU,KAAK,CAAC,KAAK;EAE9D,MAAM,gBAAgB,OAAO,OAAO,cAClC,aAAa,YAAY,CAC1B;AAED,SAAO,OAAO,OAAO,OAAO,UAAU,QAAQ,CAAC,cAAc;GAC7D,CAAC,KAAK,OAAO,MAAM"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@confect/react",
3
+ "version": "1.0.0-next.0",
4
+ "description": "Confect React hooks",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/rjdellecese/confect.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/rjdellecese/confect/issues"
11
+ },
12
+ "homepage": "https://confect.rjdellecese.com",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "files": [
16
+ "CHANGELOG.md",
17
+ "LICENSE",
18
+ "README.md",
19
+ "dist",
20
+ "package.json",
21
+ "src"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "keywords": [
31
+ "effect",
32
+ "convex",
33
+ "react"
34
+ ],
35
+ "author": "RJ Dellecese",
36
+ "license": "ISC",
37
+ "devDependencies": {
38
+ "@effect/language-service": "0.56.0",
39
+ "@eslint/js": "9.39.1",
40
+ "@tsconfig/strictest": "2.0.8",
41
+ "@types/node": "24.10.1",
42
+ "eslint": "9.39.1",
43
+ "prettier": "3.6.2",
44
+ "tsdown": "0.16.4",
45
+ "typescript": "5.9.3",
46
+ "typescript-eslint": "8.46.4"
47
+ },
48
+ "peerDependencies": {
49
+ "convex": "^1.30.0",
50
+ "effect": "^3.19.3",
51
+ "react": "^18.0.0 || ^19.0.0",
52
+ "@confect/core": "1.0.0-next.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=22",
56
+ "pnpm": ">=10"
57
+ },
58
+ "main": "./dist/index.js",
59
+ "module": "./dist/index.js",
60
+ "types": "./dist/index.d.ts",
61
+ "scripts": {
62
+ "build": "tsdown --config-loader unrun",
63
+ "dev": "tsdown --watch",
64
+ "typecheck": "tsc --noEmit --project tsconfig.json",
65
+ "fix": "prettier --write . && eslint --fix . --max-warnings=0",
66
+ "lint": "prettier --check . && eslint . --max-warnings=0",
67
+ "clean": "rm -rf dist coverage node_modules"
68
+ }
69
+ }
package/src/index.ts ADDED
@@ -0,0 +1,70 @@
1
+ import * as Ref from "@confect/core/Ref";
2
+ import {
3
+ useAction as useConvexAction,
4
+ useMutation as useConvexMutation,
5
+ useQuery as useConvexQuery,
6
+ } from "convex/react";
7
+ import { Effect, Option, Schema } from "effect";
8
+
9
+ export const useQuery = <Query extends Ref.AnyPublicQuery>(
10
+ ref: Query,
11
+ args: Ref.Args<Query>["Type"],
12
+ ): Option.Option<Ref.Returns<Query>["Type"]> => {
13
+ const function_ = Ref.getFunction(ref);
14
+ const functionName = Ref.getConvexFunctionName(ref);
15
+
16
+ const encodedArgs = Schema.encodeSync(function_.args)(args);
17
+
18
+ const encodedReturnsOrUndefined = useConvexQuery(
19
+ functionName as any,
20
+ encodedArgs,
21
+ );
22
+
23
+ if (encodedReturnsOrUndefined === undefined) {
24
+ return Option.none();
25
+ } else {
26
+ return Option.some(
27
+ Schema.decodeSync(function_.returns)(encodedReturnsOrUndefined),
28
+ );
29
+ }
30
+ };
31
+
32
+ export const useMutation = <Mutation extends Ref.AnyPublicMutation>(
33
+ ref: Mutation,
34
+ ) => {
35
+ const function_ = Ref.getFunction(ref);
36
+ const functionName = Ref.getConvexFunctionName(ref);
37
+ const actualMutation = useConvexMutation(functionName as any);
38
+
39
+ return (
40
+ args: Ref.Args<Mutation>["Type"],
41
+ ): Effect.Effect<Ref.Returns<Mutation>["Type"]> =>
42
+ Effect.gen(function* () {
43
+ const encodedArgs = yield* Schema.encode(function_.args)(args);
44
+
45
+ const actualReturns = yield* Effect.promise(() =>
46
+ actualMutation(encodedArgs),
47
+ );
48
+
49
+ return yield* Schema.decode(function_.returns)(actualReturns);
50
+ }).pipe(Effect.orDie);
51
+ };
52
+
53
+ export const useAction = <Action extends Ref.AnyPublicAction>(ref: Action) => {
54
+ const function_ = Ref.getFunction(ref);
55
+ const functionName = Ref.getConvexFunctionName(ref);
56
+ const actualAction = useConvexAction(functionName as any);
57
+
58
+ return (
59
+ args: Ref.Args<Action>["Type"],
60
+ ): Effect.Effect<Ref.Returns<Action>["Type"]> =>
61
+ Effect.gen(function* () {
62
+ const encodedArgs = yield* Schema.encode(function_.args)(args);
63
+
64
+ const actualReturns = yield* Effect.promise(() =>
65
+ actualAction(encodedArgs),
66
+ );
67
+
68
+ return yield* Schema.decode(function_.returns)(actualReturns);
69
+ }).pipe(Effect.orDie);
70
+ };