@sanity/cli 6.0.0-alpha.19 → 6.0.0-alpha.21
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/README.md +713 -533
- package/dist/actions/auth/authServer.js +13 -11
- package/dist/actions/auth/authServer.js.map +1 -1
- package/dist/actions/auth/login/getProvider.js +43 -39
- package/dist/actions/auth/login/getProvider.js.map +1 -1
- package/dist/actions/auth/login/getSSOProvider.js +25 -19
- package/dist/actions/auth/login/getSSOProvider.js.map +1 -1
- package/dist/actions/auth/login/login.js +12 -33
- package/dist/actions/auth/login/login.js.map +1 -1
- package/dist/actions/auth/types.js.map +1 -1
- package/dist/actions/codemods/reactIconsV3.js +2 -2
- package/dist/actions/codemods/reactIconsV3.js.map +1 -1
- package/dist/actions/debug/formatters.js +22 -0
- package/dist/actions/debug/formatters.js.map +1 -0
- package/dist/actions/dev/getDashboardAppUrl.js +3 -3
- package/dist/actions/dev/getDashboardAppUrl.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +2 -2
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/documents/validation/reporters/prettyReporter/formatDocumentValidation.js +1 -1
- package/dist/actions/documents/validation/reporters/prettyReporter/formatDocumentValidation.js.map +1 -1
- package/dist/actions/documents/validation/reporters/prettyReporter/tree.js +108 -0
- package/dist/actions/documents/validation/reporters/prettyReporter/tree.js.map +1 -0
- package/dist/actions/graphql/SchemaError.js +4 -26
- package/dist/actions/graphql/SchemaError.js.map +1 -1
- package/dist/actions/graphql/extractFromSanitySchema.js +3 -4
- package/dist/actions/graphql/extractFromSanitySchema.js.map +1 -1
- package/dist/actions/graphql/extractGraphQLAPIs.js +150 -0
- package/dist/actions/graphql/extractGraphQLAPIs.js.map +1 -0
- package/dist/actions/graphql/extractGraphQLAPIs.worker.js +12 -0
- package/dist/actions/graphql/extractGraphQLAPIs.worker.js.map +1 -0
- package/dist/actions/graphql/gen1/index.js +5 -5
- package/dist/actions/graphql/gen1/index.js.map +1 -1
- package/dist/actions/graphql/gen2/index.js +6 -6
- package/dist/actions/graphql/gen2/index.js.map +1 -1
- package/dist/actions/graphql/gen3/generateTypeQueries.js +2 -3
- package/dist/actions/graphql/gen3/generateTypeQueries.js.map +1 -1
- package/dist/actions/graphql/gen3/index.js +6 -7
- package/dist/actions/graphql/gen3/index.js.map +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.js +12 -35
- package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.worker.js +75 -106
- package/dist/actions/graphql/getGraphQLAPIs.worker.js.map +1 -1
- package/dist/actions/graphql/helpers.js +13 -0
- package/dist/actions/graphql/helpers.js.map +1 -1
- package/dist/actions/graphql/resolveGraphQLApisFromWorkspaces.js +187 -0
- package/dist/actions/graphql/resolveGraphQLApisFromWorkspaces.js.map +1 -0
- package/dist/actions/graphql/types.js +1 -1
- package/dist/actions/graphql/types.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.js +2 -1
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
- package/dist/actions/init/bootstrapRemoteTemplate.js +6 -5
- package/dist/actions/init/bootstrapRemoteTemplate.js.map +1 -1
- package/dist/actions/init/createPackageManifest.js +5 -0
- package/dist/actions/init/createPackageManifest.js.map +1 -1
- package/dist/actions/init/templates/appQuickstart.js +2 -1
- package/dist/actions/init/templates/appQuickstart.js.map +1 -1
- package/dist/actions/init/templates/appSanityUi.js +2 -1
- package/dist/actions/init/templates/appSanityUi.js.map +1 -1
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/media/importMedia.js +1 -2
- package/dist/actions/media/importMedia.js.map +1 -1
- package/dist/actions/projects/getManageUrl.js +1 -2
- package/dist/actions/projects/getManageUrl.js.map +1 -1
- package/dist/actions/schema/validateSchema.worker.js +1 -3
- package/dist/actions/schema/validateSchema.worker.js.map +1 -1
- package/dist/actions/telemetry/isTrueish.js +10 -0
- package/dist/actions/telemetry/isTrueish.js.map +1 -0
- package/dist/actions/telemetry/resolveConsent.js +2 -1
- package/dist/actions/telemetry/resolveConsent.js.map +1 -1
- package/dist/actions/telemetry/setConsent.js +2 -1
- package/dist/actions/telemetry/setConsent.js.map +1 -1
- package/dist/actions/versions/findSanityModulesVersions.js +1 -2
- package/dist/actions/versions/findSanityModulesVersions.js.map +1 -1
- package/dist/commands/backup/disable.js +21 -1
- package/dist/commands/backup/disable.js.map +1 -1
- package/dist/commands/backup/download.js +18 -4
- package/dist/commands/backup/download.js.map +1 -1
- package/dist/commands/backup/enable.js +21 -1
- package/dist/commands/backup/enable.js.map +1 -1
- package/dist/commands/backup/list.js +15 -1
- package/dist/commands/backup/list.js.map +1 -1
- package/dist/commands/cors/add.js +19 -1
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +21 -1
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +21 -1
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/dataset/alias/create.js +4 -2
- package/dist/commands/dataset/alias/create.js.map +1 -1
- package/dist/commands/dataset/alias/delete.js +4 -2
- package/dist/commands/dataset/alias/delete.js.map +1 -1
- package/dist/commands/dataset/alias/link.js +4 -2
- package/dist/commands/dataset/alias/link.js.map +1 -1
- package/dist/commands/dataset/alias/unlink.js +4 -2
- package/dist/commands/dataset/alias/unlink.js.map +1 -1
- package/dist/commands/dataset/copy.js +4 -2
- package/dist/commands/dataset/copy.js.map +1 -1
- package/dist/commands/dataset/create.js +4 -2
- package/dist/commands/dataset/create.js.map +1 -1
- package/dist/commands/dataset/delete.js +4 -2
- package/dist/commands/dataset/delete.js.map +1 -1
- package/dist/commands/dataset/embeddings/disable.js +4 -2
- package/dist/commands/dataset/embeddings/disable.js.map +1 -1
- package/dist/commands/dataset/embeddings/enable.js +6 -4
- package/dist/commands/dataset/embeddings/enable.js.map +1 -1
- package/dist/commands/dataset/embeddings/status.js +4 -2
- package/dist/commands/dataset/embeddings/status.js.map +1 -1
- package/dist/commands/dataset/export.js +7 -11
- package/dist/commands/dataset/export.js.map +1 -1
- package/dist/commands/dataset/list.js +4 -2
- package/dist/commands/dataset/list.js.map +1 -1
- package/dist/commands/dataset/visibility/get.js +4 -2
- package/dist/commands/dataset/visibility/get.js.map +1 -1
- package/dist/commands/dataset/visibility/set.js +4 -2
- package/dist/commands/dataset/visibility/set.js.map +1 -1
- package/dist/commands/debug.js +2 -1
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/documents/create.js +15 -5
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +17 -6
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +15 -6
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +24 -12
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +29 -9
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/deploy.js +55 -28
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/list.js +14 -1
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +36 -14
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hook/attempt.js +21 -1
- package/dist/commands/hook/attempt.js.map +1 -1
- package/dist/commands/hook/create.js +22 -2
- package/dist/commands/hook/create.js.map +1 -1
- package/dist/commands/hook/delete.js +21 -1
- package/dist/commands/hook/delete.js.map +1 -1
- package/dist/commands/hook/list.js +21 -1
- package/dist/commands/hook/list.js.map +1 -1
- package/dist/commands/hook/logs.js +19 -1
- package/dist/commands/hook/logs.js.map +1 -1
- package/dist/commands/init.js +13 -6
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +13 -6
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +8 -6
- package/dist/commands/logout.js.map +1 -1
- package/dist/commands/media/create-aspect.js +3 -3
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +8 -1
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/deploy-aspect.js +20 -3
- package/dist/commands/media/deploy-aspect.js.map +1 -1
- package/dist/commands/media/export.js +8 -1
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +9 -2
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/schema/delete.js +19 -6
- package/dist/commands/schema/delete.js.map +1 -1
- package/dist/commands/schema/deploy.js +8 -2
- package/dist/commands/schema/deploy.js.map +1 -1
- package/dist/commands/tokens/add.js +23 -1
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/commands/tokens/delete.js +19 -1
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +19 -1
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/invite.js +23 -1
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/commands/users/list.js +23 -1
- package/dist/commands/users/list.js.map +1 -1
- package/dist/hooks/prerun/flushTelemetry.worker.js +1 -1
- package/dist/hooks/prerun/flushTelemetry.worker.js.map +1 -1
- package/dist/hooks/prerun/injectEnvVariables.js +9 -1
- package/dist/hooks/prerun/injectEnvVariables.js.map +1 -1
- package/dist/hooks/prerun/setupTelemetry.js +2 -1
- package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
- package/dist/prompts/promptForProject.js.map +1 -1
- package/dist/{actions/auth/login/promptProviders.js → prompts/promptForProviders.js} +3 -3
- package/dist/prompts/promptForProviders.js.map +1 -0
- package/dist/services/auth.js +36 -3
- package/dist/services/auth.js.map +1 -1
- package/dist/services/docs.js +2 -2
- package/dist/services/docs.js.map +1 -1
- package/dist/services/getUrlHeaders.js +0 -2
- package/dist/services/getUrlHeaders.js.map +1 -1
- package/dist/services/projects.js +4 -2
- package/dist/services/projects.js.map +1 -1
- package/dist/services/telemetry.js +2 -1
- package/dist/services/telemetry.js.map +1 -1
- package/dist/util/createExpiringConfig.js +64 -0
- package/dist/util/createExpiringConfig.js.map +1 -0
- package/dist/util/detectFramework.js +135 -0
- package/dist/util/detectFramework.js.map +1 -0
- package/dist/util/extractDocumentsFromNdjsonOrTarball.js +1 -2
- package/dist/util/extractDocumentsFromNdjsonOrTarball.js.map +1 -1
- package/dist/util/isSchemaError.js +11 -0
- package/dist/util/isSchemaError.js.map +1 -0
- package/dist/util/isTar.js +8 -0
- package/dist/util/isTar.js.map +1 -0
- package/dist/util/sharedFlags.js +44 -14
- package/dist/util/sharedFlags.js.map +1 -1
- package/dist/util/telemetry/cleanupOldTelemetryFiles.js +30 -0
- package/dist/util/telemetry/cleanupOldTelemetryFiles.js.map +1 -0
- package/dist/util/telemetry/createTelemetryStore.js +95 -0
- package/dist/util/telemetry/createTelemetryStore.js.map +1 -0
- package/dist/util/telemetry/createTraceId.js +10 -0
- package/dist/util/telemetry/createTraceId.js.map +1 -0
- package/dist/util/telemetry/findTelemetryFiles.js +35 -0
- package/dist/util/telemetry/findTelemetryFiles.js.map +1 -0
- package/dist/util/telemetry/flushTelemetryFiles.js +118 -0
- package/dist/util/telemetry/flushTelemetryFiles.js.map +1 -0
- package/dist/util/telemetry/generateTelemetryFilePath.js +30 -0
- package/dist/util/telemetry/generateTelemetryFilePath.js.map +1 -0
- package/dist/util/telemetry/logger.js +59 -0
- package/dist/util/telemetry/logger.js.map +1 -0
- package/dist/util/telemetry/readNDJSON.js +28 -0
- package/dist/util/telemetry/readNDJSON.js.map +1 -0
- package/dist/util/telemetry/telemetryStoreDebug.js +7 -0
- package/dist/util/telemetry/telemetryStoreDebug.js.map +1 -0
- package/dist/util/telemetry/trace.js +150 -0
- package/dist/util/telemetry/trace.js.map +1 -0
- package/dist/util/update/updateChecker.js +2 -1
- package/dist/util/update/updateChecker.js.map +1 -1
- package/oclif.manifest.json +1211 -774
- package/package.json +19 -22
- package/dist/actions/auth/login/promptProviders.js.map +0 -1
|
@@ -1,126 +1,95 @@
|
|
|
1
1
|
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { doImport, isStudioConfig } from '@sanity/cli-core';
|
|
3
|
+
import { resolveGraphQLApiMetadata } from './resolveGraphQLApisFromWorkspaces.js';
|
|
4
|
+
const { cliConfig, configPath } = workerData;
|
|
4
5
|
async function main() {
|
|
5
6
|
if (isMainThread || !parentPort) {
|
|
6
7
|
throw new Error('This module must be run as a worker thread');
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
await
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// Import the raw config through Vite (via studioWorkerTask) — handles TS paths, browser globals.
|
|
10
|
+
// We skip resolveConfig() entirely to avoid schema compilation — we only need workspace metadata.
|
|
11
|
+
let config = await doImport(configPath);
|
|
12
|
+
// Handle both direct config exports and default exports (same logic as getStudioWorkspaces)
|
|
13
|
+
if (!isStudioConfig(config)) {
|
|
14
|
+
if (typeof config === 'object' && config !== null && 'default' in config && isStudioConfig(config.default)) {
|
|
15
|
+
config = config.default;
|
|
16
|
+
} else {
|
|
17
|
+
throw new TypeError(`Invalid studio config format in "${configPath}"`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const configs = Array.isArray(config) ? config : [
|
|
21
|
+
config
|
|
22
|
+
];
|
|
23
|
+
const workspaces = configs.map((ws)=>toWorkspaceMetadata(ws));
|
|
24
|
+
const apis = resolveGraphQLApiMetadata({
|
|
14
25
|
cliConfig,
|
|
15
26
|
workspaces
|
|
16
27
|
});
|
|
17
|
-
|
|
28
|
+
parentPort.postMessage(apis);
|
|
18
29
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const multiWorkspace = workspaces.length > 1;
|
|
23
|
-
const hasGraphQLConfig = Boolean(cliConfig?.graphql);
|
|
24
|
-
if (workspaces.length === 0) {
|
|
25
|
-
throw new Error('No studio configuration found');
|
|
30
|
+
function toWorkspaceMetadata(config) {
|
|
31
|
+
if (typeof config !== 'object' || config === null) {
|
|
32
|
+
throw new Error('Invalid workspace config: expected an object');
|
|
26
33
|
}
|
|
27
|
-
if (
|
|
28
|
-
throw new Error('
|
|
34
|
+
if (!('projectId' in config) || !config.projectId || typeof config.projectId !== 'string') {
|
|
35
|
+
throw new Error('Invalid workspace config: missing or invalid projectId');
|
|
29
36
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
throw new Error(oneline`
|
|
33
|
-
Multiple workspaces/sources configured.
|
|
34
|
-
You must define an array of GraphQL APIs in \`sanity.cli.ts\` or \`sanity.cli.js\`
|
|
35
|
-
and specify which workspace/source to use.
|
|
36
|
-
`);
|
|
37
|
+
if (!('dataset' in config) || !config.dataset || typeof config.dataset !== 'string') {
|
|
38
|
+
throw new Error('Invalid workspace config: missing or invalid dataset');
|
|
37
39
|
}
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
// Default to 'default' when no name is specified — this matches the convention used by
|
|
41
|
+
// resolveConfig() in the full-compile path (extractGraphQLAPIs). Both paths must agree on
|
|
42
|
+
// this default so that workspace lookup in resolveGraphQLApiMetadata/resolveGraphQLApis
|
|
43
|
+
// produces the same match. If Sanity's resolveConfig() ever changes this convention,
|
|
44
|
+
// this default must be updated to match.
|
|
45
|
+
const name = 'name' in config && typeof config.name === 'string' ? config.name : 'default';
|
|
46
|
+
const sources = extractSourceMetadata(config, {
|
|
47
|
+
dataset: config.dataset,
|
|
48
|
+
name,
|
|
49
|
+
projectId: config.projectId
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
dataset: config.dataset,
|
|
53
|
+
name,
|
|
54
|
+
projectId: config.projectId,
|
|
55
|
+
sources
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Extract source metadata from the raw workspace config.
|
|
60
|
+
*
|
|
61
|
+
* After `resolveConfig()`, each workspace has `unstable_sources` with full schema objects.
|
|
62
|
+
* The raw config from `defineConfig()` may also have `unstable_sources` if the user explicitly
|
|
63
|
+
* configured multiple sources. We extract only the metadata (name/dataset/projectId) we need.
|
|
64
|
+
*
|
|
65
|
+
* If no `unstable_sources` are present, we create a single default source from the workspace
|
|
66
|
+
* metadata — matching what `resolveConfig()` would produce for a single-source workspace.
|
|
67
|
+
*/ function extractSourceMetadata(config, workspaceDefaults) {
|
|
68
|
+
if (!('unstable_sources' in config) || !Array.isArray(config.unstable_sources)) {
|
|
41
69
|
return [
|
|
42
|
-
|
|
43
|
-
dataset,
|
|
44
|
-
projectId,
|
|
45
|
-
schemaTypes: getStrippedSchemaTypes(schema)
|
|
46
|
-
}
|
|
70
|
+
workspaceDefaults
|
|
47
71
|
];
|
|
48
72
|
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const workspace = !workspaceName && workspaces.length === 1 ? workspaces[0] : workspaces.find((space)=>space.name === (workspaceName || 'default'));
|
|
63
|
-
if (!workspace) {
|
|
64
|
-
throw new Error(`Workspace "${workspaceName || 'default'}" not found`);
|
|
65
|
-
}
|
|
66
|
-
// If we only have a single source defined, we can assume that is the intended one,
|
|
67
|
-
// even if no `source` is defined for the GraphQL API
|
|
68
|
-
const source = !sourceName && workspace.unstable_sources.length === 1 ? workspace.unstable_sources[0] : workspace.unstable_sources.find((src)=>src.name === (sourceName || 'default'));
|
|
69
|
-
if (!source) {
|
|
70
|
-
throw new Error(`Source "${sourceName || 'default'}" not found in workspace "${workspaceName || 'default'}"`);
|
|
71
|
-
}
|
|
72
|
-
resolvedApis.push({
|
|
73
|
-
...apiDef,
|
|
74
|
-
dataset: source.dataset,
|
|
75
|
-
projectId: source.projectId,
|
|
76
|
-
schemaTypes: getStrippedSchemaTypes(source.schema)
|
|
73
|
+
const sources = [];
|
|
74
|
+
for (const source of config.unstable_sources){
|
|
75
|
+
if (typeof source !== 'object' || source === null) continue;
|
|
76
|
+
const sourceName = 'name' in source && typeof source.name === 'string' ? source.name : 'default';
|
|
77
|
+
// Sources can inherit projectId/dataset from the parent workspace (e.g. when
|
|
78
|
+
// only `name` and `schema` are specified in `unstable_sources`). Fall back to
|
|
79
|
+
// the workspace-level values when the source doesn't define its own.
|
|
80
|
+
const projectId = 'projectId' in source && typeof source.projectId === 'string' && source.projectId ? source.projectId : workspaceDefaults.projectId;
|
|
81
|
+
const dataset = 'dataset' in source && typeof source.dataset === 'string' && source.dataset ? source.dataset : workspaceDefaults.dataset;
|
|
82
|
+
sources.push({
|
|
83
|
+
dataset,
|
|
84
|
+
name: sourceName,
|
|
85
|
+
projectId
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw new TypeError(`"graphql" key in "${configPath}" must be an array if defined`);
|
|
84
|
-
}
|
|
85
|
-
if (config.length === 0) {
|
|
86
|
-
throw new Error(`No GraphQL APIs defined in "${configPath}"`);
|
|
87
|
-
}
|
|
88
|
-
return config;
|
|
89
|
-
}
|
|
90
|
-
function getStrippedSchemaTypes(schema) {
|
|
91
|
-
const schemaDef = schema._original || {
|
|
92
|
-
types: []
|
|
93
|
-
};
|
|
94
|
-
return schemaDef.types.map((type)=>stripType(type));
|
|
95
|
-
}
|
|
96
|
-
function stripType(input) {
|
|
97
|
-
return strip(input);
|
|
98
|
-
}
|
|
99
|
-
function strip(input) {
|
|
100
|
-
if (Array.isArray(input)) {
|
|
101
|
-
return input.map((item)=>strip(item)).filter((item)=>item !== undefined);
|
|
102
|
-
}
|
|
103
|
-
if (isPlainishObject(input)) {
|
|
104
|
-
const stripped = {};
|
|
105
|
-
for (const key of Object.keys(input)){
|
|
106
|
-
stripped[key] = strip(input[key]);
|
|
107
|
-
}
|
|
108
|
-
return stripped;
|
|
109
|
-
}
|
|
110
|
-
return isBasicType(input) ? input : undefined;
|
|
111
|
-
}
|
|
112
|
-
function isPlainishObject(input) {
|
|
113
|
-
return isPlainObject(input);
|
|
114
|
-
}
|
|
115
|
-
function isBasicType(input) {
|
|
116
|
-
const type = typeof input;
|
|
117
|
-
if (type === 'boolean' || type === 'number' || type === 'string') {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
if (type !== 'object') {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
return Array.isArray(input) || input === null || isPlainishObject(input);
|
|
88
|
+
// Fall back to workspace-level metadata if no valid sources were found
|
|
89
|
+
return sources.length > 0 ? sources : [
|
|
90
|
+
workspaceDefaults
|
|
91
|
+
];
|
|
124
92
|
}
|
|
93
|
+
await main();
|
|
125
94
|
|
|
126
95
|
//# sourceMappingURL=getGraphQLAPIs.worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/getGraphQLAPIs.worker.ts"],"sourcesContent":["import {isMainThread,
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/getGraphQLAPIs.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {doImport, isStudioConfig} from '@sanity/cli-core'\n\nimport {\n resolveGraphQLApiMetadata,\n type SourceMetadata,\n type WorkspaceMetadata,\n} from './resolveGraphQLApisFromWorkspaces.js'\nimport {type GraphQLAPIConfig} from './types.js'\n\ninterface WorkerData {\n configPath: string\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n}\n\nconst {cliConfig, configPath} = workerData as WorkerData\n\nasync function main() {\n if (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n }\n\n // Import the raw config through Vite (via studioWorkerTask) — handles TS paths, browser globals.\n // We skip resolveConfig() entirely to avoid schema compilation — we only need workspace metadata.\n let config: unknown = await doImport(configPath)\n\n // Handle both direct config exports and default exports (same logic as getStudioWorkspaces)\n if (!isStudioConfig(config)) {\n if (\n typeof config === 'object' &&\n config !== null &&\n 'default' in config &&\n isStudioConfig(config.default)\n ) {\n config = config.default\n } else {\n throw new TypeError(`Invalid studio config format in \"${configPath}\"`)\n }\n }\n\n const configs: unknown[] = Array.isArray(config) ? config : [config]\n const workspaces = configs.map((ws) => toWorkspaceMetadata(ws))\n\n const apis = resolveGraphQLApiMetadata({cliConfig, workspaces})\n parentPort.postMessage(apis)\n}\n\nfunction toWorkspaceMetadata(config: unknown): WorkspaceMetadata {\n if (typeof config !== 'object' || config === null) {\n throw new Error('Invalid workspace config: expected an object')\n }\n\n if (!('projectId' in config) || !config.projectId || typeof config.projectId !== 'string') {\n throw new Error('Invalid workspace config: missing or invalid projectId')\n }\n\n if (!('dataset' in config) || !config.dataset || typeof config.dataset !== 'string') {\n throw new Error('Invalid workspace config: missing or invalid dataset')\n }\n\n // Default to 'default' when no name is specified — this matches the convention used by\n // resolveConfig() in the full-compile path (extractGraphQLAPIs). Both paths must agree on\n // this default so that workspace lookup in resolveGraphQLApiMetadata/resolveGraphQLApis\n // produces the same match. If Sanity's resolveConfig() ever changes this convention,\n // this default must be updated to match.\n const name = 'name' in config && typeof config.name === 'string' ? config.name : 'default'\n const sources = extractSourceMetadata(config, {\n dataset: config.dataset,\n name,\n projectId: config.projectId,\n })\n\n return {\n dataset: config.dataset,\n name,\n projectId: config.projectId,\n sources,\n }\n}\n\n/**\n * Extract source metadata from the raw workspace config.\n *\n * After `resolveConfig()`, each workspace has `unstable_sources` with full schema objects.\n * The raw config from `defineConfig()` may also have `unstable_sources` if the user explicitly\n * configured multiple sources. We extract only the metadata (name/dataset/projectId) we need.\n *\n * If no `unstable_sources` are present, we create a single default source from the workspace\n * metadata — matching what `resolveConfig()` would produce for a single-source workspace.\n */\nfunction extractSourceMetadata(\n config: object,\n workspaceDefaults: SourceMetadata,\n): SourceMetadata[] {\n if (!('unstable_sources' in config) || !Array.isArray(config.unstable_sources)) {\n return [workspaceDefaults]\n }\n\n const sources: SourceMetadata[] = []\n for (const source of config.unstable_sources) {\n if (typeof source !== 'object' || source === null) continue\n\n const sourceName = 'name' in source && typeof source.name === 'string' ? source.name : 'default'\n\n // Sources can inherit projectId/dataset from the parent workspace (e.g. when\n // only `name` and `schema` are specified in `unstable_sources`). Fall back to\n // the workspace-level values when the source doesn't define its own.\n const projectId =\n 'projectId' in source && typeof source.projectId === 'string' && source.projectId\n ? source.projectId\n : workspaceDefaults.projectId\n const dataset =\n 'dataset' in source && typeof source.dataset === 'string' && source.dataset\n ? source.dataset\n : workspaceDefaults.dataset\n\n sources.push({dataset, name: sourceName, projectId})\n }\n\n // Fall back to workspace-level metadata if no valid sources were found\n return sources.length > 0 ? sources : [workspaceDefaults]\n}\n\nawait main()\n"],"names":["isMainThread","parentPort","workerData","doImport","isStudioConfig","resolveGraphQLApiMetadata","cliConfig","configPath","main","Error","config","default","TypeError","configs","Array","isArray","workspaces","map","ws","toWorkspaceMetadata","apis","postMessage","projectId","dataset","name","sources","extractSourceMetadata","workspaceDefaults","unstable_sources","source","sourceName","push","length"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,QAAQ,EAAEC,cAAc,QAAO,mBAAkB;AAEzD,SACEC,yBAAyB,QAGpB,wCAAuC;AAS9C,MAAM,EAACC,SAAS,EAAEC,UAAU,EAAC,GAAGL;AAEhC,eAAeM;IACb,IAAIR,gBAAgB,CAACC,YAAY;QAC/B,MAAM,IAAIQ,MAAM;IAClB;IAEA,iGAAiG;IACjG,kGAAkG;IAClG,IAAIC,SAAkB,MAAMP,SAASI;IAErC,4FAA4F;IAC5F,IAAI,CAACH,eAAeM,SAAS;QAC3B,IACE,OAAOA,WAAW,YAClBA,WAAW,QACX,aAAaA,UACbN,eAAeM,OAAOC,OAAO,GAC7B;YACAD,SAASA,OAAOC,OAAO;QACzB,OAAO;YACL,MAAM,IAAIC,UAAU,CAAC,iCAAiC,EAAEL,WAAW,CAAC,CAAC;QACvE;IACF;IAEA,MAAMM,UAAqBC,MAAMC,OAAO,CAACL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,UAAUD,UAAU,OAAOA,OAAOL,IAAI,KAAK,WAAWK,OAAOL,IAAI,GAAG;QAEvF,6EAA6E;QAC7E,8EAA8E;QAC9E,qEAAqE;QACrE,MAAMF,YACJ,eAAeO,UAAU,OAAOA,OAAOP,SAAS,KAAK,YAAYO,OAAOP,SAAS,GAC7EO,OAAOP,SAAS,GAChBK,kBAAkBL,SAAS;QACjC,MAAMC,UACJ,aAAaM,UAAU,OAAOA,OAAON,OAAO,KAAK,YAAYM,OAAON,OAAO,GACvEM,OAAON,OAAO,GACdI,kBAAkBJ,OAAO;QAE/BE,QAAQM,IAAI,CAAC;YAACR;YAASC,MAAMM;YAAYR;QAAS;IACpD;IAEA,uEAAuE;IACvE,OAAOG,QAAQO,MAAM,GAAG,IAAIP,UAAU;QAACE;KAAkB;AAC3D;AAEA,MAAMnB"}
|
|
@@ -7,5 +7,18 @@ export function isNonUnion(type) {
|
|
|
7
7
|
export function isDocumentType(type) {
|
|
8
8
|
return isNonUnion(type) && type.type === 'Object' && Array.isArray(type.interfaces) && type.interfaces.includes('Document');
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Strip `_internal` metadata from extracted types before sending to the API.
|
|
12
|
+
* This property carries pipeline-internal data (e.g. deprecation info for query generation)
|
|
13
|
+
* and must not be included in the deployed schema.
|
|
14
|
+
*/ export function stripInternalMeta(types) {
|
|
15
|
+
return types.map((type)=>{
|
|
16
|
+
if ('_internal' in type) {
|
|
17
|
+
const { _internal, ...rest } = type;
|
|
18
|
+
return rest;
|
|
19
|
+
}
|
|
20
|
+
return type;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
10
23
|
|
|
11
24
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/helpers.ts"],"sourcesContent":["import {\n type ConvertedDocumentType,\n type ConvertedInterface,\n type ConvertedType,\n type ConvertedUnion,\n} from './types.js'\n\nexport function isUnion(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedUnion {\n return type.kind === 'Union'\n}\n\nexport function isNonUnion(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedType {\n return !isUnion(type) && 'type' in type\n}\n\nexport function isDocumentType(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedDocumentType {\n return (\n isNonUnion(type) &&\n type.type === 'Object' &&\n Array.isArray(type.interfaces) &&\n type.interfaces.includes('Document')\n )\n}\n"],"names":["isUnion","type","kind","isNonUnion","isDocumentType","Array","isArray","interfaces","includes"],"mappings":"AAOA,OAAO,SAASA,QACdC,IAAyD;IAEzD,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,OAAO,SAASC,WACdF,IAAyD;IAEzD,OAAO,CAACD,QAAQC,SAAS,UAAUA;AACrC;AAEA,OAAO,SAASG,eACdH,IAAyD;IAEzD,OACEE,WAAWF,SACXA,KAAKA,IAAI,KAAK,YACdI,MAAMC,OAAO,CAACL,KAAKM,UAAU,KAC7BN,KAAKM,UAAU,CAACC,QAAQ,CAAC;AAE7B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/helpers.ts"],"sourcesContent":["import {\n type ConvertedDocumentType,\n type ConvertedInterface,\n type ConvertedType,\n type ConvertedUnion,\n} from './types.js'\n\nexport function isUnion(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedUnion {\n return type.kind === 'Union'\n}\n\nexport function isNonUnion(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedType {\n return !isUnion(type) && 'type' in type\n}\n\nexport function isDocumentType(\n type: ConvertedInterface | ConvertedType | ConvertedUnion,\n): type is ConvertedDocumentType {\n return (\n isNonUnion(type) &&\n type.type === 'Object' &&\n Array.isArray(type.interfaces) &&\n type.interfaces.includes('Document')\n )\n}\n\n/**\n * Strip `_internal` metadata from extracted types before sending to the API.\n * This property carries pipeline-internal data (e.g. deprecation info for query generation)\n * and must not be included in the deployed schema.\n */\nexport function stripInternalMeta(\n types: (ConvertedType | ConvertedUnion)[],\n): (ConvertedType | ConvertedUnion)[] {\n return types.map((type) => {\n if ('_internal' in type) {\n const {_internal, ...rest} = type\n return rest\n }\n return type\n })\n}\n"],"names":["isUnion","type","kind","isNonUnion","isDocumentType","Array","isArray","interfaces","includes","stripInternalMeta","types","map","_internal","rest"],"mappings":"AAOA,OAAO,SAASA,QACdC,IAAyD;IAEzD,OAAOA,KAAKC,IAAI,KAAK;AACvB;AAEA,OAAO,SAASC,WACdF,IAAyD;IAEzD,OAAO,CAACD,QAAQC,SAAS,UAAUA;AACrC;AAEA,OAAO,SAASG,eACdH,IAAyD;IAEzD,OACEE,WAAWF,SACXA,KAAKA,IAAI,KAAK,YACdI,MAAMC,OAAO,CAACL,KAAKM,UAAU,KAC7BN,KAAKM,UAAU,CAACC,QAAQ,CAAC;AAE7B;AAEA;;;;CAIC,GACD,OAAO,SAASC,kBACdC,KAAyC;IAEzC,OAAOA,MAAMC,GAAG,CAAC,CAACV;QAChB,IAAI,eAAeA,MAAM;YACvB,MAAM,EAACW,SAAS,EAAE,GAAGC,MAAK,GAAGZ;YAC7B,OAAOY;QACT;QACA,OAAOZ;IACT;AACF"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import isPlainObject from 'lodash-es/isPlainObject.js';
|
|
2
|
+
import { oneline } from 'oneline';
|
|
3
|
+
export function resolveGraphQLApis({ cliConfig, workspaces }) {
|
|
4
|
+
const numSources = workspaces.reduce((count, workspace)=>count + workspace.unstable_sources.length, 0);
|
|
5
|
+
const multiSource = numSources > 1;
|
|
6
|
+
const multiWorkspace = workspaces.length > 1;
|
|
7
|
+
const hasGraphQLConfig = Boolean(cliConfig?.graphql);
|
|
8
|
+
if (workspaces.length === 0) {
|
|
9
|
+
throw new Error('No studio configuration found');
|
|
10
|
+
}
|
|
11
|
+
if (numSources === 0) {
|
|
12
|
+
throw new Error('No sources (project ID / dataset) configured');
|
|
13
|
+
}
|
|
14
|
+
// We can only automatically configure if there is a single workspace + source in play
|
|
15
|
+
if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {
|
|
16
|
+
throw new Error(oneline`
|
|
17
|
+
Multiple workspaces/sources configured.
|
|
18
|
+
You must define an array of GraphQL APIs in \`sanity.cli.ts\` or \`sanity.cli.js\`
|
|
19
|
+
and specify which workspace/source to use.
|
|
20
|
+
`);
|
|
21
|
+
}
|
|
22
|
+
// No config is defined, but we have a single workspace + source, so use that
|
|
23
|
+
if (!hasGraphQLConfig) {
|
|
24
|
+
const { dataset, projectId, schema } = workspaces[0].unstable_sources[0];
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
dataset,
|
|
28
|
+
projectId,
|
|
29
|
+
schemaTypes: getStrippedSchemaTypes(schema)
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
// Explicitly defined config
|
|
34
|
+
const apiDefs = validateCliConfig(cliConfig?.graphql || []);
|
|
35
|
+
return resolveGraphQLAPIsFromConfig(apiDefs, workspaces);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve GraphQL API metadata (projectId, dataset, tag, etc.) from raw workspace configs
|
|
39
|
+
* without compiling schemas. This is used when we only need API identifiers, not schema types —
|
|
40
|
+
* e.g. for `graphql undeploy --api` or `graphql list`.
|
|
41
|
+
*/ export function resolveGraphQLApiMetadata({ cliConfig, workspaces }) {
|
|
42
|
+
const numSources = workspaces.reduce((count, ws)=>count + ws.sources.length, 0);
|
|
43
|
+
const multiSource = numSources > 1;
|
|
44
|
+
const multiWorkspace = workspaces.length > 1;
|
|
45
|
+
const hasGraphQLConfig = Boolean(cliConfig?.graphql);
|
|
46
|
+
if (workspaces.length === 0) {
|
|
47
|
+
throw new Error('No studio configuration found');
|
|
48
|
+
}
|
|
49
|
+
if (numSources === 0) {
|
|
50
|
+
throw new Error('No sources (project ID / dataset) configured');
|
|
51
|
+
}
|
|
52
|
+
// We can only automatically configure if there is a single workspace + source in play
|
|
53
|
+
if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {
|
|
54
|
+
throw new Error(oneline`
|
|
55
|
+
Multiple workspaces/sources configured.
|
|
56
|
+
You must define an array of GraphQL APIs in \`sanity.cli.ts\` or \`sanity.cli.js\`
|
|
57
|
+
and specify which workspace/source to use.
|
|
58
|
+
`);
|
|
59
|
+
}
|
|
60
|
+
// Validate that workspaces and their sources have non-empty projectId/dataset.
|
|
61
|
+
// The worker's toWorkspaceMetadata validates this before constructing metadata,
|
|
62
|
+
// but assert here to make the invariant explicit.
|
|
63
|
+
for (const ws of workspaces){
|
|
64
|
+
if (!ws.projectId || !ws.dataset) {
|
|
65
|
+
throw new Error(`Workspace "${ws.name}" is missing a projectId or dataset. ` + 'Check your studio configuration.');
|
|
66
|
+
}
|
|
67
|
+
for (const source of ws.sources){
|
|
68
|
+
if (!source.projectId || !source.dataset) {
|
|
69
|
+
throw new Error(`Source "${source.name}" in workspace "${ws.name}" is missing a projectId or dataset. ` + 'Check your studio configuration.');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// No config is defined, but we have a single workspace + source, so use that
|
|
74
|
+
if (!hasGraphQLConfig) {
|
|
75
|
+
const { dataset, projectId } = workspaces[0].sources[0];
|
|
76
|
+
return [
|
|
77
|
+
{
|
|
78
|
+
dataset,
|
|
79
|
+
projectId
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
// Explicitly defined config
|
|
84
|
+
const apiDefs = validateCliConfig(cliConfig?.graphql || []);
|
|
85
|
+
return resolveGraphQLApiMetadataFromConfig(apiDefs, workspaces);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Shared workspace/source resolution logic for both the metadata and full-compile paths.
|
|
89
|
+
*
|
|
90
|
+
* Both `resolveGraphQLAPIsFromConfig` and `resolveGraphQLApiMetadataFromConfig` need to
|
|
91
|
+
* resolve the workspace and source for each GraphQL API config entry. This helper
|
|
92
|
+
* extracts that shared logic so bug fixes and edge-case handling apply to both paths.
|
|
93
|
+
*/ function resolveWorkspaceAndSource(apiDef, workspaces, getSources) {
|
|
94
|
+
const { source: sourceName, workspace: workspaceName } = apiDef;
|
|
95
|
+
if (!workspaceName && workspaces.length > 1) {
|
|
96
|
+
throw new Error('Must define `workspace` name in GraphQL API config when multiple workspaces are defined');
|
|
97
|
+
}
|
|
98
|
+
// If we only have a single workspace defined, we can assume that is the intended one,
|
|
99
|
+
// even if no `workspace` is defined for the GraphQL API
|
|
100
|
+
const workspace = !workspaceName && workspaces.length === 1 ? workspaces[0] : workspaces.find((space)=>space.name === (workspaceName || 'default'));
|
|
101
|
+
if (!workspace) {
|
|
102
|
+
throw new Error(`Workspace "${workspaceName || 'default'}" not found`);
|
|
103
|
+
}
|
|
104
|
+
const sources = getSources(workspace);
|
|
105
|
+
// If we only have a single source defined, we can assume that is the intended one,
|
|
106
|
+
// even if no `source` is defined for the GraphQL API
|
|
107
|
+
const source = !sourceName && sources.length === 1 ? sources[0] : sources.find((src)=>src.name === (sourceName || 'default'));
|
|
108
|
+
if (!source) {
|
|
109
|
+
throw new Error(`Source "${sourceName || 'default'}" not found in workspace "${workspaceName || 'default'}"`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
source,
|
|
113
|
+
workspace
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function resolveGraphQLApiMetadataFromConfig(apiDefs, workspaces) {
|
|
117
|
+
return apiDefs.map((apiDef)=>{
|
|
118
|
+
const { source } = resolveWorkspaceAndSource(apiDef, workspaces, (ws)=>ws.sources);
|
|
119
|
+
return {
|
|
120
|
+
dataset: source.dataset,
|
|
121
|
+
filterSuffix: apiDef.filterSuffix,
|
|
122
|
+
generation: apiDef.generation,
|
|
123
|
+
id: apiDef.id,
|
|
124
|
+
nonNullDocumentFields: apiDef.nonNullDocumentFields,
|
|
125
|
+
playground: apiDef.playground,
|
|
126
|
+
projectId: source.projectId,
|
|
127
|
+
tag: apiDef.tag
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function resolveGraphQLAPIsFromConfig(apiDefs, workspaces) {
|
|
132
|
+
return apiDefs.map((apiDef)=>{
|
|
133
|
+
const { source } = resolveWorkspaceAndSource(apiDef, workspaces, (ws)=>ws.unstable_sources);
|
|
134
|
+
return {
|
|
135
|
+
...apiDef,
|
|
136
|
+
dataset: source.dataset,
|
|
137
|
+
projectId: source.projectId,
|
|
138
|
+
schemaTypes: getStrippedSchemaTypes(source.schema)
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function validateCliConfig(config, configPath = 'sanity.cli.js') {
|
|
143
|
+
if (!Array.isArray(config)) {
|
|
144
|
+
throw new TypeError(`"graphql" key in "${configPath}" must be an array if defined`);
|
|
145
|
+
}
|
|
146
|
+
if (config.length === 0) {
|
|
147
|
+
throw new Error(`No GraphQL APIs defined in "${configPath}"`);
|
|
148
|
+
}
|
|
149
|
+
return config;
|
|
150
|
+
}
|
|
151
|
+
function getStrippedSchemaTypes(schema) {
|
|
152
|
+
const schemaDef = schema._original || {
|
|
153
|
+
types: []
|
|
154
|
+
};
|
|
155
|
+
return schemaDef.types.map((type)=>stripType(type));
|
|
156
|
+
}
|
|
157
|
+
function stripType(input) {
|
|
158
|
+
return strip(input);
|
|
159
|
+
}
|
|
160
|
+
function strip(input) {
|
|
161
|
+
if (Array.isArray(input)) {
|
|
162
|
+
return input.map((item)=>strip(item)).filter((item)=>item !== undefined);
|
|
163
|
+
}
|
|
164
|
+
if (isPlainishObject(input)) {
|
|
165
|
+
const stripped = {};
|
|
166
|
+
for (const key of Object.keys(input)){
|
|
167
|
+
stripped[key] = strip(input[key]);
|
|
168
|
+
}
|
|
169
|
+
return stripped;
|
|
170
|
+
}
|
|
171
|
+
return isBasicType(input) ? input : undefined;
|
|
172
|
+
}
|
|
173
|
+
function isPlainishObject(input) {
|
|
174
|
+
return isPlainObject(input);
|
|
175
|
+
}
|
|
176
|
+
function isBasicType(input) {
|
|
177
|
+
const type = typeof input;
|
|
178
|
+
if (type === 'boolean' || type === 'number' || type === 'string') {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
if (type !== 'object') {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
return Array.isArray(input) || input === null || isPlainishObject(input);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//# sourceMappingURL=resolveGraphQLApisFromWorkspaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/resolveGraphQLApisFromWorkspaces.ts"],"sourcesContent":["import {type Schema} from '@sanity/types'\nimport isPlainObject from 'lodash-es/isPlainObject.js'\nimport {oneline} from 'oneline'\n\nimport {\n type ExtractedGraphQLAPI,\n type GraphQLAPIConfig,\n type SchemaDefinitionish,\n type TypeResolvedGraphQLAPI,\n} from './types.js'\n\nexport interface Source {\n dataset: string\n name: string\n projectId: string\n schema: Schema\n}\n\nexport interface Workspace extends Source {\n unstable_sources: Source[]\n}\n\n/**\n * Minimal source metadata — dataset/projectId pair for a source within a workspace.\n */\nexport interface SourceMetadata {\n dataset: string\n name: string\n projectId: string\n}\n\n/**\n * Minimal workspace metadata — enough for resolving API identifiers without compiling schemas.\n * This matches the raw workspace shape from `defineConfig()` before `resolveConfig()` processes it.\n *\n * The `sources` array mirrors `Workspace.unstable_sources` from the full resolved config.\n * When the raw config includes `unstable_sources`, they are extracted here. Otherwise, the\n * workspace itself is used as a single default source (matching what `resolveConfig()` would do).\n */\nexport interface WorkspaceMetadata {\n dataset: string\n name: string\n projectId: string\n sources: SourceMetadata[]\n}\n\ninterface ResolveGraphQLApisOptions {\n workspaces: Workspace[]\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n}\n\nexport function resolveGraphQLApis({\n cliConfig,\n workspaces,\n}: ResolveGraphQLApisOptions): TypeResolvedGraphQLAPI[] {\n const numSources = workspaces.reduce(\n (count, workspace) => count + workspace.unstable_sources.length,\n 0,\n )\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId, schema} = workspaces[0].unstable_sources[0]\n return [{dataset, projectId, schemaTypes: getStrippedSchemaTypes(schema)}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLAPIsFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Resolve GraphQL API metadata (projectId, dataset, tag, etc.) from raw workspace configs\n * without compiling schemas. This is used when we only need API identifiers, not schema types —\n * e.g. for `graphql undeploy --api` or `graphql list`.\n */\nexport function resolveGraphQLApiMetadata({\n cliConfig,\n workspaces,\n}: {\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n workspaces: WorkspaceMetadata[]\n}): ExtractedGraphQLAPI[] {\n const numSources = workspaces.reduce((count, ws) => count + ws.sources.length, 0)\n const multiSource = numSources > 1\n const multiWorkspace = workspaces.length > 1\n const hasGraphQLConfig = Boolean(cliConfig?.graphql)\n\n if (workspaces.length === 0) {\n throw new Error('No studio configuration found')\n }\n\n if (numSources === 0) {\n throw new Error('No sources (project ID / dataset) configured')\n }\n\n // We can only automatically configure if there is a single workspace + source in play\n if ((multiWorkspace || multiSource) && !hasGraphQLConfig) {\n throw new Error(oneline`\n Multiple workspaces/sources configured.\n You must define an array of GraphQL APIs in \\`sanity.cli.ts\\` or \\`sanity.cli.js\\`\n and specify which workspace/source to use.\n `)\n }\n\n // Validate that workspaces and their sources have non-empty projectId/dataset.\n // The worker's toWorkspaceMetadata validates this before constructing metadata,\n // but assert here to make the invariant explicit.\n for (const ws of workspaces) {\n if (!ws.projectId || !ws.dataset) {\n throw new Error(\n `Workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n for (const source of ws.sources) {\n if (!source.projectId || !source.dataset) {\n throw new Error(\n `Source \"${source.name}\" in workspace \"${ws.name}\" is missing a projectId or dataset. ` +\n 'Check your studio configuration.',\n )\n }\n }\n }\n\n // No config is defined, but we have a single workspace + source, so use that\n if (!hasGraphQLConfig) {\n const {dataset, projectId} = workspaces[0].sources[0]\n return [{dataset, projectId}]\n }\n\n // Explicitly defined config\n const apiDefs = validateCliConfig(cliConfig?.graphql || [])\n return resolveGraphQLApiMetadataFromConfig(apiDefs, workspaces)\n}\n\n/**\n * Shared workspace/source resolution logic for both the metadata and full-compile paths.\n *\n * Both `resolveGraphQLAPIsFromConfig` and `resolveGraphQLApiMetadataFromConfig` need to\n * resolve the workspace and source for each GraphQL API config entry. This helper\n * extracts that shared logic so bug fixes and edge-case handling apply to both paths.\n */\nfunction resolveWorkspaceAndSource<\n TWorkspace extends {name: string},\n TSource extends {name: string},\n>(\n apiDef: GraphQLAPIConfig,\n workspaces: TWorkspace[],\n getSources: (workspace: TWorkspace) => TSource[],\n): {source: TSource; workspace: TWorkspace} {\n const {source: sourceName, workspace: workspaceName} = apiDef\n\n if (!workspaceName && workspaces.length > 1) {\n throw new Error(\n 'Must define `workspace` name in GraphQL API config when multiple workspaces are defined',\n )\n }\n\n // If we only have a single workspace defined, we can assume that is the intended one,\n // even if no `workspace` is defined for the GraphQL API\n const workspace =\n !workspaceName && workspaces.length === 1\n ? workspaces[0]\n : workspaces.find((space) => space.name === (workspaceName || 'default'))\n\n if (!workspace) {\n throw new Error(`Workspace \"${workspaceName || 'default'}\" not found`)\n }\n\n const sources = getSources(workspace)\n\n // If we only have a single source defined, we can assume that is the intended one,\n // even if no `source` is defined for the GraphQL API\n const source =\n !sourceName && sources.length === 1\n ? sources[0]\n : sources.find((src) => src.name === (sourceName || 'default'))\n\n if (!source) {\n throw new Error(\n `Source \"${sourceName || 'default'}\" not found in workspace \"${workspaceName || 'default'}\"`,\n )\n }\n\n return {source, workspace}\n}\n\nfunction resolveGraphQLApiMetadataFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: WorkspaceMetadata[],\n): ExtractedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.sources)\n\n return {\n dataset: source.dataset,\n filterSuffix: apiDef.filterSuffix,\n generation: apiDef.generation,\n id: apiDef.id,\n nonNullDocumentFields: apiDef.nonNullDocumentFields,\n playground: apiDef.playground,\n projectId: source.projectId,\n tag: apiDef.tag,\n }\n })\n}\n\nfunction resolveGraphQLAPIsFromConfig(\n apiDefs: GraphQLAPIConfig[],\n workspaces: Workspace[],\n): TypeResolvedGraphQLAPI[] {\n return apiDefs.map((apiDef) => {\n const {source} = resolveWorkspaceAndSource(apiDef, workspaces, (ws) => ws.unstable_sources)\n\n return {\n ...apiDef,\n dataset: source.dataset,\n projectId: source.projectId,\n schemaTypes: getStrippedSchemaTypes(source.schema),\n }\n })\n}\n\nfunction validateCliConfig(\n config: GraphQLAPIConfig[],\n configPath = 'sanity.cli.js',\n): GraphQLAPIConfig[] {\n if (!Array.isArray(config)) {\n throw new TypeError(`\"graphql\" key in \"${configPath}\" must be an array if defined`)\n }\n\n if (config.length === 0) {\n throw new Error(`No GraphQL APIs defined in \"${configPath}\"`)\n }\n\n return config\n}\n\nfunction getStrippedSchemaTypes(schema: Schema): SchemaDefinitionish[] {\n const schemaDef = schema._original || {types: []}\n return schemaDef.types.map((type) => stripType(type))\n}\n\nfunction stripType(input: unknown): SchemaDefinitionish {\n return strip(input) as SchemaDefinitionish\n}\n\nfunction strip(input: unknown): unknown {\n if (Array.isArray(input)) {\n return input.map((item) => strip(item)).filter((item) => item !== undefined)\n }\n\n if (isPlainishObject(input)) {\n const stripped: Record<string, unknown> = {}\n for (const key of Object.keys(input)) {\n stripped[key] = strip(input[key])\n }\n return stripped\n }\n\n return isBasicType(input) ? input : undefined\n}\n\nfunction isPlainishObject(input: unknown): input is Record<string, unknown> {\n return isPlainObject(input)\n}\n\nfunction isBasicType(input: unknown): boolean {\n const type = typeof input\n if (type === 'boolean' || type === 'number' || type === 'string') {\n return true\n }\n\n if (type !== 'object') {\n return false\n }\n\n return Array.isArray(input) || input === null || isPlainishObject(input)\n}\n"],"names":["isPlainObject","oneline","resolveGraphQLApis","cliConfig","workspaces","numSources","reduce","count","workspace","unstable_sources","length","multiSource","multiWorkspace","hasGraphQLConfig","Boolean","graphql","Error","dataset","projectId","schema","schemaTypes","getStrippedSchemaTypes","apiDefs","validateCliConfig","resolveGraphQLAPIsFromConfig","resolveGraphQLApiMetadata","ws","sources","name","source","resolveGraphQLApiMetadataFromConfig","resolveWorkspaceAndSource","apiDef","getSources","sourceName","workspaceName","find","space","src","map","filterSuffix","generation","id","nonNullDocumentFields","playground","tag","config","configPath","Array","isArray","TypeError","schemaDef","_original","types","type","stripType","input","strip","item","filter","undefined","isPlainishObject","stripped","key","Object","keys","isBasicType"],"mappings":"AACA,OAAOA,mBAAmB,6BAA4B;AACtD,SAAQC,OAAO,QAAO,UAAS;AAkD/B,OAAO,SAASC,mBAAmB,EACjCC,SAAS,EACTC,UAAU,EACgB;IAC1B,MAAMC,aAAaD,WAAWE,MAAM,CAClC,CAACC,OAAOC,YAAcD,QAAQC,UAAUC,gBAAgB,CAACC,MAAM,EAC/D;IAEF,MAAMC,cAAcN,aAAa;IACjC,MAAMO,iBAAiBR,WAAWM,MAAM,GAAG;IAC3C,MAAMG,mBAAmBC,QAAQX,WAAWY;IAE5C,IAAIX,WAAWM,MAAM,KAAK,GAAG;QAC3B,MAAM,IAAIM,MAAM;IAClB;IAE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ACpF;IAEA,IAAID,OAAOpC,MAAM,KAAK,GAAG;QACvB,MAAM,IAAIM,MAAM,CAAC,4BAA4B,EAAE+B,WAAW,CAAC,CAAC;IAC9D;IAEA,OAAOD;AACT;AAEA,SAASzB,uBAAuBF,MAAc;IAC5C,MAAMgC,YAAYhC,OAAOiC,SAAS,IAAI;QAACC,OAAO,EAAE;IAAA;IAChD,OAAOF,UAAUE,KAAK,CAACd,GAAG,CAAC,CAACe,OAASC,UAAUD;AACjD;AAEA,SAASC,UAAUC,KAAc;IAC/B,OAAOC,MAAMD;AACf;AAEA,SAASC,MAAMD,KAAc;IAC3B,IAAIR,MAAMC,OAAO,CAACO,QAAQ;QACxB,OAAOA,MAAMjB,GAAG,CAAC,CAACmB,OAASD,MAAMC,OAAOC,MAAM,CAAC,CAACD,OAASA,SAASE;IACpE;IAEA,IAAIC,iBAAiBL,QAAQ;QAC3B,MAAMM,WAAoC,CAAC;QAC3C,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACT,OAAQ;YACpCM,QAAQ,CAACC,IAAI,GAAGN,MAAMD,KAAK,CAACO,IAAI;QAClC;QACA,OAAOD;IACT;IAEA,OAAOI,YAAYV,SAASA,QAAQI;AACtC;AAEA,SAASC,iBAAiBL,KAAc;IACtC,OAAOxD,cAAcwD;AACvB;AAEA,SAASU,YAAYV,KAAc;IACjC,MAAMF,OAAO,OAAOE;IACpB,IAAIF,SAAS,aAAaA,SAAS,YAAYA,SAAS,UAAU;QAChE,OAAO;IACT;IAEA,IAAIA,SAAS,UAAU;QACrB,OAAO;IACT;IAEA,OAAON,MAAMC,OAAO,CAACO,UAAUA,UAAU,QAAQK,iBAAiBL;AACpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/graphql/types.ts"],"sourcesContent":["import {type
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/graphql/types.ts"],"sourcesContent":["import {type SchemaValidationProblemGroup} from '@sanity/types'\n\nexport interface Deprecation {\n deprecationReason: string\n}\n\nexport interface ApiSpecification {\n interfaces: ConvertedInterface[]\n types: (ConvertedType | ConvertedUnion)[]\n}\n\n/**\n * @public\n */\nexport interface GraphQLAPIConfig {\n /**\n * Suffix to use for generated filter types.\n *\n * Optional, Defaults to `Filter`.\n *\n */\n filterSuffix?: string\n\n /**\n * Generation of API to deploy\n *\n * Optional, defaults to `gen3` (which is the only option, currently)\n */\n generation?: 'gen1' | 'gen2' | 'gen3'\n\n /**\n * ID of GraphQL API. Only (currently) required when using the `--api` flag\n * for `sanity graphql deploy`, in order to only deploy a specific API.\n */\n id?: string\n\n /**\n * Whether or not to enable the GraphQL v2021-10-21 query semantics\n */\n nonNullDocumentFields?: boolean\n\n /**\n * Whether or not to enable the GraphQL Playground for this API\n *\n * Optional, defaults to `true` in development mode, `false` otherwise\n */\n playground?: boolean\n\n /**\n * Name of source containing the schema to deploy, within the configured workspace\n *\n * Optional, defaults to `default` (eg the one used if no `name` is defined)\n */\n source?: string\n\n /**\n * API tag for this API - allows deploying multiple different APIs to a single dataset\n *\n * Optional, defaults to `default`\n */\n tag?: string\n\n /**\n * Name of workspace containing the schema to deploy\n *\n * Optional, defaults to `default` (eg the one used if no `name` is defined)\n */\n workspace?: string\n}\n\nexport interface DeployResponse {\n location: string\n}\n\ninterface ApiChange {\n description: string\n type: string\n}\n\nexport interface ValidationResponse {\n breakingChanges: ApiChange[]\n dangerousChanges: ApiChange[]\n validationError: string\n}\n\nexport interface SchemaDefinitionish {\n name: string\n type: string\n\n fields?: SchemaDefinitionish[]\n}\n\ninterface ResolvedSerializableProperties {\n dataset: string\n projectId: string\n schemaTypes: SchemaDefinitionish[]\n}\n\nexport type TypeResolvedGraphQLAPI = Omit<GraphQLAPIConfig, 'source' | 'workspace'> &\n ResolvedSerializableProperties\n\nexport interface ExtractedGraphQLAPI {\n dataset: string\n projectId: string\n\n extracted?: ApiSpecification\n extractionError?: string\n filterSuffix?: string\n generation?: string\n id?: string\n nonNullDocumentFields?: boolean\n playground?: boolean\n schemaErrors?: SchemaValidationProblemGroup[]\n tag?: string\n}\n\nexport interface GraphQLWorkerResult {\n apis: ExtractedGraphQLAPI[]\n\n configErrors?: SchemaValidationProblemGroup[]\n}\n\ninterface ConvertedNode {\n description: string\n fields: ConvertedFieldDefinition[]\n kind: 'Interface' | 'List' | 'Type' | 'Union'\n name: string\n type: string\n}\n\ntype FieldArg =\n | {isFieldFilter?: boolean; name: string; type: string}\n | {name: string; type: ConvertedNode}\n\nexport interface ConvertedField extends Partial<Deprecation> {\n fieldName: string\n type: string\n\n args?: FieldArg[]\n description?: string\n filter?: string\n isNullable?: boolean\n isRawAlias?: boolean\n isReference?: boolean\n kind?: 'List'\n originalName?: string\n}\n\ninterface ConvertedListField extends ConvertedField {\n children: {\n inlineObjects?: string[]\n type: string\n }\n kind: 'List'\n}\n\nexport interface ApiCustomizationOptions {\n filterSuffix?: string\n}\n\nexport type InputFilterField =\n | ListDefinition\n | {\n constraint: {\n comparator: string\n field?: string\n }\n description?: string\n fieldName: string\n type: string\n }\n\nexport type ConvertedFieldDefinition = ConvertedField | ConvertedListField\n\ninterface ListDefinition {\n children: {isNullable?: boolean; type: string}\n kind: 'List'\n\n isNullable?: boolean\n}\n\nexport interface ConvertedEnum {\n kind: 'Enum'\n name: string\n values: {\n description?: string\n name: string\n value: unknown\n }[]\n}\n\nexport interface ConvertedInterface {\n fields: ConvertedFieldDefinition[]\n kind: 'Interface'\n name: string\n\n description?: string\n}\n\nexport interface ConvertedUnion {\n kind: 'Union'\n name: string\n types: string[]\n\n interfaces?: string[]\n}\n\nexport interface ConvertedDocumentType extends ConvertedType {\n interfaces: ['Document', ...string[]]\n}\n\nexport interface ConvertedType extends Partial<Deprecation> {\n fields: ConvertedFieldDefinition[]\n kind: 'Interface' | 'Type'\n name: string\n type: string\n\n _internal?: Partial<Deprecation>\n crossDatasetReferenceMetadata?: {\n dataset: string\n typeNames: string[]\n }\n description?: string\n interfaces?: string[]\n isReference?: boolean\n originalName?: string\n}\n\nexport interface InputObjectType {\n fields: unknown[] // @todo\n kind: 'InputObject'\n name: string\n\n isConstraintFilter?: boolean\n}\n\nexport interface QueryDefinition extends Partial<Deprecation> {\n args: {\n description?: string\n isFieldFilter?: boolean\n isNullable?: boolean\n name: string\n type: ListDefinition | string\n }[]\n fieldName: string\n\n type: ListDefinition | string\n\n constraints?: {\n comparator: string\n field?: string\n value?: {argName: string; kind: 'argumentValue'}\n }[]\n\n filter?: string\n}\n\nexport interface GeneratedApiSpecification {\n generation: string\n interfaces: ConvertedInterface[]\n queries: QueryDefinition[]\n types: (ConvertedEnum | ConvertedType | ConvertedUnion | InputObjectType)[]\n}\n"],"names":[],"mappings":"AAiQA,WAKC"}
|
|
@@ -81,7 +81,8 @@ export async function bootstrapLocalTemplate(opts) {
|
|
|
81
81
|
devDependencies,
|
|
82
82
|
isAppTemplate,
|
|
83
83
|
name: packageJsonName,
|
|
84
|
-
scripts: template.scripts
|
|
84
|
+
scripts: template.scripts,
|
|
85
|
+
type: template.type
|
|
85
86
|
});
|
|
86
87
|
// ...and a studio config (`sanity.config.[ts|js]`)
|
|
87
88
|
const studioConfig = createStudioConfig({
|