@schema-hub/zod-graphql-query-builder 0.0.17 → 0.0.19
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/sbom.cdx.json +5 -5
- package/zod-graphql-query-builder/build-context.js +1 -9
- package/zod-graphql-query-builder/build-context.js.map +1 -1
- package/zod-graphql-query-builder/builder.d.ts +0 -8
- package/zod-graphql-query-builder/builder.d.ts.map +1 -1
- package/zod-graphql-query-builder/builder.js +7 -41
- package/zod-graphql-query-builder/builder.js.map +1 -1
- package/zod-graphql-query-builder/custom-scalar.d.ts +0 -1
- package/zod-graphql-query-builder/custom-scalar.d.ts.map +1 -1
- package/zod-graphql-query-builder/custom-scalar.js +1 -12
- package/zod-graphql-query-builder/custom-scalar.js.map +1 -1
- package/zod-graphql-query-builder/fragment-definitions.js +0 -14
- package/zod-graphql-query-builder/fragment-definitions.js.map +1 -1
- package/zod-graphql-query-builder/root-shape.js +0 -6
- package/zod-graphql-query-builder/root-shape.js.map +1 -1
- package/zod-graphql-query-builder/serializer.js +6 -309
- package/zod-graphql-query-builder/serializer.js.map +1 -1
- package/zod-graphql-query-builder/type-name.d.ts +0 -3
- package/zod-graphql-query-builder/type-name.d.ts.map +1 -1
- package/zod-graphql-query-builder/type-name.js +3 -43
- package/zod-graphql-query-builder/type-name.js.map +1 -1
- package/zod-graphql-query-builder/values/enum.d.ts +0 -1
- package/zod-graphql-query-builder/values/enum.d.ts.map +1 -1
- package/zod-graphql-query-builder/values/enum.js +2 -15
- package/zod-graphql-query-builder/values/enum.js.map +1 -1
- package/zod-graphql-query-builder/values/name.js +0 -4
- package/zod-graphql-query-builder/values/name.js.map +1 -1
- package/zod-graphql-query-builder/values/parameter-list.js +3 -24
- package/zod-graphql-query-builder/values/parameter-list.js.map +1 -1
- package/zod-graphql-query-builder/values/record.js +0 -6
- package/zod-graphql-query-builder/values/record.js.map +1 -1
- package/zod-graphql-query-builder/values/value.d.ts +0 -5
- package/zod-graphql-query-builder/values/value.d.ts.map +1 -1
- package/zod-graphql-query-builder/values/value.js +5 -76
- package/zod-graphql-query-builder/values/value.js.map +1 -1
- package/zod-graphql-query-builder/values/variable-set.js +0 -3
- package/zod-graphql-query-builder/values/variable-set.js.map +1 -1
- package/zod-graphql-query-builder/variable-correlations.js +0 -13
- package/zod-graphql-query-builder/variable-correlations.js.map +1 -1
- package/zod-graphql-query-builder/variable-definition.d.ts +0 -1
- package/zod-graphql-query-builder/variable-definition.d.ts.map +1 -1
- package/zod-graphql-query-builder/variable-definition.js +2 -27
- package/zod-graphql-query-builder/variable-definition.js.map +1 -1
- package/zod-graphql-query-builder/variable-type.js +1 -10
- package/zod-graphql-query-builder/variable-type.js.map +1 -1
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
{
|
|
10
10
|
"type": "application",
|
|
11
11
|
"name": "packtory",
|
|
12
|
-
"version": "0.0.
|
|
12
|
+
"version": "0.0.102"
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
16
|
"component": {
|
|
17
17
|
"type": "library",
|
|
18
18
|
"name": "@schema-hub/zod-graphql-query-builder",
|
|
19
|
-
"version": "0.0.
|
|
20
|
-
"bom-ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.
|
|
21
|
-
"purl": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.
|
|
19
|
+
"version": "0.0.19",
|
|
20
|
+
"bom-ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.19",
|
|
21
|
+
"purl": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.19"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"components": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
],
|
|
52
52
|
"dependencies": [
|
|
53
53
|
{
|
|
54
|
-
"ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.
|
|
54
|
+
"ref": "pkg:npm/@schema-hub/zod-graphql-query-builder@0.0.19",
|
|
55
55
|
"dependsOn": [
|
|
56
56
|
"pkg:npm/graphql@17.0.2",
|
|
57
57
|
"pkg:npm/zod@%5E4.0.5"
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./serializer.js";
|
|
2
2
|
/* eslint-enable functional/type-declaration-immutability, enormora-typescript/prefer-readonly-types -- end of the mutable accumulator type */
|
|
3
|
-
export function createBuildContext(registry, rootShape) {
|
|
4
|
-
return {
|
|
5
|
-
counts: collectSchemaReferences(registry, rootShape),
|
|
6
|
-
nameForSchema: new Map(),
|
|
7
|
-
counterPerTypeName: new Map(),
|
|
8
|
-
definitions: new Map()
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
3
|
//# sourceMappingURL=build-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-context.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/build-context.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"build-context.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/build-context.ts"],"names":[],"mappings":"AAEA,OAAwC,iBAAiB,CAAC;AAY1D,8IAA8I"}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import type { FieldSchema, QuerySchema } from './query-schema.ts';
|
|
2
|
-
import type { GraphqlFieldOptions } from './type-name.ts';
|
|
3
1
|
import { type VariableDefinitions } from './variable-definition.ts';
|
|
4
2
|
export type OperationOptions = {
|
|
5
3
|
readonly operationName?: string | undefined;
|
|
6
4
|
readonly variableDefinitions?: VariableDefinitions | undefined;
|
|
7
5
|
};
|
|
8
|
-
export type QueryBuilder = {
|
|
9
|
-
registerFieldOptions: <Schema extends FieldSchema>(schema: Schema, options: GraphqlFieldOptions) => Schema;
|
|
10
|
-
buildQuery: (schema: QuerySchema, options?: OperationOptions) => string;
|
|
11
|
-
buildMutation: (schema: QuerySchema, options?: OperationOptions) => string;
|
|
12
|
-
};
|
|
13
|
-
export declare function createQueryBuilder(): QueryBuilder;
|
|
14
6
|
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAEA,OAAY,OAMgC,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAElG,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;CAClE,CAAC"}
|
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function withTrailingSpace(value) {
|
|
9
|
-
if (value.length === 0) {
|
|
10
|
-
return value;
|
|
11
|
-
}
|
|
12
|
-
return `${value} `;
|
|
13
|
-
}
|
|
14
|
-
function buildDocument(registry, documentType, schema, options) {
|
|
15
|
-
const { variableDefinitions = {}, operationName = '' } = options;
|
|
16
|
-
const shape = extractRootShape(schema);
|
|
17
|
-
const context = createBuildContext(registry, shape);
|
|
18
|
-
const { bodyEntries, referencedVariables } = serializeRootShape(registry, shape, context);
|
|
19
|
-
ensureValidVariableCorrelations(variableDefinitions, referencedVariables);
|
|
20
|
-
const operationNameAndParams = withTrailingSpace(`${operationName}${serializeVariableDefinitions(variableDefinitions)}`);
|
|
21
|
-
const operationOutput = `${documentType} ${operationNameAndParams}{ ${bodyEntries.join(', ')} }`;
|
|
22
|
-
return operationOutput + formatFragmentDefinitions(context.definitions);
|
|
23
|
-
}
|
|
24
|
-
export function createQueryBuilder() {
|
|
25
|
-
const fieldOptionsRegistry = new WeakMap();
|
|
26
|
-
return {
|
|
27
|
-
registerFieldOptions(schema, options) {
|
|
28
|
-
if (options.typeName !== undefined && !isValidGraphqlName(options.typeName)) {
|
|
29
|
-
throw new Error(`Invalid GraphQL type name: "${options.typeName}". A type name must match /^[A-Z_a-z]\\w*$/.`);
|
|
30
|
-
}
|
|
31
|
-
fieldOptionsRegistry.set(schema, options);
|
|
32
|
-
return schema;
|
|
33
|
-
},
|
|
34
|
-
buildQuery(schema, options = {}) {
|
|
35
|
-
return buildDocument(fieldOptionsRegistry, 'query', schema, options);
|
|
36
|
-
},
|
|
37
|
-
buildMutation(schema, options = {}) {
|
|
38
|
-
return buildDocument(fieldOptionsRegistry, 'mutation', schema, options);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
1
|
+
import "./build-context.js";
|
|
2
|
+
import "./fragment-definitions.js";
|
|
3
|
+
import "./root-shape.js";
|
|
4
|
+
import "./serializer.js";
|
|
5
|
+
import "./values/name.js";
|
|
6
|
+
import "./variable-correlations.js";
|
|
7
|
+
import "./variable-definition.js";
|
|
42
8
|
//# sourceMappingURL=builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/builder.ts"],"names":[],"mappings":"AAAA,OAAmC,oBAAoB,CAAC;AACxD,OAA0C,2BAA2B,CAAC;AAEtE,OAAiC,iBAAiB,CAAC;AACnD,OAAmC,iBAAiB,CAAC;AAErD,OAAmC,kBAAkB,CAAC;AACtD,OAAgD,4BAA4B,CAAC;AAC7E,OAAuE,0BAA0B,CAAC"}
|
|
@@ -3,7 +3,6 @@ declare const customScalarSymbol: unique symbol;
|
|
|
3
3
|
export type CustomScalarSchema<Schema extends $ZodType> = $ZodLazy<Schema> & {
|
|
4
4
|
readonly [customScalarSymbol]: true;
|
|
5
5
|
};
|
|
6
|
-
export declare function isCustomScalarSchema(schema: $ZodType): schema is CustomScalarSchema<$ZodType>;
|
|
7
6
|
export declare function createCustomScalarSchema<Schema extends $ZodType>(schema: Schema): CustomScalarSchema<Schema>;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=custom-scalar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-scalar.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,kBAAkB,EAAE,OAAO,MAAgC,CAAC;AAGlE,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG;IACzE,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC;CACvC,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"custom-scalar.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,QAAA,MAAM,kBAAkB,EAAE,OAAO,MAAgC,CAAC;AAGlE,MAAM,MAAM,kBAAkB,CAAC,MAAM,SAAS,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG;IACzE,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC;CACvC,CAAC;AAEF,gDAIwC,CAAC,MAAM,SAAS,QAAQ,EAC5D,MAAM,EAAE,MAAM,GACf,kBAAkB,CAAC,MAAM,CAAC,CAO5B"}
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
const customScalarSymbol = Symbol('custom-scalar');
|
|
3
|
-
export function isCustomScalarSchema(schema) {
|
|
4
|
-
return Object.hasOwn(schema, customScalarSymbol);
|
|
5
|
-
}
|
|
6
|
-
export function createCustomScalarSchema(schema) {
|
|
7
|
-
const wrappedSchema = z.lazy(function () {
|
|
8
|
-
return schema;
|
|
9
|
-
});
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- branding the lazy schema with the custom-scalar marker symbol can't be expressed structurally
|
|
11
|
-
return Object.assign(wrappedSchema, { [customScalarSymbol]: true });
|
|
12
|
-
}
|
|
1
|
+
import 'zod/v4-mini';
|
|
13
2
|
//# sourceMappingURL=custom-scalar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-scalar.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"custom-scalar.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/custom-scalar.ts"],"names":[],"mappings":"AAAA,OAAkB,aAAa,CAAC;AAqB5B"}
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export function formatFragmentDefinitions(definitions) {
|
|
2
|
-
if (definitions.size === 0) {
|
|
3
|
-
return '';
|
|
4
|
-
}
|
|
5
|
-
const sortedEntries = Array
|
|
6
|
-
.from(definitions)
|
|
7
|
-
.toSorted(function ([nameA], [nameB]) {
|
|
8
|
-
return nameA.localeCompare(nameB);
|
|
9
|
-
});
|
|
10
|
-
const formatted = sortedEntries.map(function ([name, definition]) {
|
|
11
|
-
return `fragment ${name} on ${definition.typeName}${definition.body}`;
|
|
12
|
-
});
|
|
13
|
-
return ` ${formatted.join(' ')}`;
|
|
14
|
-
}
|
|
15
1
|
//# sourceMappingURL=fragment-definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragment-definitions.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/fragment-definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fragment-definitions.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/fragment-definitions.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-shape.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/root-shape.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"root-shape.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/root-shape.ts"],"names":[],"mappings":""}
|
|
@@ -1,312 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle -- we need to access _zod */
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
const minimumReuseCountForFragment = 2;
|
|
9
|
-
const cyclicSchemaErrorMessage = 'Cyclic schema detected without a resolvable GraphQL type name. ' +
|
|
10
|
-
"Register it with graphqlFieldOptions(schema, { typeName: '...' }) " +
|
|
11
|
-
"or add `__typename: z.literal('...')` to its shape so the builder can emit a named fragment.";
|
|
12
|
-
function unwrapFromArraySchema(predicate, schema) {
|
|
13
|
-
const elementSchema = unwrapFieldSchema(schema._zod.def.element);
|
|
14
|
-
if (predicate(elementSchema)) {
|
|
15
|
-
return elementSchema;
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
function unwrapFromTupleSchema(predicate, schema) {
|
|
20
|
-
const { items } = schema._zod.def;
|
|
21
|
-
const [firstElementSchema] = items;
|
|
22
|
-
const unwrappedElementSchema = unwrapFieldSchema(firstElementSchema);
|
|
23
|
-
if (predicate(unwrappedElementSchema)) {
|
|
24
|
-
return unwrappedElementSchema;
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
function getObjectSchema(schema) {
|
|
29
|
-
if (isStrictObjectSchema(schema)) {
|
|
30
|
-
return schema;
|
|
31
|
-
}
|
|
32
|
-
if (isFieldArraySchema(schema)) {
|
|
33
|
-
return unwrapFromArraySchema(isStrictObjectSchema, schema);
|
|
34
|
-
}
|
|
35
|
-
return unwrapFromTupleSchema(isStrictObjectSchema, schema);
|
|
36
|
-
}
|
|
37
|
-
function getUnionSchema(schema) {
|
|
38
|
-
if (isFragmentsSchema(schema)) {
|
|
39
|
-
return schema;
|
|
40
|
-
}
|
|
41
|
-
if (isFieldArraySchema(schema)) {
|
|
42
|
-
return unwrapFromArraySchema(isFragmentsSchema, schema);
|
|
43
|
-
}
|
|
44
|
-
return unwrapFromTupleSchema(isFragmentsSchema, schema);
|
|
45
|
-
}
|
|
46
|
-
function getFieldOptionsForSchema(registry, schema) {
|
|
47
|
-
const unwrappingResult = unwrapFieldSchemaChain(schema);
|
|
48
|
-
const queue = [...unwrappingResult.wrapperElements, unwrappingResult.unwrappedSchema];
|
|
49
|
-
for (const currentSchema of queue) {
|
|
50
|
-
const fieldOptions = registry.get(currentSchema);
|
|
51
|
-
if (fieldOptions !== undefined) {
|
|
52
|
-
return fieldOptions;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
|
-
function serializedFieldSelector(registry, fieldName, fieldSchema) {
|
|
58
|
-
const { aliasFor, parameters } = getFieldOptionsForSchema(registry, fieldSchema);
|
|
59
|
-
const selectorName = aliasFor === undefined ? fieldName : `${fieldName}: ${aliasFor}`;
|
|
60
|
-
if (parameters === undefined) {
|
|
61
|
-
return { serializedValue: selectorName, referencedVariables: new Set() };
|
|
62
|
-
}
|
|
63
|
-
const normalizedParameterList = normalizeParameterList(parameters);
|
|
64
|
-
return {
|
|
65
|
-
serializedValue: `${selectorName}${normalizedParameterList.serializedValue}`,
|
|
66
|
-
referencedVariables: normalizedParameterList.referencedVariables
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function combineFieldSelectorAndFieldBody(fieldSelector, fieldBody) {
|
|
70
|
-
return {
|
|
71
|
-
serializedValue: `${fieldSelector.serializedValue}${fieldBody.serializedValue}`,
|
|
72
|
-
referencedVariables: mergeVariables(fieldSelector.referencedVariables, fieldBody.referencedVariables)
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function getObjectSchemasFromList(unwrapped) {
|
|
76
|
-
if (!isObjectOrListSchema(unwrapped)) {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
const objectSchema = getObjectSchema(unwrapped);
|
|
80
|
-
return objectSchema === null ? [] : [objectSchema];
|
|
81
|
-
}
|
|
82
|
-
function getOptionsFromUnion(unwrapped) {
|
|
83
|
-
if (!isUnionOrListSchema(unwrapped)) {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
const unionSchema = getUnionSchema(unwrapped);
|
|
87
|
-
return unionSchema === null ? [] : unionSchema._zod.def.options;
|
|
88
|
-
}
|
|
89
|
-
function getSchemasToVisit(unwrapped) {
|
|
90
|
-
if (unwrapped instanceof $ZodUndefined) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
const objectSchemas = getObjectSchemasFromList(unwrapped);
|
|
94
|
-
if (objectSchemas.length > 0) {
|
|
95
|
-
return objectSchemas;
|
|
96
|
-
}
|
|
97
|
-
return getOptionsFromUnion(unwrapped);
|
|
98
|
-
}
|
|
99
|
-
function ensureCycleHasResolvableTypeName(registry, objectSchema) {
|
|
100
|
-
if (resolveTypeName(registry, objectSchema) !== null) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
throw new Error(cyclicSchemaErrorMessage);
|
|
104
|
-
}
|
|
105
|
-
export function collectSchemaReferences(registry, rootShape) {
|
|
106
|
-
const counts = new Map();
|
|
107
|
-
const visiting = new Set();
|
|
108
|
-
function visitObject(objectSchema) {
|
|
109
|
-
counts.set(objectSchema, (counts.get(objectSchema) ?? 0) + 1);
|
|
110
|
-
if (visiting.has(objectSchema)) {
|
|
111
|
-
ensureCycleHasResolvableTypeName(registry, objectSchema);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
visiting.add(objectSchema);
|
|
115
|
-
for (const childSchema of Object.values(objectSchema._zod.def.shape)) {
|
|
116
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
117
|
-
visitField(childSchema);
|
|
118
|
-
}
|
|
119
|
-
visiting.delete(objectSchema);
|
|
120
|
-
}
|
|
121
|
-
function visitField(fieldSchema) {
|
|
122
|
-
if (isCustomScalarSchema(fieldSchema)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const unwrapped = unwrapFieldSchema(fieldSchema);
|
|
126
|
-
for (const objectSchema of getSchemasToVisit(unwrapped)) {
|
|
127
|
-
visitObject(objectSchema);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
for (const fieldSchema of Object.values(rootShape)) {
|
|
131
|
-
visitField(fieldSchema);
|
|
132
|
-
}
|
|
133
|
-
return counts;
|
|
134
|
-
}
|
|
2
|
+
import 'zod/v4/core';
|
|
3
|
+
import "./custom-scalar.js";
|
|
4
|
+
import "./query-schema.js";
|
|
5
|
+
import "./type-name.js";
|
|
6
|
+
import "./values/parameter-list.js";
|
|
7
|
+
import "./values/variable-set.js";
|
|
135
8
|
// eslint-disable-next-line functional/prefer-immutable-types -- mutates the shared fragment-name counter in place
|
|
136
|
-
function allocateFragmentName(typeName, counterPerTypeName) {
|
|
137
|
-
const nextIndex = (counterPerTypeName.get(typeName) ?? 0) + 1;
|
|
138
|
-
counterPerTypeName.set(typeName, nextIndex);
|
|
139
|
-
return `${typeName}_${nextIndex}`;
|
|
140
|
-
}
|
|
141
|
-
function tryAllocateFragmentForSchema(registry, objectSchema, context) {
|
|
142
|
-
const count = context.counts.get(objectSchema) ?? 0;
|
|
143
|
-
if (count < minimumReuseCountForFragment) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
const typeName = resolveTypeName(registry, objectSchema);
|
|
147
|
-
if (typeName === null) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
const fragmentName = allocateFragmentName(typeName, context.counterPerTypeName);
|
|
151
|
-
context.nameForSchema.set(objectSchema, fragmentName);
|
|
152
|
-
return { fragmentName, typeName };
|
|
153
|
-
}
|
|
154
|
-
function storeFragmentDefinition(registry, allocation, objectSchema, context) {
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
156
|
-
const body = serializeObjectSchemaInline(registry, objectSchema, context);
|
|
157
|
-
context.definitions.set(allocation.fragmentName, {
|
|
158
|
-
typeName: allocation.typeName,
|
|
159
|
-
body: body.serializedValue,
|
|
160
|
-
referencedVariables: body.referencedVariables
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function maybeAssignFragmentName(registry, objectSchema, context) {
|
|
164
|
-
const existing = context.nameForSchema.get(objectSchema);
|
|
165
|
-
if (existing !== undefined) {
|
|
166
|
-
return existing;
|
|
167
|
-
}
|
|
168
|
-
const allocation = tryAllocateFragmentForSchema(registry, objectSchema, context);
|
|
169
|
-
if (allocation === null) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
storeFragmentDefinition(registry, allocation, objectSchema, context);
|
|
173
|
-
return allocation.fragmentName;
|
|
174
|
-
}
|
|
175
|
-
function serializeObjectSchemaInline(registry, objectSchema, context) {
|
|
176
|
-
const entries = Object
|
|
177
|
-
.entries(objectSchema._zod.def.shape)
|
|
178
|
-
.toSorted(function ([nameA], [nameB]) {
|
|
179
|
-
return nameA.localeCompare(nameB);
|
|
180
|
-
});
|
|
181
|
-
let referencedVariables = new Set();
|
|
182
|
-
const serializedEntries = [];
|
|
183
|
-
for (const [fieldName, fieldSchema] of entries) {
|
|
184
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- recursion
|
|
185
|
-
const serializedField = serializeFieldSchema(registry, fieldName, fieldSchema, context);
|
|
186
|
-
referencedVariables = mergeVariables(referencedVariables, serializedField.referencedVariables);
|
|
187
|
-
serializedEntries.push(serializedField.serializedValue);
|
|
188
|
-
}
|
|
189
|
-
return {
|
|
190
|
-
serializedValue: ` { ${serializedEntries.join(', ')} }`,
|
|
191
|
-
referencedVariables
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function serializeFragmentReference(assignedName, context) {
|
|
195
|
-
const definition = context.definitions.get(assignedName);
|
|
196
|
-
return {
|
|
197
|
-
serializedValue: `...${assignedName}`,
|
|
198
|
-
referencedVariables: definition?.referencedVariables ?? new Set()
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function wrapFragmentReferenceAsBody(assignedName, context) {
|
|
202
|
-
const reference = serializeFragmentReference(assignedName, context);
|
|
203
|
-
return {
|
|
204
|
-
serializedValue: ` { ${reference.serializedValue} }`,
|
|
205
|
-
referencedVariables: reference.referencedVariables
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function lookupDiscriminatorName(discriminatorNames, index) {
|
|
209
|
-
const value = discriminatorNames[index];
|
|
210
|
-
if (value === undefined || value === null) {
|
|
211
|
-
throw new Error(`Fragment name for index ${index} is undefined`);
|
|
212
|
-
}
|
|
213
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- discriminator values come from zod's untyped PropValues but are always primitives
|
|
214
|
-
return value;
|
|
215
|
-
}
|
|
216
|
-
function serializeInlineUnionOption(registry, discriminatorName, fragmentSchema, context) {
|
|
217
|
-
const serializedFragment = serializeObjectSchemaInline(registry, fragmentSchema, context);
|
|
218
|
-
return {
|
|
219
|
-
serializedValue: `... on ${discriminatorName.toString()}${serializedFragment.serializedValue}`,
|
|
220
|
-
referencedVariables: serializedFragment.referencedVariables
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function serializeFragmentUnionOption(registry, discriminatorName, fragmentSchema, context) {
|
|
224
|
-
const assignedName = maybeAssignFragmentName(registry, fragmentSchema, context);
|
|
225
|
-
if (assignedName !== null) {
|
|
226
|
-
return serializeFragmentReference(assignedName, context);
|
|
227
|
-
}
|
|
228
|
-
return serializeInlineUnionOption(registry, discriminatorName, fragmentSchema, context);
|
|
229
|
-
}
|
|
230
|
-
function serializeFragments(registry,
|
|
231
|
-
// eslint-disable-next-line functional/prefer-immutable-types -- discriminatorMap is a third-party zod util type that is only read
|
|
232
|
-
discriminatorMap, unionOptions, context) {
|
|
233
|
-
let referencedVariables = new Set();
|
|
234
|
-
const serializedFragments = [];
|
|
235
|
-
const discriminatorNames = Array.from(discriminatorMap.__typename ?? []);
|
|
236
|
-
const pairedOptions = unionOptions.map(function (fragmentSchema, index) {
|
|
237
|
-
return { discriminatorName: lookupDiscriminatorName(discriminatorNames, index), fragmentSchema };
|
|
238
|
-
});
|
|
239
|
-
const sortedOptions = pairedOptions.toSorted(function (optionA, optionB) {
|
|
240
|
-
return optionA.discriminatorName.toString().localeCompare(optionB.discriminatorName.toString());
|
|
241
|
-
});
|
|
242
|
-
for (const { discriminatorName, fragmentSchema } of sortedOptions) {
|
|
243
|
-
const optionResult = serializeFragmentUnionOption(registry, discriminatorName, fragmentSchema, context);
|
|
244
|
-
referencedVariables = mergeVariables(referencedVariables, optionResult.referencedVariables);
|
|
245
|
-
serializedFragments.push(optionResult.serializedValue);
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
serializedValue: ` { ${serializedFragments.join(', ')} }`,
|
|
249
|
-
referencedVariables
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function serializeObjectField(registry, fieldSelector, objectSchema, context) {
|
|
253
|
-
const assignedName = maybeAssignFragmentName(registry, objectSchema, context);
|
|
254
|
-
if (assignedName !== null) {
|
|
255
|
-
return combineFieldSelectorAndFieldBody(fieldSelector, wrapFragmentReferenceAsBody(assignedName, context));
|
|
256
|
-
}
|
|
257
|
-
return combineFieldSelectorAndFieldBody(fieldSelector, serializeObjectSchemaInline(registry, objectSchema, context));
|
|
258
|
-
}
|
|
259
|
-
function serializeUnionField(registry, fieldSelector, unionSchema, context) {
|
|
260
|
-
return combineFieldSelectorAndFieldBody(fieldSelector, serializeFragments(registry, unionSchema._zod.propValues, unionSchema._zod.def.options, context));
|
|
261
|
-
}
|
|
262
|
-
function trySerializeObjectField(registry, fieldSelector, unwrapped, context) {
|
|
263
|
-
if (!isObjectOrListSchema(unwrapped)) {
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
const objectSchema = getObjectSchema(unwrapped);
|
|
267
|
-
if (objectSchema === null) {
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
return serializeObjectField(registry, fieldSelector, objectSchema, context);
|
|
271
|
-
}
|
|
272
|
-
function trySerializeUnionField(registry, fieldSelector, unwrapped, context) {
|
|
273
|
-
if (!isUnionOrListSchema(unwrapped)) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
const unionSchema = getUnionSchema(unwrapped);
|
|
277
|
-
if (unionSchema === null) {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
return serializeUnionField(registry, fieldSelector, unionSchema, context);
|
|
281
|
-
}
|
|
282
|
-
function serializeUnwrappedFieldBody(registry, fieldSelector, unwrapped, context) {
|
|
283
|
-
if (unwrapped instanceof $ZodUndefined) {
|
|
284
|
-
return { serializedValue: '', referencedVariables: new Set() };
|
|
285
|
-
}
|
|
286
|
-
return trySerializeObjectField(registry, fieldSelector, unwrapped, context) ??
|
|
287
|
-
trySerializeUnionField(registry, fieldSelector, unwrapped, context);
|
|
288
|
-
}
|
|
289
|
-
function serializeFieldSchema(registry, fieldName, fieldSchema, context) {
|
|
290
|
-
const fieldSelector = serializedFieldSelector(registry, fieldName, fieldSchema);
|
|
291
|
-
if (isCustomScalarSchema(fieldSchema)) {
|
|
292
|
-
return fieldSelector;
|
|
293
|
-
}
|
|
294
|
-
const unwrapped = unwrapFieldSchema(fieldSchema);
|
|
295
|
-
return serializeUnwrappedFieldBody(registry, fieldSelector, unwrapped, context) ?? fieldSelector;
|
|
296
|
-
}
|
|
297
|
-
export function serializeRootShape(registry, rootShape, context) {
|
|
298
|
-
let referencedVariables = new Set();
|
|
299
|
-
const bodyEntries = [];
|
|
300
|
-
const sortedEntries = Object.entries(rootShape).toSorted(function ([nameA], [nameB]) {
|
|
301
|
-
return nameA.localeCompare(nameB);
|
|
302
|
-
});
|
|
303
|
-
for (const [fieldName, fieldSchema] of sortedEntries) {
|
|
304
|
-
const serializedField = serializeFieldSchema(registry, fieldName, fieldSchema, context);
|
|
305
|
-
if (serializedField.serializedValue.length > 0) {
|
|
306
|
-
bodyEntries.push(serializedField.serializedValue);
|
|
307
|
-
}
|
|
308
|
-
referencedVariables = mergeVariables(referencedVariables, serializedField.referencedVariables);
|
|
309
|
-
}
|
|
310
|
-
return { bodyEntries, referencedVariables };
|
|
311
|
-
}
|
|
312
9
|
//# sourceMappingURL=serializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/serializer.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EACH,aAAa,EAEhB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAOH,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EAKnB,iBAAiB,EACjB,sBAAsB,EACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGH,eAAe,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAc1D,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,MAAM,wBAAwB,GAAG,iEAAiE;IAC9F,oEAAoE;IACpE,8FAA8F,CAAC;AAEnG,SAAS,qBAAqB,CAC1B,SAAkE,EAClE,MAAkB;IAElB,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,GAA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U,CAAC;IAC5C,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAE,KAAK,CAAE,EAAE,CAAE,KAAK,CAAE;QACnF,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IACH,KAAK,MAAM,CAAE,SAAS,EAAE,WAAW,CAAE,IAAI,aAAa,EAAE,CAAC;QACrD,MAAM,eAAe,GAAG,oBAAoB,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QACxF,IAAI,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7C,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QACtD,CAAC;QACD,mBAAmB,GAAG,cAAc,CAAC,mBAAmB,EAAE,eAAe,CAAC,mBAAmB,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;AAChD,CAAC"}
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/serializer.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAGO,aAAa,CAAC;AAErB,OAAqC,oBAAoB,CAAC;AAC1D,OAkBO,mBAAmB,CAAC;AAC3B,OAIO,gBAAgB,CAAC;AACxB,OAAuC,4BAA4B,CAAC;AAEpE,OAA+B,0BAA0B,CAAC;AAoK9C,+BACW,GAEC,IAoBxB,4EAAkH;AA+B9G"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { type FieldSchema, type FieldShape, type StrictObjectSchema } from './query-schema.ts';
|
|
2
1
|
import type { GraphqlValue } from './values/value.ts';
|
|
3
2
|
export type GraphqlFieldOptions = {
|
|
4
3
|
readonly aliasFor?: string;
|
|
5
4
|
readonly parameters?: Readonly<Record<string, GraphqlValue>>;
|
|
6
5
|
readonly typeName?: string;
|
|
7
6
|
};
|
|
8
|
-
export type FieldOptionsRegistry = WeakMap<FieldSchema, GraphqlFieldOptions>;
|
|
9
|
-
export declare function resolveTypeName(registry: FieldOptionsRegistry, schema: StrictObjectSchema<FieldShape>): string | null;
|
|
10
7
|
//# sourceMappingURL=type-name.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-name.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/type-name.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"type-name.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/type-name.ts"],"names":[],"mappings":"AAEA,OACI,KAMQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC"}
|
|
@@ -1,45 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle -- we need to access _zod */
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
function extractLiteralStringValue(schema) {
|
|
6
|
-
const unwrapped = unwrapFieldSchema(schema);
|
|
7
|
-
if (!(unwrapped instanceof $ZodLiteral)) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
const { values } = unwrapped._zod.def;
|
|
11
|
-
if (values.length !== 1) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const [value] = values;
|
|
15
|
-
if (typeof value !== 'string') {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
function inferTypeNameFromShape(schema) {
|
|
21
|
-
const typenameField = schema._zod.def.shape.__typename;
|
|
22
|
-
if (typenameField === undefined) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const value = extractLiteralStringValue(typenameField);
|
|
26
|
-
if (value === null || !isValidGraphqlName(value)) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
function assertNoTypeNameConflict(explicit, inferred) {
|
|
32
|
-
if (explicit === null || inferred === null || explicit === inferred) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const prefix = `Conflicting GraphQL type name for schema: registered as "${explicit}" but `;
|
|
36
|
-
const suffix = `\`__typename\` literal is "${inferred}".`;
|
|
37
|
-
throw new Error(prefix + suffix);
|
|
38
|
-
}
|
|
39
|
-
export function resolveTypeName(registry, schema) {
|
|
40
|
-
const explicit = registry.get(schema)?.typeName ?? null;
|
|
41
|
-
const inferred = inferTypeNameFromShape(schema);
|
|
42
|
-
assertNoTypeNameConflict(explicit, inferred);
|
|
43
|
-
return explicit ?? inferred;
|
|
44
|
-
}
|
|
2
|
+
import 'zod/v4/core';
|
|
3
|
+
import "./query-schema.js";
|
|
4
|
+
import "./values/name.js";
|
|
45
5
|
//# sourceMappingURL=type-name.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-name.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/type-name.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,
|
|
1
|
+
{"version":3,"file":"type-name.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/type-name.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAA4B,aAAa,CAAC;AAC1C,OAKO,mBAAmB,CAAC;AAC3B,OAAmC,kBAAkB,CAAC"}
|
|
@@ -2,6 +2,5 @@ export type GraphqlEnumValue = {
|
|
|
2
2
|
readonly enumValue: string;
|
|
3
3
|
readonly tag: symbol;
|
|
4
4
|
};
|
|
5
|
-
export declare function isEnumValue(value: unknown): value is GraphqlEnumValue;
|
|
6
5
|
export declare function enumValue(value: string): GraphqlEnumValue;
|
|
7
6
|
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,iCAIyB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CASzD"}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const enumValueSymbol = Symbol('GraphQL enum value');
|
|
4
|
-
export function isEnumValue(value) {
|
|
5
|
-
return isRecord(value) && hasProperty(value, 'tag') && value.tag === enumValueSymbol;
|
|
6
|
-
}
|
|
7
|
-
export function enumValue(value) {
|
|
8
|
-
if (!isValidGraphqlName(value)) {
|
|
9
|
-
throw new Error(`Enum value "${value}" is not a valid enum value`);
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
enumValue: value,
|
|
13
|
-
tag: enumValueSymbol
|
|
14
|
-
};
|
|
15
|
-
}
|
|
1
|
+
import "./name.js";
|
|
2
|
+
import "./record.js";
|
|
16
3
|
//# sourceMappingURL=enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/enum.ts"],"names":[],"mappings":"AAAA,OAAmC,WAAW,CAAC;AAC/C,OAAsC,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/name.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/name.ts"],"names":[],"mappings":"AAA2B"}
|
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
export function normalizeParameterList(parameters) {
|
|
5
|
-
let referencedVariables = new Set();
|
|
6
|
-
const serializedParameters = [];
|
|
7
|
-
const sortedEntries = Object
|
|
8
|
-
.entries(parameters)
|
|
9
|
-
.toSorted(function ([nameA], [nameB]) {
|
|
10
|
-
return nameA.localeCompare(nameB);
|
|
11
|
-
});
|
|
12
|
-
for (const [parameterName, parameterValue] of sortedEntries) {
|
|
13
|
-
if (!isValidGraphqlName(parameterName)) {
|
|
14
|
-
throw new Error(`Parameter name "${parameterName}" is not a valid GraphQL parameter name`);
|
|
15
|
-
}
|
|
16
|
-
const normalizedParameterValue = normalizeGraphqlValue(parameterValue);
|
|
17
|
-
serializedParameters.push(`${parameterName}: ${normalizedParameterValue.serializedValue}`);
|
|
18
|
-
referencedVariables = mergeVariables(referencedVariables, normalizedParameterValue.referencedVariables);
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
serializedValue: serializedParameters.length > 0 ? `(${serializedParameters.join(', ')})` : '',
|
|
22
|
-
referencedVariables
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import "./name.js";
|
|
2
|
+
import "./value.js";
|
|
3
|
+
import "./variable-set.js";
|
|
25
4
|
//# sourceMappingURL=parameter-list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parameter-list.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/parameter-list.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"parameter-list.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/parameter-list.ts"],"names":[],"mappings":"AAAA,OAAmC,WAAW,CAAC;AAC/C,OAAsF,YAAY,CAAC;AACnG,OAA+B,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/record.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/record.ts"],"names":[],"mappings":""}
|
|
@@ -5,10 +5,5 @@ type GraphqlObjectValue = {
|
|
|
5
5
|
};
|
|
6
6
|
type GraphqlPrimitiveValue = boolean | number | string | null;
|
|
7
7
|
export type GraphqlValue = GraphqlEnumValue | GraphqlObjectValue | GraphqlPrimitiveValue | GraphqlVariablePlaceholder | readonly GraphqlValue[];
|
|
8
|
-
export type NormalizedGraphqlValue = {
|
|
9
|
-
readonly serializedValue: string;
|
|
10
|
-
readonly referencedVariables: ReadonlySet<string>;
|
|
11
|
-
};
|
|
12
|
-
export declare function normalizeGraphqlValue(value: GraphqlValue): NormalizedGraphqlValue;
|
|
13
8
|
export {};
|
|
14
9
|
//# sourceMappingURL=value.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAe,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,KAAK,0BAA0B,EAAyB,MAAM,2BAA2B,CAAC;AAGnG,KAAK,kBAAkB,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAAE,CAAC;AAMpE,KAAK,qBAAqB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAO9D,MAAM,MAAM,YAAY,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,0BAA0B,GAC1B,SAAS,YAAY,EAAE,CAAC;AAE9B,MAAM,
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAe,MAAM,WAAW,CAAC;AAG/D,OAAO,EAAE,KAAK,0BAA0B,EAAyB,MAAM,2BAA2B,CAAC;AAGnG,KAAK,kBAAkB,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAAE,CAAC;AAMpE,KAAK,qBAAqB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAO9D,MAAM,MAAM,YAAY,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,qBAAqB,GACrB,0BAA0B,GAC1B,SAAS,YAAY,EAAE,CAAC;AAE9B,MAAM,CAA+B,EAGpC,CAAC"}
|
|
@@ -1,77 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function isObjectValue(value) {
|
|
7
|
-
return isRecord(value) && !isEnumValue(value) && !isVariablePlaceholder(value);
|
|
8
|
-
}
|
|
9
|
-
function isPrimitive(value) {
|
|
10
|
-
const type = typeof value;
|
|
11
|
-
return value === null || type === 'number' || type === 'string' || type === 'boolean';
|
|
12
|
-
}
|
|
13
|
-
function serializePrimitiveValue(value) {
|
|
14
|
-
return JSON.stringify(value);
|
|
15
|
-
}
|
|
16
|
-
function normalizeObjectValue(value) {
|
|
17
|
-
let referencedVariables = new Set();
|
|
18
|
-
const serializedFields = [];
|
|
19
|
-
const sortedEntries = Object
|
|
20
|
-
.entries(value)
|
|
21
|
-
.toSorted(function ([nameA], [nameB]) {
|
|
22
|
-
return nameA.localeCompare(nameB);
|
|
23
|
-
});
|
|
24
|
-
for (const [fieldName, fieldValue] of sortedEntries) {
|
|
25
|
-
if (!isValidGraphqlName(fieldName)) {
|
|
26
|
-
throw new Error(`Field name "${fieldName}" is not a valid GraphQL field name`);
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
29
|
-
const normalizedFieldValue = normalizeGraphqlValue(fieldValue);
|
|
30
|
-
serializedFields.push(`${fieldName}: ${normalizedFieldValue.serializedValue}`);
|
|
31
|
-
referencedVariables = mergeVariables(referencedVariables, normalizedFieldValue.referencedVariables);
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
serializedValue: `{${serializedFields.join(', ')}}`,
|
|
35
|
-
referencedVariables
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function normalizeListValue(value) {
|
|
39
|
-
let referencedVariables = new Set();
|
|
40
|
-
const serializedItems = [];
|
|
41
|
-
for (const item of value) {
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define -- mutual recursion
|
|
43
|
-
const normalizedItem = normalizeGraphqlValue(item);
|
|
44
|
-
serializedItems.push(normalizedItem.serializedValue);
|
|
45
|
-
referencedVariables = mergeVariables(referencedVariables, normalizedItem.referencedVariables);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
serializedValue: `[${serializedItems.join(', ')}]`,
|
|
49
|
-
referencedVariables
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
export function normalizeGraphqlValue(value) {
|
|
53
|
-
const referencedVariables = new Set();
|
|
54
|
-
if (isPrimitive(value)) {
|
|
55
|
-
return {
|
|
56
|
-
serializedValue: serializePrimitiveValue(value),
|
|
57
|
-
referencedVariables
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
if (isEnumValue(value)) {
|
|
61
|
-
return {
|
|
62
|
-
serializedValue: value.enumValue,
|
|
63
|
-
referencedVariables
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (isVariablePlaceholder(value)) {
|
|
67
|
-
return {
|
|
68
|
-
serializedValue: value.variableName,
|
|
69
|
-
referencedVariables: new Set([...referencedVariables, value.variableName])
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (isObjectValue(value)) {
|
|
73
|
-
return normalizeObjectValue(value);
|
|
74
|
-
}
|
|
75
|
-
return normalizeListValue(value);
|
|
76
|
-
}
|
|
1
|
+
import "./enum.js";
|
|
2
|
+
import "./name.js";
|
|
3
|
+
import "./record.js";
|
|
4
|
+
import "./variable-placeholder.js";
|
|
5
|
+
import "./variable-set.js";
|
|
77
6
|
//# sourceMappingURL=value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/value.ts"],"names":[],"mappings":"AAAA,OAAmD,WAAW,CAAC;AAC/D,OAAmC,WAAW,CAAC;AAC/C,OAAyB,aAAa,CAAC;AACvC,OAAuE,2BAA2B,CAAC;AACnG,OAA+B,mBAAmB,CAAC;AA6C3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable-set.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/variable-set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"variable-set.js","sourceRoot":"","sources":["../../../../../source/zod-graphql-query-builder/values/variable-set.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
export function ensureValidVariableCorrelations(variableDefinitions, referencedVariables) {
|
|
2
|
-
const unusedVariableDefinitions = new Set(Object.keys(variableDefinitions));
|
|
3
|
-
for (const referencedVariable of referencedVariables) {
|
|
4
|
-
unusedVariableDefinitions.delete(referencedVariable);
|
|
5
|
-
if (!Object.hasOwn(variableDefinitions, referencedVariable)) {
|
|
6
|
-
throw new Error(`Referenced variable "${referencedVariable}" is missing in variableDefinitions`);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
const [firstUnusedVariable] = Array.from(unusedVariableDefinitions);
|
|
10
|
-
if (firstUnusedVariable !== undefined) {
|
|
11
|
-
throw new Error(`Variable definition for "${firstUnusedVariable}" is never referenced`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
1
|
//# sourceMappingURL=variable-correlations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable-correlations.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-correlations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"variable-correlations.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-correlations.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable-definition.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"variable-definition.d.ts","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
function ensureValidVariableDefinition(variableDefinition) {
|
|
4
|
-
const [variableName, variableType] = variableDefinition;
|
|
5
|
-
if (!isValidVariableIdentifier(variableName)) {
|
|
6
|
-
throw new Error(`Variable name "${variableName}" is not a valid GraphQL variable name`);
|
|
7
|
-
}
|
|
8
|
-
if (!isValidGraphqlType(variableType)) {
|
|
9
|
-
throw new Error(`Type "${variableType}" for variable "${variableName}" is invalid`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function serializeVariableDefinitionPair(variableDefinition) {
|
|
13
|
-
const [variableName, variableType] = variableDefinition;
|
|
14
|
-
return `${variableName}: ${variableType}`;
|
|
15
|
-
}
|
|
16
|
-
export function serializeVariableDefinitions(definitions) {
|
|
17
|
-
const entries = Object.entries(definitions);
|
|
18
|
-
if (entries.length === 0) {
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
entries.forEach(ensureValidVariableDefinition);
|
|
22
|
-
const sortedEntries = entries.toSorted(function ([nameA], [nameB]) {
|
|
23
|
-
return nameA.localeCompare(nameB);
|
|
24
|
-
});
|
|
25
|
-
const serializedEntries = sortedEntries.map(serializeVariableDefinitionPair);
|
|
26
|
-
return `(${serializedEntries.join(', ')})`;
|
|
27
|
-
}
|
|
1
|
+
import "./values/variable-placeholder.js";
|
|
2
|
+
import "./variable-type.js";
|
|
28
3
|
//# sourceMappingURL=variable-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable-definition.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"variable-definition.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-definition.ts"],"names":[],"mappings":"AAAA,OAA0C,kCAAkC,CAAC;AAC7E,OAAmC,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable-type.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-type.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"variable-type.js","sourceRoot":"","sources":["../../../../source/zod-graphql-query-builder/variable-type.ts"],"names":[],"mappings":"AAAA,OAA0B,SAAS,CAAC"}
|