@sanity/cli 3.87.1 → 3.88.1-typegen-experimental.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/lib/_chunks-cjs/cli.js +58780 -56791
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/generateAction.js +113 -111
- 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/_chunks-cjs/workerChannel.js +84 -0
- package/lib/_chunks-cjs/workerChannel.js.map +1 -0
- package/lib/workers/typegenGenerate.d.ts +144 -33
- package/lib/workers/typegenGenerate.js +83 -112
- package/lib/workers/typegenGenerate.js.map +1 -1
- package/package.json +20 -22
- package/src/actions/init-project/templates/appQuickstart.ts +2 -2
- package/src/actions/init-project/templates/appSanityUi.ts +2 -2
- package/src/actions/typegen/generate.telemetry.ts +9 -3
- package/src/actions/typegen/generateAction.ts +159 -152
- package/src/cli.ts +0 -0
- package/src/commands/blueprints/addBlueprintsCommand.ts +52 -56
- package/src/commands/blueprints/blueprintsGroup.ts +0 -1
- package/src/commands/blueprints/configBlueprintsCommand.ts +50 -74
- package/src/commands/blueprints/deployBlueprintsCommand.ts +41 -133
- package/src/commands/blueprints/destroyBlueprintsCommand.ts +76 -0
- package/src/commands/blueprints/infoBlueprintsCommand.ts +29 -51
- package/src/commands/blueprints/initBlueprintsCommand.ts +55 -73
- package/src/commands/blueprints/logsBlueprintsCommand.ts +43 -81
- package/src/commands/blueprints/planBlueprintsCommand.ts +26 -36
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +43 -51
- package/src/commands/functions/devFunctionsCommand.ts +1 -2
- package/src/commands/functions/envFunctionsCommand.ts +55 -46
- package/src/commands/functions/functionsGroup.ts +1 -2
- package/src/commands/functions/logsFunctionsCommand.ts +101 -58
- package/src/commands/functions/testFunctionsCommand.ts +56 -36
- package/src/commands/index.ts +6 -4
- package/src/commands/projects/listProjectsCommand.ts +0 -0
- package/src/commands/projects/projectsGroup.ts +0 -0
- package/src/util/__tests__/workerChannel.test.ts +222 -0
- package/src/util/workerChannel.ts +312 -0
- package/src/workers/typegenGenerate.ts +181 -183
- package/templates/app-sanity-ui/src/ExampleComponent.tsx +1 -1
@@ -1,43 +1,154 @@
|
|
1
|
+
declare interface QueryProgress {
|
2
|
+
queriesCount: number
|
3
|
+
projectionsCount: number
|
4
|
+
filesCount: number
|
5
|
+
}
|
6
|
+
|
1
7
|
export declare interface TypegenGenerateTypesWorkerData {
|
2
8
|
workDir: string
|
3
|
-
|
4
|
-
|
9
|
+
schemas: {
|
10
|
+
schemaPath: string
|
11
|
+
schemaId: string
|
12
|
+
}[]
|
5
13
|
searchPath: string | string[]
|
6
|
-
overloadClientMethods
|
14
|
+
overloadClientMethods: boolean
|
15
|
+
augmentGroqModule: boolean
|
7
16
|
}
|
8
17
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
}[]
|
18
|
+
/** @internal */
|
19
|
+
export declare type TypegenWorkerChannel = WorkerChannel<{
|
20
|
+
loadedSchemas: WorkerChannelEvent
|
21
|
+
generatedSchemaDeclarations: WorkerChannelEvent<{
|
22
|
+
code: string
|
23
|
+
schemaStats: {
|
24
|
+
schemaTypesCount: number
|
25
|
+
schemaCount: number
|
28
26
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
}>
|
28
|
+
fileCount: WorkerChannelEvent<{
|
29
|
+
fileCount: number
|
30
|
+
}>
|
31
|
+
generatedQueryResultDeclaration: WorkerChannelStream<
|
32
|
+
| {
|
33
|
+
type: 'progress'
|
34
|
+
progress: QueryProgress
|
35
|
+
}
|
36
|
+
| {
|
37
|
+
type: 'declaration'
|
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
|
34
50
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
51
|
+
queryStats: {
|
52
|
+
queriesCount: number
|
53
|
+
projectionsCount: number
|
54
|
+
totalScannedFilesCount: number
|
55
|
+
queryFilesCount: number
|
56
|
+
projectionFilesCount: number
|
57
|
+
filesWithErrors: number
|
58
|
+
errorCount: number
|
59
|
+
typeNodesGenerated: number
|
60
|
+
unknownTypeNodesGenerated: number
|
61
|
+
unknownTypeNodesRatio: number
|
62
|
+
emptyUnionTypeNodesGenerated: number
|
41
63
|
}
|
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
|
+
}
|
42
153
|
|
43
154
|
export {}
|
@@ -1,124 +1,95 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
3
|
-
|
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");
|
2
|
+
var fs = require("node:fs/promises"), node_worker_threads = require("node:worker_threads"), codegen = require("@sanity/codegen"), workerChannel = require("../_chunks-cjs/workerChannel.js");
|
3
|
+
const DEFAULT_SCHEMA_PATH = codegen.DEFAULT_CONFIG.schemas[0].schemaPath;
|
9
4
|
if (node_worker_threads.isMainThread || !node_worker_threads.parentPort)
|
10
5
|
throw new Error("This module must be run as a worker thread");
|
11
|
-
const opts = node_worker_threads.workerData;
|
12
|
-
codegen.registerBabel();
|
6
|
+
const report = workerChannel.createReporter(node_worker_threads.parentPort), opts = node_worker_threads.workerData;
|
13
7
|
async function main() {
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
node_worker_threads.parentPort?.postMessage({
|
30
|
-
type: "error",
|
31
|
-
error: result.error,
|
32
|
-
fatal: !1,
|
33
|
-
filename: result.filename
|
34
|
-
});
|
35
|
-
continue;
|
8
|
+
const schemas = [];
|
9
|
+
for (const { schemaId, schemaPath } of opts.schemas)
|
10
|
+
try {
|
11
|
+
if (!(await fs.stat(schemaPath)).isFile())
|
12
|
+
throw new Error(
|
13
|
+
`Failed to load schema "${schemaId}". Schema path is not a file: ${schemaPath}`
|
14
|
+
);
|
15
|
+
const schema = await codegen.readSchema(schemaPath);
|
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;
|
36
23
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
});
|
63
|
-
}
|
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);
|
70
|
-
}
|
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"
|
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
|
81
30
|
});
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
31
|
+
report.event.generatedSchemaDeclarations({
|
32
|
+
code: [
|
33
|
+
generator.getKnownTypes().code,
|
34
|
+
...generator.getSchemaTypeDeclarations().map((i) => i.code),
|
35
|
+
generator.getAllSanitySchemaTypesDeclaration().code,
|
36
|
+
...generator.getSchemaDeclarations().map((i) => i.code),
|
37
|
+
generator.getAugmentedSchemasDeclarations().code
|
38
|
+
].join(`
|
39
|
+
`),
|
40
|
+
schemaStats: {
|
41
|
+
schemaTypesCount: generator.getSchemaTypeDeclarations().length,
|
42
|
+
schemaCount: schemas.length
|
90
43
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
44
|
+
});
|
45
|
+
const allFilenames = /* @__PURE__ */ new Set(), errorFilenames = /* @__PURE__ */ new Set(), queryFilenames = /* @__PURE__ */ new Set(), projectionFilenames = /* @__PURE__ */ new Set();
|
46
|
+
let errorCount = 0, queriesCount = 0, projectionsCount = 0, typeNodesGenerated = 0, unknownTypeNodesGenerated = 0, emptyUnionTypeNodesGenerated = 0;
|
47
|
+
const { fileCount } = await generator.getQueryFileCount();
|
48
|
+
report.event.fileCount({ fileCount });
|
49
|
+
for await (const { filename, ...result } of generator.getQueryResultDeclarations()) {
|
50
|
+
allFilenames.add(filename);
|
51
|
+
const progress = {
|
52
|
+
queriesCount,
|
53
|
+
projectionsCount,
|
54
|
+
filesCount: allFilenames.size
|
55
|
+
};
|
56
|
+
switch (result.type) {
|
57
|
+
case "error": {
|
58
|
+
errorCount += 1, errorFilenames.add(filename);
|
59
|
+
const errorMessage = typeof result.error == "object" && result.error !== null && "message" in result.error ? String(result.error.message) : "Unknown Error", message = `Error generating types in "${filename}": ${errorMessage}`;
|
60
|
+
report.stream.generatedQueryResultDeclaration.emit({ type: "error", message, progress });
|
61
|
+
continue;
|
62
|
+
}
|
63
|
+
case "queries": {
|
64
|
+
if (!result.queryResultDeclarations.length) {
|
65
|
+
report.stream.generatedQueryResultDeclaration.emit({ type: "progress", progress });
|
66
|
+
continue;
|
67
|
+
}
|
68
|
+
for (const { code, type, stats } of result.queryResultDeclarations)
|
69
|
+
queriesCount += type === "query" ? 1 : 0, projectionsCount += type === "projection" ? 1 : 0, typeNodesGenerated += stats.allTypes, unknownTypeNodesGenerated += stats.unknownTypes, emptyUnionTypeNodesGenerated += stats.emptyUnions, type === "projection" ? projectionFilenames.add(filename) : queryFilenames.add(filename), report.stream.generatedQueryResultDeclaration.emit({ type: "declaration", code, progress });
|
70
|
+
continue;
|
71
|
+
}
|
72
|
+
default:
|
73
|
+
continue;
|
105
74
|
}
|
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
75
|
}
|
76
|
+
report.stream.generatedQueryResultDeclaration.end(), report.event.generationComplete({
|
77
|
+
augmentedQueryResultDeclarations: await generator.getAugmentedQueryResultsDeclarations(),
|
78
|
+
queryStats: {
|
79
|
+
errorCount,
|
80
|
+
queriesCount,
|
81
|
+
projectionsCount,
|
82
|
+
typeNodesGenerated,
|
83
|
+
unknownTypeNodesGenerated,
|
84
|
+
emptyUnionTypeNodesGenerated,
|
85
|
+
totalScannedFilesCount: allFilenames.size,
|
86
|
+
filesWithErrors: errorFilenames.size,
|
87
|
+
queryFilesCount: queryFilenames.size,
|
88
|
+
projectionFilesCount: projectionFilenames.size,
|
89
|
+
unknownTypeNodesRatio: typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0
|
90
|
+
}
|
91
|
+
});
|
122
92
|
}
|
93
|
+
codegen.registerBabel();
|
123
94
|
main();
|
124
95
|
//# 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":["/* eslint-disable max-statements */\nimport {stat} from 'node:fs/promises'\nimport {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'\n\nimport {\n DEFAULT_CONFIG,\n findQueriesInPath,\n getResolver,\n readSchema,\n registerBabel,\n TypeGenerator,\n} from '@sanity/codegen'\nimport {type SchemaType} from 'groq-js'\n\nimport {\n createReporter,\n type WorkerChannel,\n type WorkerChannelEvent,\n type WorkerChannelStream,\n} from '../util/workerChannel'\n\nconst DEFAULT_SCHEMA_PATH = DEFAULT_CONFIG.schemas[0].schemaPath\n\nexport interface TypegenGenerateTypesWorkerData {\n workDir: string\n schemas: {schemaPath: string; schemaId: string}[]\n searchPath: string | string[]\n overloadClientMethods: boolean\n augmentGroqModule: boolean\n}\n\ninterface QueryProgress {\n queriesCount: number\n projectionsCount: number\n filesCount: number\n}\n\n/** @internal */\nexport type TypegenWorkerChannel = WorkerChannel<{\n loadedSchemas: WorkerChannelEvent\n generatedSchemaDeclarations: WorkerChannelEvent<{\n code: string\n schemaStats: {\n schemaTypesCount: number\n schemaCount: number\n }\n }>\n fileCount: WorkerChannelEvent<{fileCount: number}>\n generatedQueryResultDeclaration: WorkerChannelStream<\n | {\n type: 'progress'\n progress: QueryProgress\n }\n | {\n type: 'declaration'\n code: string\n progress: QueryProgress\n }\n | {\n type: 'error'\n message: string\n progress: QueryProgress\n }\n >\n generationComplete: WorkerChannelEvent<{\n augmentedQueryResultDeclarations: {code: string}\n queryStats: {\n queriesCount: number\n projectionsCount: number\n totalScannedFilesCount: number\n queryFilesCount: number\n projectionFilesCount: number\n filesWithErrors: number\n errorCount: number\n typeNodesGenerated: number\n unknownTypeNodesGenerated: number\n unknownTypeNodesRatio: number\n emptyUnionTypeNodesGenerated: number\n }\n }>\n}>\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nconst report = createReporter<TypegenWorkerChannel>(parentPort)\nconst opts = _workerData as TypegenGenerateTypesWorkerData\n\nasync function main() {\n const schemas: {schema: SchemaType; schemaId: string; filename: string}[] = []\n\n for (const {schemaId, schemaPath} of opts.schemas) {\n try {\n const schemaStats = await stat(schemaPath)\n if (!schemaStats.isFile()) {\n throw new Error(\n `Failed to load schema \"${schemaId}\". Schema path is not a file: ${schemaPath}`,\n )\n }\n\n const schema = await readSchema(schemaPath)\n schemas.push({schema, schemaId, filename: schemaPath})\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If the user has not provided a specific schema path (eg we're using the default), give some help\n const hint =\n schemaPath === DEFAULT_SCHEMA_PATH ? ` - did you run \"sanity schema extract\"?` : ''\n throw new Error(`Schema file not found for schema \"${schemaId}\": ${schemaPath}${hint}`)\n } else {\n throw err\n }\n }\n }\n report.event.loadedSchemas()\n\n const generator = new TypeGenerator({\n schemas,\n queriesByFile: findQueriesInPath({path: opts.searchPath, resolver: getResolver()}),\n augmentGroqModule: opts.augmentGroqModule,\n overloadClientMethods: opts.overloadClientMethods,\n })\n\n report.event.generatedSchemaDeclarations({\n code: [\n generator.getKnownTypes().code,\n ...generator.getSchemaTypeDeclarations().map((i) => i.code),\n generator.getAllSanitySchemaTypesDeclaration().code,\n ...generator.getSchemaDeclarations().map((i) => i.code),\n generator.getAugmentedSchemasDeclarations().code,\n ].join('\\n'),\n schemaStats: {\n schemaTypesCount: generator.getSchemaTypeDeclarations().length,\n schemaCount: schemas.length,\n },\n })\n\n const allFilenames = new Set<string>()\n const errorFilenames = new Set<string>()\n const queryFilenames = new Set<string>()\n const projectionFilenames = new Set<string>()\n\n let errorCount = 0\n let queriesCount = 0\n let projectionsCount = 0\n let typeNodesGenerated = 0\n let unknownTypeNodesGenerated = 0\n let emptyUnionTypeNodesGenerated = 0\n\n const {fileCount} = await generator.getQueryFileCount()\n report.event.fileCount({fileCount})\n\n for await (const {filename, ...result} of generator.getQueryResultDeclarations()) {\n allFilenames.add(filename)\n const progress = {\n queriesCount,\n projectionsCount,\n filesCount: allFilenames.size,\n }\n\n switch (result.type) {\n case 'error': {\n errorCount += 1\n errorFilenames.add(filename)\n\n const errorMessage =\n typeof result.error === 'object' && result.error !== null && 'message' in result.error\n ? String(result.error.message)\n : 'Unknown Error'\n\n const message = `Error generating types in \"${filename}\": ${errorMessage}`\n report.stream.generatedQueryResultDeclaration.emit({type: 'error', message, progress})\n continue\n }\n\n case 'queries': {\n if (!result.queryResultDeclarations.length) {\n report.stream.generatedQueryResultDeclaration.emit({type: 'progress', progress})\n continue\n }\n\n for (const {code, type, stats} of result.queryResultDeclarations) {\n queriesCount += type === 'query' ? 1 : 0\n projectionsCount += type === 'projection' ? 1 : 0\n typeNodesGenerated += stats.allTypes\n unknownTypeNodesGenerated += stats.unknownTypes\n emptyUnionTypeNodesGenerated += stats.emptyUnions\n\n if (type === 'projection') {\n projectionFilenames.add(filename)\n } else {\n queryFilenames.add(filename)\n }\n\n report.stream.generatedQueryResultDeclaration.emit({type: 'declaration', code, progress})\n }\n continue\n }\n\n default: {\n continue\n }\n }\n }\n report.stream.generatedQueryResultDeclaration.end()\n\n report.event.generationComplete({\n augmentedQueryResultDeclarations: await generator.getAugmentedQueryResultsDeclarations(),\n queryStats: {\n errorCount,\n queriesCount,\n projectionsCount,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n emptyUnionTypeNodesGenerated,\n totalScannedFilesCount: allFilenames.size,\n filesWithErrors: errorFilenames.size,\n queryFilesCount: queryFilenames.size,\n projectionFilesCount: projectionFilenames.size,\n unknownTypeNodesRatio:\n typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0,\n },\n })\n}\n\nregisterBabel()\nmain()\n"],"names":["DEFAULT_CONFIG","isMainThread","parentPort","createReporter","_workerData","stat","readSchema","TypeGenerator","findQueriesInPath","getResolver","registerBabel"],"mappings":";;AAqBA,MAAM,sBAAsBA,QAAA,eAAe,QAAQ,CAAC,EAAE;AA6DtD,IAAIC,oBAAAA,gBAAgB,CAACC,oBAAA;AACb,QAAA,IAAI,MAAM,4CAA4C;AAG9D,MAAM,SAASC,cAAA,eAAqCD,8BAAU,GACxD,OAAOE,oBAAA;AAEb,eAAe,OAAO;AACpB,QAAM,UAAsE,CAAC;AAE7E,aAAW,EAAC,UAAU,WAAU,KAAK,KAAK;AACpC,QAAA;AAEF,UA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AAA,MACA;AAAA,MACA,wBAAwB,aAAa;AAAA,MACrC,iBAAiB,eAAe;AAAA,MAChC,iBAAiB,eAAe;AAAA,MAChC,sBAAsB,oBAAoB;AAAA,MAC1C,uBACE,qBAAqB,IAAI,4BAA4B,qBAAqB;AAAA,IAAA;AAAA,EAC9E,CACD;AACH;AAEAC,QAAAA,cAAc;AACd,KAAK;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.88.1-typegen-experimental.0",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -46,24 +46,13 @@
|
|
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
|
-
},
|
59
49
|
"dependencies": {
|
60
50
|
"@babel/traverse": "^7.23.5",
|
61
|
-
"@sanity/client": "^7.
|
62
|
-
"@sanity/
|
63
|
-
"@sanity/runtime-cli": "^3.0.0",
|
51
|
+
"@sanity/client": "^7.1.0",
|
52
|
+
"@sanity/runtime-cli": "^6.1.1",
|
64
53
|
"@sanity/telemetry": "^0.8.0",
|
65
54
|
"@sanity/template-validator": "^2.4.3",
|
66
|
-
"@sanity/util": "3.
|
55
|
+
"@sanity/util": "3.88.1",
|
67
56
|
"chalk": "^4.1.2",
|
68
57
|
"debug": "^4.3.4",
|
69
58
|
"decompress": "^4.2.0",
|
@@ -74,16 +63,14 @@
|
|
74
63
|
"pkg-dir": "^5.0.0",
|
75
64
|
"prettier": "^3.3.0",
|
76
65
|
"semver": "^7.3.5",
|
77
|
-
"validate-npm-package-name": "^3.0.0"
|
66
|
+
"validate-npm-package-name": "^3.0.0",
|
67
|
+
"@sanity/codegen": "3.88.1-typegen-experimental.0"
|
78
68
|
},
|
79
69
|
"devDependencies": {
|
80
|
-
"@repo/package.config": "3.87.1",
|
81
|
-
"@repo/test-config": "3.87.1",
|
82
70
|
"@rexxars/gitconfiglocal": "^3.0.1",
|
83
71
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
84
72
|
"@sanity/eslint-config-studio": "^4.0.0",
|
85
73
|
"@sanity/generate-help-url": "^3.0.0",
|
86
|
-
"@sanity/types": "3.87.1",
|
87
74
|
"@types/babel__traverse": "^7.20.5",
|
88
75
|
"@types/configstore": "^5.0.1",
|
89
76
|
"@types/cpx": "^1.5.2",
|
@@ -130,10 +117,21 @@
|
|
130
117
|
"vite": "^6.2.4",
|
131
118
|
"vitest": "^3.1.1",
|
132
119
|
"which": "^2.0.2",
|
133
|
-
"xdg-basedir": "^4.0.0"
|
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"
|
134
124
|
},
|
135
125
|
"engines": {
|
136
126
|
"node": ">=18"
|
137
127
|
},
|
138
|
-
"
|
139
|
-
|
128
|
+
"scripts": {
|
129
|
+
"build": "pkg-utils build --strict --check --clean",
|
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
|
+
}
|
@@ -2,8 +2,8 @@ import {type ProjectTemplate} from '../initProject'
|
|
2
2
|
|
3
3
|
const appTemplate: ProjectTemplate = {
|
4
4
|
dependencies: {
|
5
|
-
'@sanity/sdk': '^
|
6
|
-
'@sanity/sdk-react': '^
|
5
|
+
'@sanity/sdk': '^1',
|
6
|
+
'@sanity/sdk-react': '^1',
|
7
7
|
'react': '^19',
|
8
8
|
'react-dom': '^19',
|
9
9
|
},
|
@@ -2,8 +2,8 @@ import {type ProjectTemplate} from '../initProject'
|
|
2
2
|
|
3
3
|
const appSanityUiTemplate: ProjectTemplate = {
|
4
4
|
dependencies: {
|
5
|
-
'@sanity/sdk': '^
|
6
|
-
'@sanity/sdk-react': '^
|
5
|
+
'@sanity/sdk': '^1',
|
6
|
+
'@sanity/sdk-react': '^1',
|
7
7
|
'@sanity/ui': '^2',
|
8
8
|
'react': '^19',
|
9
9
|
'react-dom': '^19',
|
@@ -1,20 +1,26 @@
|
|
1
1
|
import {defineTrace} from '@sanity/telemetry'
|
2
2
|
|
3
|
-
interface
|
3
|
+
interface TypesGeneratedTraceAttributes {
|
4
4
|
outputSize: number
|
5
5
|
queriesCount: number
|
6
|
+
projectionsCount: number
|
6
7
|
schemaTypesCount: number
|
8
|
+
schemaCount: number
|
9
|
+
totalScannedFilesCount: number
|
7
10
|
queryFilesCount: number
|
11
|
+
projectionFilesCount: number
|
8
12
|
filesWithErrors: number
|
13
|
+
errorCount: number
|
9
14
|
typeNodesGenerated: number
|
10
15
|
unknownTypeNodesGenerated: number
|
11
16
|
unknownTypeNodesRatio: number
|
12
17
|
emptyUnionTypeNodesGenerated: number
|
13
18
|
configOverloadClientMethods: boolean
|
19
|
+
configAugmentGroqModule: boolean
|
14
20
|
}
|
15
21
|
|
16
|
-
export const TypesGeneratedTrace = defineTrace<
|
22
|
+
export const TypesGeneratedTrace = defineTrace<TypesGeneratedTraceAttributes>({
|
17
23
|
name: 'Types Generated',
|
18
|
-
version:
|
24
|
+
version: 1,
|
19
25
|
description: 'Trace emitted when generating TypeScript types for queries',
|
20
26
|
})
|