fluent-convex 0.1.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/LICENSE.txt +202 -0
- package/README.md +147 -0
- package/dist/builder.d.ts +32 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +102 -0
- package/dist/builder.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +17 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +2 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/zod_support.d.ts +7 -0
- package/dist/zod_support.d.ts.map +1 -0
- package/dist/zod_support.js +8 -0
- package/dist/zod_support.js.map +1 -0
- package/package.json +61 -0
- package/src/builder.test-d.ts +472 -0
- package/src/builder.ts +294 -0
- package/src/index.ts +26 -0
- package/src/middleware.ts +20 -0
- package/src/types.ts +30 -0
- package/src/zod_support.ts +23 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2024 Convex, Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# fluent-convex
|
|
2
|
+
|
|
3
|
+
A fluent API builder for Convex functions with middleware support, inspired by [oRPC](https://orpc.unnoq.com/).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔄 **Middleware support** - Compose reusable middleware for authentication, logging, and more
|
|
8
|
+
- 🎯 **Type-safe** - Full TypeScript support with type inference
|
|
9
|
+
- ✨ **Fluent API** - Chain methods for a clean, readable syntax
|
|
10
|
+
- 🔌 **Zod integration** - Use Zod schemas alongside Convex validators
|
|
11
|
+
- 🚀 **Works with Convex** - Built on top of Convex's function system
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install fluent-convex convex convex-helpers zod
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { cvx } from "fluent-convex";
|
|
23
|
+
import { v } from "convex/values";
|
|
24
|
+
|
|
25
|
+
// Simple query
|
|
26
|
+
export const listNumbers = cvx
|
|
27
|
+
.query()
|
|
28
|
+
.input({ count: v.number() })
|
|
29
|
+
.handler(async ({ context, input }) => {
|
|
30
|
+
const numbers = await context.db
|
|
31
|
+
.query("numbers")
|
|
32
|
+
.order("desc")
|
|
33
|
+
.take(input.count);
|
|
34
|
+
|
|
35
|
+
return { numbers: numbers.map((n) => n.value) };
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// With middleware
|
|
39
|
+
const authMiddleware = cvx.query().middleware(async ({ context, next }) => {
|
|
40
|
+
const identity = await context.auth.getUserIdentity();
|
|
41
|
+
if (!identity) {
|
|
42
|
+
throw new Error("Unauthorized");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return next({
|
|
46
|
+
context: {
|
|
47
|
+
...context,
|
|
48
|
+
user: {
|
|
49
|
+
id: identity.subject,
|
|
50
|
+
name: identity.name ?? "Unknown",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const listNumbersAuth = cvx
|
|
57
|
+
.query()
|
|
58
|
+
.use(authMiddleware)
|
|
59
|
+
.input({ count: v.number() })
|
|
60
|
+
.handler(async ({ context, input }) => {
|
|
61
|
+
const numbers = await context.db
|
|
62
|
+
.query("numbers")
|
|
63
|
+
.order("desc")
|
|
64
|
+
.take(input.count);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
viewer: context.user.name, // user is available from middleware!
|
|
68
|
+
numbers: numbers.map((n) => n.value),
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Using Zod
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { z } from "zod";
|
|
77
|
+
import { cvx } from "fluent-convex";
|
|
78
|
+
|
|
79
|
+
export const listNumbersWithZod = cvx
|
|
80
|
+
.query()
|
|
81
|
+
.input(
|
|
82
|
+
z.object({
|
|
83
|
+
count: z.number().int().min(1).max(100),
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
.handler(async ({ context, input }) => {
|
|
87
|
+
// input.count is properly typed as number
|
|
88
|
+
const numbers = await context.db.query("numbers").take(input.count);
|
|
89
|
+
|
|
90
|
+
return { numbers: numbers.map((n) => n.value) };
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## API
|
|
95
|
+
|
|
96
|
+
### Methods
|
|
97
|
+
|
|
98
|
+
- `.query()` - Define a Convex query
|
|
99
|
+
- `.mutation()` - Define a Convex mutation
|
|
100
|
+
- `.action()` - Define a Convex action
|
|
101
|
+
- `.internal()` - Make the function internal (private)
|
|
102
|
+
- `.input(validator)` - Set input validation (Convex or Zod)
|
|
103
|
+
- `.returns(validator)` - Set return validation (Convex or Zod)
|
|
104
|
+
- `.use(middleware)` - Apply middleware
|
|
105
|
+
- `.middleware(fn)` - Create a middleware function
|
|
106
|
+
- `.handler(fn)` - Define the function handler
|
|
107
|
+
|
|
108
|
+
## Example
|
|
109
|
+
|
|
110
|
+
Check out the `/example` directory for a complete working example with various use cases including:
|
|
111
|
+
|
|
112
|
+
- Simple queries and mutations
|
|
113
|
+
- Middleware composition
|
|
114
|
+
- Zod integration
|
|
115
|
+
- Internal functions
|
|
116
|
+
- Type-safe context transformations
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
This is a monorepo structure:
|
|
121
|
+
|
|
122
|
+
- `/src` - The npm package source code
|
|
123
|
+
- `/example` - Example Convex app using the package
|
|
124
|
+
|
|
125
|
+
### Building the package
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm run build
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Running tests
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm test
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Running the example
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cd example
|
|
141
|
+
npm install
|
|
142
|
+
npm run dev
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Credits
|
|
146
|
+
|
|
147
|
+
Borrowed heavily from [oRPC](https://orpc.unnoq.com/learn-and-contribute/overview) and helped out by AI.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type RegisteredQuery, type RegisteredMutation, type RegisteredAction } from "convex/server";
|
|
2
|
+
import type { ConvexMiddleware, AnyConvexMiddleware } from "./middleware";
|
|
3
|
+
import type { Context, ConvexArgsValidator, ConvexReturnsValidator, InferArgs, FunctionType, Visibility, QueryCtx, MutationCtx, ActionCtx } from "./types";
|
|
4
|
+
import { type ValidatorInput, type ReturnsValidatorInput } from "./zod_support";
|
|
5
|
+
type InferredArgs<T extends ConvexArgsValidator | undefined> = T extends ConvexArgsValidator ? InferArgs<T> : Record<never, never>;
|
|
6
|
+
interface ConvexBuilderDef<TFunctionType extends FunctionType | undefined, TArgsValidator extends ConvexArgsValidator | undefined, TReturnsValidator extends ConvexReturnsValidator | undefined, TVisibility extends Visibility> {
|
|
7
|
+
functionType?: TFunctionType;
|
|
8
|
+
middlewares: readonly AnyConvexMiddleware[];
|
|
9
|
+
argsValidator?: TArgsValidator;
|
|
10
|
+
returnsValidator?: TReturnsValidator;
|
|
11
|
+
visibility: TVisibility;
|
|
12
|
+
}
|
|
13
|
+
export declare class ConvexBuilder<TFunctionType extends FunctionType | undefined = undefined, TInitialContext extends Context = Record<never, never>, TCurrentContext extends Context = Record<never, never>, TArgsValidator extends ConvexArgsValidator | undefined = undefined, TReturnsValidator extends ConvexReturnsValidator | undefined = undefined, TVisibility extends Visibility = "public"> {
|
|
14
|
+
private def;
|
|
15
|
+
constructor(def: ConvexBuilderDef<TFunctionType, TArgsValidator, TReturnsValidator, TVisibility>);
|
|
16
|
+
$context<U extends Context>(): ConvexBuilder<TFunctionType, U & Record<never, never>, U, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
17
|
+
middleware<UOutContext extends Context>(middleware: ConvexMiddleware<TInitialContext, UOutContext>): ConvexMiddleware<TInitialContext, UOutContext>;
|
|
18
|
+
use<UOutContext extends Context>(middleware: ConvexMiddleware<TCurrentContext, UOutContext>): ConvexBuilder<TFunctionType, TInitialContext, TCurrentContext & UOutContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
19
|
+
query(): ConvexBuilder<"query", TInitialContext extends Record<never, never> ? QueryCtx : TInitialContext, TCurrentContext extends Record<never, never> ? QueryCtx : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
20
|
+
mutation(): ConvexBuilder<"mutation", TInitialContext extends Record<never, never> ? MutationCtx : TInitialContext, TCurrentContext extends Record<never, never> ? MutationCtx : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
21
|
+
action(): ConvexBuilder<"action", TInitialContext extends Record<never, never> ? ActionCtx : TInitialContext, TCurrentContext extends Record<never, never> ? ActionCtx : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
22
|
+
internal(): ConvexBuilder<TFunctionType, TInitialContext, TCurrentContext, TArgsValidator, TReturnsValidator, "internal">;
|
|
23
|
+
input<UInput extends ValidatorInput>(validator: UInput): ConvexBuilder<TFunctionType, TInitialContext, TCurrentContext, ConvexArgsValidator, TReturnsValidator, TVisibility>;
|
|
24
|
+
returns<UReturns extends ReturnsValidatorInput>(validator: UReturns): ConvexBuilder<TFunctionType, TInitialContext, TCurrentContext, TArgsValidator, ConvexReturnsValidator, TVisibility>;
|
|
25
|
+
handler<TReturn>(handlerFn: (options: {
|
|
26
|
+
context: TCurrentContext;
|
|
27
|
+
input: InferredArgs<TArgsValidator>;
|
|
28
|
+
}) => Promise<TReturn>): TFunctionType extends "query" ? RegisteredQuery<TVisibility, InferredArgs<TArgsValidator>, Promise<TReturn>> : TFunctionType extends "mutation" ? RegisteredMutation<TVisibility, InferredArgs<TArgsValidator>, Promise<TReturn>> : TFunctionType extends "action" ? RegisteredAction<TVisibility, InferredArgs<TArgsValidator>, Promise<TReturn>> : never;
|
|
29
|
+
}
|
|
30
|
+
export declare const cvx: ConvexBuilder<undefined, Record<never, never>, Record<never, never>, undefined, undefined, "public">;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAOtB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,WAAW,EACX,SAAS,EACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,KAAK,YAAY,CAAC,CAAC,SAAS,mBAAmB,GAAG,SAAS,IACzD,CAAC,SAAS,mBAAmB,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG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AW,CACZ;IAWD,OAAO,CAAC,OAAO,EACb,SAAS,EAAE,CAAC,OAAO,EAAE;QACnB,OAAO,EAAE,eAAe,CAAC;QACzB,KAAK,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;KACrC,KAAK,OAAO,CAAC,OAAO,CAAC,GACrB,aAAa,SAAS,OAAO,GAC5B,eAAe,CACb,WAAW,EACX,YAAY,CAAC,cAAc,CAAC,EAC5B,OAAO,CAAC,OAAO,CAAC,CACjB,GACD,aAAa,SAAS,UAAU,GAC9B,kBAAkB,CAChB,WAAW,EACX,YAAY,CAAC,cAAc,CAAC,EAC5B,OAAO,CAAC,OAAO,CAAC,CACjB,GACD,aAAa,SAAS,QAAQ,GAC5B,gBAAgB,CACd,WAAW,EACX,YAAY,CAAC,cAAc,CAAC,EAC5B,OAAO,CAAC,OAAO,CAAC,CACjB,GACD,KAAK;CAkDd;AAED,eAAO,MAAM,GAAG,sGAUd,CAAC"}
|
package/dist/builder.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { queryGeneric, internalQueryGeneric, mutationGeneric, internalMutationGeneric, actionGeneric, internalActionGeneric, } from "convex/server";
|
|
2
|
+
import { isZodSchema, toConvexValidator, } from "./zod_support";
|
|
3
|
+
export class ConvexBuilder {
|
|
4
|
+
def;
|
|
5
|
+
constructor(def) {
|
|
6
|
+
this.def = def;
|
|
7
|
+
}
|
|
8
|
+
$context() {
|
|
9
|
+
return new ConvexBuilder({
|
|
10
|
+
...this.def,
|
|
11
|
+
middlewares: [],
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
middleware(middleware) {
|
|
15
|
+
return middleware;
|
|
16
|
+
}
|
|
17
|
+
use(middleware) {
|
|
18
|
+
return new ConvexBuilder({
|
|
19
|
+
...this.def,
|
|
20
|
+
middlewares: [...this.def.middlewares, middleware],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
query() {
|
|
24
|
+
return new ConvexBuilder({
|
|
25
|
+
...this.def,
|
|
26
|
+
functionType: "query",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
mutation() {
|
|
30
|
+
return new ConvexBuilder({
|
|
31
|
+
...this.def,
|
|
32
|
+
functionType: "mutation",
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
action() {
|
|
36
|
+
return new ConvexBuilder({
|
|
37
|
+
...this.def,
|
|
38
|
+
functionType: "action",
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
internal() {
|
|
42
|
+
return new ConvexBuilder({
|
|
43
|
+
...this.def,
|
|
44
|
+
visibility: "internal",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
input(validator) {
|
|
48
|
+
const convexValidator = isZodSchema(validator)
|
|
49
|
+
? toConvexValidator(validator)
|
|
50
|
+
: validator;
|
|
51
|
+
return new ConvexBuilder({
|
|
52
|
+
...this.def,
|
|
53
|
+
argsValidator: convexValidator,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
returns(validator) {
|
|
57
|
+
const convexValidator = isZodSchema(validator)
|
|
58
|
+
? toConvexValidator(validator)
|
|
59
|
+
: validator;
|
|
60
|
+
return new ConvexBuilder({
|
|
61
|
+
...this.def,
|
|
62
|
+
returnsValidator: convexValidator,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
handler(handlerFn) {
|
|
66
|
+
const { functionType, middlewares, argsValidator, returnsValidator, visibility, } = this.def;
|
|
67
|
+
if (!functionType) {
|
|
68
|
+
throw new Error("Function type not set. Call .query(), .mutation(), or .action() first.");
|
|
69
|
+
}
|
|
70
|
+
const composedHandler = async (baseCtx, baseArgs) => {
|
|
71
|
+
let currentContext = baseCtx;
|
|
72
|
+
for (const middleware of middlewares) {
|
|
73
|
+
const result = await middleware({
|
|
74
|
+
context: currentContext,
|
|
75
|
+
next: async (options) => ({ context: options.context }),
|
|
76
|
+
});
|
|
77
|
+
currentContext = result.context;
|
|
78
|
+
}
|
|
79
|
+
return handlerFn({
|
|
80
|
+
context: currentContext,
|
|
81
|
+
input: baseArgs,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const config = {
|
|
85
|
+
args: argsValidator || {},
|
|
86
|
+
...(returnsValidator ? { returns: returnsValidator } : {}),
|
|
87
|
+
handler: composedHandler,
|
|
88
|
+
};
|
|
89
|
+
const isPublic = visibility === "public";
|
|
90
|
+
const registrationFn = {
|
|
91
|
+
query: isPublic ? queryGeneric : internalQueryGeneric,
|
|
92
|
+
mutation: isPublic ? mutationGeneric : internalMutationGeneric,
|
|
93
|
+
action: isPublic ? actionGeneric : internalActionGeneric,
|
|
94
|
+
}[functionType];
|
|
95
|
+
return registrationFn(config);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export const cvx = new ConvexBuilder({
|
|
99
|
+
middlewares: [],
|
|
100
|
+
visibility: "public",
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EACZ,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAavB,OAAO,EACL,WAAW,EACX,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AAkBvB,MAAM,OAAO,aAAa;IAQhB,GAAG,CAKT;IAEF,YACE,GAKC;QAED,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,QAAQ;QAQN,OAAO,IAAI,aAAa,CAAC;YACvB,GAAG,IAAI,CAAC,GAAG;YACX,WAAW,EAAE,EAAE;SAChB,CAAC,CAAC;IACL,CAAC;IAED,UAAU,CACR,UAA0D;QAE1D,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,GAAG,CACD,UAA0D;QAS1D,OAAO,IAAI,aAAa,CAAC;YACvB,GAAG,IAAI,CAAC,GAAG;YACX,WAAW,E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,CAAC;CACF;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,aAAa,CAOlC;IACA,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,QAAQ;CACrB,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ConvexBuilder, cvx } from "./builder";
|
|
2
|
+
export type { ConvexMiddleware, ConvexMiddlewareOptions, AnyConvexMiddleware, } from "./middleware";
|
|
3
|
+
export type { Context, ConvexArgsValidator, ConvexReturnsValidator, InferArgs, QueryCtx, MutationCtx, ActionCtx, FunctionType, Visibility, } from "./types";
|
|
4
|
+
export { isZodSchema, toConvexValidator, type ValidatorInput, type ReturnsValidatorInput, } from "./zod_support";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE/C,YAAY,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,OAAO,EACP,mBAAmB,EACnB,sBAAsB,EACtB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,UAAU,GACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAoB/C,OAAO,EACL,WAAW,EACX,iBAAiB,GAGlB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Promisable } from "@orpc/shared";
|
|
2
|
+
import type { Context } from "./types";
|
|
3
|
+
export interface ConvexMiddlewareOptions<TInContext extends Context> {
|
|
4
|
+
context: TInContext;
|
|
5
|
+
next: <U extends Context>(options: {
|
|
6
|
+
context: U;
|
|
7
|
+
}) => Promisable<{
|
|
8
|
+
context: U;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
11
|
+
export interface ConvexMiddleware<TInContext extends Context, TOutContext extends Context> {
|
|
12
|
+
(options: ConvexMiddlewareOptions<TInContext>): Promisable<{
|
|
13
|
+
context: TOutContext;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export type AnyConvexMiddleware = ConvexMiddleware<any, any>;
|
|
17
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,uBAAuB,CAAC,UAAU,SAAS,OAAO;IACjE,OAAO,EAAE,UAAU,CAAC;IACpB,IAAI,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,OAAO,EAAE;QACjC,OAAO,EAAE,CAAC,CAAC;KACZ,KAAK,UAAU,CAAC;QAAE,OAAO,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB,CAC/B,UAAU,SAAS,OAAO,EAC1B,WAAW,SAAS,OAAO;IAE3B,CACE,OAAO,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC3C,UAAU,CAAC;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;CACzC;AAED,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PropertyValidators, GenericValidator } from "convex/values";
|
|
2
|
+
import type { GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDataModel } from "convex/server";
|
|
3
|
+
export type Context = Record<PropertyKey, any>;
|
|
4
|
+
export type ConvexArgsValidator = PropertyValidators | GenericValidator;
|
|
5
|
+
export type ConvexReturnsValidator = GenericValidator;
|
|
6
|
+
export type InferArgs<T extends ConvexArgsValidator> = T extends GenericValidator ? T["type"] : {
|
|
7
|
+
[K in keyof T]: T[K] extends GenericValidator ? T[K]["isOptional"] extends true ? T[K]["type"] | undefined : T[K]["type"] : never;
|
|
8
|
+
};
|
|
9
|
+
export type QueryCtx = GenericQueryCtx<GenericDataModel>;
|
|
10
|
+
export type MutationCtx = GenericMutationCtx<GenericDataModel>;
|
|
11
|
+
export type ActionCtx = GenericActionCtx<GenericDataModel>;
|
|
12
|
+
export type FunctionType = "query" | "mutation" | "action";
|
|
13
|
+
export type Visibility = "public" | "internal";
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC1E,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AACxE,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AAEtD,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,mBAAmB,IACjD,CAAC,SAAS,gBAAgB,GACtB,CAAC,CAAC,MAAM,CAAC,GACT;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,gBAAgB,GACzC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,IAAI,GAC7B,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,GACxB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GACd,KAAK;CACV,CAAC;AAER,MAAM,MAAM,QAAQ,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;AACzD,MAAM,MAAM,WAAW,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAC/D,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { PropertyValidators, GenericValidator } from "convex/values";
|
|
3
|
+
export declare function isZodSchema(value: any): value is z.ZodTypeAny;
|
|
4
|
+
export declare function toConvexValidator<T extends z.ZodTypeAny>(schema: T): PropertyValidators | GenericValidator;
|
|
5
|
+
export type ValidatorInput = PropertyValidators | GenericValidator | z.ZodObject<any> | z.ZodEffects<any>;
|
|
6
|
+
export type ReturnsValidatorInput = GenericValidator | z.ZodType;
|
|
7
|
+
//# sourceMappingURL=zod_support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod_support.d.ts","sourceRoot":"","sources":["../src/zod_support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE1E,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC,UAAU,CAI7D;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EACtD,MAAM,EAAE,CAAC,GACR,kBAAkB,GAAG,gBAAgB,CAEvC;AAED,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,gBAAgB,GAChB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAChB,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAEtB,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,CAAC,CAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { zodToConvex } from "convex-helpers/server/zod";
|
|
2
|
+
export function isZodSchema(value) {
|
|
3
|
+
return (value && typeof value === "object" && "_def" in value && "parse" in value);
|
|
4
|
+
}
|
|
5
|
+
export function toConvexValidator(schema) {
|
|
6
|
+
return zodToConvex(schema);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=zod_support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod_support.js","sourceRoot":"","sources":["../src/zod_support.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,MAAM,UAAU,WAAW,CAAC,KAAU;IACpC,OAAO,CACL,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,CAC1E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,MAAS;IAET,OAAO,WAAW,CAAC,MAAM,CAAQ,CAAC;AACpC,CAAC"}
|