Comparing version 0.0.5 to 0.0.6
# @gqlb/core | ||
## 0.0.6 | ||
### Patch Changes | ||
- ce41291: Remove FragmentRef<F> in favor of FragmentData<F>. | ||
Added enumValue() function to create static enums. | ||
Selections now evaluated lazily upon first `.document()` call. | ||
## 0.0.5 | ||
@@ -4,0 +12,0 @@ |
import { Field, FragmentDefinition, FragmentDefinitionWithVariables as FragmentDefinitionWithVariables, InlineFragment, FragmentSpread, Operation } from "./runtime"; | ||
declare const FragmentRefKey: unique symbol; | ||
export type ResponseKey<F extends Field> = F extends Field<infer Name, infer Alias> ? Alias extends string ? Alias : Name : never; | ||
@@ -14,12 +13,8 @@ export type ResponseKeyObj<F extends Field, O> = { | ||
export type FragmentName<T extends FragmentDefinition | FragmentDefinitionWithVariables> = T extends FragmentDefinition<infer N> | FragmentDefinitionWithVariables<infer N> ? N : never; | ||
export type FragmentRefObj<T extends FragmentDefinition | FragmentDefinitionWithVariables> = { | ||
readonly [FragmentRefKey]: FragmentName<T>; | ||
}; | ||
export type FragmentRef<T extends FragmentDefinition | FragmentDefinitionWithVariables> = FragmentData<T> extends infer U ? IntersectWithFragmentRefUnion<U, FragmentRefObj<T>> : never; | ||
export type FragmentData<T extends FragmentDefinition | FragmentDefinitionWithVariables> = T extends FragmentDefinition<any, any, any, infer O> ? O : T extends FragmentDefinitionWithVariables<any, any, any, any, infer O> ? O : never; | ||
export type FragmentOutput<T extends InlineFragment | FragmentDefinition | FragmentDefinitionWithVariables, PT extends string> = NeverToEmptyObj<Extract<IntersectWithFragmentRefUnion<SelectionOutput<T>, T extends FragmentDefinition | FragmentDefinitionWithVariables ? FragmentRefObj<T> : {}>, { | ||
export type FragmentOutput<T extends InlineFragment | FragmentDefinition | FragmentDefinitionWithVariables, PT extends string> = NeverToEmptyObj<Extract<SelectionOutput<T>, { | ||
readonly __typename: PT; | ||
}>>; | ||
type IntersectWithFragmentRefUnion<A, B> = Omit<A, typeof FragmentRefKey> & Omit<B, typeof FragmentRefKey> & { | ||
[FragmentRefKey]: A[typeof FragmentRefKey & keyof A] | B[typeof FragmentRefKey & keyof B]; | ||
type ReadonlyMerge<A, B> = A extends Function ? never : { | ||
readonly [K in keyof A | keyof B]: K extends keyof A ? A[K] : K extends keyof B ? B[K] : never; | ||
}; | ||
@@ -31,7 +26,11 @@ export type BuildSelectionSet<T extends ReadonlyArray<SelectionSetSelection>, PT extends string, Acc = { | ||
...infer Tail extends ReadonlyArray<SelectionSetSelection> | ||
] ? Head extends Field ? BuildSelectionSet<Tail, PT, Acc & ResponseKeyObj<Head, SelectionOutput<Head>>> : Head extends FragmentSpread<infer F extends FragmentDefinition | FragmentDefinitionWithVariables> ? BuildSelectionSet<Tail, PT, IntersectWithFragmentRefUnion<Acc, FragmentOutput<F, PT>>> : Head extends InlineFragment ? BuildSelectionSet<Tail, PT, Acc & FragmentOutput<Head, PT>> : never : Acc; | ||
] ? Head extends Field ? BuildSelectionSet<Tail, PT, Acc & ResponseKeyObj<Head, SelectionOutput<Head>>> : Head extends FragmentSpread<infer F extends FragmentDefinition | FragmentDefinitionWithVariables> ? BuildSelectionSet<Tail, PT, ReadonlyMerge<Acc, FragmentOutput<F, PT>>> : Head extends InlineFragment ? BuildSelectionSet<Tail, PT, Acc & FragmentOutput<Head, PT>> : never : Acc; | ||
export type SelectionSetOutput<T extends ReadonlyArray<SelectionSetSelection>, PossibleTypes extends string> = T extends Function ? never : PossibleTypes extends infer PT ? ReadonlyIntersectionCollapse<BuildSelectionSet<T, PT & string>> : never; | ||
export type OutputOf<T> = T extends Operation<infer Output> ? Output : SelectionOutput<T>; | ||
export type OutputOf<T> = T extends Operation<infer Output> ? Output : T extends FragmentDefinitionWithVariables<any, any, any, infer Output> ? Output : T extends FragmentDefinition<any, any, any, infer Output> ? Output : SelectionOutput<T>; | ||
export type VariablesOf<T> = T extends Operation<any, infer Variables> ? Variables : T extends FragmentDefinitionWithVariables<any, any, any, infer Variables> ? Variables : never; | ||
export declare const EnumValueSymbol: unique symbol; | ||
export type EnumValue<T> = { | ||
readonly [EnumValueSymbol]: T; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=helpers.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EnumValueSymbol = void 0; | ||
exports.EnumValueSymbol = Symbol("EnumValue"); | ||
//# sourceMappingURL=helpers.js.map |
import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; | ||
import { type ArgumentNode, type FieldNode, type FragmentDefinitionNode, type FragmentSpreadNode, type InlineFragmentNode, type VariableDefinitionNode, type VariableNode } from "graphql"; | ||
import { SelectionSetSelection } from "./helpers"; | ||
import { SelectionSetSelection, EnumValue } from "./helpers"; | ||
type Field_ArgumentsArg = Record<string, unknown>; | ||
@@ -56,3 +56,3 @@ type Field_BuilderArg = (b: BuilderObject) => ReadonlyArray<SelectionSetSelection>; | ||
private cache; | ||
constructor(name: Name, typeCondition: TypeCondition, selections: ReadonlyArray<SelectionSetSelection>); | ||
constructor(name: Name, typeCondition: TypeCondition, selections: () => ReadonlyArray<SelectionSetSelection>); | ||
collectFragments(map: FragmentMap): void; | ||
@@ -99,5 +99,5 @@ definition(): FragmentDefinitionNode; | ||
readonly variableDefinitions: ReadonlyArray<VariableDefinitionNode>; | ||
readonly selections: ReadonlyArray<SelectionSetSelection>; | ||
readonly selections: () => ReadonlyArray<SelectionSetSelection>; | ||
private cache; | ||
constructor(name: string, type: "query" | "mutation" | "subscription", variableDefinitions: ReadonlyArray<VariableDefinitionNode>, selections: ReadonlyArray<SelectionSetSelection>); | ||
constructor(name: string, type: "query" | "mutation" | "subscription", variableDefinitions: ReadonlyArray<VariableDefinitionNode>, selections: () => ReadonlyArray<SelectionSetSelection>); | ||
document(): TypedDocumentNode<Output, Variables>; | ||
@@ -112,2 +112,3 @@ /** | ||
declare const variableSymbol: unique symbol; | ||
export declare function enumValue<T extends string>(value: T): EnumValue<T>; | ||
type Operation_VariablesArg = Record<string, string>; | ||
@@ -114,0 +115,0 @@ type Operation_BuilderArg = (b: BuilderObject, variables: Record<string, { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.builder = exports.Operation = exports.FragmentSpread = exports.FragmentDefinitionWithVariables = exports.FragmentDefinition = exports.InlineFragment = exports.Field = void 0; | ||
exports.builder = exports.enumValue = exports.Operation = exports.FragmentSpread = exports.FragmentDefinitionWithVariables = exports.FragmentDefinition = exports.InlineFragment = exports.Field = void 0; | ||
const graphql_1 = require("graphql"); | ||
const helpers_1 = require("./helpers"); | ||
class FragmentMap extends Map { | ||
@@ -87,2 +88,8 @@ fragments = new Set(); | ||
} | ||
if (helpers_1.EnumValueSymbol in value) { | ||
return { | ||
kind: "EnumValue", | ||
value: String(value[helpers_1.EnumValueSymbol]), | ||
}; | ||
} | ||
return { | ||
@@ -106,3 +113,2 @@ kind: "ObjectValue", | ||
kind: "Field", | ||
alias: undefined, | ||
arguments: [], | ||
@@ -114,3 +120,2 @@ directives: [], | ||
}, | ||
selectionSet: undefined, | ||
}, | ||
@@ -161,12 +166,14 @@ ]; | ||
directives: [], | ||
alias: this._alias | ||
...(this._alias | ||
? { | ||
kind: "Name", | ||
value: this._alias, | ||
alias: { | ||
kind: "Name", | ||
value: this._alias, | ||
}, | ||
} | ||
: undefined, | ||
: {}), | ||
arguments: this.args, | ||
selectionSet: this.selections | ||
? createSelectionSet(this.selections) | ||
: undefined, | ||
...(this.selections | ||
? { selectionSet: createSelectionSet(this.selections) } | ||
: {}), | ||
}; | ||
@@ -254,3 +261,3 @@ } | ||
map.set(this.name, this); | ||
for (const selection of this.selections) { | ||
for (const selection of this.selections()) { | ||
selection.collectFragments(map); | ||
@@ -273,3 +280,3 @@ } | ||
}, | ||
selectionSet: createSelectionSet(this.selections), | ||
selectionSet: createSelectionSet(this.selections()), | ||
}; | ||
@@ -457,3 +464,3 @@ } | ||
const fragmentMap = new FragmentMap(); | ||
for (const selection of this.selections) { | ||
for (const selection of this.selections()) { | ||
selection.collectFragments(fragmentMap); | ||
@@ -474,3 +481,3 @@ } | ||
variableDefinitions: this.variableDefinitions, | ||
selectionSet: createSelectionSet(this.selections), | ||
selectionSet: createSelectionSet(this.selections()), | ||
}, | ||
@@ -560,2 +567,8 @@ ], | ||
const variableSymbol = Symbol.for("variable"); | ||
function enumValue(value) { | ||
return { | ||
[helpers_1.EnumValueSymbol]: value, | ||
}; | ||
} | ||
exports.enumValue = enumValue; | ||
function makeOperationBuilder(type) { | ||
@@ -570,3 +583,2 @@ return function builderOperation(name, arg1, arg2) { | ||
kind: "VariableDefinition", | ||
defaultValue: undefined, | ||
directives: [], | ||
@@ -593,4 +605,3 @@ variable: { | ||
} | ||
const selections = builder(makeBuilderObject(), variables); | ||
return new Operation(name, type, variableDefinitions, selections); | ||
return new Operation(name, type, variableDefinitions, () => builder(makeBuilderObject(), variables)); | ||
}; | ||
@@ -625,4 +636,3 @@ } | ||
} | ||
const selections = builder(makeBuilderObject(), variables); | ||
return new FragmentDefinition(name, typeCondition, selections); | ||
return new FragmentDefinition(name, typeCondition, () => builder(makeBuilderObject(), variables)); | ||
}; | ||
@@ -629,0 +639,0 @@ } |
{ | ||
"name": "@gqlb/core", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,4 +10,2 @@ import { | ||
declare const FragmentRefKey: unique symbol; | ||
export type ResponseKey<F extends Field> = F extends Field< | ||
@@ -62,14 +60,2 @@ infer Name, | ||
export type FragmentRefObj< | ||
T extends FragmentDefinition | FragmentDefinitionWithVariables, | ||
> = { | ||
readonly [FragmentRefKey]: FragmentName<T>; | ||
}; | ||
export type FragmentRef< | ||
T extends FragmentDefinition | FragmentDefinitionWithVariables, | ||
> = FragmentData<T> extends infer U | ||
? IntersectWithFragmentRefUnion<U, FragmentRefObj<T>> | ||
: never; | ||
export type FragmentData< | ||
@@ -89,20 +75,13 @@ T extends FragmentDefinition | FragmentDefinitionWithVariables, | ||
PT extends string, | ||
> = NeverToEmptyObj< | ||
Extract< | ||
IntersectWithFragmentRefUnion< | ||
SelectionOutput<T>, | ||
T extends FragmentDefinition | FragmentDefinitionWithVariables | ||
? FragmentRefObj<T> | ||
: {} | ||
>, | ||
{ readonly __typename: PT } | ||
> | ||
>; | ||
> = NeverToEmptyObj<Extract<SelectionOutput<T>, { readonly __typename: PT }>>; | ||
type IntersectWithFragmentRefUnion<A, B> = Omit<A, typeof FragmentRefKey> & | ||
Omit<B, typeof FragmentRefKey> & { | ||
[FragmentRefKey]: | ||
| A[typeof FragmentRefKey & keyof A] | ||
| B[typeof FragmentRefKey & keyof B]; | ||
}; | ||
type ReadonlyMerge<A, B> = A extends Function | ||
? never | ||
: { | ||
readonly [K in keyof A | keyof B]: K extends keyof A | ||
? A[K] | ||
: K extends keyof B | ||
? B[K] | ||
: never; | ||
}; | ||
@@ -128,7 +107,3 @@ export type BuildSelectionSet< | ||
> | ||
? BuildSelectionSet< | ||
Tail, | ||
PT, | ||
IntersectWithFragmentRefUnion<Acc, FragmentOutput<F, PT>> | ||
> | ||
? BuildSelectionSet<Tail, PT, ReadonlyMerge<Acc, FragmentOutput<F, PT>>> | ||
: Head extends InlineFragment | ||
@@ -150,3 +125,8 @@ ? BuildSelectionSet<Tail, PT, Acc & FragmentOutput<Head, PT>> | ||
? Output | ||
: SelectionOutput<T>; | ||
: T extends FragmentDefinitionWithVariables<any, any, any, infer Output> | ||
? Output | ||
: T extends FragmentDefinition<any, any, any, infer Output> | ||
? Output | ||
: SelectionOutput<T>; | ||
export type VariablesOf<T> = T extends Operation<any, infer Variables> | ||
@@ -157,1 +137,6 @@ ? Variables | ||
: never; | ||
export const EnumValueSymbol = Symbol("EnumValue"); | ||
export type EnumValue<T> = { | ||
readonly [EnumValueSymbol]: T; | ||
}; |
@@ -18,3 +18,3 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; | ||
} from "graphql"; | ||
import { SelectionSetSelection } from "./helpers"; | ||
import { SelectionSetSelection, EnumValueSymbol, EnumValue } from "./helpers"; | ||
@@ -169,2 +169,8 @@ type Field_ArgumentsArg = Record<string, unknown>; | ||
} | ||
if (EnumValueSymbol in value) { | ||
return { | ||
kind: "EnumValue" as Kind.ENUM, | ||
value: String(value[EnumValueSymbol]), | ||
}; | ||
} | ||
return { | ||
@@ -191,3 +197,2 @@ kind: "ObjectValue" as Kind.OBJECT, | ||
kind: "Field" as Kind.FIELD, | ||
alias: undefined, | ||
arguments: [], | ||
@@ -199,3 +204,2 @@ directives: [], | ||
}, | ||
selectionSet: undefined, | ||
}, | ||
@@ -260,12 +264,14 @@ ]; | ||
directives: [], | ||
alias: this._alias | ||
...(this._alias | ||
? { | ||
kind: "Name" as Kind.NAME, | ||
value: this._alias, | ||
alias: { | ||
kind: "Name" as Kind.NAME, | ||
value: this._alias, | ||
}, | ||
} | ||
: undefined, | ||
: {}), | ||
arguments: this.args, | ||
selectionSet: this.selections | ||
? createSelectionSet(this.selections) | ||
: undefined, | ||
...(this.selections | ||
? { selectionSet: createSelectionSet(this.selections) } | ||
: {}), | ||
}; | ||
@@ -362,3 +368,3 @@ } | ||
public readonly typeCondition: TypeCondition, | ||
private selections: ReadonlyArray<SelectionSetSelection> | ||
private selections: () => ReadonlyArray<SelectionSetSelection> | ||
) { | ||
@@ -373,3 +379,3 @@ super(); | ||
map.set(this.name, this); | ||
for (const selection of this.selections) { | ||
for (const selection of this.selections()) { | ||
selection.collectFragments(map); | ||
@@ -393,3 +399,3 @@ } | ||
}, | ||
selectionSet: createSelectionSet(this.selections)!, | ||
selectionSet: createSelectionSet(this.selections())!, | ||
}; | ||
@@ -628,3 +634,3 @@ } | ||
public readonly variableDefinitions: ReadonlyArray<VariableDefinitionNode>, | ||
public readonly selections: ReadonlyArray<SelectionSetSelection> | ||
public readonly selections: () => ReadonlyArray<SelectionSetSelection> | ||
) {} | ||
@@ -638,3 +644,3 @@ | ||
const fragmentMap = new FragmentMap(); | ||
for (const selection of this.selections) { | ||
for (const selection of this.selections()) { | ||
selection.collectFragments(fragmentMap); | ||
@@ -655,3 +661,3 @@ } | ||
variableDefinitions: this.variableDefinitions, | ||
selectionSet: createSelectionSet(this.selections), | ||
selectionSet: createSelectionSet(this.selections()), | ||
}, | ||
@@ -752,2 +758,8 @@ ], | ||
export function enumValue<T extends string>(value: T): EnumValue<T> { | ||
return { | ||
[EnumValueSymbol]: value, | ||
}; | ||
} | ||
type Operation_VariablesArg = Record<string, string>; | ||
@@ -772,3 +784,2 @@ type Operation_BuilderArg = ( | ||
kind: "VariableDefinition" as Kind.VARIABLE_DEFINITION, | ||
defaultValue: undefined, | ||
directives: [], | ||
@@ -795,4 +806,5 @@ variable: { | ||
const selections = builder(makeBuilderObject(), variables); | ||
return new Operation(name, type, variableDefinitions, selections); | ||
return new Operation(name, type, variableDefinitions, () => | ||
builder(makeBuilderObject(), variables) | ||
); | ||
}; | ||
@@ -857,4 +869,5 @@ } | ||
} | ||
const selections = builder(makeBuilderObject(), variables); | ||
return new FragmentDefinition(name, typeCondition, selections); | ||
return new FragmentDefinition(name, typeCondition, () => | ||
builder(makeBuilderObject(), variables) | ||
); | ||
}; | ||
@@ -861,0 +874,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83104
1755