fluent-convex 0.2.0 → 0.3.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/dist/builder.d.ts +12 -12
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +6 -4
- package/dist/builder.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +1 -2
- package/dist/middleware.d.ts.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/zod_support.d.ts +8 -1
- package/dist/zod_support.d.ts.map +1 -1
- package/dist/zod_support.js.map +1 -1
- package/package.json +2 -1
- package/src/builder.test-d.ts +10 -1
- package/src/builder.ts +44 -14
- package/src/index.ts +1 -1
- package/src/middleware.ts +2 -3
- package/src/types.ts +8 -3
- package/src/zod_support.ts +42 -1
package/dist/builder.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type RegisteredQuery, type RegisteredMutation, type RegisteredAction } from "convex/server";
|
|
1
|
+
import { type RegisteredQuery, type RegisteredMutation, type RegisteredAction, type GenericDataModel, type DataModelFromSchemaDefinition, type SchemaDefinition } from "convex/server";
|
|
2
2
|
import type { ConvexMiddleware, AnyConvexMiddleware } from "./middleware";
|
|
3
3
|
import type { Context, ConvexArgsValidator, ConvexReturnsValidator, InferArgs, FunctionType, Visibility, QueryCtx, MutationCtx, ActionCtx } from "./types";
|
|
4
|
-
import { type ValidatorInput, type ReturnsValidatorInput } from "./zod_support";
|
|
4
|
+
import { type ValidatorInput, type ReturnsValidatorInput, type ToConvexArgsValidator, type ToConvexReturnsValidator } from "./zod_support";
|
|
5
5
|
type InferredArgs<T extends ConvexArgsValidator | undefined> = T extends ConvexArgsValidator ? InferArgs<T> : Record<never, never>;
|
|
6
6
|
interface ConvexBuilderDef<TFunctionType extends FunctionType | undefined, TArgsValidator extends ConvexArgsValidator | undefined, TReturnsValidator extends ConvexReturnsValidator | undefined, TVisibility extends Visibility> {
|
|
7
7
|
functionType?: TFunctionType;
|
|
@@ -10,23 +10,23 @@ interface ConvexBuilderDef<TFunctionType extends FunctionType | undefined, TArgs
|
|
|
10
10
|
returnsValidator?: TReturnsValidator;
|
|
11
11
|
visibility: TVisibility;
|
|
12
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"> {
|
|
13
|
+
export declare class ConvexBuilder<TDataModel extends GenericDataModel = GenericDataModel, 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
14
|
private def;
|
|
15
15
|
constructor(def: ConvexBuilderDef<TFunctionType, TArgsValidator, TReturnsValidator, TVisibility>);
|
|
16
|
-
$context<U extends Context>(): ConvexBuilder<TFunctionType, U & Record<never, never>, U, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
16
|
+
$context<U extends Context>(): ConvexBuilder<TDataModel, TFunctionType, U & Record<never, never>, U, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
17
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,
|
|
24
|
-
returns<UReturns extends ReturnsValidatorInput>(validator: UReturns): ConvexBuilder<TFunctionType, TInitialContext, TCurrentContext, TArgsValidator,
|
|
18
|
+
use<UOutContext extends Context>(middleware: ConvexMiddleware<TCurrentContext, UOutContext>): ConvexBuilder<TDataModel, TFunctionType, TInitialContext, TCurrentContext & UOutContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
19
|
+
query(): ConvexBuilder<TDataModel, "query", TInitialContext extends Record<never, never> ? QueryCtx<TDataModel> : TInitialContext, TCurrentContext extends Record<never, never> ? QueryCtx<TDataModel> : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
20
|
+
mutation(): ConvexBuilder<TDataModel, "mutation", TInitialContext extends Record<never, never> ? MutationCtx<TDataModel> : TInitialContext, TCurrentContext extends Record<never, never> ? MutationCtx<TDataModel> : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
21
|
+
action(): ConvexBuilder<TDataModel, "action", TInitialContext extends Record<never, never> ? ActionCtx<TDataModel> : TInitialContext, TCurrentContext extends Record<never, never> ? ActionCtx<TDataModel> : TCurrentContext, TArgsValidator, TReturnsValidator, TVisibility>;
|
|
22
|
+
internal(): ConvexBuilder<TDataModel, TFunctionType, TInitialContext, TCurrentContext, TArgsValidator, TReturnsValidator, "internal">;
|
|
23
|
+
input<UInput extends ValidatorInput>(validator: UInput): ConvexBuilder<TDataModel, TFunctionType, TInitialContext, TCurrentContext, ToConvexArgsValidator<UInput>, TReturnsValidator, TVisibility>;
|
|
24
|
+
returns<UReturns extends ReturnsValidatorInput>(validator: UReturns): ConvexBuilder<TDataModel, TFunctionType, TInitialContext, TCurrentContext, TArgsValidator, ToConvexReturnsValidator<UReturns>, TVisibility>;
|
|
25
25
|
handler<TReturn>(handlerFn: (options: {
|
|
26
26
|
context: TCurrentContext;
|
|
27
27
|
input: InferredArgs<TArgsValidator>;
|
|
28
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
29
|
}
|
|
30
|
-
export declare
|
|
30
|
+
export declare function createBuilder<TSchema extends SchemaDefinition<any, boolean>>(_schema: TSchema): ConvexBuilder<DataModelFromSchemaDefinition<TSchema>, undefined, Record<never, never>, Record<never, never>, undefined, undefined, "public">;
|
|
31
31
|
export {};
|
|
32
32
|
//# sourceMappingURL=builder.d.ts.map
|
package/dist/builder.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,EA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ACD,aAAa,SAAS,QAAQ,GAC5B,gBAAgB,CACd,WAAW,EACX,YAAY,CAAC,cAAc,CAAC,EAC5B,OAAO,CAAC,OAAO,CAAC,CACjB,GACD,KAAK;CAqDd;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,EAC1E,OAAO,EAAE,OAAO,GACf,aAAa,CACd,6BAA6B,CAAC,OAAO,CAAC,EACtC,SAAS,EACT,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACpB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACpB,SAAS,EACT,SAAS,EACT,QAAQ,CACT,CAKA"}
|
package/dist/builder.js
CHANGED
|
@@ -95,8 +95,10 @@ export class ConvexBuilder {
|
|
|
95
95
|
return registrationFn(config);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
export
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
export function createBuilder(_schema) {
|
|
99
|
+
return new ConvexBuilder({
|
|
100
|
+
middlewares: [],
|
|
101
|
+
visibility: "public",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
102
104
|
//# sourceMappingURL=builder.js.map
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +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,
|
|
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,GAItB,MAAM,eAAe,CAAC;AAavB,OAAO,EACL,WAAW,EACX,iBAAiB,GAKlB,MAAM,eAAe,CAAC;AAkBvB,MAAM,OAAO,aAAa;IAShB,GAAG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AU,KAAK,QAAQ,CAAC;QACzC,MAAM,cAAc,GAAG;YACrB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,oBAAoB;YACrD,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,uBAAuB;YAC9D,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,qBAAqB;SACzD,CAAC,YAAY,CAAC,CAAC;QAEhB,OAAO,cAAc,CAAC,MAAM,CAAQ,CAAC;IACvC,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAC3B,OAAgB;IAUhB,OAAO,IAAI,aAAa,CAAC;QACvB,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ConvexBuilder,
|
|
1
|
+
export { ConvexBuilder, createBuilder } from "./builder";
|
|
2
2
|
export type { ConvexMiddleware, ConvexMiddlewareOptions, AnyConvexMiddleware, } from "./middleware";
|
|
3
3
|
export type { Context, ConvexArgsValidator, ConvexReturnsValidator, InferArgs, QueryCtx, MutationCtx, ActionCtx, FunctionType, Visibility, } from "./types";
|
|
4
4
|
export { isZodSchema, toConvexValidator, type ValidatorInput, type ReturnsValidatorInput, } from "./zod_support";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAEzD,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
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAoBzD,OAAO,EACL,WAAW,EACX,iBAAiB,GAGlB,MAAM,eAAe,CAAC"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Context } from "./types";
|
|
1
|
+
import { Context, Promisable } from "./types";
|
|
3
2
|
export interface ConvexMiddlewareOptions<TInContext extends Context> {
|
|
4
3
|
context: TInContext;
|
|
5
4
|
next: <U extends Context>(options: {
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE9C,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"}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export type ConvexReturnsValidator = GenericValidator;
|
|
|
6
6
|
export type InferArgs<T extends ConvexArgsValidator> = T extends GenericValidator ? T["type"] : {
|
|
7
7
|
[K in keyof T]: T[K] extends GenericValidator ? T[K]["isOptional"] extends true ? T[K]["type"] | undefined : T[K]["type"] : never;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
9
|
+
export type Promisable<T> = T | PromiseLike<T>;
|
|
10
|
+
export type QueryCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericQueryCtx<DataModel>;
|
|
11
|
+
export type MutationCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericMutationCtx<DataModel>;
|
|
12
|
+
export type ActionCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericActionCtx<DataModel>;
|
|
12
13
|
export type FunctionType = "query" | "mutation" | "action";
|
|
13
14
|
export type Visibility = "public" | "internal";
|
|
14
15
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +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;AAC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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,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAE/C,MAAM,MAAM,QAAQ,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,IACxE,eAAe,CAAC,SAAS,CAAC,CAAC;AAC7B,MAAM,MAAM,WAAW,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,IAC3E,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAChC,MAAM,MAAM,SAAS,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,IACzE,gBAAgB,CAAC,SAAS,CAAC,CAAC;AAE9B,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC"}
|
package/dist/zod_support.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { PropertyValidators, GenericValidator } from "convex/values";
|
|
2
|
+
import type { PropertyValidators, GenericValidator, Validator } from "convex/values";
|
|
3
|
+
import type { ConvexArgsValidator } from "./types";
|
|
3
4
|
export declare function isZodSchema(value: any): value is z.ZodTypeAny;
|
|
4
5
|
export declare function toConvexValidator<T extends z.ZodTypeAny>(schema: T): PropertyValidators | GenericValidator;
|
|
5
6
|
export type ValidatorInput = PropertyValidators | GenericValidator | z.ZodObject<any> | z.ZodEffects<any>;
|
|
6
7
|
export type ReturnsValidatorInput = GenericValidator | z.ZodType;
|
|
8
|
+
export type ToConvexArgsValidator<T extends ValidatorInput> = T extends z.ZodObject<infer Shape> ? {
|
|
9
|
+
[K in keyof Shape]: Shape[K] extends z.ZodType<infer Output> ? Validator<Output, Shape[K] extends z.ZodOptional<any> ? "optional" : "required", any> : never;
|
|
10
|
+
} : T extends z.ZodEffects<infer Schema> ? Schema extends z.ZodObject<infer Shape> ? {
|
|
11
|
+
[K in keyof Shape]: Shape[K] extends z.ZodType<infer FieldOutput> ? Validator<FieldOutput, Shape[K] extends z.ZodOptional<any> ? "optional" : "required", any> : never;
|
|
12
|
+
} : ConvexArgsValidator : T extends ConvexArgsValidator ? T : ConvexArgsValidator;
|
|
13
|
+
export type ToConvexReturnsValidator<T extends ReturnsValidatorInput> = T extends z.ZodType<infer Output> ? Validator<Output, "required", any> : T extends GenericValidator ? T : GenericValidator;
|
|
7
14
|
//# sourceMappingURL=zod_support.d.ts.map
|
|
@@ -1 +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,
|
|
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,EACV,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,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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CAAC,GACD,gBAAgB,CAAC"}
|
package/dist/zod_support.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod_support.js","sourceRoot":"","sources":["../src/zod_support.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"zod_support.js","sourceRoot":"","sources":["../src/zod_support.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQxD,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fluent-convex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A fluent API builder for Convex functions with middleware support, inspired by oRPC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
25
|
"test": "vitest run --typecheck",
|
|
26
26
|
"dev:test": "vitest --typecheck",
|
|
27
|
+
"example": "cd example && npm run",
|
|
27
28
|
"prepublishOnly": "npm run build"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
package/src/builder.test-d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { describe, it, assertType } from "vitest";
|
|
2
|
-
import { convex } from "./builder";
|
|
3
2
|
import { v } from "convex/values";
|
|
4
3
|
import { z } from "zod";
|
|
4
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
5
|
+
import { createBuilder } from "./builder";
|
|
6
|
+
|
|
7
|
+
const schema = defineSchema({
|
|
8
|
+
numbers: defineTable({
|
|
9
|
+
value: v.number(),
|
|
10
|
+
}),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const convex = createBuilder(schema);
|
|
5
14
|
|
|
6
15
|
describe("ConvexBuilder Type Tests", () => {
|
|
7
16
|
describe("input validation", () => {
|
package/src/builder.ts
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
internalMutationGeneric,
|
|
9
9
|
actionGeneric,
|
|
10
10
|
internalActionGeneric,
|
|
11
|
+
type GenericDataModel,
|
|
12
|
+
type DataModelFromSchemaDefinition,
|
|
13
|
+
type SchemaDefinition,
|
|
11
14
|
} from "convex/server";
|
|
12
15
|
import type { ConvexMiddleware, AnyConvexMiddleware } from "./middleware";
|
|
13
16
|
import type {
|
|
@@ -26,6 +29,8 @@ import {
|
|
|
26
29
|
toConvexValidator,
|
|
27
30
|
type ValidatorInput,
|
|
28
31
|
type ReturnsValidatorInput,
|
|
32
|
+
type ToConvexArgsValidator,
|
|
33
|
+
type ToConvexReturnsValidator,
|
|
29
34
|
} from "./zod_support";
|
|
30
35
|
|
|
31
36
|
type InferredArgs<T extends ConvexArgsValidator | undefined> =
|
|
@@ -45,6 +50,7 @@ interface ConvexBuilderDef<
|
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
export class ConvexBuilder<
|
|
53
|
+
TDataModel extends GenericDataModel = GenericDataModel,
|
|
48
54
|
TFunctionType extends FunctionType | undefined = undefined,
|
|
49
55
|
TInitialContext extends Context = Record<never, never>,
|
|
50
56
|
TCurrentContext extends Context = Record<never, never>,
|
|
@@ -71,6 +77,7 @@ export class ConvexBuilder<
|
|
|
71
77
|
}
|
|
72
78
|
|
|
73
79
|
$context<U extends Context>(): ConvexBuilder<
|
|
80
|
+
TDataModel,
|
|
74
81
|
TFunctionType,
|
|
75
82
|
U & Record<never, never>,
|
|
76
83
|
U,
|
|
@@ -93,6 +100,7 @@ export class ConvexBuilder<
|
|
|
93
100
|
use<UOutContext extends Context>(
|
|
94
101
|
middleware: ConvexMiddleware<TCurrentContext, UOutContext>
|
|
95
102
|
): ConvexBuilder<
|
|
103
|
+
TDataModel,
|
|
96
104
|
TFunctionType,
|
|
97
105
|
TInitialContext,
|
|
98
106
|
TCurrentContext & UOutContext,
|
|
@@ -107,9 +115,14 @@ export class ConvexBuilder<
|
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
query(): ConvexBuilder<
|
|
118
|
+
TDataModel,
|
|
110
119
|
"query",
|
|
111
|
-
TInitialContext extends Record<never, never>
|
|
112
|
-
|
|
120
|
+
TInitialContext extends Record<never, never>
|
|
121
|
+
? QueryCtx<TDataModel>
|
|
122
|
+
: TInitialContext,
|
|
123
|
+
TCurrentContext extends Record<never, never>
|
|
124
|
+
? QueryCtx<TDataModel>
|
|
125
|
+
: TCurrentContext,
|
|
113
126
|
TArgsValidator,
|
|
114
127
|
TReturnsValidator,
|
|
115
128
|
TVisibility
|
|
@@ -121,12 +134,13 @@ export class ConvexBuilder<
|
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
mutation(): ConvexBuilder<
|
|
137
|
+
TDataModel,
|
|
124
138
|
"mutation",
|
|
125
139
|
TInitialContext extends Record<never, never>
|
|
126
|
-
? MutationCtx
|
|
140
|
+
? MutationCtx<TDataModel>
|
|
127
141
|
: TInitialContext,
|
|
128
142
|
TCurrentContext extends Record<never, never>
|
|
129
|
-
? MutationCtx
|
|
143
|
+
? MutationCtx<TDataModel>
|
|
130
144
|
: TCurrentContext,
|
|
131
145
|
TArgsValidator,
|
|
132
146
|
TReturnsValidator,
|
|
@@ -139,9 +153,14 @@ export class ConvexBuilder<
|
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
action(): ConvexBuilder<
|
|
156
|
+
TDataModel,
|
|
142
157
|
"action",
|
|
143
|
-
TInitialContext extends Record<never, never>
|
|
144
|
-
|
|
158
|
+
TInitialContext extends Record<never, never>
|
|
159
|
+
? ActionCtx<TDataModel>
|
|
160
|
+
: TInitialContext,
|
|
161
|
+
TCurrentContext extends Record<never, never>
|
|
162
|
+
? ActionCtx<TDataModel>
|
|
163
|
+
: TCurrentContext,
|
|
145
164
|
TArgsValidator,
|
|
146
165
|
TReturnsValidator,
|
|
147
166
|
TVisibility
|
|
@@ -153,6 +172,7 @@ export class ConvexBuilder<
|
|
|
153
172
|
}
|
|
154
173
|
|
|
155
174
|
internal(): ConvexBuilder<
|
|
175
|
+
TDataModel,
|
|
156
176
|
TFunctionType,
|
|
157
177
|
TInitialContext,
|
|
158
178
|
TCurrentContext,
|
|
@@ -169,10 +189,11 @@ export class ConvexBuilder<
|
|
|
169
189
|
input<UInput extends ValidatorInput>(
|
|
170
190
|
validator: UInput
|
|
171
191
|
): ConvexBuilder<
|
|
192
|
+
TDataModel,
|
|
172
193
|
TFunctionType,
|
|
173
194
|
TInitialContext,
|
|
174
195
|
TCurrentContext,
|
|
175
|
-
|
|
196
|
+
ToConvexArgsValidator<UInput>,
|
|
176
197
|
TReturnsValidator,
|
|
177
198
|
TVisibility
|
|
178
199
|
> {
|
|
@@ -189,11 +210,12 @@ export class ConvexBuilder<
|
|
|
189
210
|
returns<UReturns extends ReturnsValidatorInput>(
|
|
190
211
|
validator: UReturns
|
|
191
212
|
): ConvexBuilder<
|
|
213
|
+
TDataModel,
|
|
192
214
|
TFunctionType,
|
|
193
215
|
TInitialContext,
|
|
194
216
|
TCurrentContext,
|
|
195
217
|
TArgsValidator,
|
|
196
|
-
|
|
218
|
+
ToConvexReturnsValidator<UReturns>,
|
|
197
219
|
TVisibility
|
|
198
220
|
> {
|
|
199
221
|
const convexValidator = isZodSchema(validator)
|
|
@@ -245,7 +267,10 @@ export class ConvexBuilder<
|
|
|
245
267
|
}
|
|
246
268
|
|
|
247
269
|
const composedHandler = async (
|
|
248
|
-
baseCtx:
|
|
270
|
+
baseCtx:
|
|
271
|
+
| QueryCtx<TDataModel>
|
|
272
|
+
| MutationCtx<TDataModel>
|
|
273
|
+
| ActionCtx<TDataModel>,
|
|
249
274
|
baseArgs: InferredArgs<TArgsValidator>
|
|
250
275
|
) => {
|
|
251
276
|
let currentContext: any = baseCtx;
|
|
@@ -281,14 +306,19 @@ export class ConvexBuilder<
|
|
|
281
306
|
}
|
|
282
307
|
}
|
|
283
308
|
|
|
284
|
-
export
|
|
309
|
+
export function createBuilder<TSchema extends SchemaDefinition<any, boolean>>(
|
|
310
|
+
_schema: TSchema
|
|
311
|
+
): ConvexBuilder<
|
|
312
|
+
DataModelFromSchemaDefinition<TSchema>,
|
|
285
313
|
undefined,
|
|
286
314
|
Record<never, never>,
|
|
287
315
|
Record<never, never>,
|
|
288
316
|
undefined,
|
|
289
317
|
undefined,
|
|
290
318
|
"public"
|
|
291
|
-
>
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
319
|
+
> {
|
|
320
|
+
return new ConvexBuilder({
|
|
321
|
+
middlewares: [],
|
|
322
|
+
visibility: "public",
|
|
323
|
+
});
|
|
324
|
+
}
|
package/src/index.ts
CHANGED
package/src/middleware.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Context } from "./types";
|
|
1
|
+
import { Context, Promisable } from "./types";
|
|
3
2
|
|
|
4
3
|
export interface ConvexMiddlewareOptions<TInContext extends Context> {
|
|
5
4
|
context: TInContext;
|
|
@@ -13,7 +12,7 @@ export interface ConvexMiddleware<
|
|
|
13
12
|
TOutContext extends Context,
|
|
14
13
|
> {
|
|
15
14
|
(
|
|
16
|
-
options: ConvexMiddlewareOptions<TInContext
|
|
15
|
+
options: ConvexMiddlewareOptions<TInContext>,
|
|
17
16
|
): Promisable<{ context: TOutContext }>;
|
|
18
17
|
}
|
|
19
18
|
|
package/src/types.ts
CHANGED
|
@@ -22,9 +22,14 @@ export type InferArgs<T extends ConvexArgsValidator> =
|
|
|
22
22
|
: never;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export type
|
|
26
|
-
|
|
27
|
-
export type
|
|
25
|
+
export type Promisable<T> = T | PromiseLike<T>;
|
|
26
|
+
|
|
27
|
+
export type QueryCtx<DataModel extends GenericDataModel = GenericDataModel> =
|
|
28
|
+
GenericQueryCtx<DataModel>;
|
|
29
|
+
export type MutationCtx<DataModel extends GenericDataModel = GenericDataModel> =
|
|
30
|
+
GenericMutationCtx<DataModel>;
|
|
31
|
+
export type ActionCtx<DataModel extends GenericDataModel = GenericDataModel> =
|
|
32
|
+
GenericActionCtx<DataModel>;
|
|
28
33
|
|
|
29
34
|
export type FunctionType = "query" | "mutation" | "action";
|
|
30
35
|
export type Visibility = "public" | "internal";
|
package/src/zod_support.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
2
|
import { zodToConvex } from "convex-helpers/server/zod";
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
PropertyValidators,
|
|
5
|
+
GenericValidator,
|
|
6
|
+
Validator,
|
|
7
|
+
} from "convex/values";
|
|
8
|
+
import type { ConvexArgsValidator } from "./types";
|
|
4
9
|
|
|
5
10
|
export function isZodSchema(value: any): value is z.ZodTypeAny {
|
|
6
11
|
return (
|
|
@@ -21,3 +26,39 @@ export type ValidatorInput =
|
|
|
21
26
|
| z.ZodEffects<any>;
|
|
22
27
|
|
|
23
28
|
export type ReturnsValidatorInput = GenericValidator | z.ZodType;
|
|
29
|
+
|
|
30
|
+
// Helper type to convert ValidatorInput to a proper ConvexArgsValidator while preserving types
|
|
31
|
+
export type ToConvexArgsValidator<T extends ValidatorInput> =
|
|
32
|
+
T extends z.ZodObject<infer Shape>
|
|
33
|
+
? {
|
|
34
|
+
[K in keyof Shape]: Shape[K] extends z.ZodType<infer Output>
|
|
35
|
+
? Validator<
|
|
36
|
+
Output,
|
|
37
|
+
Shape[K] extends z.ZodOptional<any> ? "optional" : "required",
|
|
38
|
+
any
|
|
39
|
+
>
|
|
40
|
+
: never;
|
|
41
|
+
}
|
|
42
|
+
: T extends z.ZodEffects<infer Schema>
|
|
43
|
+
? Schema extends z.ZodObject<infer Shape>
|
|
44
|
+
? {
|
|
45
|
+
[K in keyof Shape]: Shape[K] extends z.ZodType<infer FieldOutput>
|
|
46
|
+
? Validator<
|
|
47
|
+
FieldOutput,
|
|
48
|
+
Shape[K] extends z.ZodOptional<any> ? "optional" : "required",
|
|
49
|
+
any
|
|
50
|
+
>
|
|
51
|
+
: never;
|
|
52
|
+
}
|
|
53
|
+
: ConvexArgsValidator
|
|
54
|
+
: T extends ConvexArgsValidator
|
|
55
|
+
? T
|
|
56
|
+
: ConvexArgsValidator;
|
|
57
|
+
|
|
58
|
+
// Helper type to convert ReturnsValidatorInput to a proper ConvexReturnsValidator while preserving types
|
|
59
|
+
export type ToConvexReturnsValidator<T extends ReturnsValidatorInput> =
|
|
60
|
+
T extends z.ZodType<infer Output>
|
|
61
|
+
? Validator<Output, "required", any>
|
|
62
|
+
: T extends GenericValidator
|
|
63
|
+
? T
|
|
64
|
+
: GenericValidator;
|