@sanity/codegen 3.93.1-bump-pkg-utils.10.412e2ab170 → 3.93.1-next.0.3919f50978
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/lib/index.d.mts +132 -116
- package/lib/index.d.ts +132 -116
- package/package.json +3 -3
package/lib/index.d.mts
CHANGED
|
@@ -1,87 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare function readSchema(path: string): Promise<SchemaType>;
|
|
36
|
-
/**
|
|
37
|
-
* safeParseQuery parses a GROQ query string, but first attempts to extract any parameters used in slices. This method is _only_
|
|
38
|
-
* intended for use in type generation where we don't actually execute the parsed AST on a dataset, and should not be used elsewhere.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
declare function safeParseQuery(query: string): groq_js1.ExprNode;
|
|
42
|
-
/**
|
|
43
|
-
* Finds occurences of `[($start|{number})..($end|{number})]` in a query string and returns the start and end values, and return
|
|
44
|
-
* the names of the start and end variables.
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
type resolveExpressionReturnType = string;
|
|
48
|
-
/**
|
|
49
|
-
* NamedQueryResult is a result of a named query
|
|
50
|
-
*/
|
|
51
|
-
interface NamedQueryResult {
|
|
52
|
-
/** name is the name of the query */
|
|
53
|
-
name: string;
|
|
54
|
-
/** result is a groq query */
|
|
55
|
-
result: resolveExpressionReturnType;
|
|
56
|
-
/** location is the location of the query in the source */
|
|
57
|
-
location: {
|
|
58
|
-
start?: {
|
|
59
|
-
line: number;
|
|
60
|
-
column: number;
|
|
61
|
-
index: number;
|
|
62
|
-
};
|
|
63
|
-
end?: {
|
|
64
|
-
line: number;
|
|
65
|
-
column: number;
|
|
66
|
-
index: number;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* resolveExpression takes a node and returns the resolved value of the expression.
|
|
72
|
-
* @beta
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
type ResultQueries = {
|
|
76
|
-
type: 'queries';
|
|
77
|
-
filename: string;
|
|
78
|
-
queries: NamedQueryResult[];
|
|
79
|
-
};
|
|
80
|
-
type ResultError = {
|
|
81
|
-
type: 'error';
|
|
82
|
-
error: Error;
|
|
83
|
-
filename: string;
|
|
84
|
-
};
|
|
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
|
+
|
|
85
35
|
/**
|
|
86
36
|
* findQueriesInPath takes a path or array of paths and returns all GROQ queries in the files.
|
|
87
37
|
* @param path - The path or array of paths to search for queries
|
|
@@ -91,15 +41,16 @@ type ResultError = {
|
|
|
91
41
|
* @beta
|
|
92
42
|
* @internal
|
|
93
43
|
*/
|
|
94
|
-
declare function findQueriesInPath({
|
|
44
|
+
export declare function findQueriesInPath({
|
|
95
45
|
path,
|
|
96
46
|
babelOptions,
|
|
97
|
-
resolver
|
|
47
|
+
resolver,
|
|
98
48
|
}: {
|
|
99
|
-
path: string | string[]
|
|
100
|
-
babelOptions?: TransformOptions
|
|
101
|
-
resolver?: NodeJS.RequireResolve
|
|
102
|
-
}): AsyncGenerator<ResultQueries | ResultError
|
|
49
|
+
path: string | string[]
|
|
50
|
+
babelOptions?: TransformOptions
|
|
51
|
+
resolver?: NodeJS.RequireResolve
|
|
52
|
+
}): AsyncGenerator<ResultQueries | ResultError>
|
|
53
|
+
|
|
103
54
|
/**
|
|
104
55
|
* findQueriesInSource takes a source string and returns all GROQ queries in it.
|
|
105
56
|
* @param source - The source code to search for queries
|
|
@@ -110,7 +61,13 @@ declare function findQueriesInPath({
|
|
|
110
61
|
* @beta
|
|
111
62
|
* @internal
|
|
112
63
|
*/
|
|
113
|
-
declare function findQueriesInSource(
|
|
64
|
+
export declare function findQueriesInSource(
|
|
65
|
+
source: string,
|
|
66
|
+
filename: string,
|
|
67
|
+
babelConfig?: TransformOptions,
|
|
68
|
+
resolver?: NodeJS.RequireResolve,
|
|
69
|
+
): NamedQueryResult[]
|
|
70
|
+
|
|
114
71
|
/**
|
|
115
72
|
* This is a custom implementation of require.resolve that takes into account the paths
|
|
116
73
|
* configuration in tsconfig.json. This is necessary if we want to resolve paths that are
|
|
@@ -118,36 +75,94 @@ declare function findQueriesInSource(source: string, filename: string, babelConf
|
|
|
118
75
|
* Resolving here is best effort and might not work in all cases.
|
|
119
76
|
* @beta
|
|
120
77
|
*/
|
|
121
|
-
declare function getResolver(cwd?: string): NodeJS.RequireResolve
|
|
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
|
+
|
|
122
119
|
/**
|
|
123
120
|
* Register Babel with the given options
|
|
124
121
|
*
|
|
125
122
|
* @param babelOptions - The options to use when registering Babel
|
|
126
123
|
* @beta
|
|
127
124
|
*/
|
|
128
|
-
declare function registerBabel(babelOptions?: TransformOptions): void
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
|
|
133
148
|
/**
|
|
134
149
|
* A class used to generate TypeScript types from a given schema
|
|
135
150
|
* @internal
|
|
136
151
|
* @beta
|
|
137
152
|
*/
|
|
138
|
-
declare class TypeGenerator {
|
|
139
|
-
private generatedTypeName
|
|
140
|
-
private typeNameMap
|
|
141
|
-
private typeNodeNameMap
|
|
142
|
-
private readonly schema
|
|
143
|
-
constructor(schema: SchemaType)
|
|
153
|
+
export declare class TypeGenerator {
|
|
154
|
+
private generatedTypeName
|
|
155
|
+
private typeNameMap
|
|
156
|
+
private typeNodeNameMap
|
|
157
|
+
private readonly schema
|
|
158
|
+
constructor(schema: SchemaType)
|
|
144
159
|
/**
|
|
145
160
|
* Generate TypeScript types for the given schema
|
|
146
161
|
* @returns string
|
|
147
162
|
* @internal
|
|
148
163
|
* @beta
|
|
149
164
|
*/
|
|
150
|
-
generateSchemaTypes(): string
|
|
165
|
+
generateSchemaTypes(): string
|
|
151
166
|
/**
|
|
152
167
|
* Takes a identifier and a type node and generates a type alias for the type node.
|
|
153
168
|
* @param identifierName - The name of the type to generated
|
|
@@ -156,8 +171,8 @@ declare class TypeGenerator {
|
|
|
156
171
|
* @internal
|
|
157
172
|
* @beta
|
|
158
173
|
*/
|
|
159
|
-
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
160
|
-
static generateKnownTypes(): string
|
|
174
|
+
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
175
|
+
static generateKnownTypes(): string
|
|
161
176
|
/**
|
|
162
177
|
* Takes a list of queries from the codebase and generates a type declaration
|
|
163
178
|
* for SanityClient to consume.
|
|
@@ -170,19 +185,20 @@ declare class TypeGenerator {
|
|
|
170
185
|
* @internal
|
|
171
186
|
* @beta
|
|
172
187
|
*/
|
|
173
|
-
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
188
|
+
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
174
189
|
/**
|
|
175
190
|
* Since we are sanitizing identifiers we migt end up with collisions. Ie there might be a type mux.video and muxVideo, both these
|
|
176
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.
|
|
177
192
|
* When we reference a type we also keep track of the original name so we can reference the correct type later.
|
|
178
193
|
*/
|
|
179
|
-
private getTypeName
|
|
180
|
-
private getTypeNodeType
|
|
181
|
-
private generateArrayTsType
|
|
182
|
-
private generateObjectProperty
|
|
183
|
-
private generateObjectTsType
|
|
184
|
-
private generateInlineTsType
|
|
185
|
-
private generateUnionTsType
|
|
186
|
-
private generateDocumentType
|
|
194
|
+
private getTypeName
|
|
195
|
+
private getTypeNodeType
|
|
196
|
+
private generateArrayTsType
|
|
197
|
+
private generateObjectProperty
|
|
198
|
+
private generateObjectTsType
|
|
199
|
+
private generateInlineTsType
|
|
200
|
+
private generateUnionTsType
|
|
201
|
+
private generateDocumentType
|
|
187
202
|
}
|
|
188
|
-
|
|
203
|
+
|
|
204
|
+
export {}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,87 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
declare function readSchema(path: string): Promise<SchemaType>;
|
|
36
|
-
/**
|
|
37
|
-
* safeParseQuery parses a GROQ query string, but first attempts to extract any parameters used in slices. This method is _only_
|
|
38
|
-
* intended for use in type generation where we don't actually execute the parsed AST on a dataset, and should not be used elsewhere.
|
|
39
|
-
* @internal
|
|
40
|
-
*/
|
|
41
|
-
declare function safeParseQuery(query: string): groq_js1.ExprNode;
|
|
42
|
-
/**
|
|
43
|
-
* Finds occurences of `[($start|{number})..($end|{number})]` in a query string and returns the start and end values, and return
|
|
44
|
-
* the names of the start and end variables.
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
type resolveExpressionReturnType = string;
|
|
48
|
-
/**
|
|
49
|
-
* NamedQueryResult is a result of a named query
|
|
50
|
-
*/
|
|
51
|
-
interface NamedQueryResult {
|
|
52
|
-
/** name is the name of the query */
|
|
53
|
-
name: string;
|
|
54
|
-
/** result is a groq query */
|
|
55
|
-
result: resolveExpressionReturnType;
|
|
56
|
-
/** location is the location of the query in the source */
|
|
57
|
-
location: {
|
|
58
|
-
start?: {
|
|
59
|
-
line: number;
|
|
60
|
-
column: number;
|
|
61
|
-
index: number;
|
|
62
|
-
};
|
|
63
|
-
end?: {
|
|
64
|
-
line: number;
|
|
65
|
-
column: number;
|
|
66
|
-
index: number;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* resolveExpression takes a node and returns the resolved value of the expression.
|
|
72
|
-
* @beta
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
type ResultQueries = {
|
|
76
|
-
type: 'queries';
|
|
77
|
-
filename: string;
|
|
78
|
-
queries: NamedQueryResult[];
|
|
79
|
-
};
|
|
80
|
-
type ResultError = {
|
|
81
|
-
type: 'error';
|
|
82
|
-
error: Error;
|
|
83
|
-
filename: string;
|
|
84
|
-
};
|
|
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
|
+
|
|
85
35
|
/**
|
|
86
36
|
* findQueriesInPath takes a path or array of paths and returns all GROQ queries in the files.
|
|
87
37
|
* @param path - The path or array of paths to search for queries
|
|
@@ -91,15 +41,16 @@ type ResultError = {
|
|
|
91
41
|
* @beta
|
|
92
42
|
* @internal
|
|
93
43
|
*/
|
|
94
|
-
declare function findQueriesInPath({
|
|
44
|
+
export declare function findQueriesInPath({
|
|
95
45
|
path,
|
|
96
46
|
babelOptions,
|
|
97
|
-
resolver
|
|
47
|
+
resolver,
|
|
98
48
|
}: {
|
|
99
|
-
path: string | string[]
|
|
100
|
-
babelOptions?: TransformOptions
|
|
101
|
-
resolver?: NodeJS.RequireResolve
|
|
102
|
-
}): AsyncGenerator<ResultQueries | ResultError
|
|
49
|
+
path: string | string[]
|
|
50
|
+
babelOptions?: TransformOptions
|
|
51
|
+
resolver?: NodeJS.RequireResolve
|
|
52
|
+
}): AsyncGenerator<ResultQueries | ResultError>
|
|
53
|
+
|
|
103
54
|
/**
|
|
104
55
|
* findQueriesInSource takes a source string and returns all GROQ queries in it.
|
|
105
56
|
* @param source - The source code to search for queries
|
|
@@ -110,7 +61,13 @@ declare function findQueriesInPath({
|
|
|
110
61
|
* @beta
|
|
111
62
|
* @internal
|
|
112
63
|
*/
|
|
113
|
-
declare function findQueriesInSource(
|
|
64
|
+
export declare function findQueriesInSource(
|
|
65
|
+
source: string,
|
|
66
|
+
filename: string,
|
|
67
|
+
babelConfig?: TransformOptions,
|
|
68
|
+
resolver?: NodeJS.RequireResolve,
|
|
69
|
+
): NamedQueryResult[]
|
|
70
|
+
|
|
114
71
|
/**
|
|
115
72
|
* This is a custom implementation of require.resolve that takes into account the paths
|
|
116
73
|
* configuration in tsconfig.json. This is necessary if we want to resolve paths that are
|
|
@@ -118,36 +75,94 @@ declare function findQueriesInSource(source: string, filename: string, babelConf
|
|
|
118
75
|
* Resolving here is best effort and might not work in all cases.
|
|
119
76
|
* @beta
|
|
120
77
|
*/
|
|
121
|
-
declare function getResolver(cwd?: string): NodeJS.RequireResolve
|
|
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
|
+
|
|
122
119
|
/**
|
|
123
120
|
* Register Babel with the given options
|
|
124
121
|
*
|
|
125
122
|
* @param babelOptions - The options to use when registering Babel
|
|
126
123
|
* @beta
|
|
127
124
|
*/
|
|
128
|
-
declare function registerBabel(babelOptions?: TransformOptions): void
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
+
|
|
133
148
|
/**
|
|
134
149
|
* A class used to generate TypeScript types from a given schema
|
|
135
150
|
* @internal
|
|
136
151
|
* @beta
|
|
137
152
|
*/
|
|
138
|
-
declare class TypeGenerator {
|
|
139
|
-
private generatedTypeName
|
|
140
|
-
private typeNameMap
|
|
141
|
-
private typeNodeNameMap
|
|
142
|
-
private readonly schema
|
|
143
|
-
constructor(schema: SchemaType)
|
|
153
|
+
export declare class TypeGenerator {
|
|
154
|
+
private generatedTypeName
|
|
155
|
+
private typeNameMap
|
|
156
|
+
private typeNodeNameMap
|
|
157
|
+
private readonly schema
|
|
158
|
+
constructor(schema: SchemaType)
|
|
144
159
|
/**
|
|
145
160
|
* Generate TypeScript types for the given schema
|
|
146
161
|
* @returns string
|
|
147
162
|
* @internal
|
|
148
163
|
* @beta
|
|
149
164
|
*/
|
|
150
|
-
generateSchemaTypes(): string
|
|
165
|
+
generateSchemaTypes(): string
|
|
151
166
|
/**
|
|
152
167
|
* Takes a identifier and a type node and generates a type alias for the type node.
|
|
153
168
|
* @param identifierName - The name of the type to generated
|
|
@@ -156,8 +171,8 @@ declare class TypeGenerator {
|
|
|
156
171
|
* @internal
|
|
157
172
|
* @beta
|
|
158
173
|
*/
|
|
159
|
-
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
160
|
-
static generateKnownTypes(): string
|
|
174
|
+
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
175
|
+
static generateKnownTypes(): string
|
|
161
176
|
/**
|
|
162
177
|
* Takes a list of queries from the codebase and generates a type declaration
|
|
163
178
|
* for SanityClient to consume.
|
|
@@ -170,19 +185,20 @@ declare class TypeGenerator {
|
|
|
170
185
|
* @internal
|
|
171
186
|
* @beta
|
|
172
187
|
*/
|
|
173
|
-
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
188
|
+
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
174
189
|
/**
|
|
175
190
|
* Since we are sanitizing identifiers we migt end up with collisions. Ie there might be a type mux.video and muxVideo, both these
|
|
176
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.
|
|
177
192
|
* When we reference a type we also keep track of the original name so we can reference the correct type later.
|
|
178
193
|
*/
|
|
179
|
-
private getTypeName
|
|
180
|
-
private getTypeNodeType
|
|
181
|
-
private generateArrayTsType
|
|
182
|
-
private generateObjectProperty
|
|
183
|
-
private generateObjectTsType
|
|
184
|
-
private generateInlineTsType
|
|
185
|
-
private generateUnionTsType
|
|
186
|
-
private generateDocumentType
|
|
194
|
+
private getTypeName
|
|
195
|
+
private getTypeNodeType
|
|
196
|
+
private generateArrayTsType
|
|
197
|
+
private generateObjectProperty
|
|
198
|
+
private generateObjectTsType
|
|
199
|
+
private generateInlineTsType
|
|
200
|
+
private generateUnionTsType
|
|
201
|
+
private generateDocumentType
|
|
187
202
|
}
|
|
188
|
-
|
|
203
|
+
|
|
204
|
+
export {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/codegen",
|
|
3
|
-
"version": "3.93.1-
|
|
3
|
+
"version": "3.93.1-next.0.3919f50978",
|
|
4
4
|
"description": "Codegen toolkit for Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@babel/types": "^7.27.6",
|
|
62
62
|
"debug": "^4.3.4",
|
|
63
63
|
"globby": "^11.1.0",
|
|
64
|
-
"groq": "3.93.1-
|
|
64
|
+
"groq": "3.93.1-next.0.3919f50978",
|
|
65
65
|
"groq-js": "^1.17.0",
|
|
66
66
|
"json5": "^2.2.3",
|
|
67
67
|
"tsconfig-paths": "^4.2.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "3919f5097842e32fc60a66b15761e903a8f3eade"
|
|
89
89
|
}
|