@sanity/cli 3.88.1-typegen-experimental.0 → 3.88.1
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/_chunks-cjs/generateAction.js +111 -113
- package/lib/_chunks-cjs/generateAction.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js +3 -3
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/workers/typegenGenerate.d.ts +33 -144
- package/lib/workers/typegenGenerate.js +112 -83
- package/lib/workers/typegenGenerate.js.map +1 -1
- package/package.json +19 -17
- package/src/actions/typegen/generate.telemetry.ts +3 -9
- package/src/actions/typegen/generateAction.ts +152 -159
- package/src/cli.ts +0 -0
- package/src/commands/projects/listProjectsCommand.ts +0 -0
- package/src/commands/projects/projectsGroup.ts +0 -0
- package/src/workers/typegenGenerate.ts +183 -181
- package/lib/_chunks-cjs/workerChannel.js +0 -84
- package/lib/_chunks-cjs/workerChannel.js.map +0 -1
- package/src/util/__tests__/workerChannel.test.ts +0 -222
- package/src/util/workerChannel.ts +0 -312
@@ -1,154 +1,43 @@
|
|
1
|
-
declare interface QueryProgress {
|
2
|
-
queriesCount: number
|
3
|
-
projectionsCount: number
|
4
|
-
filesCount: number
|
5
|
-
}
|
6
|
-
|
7
1
|
export declare interface TypegenGenerateTypesWorkerData {
|
8
2
|
workDir: string
|
9
|
-
|
10
|
-
|
11
|
-
schemaId: string
|
12
|
-
}[]
|
3
|
+
workspaceName?: string
|
4
|
+
schemaPath: string
|
13
5
|
searchPath: string | string[]
|
14
|
-
overloadClientMethods
|
15
|
-
augmentGroqModule: boolean
|
6
|
+
overloadClientMethods?: boolean
|
16
7
|
}
|
17
8
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
schemaCount: number
|
9
|
+
export declare type TypegenGenerateTypesWorkerMessage =
|
10
|
+
| {
|
11
|
+
type: 'error'
|
12
|
+
error: Error
|
13
|
+
fatal: boolean
|
14
|
+
query?: string
|
15
|
+
filename?: string
|
26
16
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
type:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
code: string
|
39
|
-
progress: QueryProgress
|
40
|
-
}
|
41
|
-
| {
|
42
|
-
type: 'error'
|
43
|
-
message: string
|
44
|
-
progress: QueryProgress
|
45
|
-
}
|
46
|
-
>
|
47
|
-
generationComplete: WorkerChannelEvent<{
|
48
|
-
augmentedQueryResultDeclarations: {
|
49
|
-
code: string
|
17
|
+
| {
|
18
|
+
type: 'types'
|
19
|
+
filename: string
|
20
|
+
types: {
|
21
|
+
queryName: string
|
22
|
+
query: string
|
23
|
+
type: string
|
24
|
+
unknownTypeNodesGenerated: number
|
25
|
+
typeNodesGenerated: number
|
26
|
+
emptyUnionTypeNodesGenerated: number
|
27
|
+
}[]
|
50
28
|
}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
29
|
+
| {
|
30
|
+
type: 'schema'
|
31
|
+
filename: string
|
32
|
+
schema: string
|
33
|
+
length: number
|
34
|
+
}
|
35
|
+
| {
|
36
|
+
type: 'typemap'
|
37
|
+
typeMap: string
|
38
|
+
}
|
39
|
+
| {
|
40
|
+
type: 'complete'
|
63
41
|
}
|
64
|
-
}>
|
65
|
-
}>
|
66
|
-
|
67
|
-
/**
|
68
|
-
* Represents the definition of a "worker channel" to report progress from the
|
69
|
-
* worker to the parent. Worker channels can define named events or streams and
|
70
|
-
* the worker will report events and streams while the parent will await them.
|
71
|
-
* This allows the control flow of the parent to follow the control flow of the
|
72
|
-
* worker 1-to-1.
|
73
|
-
*
|
74
|
-
* @example
|
75
|
-
*
|
76
|
-
* ```ts
|
77
|
-
* // Define the channel interface (shared between parent and worker)
|
78
|
-
* type MyWorkerChannel = WorkerChannel<{
|
79
|
-
* compileStart: WorkerChannelEvent<void>
|
80
|
-
* compileProgress: WorkerChannelStream<{ file: string; progress: number }>
|
81
|
-
* compileEnd: WorkerChannelEvent<{ duration: number }>
|
82
|
-
* }>;
|
83
|
-
*
|
84
|
-
* // --- In the worker file (e.g., worker.ts) ---
|
85
|
-
* import { parentPort } from 'node:worker_threads';
|
86
|
-
* import { createReporter } from './workerChannels';
|
87
|
-
*
|
88
|
-
* const report = createReporter<MyWorkerChannel>(parentPort);
|
89
|
-
*
|
90
|
-
* async function runCompilation() {
|
91
|
-
* report.event.compileStart(); // Signal start
|
92
|
-
*
|
93
|
-
* const files = ['a.js', 'b.js', 'c.js'];
|
94
|
-
* for (const file of files) {
|
95
|
-
* // Simulate work and report progress
|
96
|
-
* await new Promise(resolve => setTimeout(resolve, 100));
|
97
|
-
* report.stream.compileProgress.emit({ file, progress: 100 });
|
98
|
-
* }
|
99
|
-
* report.stream.compileProgress.end(); // Signal end of progress stream
|
100
|
-
*
|
101
|
-
* report.event.compileEnd({ duration: 300 }); // Signal end with result
|
102
|
-
* }
|
103
|
-
*
|
104
|
-
* runCompilation();
|
105
|
-
*
|
106
|
-
* // --- In the parent file (e.g., main.ts) ---
|
107
|
-
* import { Worker } from 'node:worker_threads';
|
108
|
-
* import { createReceiver } from './workerChannels';
|
109
|
-
*
|
110
|
-
* const worker = new Worker('./worker.js');
|
111
|
-
* const receiver = createReceiver<MyWorkerChannel>(worker);
|
112
|
-
*
|
113
|
-
* async function monitorCompilation() {
|
114
|
-
* console.log('Waiting for compilation to start...');
|
115
|
-
* await receiver.event.compileStart();
|
116
|
-
* console.log('Compilation started.');
|
117
|
-
*
|
118
|
-
* console.log('Receiving progress:');
|
119
|
-
* for await (const progress of receiver.stream.compileProgress()) {
|
120
|
-
* console.log(` - ${progress.file}: ${progress.progress}%`);
|
121
|
-
* }
|
122
|
-
*
|
123
|
-
* console.log('Waiting for compilation to end...');
|
124
|
-
* const { duration } = await receiver.event.compileEnd();
|
125
|
-
* console.log(`Compilation finished in ${duration}ms.`);
|
126
|
-
*
|
127
|
-
* await receiver.dispose(); // Clean up listeners and terminate worker
|
128
|
-
* }
|
129
|
-
*
|
130
|
-
* monitorCompilation();
|
131
|
-
* ```
|
132
|
-
*
|
133
|
-
* @internal
|
134
|
-
*/
|
135
|
-
declare type WorkerChannel<
|
136
|
-
TWorkerChannel extends Record<
|
137
|
-
string,
|
138
|
-
WorkerChannelEvent<unknown> | WorkerChannelStream<unknown>
|
139
|
-
> = Record<string, WorkerChannelEvent<unknown> | WorkerChannelStream<unknown>>,
|
140
|
-
> = TWorkerChannel
|
141
|
-
|
142
|
-
/** @internal */
|
143
|
-
declare type WorkerChannelEvent<TPayload = void> = {
|
144
|
-
type: 'event'
|
145
|
-
payload: TPayload
|
146
|
-
}
|
147
|
-
|
148
|
-
/** @internal */
|
149
|
-
declare type WorkerChannelStream<TPayload = void> = {
|
150
|
-
type: 'stream'
|
151
|
-
payload: TPayload
|
152
|
-
}
|
153
42
|
|
154
43
|
export {}
|
@@ -1,95 +1,124 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
2
|
+
var node_worker_threads = require("node:worker_threads"), codegen = require("@sanity/codegen"), createDebug = require("debug"), groqJs = require("groq-js");
|
3
|
+
function _interopDefaultCompat(e) {
|
4
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
5
|
+
}
|
6
|
+
var createDebug__default = /* @__PURE__ */ _interopDefaultCompat(createDebug);
|
7
|
+
const $info = createDebug__default.default("sanity:codegen:generate:info");
|
8
|
+
createDebug__default.default("sanity:codegen:generate:warn");
|
4
9
|
if (node_worker_threads.isMainThread || !node_worker_threads.parentPort)
|
5
10
|
throw new Error("This module must be run as a worker thread");
|
6
|
-
const
|
11
|
+
const opts = node_worker_threads.workerData;
|
12
|
+
codegen.registerBabel();
|
7
13
|
async function main() {
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
schemas.push({ schema, schemaId, filename: schemaPath });
|
17
|
-
} catch (err) {
|
18
|
-
if (err.code === "ENOENT") {
|
19
|
-
const hint = schemaPath === DEFAULT_SCHEMA_PATH ? ' - did you run "sanity schema extract"?' : "";
|
20
|
-
throw new Error(`Schema file not found for schema "${schemaId}": ${schemaPath}${hint}`);
|
21
|
-
} else
|
22
|
-
throw err;
|
23
|
-
}
|
24
|
-
report.event.loadedSchemas();
|
25
|
-
const generator = new codegen.TypeGenerator({
|
26
|
-
schemas,
|
27
|
-
queriesByFile: codegen.findQueriesInPath({ path: opts.searchPath, resolver: codegen.getResolver() }),
|
28
|
-
augmentGroqModule: opts.augmentGroqModule,
|
29
|
-
overloadClientMethods: opts.overloadClientMethods
|
14
|
+
const schema = await codegen.readSchema(opts.schemaPath), typeGenerator = new codegen.TypeGenerator(schema), schemaTypes = [typeGenerator.generateSchemaTypes(), codegen.TypeGenerator.generateKnownTypes()].join(`
|
15
|
+
`).trim(), resolver = codegen.getResolver();
|
16
|
+
node_worker_threads.parentPort?.postMessage({
|
17
|
+
type: "schema",
|
18
|
+
schema: `${schemaTypes.trim()}
|
19
|
+
`,
|
20
|
+
filename: "schema.json",
|
21
|
+
length: schema.length
|
30
22
|
});
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
23
|
+
const queries = codegen.findQueriesInPath({
|
24
|
+
path: opts.searchPath,
|
25
|
+
resolver
|
26
|
+
}), allQueries = [];
|
27
|
+
for await (const result of queries) {
|
28
|
+
if (result.type === "error") {
|
29
|
+
node_worker_threads.parentPort?.postMessage({
|
30
|
+
type: "error",
|
31
|
+
error: result.error,
|
32
|
+
fatal: !1,
|
33
|
+
filename: result.filename
|
34
|
+
});
|
35
|
+
continue;
|
43
36
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
continue;
|
37
|
+
$info(`Processing ${result.queries.length} queries in "${result.filename}"...`);
|
38
|
+
const fileQueryTypes = [];
|
39
|
+
for (const { name: queryName, result: query } of result.queries)
|
40
|
+
try {
|
41
|
+
const ast = codegen.safeParseQuery(query), queryTypes = groqJs.typeEvaluate(ast, schema), typeName = `${queryName}Result`, type = typeGenerator.generateTypeNodeTypes(typeName, queryTypes), queryTypeStats = walkAndCountQueryTypeNodeStats(queryTypes);
|
42
|
+
fileQueryTypes.push({
|
43
|
+
queryName,
|
44
|
+
query,
|
45
|
+
typeName,
|
46
|
+
typeNode: queryTypes,
|
47
|
+
type: `${type.trim()}
|
48
|
+
`,
|
49
|
+
unknownTypeNodesGenerated: queryTypeStats.unknownTypes,
|
50
|
+
typeNodesGenerated: queryTypeStats.allTypes,
|
51
|
+
emptyUnionTypeNodesGenerated: queryTypeStats.emptyUnions
|
52
|
+
});
|
53
|
+
} catch (err) {
|
54
|
+
node_worker_threads.parentPort?.postMessage({
|
55
|
+
type: "error",
|
56
|
+
error: new Error(
|
57
|
+
`Error generating types for query "${queryName}" in "${result.filename}": ${err.message}`,
|
58
|
+
{ cause: err }
|
59
|
+
),
|
60
|
+
fatal: !1,
|
61
|
+
query
|
62
|
+
});
|
71
63
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
64
|
+
fileQueryTypes.length > 0 && ($info(`Generated types for ${fileQueryTypes.length} queries in "${result.filename}"
|
65
|
+
`), node_worker_threads.parentPort?.postMessage({
|
66
|
+
type: "types",
|
67
|
+
types: fileQueryTypes,
|
68
|
+
filename: result.filename
|
69
|
+
})), fileQueryTypes.length > 0 && allQueries.push(...fileQueryTypes);
|
75
70
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
filesWithErrors: errorFilenames.size,
|
87
|
-
queryFilesCount: queryFilenames.size,
|
88
|
-
projectionFilesCount: projectionFilenames.size,
|
89
|
-
unknownTypeNodesRatio: typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0
|
90
|
-
}
|
71
|
+
if (opts.overloadClientMethods && allQueries.length > 0) {
|
72
|
+
const typeMap = `${typeGenerator.generateQueryMap(allQueries).trim()}
|
73
|
+
`;
|
74
|
+
node_worker_threads.parentPort?.postMessage({
|
75
|
+
type: "typemap",
|
76
|
+
typeMap
|
77
|
+
});
|
78
|
+
}
|
79
|
+
node_worker_threads.parentPort?.postMessage({
|
80
|
+
type: "complete"
|
91
81
|
});
|
92
82
|
}
|
93
|
-
|
83
|
+
function walkAndCountQueryTypeNodeStats(typeNode) {
|
84
|
+
switch (typeNode.type) {
|
85
|
+
case "unknown":
|
86
|
+
return { allTypes: 1, unknownTypes: 1, emptyUnions: 0 };
|
87
|
+
case "array": {
|
88
|
+
const acc = walkAndCountQueryTypeNodeStats(typeNode.of);
|
89
|
+
return acc.allTypes += 1, acc;
|
90
|
+
}
|
91
|
+
case "object": {
|
92
|
+
if (typeNode.rest && typeNode.rest.type === "unknown")
|
93
|
+
return { allTypes: 2, unknownTypes: 1, emptyUnions: 0 };
|
94
|
+
const restStats = typeNode.rest ? walkAndCountQueryTypeNodeStats(typeNode.rest) : { allTypes: 1, unknownTypes: 0, emptyUnions: 0 };
|
95
|
+
return Object.values(typeNode.attributes).reduce((acc, attribute) => {
|
96
|
+
const { allTypes, unknownTypes, emptyUnions } = walkAndCountQueryTypeNodeStats(
|
97
|
+
attribute.value
|
98
|
+
);
|
99
|
+
return {
|
100
|
+
allTypes: acc.allTypes + allTypes,
|
101
|
+
unknownTypes: acc.unknownTypes + unknownTypes,
|
102
|
+
emptyUnions: acc.emptyUnions + emptyUnions
|
103
|
+
};
|
104
|
+
}, restStats);
|
105
|
+
}
|
106
|
+
case "union":
|
107
|
+
return typeNode.of.length === 0 ? { allTypes: 1, unknownTypes: 0, emptyUnions: 1 } : typeNode.of.reduce(
|
108
|
+
(acc, type) => {
|
109
|
+
const { allTypes, unknownTypes, emptyUnions } = walkAndCountQueryTypeNodeStats(type);
|
110
|
+
return {
|
111
|
+
allTypes: acc.allTypes + allTypes,
|
112
|
+
unknownTypes: acc.unknownTypes + unknownTypes,
|
113
|
+
emptyUnions: acc.emptyUnions + emptyUnions
|
114
|
+
};
|
115
|
+
},
|
116
|
+
{ allTypes: 1, unknownTypes: 0, emptyUnions: 0 }
|
117
|
+
// count the union type itself
|
118
|
+
);
|
119
|
+
default:
|
120
|
+
return { allTypes: 1, unknownTypes: 0, emptyUnions: 0 };
|
121
|
+
}
|
122
|
+
}
|
94
123
|
main();
|
95
124
|
//# sourceMappingURL=typegenGenerate.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"typegenGenerate.js","sources":["../../src/workers/typegenGenerate.ts"],"sourcesContent":["
|
1
|
+
{"version":3,"file":"typegenGenerate.js","sources":["../../src/workers/typegenGenerate.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'\n\nimport {\n findQueriesInPath,\n getResolver,\n readSchema,\n registerBabel,\n safeParseQuery,\n TypeGenerator,\n} from '@sanity/codegen'\nimport createDebug from 'debug'\nimport {typeEvaluate, type TypeNode} from 'groq-js'\n\nconst $info = createDebug('sanity:codegen:generate:info')\nconst $warn = createDebug('sanity:codegen:generate:warn')\n\nexport interface TypegenGenerateTypesWorkerData {\n workDir: string\n workspaceName?: string\n schemaPath: string\n searchPath: string | string[]\n overloadClientMethods?: boolean\n}\n\nexport type TypegenGenerateTypesWorkerMessage =\n | {\n type: 'error'\n error: Error\n fatal: boolean\n query?: string\n filename?: string\n }\n | {\n type: 'types'\n filename: string\n types: {\n queryName: string\n query: string\n type: string\n unknownTypeNodesGenerated: number\n typeNodesGenerated: number\n emptyUnionTypeNodesGenerated: number\n }[]\n }\n | {\n type: 'schema'\n filename: string\n schema: string\n length: number\n }\n | {\n type: 'typemap'\n typeMap: string\n }\n | {\n type: 'complete'\n }\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nconst opts = _workerData as TypegenGenerateTypesWorkerData\n\nregisterBabel()\n\nasync function main() {\n const schema = await readSchema(opts.schemaPath)\n\n const typeGenerator = new TypeGenerator(schema)\n const schemaTypes = [typeGenerator.generateSchemaTypes(), TypeGenerator.generateKnownTypes()]\n .join('\\n')\n .trim()\n const resolver = getResolver()\n\n parentPort?.postMessage({\n type: 'schema',\n schema: `${schemaTypes.trim()}\\n`,\n filename: 'schema.json',\n length: schema.length,\n } satisfies TypegenGenerateTypesWorkerMessage)\n\n const queries = findQueriesInPath({\n path: opts.searchPath,\n resolver,\n })\n\n const allQueries = []\n\n for await (const result of queries) {\n if (result.type === 'error') {\n parentPort?.postMessage({\n type: 'error',\n error: result.error,\n fatal: false,\n filename: result.filename,\n } satisfies TypegenGenerateTypesWorkerMessage)\n continue\n }\n $info(`Processing ${result.queries.length} queries in \"${result.filename}\"...`)\n\n const fileQueryTypes: {\n queryName: string\n query: string\n type: string\n typeName: string\n typeNode: TypeNode\n unknownTypeNodesGenerated: number\n typeNodesGenerated: number\n emptyUnionTypeNodesGenerated: number\n }[] = []\n for (const {name: queryName, result: query} of result.queries) {\n try {\n const ast = safeParseQuery(query)\n const queryTypes = typeEvaluate(ast, schema)\n\n const typeName = `${queryName}Result`\n const type = typeGenerator.generateTypeNodeTypes(typeName, queryTypes)\n\n const queryTypeStats = walkAndCountQueryTypeNodeStats(queryTypes)\n fileQueryTypes.push({\n queryName,\n query,\n typeName,\n typeNode: queryTypes,\n type: `${type.trim()}\\n`,\n unknownTypeNodesGenerated: queryTypeStats.unknownTypes,\n typeNodesGenerated: queryTypeStats.allTypes,\n emptyUnionTypeNodesGenerated: queryTypeStats.emptyUnions,\n })\n } catch (err) {\n parentPort?.postMessage({\n type: 'error',\n error: new Error(\n `Error generating types for query \"${queryName}\" in \"${result.filename}\": ${err.message}`,\n {cause: err},\n ),\n fatal: false,\n query,\n } satisfies TypegenGenerateTypesWorkerMessage)\n }\n }\n\n if (fileQueryTypes.length > 0) {\n $info(`Generated types for ${fileQueryTypes.length} queries in \"${result.filename}\"\\n`)\n parentPort?.postMessage({\n type: 'types',\n types: fileQueryTypes,\n filename: result.filename,\n } satisfies TypegenGenerateTypesWorkerMessage)\n }\n\n if (fileQueryTypes.length > 0) {\n allQueries.push(...fileQueryTypes)\n }\n }\n\n if (opts.overloadClientMethods && allQueries.length > 0) {\n const typeMap = `${typeGenerator.generateQueryMap(allQueries).trim()}\\n`\n parentPort?.postMessage({\n type: 'typemap',\n typeMap,\n } satisfies TypegenGenerateTypesWorkerMessage)\n }\n\n parentPort?.postMessage({\n type: 'complete',\n } satisfies TypegenGenerateTypesWorkerMessage)\n}\n\nfunction walkAndCountQueryTypeNodeStats(typeNode: TypeNode): {\n allTypes: number\n unknownTypes: number\n emptyUnions: number\n} {\n switch (typeNode.type) {\n case 'unknown': {\n return {allTypes: 1, unknownTypes: 1, emptyUnions: 0}\n }\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, unknownTypes: 1, emptyUnions: 0} // count the object type itself as well\n }\n\n const restStats = typeNode.rest\n ? walkAndCountQueryTypeNodeStats(typeNode.rest)\n : {allTypes: 1, unknownTypes: 0, emptyUnions: 0} // count the object type itself\n\n return Object.values(typeNode.attributes).reduce((acc, attribute) => {\n const {allTypes, unknownTypes, emptyUnions} = walkAndCountQueryTypeNodeStats(\n attribute.value,\n )\n return {\n allTypes: acc.allTypes + allTypes,\n unknownTypes: acc.unknownTypes + unknownTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n }\n }, restStats)\n }\n case 'union': {\n if (typeNode.of.length === 0) {\n return {allTypes: 1, unknownTypes: 0, emptyUnions: 1}\n }\n\n return typeNode.of.reduce(\n (acc, type) => {\n const {allTypes, unknownTypes, emptyUnions} = walkAndCountQueryTypeNodeStats(type)\n return {\n allTypes: acc.allTypes + allTypes,\n unknownTypes: acc.unknownTypes + unknownTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n }\n },\n {allTypes: 1, unknownTypes: 0, emptyUnions: 0}, // count the union type itself\n )\n }\n default: {\n return {allTypes: 1, unknownTypes: 0, emptyUnions: 0}\n }\n }\n}\n\nmain()\n"],"names":["createDebug","isMainThread","parentPort","_workerData","registerBabel","readSchema","TypeGenerator","getResolver","findQueriesInPath","safeParseQuery","typeEvaluate"],"mappings":";;;;;;AAaA,MAAM,QAAQA,qBAAAA,QAAY,8BAA8B;AAC1CA,6BAAY,8BAA8B;AA4CxD,IAAIC,oBAAAA,gBAAgB,CAACC,oBAAA;AACb,QAAA,IAAI,MAAM,4CAA4C;AAG9D,MAAM,OAAOC,oBAAA;AAEbC,QAAAA,cAAc;AAEd,eAAe,OAAO;AACd,QAAA,SAAS,MAAMC,mBAAW,KAAK,UAAU,GAEzC,gBAAgB,IAAIC,sBAAc,MAAM,GACxC,cAAc,CAAC,cAAc,oBAAoB,GAAGA,QAAAA,cAAc,mBAAmB,CAAC,EACzF,KAAK;AAAA,CAAI,EACT,KAAA,GACG,WAAWC,oBAAY;AAE7BL,sBAAAA,YAAY,YAAY;AAAA,IACtB,MAAM;AAAA,IACN,QAAQ,GAAG,YAAY,KAAM,CAAA;AAAA;AAAA,IAC7B,UAAU;AAAA,IACV,QAAQ,OAAO;AAAA,EAAA,CAC4B;AAE7C,QAAM,UAAUM,QAAAA,kBAAkB;AAAA,IAChC,MAAM,KAAK;AAAA,IACX;AAAA,EAAA,CACD,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E,iBAAA;AAAA,YACL,UAAU,IAAI,WAAW;AAAA,YACzB,cAAc,IAAI,eAAe;AAAA,YACjC,aAAa,IAAI,cAAc;AAAA,UACjC;AAAA,QACF;AAAA,QACA,EAAC,UAAU,GAAG,cAAc,GAAG,aAAa,EAAC;AAAA;AAAA,MAC/C;AAAA,IAEF;AACE,aAAO,EAAC,UAAU,GAAG,cAAc,GAAG,aAAa,EAAC;AAAA,EAAA;AAG1D;AAEA,KAAK;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.88.1
|
3
|
+
"version": "3.88.1",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -46,9 +46,20 @@
|
|
46
46
|
"src",
|
47
47
|
"templates"
|
48
48
|
],
|
49
|
+
"scripts": {
|
50
|
+
"build": "pkg-utils build --strict --check --clean",
|
51
|
+
"check:types": "tsc --project tsconfig.lib.json",
|
52
|
+
"clean": "rimraf lib",
|
53
|
+
"lint": "eslint --cache .",
|
54
|
+
"prepublishOnly": "turbo run build",
|
55
|
+
"test": "vitest",
|
56
|
+
"ts": "node -r esbuild-register",
|
57
|
+
"watch": "pkg-utils watch"
|
58
|
+
},
|
49
59
|
"dependencies": {
|
50
60
|
"@babel/traverse": "^7.23.5",
|
51
61
|
"@sanity/client": "^7.1.0",
|
62
|
+
"@sanity/codegen": "3.88.1",
|
52
63
|
"@sanity/runtime-cli": "^6.1.1",
|
53
64
|
"@sanity/telemetry": "^0.8.0",
|
54
65
|
"@sanity/template-validator": "^2.4.3",
|
@@ -63,14 +74,16 @@
|
|
63
74
|
"pkg-dir": "^5.0.0",
|
64
75
|
"prettier": "^3.3.0",
|
65
76
|
"semver": "^7.3.5",
|
66
|
-
"validate-npm-package-name": "^3.0.0"
|
67
|
-
"@sanity/codegen": "3.88.1-typegen-experimental.0"
|
77
|
+
"validate-npm-package-name": "^3.0.0"
|
68
78
|
},
|
69
79
|
"devDependencies": {
|
80
|
+
"@repo/package.config": "3.88.1",
|
81
|
+
"@repo/test-config": "3.88.1",
|
70
82
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
71
83
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
72
84
|
"@sanity/eslint-config-studio": "^4.0.0",
|
73
85
|
"@sanity/generate-help-url": "^3.0.0",
|
86
|
+
"@sanity/types": "3.88.1",
|
74
87
|
"@types/babel__traverse": "^7.20.5",
|
75
88
|
"@types/configstore": "^5.0.1",
|
76
89
|
"@types/cpx": "^1.5.2",
|
@@ -117,21 +130,10 @@
|
|
117
130
|
"vite": "^6.2.4",
|
118
131
|
"vitest": "^3.1.1",
|
119
132
|
"which": "^2.0.2",
|
120
|
-
"xdg-basedir": "^4.0.0"
|
121
|
-
"@repo/package.config": "3.88.1",
|
122
|
-
"@repo/test-config": "3.88.1",
|
123
|
-
"@sanity/types": "3.88.1"
|
133
|
+
"xdg-basedir": "^4.0.0"
|
124
134
|
},
|
125
135
|
"engines": {
|
126
136
|
"node": ">=18"
|
127
137
|
},
|
128
|
-
"
|
129
|
-
|
130
|
-
"check:types": "tsc --project tsconfig.lib.json",
|
131
|
-
"clean": "rimraf lib",
|
132
|
-
"lint": "eslint --cache .",
|
133
|
-
"test": "vitest",
|
134
|
-
"ts": "node -r esbuild-register",
|
135
|
-
"watch": "pkg-utils watch"
|
136
|
-
}
|
137
|
-
}
|
138
|
+
"gitHead": "26a4552965274b9d35f92b9d1191eb029cb913e8"
|
139
|
+
}
|
@@ -1,26 +1,20 @@
|
|
1
1
|
import {defineTrace} from '@sanity/telemetry'
|
2
2
|
|
3
|
-
interface
|
3
|
+
interface TypesGeneratedTraceAttrubutes {
|
4
4
|
outputSize: number
|
5
5
|
queriesCount: number
|
6
|
-
projectionsCount: number
|
7
6
|
schemaTypesCount: number
|
8
|
-
schemaCount: number
|
9
|
-
totalScannedFilesCount: number
|
10
7
|
queryFilesCount: number
|
11
|
-
projectionFilesCount: number
|
12
8
|
filesWithErrors: number
|
13
|
-
errorCount: number
|
14
9
|
typeNodesGenerated: number
|
15
10
|
unknownTypeNodesGenerated: number
|
16
11
|
unknownTypeNodesRatio: number
|
17
12
|
emptyUnionTypeNodesGenerated: number
|
18
13
|
configOverloadClientMethods: boolean
|
19
|
-
configAugmentGroqModule: boolean
|
20
14
|
}
|
21
15
|
|
22
|
-
export const TypesGeneratedTrace = defineTrace<
|
16
|
+
export const TypesGeneratedTrace = defineTrace<TypesGeneratedTraceAttrubutes>({
|
23
17
|
name: 'Types Generated',
|
24
|
-
version:
|
18
|
+
version: 0,
|
25
19
|
description: 'Trace emitted when generating TypeScript types for queries',
|
26
20
|
})
|