@sanity/codegen 3.93.0 → 3.93.1-bump-pkg-utils.10.412e2ab170
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 +116 -132
- package/lib/index.d.ts +116 -132
- package/package.json +3 -3
package/lib/index.d.mts
CHANGED
|
@@ -1,37 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import * as groq_js1 from "groq-js";
|
|
3
|
+
import { SchemaType, TypeNode } from "groq-js";
|
|
4
|
+
import { TransformOptions } from "@babel/core";
|
|
5
|
+
import "@babel/traverse";
|
|
6
|
+
import "@babel/types";
|
|
7
|
+
declare const configDefintion: z.ZodObject<{
|
|
8
|
+
path: z.ZodDefault<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
9
|
+
schema: z.ZodDefault<z.ZodString>;
|
|
10
|
+
generates: z.ZodDefault<z.ZodString>;
|
|
11
|
+
formatGeneratedCode: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
+
overloadClientMethods: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
path: string | string[];
|
|
15
|
+
schema: string;
|
|
16
|
+
generates: string;
|
|
17
|
+
formatGeneratedCode: boolean;
|
|
18
|
+
overloadClientMethods: boolean;
|
|
19
|
+
}, {
|
|
20
|
+
path?: string | string[] | undefined;
|
|
21
|
+
schema?: string | undefined;
|
|
22
|
+
generates?: string | undefined;
|
|
23
|
+
formatGeneratedCode?: boolean | undefined;
|
|
24
|
+
overloadClientMethods?: boolean | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
type CodegenConfig = z.infer<typeof configDefintion>;
|
|
27
|
+
declare function readConfig(path: string): Promise<CodegenConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* Read a schema from a given path
|
|
30
|
+
* @param path - The path to the schema
|
|
31
|
+
* @returns The schema
|
|
32
|
+
* @internal
|
|
33
|
+
* @beta
|
|
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
|
+
};
|
|
35
85
|
/**
|
|
36
86
|
* findQueriesInPath takes a path or array of paths and returns all GROQ queries in the files.
|
|
37
87
|
* @param path - The path or array of paths to search for queries
|
|
@@ -41,16 +91,15 @@ declare const configDefintion: z.ZodObject<
|
|
|
41
91
|
* @beta
|
|
42
92
|
* @internal
|
|
43
93
|
*/
|
|
44
|
-
|
|
94
|
+
declare function findQueriesInPath({
|
|
45
95
|
path,
|
|
46
96
|
babelOptions,
|
|
47
|
-
resolver
|
|
97
|
+
resolver
|
|
48
98
|
}: {
|
|
49
|
-
path: string | string[]
|
|
50
|
-
babelOptions?: TransformOptions
|
|
51
|
-
resolver?: NodeJS.RequireResolve
|
|
52
|
-
}): AsyncGenerator<ResultQueries | ResultError
|
|
53
|
-
|
|
99
|
+
path: string | string[];
|
|
100
|
+
babelOptions?: TransformOptions;
|
|
101
|
+
resolver?: NodeJS.RequireResolve;
|
|
102
|
+
}): AsyncGenerator<ResultQueries | ResultError>;
|
|
54
103
|
/**
|
|
55
104
|
* findQueriesInSource takes a source string and returns all GROQ queries in it.
|
|
56
105
|
* @param source - The source code to search for queries
|
|
@@ -61,13 +110,7 @@ export declare function findQueriesInPath({
|
|
|
61
110
|
* @beta
|
|
62
111
|
* @internal
|
|
63
112
|
*/
|
|
64
|
-
|
|
65
|
-
source: string,
|
|
66
|
-
filename: string,
|
|
67
|
-
babelConfig?: TransformOptions,
|
|
68
|
-
resolver?: NodeJS.RequireResolve,
|
|
69
|
-
): NamedQueryResult[]
|
|
70
|
-
|
|
113
|
+
declare function findQueriesInSource(source: string, filename: string, babelConfig?: TransformOptions, resolver?: NodeJS.RequireResolve): NamedQueryResult[];
|
|
71
114
|
/**
|
|
72
115
|
* This is a custom implementation of require.resolve that takes into account the paths
|
|
73
116
|
* configuration in tsconfig.json. This is necessary if we want to resolve paths that are
|
|
@@ -75,94 +118,36 @@ export declare function findQueriesInSource(
|
|
|
75
118
|
* Resolving here is best effort and might not work in all cases.
|
|
76
119
|
* @beta
|
|
77
120
|
*/
|
|
78
|
-
|
|
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
|
-
|
|
121
|
+
declare function getResolver(cwd?: string): NodeJS.RequireResolve;
|
|
119
122
|
/**
|
|
120
123
|
* Register Babel with the given options
|
|
121
124
|
*
|
|
122
125
|
* @param babelOptions - The options to use when registering Babel
|
|
123
126
|
* @beta
|
|
124
127
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
128
|
+
declare function registerBabel(babelOptions?: TransformOptions): void;
|
|
129
|
+
type QueryWithTypeNode = {
|
|
130
|
+
query: string;
|
|
131
|
+
typeNode: TypeNode;
|
|
132
|
+
};
|
|
148
133
|
/**
|
|
149
134
|
* A class used to generate TypeScript types from a given schema
|
|
150
135
|
* @internal
|
|
151
136
|
* @beta
|
|
152
137
|
*/
|
|
153
|
-
|
|
154
|
-
private generatedTypeName
|
|
155
|
-
private typeNameMap
|
|
156
|
-
private typeNodeNameMap
|
|
157
|
-
private readonly schema
|
|
158
|
-
constructor(schema: SchemaType)
|
|
138
|
+
declare class TypeGenerator {
|
|
139
|
+
private generatedTypeName;
|
|
140
|
+
private typeNameMap;
|
|
141
|
+
private typeNodeNameMap;
|
|
142
|
+
private readonly schema;
|
|
143
|
+
constructor(schema: SchemaType);
|
|
159
144
|
/**
|
|
160
145
|
* Generate TypeScript types for the given schema
|
|
161
146
|
* @returns string
|
|
162
147
|
* @internal
|
|
163
148
|
* @beta
|
|
164
149
|
*/
|
|
165
|
-
generateSchemaTypes(): string
|
|
150
|
+
generateSchemaTypes(): string;
|
|
166
151
|
/**
|
|
167
152
|
* Takes a identifier and a type node and generates a type alias for the type node.
|
|
168
153
|
* @param identifierName - The name of the type to generated
|
|
@@ -171,8 +156,8 @@ export declare class TypeGenerator {
|
|
|
171
156
|
* @internal
|
|
172
157
|
* @beta
|
|
173
158
|
*/
|
|
174
|
-
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
175
|
-
static generateKnownTypes(): string
|
|
159
|
+
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string;
|
|
160
|
+
static generateKnownTypes(): string;
|
|
176
161
|
/**
|
|
177
162
|
* Takes a list of queries from the codebase and generates a type declaration
|
|
178
163
|
* for SanityClient to consume.
|
|
@@ -185,20 +170,19 @@ export declare class TypeGenerator {
|
|
|
185
170
|
* @internal
|
|
186
171
|
* @beta
|
|
187
172
|
*/
|
|
188
|
-
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
173
|
+
generateQueryMap(queries: QueryWithTypeNode[]): string;
|
|
189
174
|
/**
|
|
190
175
|
* Since we are sanitizing identifiers we migt end up with collisions. Ie there might be a type mux.video and muxVideo, both these
|
|
191
176
|
* 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
177
|
* When we reference a type we also keep track of the original name so we can reference the correct type later.
|
|
193
178
|
*/
|
|
194
|
-
private getTypeName
|
|
195
|
-
private getTypeNodeType
|
|
196
|
-
private generateArrayTsType
|
|
197
|
-
private generateObjectProperty
|
|
198
|
-
private generateObjectTsType
|
|
199
|
-
private generateInlineTsType
|
|
200
|
-
private generateUnionTsType
|
|
201
|
-
private generateDocumentType
|
|
179
|
+
private getTypeName;
|
|
180
|
+
private getTypeNodeType;
|
|
181
|
+
private generateArrayTsType;
|
|
182
|
+
private generateObjectProperty;
|
|
183
|
+
private generateObjectTsType;
|
|
184
|
+
private generateInlineTsType;
|
|
185
|
+
private generateUnionTsType;
|
|
186
|
+
private generateDocumentType;
|
|
202
187
|
}
|
|
203
|
-
|
|
204
|
-
export {}
|
|
188
|
+
export { CodegenConfig, TypeGenerator, findQueriesInPath, findQueriesInSource, getResolver, readConfig, readSchema, registerBabel, safeParseQuery };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,37 +1,87 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import * as groq_js1 from "groq-js";
|
|
3
|
+
import { SchemaType, TypeNode } from "groq-js";
|
|
4
|
+
import { TransformOptions } from "@babel/core";
|
|
5
|
+
import "@babel/traverse";
|
|
6
|
+
import "@babel/types";
|
|
7
|
+
declare const configDefintion: z.ZodObject<{
|
|
8
|
+
path: z.ZodDefault<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
9
|
+
schema: z.ZodDefault<z.ZodString>;
|
|
10
|
+
generates: z.ZodDefault<z.ZodString>;
|
|
11
|
+
formatGeneratedCode: z.ZodDefault<z.ZodBoolean>;
|
|
12
|
+
overloadClientMethods: z.ZodDefault<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
path: string | string[];
|
|
15
|
+
schema: string;
|
|
16
|
+
generates: string;
|
|
17
|
+
formatGeneratedCode: boolean;
|
|
18
|
+
overloadClientMethods: boolean;
|
|
19
|
+
}, {
|
|
20
|
+
path?: string | string[] | undefined;
|
|
21
|
+
schema?: string | undefined;
|
|
22
|
+
generates?: string | undefined;
|
|
23
|
+
formatGeneratedCode?: boolean | undefined;
|
|
24
|
+
overloadClientMethods?: boolean | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
type CodegenConfig = z.infer<typeof configDefintion>;
|
|
27
|
+
declare function readConfig(path: string): Promise<CodegenConfig>;
|
|
28
|
+
/**
|
|
29
|
+
* Read a schema from a given path
|
|
30
|
+
* @param path - The path to the schema
|
|
31
|
+
* @returns The schema
|
|
32
|
+
* @internal
|
|
33
|
+
* @beta
|
|
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
|
+
};
|
|
35
85
|
/**
|
|
36
86
|
* findQueriesInPath takes a path or array of paths and returns all GROQ queries in the files.
|
|
37
87
|
* @param path - The path or array of paths to search for queries
|
|
@@ -41,16 +91,15 @@ declare const configDefintion: z.ZodObject<
|
|
|
41
91
|
* @beta
|
|
42
92
|
* @internal
|
|
43
93
|
*/
|
|
44
|
-
|
|
94
|
+
declare function findQueriesInPath({
|
|
45
95
|
path,
|
|
46
96
|
babelOptions,
|
|
47
|
-
resolver
|
|
97
|
+
resolver
|
|
48
98
|
}: {
|
|
49
|
-
path: string | string[]
|
|
50
|
-
babelOptions?: TransformOptions
|
|
51
|
-
resolver?: NodeJS.RequireResolve
|
|
52
|
-
}): AsyncGenerator<ResultQueries | ResultError
|
|
53
|
-
|
|
99
|
+
path: string | string[];
|
|
100
|
+
babelOptions?: TransformOptions;
|
|
101
|
+
resolver?: NodeJS.RequireResolve;
|
|
102
|
+
}): AsyncGenerator<ResultQueries | ResultError>;
|
|
54
103
|
/**
|
|
55
104
|
* findQueriesInSource takes a source string and returns all GROQ queries in it.
|
|
56
105
|
* @param source - The source code to search for queries
|
|
@@ -61,13 +110,7 @@ export declare function findQueriesInPath({
|
|
|
61
110
|
* @beta
|
|
62
111
|
* @internal
|
|
63
112
|
*/
|
|
64
|
-
|
|
65
|
-
source: string,
|
|
66
|
-
filename: string,
|
|
67
|
-
babelConfig?: TransformOptions,
|
|
68
|
-
resolver?: NodeJS.RequireResolve,
|
|
69
|
-
): NamedQueryResult[]
|
|
70
|
-
|
|
113
|
+
declare function findQueriesInSource(source: string, filename: string, babelConfig?: TransformOptions, resolver?: NodeJS.RequireResolve): NamedQueryResult[];
|
|
71
114
|
/**
|
|
72
115
|
* This is a custom implementation of require.resolve that takes into account the paths
|
|
73
116
|
* configuration in tsconfig.json. This is necessary if we want to resolve paths that are
|
|
@@ -75,94 +118,36 @@ export declare function findQueriesInSource(
|
|
|
75
118
|
* Resolving here is best effort and might not work in all cases.
|
|
76
119
|
* @beta
|
|
77
120
|
*/
|
|
78
|
-
|
|
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
|
-
|
|
121
|
+
declare function getResolver(cwd?: string): NodeJS.RequireResolve;
|
|
119
122
|
/**
|
|
120
123
|
* Register Babel with the given options
|
|
121
124
|
*
|
|
122
125
|
* @param babelOptions - The options to use when registering Babel
|
|
123
126
|
* @beta
|
|
124
127
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
128
|
+
declare function registerBabel(babelOptions?: TransformOptions): void;
|
|
129
|
+
type QueryWithTypeNode = {
|
|
130
|
+
query: string;
|
|
131
|
+
typeNode: TypeNode;
|
|
132
|
+
};
|
|
148
133
|
/**
|
|
149
134
|
* A class used to generate TypeScript types from a given schema
|
|
150
135
|
* @internal
|
|
151
136
|
* @beta
|
|
152
137
|
*/
|
|
153
|
-
|
|
154
|
-
private generatedTypeName
|
|
155
|
-
private typeNameMap
|
|
156
|
-
private typeNodeNameMap
|
|
157
|
-
private readonly schema
|
|
158
|
-
constructor(schema: SchemaType)
|
|
138
|
+
declare class TypeGenerator {
|
|
139
|
+
private generatedTypeName;
|
|
140
|
+
private typeNameMap;
|
|
141
|
+
private typeNodeNameMap;
|
|
142
|
+
private readonly schema;
|
|
143
|
+
constructor(schema: SchemaType);
|
|
159
144
|
/**
|
|
160
145
|
* Generate TypeScript types for the given schema
|
|
161
146
|
* @returns string
|
|
162
147
|
* @internal
|
|
163
148
|
* @beta
|
|
164
149
|
*/
|
|
165
|
-
generateSchemaTypes(): string
|
|
150
|
+
generateSchemaTypes(): string;
|
|
166
151
|
/**
|
|
167
152
|
* Takes a identifier and a type node and generates a type alias for the type node.
|
|
168
153
|
* @param identifierName - The name of the type to generated
|
|
@@ -171,8 +156,8 @@ export declare class TypeGenerator {
|
|
|
171
156
|
* @internal
|
|
172
157
|
* @beta
|
|
173
158
|
*/
|
|
174
|
-
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string
|
|
175
|
-
static generateKnownTypes(): string
|
|
159
|
+
generateTypeNodeTypes(identifierName: string, typeNode: TypeNode): string;
|
|
160
|
+
static generateKnownTypes(): string;
|
|
176
161
|
/**
|
|
177
162
|
* Takes a list of queries from the codebase and generates a type declaration
|
|
178
163
|
* for SanityClient to consume.
|
|
@@ -185,20 +170,19 @@ export declare class TypeGenerator {
|
|
|
185
170
|
* @internal
|
|
186
171
|
* @beta
|
|
187
172
|
*/
|
|
188
|
-
generateQueryMap(queries: QueryWithTypeNode[]): string
|
|
173
|
+
generateQueryMap(queries: QueryWithTypeNode[]): string;
|
|
189
174
|
/**
|
|
190
175
|
* Since we are sanitizing identifiers we migt end up with collisions. Ie there might be a type mux.video and muxVideo, both these
|
|
191
176
|
* 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
177
|
* When we reference a type we also keep track of the original name so we can reference the correct type later.
|
|
193
178
|
*/
|
|
194
|
-
private getTypeName
|
|
195
|
-
private getTypeNodeType
|
|
196
|
-
private generateArrayTsType
|
|
197
|
-
private generateObjectProperty
|
|
198
|
-
private generateObjectTsType
|
|
199
|
-
private generateInlineTsType
|
|
200
|
-
private generateUnionTsType
|
|
201
|
-
private generateDocumentType
|
|
179
|
+
private getTypeName;
|
|
180
|
+
private getTypeNodeType;
|
|
181
|
+
private generateArrayTsType;
|
|
182
|
+
private generateObjectProperty;
|
|
183
|
+
private generateObjectTsType;
|
|
184
|
+
private generateInlineTsType;
|
|
185
|
+
private generateUnionTsType;
|
|
186
|
+
private generateDocumentType;
|
|
202
187
|
}
|
|
203
|
-
|
|
204
|
-
export {}
|
|
188
|
+
export { CodegenConfig, TypeGenerator, findQueriesInPath, findQueriesInSource, getResolver, readConfig, readSchema, registerBabel, safeParseQuery };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/codegen",
|
|
3
|
-
"version": "3.93.
|
|
3
|
+
"version": "3.93.1-bump-pkg-utils.10.412e2ab170",
|
|
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.
|
|
64
|
+
"groq": "3.93.1-bump-pkg-utils.10.412e2ab170",
|
|
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": "412e2ab1709ae9a314ad020f81e650158cfde397"
|
|
89
89
|
}
|