fluent-convex 0.4.1 → 0.4.2

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/types.d.ts CHANGED
@@ -3,13 +3,25 @@ import type { GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericData
3
3
  export type Context = Record<PropertyKey, any>;
4
4
  export type ConvexArgsValidator = PropertyValidators | GenericValidator;
5
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;
6
+ type ValidatorType<T> = T extends GenericValidator ? T["type"] : never;
7
+ type OptionalKeys<T extends Record<PropertyKey, any>> = {
8
+ [K in keyof T]: T[K] extends GenericValidator ? T[K]["isOptional"] extends "optional" ? K : never : never;
9
+ }[keyof T];
10
+ type RequiredKeys<T extends Record<PropertyKey, any>> = {
11
+ [K in keyof T]: T[K] extends GenericValidator ? T[K]["isOptional"] extends "optional" ? never : K : never;
12
+ }[keyof T];
13
+ type OptionalArgs<T extends Record<PropertyKey, any>> = {
14
+ [K in OptionalKeys<T>]?: T[K] extends GenericValidator ? ValidatorType<T[K]> | undefined : never;
8
15
  };
16
+ type RequiredArgs<T extends Record<PropertyKey, any>> = {
17
+ [K in RequiredKeys<T>]: ValidatorType<T[K]>;
18
+ };
19
+ export type InferArgs<T extends ConvexArgsValidator> = T extends GenericValidator ? T["type"] : RequiredArgs<T> & OptionalArgs<T>;
9
20
  export type Promisable<T> = T | PromiseLike<T>;
10
21
  export type QueryCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericQueryCtx<DataModel>;
11
22
  export type MutationCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericMutationCtx<DataModel>;
12
23
  export type ActionCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericActionCtx<DataModel>;
13
24
  export type FunctionType = "query" | "mutation" | "action";
14
25
  export type Visibility = "public" | "internal";
26
+ export {};
15
27
  //# sourceMappingURL=types.d.ts.map
@@ -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;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,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,g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- "version": "0.4.1",
3
+ "version": "0.4.2",
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",
package/src/types.ts CHANGED
@@ -11,16 +11,36 @@ export type Context = Record<PropertyKey, any>;
11
11
  export type ConvexArgsValidator = PropertyValidators | GenericValidator;
12
12
  export type ConvexReturnsValidator = GenericValidator;
13
13
 
14
+ type ValidatorType<T> = T extends GenericValidator ? T["type"] : never;
15
+
16
+ type OptionalKeys<T extends Record<PropertyKey, any>> = {
17
+ [K in keyof T]: T[K] extends GenericValidator
18
+ ? T[K]["isOptional"] extends "optional"
19
+ ? K
20
+ : never
21
+ : never;
22
+ }[keyof T];
23
+
24
+ type RequiredKeys<T extends Record<PropertyKey, any>> = {
25
+ [K in keyof T]: T[K] extends GenericValidator
26
+ ? T[K]["isOptional"] extends "optional"
27
+ ? never
28
+ : K
29
+ : never;
30
+ }[keyof T];
31
+
32
+ type OptionalArgs<T extends Record<PropertyKey, any>> = {
33
+ [K in OptionalKeys<T>]?: T[K] extends GenericValidator
34
+ ? ValidatorType<T[K]> | undefined
35
+ : never;
36
+ };
37
+
38
+ type RequiredArgs<T extends Record<PropertyKey, any>> = {
39
+ [K in RequiredKeys<T>]: ValidatorType<T[K]>;
40
+ };
41
+
14
42
  export type InferArgs<T extends ConvexArgsValidator> =
15
- T extends GenericValidator
16
- ? T["type"]
17
- : {
18
- [K in keyof T]: T[K] extends GenericValidator
19
- ? T[K]["isOptional"] extends true
20
- ? T[K]["type"] | undefined
21
- : T[K]["type"]
22
- : never;
23
- };
43
+ T extends GenericValidator ? T["type"] : RequiredArgs<T> & OptionalArgs<T>;
24
44
 
25
45
  export type Promisable<T> = T | PromiseLike<T>;
26
46