@sanity/cli 3.93.1-next.8.cf0bf8550a → 3.94.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 +1 -1
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/package.json +10 -11
- package/templates/blog/README.md +1 -1
- package/templates/clean/README.md +1 -1
- package/templates/ecommerce/README.md +1 -1
- package/templates/get-started/README.md +1 -1
- package/templates/moviedb/README.md +1 -1
- package/templates/quickstart/README.md +1 -1
- package/src/CommandRunner.ts +0 -219
- package/src/__telemetry__/cli.telemetry.ts +0 -29
- package/src/__telemetry__/init.telemetry.ts +0 -95
- package/src/actions/codemod/codemodAction.ts +0 -109
- package/src/actions/codemod/mods/deskRename.ts +0 -19
- package/src/actions/codemod/mods/index.ts +0 -9
- package/src/actions/codemod/mods/partsTypeDirective.ts +0 -28
- package/src/actions/codemod/mods/reactIconsV3.ts +0 -54
- package/src/actions/codemod/types.ts +0 -10
- package/src/actions/init-plugin/bootstrapFromTemplate.ts +0 -196
- package/src/actions/init-project/bootstrapLocalTemplate.ts +0 -201
- package/src/actions/init-project/bootstrapRemoteTemplate.ts +0 -118
- package/src/actions/init-project/createAppCliConfig.ts +0 -24
- package/src/actions/init-project/createCliConfig.ts +0 -31
- package/src/actions/init-project/createPackageManifest.ts +0 -102
- package/src/actions/init-project/createStudioConfig.ts +0 -53
- package/src/actions/init-project/determineAppTemplate.ts +0 -13
- package/src/actions/init-project/fsUtils.ts +0 -40
- package/src/actions/init-project/git.ts +0 -59
- package/src/actions/init-project/initProject.ts +0 -1708
- package/src/actions/init-project/processTemplate.ts +0 -55
- package/src/actions/init-project/promptForDatasetName.ts +0 -68
- package/src/actions/init-project/prompts/index.ts +0 -51
- package/src/actions/init-project/prompts/nextjs.ts +0 -59
- package/src/actions/init-project/readPackageJson.ts +0 -17
- package/src/actions/init-project/templates/appQuickstart.ts +0 -23
- package/src/actions/init-project/templates/appSanityUi.ts +0 -25
- package/src/actions/init-project/templates/blog.ts +0 -5
- package/src/actions/init-project/templates/clean.ts +0 -5
- package/src/actions/init-project/templates/getStarted.ts +0 -37
- package/src/actions/init-project/templates/index.ts +0 -24
- package/src/actions/init-project/templates/moviedb.ts +0 -35
- package/src/actions/init-project/templates/nextjs/index.ts +0 -238
- package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +0 -252
- package/src/actions/init-project/templates/quickstart.ts +0 -5
- package/src/actions/init-project/templates/shopify.ts +0 -78
- package/src/actions/init-project/templates/shopifyOnline.ts +0 -50
- package/src/actions/init-project/updateInitialTemplateMetadata.ts +0 -24
- package/src/actions/login/login.telemetry.ts +0 -18
- package/src/actions/login/login.ts +0 -350
- package/src/actions/login/types.ts +0 -19
- package/src/actions/project/createProject.ts +0 -36
- package/src/actions/telemetry/setTelemetryConsent.ts +0 -101
- package/src/actions/typegen/generate.telemetry.ts +0 -20
- package/src/actions/typegen/generateAction.ts +0 -210
- package/src/actions/versions/findSanityModuleVersions.ts +0 -185
- package/src/actions/yarn/events.ts +0 -73
- package/src/cli.ts +0 -350
- package/src/cliClient.ts +0 -62
- package/src/commands/blueprints/addBlueprintsCommand.ts +0 -155
- package/src/commands/blueprints/blueprintsGroup.ts +0 -10
- package/src/commands/blueprints/configBlueprintsCommand.ts +0 -86
- package/src/commands/blueprints/deployBlueprintsCommand.ts +0 -63
- package/src/commands/blueprints/destroyBlueprintsCommand.ts +0 -78
- package/src/commands/blueprints/infoBlueprintsCommand.ts +0 -55
- package/src/commands/blueprints/initBlueprintsCommand.ts +0 -99
- package/src/commands/blueprints/logsBlueprintsCommand.ts +0 -66
- package/src/commands/blueprints/planBlueprintsCommand.ts +0 -51
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +0 -66
- package/src/commands/codemod/codemodCommand.ts +0 -32
- package/src/commands/debug/debugCommand.ts +0 -26
- package/src/commands/debug/printDebugInfo.ts +0 -243
- package/src/commands/docs/docsCommand.ts +0 -20
- package/src/commands/functions/devFunctionsCommand.ts +0 -73
- package/src/commands/functions/envFunctionsCommand.ts +0 -105
- package/src/commands/functions/functionsGroup.ts +0 -10
- package/src/commands/functions/logsFunctionsCommand.ts +0 -94
- package/src/commands/functions/testFunctionsCommand.ts +0 -93
- package/src/commands/help/helpCommand.ts +0 -21
- package/src/commands/help/showHelp.ts +0 -58
- package/src/commands/index.ts +0 -72
- package/src/commands/init/initCommand.ts +0 -123
- package/src/commands/install/installCommand.ts +0 -38
- package/src/commands/learn/learnCommand.ts +0 -20
- package/src/commands/login/loginCommand.ts +0 -29
- package/src/commands/logout/logoutCommand.ts +0 -52
- package/src/commands/manage/manageCommand.ts +0 -24
- package/src/commands/projects/listProjectsCommand.ts +0 -62
- package/src/commands/projects/projectsGroup.ts +0 -10
- package/src/commands/telemetry/disableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/enableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/telemetryGroup.ts +0 -10
- package/src/commands/telemetry/telemetryStatusCommand.ts +0 -89
- package/src/commands/typegen/generateTypesCommand.ts +0 -56
- package/src/commands/typegen/typegenGroup.ts +0 -10
- package/src/commands/versions/printVersionResult.ts +0 -51
- package/src/commands/versions/versionsCommand.ts +0 -13
- package/src/config.ts +0 -14
- package/src/debug.ts +0 -3
- package/src/index.ts +0 -6
- package/src/outputters/cliOutputter.ts +0 -47
- package/src/packageManager/getInstallCommand.ts +0 -26
- package/src/packageManager/getUpgradeCommand.ts +0 -52
- package/src/packageManager/index.ts +0 -33
- package/src/packageManager/installPackages.ts +0 -99
- package/src/packageManager/packageManagerChoice.ts +0 -204
- package/src/packageManager/uninstallPackages.ts +0 -44
- package/src/packageManager/yarnStub.ts +0 -22
- package/src/prompters/cliPrompter.ts +0 -9
- package/src/run.ts +0 -8
- package/src/studioDependencies.ts +0 -25
- package/src/types.ts +0 -387
- package/src/util/canLaunchBrowser.ts +0 -12
- package/src/util/cliWorker.ts +0 -34
- package/src/util/clientWrapper.ts +0 -119
- package/src/util/copy.ts +0 -50
- package/src/util/createExpiringConfig.ts +0 -80
- package/src/util/createTelemetryStore.ts +0 -204
- package/src/util/detectRuntime.ts +0 -12
- package/src/util/dynamicRequire.ts +0 -17
- package/src/util/frameworkPort.ts +0 -63
- package/src/util/generateCommandsDocumentation.ts +0 -62
- package/src/util/getCliConfig.ts +0 -172
- package/src/util/getCliVersion.ts +0 -22
- package/src/util/getLocalVersion.ts +0 -35
- package/src/util/getProjectDefaults.ts +0 -103
- package/src/util/getProviderName.ts +0 -9
- package/src/util/getUserConfig.ts +0 -15
- package/src/util/isCi.ts +0 -7
- package/src/util/isCommandGroup.ts +0 -7
- package/src/util/isInteractive.ts +0 -3
- package/src/util/isTrueish.ts +0 -8
- package/src/util/journeyConfig.ts +0 -280
- package/src/util/loadEnv.ts +0 -110
- package/src/util/mergeCommands.ts +0 -78
- package/src/util/neatStack.ts +0 -30
- package/src/util/noSuchCommandText.ts +0 -91
- package/src/util/parseArguments.ts +0 -76
- package/src/util/pathExists.ts +0 -14
- package/src/util/readJson.ts +0 -6
- package/src/util/readdirRecursive.ts +0 -26
- package/src/util/remoteTemplate.ts +0 -320
- package/src/util/resolveLatestVersions.ts +0 -24
- package/src/util/resolveRootDir.ts +0 -59
- package/src/util/telemetryDisclosure.ts +0 -45
- package/src/util/updateNotifier.ts +0 -158
- package/src/util/writeJson.ts +0 -6
- package/src/workers/getAndWriteJourneySchema.ts +0 -7
- package/src/workers/getCliConfig.ts +0 -14
- package/src/workers/typegenGenerate.ts +0 -228
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-process-env */
|
|
2
|
-
import boxen from 'boxen'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import latestVersion from 'get-latest-version'
|
|
5
|
-
import pTimeout from 'p-timeout'
|
|
6
|
-
import semverCompare from 'semver-compare'
|
|
7
|
-
|
|
8
|
-
import {debug} from '../debug'
|
|
9
|
-
import {getCliUpgradeCommand} from '../packageManager'
|
|
10
|
-
import {type PackageJson} from '../types'
|
|
11
|
-
import {getUserConfig} from './getUserConfig'
|
|
12
|
-
import {isCi} from './isCi'
|
|
13
|
-
|
|
14
|
-
const MAX_BLOCKING_TIME = 300
|
|
15
|
-
const TWELVE_HOURS = 1000 * 60 * 60 * 12
|
|
16
|
-
const isDisabled =
|
|
17
|
-
isCi || // Running in CI environment
|
|
18
|
-
process.env.NO_UPDATE_NOTIFIER // Explicitly disabled
|
|
19
|
-
|
|
20
|
-
interface UpdateCheckOptions {
|
|
21
|
-
pkg: PackageJson
|
|
22
|
-
cwd: string
|
|
23
|
-
workDir: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function runUpdateCheck(options: UpdateCheckOptions): {notify: () => Promise<void>} {
|
|
27
|
-
debug('CLI installed at %s', __dirname)
|
|
28
|
-
|
|
29
|
-
const {pkg, cwd, workDir} = options
|
|
30
|
-
const {name, version} = pkg
|
|
31
|
-
const userConfig = getUserConfig()
|
|
32
|
-
const check = getLatestRemote().catch((): false => false)
|
|
33
|
-
let hasPrintedResult = false
|
|
34
|
-
|
|
35
|
-
return {notify}
|
|
36
|
-
|
|
37
|
-
async function notify() {
|
|
38
|
-
if (!process.stdout.isTTY) {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const result = await pTimeout(check, MAX_BLOCKING_TIME, printCachedResult)
|
|
43
|
-
if (hasPrintedResult) {
|
|
44
|
-
debug('Has already printed result through timeout check, skipping result notification')
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
printResult(result)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function printCachedResult(): Promise<false> {
|
|
52
|
-
debug('Max time (%dms) reached waiting for latest version info', MAX_BLOCKING_TIME)
|
|
53
|
-
hasPrintedResult = true
|
|
54
|
-
|
|
55
|
-
const cached = userConfig.get('cliHasUpdate')
|
|
56
|
-
if (!cached) {
|
|
57
|
-
debug('No cached latest version result found')
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const diff = semverCompare(cached, version)
|
|
62
|
-
if (diff <= 0) {
|
|
63
|
-
// Looks like CLI was upgraded since last check
|
|
64
|
-
debug('CLI was upgraded since last check, falling back')
|
|
65
|
-
userConfig.delete('cliHasUpdate')
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
debug('Printing cached latest version result')
|
|
70
|
-
await printResult(cached)
|
|
71
|
-
return false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function printResult(newVersion: string | false) {
|
|
75
|
-
hasPrintedResult = true
|
|
76
|
-
|
|
77
|
-
const lastUpdated = userConfig.get('cliLastUpdateNag') || 0
|
|
78
|
-
if (Date.now() - lastUpdated < TWELVE_HOURS) {
|
|
79
|
-
debug('Less than 12 hours since last nag, skipping')
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!newVersion || semverCompare(newVersion, version) <= 0) {
|
|
84
|
-
debug(`New version is ${newVersion || 'unknown'}, current is ${version}. Falling back.`)
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const upgradeCommand = await getCliUpgradeCommand({cwd, workDir})
|
|
89
|
-
const message = [
|
|
90
|
-
'Update available ',
|
|
91
|
-
chalk.dim(version),
|
|
92
|
-
chalk.reset(' → '),
|
|
93
|
-
chalk.green(newVersion),
|
|
94
|
-
' \nRun ',
|
|
95
|
-
chalk.cyan(upgradeCommand),
|
|
96
|
-
' to update',
|
|
97
|
-
].join('')
|
|
98
|
-
|
|
99
|
-
const boxenOpts = {
|
|
100
|
-
padding: 1,
|
|
101
|
-
margin: 1,
|
|
102
|
-
borderColor: 'yellow',
|
|
103
|
-
|
|
104
|
-
// Typescript issues forcing these to any
|
|
105
|
-
align: 'center' as any,
|
|
106
|
-
borderStyle: 'round' as any,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Print to stderr to prevent garbling command output
|
|
110
|
-
// eslint-disable-next-line no-console
|
|
111
|
-
console.error(`\n${boxen(message, boxenOpts)}`)
|
|
112
|
-
|
|
113
|
-
userConfig.set('cliLastUpdateNag', Date.now())
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function getLatestRemote(): Promise<false | string> {
|
|
117
|
-
if (isDisabled) {
|
|
118
|
-
debug('Running on CI, or explicitly disabled, skipping update check')
|
|
119
|
-
return false
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const lastUpdated = userConfig.get('cliLastUpdateCheck') || 0
|
|
123
|
-
if (Date.now() - lastUpdated < TWELVE_HOURS) {
|
|
124
|
-
debug('Less than 12 hours since last check, skipping update check')
|
|
125
|
-
return userConfig.get('cliHasUpdate') || false
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
let latestRemote: string | undefined
|
|
129
|
-
try {
|
|
130
|
-
debug('Checking for latest remote version')
|
|
131
|
-
latestRemote = await latestVersion(name)
|
|
132
|
-
debug('Latest remote version is %s', latestRemote)
|
|
133
|
-
} catch (err) {
|
|
134
|
-
debug(`Failed to fetch latest version of ${name} from npm:\n${err.stack}`)
|
|
135
|
-
return false
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (!latestRemote) {
|
|
139
|
-
debug(`Failed to fetch latest version of ${name} from npm`)
|
|
140
|
-
return false
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
userConfig.set('cliLastUpdateCheck', Date.now())
|
|
144
|
-
|
|
145
|
-
const diff = semverCompare(latestRemote, version)
|
|
146
|
-
if (diff <= 0) {
|
|
147
|
-
// No change, or lower
|
|
148
|
-
debug(diff === 0 ? 'No update found' : 'Remote version older than local')
|
|
149
|
-
userConfig.delete('cliHasUpdate')
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Update available, set to user config so we may notify on next startup
|
|
154
|
-
userConfig.set('cliHasUpdate', latestRemote)
|
|
155
|
-
debug('Update is available (%s)', latestRemote)
|
|
156
|
-
return latestRemote
|
|
157
|
-
}
|
|
158
|
-
}
|
package/src/util/writeJson.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import {parentPort, workerData} from 'node:worker_threads'
|
|
2
|
-
|
|
3
|
-
import {getAndWriteJourneySchema} from '../util/journeyConfig'
|
|
4
|
-
|
|
5
|
-
getAndWriteJourneySchema(workerData)
|
|
6
|
-
.then(() => parentPort?.postMessage({type: 'success'}))
|
|
7
|
-
.catch((error) => parentPort?.postMessage({type: 'error', error}))
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {parentPort, workerData} from 'node:worker_threads'
|
|
2
|
-
|
|
3
|
-
import {getCliConfig} from '../util/getCliConfig'
|
|
4
|
-
|
|
5
|
-
// We're communicating with a parent process through a message channel
|
|
6
|
-
getCliConfig(workerData, {forked: false})
|
|
7
|
-
.then((config) => parentPort?.postMessage({type: 'config', config}))
|
|
8
|
-
.catch((error) =>
|
|
9
|
-
parentPort?.postMessage({
|
|
10
|
-
type: 'error',
|
|
11
|
-
error: error instanceof Error ? error.stack : error,
|
|
12
|
-
errorType: error && (error.type || error.name),
|
|
13
|
-
}),
|
|
14
|
-
)
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import {isMainThread, parentPort, workerData as _workerData} from 'node:worker_threads'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
findQueriesInPath,
|
|
5
|
-
getResolver,
|
|
6
|
-
readSchema,
|
|
7
|
-
registerBabel,
|
|
8
|
-
safeParseQuery,
|
|
9
|
-
TypeGenerator,
|
|
10
|
-
} from '@sanity/codegen'
|
|
11
|
-
import createDebug from 'debug'
|
|
12
|
-
import {typeEvaluate, type TypeNode} from 'groq-js'
|
|
13
|
-
|
|
14
|
-
const $info = createDebug('sanity:codegen:generate:info')
|
|
15
|
-
|
|
16
|
-
export interface TypegenGenerateTypesWorkerData {
|
|
17
|
-
workDir: string
|
|
18
|
-
workspaceName?: string
|
|
19
|
-
schemaPath: string
|
|
20
|
-
searchPath: string | string[]
|
|
21
|
-
overloadClientMethods?: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type TypegenGenerateTypesWorkerMessage =
|
|
25
|
-
| {
|
|
26
|
-
type: 'error'
|
|
27
|
-
error: Error
|
|
28
|
-
fatal: boolean
|
|
29
|
-
query?: string
|
|
30
|
-
filename?: string
|
|
31
|
-
}
|
|
32
|
-
| {
|
|
33
|
-
type: 'types'
|
|
34
|
-
filename: string
|
|
35
|
-
types: {
|
|
36
|
-
queryName: string
|
|
37
|
-
query: string
|
|
38
|
-
type: string
|
|
39
|
-
unknownTypeNodesGenerated: number
|
|
40
|
-
typeNodesGenerated: number
|
|
41
|
-
emptyUnionTypeNodesGenerated: number
|
|
42
|
-
}[]
|
|
43
|
-
}
|
|
44
|
-
| {
|
|
45
|
-
type: 'schema'
|
|
46
|
-
filename: string
|
|
47
|
-
schema: string
|
|
48
|
-
length: number
|
|
49
|
-
}
|
|
50
|
-
| {
|
|
51
|
-
type: 'typemap'
|
|
52
|
-
typeMap: string
|
|
53
|
-
}
|
|
54
|
-
| {
|
|
55
|
-
type: 'complete'
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (isMainThread || !parentPort) {
|
|
59
|
-
throw new Error('This module must be run as a worker thread')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const opts = _workerData as TypegenGenerateTypesWorkerData
|
|
63
|
-
|
|
64
|
-
registerBabel()
|
|
65
|
-
|
|
66
|
-
async function main() {
|
|
67
|
-
const schema = await readSchema(opts.schemaPath)
|
|
68
|
-
|
|
69
|
-
const typeGenerator = new TypeGenerator(schema)
|
|
70
|
-
const schemaTypes = [typeGenerator.generateSchemaTypes(), TypeGenerator.generateKnownTypes()]
|
|
71
|
-
.join('\n')
|
|
72
|
-
.trim()
|
|
73
|
-
const resolver = getResolver()
|
|
74
|
-
|
|
75
|
-
parentPort?.postMessage({
|
|
76
|
-
type: 'schema',
|
|
77
|
-
schema: `${schemaTypes.trim()}\n`,
|
|
78
|
-
filename: 'schema.json',
|
|
79
|
-
length: schema.length,
|
|
80
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
81
|
-
|
|
82
|
-
const queries = findQueriesInPath({
|
|
83
|
-
path: opts.searchPath,
|
|
84
|
-
resolver,
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const allQueries = []
|
|
88
|
-
|
|
89
|
-
for await (const result of queries) {
|
|
90
|
-
if (result.type === 'error') {
|
|
91
|
-
parentPort?.postMessage({
|
|
92
|
-
type: 'error',
|
|
93
|
-
error: result.error,
|
|
94
|
-
fatal: false,
|
|
95
|
-
filename: result.filename,
|
|
96
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
97
|
-
continue
|
|
98
|
-
}
|
|
99
|
-
$info(`Processing ${result.queries.length} queries in "${result.filename}"...`)
|
|
100
|
-
|
|
101
|
-
const fileQueryTypes: {
|
|
102
|
-
queryName: string
|
|
103
|
-
query: string
|
|
104
|
-
type: string
|
|
105
|
-
typeName: string
|
|
106
|
-
typeNode: TypeNode
|
|
107
|
-
unknownTypeNodesGenerated: number
|
|
108
|
-
typeNodesGenerated: number
|
|
109
|
-
emptyUnionTypeNodesGenerated: number
|
|
110
|
-
}[] = []
|
|
111
|
-
for (const {name: queryName, result: query} of result.queries) {
|
|
112
|
-
try {
|
|
113
|
-
const ast = safeParseQuery(query)
|
|
114
|
-
const queryTypes = typeEvaluate(ast, schema)
|
|
115
|
-
|
|
116
|
-
const typeName = `${queryName}Result`
|
|
117
|
-
const type = typeGenerator.generateTypeNodeTypes(typeName, queryTypes)
|
|
118
|
-
|
|
119
|
-
const queryTypeStats = walkAndCountQueryTypeNodeStats(queryTypes)
|
|
120
|
-
fileQueryTypes.push({
|
|
121
|
-
queryName,
|
|
122
|
-
query,
|
|
123
|
-
typeName,
|
|
124
|
-
typeNode: queryTypes,
|
|
125
|
-
type: `${type.trim()}\n`,
|
|
126
|
-
unknownTypeNodesGenerated: queryTypeStats.unknownTypes,
|
|
127
|
-
typeNodesGenerated: queryTypeStats.allTypes,
|
|
128
|
-
emptyUnionTypeNodesGenerated: queryTypeStats.emptyUnions,
|
|
129
|
-
})
|
|
130
|
-
} catch (err) {
|
|
131
|
-
parentPort?.postMessage({
|
|
132
|
-
type: 'error',
|
|
133
|
-
error: new Error(
|
|
134
|
-
`Error generating types for query "${queryName}" in "${result.filename}": ${err.message}`,
|
|
135
|
-
{cause: err},
|
|
136
|
-
),
|
|
137
|
-
fatal: false,
|
|
138
|
-
query,
|
|
139
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (fileQueryTypes.length > 0) {
|
|
144
|
-
$info(`Generated types for ${fileQueryTypes.length} queries in "${result.filename}"\n`)
|
|
145
|
-
parentPort?.postMessage({
|
|
146
|
-
type: 'types',
|
|
147
|
-
types: fileQueryTypes,
|
|
148
|
-
filename: result.filename,
|
|
149
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (fileQueryTypes.length > 0) {
|
|
153
|
-
allQueries.push(...fileQueryTypes)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (opts.overloadClientMethods && allQueries.length > 0) {
|
|
158
|
-
const typeMap = `${typeGenerator.generateQueryMap(allQueries).trim()}\n`
|
|
159
|
-
parentPort?.postMessage({
|
|
160
|
-
type: 'typemap',
|
|
161
|
-
typeMap,
|
|
162
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
parentPort?.postMessage({
|
|
166
|
-
type: 'complete',
|
|
167
|
-
} satisfies TypegenGenerateTypesWorkerMessage)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function walkAndCountQueryTypeNodeStats(typeNode: TypeNode): {
|
|
171
|
-
allTypes: number
|
|
172
|
-
unknownTypes: number
|
|
173
|
-
emptyUnions: number
|
|
174
|
-
} {
|
|
175
|
-
switch (typeNode.type) {
|
|
176
|
-
case 'unknown': {
|
|
177
|
-
return {allTypes: 1, unknownTypes: 1, emptyUnions: 0}
|
|
178
|
-
}
|
|
179
|
-
case 'array': {
|
|
180
|
-
const acc = walkAndCountQueryTypeNodeStats(typeNode.of)
|
|
181
|
-
acc.allTypes += 1 // count the array type itself
|
|
182
|
-
return acc
|
|
183
|
-
}
|
|
184
|
-
case 'object': {
|
|
185
|
-
// if the rest is unknown, we count it as one unknown type
|
|
186
|
-
if (typeNode.rest && typeNode.rest.type === 'unknown') {
|
|
187
|
-
return {allTypes: 2, unknownTypes: 1, emptyUnions: 0} // count the object type itself as well
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const restStats = typeNode.rest
|
|
191
|
-
? walkAndCountQueryTypeNodeStats(typeNode.rest)
|
|
192
|
-
: {allTypes: 1, unknownTypes: 0, emptyUnions: 0} // count the object type itself
|
|
193
|
-
|
|
194
|
-
return Object.values(typeNode.attributes).reduce((acc, attribute) => {
|
|
195
|
-
const {allTypes, unknownTypes, emptyUnions} = walkAndCountQueryTypeNodeStats(
|
|
196
|
-
attribute.value,
|
|
197
|
-
)
|
|
198
|
-
return {
|
|
199
|
-
allTypes: acc.allTypes + allTypes,
|
|
200
|
-
unknownTypes: acc.unknownTypes + unknownTypes,
|
|
201
|
-
emptyUnions: acc.emptyUnions + emptyUnions,
|
|
202
|
-
}
|
|
203
|
-
}, restStats)
|
|
204
|
-
}
|
|
205
|
-
case 'union': {
|
|
206
|
-
if (typeNode.of.length === 0) {
|
|
207
|
-
return {allTypes: 1, unknownTypes: 0, emptyUnions: 1}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return typeNode.of.reduce(
|
|
211
|
-
(acc, type) => {
|
|
212
|
-
const {allTypes, unknownTypes, emptyUnions} = walkAndCountQueryTypeNodeStats(type)
|
|
213
|
-
return {
|
|
214
|
-
allTypes: acc.allTypes + allTypes,
|
|
215
|
-
unknownTypes: acc.unknownTypes + unknownTypes,
|
|
216
|
-
emptyUnions: acc.emptyUnions + emptyUnions,
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
{allTypes: 1, unknownTypes: 0, emptyUnions: 0}, // count the union type itself
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
default: {
|
|
223
|
-
return {allTypes: 1, unknownTypes: 0, emptyUnions: 0}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
main()
|