@sanity/codegen 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.7
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/LICENSE +1 -1
- package/lib/index.d.ts +158 -92
- package/lib/index.js +497 -298
- package/lib/index.js.map +1 -1
- package/package.json +30 -26
- package/lib/index.d.mts +0 -204
- package/lib/index.mjs +0 -753
- package/lib/index.mjs.map +0 -1
package/lib/index.d.mts
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import {ExprNode} from 'groq-js'
|
|
2
|
-
import {SchemaType} from 'groq-js'
|
|
3
|
-
import {TransformOptions} from '@babel/core'
|
|
4
|
-
import {TypeNode} from 'groq-js'
|
|
5
|
-
import * as z from 'zod'
|
|
6
|
-
|
|
7
|
-
export declare type CodegenConfig = z.infer<typeof configDefintion>
|
|
8
|
-
|
|
9
|
-
declare const configDefintion: z.ZodObject<
|
|
10
|
-
{
|
|
11
|
-
path: z.ZodDefault<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, 'many'>]>>
|
|
12
|
-
schema: z.ZodDefault<z.ZodString>
|
|
13
|
-
generates: z.ZodDefault<z.ZodString>
|
|
14
|
-
formatGeneratedCode: z.ZodDefault<z.ZodBoolean>
|
|
15
|
-
overloadClientMethods: z.ZodDefault<z.ZodBoolean>
|
|
16
|
-
},
|
|
17
|
-
'strip',
|
|
18
|
-
z.ZodTypeAny,
|
|
19
|
-
{
|
|
20
|
-
path: string | string[]
|
|
21
|
-
schema: string
|
|
22
|
-
generates: string
|
|
23
|
-
formatGeneratedCode: boolean
|
|
24
|
-
overloadClientMethods: boolean
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
path?: string | string[] | undefined
|
|
28
|
-
schema?: string | undefined
|
|
29
|
-
generates?: string | undefined
|
|
30
|
-
formatGeneratedCode?: boolean | undefined
|
|
31
|
-
overloadClientMethods?: boolean | undefined
|
|
32
|
-
}
|
|
33
|
-
>
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* findQueriesInPath takes a path or array of paths and returns all GROQ queries in the files.
|
|
37
|
-
* @param path - The path or array of paths to search for queries
|
|
38
|
-
* @param babelOptions - The babel configuration to use when parsing the source
|
|
39
|
-
* @param resolver - A resolver function to use when resolving module imports
|
|
40
|
-
* @returns An async generator that yields the results of the search
|
|
41
|
-
* @beta
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
export declare function findQueriesInPath({
|
|
45
|
-
path,
|
|
46
|
-
babelOptions,
|
|
47
|
-
resolver,
|
|
48
|
-
}: {
|
|
49
|
-
path: string | string[]
|
|
50
|
-
babelOptions?: TransformOptions
|
|
51
|
-
resolver?: NodeJS.RequireResolve
|
|
52
|
-
}): AsyncGenerator<ResultQueries | ResultError>
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* findQueriesInSource takes a source string and returns all GROQ queries in it.
|
|
56
|
-
* @param source - The source code to search for queries
|
|
57
|
-
* @param filename - The filename of the source code
|
|
58
|
-
* @param babelConfig - The babel configuration to use when parsing the source
|
|
59
|
-
* @param resolver - A resolver function to use when resolving module imports
|
|
60
|
-
* @returns
|
|
61
|
-
* @beta
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
export declare function findQueriesInSource(
|
|
65
|
-
source: string,
|
|
66
|
-
filename: string,
|
|
67
|
-
babelConfig?: TransformOptions,
|
|
68
|
-
resolver?: NodeJS.RequireResolve,
|
|
69
|
-
): NamedQueryResult[]
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* This is a custom implementation of require.resolve that takes into account the paths
|
|
73
|
-
* configuration in tsconfig.json. This is necessary if we want to resolve paths that are
|
|
74
|
-
* custom defined in the tsconfig.json file.
|
|
75
|
-
* Resolving here is best effort and might not work in all cases.
|
|
76
|
-
* @beta
|
|
77
|
-
*/
|
|
78
|
-
export declare function getResolver(cwd?: string): NodeJS.RequireResolve
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* NamedQueryResult is a result of a named query
|
|
82
|
-
*/
|
|
83
|
-
declare interface NamedQueryResult {
|
|
84
|
-
/** name is the name of the query */
|
|
85
|
-
name: string
|
|
86
|
-
/** result is a groq query */
|
|
87
|
-
result: resolveExpressionReturnType
|
|
88
|
-
/** location is the location of the query in the source */
|
|
89
|
-
location: {
|
|
90
|
-
start?: {
|
|
91
|
-
line: number
|
|
92
|
-
column: number
|
|
93
|
-
index: number
|
|
94
|
-
}
|
|
95
|
-
end?: {
|
|
96
|
-
line: number
|
|
97
|
-
column: number
|
|
98
|
-
index: number
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
declare type QueryWithTypeNode = {
|
|
104
|
-
query: string
|
|
105
|
-
typeNode: TypeNode
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export declare function readConfig(path: string): Promise<CodegenConfig>
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Read a schema from a given path
|
|
112
|
-
* @param path - The path to the schema
|
|
113
|
-
* @returns The schema
|
|
114
|
-
* @internal
|
|
115
|
-
* @beta
|
|
116
|
-
**/
|
|
117
|
-
export declare function readSchema(path: string): Promise<SchemaType>
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Register Babel with the given options
|
|
121
|
-
*
|
|
122
|
-
* @param babelOptions - The options to use when registering Babel
|
|
123
|
-
* @beta
|
|
124
|
-
*/
|
|
125
|
-
export declare function registerBabel(babelOptions?: TransformOptions): void
|
|
126
|
-
|
|
127
|
-
declare type resolveExpressionReturnType = string
|
|
128
|
-
|
|
129
|
-
declare type ResultError = {
|
|
130
|
-
type: 'error'
|
|
131
|
-
error: Error
|
|
132
|
-
filename: string
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
declare type ResultQueries = {
|
|
136
|
-
type: 'queries'
|
|
137
|
-
filename: string
|
|
138
|
-
queries: NamedQueryResult[]
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* safeParseQuery parses a GROQ query string, but first attempts to extract any parameters used in slices. This method is _only_
|
|
143
|
-
* intended for use in type generation where we don't actually execute the parsed AST on a dataset, and should not be used elsewhere.
|
|
144
|
-
* @internal
|
|
145
|
-
*/
|
|
146
|
-
export declare function safeParseQuery(query: string): ExprNode
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* A class used to generate TypeScript types from a given schema
|
|
150
|
-
* @internal
|
|
151
|
-
* @beta
|
|
152
|
-
*/
|
|
153
|
-
export declare class TypeGenerator {
|
|
154
|
-
private generatedTypeName
|
|
155
|
-
private typeNameMap
|
|
156
|
-
private typeNodeNameMap
|
|
157
|
-
private readonly schema
|
|
158
|
-
constructor(schema: SchemaType)
|
|
159
|
-
/**
|
|
160
|
-
* Generate TypeScript types for the given schema
|
|
161
|
-
* @returns string
|
|
162
|
-
* @internal
|
|
163
|
-
* @beta
|
|
164
|
-
*/
|
|
165
|
-
generateSchemaTypes(): string
|
|
166
|
-
/**
|
|
167
|
-
* Takes a identifier and a type node and generates a type alias for the type node.
|
|
168
|
-
* @param identifierName - The name of the type to generated
|
|
169
|
-
* @param typeNode - The type node to generate the type for
|
|
170
|
-
* @returns
|
|
171
|
-
* @internal
|
|
172
|
-
* @beta
|
|
173
|
-
*/
|
|
174
|
-
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
175
|
-
static generateKnownTypes(): string
|
|
176
|
-
/**
|
|
177
|
-
* Takes a list of queries from the codebase and generates a type declaration
|
|
178
|
-
* for SanityClient to consume.
|
|
179
|
-
*
|
|
180
|
-
* Note: only types that have previously been generated with `generateTypeNodeTypes`
|
|
181
|
-
* will be included in the query map.
|
|
182
|
-
*
|
|
183
|
-
* @param queries - A list of queries to generate a type declaration for
|
|
184
|
-
* @returns
|
|
185
|
-
* @internal
|
|
186
|
-
* @beta
|
|
187
|
-
*/
|
|
188
|
-
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
189
|
-
/**
|
|
190
|
-
* Since we are sanitizing identifiers we migt end up with collisions. Ie there might be a type mux.video and muxVideo, both these
|
|
191
|
-
* types would be sanityized into MuxVideo. To avoid this we keep track of the generated type names and add a index to the name.
|
|
192
|
-
* When we reference a type we also keep track of the original name so we can reference the correct type later.
|
|
193
|
-
*/
|
|
194
|
-
private getTypeName
|
|
195
|
-
private getTypeNodeType
|
|
196
|
-
private generateArrayTsType
|
|
197
|
-
private generateObjectProperty
|
|
198
|
-
private generateObjectTsType
|
|
199
|
-
private generateInlineTsType
|
|
200
|
-
private generateUnionTsType
|
|
201
|
-
private generateDocumentType
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export {}
|