@sanity/codegen 8.2.0 → 8.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/_exports/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {DefinedTelemetryTrace} from '@sanity/telemetry'
|
|
2
|
+
import {DocumentSchemaType} from 'groq-js'
|
|
2
3
|
import {ExprNode} from 'groq-js'
|
|
3
4
|
import {FSWatcher} from 'chokidar'
|
|
4
5
|
import {SchemaType} from 'groq-js'
|
|
5
6
|
import * as t from '@babel/types'
|
|
6
7
|
import {TransformOptions} from '@babel/core'
|
|
8
|
+
import {TypeDeclarationSchemaType} from 'groq-js'
|
|
9
|
+
import {TypeNode} from 'groq-js'
|
|
7
10
|
import * as v from 'valibot'
|
|
8
11
|
import {WorkerChannel} from '@sanity/worker-channels'
|
|
9
12
|
import {WorkerChannelReporter} from '@sanity/worker-channels'
|
|
@@ -500,6 +503,74 @@ export declare function runTypegenWatcher(options: RunTypegenOptions): {
|
|
|
500
503
|
*/
|
|
501
504
|
export declare function safeParseQuery(query: string): ExprNode
|
|
502
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Generates TypeScript types from a schema, as `sanity schema extract` writes it.
|
|
508
|
+
*
|
|
509
|
+
* On construction, every type in the schema gets a TypeScript type and a unique alias
|
|
510
|
+
* identifier; iterating the instance yields them as `{name, id, tsType}`, in schema order.
|
|
511
|
+
* `generateTsType` turns any groq-js type node into a TypeScript type that names schema types
|
|
512
|
+
* by those aliases, and `evaluateQuery` does so for the result of a GROQ query. A tool that
|
|
513
|
+
* types GROQ outside `TypeGenerator`, such as a TypeScript content mapper for `.groq` files,
|
|
514
|
+
* uses this class so that its output agrees with what `sanity typegen generate` writes.
|
|
515
|
+
* @beta
|
|
516
|
+
*/
|
|
517
|
+
export declare class SchemaTypeGenerator {
|
|
518
|
+
readonly schema: SchemaType
|
|
519
|
+
evaluateQuery: (arg: Pick<ExtractedQuery, 'query'>) => {
|
|
520
|
+
stats: TypeEvaluationStats
|
|
521
|
+
tsType: t.TSType
|
|
522
|
+
}
|
|
523
|
+
private arrayOfUsed
|
|
524
|
+
private identifiers
|
|
525
|
+
private tsTypes
|
|
526
|
+
constructor(schema: SchemaType)
|
|
527
|
+
/** The names of the schema's document types, in schema order. */
|
|
528
|
+
documentTypeNames(): string[]
|
|
529
|
+
/**
|
|
530
|
+
* Evaluates a projection for one document type, as `*[_type == TYPE][0]PROJECTION` without
|
|
531
|
+
* the `null` for a missing document: the SDK projects documents it has found.
|
|
532
|
+
*/
|
|
533
|
+
evaluateProjection({documentType, projection}: {documentType: string; projection: string}): {
|
|
534
|
+
stats: TypeEvaluationStats
|
|
535
|
+
tsType: t.TSType
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* The TypeScript type for a groq-js type node. A reference to a schema type becomes its alias
|
|
539
|
+
* identifier, an array of inline types becomes `ArrayOf<...>` (and `isArrayOfUsed` reports
|
|
540
|
+
* that the helper is needed), and a reference object carries `internalGroqTypeReferenceTo`.
|
|
541
|
+
*/
|
|
542
|
+
generateTsType(typeNode: DocumentSchemaType | TypeDeclarationSchemaType | TypeNode): t.TSType
|
|
543
|
+
getType(typeName: string):
|
|
544
|
+
| {
|
|
545
|
+
id: t.Identifier
|
|
546
|
+
tsType: t.TSType
|
|
547
|
+
}
|
|
548
|
+
| undefined
|
|
549
|
+
hasType(typeName: string): boolean
|
|
550
|
+
isArrayOfUsed(): boolean
|
|
551
|
+
[Symbol.iterator](): Generator<
|
|
552
|
+
{
|
|
553
|
+
id: t.Identifier
|
|
554
|
+
tsType: t.TSType
|
|
555
|
+
name: string
|
|
556
|
+
},
|
|
557
|
+
void,
|
|
558
|
+
unknown
|
|
559
|
+
>
|
|
560
|
+
typeNames(): string[]
|
|
561
|
+
/**
|
|
562
|
+
* Helper function used to generate TS types for arrays of inline types, or arrays of inline types
|
|
563
|
+
* wrapped in the ArrayOf wrapper that adds _key prop
|
|
564
|
+
*/
|
|
565
|
+
private generateArrayOfTsType
|
|
566
|
+
private generateArrayTsType
|
|
567
|
+
private generateDocumentTsType
|
|
568
|
+
private generateInlineTsType
|
|
569
|
+
private generateObjectTsType
|
|
570
|
+
private generateTsObjectProperty
|
|
571
|
+
private generateUnionTsType
|
|
572
|
+
}
|
|
573
|
+
|
|
503
574
|
/** Builds a tuple from elements, stopping at the first `never`. */
|
|
504
575
|
declare type TakeUntilNever<T extends unknown[]> = T extends [infer H, ...infer Rest]
|
|
505
576
|
? [H] extends [never]
|
package/dist/_exports/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { findQueriesInPath } from '../typescript/findQueriesInPath.js';
|
|
|
8
8
|
export { findQueriesInSource } from '../typescript/findQueriesInSource.js';
|
|
9
9
|
export { getResolver } from '../typescript/moduleResolver.js';
|
|
10
10
|
export { registerBabel } from '../typescript/registerBabel.js';
|
|
11
|
+
export { SchemaTypeGenerator } from '../typescript/schemaTypeGenerator.js';
|
|
11
12
|
export { TypeGenerator } from '../typescript/typeGenerator.js';
|
|
12
13
|
export { QueryExtractionError } from '../typescript/types.js';
|
|
13
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export {runTypegenGenerate} from '../actions/typegenGenerate.js'\nexport {runTypegenWatcher} from '../actions/typegenWatch.js'\nexport {\n type GenerationResult,\n type RunTypegenOptions,\n type TypegenProgressEvent,\n} from '../actions/types.js'\nexport {\n type CodegenConfig,\n configDefinition,\n readConfig,\n type TypeGenConfig,\n} from '../readConfig.js'\nexport {readSchema} from '../readSchema.js'\nexport {safeParseQuery} from '../safeParseQuery.js'\nexport {TypegenWatchModeTrace, TypesGeneratedTrace} from '../typegen.telemetry.js'\nexport {findQueriesInPath} from '../typescript/findQueriesInPath.js'\nexport {findQueriesInSource} from '../typescript/findQueriesInSource.js'\nexport {getResolver} from '../typescript/moduleResolver.js'\nexport {registerBabel} from '../typescript/registerBabel.js'\nexport {\n type GenerateTypesOptions,\n TypeGenerator,\n type TypegenResource,\n type TypegenWorkerChannel,\n} from '../typescript/typeGenerator.js'\nexport {\n type EvaluatedModule,\n type EvaluatedProjection,\n type EvaluatedQuery,\n type ExtractedModule,\n type ExtractedProjection,\n type ExtractedQuery,\n QueryExtractionError,\n} from '../typescript/types.js'\nexport {type FilterByType, type Get} from '../typeUtils.js'\n"],"names":["runTypegenGenerate","runTypegenWatcher","configDefinition","readConfig","readSchema","safeParseQuery","TypegenWatchModeTrace","TypesGeneratedTrace","findQueriesInPath","findQueriesInSource","getResolver","registerBabel","TypeGenerator","QueryExtractionError"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,gCAA+B;AAChE,SAAQC,iBAAiB,QAAO,6BAA4B;AAM5D,SAEEC,gBAAgB,EAChBC,UAAU,QAEL,mBAAkB;AACzB,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,cAAc,QAAO,uBAAsB;AACnD,SAAQC,qBAAqB,EAAEC,mBAAmB,QAAO,0BAAyB;AAClF,SAAQC,iBAAiB,QAAO,qCAAoC;AACpE,SAAQC,mBAAmB,QAAO,uCAAsC;AACxE,SAAQC,WAAW,QAAO,kCAAiC;AAC3D,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAEEC,aAAa,QAGR,iCAAgC;AACvC,SAOEC,oBAAoB,QACf,yBAAwB"}
|
|
1
|
+
{"version":3,"sources":["../../src/_exports/index.ts"],"sourcesContent":["export {runTypegenGenerate} from '../actions/typegenGenerate.js'\nexport {runTypegenWatcher} from '../actions/typegenWatch.js'\nexport {\n type GenerationResult,\n type RunTypegenOptions,\n type TypegenProgressEvent,\n} from '../actions/types.js'\nexport {\n type CodegenConfig,\n configDefinition,\n readConfig,\n type TypeGenConfig,\n} from '../readConfig.js'\nexport {readSchema} from '../readSchema.js'\nexport {safeParseQuery} from '../safeParseQuery.js'\nexport {TypegenWatchModeTrace, TypesGeneratedTrace} from '../typegen.telemetry.js'\nexport {findQueriesInPath} from '../typescript/findQueriesInPath.js'\nexport {findQueriesInSource} from '../typescript/findQueriesInSource.js'\nexport {getResolver} from '../typescript/moduleResolver.js'\nexport {registerBabel} from '../typescript/registerBabel.js'\nexport {SchemaTypeGenerator} from '../typescript/schemaTypeGenerator.js'\nexport {\n type GenerateTypesOptions,\n TypeGenerator,\n type TypegenResource,\n type TypegenWorkerChannel,\n} from '../typescript/typeGenerator.js'\nexport {\n type EvaluatedModule,\n type EvaluatedProjection,\n type EvaluatedQuery,\n type ExtractedModule,\n type ExtractedProjection,\n type ExtractedQuery,\n QueryExtractionError,\n} from '../typescript/types.js'\nexport {type FilterByType, type Get} from '../typeUtils.js'\n"],"names":["runTypegenGenerate","runTypegenWatcher","configDefinition","readConfig","readSchema","safeParseQuery","TypegenWatchModeTrace","TypesGeneratedTrace","findQueriesInPath","findQueriesInSource","getResolver","registerBabel","SchemaTypeGenerator","TypeGenerator","QueryExtractionError"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,gCAA+B;AAChE,SAAQC,iBAAiB,QAAO,6BAA4B;AAM5D,SAEEC,gBAAgB,EAChBC,UAAU,QAEL,mBAAkB;AACzB,SAAQC,UAAU,QAAO,mBAAkB;AAC3C,SAAQC,cAAc,QAAO,uBAAsB;AACnD,SAAQC,qBAAqB,EAAEC,mBAAmB,QAAO,0BAAyB;AAClF,SAAQC,iBAAiB,QAAO,qCAAoC;AACpE,SAAQC,mBAAmB,QAAO,uCAAsC;AACxE,SAAQC,WAAW,QAAO,kCAAiC;AAC3D,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAAQC,mBAAmB,QAAO,uCAAsC;AACxE,SAEEC,aAAa,QAGR,iCAAgC;AACvC,SAOEC,oBAAoB,QACf,yBAAwB"}
|
|
@@ -3,7 +3,17 @@ import { typeEvaluate } from 'groq-js';
|
|
|
3
3
|
import { safeParseQuery } from '../safeParseQuery.js';
|
|
4
4
|
import { ARRAY_OF, INTERNAL_REFERENCE_SYMBOL } from './constants.js';
|
|
5
5
|
import { getFilterArrayUnionType, getUniqueIdentifierForName, isIdentifierName, weakMapMemo } from './helpers.js';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Generates TypeScript types from a schema, as `sanity schema extract` writes it.
|
|
8
|
+
*
|
|
9
|
+
* On construction, every type in the schema gets a TypeScript type and a unique alias
|
|
10
|
+
* identifier; iterating the instance yields them as `{name, id, tsType}`, in schema order.
|
|
11
|
+
* `generateTsType` turns any groq-js type node into a TypeScript type that names schema types
|
|
12
|
+
* by those aliases, and `evaluateQuery` does so for the result of a GROQ query. A tool that
|
|
13
|
+
* types GROQ outside `TypeGenerator`, such as a TypeScript content mapper for `.groq` files,
|
|
14
|
+
* uses this class so that its output agrees with what `sanity typegen generate` writes.
|
|
15
|
+
* @beta
|
|
16
|
+
*/ export class SchemaTypeGenerator {
|
|
7
17
|
schema;
|
|
8
18
|
evaluateQuery = weakMapMemo(// eslint-disable-next-line unicorn/consistent-function-scoping
|
|
9
19
|
({ query })=>{
|
|
@@ -53,6 +63,72 @@ export class SchemaTypeGenerator {
|
|
|
53
63
|
tsType: this.generateTsType(typeNode)
|
|
54
64
|
};
|
|
55
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The TypeScript type for a groq-js type node. A reference to a schema type becomes its alias
|
|
68
|
+
* identifier, an array of inline types becomes `ArrayOf<...>` (and `isArrayOfUsed` reports
|
|
69
|
+
* that the helper is needed), and a reference object carries `internalGroqTypeReferenceTo`.
|
|
70
|
+
*/ generateTsType(typeNode) {
|
|
71
|
+
switch(typeNode.type){
|
|
72
|
+
case 'array':
|
|
73
|
+
{
|
|
74
|
+
return this.generateArrayTsType(typeNode);
|
|
75
|
+
}
|
|
76
|
+
case 'boolean':
|
|
77
|
+
{
|
|
78
|
+
if (typeNode.value !== undefined) {
|
|
79
|
+
return t.tsLiteralType(t.booleanLiteral(typeNode.value));
|
|
80
|
+
}
|
|
81
|
+
return t.tsBooleanKeyword();
|
|
82
|
+
}
|
|
83
|
+
case 'document':
|
|
84
|
+
{
|
|
85
|
+
return this.generateDocumentTsType(typeNode);
|
|
86
|
+
}
|
|
87
|
+
case 'inline':
|
|
88
|
+
{
|
|
89
|
+
return this.generateInlineTsType(typeNode);
|
|
90
|
+
}
|
|
91
|
+
case 'null':
|
|
92
|
+
{
|
|
93
|
+
return t.tsNullKeyword();
|
|
94
|
+
}
|
|
95
|
+
case 'number':
|
|
96
|
+
{
|
|
97
|
+
if (typeNode.value !== undefined) {
|
|
98
|
+
return t.tsLiteralType(t.numericLiteral(typeNode.value));
|
|
99
|
+
}
|
|
100
|
+
return t.tsNumberKeyword();
|
|
101
|
+
}
|
|
102
|
+
case 'object':
|
|
103
|
+
{
|
|
104
|
+
return this.generateObjectTsType(typeNode);
|
|
105
|
+
}
|
|
106
|
+
case 'string':
|
|
107
|
+
{
|
|
108
|
+
if (typeNode.value !== undefined) {
|
|
109
|
+
return t.tsLiteralType(t.stringLiteral(typeNode.value));
|
|
110
|
+
}
|
|
111
|
+
return t.tsStringKeyword();
|
|
112
|
+
}
|
|
113
|
+
case 'type':
|
|
114
|
+
{
|
|
115
|
+
return this.generateTsType(typeNode.value);
|
|
116
|
+
}
|
|
117
|
+
case 'union':
|
|
118
|
+
{
|
|
119
|
+
return this.generateUnionTsType(typeNode);
|
|
120
|
+
}
|
|
121
|
+
case 'unknown':
|
|
122
|
+
{
|
|
123
|
+
return t.tsUnknownKeyword();
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
{
|
|
127
|
+
throw new Error(`Encountered unsupported node type "${// @ts-expect-error This should never happen
|
|
128
|
+
typeNode.type}" while generating schema types`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
56
132
|
getType(typeName) {
|
|
57
133
|
const tsType = this.tsTypes.get(typeName);
|
|
58
134
|
const id = this.identifiers.get(typeName);
|
|
@@ -188,68 +264,6 @@ export class SchemaTypeGenerator {
|
|
|
188
264
|
propertySignature.optional = attribute.optional;
|
|
189
265
|
return propertySignature;
|
|
190
266
|
}
|
|
191
|
-
generateTsType(typeNode) {
|
|
192
|
-
switch(typeNode.type){
|
|
193
|
-
case 'array':
|
|
194
|
-
{
|
|
195
|
-
return this.generateArrayTsType(typeNode);
|
|
196
|
-
}
|
|
197
|
-
case 'boolean':
|
|
198
|
-
{
|
|
199
|
-
if (typeNode.value !== undefined) {
|
|
200
|
-
return t.tsLiteralType(t.booleanLiteral(typeNode.value));
|
|
201
|
-
}
|
|
202
|
-
return t.tsBooleanKeyword();
|
|
203
|
-
}
|
|
204
|
-
case 'document':
|
|
205
|
-
{
|
|
206
|
-
return this.generateDocumentTsType(typeNode);
|
|
207
|
-
}
|
|
208
|
-
case 'inline':
|
|
209
|
-
{
|
|
210
|
-
return this.generateInlineTsType(typeNode);
|
|
211
|
-
}
|
|
212
|
-
case 'null':
|
|
213
|
-
{
|
|
214
|
-
return t.tsNullKeyword();
|
|
215
|
-
}
|
|
216
|
-
case 'number':
|
|
217
|
-
{
|
|
218
|
-
if (typeNode.value !== undefined) {
|
|
219
|
-
return t.tsLiteralType(t.numericLiteral(typeNode.value));
|
|
220
|
-
}
|
|
221
|
-
return t.tsNumberKeyword();
|
|
222
|
-
}
|
|
223
|
-
case 'object':
|
|
224
|
-
{
|
|
225
|
-
return this.generateObjectTsType(typeNode);
|
|
226
|
-
}
|
|
227
|
-
case 'string':
|
|
228
|
-
{
|
|
229
|
-
if (typeNode.value !== undefined) {
|
|
230
|
-
return t.tsLiteralType(t.stringLiteral(typeNode.value));
|
|
231
|
-
}
|
|
232
|
-
return t.tsStringKeyword();
|
|
233
|
-
}
|
|
234
|
-
case 'type':
|
|
235
|
-
{
|
|
236
|
-
return this.generateTsType(typeNode.value);
|
|
237
|
-
}
|
|
238
|
-
case 'union':
|
|
239
|
-
{
|
|
240
|
-
return this.generateUnionTsType(typeNode);
|
|
241
|
-
}
|
|
242
|
-
case 'unknown':
|
|
243
|
-
{
|
|
244
|
-
return t.tsUnknownKeyword();
|
|
245
|
-
}
|
|
246
|
-
default:
|
|
247
|
-
{
|
|
248
|
-
throw new Error(`Encountered unsupported node type "${// @ts-expect-error This should never happen
|
|
249
|
-
typeNode.type}" while generating schema types`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
267
|
// Helper function used to generate TS types for union type nodes.
|
|
254
268
|
generateUnionTsType(typeNode) {
|
|
255
269
|
if (typeNode.of.length === 0) return t.tsNeverKeyword();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typescript/schemaTypeGenerator.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport {\n type ArrayTypeNode,\n type DocumentSchemaType,\n type InlineTypeNode,\n type ObjectAttribute,\n type ObjectTypeNode,\n type SchemaType,\n type TypeDeclarationSchemaType,\n typeEvaluate,\n type TypeNode,\n type UnionTypeNode,\n} from 'groq-js'\n\nimport {safeParseQuery} from '../safeParseQuery.js'\nimport {ARRAY_OF, INTERNAL_REFERENCE_SYMBOL} from './constants.js'\nimport {\n getFilterArrayUnionType,\n getUniqueIdentifierForName,\n isIdentifierName,\n weakMapMemo,\n} from './helpers.js'\nimport {type ExtractedQuery, type TypeEvaluationStats} from './types.js'\n\nexport class SchemaTypeGenerator {\n public readonly schema: SchemaType\n evaluateQuery = weakMapMemo(\n // eslint-disable-next-line unicorn/consistent-function-scoping\n ({query}: Pick<ExtractedQuery, 'query'>): {stats: TypeEvaluationStats; tsType: t.TSType} => {\n const ast = safeParseQuery(query)\n const typeNode = typeEvaluate(ast, this.schema)\n const tsType = this.generateTsType(typeNode)\n const stats = walkAndCountQueryTypeNodeStats(typeNode)\n return {stats, tsType}\n },\n )\n private arrayOfUsed = false\n\n private identifiers = new Map<string, t.Identifier>()\n\n private tsTypes = new Map<string, t.TSType>()\n\n constructor(schema: SchemaType) {\n this.schema = schema\n\n const uniqueTypeNames = new Set<string>()\n for (const type of schema) {\n if (uniqueTypeNames.has(type.name)) {\n throw new Error(\n `Duplicate type name \"${type.name}\" in schema. Type names must be unique within the same schema.`,\n )\n }\n uniqueTypeNames.add(type.name)\n }\n\n for (const type of schema) {\n const currentIdentifierNames = new Set([...this.identifiers.values()].map((id) => id.name))\n const uniqueIdentifier = getUniqueIdentifierForName(type.name, currentIdentifierNames)\n this.identifiers.set(type.name, uniqueIdentifier)\n }\n\n for (const type of schema) {\n this.tsTypes.set(type.name, this.generateTsType(type))\n }\n }\n\n /** The names of the schema's document types, in schema order. */\n documentTypeNames(): string[] {\n return this.schema.filter((schemaType) => schemaType.type === 'document').map(({name}) => name)\n }\n\n /**\n * Evaluates a projection for one document type, as `*[_type == TYPE][0]PROJECTION` without\n * the `null` for a missing document: the SDK projects documents it has found.\n */\n evaluateProjection({documentType, projection}: {documentType: string; projection: string}): {\n stats: TypeEvaluationStats\n tsType: t.TSType\n } {\n const ast = safeParseQuery(`*[_type == ${JSON.stringify(documentType)}][0]${projection}`)\n const typeNode = withoutNull(typeEvaluate(ast, this.schema))\n return {stats: walkAndCountQueryTypeNodeStats(typeNode), tsType: this.generateTsType(typeNode)}\n }\n\n getType(typeName: string): {id: t.Identifier; tsType: t.TSType} | undefined {\n const tsType = this.tsTypes.get(typeName)\n const id = this.identifiers.get(typeName)\n if (tsType && id) return {id, tsType}\n return undefined\n }\n\n hasType(typeName: string): boolean {\n return this.tsTypes.has(typeName)\n }\n\n isArrayOfUsed(): boolean {\n return this.arrayOfUsed\n }\n\n *[Symbol.iterator]() {\n for (const {name} of this.schema) {\n yield {name, ...this.getType(name)!}\n }\n }\n\n typeNames(): string[] {\n return this.schema.map((schemaType) => schemaType.name)\n }\n\n /**\n * Helper function used to generate TS types for arrays of inline types, or arrays of inline types\n * wrapped in the ArrayOf wrapper that adds _key prop\n */\n private generateArrayOfTsType(typeNode: ArrayTypeNode): t.TSTypeReference {\n this.arrayOfUsed = true\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(ARRAY_OF, t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // Helper function used to generate TS types for array type nodes.\n private generateArrayTsType(typeNode: ArrayTypeNode): t.TSTypeReference | t.TSUnionType {\n // if it's an array of a single inline type, wrap it in ArrayOf\n if (typeNode.of.type === 'inline') {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // if it's not an inline object and not a union, wrap in Array\n if (typeNode.of.type !== 'union') {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // if it's not a union type or all of the union type members are non-inlines, wrap type in Array\n if (typeNode.of.of.every((unionTypeNode) => unionTypeNode.type !== 'inline')) {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // all the union types nodes are inline\n if (typeNode.of.of.every((unionMember) => unionMember.type === 'inline')) {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // some of the union types are inlines, while some are not - split and recurse\n const arrayOfNonInline = getFilterArrayUnionType(typeNode, (member) => member.type !== 'inline')\n const arrayOfInline = getFilterArrayUnionType(typeNode, (member) => member.type === 'inline')\n\n return t.tsUnionType([\n this.generateArrayTsType(arrayOfNonInline),\n this.generateArrayTsType(arrayOfInline),\n ])\n }\n\n // Helper function used to generate TS types for document type nodes.\n private generateDocumentTsType(document: DocumentSchemaType): t.TSType {\n const props = Object.entries(document.attributes).map(([key, node]) =>\n this.generateTsObjectProperty(key, node),\n )\n\n return t.tsTypeLiteral(props)\n }\n\n private generateInlineTsType(typeNode: InlineTypeNode): t.TSType {\n const id = this.identifiers.get(typeNode.name)\n if (!id) {\n // Not found in schema, return unknown type\n return t.addComment(\n t.tsUnknownKeyword(),\n 'trailing',\n ` Unable to locate the referenced type \"${typeNode.name}\" in schema`,\n true,\n )\n }\n\n return t.tsTypeReference(id)\n }\n\n // Helper function used to generate TS types for object type nodes.\n private generateObjectTsType(typeNode: ObjectTypeNode): t.TSType {\n const props: t.TSPropertySignature[] = []\n for (const [key, attribute] of Object.entries(typeNode.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n const rest = typeNode.rest\n\n if (rest) {\n switch (rest.type) {\n case 'inline': {\n const resolved = this.generateInlineTsType(rest)\n // if object rest is unknown, we can't generate a type literal for it\n if (t.isTSUnknownKeyword(resolved)) return resolved\n return t.tsIntersectionType([t.tsTypeLiteral(props), resolved])\n }\n case 'object': {\n for (const [key, attribute] of Object.entries(rest.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n break\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n default: {\n // @ts-expect-error This should never happen\n throw new Error(`Type \"${rest.type}\" not found in schema`)\n }\n }\n }\n\n if (typeNode.dereferencesTo) {\n const derefType = Object.assign(\n t.tsPropertySignature(\n INTERNAL_REFERENCE_SYMBOL,\n t.tsTypeAnnotation(t.tsLiteralType(t.stringLiteral(typeNode.dereferencesTo))),\n ),\n {computed: true, optional: true},\n )\n props.push(derefType)\n }\n\n return t.tsTypeLiteral(props)\n }\n\n // Helper function used to generate TS types for object properties.\n private generateTsObjectProperty(key: string, attribute: ObjectAttribute): t.TSPropertySignature {\n const type = this.generateTsType(attribute.value)\n const keyNode = isIdentifierName(key) ? t.identifier(key) : t.stringLiteral(key)\n const propertySignature = t.tsPropertySignature(keyNode, t.tsTypeAnnotation(type))\n propertySignature.optional = attribute.optional\n\n return propertySignature\n }\n\n private generateTsType(\n typeNode: DocumentSchemaType | TypeDeclarationSchemaType | TypeNode,\n ): t.TSType {\n switch (typeNode.type) {\n case 'array': {\n return this.generateArrayTsType(typeNode)\n }\n case 'boolean': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.booleanLiteral(typeNode.value))\n }\n return t.tsBooleanKeyword()\n }\n case 'document': {\n return this.generateDocumentTsType(typeNode)\n }\n case 'inline': {\n return this.generateInlineTsType(typeNode)\n }\n case 'null': {\n return t.tsNullKeyword()\n }\n case 'number': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.numericLiteral(typeNode.value))\n }\n return t.tsNumberKeyword()\n }\n case 'object': {\n return this.generateObjectTsType(typeNode)\n }\n case 'string': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.stringLiteral(typeNode.value))\n }\n return t.tsStringKeyword()\n }\n case 'type': {\n return this.generateTsType(typeNode.value)\n }\n case 'union': {\n return this.generateUnionTsType(typeNode)\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n\n default: {\n throw new Error(\n `Encountered unsupported node type \"${\n // @ts-expect-error This should never happen\n typeNode.type\n }\" while generating schema types`,\n )\n }\n }\n }\n\n // Helper function used to generate TS types for union type nodes.\n private generateUnionTsType(typeNode: UnionTypeNode): t.TSType {\n if (typeNode.of.length === 0) return t.tsNeverKeyword()\n if (typeNode.of.length === 1) return this.generateTsType(typeNode.of[0]!)\n return t.tsUnionType(typeNode.of.map((node) => this.generateTsType(node)))\n }\n}\n\nexport function walkAndCountQueryTypeNodeStats(typeNode: TypeNode): TypeEvaluationStats {\n switch (typeNode.type) {\n case 'array': {\n const acc = walkAndCountQueryTypeNodeStats(typeNode.of)\n acc.allTypes += 1 // count the array type itself\n return acc\n }\n case 'object': {\n // if the rest is unknown, we count it as one unknown type\n if (typeNode.rest && typeNode.rest.type === 'unknown') {\n return {allTypes: 2, emptyUnions: 0, unknownTypes: 1} // count the object type itself as well\n }\n\n const restStats = typeNode.rest\n ? walkAndCountQueryTypeNodeStats(typeNode.rest)\n : {allTypes: 0, emptyUnions: 0, unknownTypes: 0}\n\n // count the object type itself\n restStats.allTypes += 1\n\n const attrs = Object.values(typeNode.attributes)\n let acc = restStats\n for (const attribute of attrs) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(\n attribute.value,\n )\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'union': {\n if (typeNode.of.length === 0) {\n return {allTypes: 1, emptyUnions: 1, unknownTypes: 0}\n }\n\n let acc = {allTypes: 1, emptyUnions: 0, unknownTypes: 0} // count the union type itself\n for (const type of typeNode.of) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(type)\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'unknown': {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 1}\n }\n default: {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 0}\n }\n }\n}\n\nfunction withoutNull(typeNode: TypeNode): TypeNode {\n if (typeNode.type !== 'union') return typeNode\n const of = typeNode.of.filter((member) => member.type !== 'null')\n return of.length === 1 ? of[0]! : {...typeNode, of}\n}\n"],"names":["t","typeEvaluate","safeParseQuery","ARRAY_OF","INTERNAL_REFERENCE_SYMBOL","getFilterArrayUnionType","getUniqueIdentifierForName","isIdentifierName","weakMapMemo","SchemaTypeGenerator","schema","evaluateQuery","query","ast","typeNode","tsType","generateTsType","stats","walkAndCountQueryTypeNodeStats","arrayOfUsed","identifiers","Map","tsTypes","uniqueTypeNames","Set","type","has","name","Error","add","currentIdentifierNames","values","map","id","uniqueIdentifier","set","documentTypeNames","filter","schemaType","evaluateProjection","documentType","projection","JSON","stringify","withoutNull","getType","typeName","get","undefined","hasType","isArrayOfUsed","Symbol","iterator","typeNames","generateArrayOfTsType","typeNodes","of","tsTypeReference","tsTypeParameterInstantiation","generateArrayTsType","identifier","every","unionTypeNode","unionMember","arrayOfNonInline","member","arrayOfInline","tsUnionType","generateDocumentTsType","document","props","Object","entries","attributes","key","node","generateTsObjectProperty","tsTypeLiteral","generateInlineTsType","addComment","tsUnknownKeyword","generateObjectTsType","attribute","push","rest","resolved","isTSUnknownKeyword","tsIntersectionType","dereferencesTo","derefType","assign","tsPropertySignature","tsTypeAnnotation","tsLiteralType","stringLiteral","computed","optional","value","keyNode","propertySignature","booleanLiteral","tsBooleanKeyword","tsNullKeyword","numericLiteral","tsNumberKeyword","tsStringKeyword","generateUnionTsType","length","tsNeverKeyword","acc","allTypes","emptyUnions","unknownTypes","restStats","attrs"],"mappings":"AAAA,YAAYA,OAAO,eAAc;AACjC,SAQEC,YAAY,QAGP,UAAS;AAEhB,SAAQC,cAAc,QAAO,uBAAsB;AACnD,SAAQC,QAAQ,EAAEC,yBAAyB,QAAO,iBAAgB;AAClE,SACEC,uBAAuB,EACvBC,0BAA0B,EAC1BC,gBAAgB,EAChBC,WAAW,QACN,eAAc;AAGrB,OAAO,MAAMC;IACKC,OAAkB;IAClCC,gBAAgBH,YACd,+DAA+D;IAC/D,CAAC,EAACI,KAAK,EAAgC;QACrC,MAAMC,MAAMX,eAAeU;QAC3B,MAAME,WAAWb,aAAaY,KAAK,IAAI,CAACH,MAAM;QAC9C,MAAMK,SAAS,IAAI,CAACC,cAAc,CAACF;QACnC,MAAMG,QAAQC,+BAA+BJ;QAC7C,OAAO;YAACG;YAAOF;QAAM;IACvB,GACD;IACOI,cAAc,MAAK;IAEnBC,cAAc,IAAIC,MAA2B;IAE7CC,UAAU,IAAID,MAAuB;IAE7C,YAAYX,MAAkB,CAAE;QAC9B,IAAI,CAACA,MAAM,GAAGA;QAEd,MAAMa,kBAAkB,IAAIC;QAC5B,KAAK,MAAMC,QAAQf,OAAQ;YACzB,IAAIa,gBAAgBG,GAAG,CAACD,KAAKE,IAAI,GAAG;gBAClC,MAAM,IAAIC,MACR,CAAC,qBAAqB,EAAEH,KAAKE,IAAI,CAAC,8DAA8D,CAAC;YAErG;YACAJ,gBAAgBM,GAAG,CAACJ,KAAKE,IAAI;QAC/B;QAEA,KAAK,MAAMF,QAAQf,OAAQ;YACzB,MAAMoB,yBAAyB,IAAIN,IAAI;mBAAI,IAAI,CAACJ,WAAW,CAACW,MAAM;aAAG,CAACC,GAAG,CAAC,CAACC,KAAOA,GAAGN,IAAI;YACzF,MAAMO,mBAAmB5B,2BAA2BmB,KAAKE,IAAI,EAA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AS;gBACZ,IAAI/F,SAAS0C,EAAE,CAACmD,MAAM,KAAK,GAAG;oBAC5B,OAAO;wBAACG,UAAU;wBAAGC,aAAa;wBAAGC,cAAc;oBAAC;gBACtD;gBAEA,IAAIH,MAAM;oBAACC,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC,EAAE,8BAA8B;;gBACvF,KAAK,MAAMvF,QAAQX,SAAS0C,EAAE,CAAE;oBAC9B,MAAM,EAACsD,QAAQ,EAAEC,WAAW,EAAEC,YAAY,EAAC,GAAG9F,+BAA+BO;oBAC7EoF,MAAM;wBACJC,UAAUD,IAAIC,QAAQ,GAAGA;wBACzBC,aAAaF,IAAIE,WAAW,GAAGA;wBAC/BC,cAAcH,IAAIG,YAAY,GAAGA;oBACnC;gBACF;gBACA,OAAOH;YACT;QACA,KAAK;YAAW;gBACd,OAAO;oBAACC,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;QACA;YAAS;gBACP,OAAO;oBAACF,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;IACF;AACF;AAEA,SAASpE,YAAY9B,QAAkB;IACrC,IAAIA,SAASW,IAAI,KAAK,SAAS,OAAOX;IACtC,MAAM0C,KAAK1C,SAAS0C,EAAE,CAACnB,MAAM,CAAC,CAAC4B,SAAWA,OAAOxC,IAAI,KAAK;IAC1D,OAAO+B,GAAGmD,MAAM,KAAK,IAAInD,EAAE,CAAC,EAAE,GAAI;QAAC,GAAG1C,QAAQ;QAAE0C;IAAE;AACpD"}
|
|
1
|
+
{"version":3,"sources":["../../src/typescript/schemaTypeGenerator.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport {\n type ArrayTypeNode,\n type DocumentSchemaType,\n type InlineTypeNode,\n type ObjectAttribute,\n type ObjectTypeNode,\n type SchemaType,\n type TypeDeclarationSchemaType,\n typeEvaluate,\n type TypeNode,\n type UnionTypeNode,\n} from 'groq-js'\n\nimport {safeParseQuery} from '../safeParseQuery.js'\nimport {ARRAY_OF, INTERNAL_REFERENCE_SYMBOL} from './constants.js'\nimport {\n getFilterArrayUnionType,\n getUniqueIdentifierForName,\n isIdentifierName,\n weakMapMemo,\n} from './helpers.js'\nimport {type ExtractedQuery, type TypeEvaluationStats} from './types.js'\n\n/**\n * Generates TypeScript types from a schema, as `sanity schema extract` writes it.\n *\n * On construction, every type in the schema gets a TypeScript type and a unique alias\n * identifier; iterating the instance yields them as `{name, id, tsType}`, in schema order.\n * `generateTsType` turns any groq-js type node into a TypeScript type that names schema types\n * by those aliases, and `evaluateQuery` does so for the result of a GROQ query. A tool that\n * types GROQ outside `TypeGenerator`, such as a TypeScript content mapper for `.groq` files,\n * uses this class so that its output agrees with what `sanity typegen generate` writes.\n * @beta\n */\nexport class SchemaTypeGenerator {\n public readonly schema: SchemaType\n evaluateQuery = weakMapMemo(\n // eslint-disable-next-line unicorn/consistent-function-scoping\n ({query}: Pick<ExtractedQuery, 'query'>): {stats: TypeEvaluationStats; tsType: t.TSType} => {\n const ast = safeParseQuery(query)\n const typeNode = typeEvaluate(ast, this.schema)\n const tsType = this.generateTsType(typeNode)\n const stats = walkAndCountQueryTypeNodeStats(typeNode)\n return {stats, tsType}\n },\n )\n private arrayOfUsed = false\n\n private identifiers = new Map<string, t.Identifier>()\n\n private tsTypes = new Map<string, t.TSType>()\n\n constructor(schema: SchemaType) {\n this.schema = schema\n\n const uniqueTypeNames = new Set<string>()\n for (const type of schema) {\n if (uniqueTypeNames.has(type.name)) {\n throw new Error(\n `Duplicate type name \"${type.name}\" in schema. Type names must be unique within the same schema.`,\n )\n }\n uniqueTypeNames.add(type.name)\n }\n\n for (const type of schema) {\n const currentIdentifierNames = new Set([...this.identifiers.values()].map((id) => id.name))\n const uniqueIdentifier = getUniqueIdentifierForName(type.name, currentIdentifierNames)\n this.identifiers.set(type.name, uniqueIdentifier)\n }\n\n for (const type of schema) {\n this.tsTypes.set(type.name, this.generateTsType(type))\n }\n }\n\n /** The names of the schema's document types, in schema order. */\n documentTypeNames(): string[] {\n return this.schema.filter((schemaType) => schemaType.type === 'document').map(({name}) => name)\n }\n\n /**\n * Evaluates a projection for one document type, as `*[_type == TYPE][0]PROJECTION` without\n * the `null` for a missing document: the SDK projects documents it has found.\n */\n evaluateProjection({documentType, projection}: {documentType: string; projection: string}): {\n stats: TypeEvaluationStats\n tsType: t.TSType\n } {\n const ast = safeParseQuery(`*[_type == ${JSON.stringify(documentType)}][0]${projection}`)\n const typeNode = withoutNull(typeEvaluate(ast, this.schema))\n return {stats: walkAndCountQueryTypeNodeStats(typeNode), tsType: this.generateTsType(typeNode)}\n }\n\n /**\n * The TypeScript type for a groq-js type node. A reference to a schema type becomes its alias\n * identifier, an array of inline types becomes `ArrayOf<...>` (and `isArrayOfUsed` reports\n * that the helper is needed), and a reference object carries `internalGroqTypeReferenceTo`.\n */\n generateTsType(typeNode: DocumentSchemaType | TypeDeclarationSchemaType | TypeNode): t.TSType {\n switch (typeNode.type) {\n case 'array': {\n return this.generateArrayTsType(typeNode)\n }\n case 'boolean': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.booleanLiteral(typeNode.value))\n }\n return t.tsBooleanKeyword()\n }\n case 'document': {\n return this.generateDocumentTsType(typeNode)\n }\n case 'inline': {\n return this.generateInlineTsType(typeNode)\n }\n case 'null': {\n return t.tsNullKeyword()\n }\n case 'number': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.numericLiteral(typeNode.value))\n }\n return t.tsNumberKeyword()\n }\n case 'object': {\n return this.generateObjectTsType(typeNode)\n }\n case 'string': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.stringLiteral(typeNode.value))\n }\n return t.tsStringKeyword()\n }\n case 'type': {\n return this.generateTsType(typeNode.value)\n }\n case 'union': {\n return this.generateUnionTsType(typeNode)\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n\n default: {\n throw new Error(\n `Encountered unsupported node type \"${\n // @ts-expect-error This should never happen\n typeNode.type\n }\" while generating schema types`,\n )\n }\n }\n }\n\n getType(typeName: string): {id: t.Identifier; tsType: t.TSType} | undefined {\n const tsType = this.tsTypes.get(typeName)\n const id = this.identifiers.get(typeName)\n if (tsType && id) return {id, tsType}\n return undefined\n }\n\n hasType(typeName: string): boolean {\n return this.tsTypes.has(typeName)\n }\n\n isArrayOfUsed(): boolean {\n return this.arrayOfUsed\n }\n\n *[Symbol.iterator]() {\n for (const {name} of this.schema) {\n yield {name, ...this.getType(name)!}\n }\n }\n\n typeNames(): string[] {\n return this.schema.map((schemaType) => schemaType.name)\n }\n\n /**\n * Helper function used to generate TS types for arrays of inline types, or arrays of inline types\n * wrapped in the ArrayOf wrapper that adds _key prop\n */\n private generateArrayOfTsType(typeNode: ArrayTypeNode): t.TSTypeReference {\n this.arrayOfUsed = true\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(ARRAY_OF, t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // Helper function used to generate TS types for array type nodes.\n private generateArrayTsType(typeNode: ArrayTypeNode): t.TSTypeReference | t.TSUnionType {\n // if it's an array of a single inline type, wrap it in ArrayOf\n if (typeNode.of.type === 'inline') {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // if it's not an inline object and not a union, wrap in Array\n if (typeNode.of.type !== 'union') {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // if it's not a union type or all of the union type members are non-inlines, wrap type in Array\n if (typeNode.of.of.every((unionTypeNode) => unionTypeNode.type !== 'inline')) {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // all the union types nodes are inline\n if (typeNode.of.of.every((unionMember) => unionMember.type === 'inline')) {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // some of the union types are inlines, while some are not - split and recurse\n const arrayOfNonInline = getFilterArrayUnionType(typeNode, (member) => member.type !== 'inline')\n const arrayOfInline = getFilterArrayUnionType(typeNode, (member) => member.type === 'inline')\n\n return t.tsUnionType([\n this.generateArrayTsType(arrayOfNonInline),\n this.generateArrayTsType(arrayOfInline),\n ])\n }\n\n // Helper function used to generate TS types for document type nodes.\n private generateDocumentTsType(document: DocumentSchemaType): t.TSType {\n const props = Object.entries(document.attributes).map(([key, node]) =>\n this.generateTsObjectProperty(key, node),\n )\n\n return t.tsTypeLiteral(props)\n }\n\n private generateInlineTsType(typeNode: InlineTypeNode): t.TSType {\n const id = this.identifiers.get(typeNode.name)\n if (!id) {\n // Not found in schema, return unknown type\n return t.addComment(\n t.tsUnknownKeyword(),\n 'trailing',\n ` Unable to locate the referenced type \"${typeNode.name}\" in schema`,\n true,\n )\n }\n\n return t.tsTypeReference(id)\n }\n\n // Helper function used to generate TS types for object type nodes.\n private generateObjectTsType(typeNode: ObjectTypeNode): t.TSType {\n const props: t.TSPropertySignature[] = []\n for (const [key, attribute] of Object.entries(typeNode.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n const rest = typeNode.rest\n\n if (rest) {\n switch (rest.type) {\n case 'inline': {\n const resolved = this.generateInlineTsType(rest)\n // if object rest is unknown, we can't generate a type literal for it\n if (t.isTSUnknownKeyword(resolved)) return resolved\n return t.tsIntersectionType([t.tsTypeLiteral(props), resolved])\n }\n case 'object': {\n for (const [key, attribute] of Object.entries(rest.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n break\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n default: {\n // @ts-expect-error This should never happen\n throw new Error(`Type \"${rest.type}\" not found in schema`)\n }\n }\n }\n\n if (typeNode.dereferencesTo) {\n const derefType = Object.assign(\n t.tsPropertySignature(\n INTERNAL_REFERENCE_SYMBOL,\n t.tsTypeAnnotation(t.tsLiteralType(t.stringLiteral(typeNode.dereferencesTo))),\n ),\n {computed: true, optional: true},\n )\n props.push(derefType)\n }\n\n return t.tsTypeLiteral(props)\n }\n\n // Helper function used to generate TS types for object properties.\n private generateTsObjectProperty(key: string, attribute: ObjectAttribute): t.TSPropertySignature {\n const type = this.generateTsType(attribute.value)\n const keyNode = isIdentifierName(key) ? t.identifier(key) : t.stringLiteral(key)\n const propertySignature = t.tsPropertySignature(keyNode, t.tsTypeAnnotation(type))\n propertySignature.optional = attribute.optional\n\n return propertySignature\n }\n\n // Helper function used to generate TS types for union type nodes.\n private generateUnionTsType(typeNode: UnionTypeNode): t.TSType {\n if (typeNode.of.length === 0) return t.tsNeverKeyword()\n if (typeNode.of.length === 1) return this.generateTsType(typeNode.of[0]!)\n return t.tsUnionType(typeNode.of.map((node) => this.generateTsType(node)))\n }\n}\n\nexport function walkAndCountQueryTypeNodeStats(typeNode: TypeNode): TypeEvaluationStats {\n switch (typeNode.type) {\n case 'array': {\n const acc = walkAndCountQueryTypeNodeStats(typeNode.of)\n acc.allTypes += 1 // count the array type itself\n return acc\n }\n case 'object': {\n // if the rest is unknown, we count it as one unknown type\n if (typeNode.rest && typeNode.rest.type === 'unknown') {\n return {allTypes: 2, emptyUnions: 0, unknownTypes: 1} // count the object type itself as well\n }\n\n const restStats = typeNode.rest\n ? walkAndCountQueryTypeNodeStats(typeNode.rest)\n : {allTypes: 0, emptyUnions: 0, unknownTypes: 0}\n\n // count the object type itself\n restStats.allTypes += 1\n\n const attrs = Object.values(typeNode.attributes)\n let acc = restStats\n for (const attribute of attrs) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(\n attribute.value,\n )\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'union': {\n if (typeNode.of.length === 0) {\n return {allTypes: 1, emptyUnions: 1, unknownTypes: 0}\n }\n\n let acc = {allTypes: 1, emptyUnions: 0, unknownTypes: 0} // count the union type itself\n for (const type of typeNode.of) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(type)\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'unknown': {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 1}\n }\n default: {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 0}\n }\n }\n}\n\nfunction withoutNull(typeNode: TypeNode): TypeNode {\n if (typeNode.type !== 'union') return typeNode\n const of = typeNode.of.filter((member) => member.type !== 'null')\n return of.length === 1 ? of[0]! : {...typeNode, of}\n}\n"],"names":["t","typeEvaluate","safeParseQuery","ARRAY_OF","INTERNAL_REFERENCE_SYMBOL","getFilterArrayUnionType","getUniqueIdentifierForName","isIdentifierName","weakMapMemo","SchemaTypeGenerator","schema","evaluateQuery","query","ast","typeNode","tsType","generateTsType","stats","walkAndCountQueryTypeNodeStats","arrayOfUsed","identifiers","Map","tsTypes","uniqueTypeNames","Set","type","has","name","Error","add","currentIdentifierNames","values","map","id","uniqueIdentifier","set","documentTypeNames","filter","schemaType","evaluateProjection","documentType","projection","JSON","stringify","withoutNull","generateArrayTsType","value","undefined","tsLiteralType","booleanLiteral","tsBooleanKeyword","generateDocumentTsType","generateInlineTsType","tsNullKeyword","numericLiteral","tsNumberKeyword","generateObjectTsType","stringLiteral","tsStringKeyword","generateUnionTsType","tsUnknownKeyword","getType","typeName","get","hasType","isArrayOfUsed","Symbol","iterator","typeNames","generateArrayOfTsType","typeNodes","of","tsTypeReference","tsTypeParameterInstantiation","identifier","every","unionTypeNode","unionMember","arrayOfNonInline","member","arrayOfInline","tsUnionType","document","props","Object","entries","attributes","key","node","generateTsObjectProperty","tsTypeLiteral","addComment","attribute","push","rest","resolved","isTSUnknownKeyword","tsIntersectionType","dereferencesTo","derefType","assign","tsPropertySignature","tsTypeAnnotation","computed","optional","keyNode","propertySignature","length","tsNeverKeyword","acc","allTypes","emptyUnions","unknownTypes","restStats","attrs"],"mappings":"AAAA,YAAYA,OAAO,eA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