graphql-data-generator 0.4.6-alpha.2 → 0.4.6-alpha.4
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/package.json +1 -1
- package/types/extendedTypes.d.ts +12 -22
- package/types/init.d.ts +2 -2
package/package.json
CHANGED
package/types/extendedTypes.d.ts
CHANGED
|
@@ -25,6 +25,13 @@ type PrefixKeys<T, Prefix extends string> = {
|
|
|
25
25
|
type MapObjectsToBuilders<T, Transforms> = {
|
|
26
26
|
[K in keyof T]: ObjectBuilder<T[K], K extends keyof Transforms ? Transforms[K] : ContravariantEmpty>;
|
|
27
27
|
};
|
|
28
|
+
export type MapObjectsToTransforms<Objects extends Record<string, Record<string, unknown>>> = {
|
|
29
|
+
[Object in keyof Objects]?: Record<string, DefaultObjectTransform<Objects[Object], Objects[Object]> | ((prev: Objects[Object], ...args: any[]) => Patch<Objects[Object]>)>;
|
|
30
|
+
};
|
|
31
|
+
type InnerMapOperationsToTransforms<Operations> = {
|
|
32
|
+
[Operation in keyof Operations]?: Record<string, InferOperationTransforms<Operations[Operation]>>;
|
|
33
|
+
};
|
|
34
|
+
export type MapOperationsToTransforms<Queries, Mutations, Subscriptions, Types, Inputs> = InnerMapOperationsToTransforms<ResolveConflicts<Queries, Mutations, Subscriptions, Types, Inputs>>;
|
|
28
35
|
type MapOperationsToBuilders<T, Transforms, Extra> = {
|
|
29
36
|
[K in keyof T]: OperationBuilder<T[K] extends {
|
|
30
37
|
data: infer U;
|
|
@@ -42,31 +49,14 @@ type DefaultOperationTransform<T> = {
|
|
|
42
49
|
variables: infer V;
|
|
43
50
|
} ? Patch<V> : never;
|
|
44
51
|
};
|
|
45
|
-
type
|
|
46
|
-
|
|
47
|
-
type ExcessCheck<R, T> = Record<Exclude<keyof R, AllKeysOf<T>>, never> & {
|
|
48
|
-
[K in keyof R & AllKeysOf<T>]?: R[K] extends (...args: any[]) => any ? unknown : NonNullable<ValueOf<T, K>> extends any[] ? unknown : NonNullable<R[K]> extends object ? NonNullable<ValueOf<T, K>> extends object ? ExcessCheck<NonNullable<R[K]>, NonNullable<ValueOf<T, K>>> : unknown : unknown;
|
|
49
|
-
};
|
|
50
|
-
type ObjectTransformValue<Value, Obj> = Value extends (...args: any[]) => infer R ? (prev: Obj, ...args: any[]) => Patch<Obj extends Record<string, unknown> ? Obj : never> & ExcessCheck<R, Obj> : DefaultObjectTransform<Obj extends Record<string, unknown> ? Obj : never, Obj extends Record<string, unknown> ? Obj : never> & Record<Exclude<keyof Value, AllKeysOf<Obj>>, never>;
|
|
51
|
-
type OperationTransformValue<Value, Op> = Value extends (...args: any[]) => infer R ? (b: {
|
|
52
|
-
data: Op extends {
|
|
52
|
+
type OperationTransform<T> = (b: {
|
|
53
|
+
data: T extends {
|
|
53
54
|
data: infer U;
|
|
54
55
|
} ? U : never;
|
|
55
|
-
variables:
|
|
56
|
+
variables: T extends {
|
|
56
57
|
variables: infer U;
|
|
57
58
|
} ? U : never;
|
|
58
|
-
}, ...args: any[]) => Patch<
|
|
59
|
-
|
|
60
|
-
* Self-referential constraint that ensures:
|
|
61
|
-
* 1. Top-level keys are known type/input/operation names (unknown → never)
|
|
62
|
-
* 2. Transform values don't have excess properties
|
|
63
|
-
*/
|
|
64
|
-
export type Transforms<T, Objects extends Record<string, Record<string, unknown>>, Queries, Mutations, Subscriptions, Types extends Record<string, Record<string, unknown>>, Inputs extends Record<string, Record<string, unknown>>> = {
|
|
65
|
-
[K in keyof T]: K extends keyof Objects ? {
|
|
66
|
-
[TK in keyof T[K]]: ObjectTransformValue<T[K][TK], Objects[K]>;
|
|
67
|
-
} : K extends keyof ResolveConflicts<Queries, Mutations, Subscriptions, Types, Inputs> ? {
|
|
68
|
-
[TK in keyof T[K]]: OperationTransformValue<T[K][TK], ResolveConflicts<Queries, Mutations, Subscriptions, Types, Inputs>[K]>;
|
|
69
|
-
} : never;
|
|
70
|
-
};
|
|
59
|
+
}, ...args: any[]) => Patch<T>;
|
|
60
|
+
type InferOperationTransforms<T> = DefaultOperationTransform<T> | OperationTransform<T>;
|
|
71
61
|
export type Build<Queries, Mutations, Subscriptions, Types, Inputs, Transforms, Extra> = MapObjectsToBuilders<Types & Inputs, Transforms> & MapOperationsToBuilders<ResolveConflicts<Queries, Mutations, Subscriptions, Types, Inputs>, Transforms, Extra>;
|
|
72
62
|
export {};
|
package/types/init.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DocumentNode } from "graphql";
|
|
2
|
-
import type { Build,
|
|
2
|
+
import type { Build, MapObjectsToTransforms, MapOperationsToTransforms } from "./extendedTypes.js";
|
|
3
3
|
import type { ContravariantEmpty, OperationMock } from "./types.js";
|
|
4
4
|
/** A GraphQL document can be provided as a string or a pre-parsed DocumentNode. */
|
|
5
5
|
export type DocumentInput = string | DocumentNode;
|
|
@@ -30,4 +30,4 @@ export declare const init: <Query extends Record<string, {
|
|
|
30
30
|
/** Load an operation document from a path. Returns string or DocumentNode. */
|
|
31
31
|
loadDocument?: (path: string) => DocumentInput;
|
|
32
32
|
finalizeOperation?: <T extends OperationMock & Partial<Extra>>(operation: T) => T;
|
|
33
|
-
}) => <
|
|
33
|
+
}) => <Transforms extends MapObjectsToTransforms<Types & Inputs> & MapOperationsToTransforms<Query, Mutation, Subscription, Types, Inputs>>(fn: (b: Build<Query, Mutation, Subscription, Types, Inputs, ContravariantEmpty, Extra>) => Transforms) => Build<Query, Mutation, Subscription, Types, Inputs, Transforms, Extra>;
|