@sanity/cli 6.0.0-alpha.9 → 6.0.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/README.md +602 -258
- package/bin/run.js +2 -0
- package/dist/SanityHelp.js +51 -23
- package/dist/SanityHelp.js.map +1 -1
- package/dist/actions/auth/authServer.js +28 -22
- package/dist/actions/auth/authServer.js.map +1 -1
- package/dist/actions/auth/login/getProvider.js +49 -38
- 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/backup/downloadAsset.js +9 -9
- package/dist/actions/backup/downloadAsset.js.map +1 -1
- package/dist/actions/backup/downloadDocument.js +8 -8
- package/dist/actions/backup/downloadDocument.js.map +1 -1
- package/dist/actions/build/buildApp.js +55 -18
- package/dist/actions/build/buildApp.js.map +1 -1
- package/dist/actions/build/buildStaticFiles.js +3 -2
- package/dist/actions/build/buildStaticFiles.js.map +1 -1
- package/dist/actions/build/buildStudio.js +72 -44
- package/dist/actions/build/buildStudio.js.map +1 -1
- package/dist/actions/build/buildVendorDependencies.js +18 -52
- package/dist/actions/build/buildVendorDependencies.js.map +1 -1
- package/dist/actions/build/checkRequiredDependencies.js +13 -8
- package/dist/actions/build/checkRequiredDependencies.js.map +1 -1
- package/dist/actions/build/checkStudioDependencyVersions.js +19 -17
- package/dist/actions/build/checkStudioDependencyVersions.js.map +1 -1
- package/dist/actions/build/createExternalFromImportMap.js +1 -1
- package/dist/actions/build/createExternalFromImportMap.js.map +1 -1
- package/dist/actions/build/determineBasePath.js +5 -2
- package/dist/actions/build/determineBasePath.js.map +1 -1
- package/dist/actions/build/getViteConfig.js +47 -4
- package/dist/actions/build/getViteConfig.js.map +1 -1
- package/dist/actions/build/handlePrereleaseVersions.js +44 -0
- package/dist/actions/build/handlePrereleaseVersions.js.map +1 -0
- package/dist/actions/build/renderDocument.js +6 -10
- package/dist/actions/build/renderDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js +4 -4
- package/dist/actions/build/renderDocumentWorker/components/BasicDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js +3 -3
- package/dist/actions/build/renderDocumentWorker/components/DefaultDocument.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js +1 -0
- package/dist/actions/build/renderDocumentWorker/components/GlobalErrorHandler.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js +2 -2
- package/dist/actions/build/renderDocumentWorker/getDocumentComponent.js.map +1 -1
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js +1 -1
- package/dist/actions/build/renderDocumentWorker/renderDocumentWorker.js.map +1 -1
- package/dist/actions/build/shouldAutoUpdate.js +2 -0
- package/dist/actions/build/shouldAutoUpdate.js.map +1 -1
- package/dist/actions/build/types.js.map +1 -1
- package/dist/actions/build/writeFavicons.js +3 -5
- package/dist/actions/build/writeFavicons.js.map +1 -1
- package/dist/actions/build/writeSanityRuntime.js +4 -3
- package/dist/actions/build/writeSanityRuntime.js.map +1 -1
- package/dist/actions/codemods/reactIconsV3.js +2 -2
- package/dist/actions/codemods/reactIconsV3.js.map +1 -1
- package/dist/actions/dataset/create.js +7 -1
- package/dist/actions/dataset/create.js.map +1 -1
- package/dist/actions/dataset/determineDatasetAclMode.js.map +1 -1
- package/dist/actions/dataset/resolveDataset.js +26 -0
- package/dist/actions/dataset/resolveDataset.js.map +1 -0
- package/dist/actions/debug/formatters.js +22 -0
- package/dist/actions/debug/formatters.js.map +1 -0
- package/dist/actions/deploy/createStudioUserApplication.js +17 -4
- package/dist/actions/deploy/createStudioUserApplication.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +41 -15
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/deploy/deployStudio.js +92 -44
- package/dist/actions/deploy/deployStudio.js.map +1 -1
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js +55 -0
- package/dist/actions/deploy/deployStudioSchemasAndManifests.js.map +1 -0
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js +120 -0
- package/dist/actions/deploy/deployStudioSchemasAndManifests.worker.js.map +1 -0
- package/dist/actions/deploy/findUserApplicationForStudio.js +35 -12
- package/dist/actions/deploy/findUserApplicationForStudio.js.map +1 -1
- package/dist/actions/deploy/types.js +10 -1
- package/dist/actions/deploy/types.js.map +1 -1
- package/dist/actions/deploy/urlUtils.js +21 -0
- package/dist/actions/deploy/urlUtils.js.map +1 -0
- package/dist/actions/dev/getDashboardAppUrl.js +48 -0
- package/dist/actions/dev/getDashboardAppUrl.js.map +1 -0
- package/dist/actions/dev/getDevServerConfig.js +7 -3
- package/dist/actions/dev/getDevServerConfig.js.map +1 -1
- package/dist/actions/dev/startAppDevServer.js +3 -3
- package/dist/actions/dev/startAppDevServer.js.map +1 -1
- package/dist/actions/dev/startStudioDevServer.js +14 -14
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/doctor/checks/cliInstallation.js +56 -0
- package/dist/actions/doctor/checks/cliInstallation.js.map +1 -0
- package/dist/actions/doctor/checks/index.js +16 -0
- package/dist/actions/doctor/checks/index.js.map +1 -0
- package/dist/actions/doctor/runDoctorChecks.js +56 -0
- package/dist/actions/doctor/runDoctorChecks.js.map +1 -0
- package/dist/actions/doctor/types.js +3 -0
- package/dist/actions/doctor/types.js.map +1 -0
- package/dist/actions/documents/types.js.map +1 -1
- package/dist/actions/documents/validate.js +11 -2
- package/dist/actions/documents/validate.js.map +1 -1
- package/dist/actions/documents/validateDocuments.worker.js +4 -4
- package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
- package/dist/actions/documents/validation/reporters/jsonReporter.js +1 -1
- package/dist/actions/documents/validation/reporters/jsonReporter.js.map +1 -1
- package/dist/actions/documents/validation/reporters/ndjsonReporter.js +1 -1
- package/dist/actions/documents/validation/reporters/ndjsonReporter.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/__tests__/fixtures/many-self-refs.js +540 -0
- package/dist/actions/graphql/__tests__/fixtures/many-self-refs.js.map +1 -0
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js +1143 -0
- package/dist/actions/graphql/__tests__/fixtures/test-studio.js.map +1 -0
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js +591 -0
- package/dist/actions/graphql/__tests__/fixtures/union-refs.js.map +1 -0
- package/dist/actions/graphql/__tests__/helpers.js +23 -0
- package/dist/actions/graphql/__tests__/helpers.js.map +1 -0
- package/dist/actions/graphql/extractFromSanitySchema.js +5 -5
- 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/generateTypeFilters.js +1 -1
- package/dist/actions/graphql/gen1/generateTypeFilters.js.map +1 -1
- package/dist/actions/graphql/gen1/generateTypeQueries.js +2 -1
- package/dist/actions/graphql/gen1/generateTypeQueries.js.map +1 -1
- package/dist/actions/graphql/gen1/index.js +5 -5
- package/dist/actions/graphql/gen1/index.js.map +1 -1
- package/dist/actions/graphql/gen2/generateTypeQueries.js +1 -1
- package/dist/actions/graphql/gen2/generateTypeQueries.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 +3 -4
- 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 +15 -57
- 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 +10 -8
- 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/bootstrapTemplate.js.map +1 -1
- package/dist/actions/init/checkNextJsReactCompatibility.js +1 -1
- package/dist/actions/init/checkNextJsReactCompatibility.js.map +1 -1
- package/dist/actions/init/createAppCliConfig.js.map +1 -1
- package/dist/actions/init/createCliConfig.js.map +1 -1
- package/dist/actions/init/createPackageManifest.js +21 -9
- package/dist/actions/init/createPackageManifest.js.map +1 -1
- package/dist/actions/init/remoteTemplate.js +1 -2
- package/dist/actions/init/remoteTemplate.js.map +1 -1
- package/dist/actions/init/sdkAppDependencies.js +19 -0
- package/dist/actions/init/sdkAppDependencies.js.map +1 -0
- package/dist/actions/init/studioDependencies.js.map +1 -0
- package/dist/actions/init/templates/appQuickstart.js +1 -22
- package/dist/actions/init/templates/appQuickstart.js.map +1 -1
- package/dist/actions/init/templates/appSanityUi.js +3 -22
- package/dist/actions/init/templates/appSanityUi.js.map +1 -1
- package/dist/actions/init/types.js.map +1 -1
- package/dist/actions/manifest/SchemaIcon.js +6 -4
- package/dist/actions/manifest/SchemaIcon.js.map +1 -1
- package/dist/actions/manifest/blockTypeTransformer.js +67 -0
- package/dist/actions/manifest/blockTypeTransformer.js.map +1 -0
- package/dist/actions/manifest/debug.js +4 -0
- package/dist/actions/manifest/debug.js.map +1 -0
- package/dist/actions/manifest/extractAppManifest.js +39 -22
- package/dist/actions/manifest/extractAppManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +27 -78
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/extractManifest.worker.js +30 -0
- package/dist/actions/manifest/extractManifest.worker.js.map +1 -0
- package/dist/actions/manifest/extractWorkspaceManifest.js +31 -372
- package/dist/actions/manifest/extractWorkspaceManifest.js.map +1 -1
- package/dist/actions/manifest/iconResolver.js +30 -0
- package/dist/actions/manifest/iconResolver.js.map +1 -0
- package/dist/actions/manifest/referenceTransformer.js +51 -0
- package/dist/actions/manifest/referenceTransformer.js.map +1 -0
- package/dist/actions/manifest/schemaTypeHelpers.js +2 -2
- package/dist/actions/manifest/schemaTypeHelpers.js.map +1 -1
- package/dist/actions/manifest/schemaTypeTransformer.js +168 -0
- package/dist/actions/manifest/schemaTypeTransformer.js.map +1 -0
- package/dist/actions/manifest/transformerUtils.js +40 -0
- package/dist/actions/manifest/transformerUtils.js.map +1 -0
- package/dist/actions/manifest/types.js +5 -0
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/manifest/validationTransformer.js +84 -0
- package/dist/actions/manifest/validationTransformer.js.map +1 -0
- package/dist/actions/manifest/writeManifestFile.js +30 -0
- package/dist/actions/manifest/writeManifestFile.js.map +1 -0
- package/dist/actions/manifest/writeWorkspaceFiles.js +30 -0
- package/dist/actions/manifest/writeWorkspaceFiles.js.map +1 -0
- package/dist/actions/mcp/detectAvailableEditors.js +16 -4
- package/dist/actions/mcp/detectAvailableEditors.js.map +1 -1
- package/dist/actions/mcp/editorConfigs.js +64 -6
- package/dist/actions/mcp/editorConfigs.js.map +1 -1
- package/dist/actions/mcp/setupMCP.js.map +1 -1
- package/dist/actions/mcp/writeMCPConfig.js +27 -15
- package/dist/actions/mcp/writeMCPConfig.js.map +1 -1
- package/dist/actions/media/buildNdjsonIndex.js +32 -0
- package/dist/actions/media/buildNdjsonIndex.js.map +1 -0
- package/dist/actions/media/importAspects.js +2 -11
- package/dist/actions/media/importAspects.js.map +1 -1
- package/dist/actions/media/importMedia.js +22 -18
- package/dist/actions/media/importMedia.js.map +1 -1
- package/dist/actions/organizations/findOrganizationByUserName.js +5 -0
- package/dist/actions/organizations/findOrganizationByUserName.js.map +1 -0
- package/dist/actions/organizations/getOrganization.js +3 -2
- package/dist/actions/organizations/getOrganization.js.map +1 -1
- package/dist/actions/organizations/getOrganizationChoices.js +27 -19
- package/dist/actions/organizations/getOrganizationChoices.js.map +1 -1
- package/dist/actions/organizations/types.js +3 -0
- package/dist/actions/organizations/types.js.map +1 -0
- package/dist/actions/projects/getManageUrl.js +1 -2
- package/dist/actions/projects/getManageUrl.js.map +1 -1
- package/dist/actions/schema/deleteSchemaAction.js +14 -30
- package/dist/actions/schema/deleteSchemaAction.js.map +1 -1
- package/dist/actions/schema/deploySchemas.js +22 -91
- package/dist/actions/schema/deploySchemas.js.map +1 -1
- package/dist/actions/schema/extractSanitySchema.worker.js +0 -5
- package/dist/actions/schema/extractSanitySchema.worker.js.map +1 -1
- package/dist/actions/schema/extractSanityWorkspace.worker.js +24 -0
- package/dist/actions/schema/extractSanityWorkspace.worker.js.map +1 -0
- package/dist/actions/schema/extractSchema.js +8 -40
- package/dist/actions/schema/extractSchema.js.map +1 -1
- package/dist/actions/schema/extractSchemaWatcher.js +128 -0
- package/dist/actions/schema/extractSchemaWatcher.js.map +1 -0
- package/dist/actions/schema/formatSchemaValidation.js +5 -1
- package/dist/actions/schema/formatSchemaValidation.js.map +1 -1
- package/dist/actions/schema/getExtractOptions.js +16 -0
- package/dist/actions/schema/getExtractOptions.js.map +1 -0
- package/dist/actions/schema/listSchemas.js +53 -56
- package/dist/actions/schema/listSchemas.js.map +1 -1
- package/dist/actions/schema/matchSchemaPattern.js +22 -0
- package/dist/actions/schema/matchSchemaPattern.js.map +1 -0
- package/dist/actions/schema/runSchemaExtraction.js +39 -0
- package/dist/actions/schema/runSchemaExtraction.js.map +1 -0
- package/dist/actions/schema/types.js +8 -0
- package/dist/actions/schema/types.js.map +1 -1
- package/dist/actions/schema/uniqueWorkspaces.worker.js +24 -0
- package/dist/actions/schema/uniqueWorkspaces.worker.js.map +1 -0
- package/dist/actions/schema/updateWorkspaceSchema.js +63 -0
- package/dist/actions/schema/updateWorkspaceSchema.js.map +1 -0
- package/dist/actions/schema/uploadSchemaToLexicon.js +87 -0
- package/dist/actions/schema/uploadSchemaToLexicon.js.map +1 -0
- package/dist/actions/schema/utils/SchemaExtractionError.js +10 -0
- package/dist/actions/schema/utils/SchemaExtractionError.js.map +1 -0
- package/dist/actions/schema/utils/schemaStoreValidation.js +1 -15
- package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js.map +1 -1
- package/dist/actions/schema/validateSchema.worker.js +1 -8
- package/dist/actions/schema/validateSchema.worker.js.map +1 -1
- package/dist/actions/schema/watchExtractSchema.js +72 -0
- package/dist/actions/schema/watchExtractSchema.js.map +1 -0
- 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/users/getMembersForProject.js.map +1 -1
- package/dist/actions/users/getPendingInvitations.js +1 -1
- package/dist/actions/users/getPendingInvitations.js.map +1 -1
- package/dist/actions/users/types.js.map +1 -1
- package/dist/actions/versions/filterSanityModules.js.map +1 -1
- package/dist/actions/versions/findSanityModulesVersions.js +2 -3
- package/dist/actions/versions/findSanityModulesVersions.js.map +1 -1
- package/dist/actions/versions/getFormatters.js +1 -1
- package/dist/actions/versions/getFormatters.js.map +1 -1
- package/dist/actions/versions/tryFindLatestVersion.js +1 -1
- package/dist/actions/versions/tryFindLatestVersion.js.map +1 -1
- package/dist/commands/backup/disable.js +22 -7
- package/dist/commands/backup/disable.js.map +1 -1
- package/dist/commands/backup/download.js +19 -10
- package/dist/commands/backup/download.js.map +1 -1
- package/dist/commands/backup/enable.js +22 -7
- package/dist/commands/backup/enable.js.map +1 -1
- package/dist/commands/backup/list.js +20 -8
- package/dist/commands/backup/list.js.map +1 -1
- package/dist/commands/build.js +2 -5
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/cors/add.js +20 -7
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +22 -7
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +22 -7
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/dataset/alias/create.js +26 -7
- package/dist/commands/dataset/alias/create.js.map +1 -1
- package/dist/commands/dataset/alias/delete.js +20 -7
- package/dist/commands/dataset/alias/delete.js.map +1 -1
- package/dist/commands/dataset/alias/link.js +20 -7
- package/dist/commands/dataset/alias/link.js.map +1 -1
- package/dist/commands/dataset/alias/unlink.js +20 -7
- package/dist/commands/dataset/alias/unlink.js.map +1 -1
- package/dist/commands/dataset/copy.js +45 -30
- package/dist/commands/dataset/copy.js.map +1 -1
- package/dist/commands/dataset/create.js +32 -7
- package/dist/commands/dataset/create.js.map +1 -1
- package/dist/commands/dataset/delete.js +16 -7
- package/dist/commands/dataset/delete.js.map +1 -1
- package/dist/commands/dataset/embeddings/disable.js +77 -0
- package/dist/commands/dataset/embeddings/disable.js.map +1 -0
- package/dist/commands/dataset/embeddings/enable.js +141 -0
- package/dist/commands/dataset/embeddings/enable.js.map +1 -0
- package/dist/commands/dataset/embeddings/status.js +72 -0
- package/dist/commands/dataset/embeddings/status.js.map +1 -0
- package/dist/commands/dataset/export.js +25 -16
- package/dist/commands/dataset/export.js.map +1 -1
- package/dist/commands/dataset/import.js +306 -1
- package/dist/commands/dataset/import.js.map +1 -1
- package/dist/commands/dataset/list.js +22 -7
- package/dist/commands/dataset/list.js.map +1 -1
- package/dist/commands/dataset/visibility/get.js +18 -7
- package/dist/commands/dataset/visibility/get.js.map +1 -1
- package/dist/commands/dataset/visibility/set.js +22 -7
- package/dist/commands/dataset/visibility/set.js.map +1 -1
- package/dist/commands/debug.js +4 -2
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/deploy.js +22 -11
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +2 -4
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.js +125 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/documents/create.js +19 -12
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +19 -12
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +17 -12
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +26 -18
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +32 -10
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/deploy.js +58 -30
- package/dist/commands/graphql/deploy.js.map +1 -1
- package/dist/commands/graphql/list.js +15 -7
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +37 -19
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hook/attempt.js +22 -7
- package/dist/commands/hook/attempt.js.map +1 -1
- package/dist/commands/hook/create.js +23 -8
- package/dist/commands/hook/create.js.map +1 -1
- package/dist/commands/hook/delete.js +22 -7
- package/dist/commands/hook/delete.js.map +1 -1
- package/dist/commands/hook/list.js +22 -7
- package/dist/commands/hook/list.js.map +1 -1
- package/dist/commands/hook/logs.js +21 -8
- package/dist/commands/hook/logs.js.map +1 -1
- package/dist/commands/init.js +46 -28
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +19 -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/manage.js +0 -1
- package/dist/commands/manage.js.map +1 -1
- package/dist/commands/manifest/extract.js +14 -10
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/commands/mcp/configure.js +1 -1
- package/dist/commands/mcp/configure.js.map +1 -1
- package/dist/commands/media/create-aspect.js +4 -4
- package/dist/commands/media/create-aspect.js.map +1 -1
- package/dist/commands/media/delete-aspect.js +9 -7
- package/dist/commands/media/delete-aspect.js.map +1 -1
- package/dist/commands/media/deploy-aspect.js +22 -9
- package/dist/commands/media/deploy-aspect.js.map +1 -1
- package/dist/commands/media/export.js +9 -7
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +10 -8
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/preview.js +2 -4
- package/dist/commands/preview.js.map +1 -1
- package/dist/commands/projects/list.js +2 -1
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schema/delete.js +33 -34
- package/dist/commands/schema/delete.js.map +1 -1
- package/dist/commands/schema/deploy.js +19 -30
- package/dist/commands/schema/deploy.js.map +1 -1
- package/dist/commands/schema/extract.js +32 -4
- package/dist/commands/schema/extract.js.map +1 -1
- package/dist/commands/schema/list.js +10 -31
- package/dist/commands/schema/list.js.map +1 -1
- package/dist/commands/tokens/add.js +24 -7
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/commands/tokens/delete.js +20 -7
- package/dist/commands/tokens/delete.js.map +1 -1
- package/dist/commands/tokens/list.js +20 -7
- package/dist/commands/tokens/list.js.map +1 -1
- package/dist/commands/users/invite.js +24 -7
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/commands/users/list.js +76 -33
- package/dist/commands/users/list.js.map +1 -1
- package/dist/commands/versions.js +1 -1
- package/dist/commands/versions.js.map +1 -1
- package/dist/config/createCliConfig.js +1 -2
- package/dist/config/createCliConfig.js.map +1 -1
- package/dist/exports/_internal.d.ts +132 -0
- package/dist/exports/_internal.js +4 -0
- package/dist/exports/_internal.js.map +1 -0
- package/dist/exports/index.d.ts +113 -0
- package/dist/exports/index.js +6 -0
- package/dist/exports/index.js.map +1 -0
- package/dist/hooks/init/checkForUpdates.js +14 -0
- package/dist/hooks/init/checkForUpdates.js.map +1 -0
- 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 +9 -3
- package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
- package/dist/prompts/promptForProject.js +64 -0
- package/dist/prompts/promptForProject.js.map +1 -0
- package/dist/{actions/auth/login/promptProviders.js → prompts/promptForProviders.js} +3 -3
- package/dist/prompts/promptForProviders.js.map +1 -0
- package/dist/prompts/selectMediaLibrary.js +1 -1
- package/dist/prompts/selectMediaLibrary.js.map +1 -1
- package/dist/server/devServer.js +4 -2
- package/dist/server/devServer.js.map +1 -1
- package/dist/server/previewServer.js +2 -2
- package/dist/server/previewServer.js.map +1 -1
- package/dist/server/vite/plugin-schema-extraction.js +201 -0
- package/dist/server/vite/plugin-schema-extraction.js.map +1 -0
- package/dist/server/vite/plugin-typegen.js +217 -0
- package/dist/server/vite/plugin-typegen.js.map +1 -0
- package/dist/services/auth.js +42 -3
- package/dist/services/auth.js.map +1 -1
- package/dist/services/datasets.js +7 -5
- package/dist/services/datasets.js.map +1 -1
- package/dist/services/docs.js +2 -2
- package/dist/services/docs.js.map +1 -1
- package/dist/services/embeddings.js +25 -0
- package/dist/services/embeddings.js.map +1 -0
- package/dist/services/getUrlHeaders.js +7 -18
- package/dist/services/getUrlHeaders.js.map +1 -1
- package/dist/services/grants.js +13 -0
- package/dist/services/grants.js.map +1 -0
- package/dist/services/graphql.js +1 -1
- package/dist/services/graphql.js.map +1 -1
- package/dist/services/projects.js +4 -2
- package/dist/services/projects.js.map +1 -1
- package/dist/services/schemas.js +1 -1
- package/dist/services/schemas.js.map +1 -1
- package/dist/services/telemetry.js +2 -1
- package/dist/services/telemetry.js.map +1 -1
- package/dist/services/userApplications.js +21 -6
- package/dist/services/userApplications.js.map +1 -1
- package/dist/telemetry/extractSchema.telemetry.js +10 -0
- package/dist/telemetry/extractSchema.telemetry.js.map +1 -1
- package/dist/types/grants.js +3 -0
- package/dist/types/grants.js.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/dist/util/checkProjectPermissions.js +21 -0
- package/dist/util/checkProjectPermissions.js.map +1 -0
- package/dist/util/cliClient.js +5 -3
- package/dist/util/cliClient.js.map +1 -1
- package/dist/util/compareDependencyVersions.js +74 -38
- package/dist/util/compareDependencyVersions.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/errorMessages.js +0 -1
- package/dist/util/errorMessages.js.map +1 -1
- package/dist/util/extractDocumentsFromNdjsonOrTarball.js +1 -2
- package/dist/util/extractDocumentsFromNdjsonOrTarball.js.map +1 -1
- package/dist/util/getCliVersion.js +1 -1
- package/dist/util/getCliVersion.js.map +1 -1
- package/dist/util/getLocalPackageVersion.js +31 -23
- package/dist/util/getLocalPackageVersion.js.map +1 -1
- package/dist/util/getProjectDefaults.js.map +1 -1
- package/dist/util/getSharedServerConfig.js +1 -0
- package/dist/util/getSharedServerConfig.js.map +1 -1
- package/dist/util/getWorkspace.js +1 -1
- package/dist/util/getWorkspace.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/packageManager/getPeerDependencies.js +44 -0
- package/dist/util/packageManager/getPeerDependencies.js.map +1 -0
- package/dist/util/packageManager/installationInfo/analyzeIssues.js +225 -0
- package/dist/util/packageManager/installationInfo/analyzeIssues.js.map +1 -0
- package/dist/util/packageManager/installationInfo/commands.js +73 -0
- package/dist/util/packageManager/installationInfo/commands.js.map +1 -0
- package/dist/util/packageManager/installationInfo/detectCliInstallation.js +66 -0
- package/dist/util/packageManager/installationInfo/detectCliInstallation.js.map +1 -0
- package/dist/util/packageManager/installationInfo/detectGlobals.js +295 -0
- package/dist/util/packageManager/installationInfo/detectGlobals.js.map +1 -0
- package/dist/util/packageManager/installationInfo/detectPackages.js +190 -0
- package/dist/util/packageManager/installationInfo/detectPackages.js.map +1 -0
- package/dist/util/packageManager/installationInfo/detectWorkspace.js +192 -0
- package/dist/util/packageManager/installationInfo/detectWorkspace.js.map +1 -0
- package/dist/util/packageManager/installationInfo/index.js +4 -0
- package/dist/util/packageManager/installationInfo/index.js.map +1 -0
- package/dist/util/packageManager/installationInfo/readJsonFile.js +14 -0
- package/dist/util/packageManager/installationInfo/readJsonFile.js.map +1 -0
- package/dist/util/packageManager/installationInfo/resolveVersionRange.js +42 -0
- package/dist/util/packageManager/installationInfo/resolveVersionRange.js.map +1 -0
- package/dist/util/packageManager/installationInfo/types.js +3 -0
- package/dist/util/packageManager/installationInfo/types.js.map +1 -0
- package/dist/util/packageManager/packageManagerChoice.js +1 -20
- package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
- package/dist/util/packageManager/upgradePackages.js +4 -1
- package/dist/util/packageManager/upgradePackages.js.map +1 -1
- package/dist/util/promiseRaceWithTimeout.js +28 -0
- package/dist/util/promiseRaceWithTimeout.js.map +1 -0
- package/dist/util/readdirRecursive.js.map +1 -1
- package/dist/util/resolveLatestVersions.js +2 -2
- package/dist/util/resolveLatestVersions.js.map +1 -1
- package/dist/util/sharedFlags.js +54 -0
- package/dist/util/sharedFlags.js.map +1 -0
- 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/toForwardSlashes.js +8 -0
- package/dist/util/toForwardSlashes.js.map +1 -0
- package/dist/util/update/fetchLatestVersion.js +21 -0
- package/dist/util/update/fetchLatestVersion.js.map +1 -0
- package/dist/util/update/getUpdateCommand.js +20 -0
- package/dist/util/update/getUpdateCommand.js.map +1 -0
- package/dist/util/update/isInstalledUsingYarn.js +17 -0
- package/dist/util/update/isInstalledUsingYarn.js.map +1 -0
- package/dist/util/update/showNotificationUpdate.js +31 -0
- package/dist/util/update/showNotificationUpdate.js.map +1 -0
- package/dist/util/update/updateChecker.js +60 -0
- package/dist/util/update/updateChecker.js.map +1 -0
- package/dist/util/update/updateCheckerDebug.js +4 -0
- package/dist/util/update/updateCheckerDebug.js.map +1 -0
- package/oclif.config.js +1 -0
- package/oclif.manifest.json +900 -107
- package/package.json +72 -71
- package/static/favicons/apple-touch-icon.png +0 -0
- package/static/favicons/favicon-192.png +0 -0
- package/static/favicons/favicon-512.png +0 -0
- package/static/favicons/favicon-96.png +0 -0
- package/static/favicons/favicon.ico +0 -0
- package/static/favicons/favicon.svg +12 -0
- package/dist/actions/auth/login/promptProviders.js.map +0 -1
- package/dist/actions/dev/getCoreAppUrl.js +0 -10
- package/dist/actions/dev/getCoreAppUrl.js.map +0 -1
- package/dist/actions/schema/schemaStoreTypes.js +0 -19
- package/dist/actions/schema/schemaStoreTypes.js.map +0 -1
- package/dist/actions/schema/utils/manifestExtractor.js +0 -33
- package/dist/actions/schema/utils/manifestExtractor.js.map +0 -1
- package/dist/actions/schema/utils/manifestReader.js +0 -71
- package/dist/actions/schema/utils/manifestReader.js.map +0 -1
- package/dist/index.d.ts +0 -2326
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/studioDependencies.js.map +0 -1
- package/dist/typings/deepSortObject.d.js +0 -2
- package/dist/typings/deepSortObject.d.js.map +0 -1
- package/dist/util/findNdjsonEntry.js +0 -21
- package/dist/util/findNdjsonEntry.js.map +0 -1
- package/dist/util/importStudioConfig.js +0 -40
- package/dist/util/importStudioConfig.js.map +0 -1
- package/dist/util/readModuleVersion.js +0 -15
- package/dist/util/readModuleVersion.js.map +0 -1
- package/dist/util/readPackageJson.js +0 -44
- package/dist/util/readPackageJson.js.map +0 -1
- package/dist/util/readPackageManifest.js +0 -46
- package/dist/util/readPackageManifest.js.map +0 -1
- package/dist/util/uniqBy.js +0 -14
- package/dist/util/uniqBy.js.map +0 -1
- package/dist/util/workerChannels.js +0 -172
- package/dist/util/workerChannels.js.map +0 -1
- /package/dist/{studioDependencies.js → actions/init/studioDependencies.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/listSchemas.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type Output} from '@sanity/cli-core'\
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/listSchemas.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {type Output, studioWorkerTask} from '@sanity/cli-core'\nimport {logSymbols} from '@sanity/cli-core/ux'\nimport {Table} from 'console-table-printer'\nimport {type Workspace} from 'sanity'\n\nimport {getSchemas} from '../../services/schemas.js'\nimport {isDefined} from '../manifest/schemaTypeHelpers.js'\nimport {type StoredWorkspaceSchema} from '../manifest/types.js'\nimport {type UniqWorkspaceWorkerData} from './types.js'\nimport {getDatasetsOutString} from './utils/schemaStoreOutStrings.js'\nimport {SCHEMA_PERMISSION_HELP_TEXT} from './utils/schemaStoreValidation.js'\n\ninterface ListSchemasOptions {\n configPath: string\n json: boolean\n output: Output\n workDir: string\n\n id?: string\n}\n\nclass DatasetError extends Error {\n public dataset: string\n public projectId: string\n constructor(args: {dataset: string; options?: ErrorOptions; projectId: string}) {\n super((args.options?.cause as {message?: string})?.message, args.options)\n this.projectId = args.projectId\n this.dataset = args.dataset\n this.name = 'DatasetError'\n }\n}\n\nexport async function listSchemas(options: ListSchemasOptions): Promise<void> {\n const {configPath, id, json, output, workDir} = options\n\n const projectDatasets = await studioWorkerTask<(Workspace & {key: string})[]>(\n new URL('uniqueWorkspaces.worker.js', import.meta.url),\n {\n name: 'uniqueWorkspaces',\n studioRootPath: workDir,\n workerData: {configPath} satisfies UniqWorkspaceWorkerData,\n },\n )\n\n const schemas = await getDatasetSchemas(projectDatasets, id)\n const parsedSchemas = parseSchemas(schemas, output)\n\n if (parsedSchemas.length === 0) {\n const datasetString = getDatasetsOutString(projectDatasets.map((dataset) => dataset.dataset))\n\n throw new Error(\n id\n ? `Schema for id \"${id}\" not found in ${datasetString}`\n : `No schemas found in ${datasetString}`,\n )\n }\n\n if (json) {\n output.log(JSON.stringify(id ? parsedSchemas[0] : parsedSchemas, null, 2))\n } else {\n printSchemas({output, schemas: parsedSchemas, workspaces: projectDatasets})\n }\n}\n\nasync function getDatasetSchemas(projectDatasets: Workspace[], id?: string) {\n return Promise.allSettled(\n projectDatasets.map(async ({dataset, projectId}) => {\n try {\n return await getSchemas(dataset, projectId, id)\n } catch (error) {\n throw new DatasetError({dataset, options: {cause: error}, projectId})\n }\n }),\n )\n}\n\nfunction parseSchemas(schemas: PromiseSettledResult<StoredWorkspaceSchema[]>[], output: Output) {\n return schemas\n .map((schema) => {\n if (schema.status === 'fulfilled') return schema.value\n\n const error = schema.reason\n\n if (error instanceof DatasetError) {\n if (\n 'cause' in error &&\n error.cause &&\n typeof error.cause === 'object' &&\n 'statusCode' in error.cause &&\n error.cause.statusCode === 401\n ) {\n output.log(\n styleText(\n 'yellow',\n `${logSymbols.warning} ↳ No permissions to read schema from \"${error.dataset}\". ${\n SCHEMA_PERMISSION_HELP_TEXT\n }:\\n ${styleText('red', `${error.message}`)}`,\n ),\n )\n return []\n }\n\n output.log(\n styleText('red', `↳ Failed to fetch schema from \"${error.dataset}\":\\n ${error.message}`),\n )\n return []\n } else {\n //hubris inc: given the try-catch wrapping all the full promise \"this should never happen\"\n throw error\n }\n })\n .filter((schema) => isDefined(schema))\n .flat()\n}\n\nfunction printSchemas({\n output,\n schemas,\n workspaces,\n}: {\n output: Output\n schemas: StoredWorkspaceSchema[]\n workspaces: Workspace[]\n}) {\n const rows = schemas\n .toSorted((a, b) => -(a._createdAt || '').localeCompare(b._createdAt || ''))\n .map(({_createdAt: createdAt, _id: id, workspace}) => {\n const workspaceData = workspaces.find((w) => w.name === workspace.name)\n if (!workspaceData) return\n\n return {\n CreatedAt: createdAt,\n Dataset: workspaceData.dataset,\n Id: id,\n ProjectId: workspaceData.projectId,\n Workspace: workspace.name,\n }\n })\n .filter((schema) => isDefined(schema))\n\n const table = new Table({\n columns: [\n {alignment: 'left', name: 'Id'},\n {alignment: 'left', name: 'Workspace'},\n {alignment: 'left', name: 'Dataset'},\n {alignment: 'left', name: 'ProjectId'},\n {alignment: 'left', name: 'CreatedAt'},\n ],\n })\n\n table.addRows(rows)\n output.log(table.render())\n}\n"],"names":["styleText","studioWorkerTask","logSymbols","Table","getSchemas","isDefined","getDatasetsOutString","SCHEMA_PERMISSION_HELP_TEXT","DatasetError","Error","dataset","projectId","args","options","cause","message","name","listSchemas","configPath","id","json","output","workDir","projectDatasets","URL","url","studioRootPath","workerData","schemas","getDatasetSchemas","parsedSchemas","parseSchemas","length","datasetString","map","log","JSON","stringify","printSchemas","workspaces","Promise","allSettled","error","schema","status","value","reason","statusCode","warning","filter","flat","rows","toSorted","a","b","_createdAt","localeCompare","createdAt","_id","workspace","workspaceData","find","w","CreatedAt","Dataset","Id","ProjectId","Workspace","table","columns","alignment","addRows","render"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAqBC,gBAAgB,QAAO,mBAAkB;AAC9D,SAAQC,UAAU,QAAO,sBAAqB;AAC9C,SAAQC,KAAK,QAAO,wBAAuB;AAG3C,SAAQC,UAAU,QAAO,4BAA2B;AACpD,SAAQC,SAAS,QAAO,mCAAkC;AAG1D,SAAQC,oBAAoB,QAAO,mCAAkC;AACrE,SAAQC,2BAA2B,QAAO,mCAAkC;AAW5E,MAAMC,qBAAqBC;IAClBC,QAAe;IACfC,UAAiB;IACxB,YAAYC,IAAkE,CAAE;QAC9E,KAAK,CAAEA,KAAKC,OAAO,EAAEC,OAA8BC,SAASH,KAAKC,OAAO;QACxE,IAAI,CAACF,SAAS,GAAGC,KAAKD,SAAS;QAC/B,IAAI,CAACD,OAAO,GAAGE,KAAKF,OAAO;QAC3B,IAAI,CAACM,IAAI,GAAG;IACd;AACF;AAEA,OAAO,eAAeC,YAAYJ,OAA2B;IAC3D,MAAM,EAACK,UAAU,EAAEC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAC,GAAGT;IAEhD,MAAMU,kBAAkB,MAAMtB,iBAC5B,IAAIuB,IAAI,8BAA8B,Y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W;YACrC;gBAACsD,WAAW;gBAAQtD,MAAM;YAAS;YACnC;gBAACsD,WAAW;gBAAQtD,MAAM;YAAW;YACrC;gBAACsD,WAAW;gBAAQtD,MAAM;YAAW;SACtC;IACH;IAEAoD,MAAMG,OAAO,CAACpB;IACd9B,OAAOc,GAAG,CAACiC,MAAMI,MAAM;AACzB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isAbsolute, relative } from 'node:path';
|
|
2
|
+
import picomatch from 'picomatch';
|
|
3
|
+
import { toForwardSlashes } from '../../util/toForwardSlashes.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a pattern matcher function for schema watch patterns.
|
|
6
|
+
* Normalizes file paths to forward slashes and makes them relative before matching.
|
|
7
|
+
*
|
|
8
|
+
* @param patterns - Array of glob patterns to match against
|
|
9
|
+
* @returns Function that takes a file path and workDir, returns true if file matches any pattern
|
|
10
|
+
* @internal
|
|
11
|
+
*/ export function createSchemaPatternMatcher(patterns) {
|
|
12
|
+
const matcher = picomatch(patterns);
|
|
13
|
+
return {
|
|
14
|
+
isMatch: (filePath, workDir)=>{
|
|
15
|
+
const relativePath = isAbsolute(filePath) ? relative(workDir, filePath) : filePath;
|
|
16
|
+
const normalizedPath = toForwardSlashes(relativePath);
|
|
17
|
+
return matcher(normalizedPath);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=matchSchemaPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/matchSchemaPattern.ts"],"sourcesContent":["import {isAbsolute, relative} from 'node:path'\n\nimport picomatch from 'picomatch'\n\nimport {toForwardSlashes} from '../../util/toForwardSlashes.js'\n\n/**\n * Creates a pattern matcher function for schema watch patterns.\n * Normalizes file paths to forward slashes and makes them relative before matching.\n *\n * @param patterns - Array of glob patterns to match against\n * @returns Function that takes a file path and workDir, returns true if file matches any pattern\n * @internal\n */\nexport function createSchemaPatternMatcher(patterns: string[]): {\n isMatch: (filePath: string, workDir: string) => boolean\n} {\n const matcher = picomatch(patterns)\n\n return {\n isMatch: (filePath: string, workDir: string): boolean => {\n const relativePath = isAbsolute(filePath) ? relative(workDir, filePath) : filePath\n const normalizedPath = toForwardSlashes(relativePath)\n return matcher(normalizedPath)\n },\n }\n}\n"],"names":["isAbsolute","relative","picomatch","toForwardSlashes","createSchemaPatternMatcher","patterns","matcher","isMatch","filePath","workDir","relativePath","normalizedPath"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,QAAQ,QAAO,YAAW;AAE9C,OAAOC,eAAe,YAAW;AAEjC,SAAQC,gBAAgB,QAAO,iCAAgC;AAE/D;;;;;;;CAOC,GACD,OAAO,SAASC,2BAA2BC,QAAkB;IAG3D,MAAMC,UAAUJ,UAAUG;IAE1B,OAAO;QACLE,SAAS,CAACC,UAAkBC;YAC1B,MAAMC,eAAeV,WAAWQ,YAAYP,SAASQ,SAASD,YAAYA;YAC1E,MAAMG,iBAAiBR,iBAAiBO;YACxC,OAAOJ,QAAQK;QACjB;IACF;AACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { studioWorkerTask } from '@sanity/cli-core';
|
|
4
|
+
import { SchemaExtractionError } from './utils/SchemaExtractionError.js';
|
|
5
|
+
/**
|
|
6
|
+
* Core schema extraction logic.
|
|
7
|
+
* Performs the extraction via worker and writes to file.
|
|
8
|
+
* Throws SchemaExtractionError on failure.
|
|
9
|
+
*/ export async function runSchemaExtraction(extractOptions) {
|
|
10
|
+
const { configPath, enforceRequiredFields, format, outputPath, workspace } = extractOptions;
|
|
11
|
+
if (format !== 'groq-type-nodes') {
|
|
12
|
+
throw new Error(`Unsupported format: "${format}"`);
|
|
13
|
+
}
|
|
14
|
+
const workDir = dirname(configPath);
|
|
15
|
+
const outputDir = dirname(outputPath);
|
|
16
|
+
const result = await studioWorkerTask(new URL('extractSanitySchema.worker.js', import.meta.url), {
|
|
17
|
+
name: 'extractSanitySchema',
|
|
18
|
+
studioRootPath: workDir,
|
|
19
|
+
workerData: {
|
|
20
|
+
configPath,
|
|
21
|
+
enforceRequiredFields,
|
|
22
|
+
workDir,
|
|
23
|
+
workspaceName: workspace
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (result.type === 'error') {
|
|
27
|
+
throw new SchemaExtractionError(result.error, result.validation);
|
|
28
|
+
}
|
|
29
|
+
const schema = result.schema;
|
|
30
|
+
// Ensure output directory exists
|
|
31
|
+
await mkdir(outputDir, {
|
|
32
|
+
recursive: true
|
|
33
|
+
});
|
|
34
|
+
// Write schema to file
|
|
35
|
+
await writeFile(outputPath, `${JSON.stringify(schema, null, 2)}\n`);
|
|
36
|
+
return schema;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=runSchemaExtraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/runSchemaExtraction.ts"],"sourcesContent":["import {mkdir, writeFile} from 'node:fs/promises'\nimport {dirname} from 'node:path'\n\nimport {studioWorkerTask} from '@sanity/cli-core'\nimport {type extractSchema as extractSchemaInternal} from '@sanity/schema/_internal'\n\nimport {type ExtractOptions} from './getExtractOptions.js'\nimport {type ExtractSchemaWorkerData, type ExtractSchemaWorkerError} from './types.js'\nimport {SchemaExtractionError} from './utils/SchemaExtractionError.js'\n\ninterface ExtractSchemaWorkerResult {\n schema: ReturnType<typeof extractSchemaInternal>\n type: 'success'\n}\n\ntype ExtractSchemaWorkerMessage = ExtractSchemaWorkerError | ExtractSchemaWorkerResult\n\n/**\n * Core schema extraction logic.\n * Performs the extraction via worker and writes to file.\n * Throws SchemaExtractionError on failure.\n */\nexport async function runSchemaExtraction(\n extractOptions: Omit<ExtractOptions, 'watchPatterns'>,\n): Promise<ReturnType<typeof extractSchemaInternal>> {\n const {configPath, enforceRequiredFields, format, outputPath, workspace} = extractOptions\n\n if (format !== 'groq-type-nodes') {\n throw new Error(`Unsupported format: \"${format}\"`)\n }\n\n const workDir = dirname(configPath)\n const outputDir = dirname(outputPath)\n\n const result = await studioWorkerTask<ExtractSchemaWorkerMessage>(\n new URL('extractSanitySchema.worker.js', import.meta.url),\n {\n name: 'extractSanitySchema',\n studioRootPath: workDir,\n workerData: {\n configPath,\n enforceRequiredFields,\n workDir,\n workspaceName: workspace,\n } satisfies ExtractSchemaWorkerData,\n },\n )\n\n if (result.type === 'error') {\n throw new SchemaExtractionError(result.error, result.validation)\n }\n\n const schema = result.schema\n\n // Ensure output directory exists\n await mkdir(outputDir, {recursive: true})\n\n // Write schema to file\n await writeFile(outputPath, `${JSON.stringify(schema, null, 2)}\\n`)\n\n return schema\n}\n"],"names":["mkdir","writeFile","dirname","studioWorkerTask","SchemaExtractionError","runSchemaExtraction","extractOptions","configPath","enforceRequiredFields","format","outputPath","workspace","Error","workDir","outputDir","result","URL","url","name","studioRootPath","workerData","workspaceName","type","error","validation","schema","recursive","JSON","stringify"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AACjD,SAAQC,OAAO,QAAO,YAAW;AAEjC,SAAQC,gBAAgB,QAAO,mBAAkB;AAKjD,SAAQC,qBAAqB,QAAO,mCAAkC;AAStE;;;;CAIC,GACD,OAAO,eAAeC,oBACpBC,cAAqD;IAErD,MAAM,EAACC,UAAU,EAAEC,qBAAqB,EAAEC,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAC,GAAGL;IAE3E,IAAIG,WAAW,mBAAmB;QAChC,MAAM,IAAIG,MAAM,CAAC,qBAAqB,EAAEH,OAAO,CAAC,CAAC;IACnD;IAEA,MAAMI,UAAUX,QAAQK;IACxB,MAAMO,YAAYZ,QAAQQ;IAE1B,MAAMK,SAAS,MAAMZ,iBACnB,IAAIa,IAAI,iCAAiC,YAAYC,GAAG,GACxD;QACEC,MAAM;QACNC,gBAAgBN;QAChBO,YAAY;YACVb;YACAC;YACAK;YACAQ,eAAeV;QACjB;IACF;IAGF,IAAII,OAAOO,IAAI,KAAK,SAAS;QAC3B,MAAM,IAAIlB,sBAAsBW,OAAOQ,KAAK,EAAER,OAAOS,UAAU;IACjE;IAEA,MAAMC,SAASV,OAAOU,MAAM;IAE5B,iCAAiC;IACjC,MAAMzB,MAAMc,WAAW;QAACY,WAAW;IAAI;IAEvC,uBAAuB;IACvB,MAAMzB,UAAUS,YAAY,GAAGiB,KAAKC,SAAS,CAACH,QAAQ,MAAM,GAAG,EAAE,CAAC;IAElE,OAAOA;AACT"}
|
|
@@ -5,5 +5,13 @@ export const extractSchemaWorkerData = z.object({
|
|
|
5
5
|
workDir: z.string(),
|
|
6
6
|
workspaceName: z.string().optional()
|
|
7
7
|
});
|
|
8
|
+
export const uniqWorkspaceWorkerDataSchema = z.object({
|
|
9
|
+
configPath: z.string(),
|
|
10
|
+
dataset: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
export const extractWorkspaceWorkerData = z.object({
|
|
13
|
+
configPath: z.string(),
|
|
14
|
+
workDir: z.string()
|
|
15
|
+
});
|
|
8
16
|
|
|
9
17
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {z} from 'zod'\n\nexport const extractSchemaWorkerData = z.object({\n configPath: z.string(),\n enforceRequiredFields: z.boolean(),\n workDir: z.string(),\n workspaceName: z.string().optional(),\n})\n\nexport type ExtractSchemaWorkerData = z.infer<typeof extractSchemaWorkerData>\n\n/**\n * Contains debug information about the serialized schema.\n *\n * @internal\n **/\nexport type SerializedSchemaDebug = {\n hoisted: Record<string, SerializedTypeDebug>\n parent?: SerializedSchemaDebug\n size: number\n types: Record<string, SerializedTypeDebug>\n}\n\n/**\n * Contains debug information about a serialized type.\n *\n * @internal\n **/\nexport type SerializedTypeDebug = {\n extends: string\n fields?: Record<string, SerializedTypeDebug>\n of?: Record<string, SerializedTypeDebug>\n size: number\n}\n"],"names":["z","extractSchemaWorkerData","object","configPath","string","enforceRequiredFields","boolean","workDir","workspaceName","optional"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/types.ts"],"sourcesContent":["import {type SchemaValidationProblemGroup} from '@sanity/types'\nimport {z} from 'zod'\n\nexport const extractSchemaWorkerData = z.object({\n configPath: z.string(),\n enforceRequiredFields: z.boolean(),\n workDir: z.string(),\n workspaceName: z.string().optional(),\n})\n\nexport type ExtractSchemaWorkerData = z.infer<typeof extractSchemaWorkerData>\n\n/**\n * Contains debug information about the serialized schema.\n *\n * @internal\n **/\nexport type SerializedSchemaDebug = {\n hoisted: Record<string, SerializedTypeDebug>\n parent?: SerializedSchemaDebug\n size: number\n types: Record<string, SerializedTypeDebug>\n}\n\n/**\n * Contains debug information about a serialized type.\n *\n * @internal\n **/\nexport type SerializedTypeDebug = {\n extends: string\n fields?: Record<string, SerializedTypeDebug>\n of?: Record<string, SerializedTypeDebug>\n size: number\n}\n\n/** @internal */\nexport interface ExtractSchemaWorkerError {\n error: string\n type: 'error'\n\n validation?: SchemaValidationProblemGroup[]\n}\n\nexport const uniqWorkspaceWorkerDataSchema = z.object({\n configPath: z.string(),\n dataset: z.string().optional(),\n})\n\nexport type UniqWorkspaceWorkerData = z.infer<typeof uniqWorkspaceWorkerDataSchema>\n\nexport const extractWorkspaceWorkerData = z.object({\n configPath: z.string(),\n workDir: z.string(),\n})\n\nexport type ExtractWorkspaceWorkerData = z.infer<typeof extractWorkspaceWorkerData>\n"],"names":["z","extractSchemaWorkerData","object","configPath","string","enforceRequiredFields","boolean","workDir","workspaceName","optional","uniqWorkspaceWorkerDataSchema","dataset","extractWorkspaceWorkerData"],"mappings":"AACA,SAAQA,CAAC,QAAO,MAAK;AAErB,OAAO,MAAMC,0BAA0BD,EAAEE,MAAM,CAAC;IAC9CC,YAAYH,EAAEI,MAAM;IACpBC,uBAAuBL,EAAEM,OAAO;IAChCC,SAASP,EAAEI,MAAM;IACjBI,eAAeR,EAAEI,MAAM,GAAGK,QAAQ;AACpC,GAAE;AAoCF,OAAO,MAAMC,gCAAgCV,EAAEE,MAAM,CAAC;IACpDC,YAAYH,EAAEI,MAAM;IACpBO,SAASX,EAAEI,MAAM,GAAGK,QAAQ;AAC9B,GAAE;AAIF,OAAO,MAAMG,6BAA6BZ,EAAEE,MAAM,CAAC;IACjDC,YAAYH,EAAEI,MAAM;IACpBG,SAASP,EAAEI,MAAM;AACnB,GAAE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
import { getStudioWorkspaces, safeStructuredClone } from '@sanity/cli-core';
|
|
3
|
+
import { uniqWorkspaceWorkerDataSchema } from './types.js';
|
|
4
|
+
import { uniqByProjectIdDataset } from './utils/uniqByProjectIdDataset.js';
|
|
5
|
+
if (isMainThread || !parentPort) {
|
|
6
|
+
throw new Error('Should only be run in a worker!');
|
|
7
|
+
}
|
|
8
|
+
const { configPath, dataset } = uniqWorkspaceWorkerDataSchema.parse(workerData);
|
|
9
|
+
try {
|
|
10
|
+
const workspaces = await getStudioWorkspaces(configPath);
|
|
11
|
+
let filteredWorkspaces = workspaces;
|
|
12
|
+
// If a dataset is provided, filter the workspaces to only include those with the same dataset
|
|
13
|
+
if (dataset) {
|
|
14
|
+
filteredWorkspaces = workspaces.filter((workspace)=>workspace.dataset === dataset);
|
|
15
|
+
}
|
|
16
|
+
const uniqueWorkspaces = uniqByProjectIdDataset(filteredWorkspaces);
|
|
17
|
+
parentPort.postMessage(safeStructuredClone(uniqueWorkspaces));
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new Error(error instanceof Error ? error.message : String(error), {
|
|
20
|
+
cause: error
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=uniqueWorkspaces.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/uniqueWorkspaces.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, safeStructuredClone} from '@sanity/cli-core'\n\nimport {uniqWorkspaceWorkerDataSchema} from './types.js'\nimport {uniqByProjectIdDataset} from './utils/uniqByProjectIdDataset.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('Should only be run in a worker!')\n}\n\nconst {configPath, dataset} = uniqWorkspaceWorkerDataSchema.parse(workerData)\n\ntry {\n const workspaces = await getStudioWorkspaces(configPath)\n\n let filteredWorkspaces = workspaces\n // If a dataset is provided, filter the workspaces to only include those with the same dataset\n if (dataset) {\n filteredWorkspaces = workspaces.filter((workspace) => workspace.dataset === dataset)\n }\n\n const uniqueWorkspaces = uniqByProjectIdDataset(filteredWorkspaces)\n\n parentPort.postMessage(safeStructuredClone(uniqueWorkspaces))\n} catch (error) {\n throw new Error(error instanceof Error ? error.message : String(error), {cause: error})\n}\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","safeStructuredClone","uniqWorkspaceWorkerDataSchema","uniqByProjectIdDataset","Error","configPath","dataset","parse","workspaces","filteredWorkspaces","filter","workspace","uniqueWorkspaces","postMessage","error","message","String","cause"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,mBAAmB,QAAO,mBAAkB;AAEzE,SAAQC,6BAA6B,QAAO,aAAY;AACxD,SAAQC,sBAAsB,QAAO,oCAAmC;AAExE,IAAIN,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIM,MAAM;AAClB;AAEA,MAAM,EAACC,UAAU,EAAEC,OAAO,EAAC,GAAGJ,8BAA8BK,KAAK,CAACR;AAElE,IAAI;IACF,MAAMS,aAAa,MAAMR,oBAAoBK;IAE7C,IAAII,qBAAqBD;IACzB,8FAA8F;IAC9F,IAAIF,SAAS;QACXG,qBAAqBD,WAAWE,MAAM,CAAC,CAACC,YAAcA,UAAUL,OAAO,KAAKA;IAC9E;IAEA,MAAMM,mBAAmBT,uBAAuBM;IAEhDX,WAAWe,WAAW,CAACZ,oBAAoBW;AAC7C,EAAE,OAAOE,OAAO;IACd,MAAM,IAAIV,MAAMU,iBAAiBV,QAAQU,MAAMC,OAAO,GAAGC,OAAOF,QAAQ;QAACG,OAAOH;IAAK;AACvF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { ux } from '@oclif/core/ux';
|
|
3
|
+
import { spinner } from '@sanity/cli-core/ux';
|
|
4
|
+
import partition from 'lodash-es/partition.js';
|
|
5
|
+
import { updateSchemas } from '../../services/schemas.js';
|
|
6
|
+
import { CURRENT_WORKSPACE_SCHEMA_VERSION } from '../manifest/types.js';
|
|
7
|
+
import { SCHEMA_PERMISSION_HELP_TEXT } from './utils/schemaStoreValidation.js';
|
|
8
|
+
import { getWorkspaceSchemaId } from './utils/workspaceSchemaId.js';
|
|
9
|
+
/**
|
|
10
|
+
* Updates the schemas for a list of workspaces.
|
|
11
|
+
*/ export async function updateWorkspacesSchemas(args) {
|
|
12
|
+
const { tag, verbose, workspaces } = args;
|
|
13
|
+
/* Known caveat: we _don't_ rollback failed operations or partial success */ const results = await Promise.allSettled(workspaces.map(async (workspace)=>{
|
|
14
|
+
await updateWorkspaceSchema({
|
|
15
|
+
tag,
|
|
16
|
+
verbose,
|
|
17
|
+
workspace
|
|
18
|
+
});
|
|
19
|
+
}));
|
|
20
|
+
const [fulfilledUpdates, rejectedUpdates] = partition(results, (result)=>result.status === 'fulfilled');
|
|
21
|
+
if (rejectedUpdates.length > 0) {
|
|
22
|
+
throw new Error(`Failed to deploy ${rejectedUpdates.length}/${workspaces.length} schemas. Successfully deployed ${fulfilledUpdates.length}/${workspaces.length} schemas.`);
|
|
23
|
+
}
|
|
24
|
+
spinner(`Deployed ${fulfilledUpdates.length}/${workspaces.length} schemas`).succeed();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Updates a workspace schema in the dataset.
|
|
28
|
+
*/ async function updateWorkspaceSchema(args) {
|
|
29
|
+
const { tag, verbose, workspace } = args;
|
|
30
|
+
const { dataset, projectId } = workspace;
|
|
31
|
+
const { idWarning, safeBaseId: id } = getWorkspaceSchemaId({
|
|
32
|
+
tag,
|
|
33
|
+
workspaceName: workspace.name
|
|
34
|
+
});
|
|
35
|
+
if (idWarning) ux.warn(idWarning);
|
|
36
|
+
try {
|
|
37
|
+
await updateSchemas(dataset, projectId, [
|
|
38
|
+
{
|
|
39
|
+
// the API will stringify the schema – we send as JSON
|
|
40
|
+
schema: workspace.schema,
|
|
41
|
+
tag,
|
|
42
|
+
version: CURRENT_WORKSPACE_SCHEMA_VERSION,
|
|
43
|
+
workspace: {
|
|
44
|
+
name: workspace.name,
|
|
45
|
+
title: workspace.title
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]);
|
|
49
|
+
if (verbose) {
|
|
50
|
+
ux.stdout(styleText('gray', `↳ schemaId: ${id}, projectId: ${projectId}, dataset: ${dataset}`));
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
54
|
+
if (err instanceof Error && 'statusCode' in err && err.statusCode === 401) {
|
|
55
|
+
ux.warn(`↳ No permissions to write schema for workspace "${workspace.name}" in dataset "${workspace.dataset}". ${SCHEMA_PERMISSION_HELP_TEXT}:\n ${styleText('red', message)}`);
|
|
56
|
+
} else {
|
|
57
|
+
ux.stdout(styleText('red', `↳ Error deploying schema for workspace "${workspace.name}":\n ${styleText('red', message)}`));
|
|
58
|
+
}
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=updateWorkspaceSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/updateWorkspaceSchema.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {ux} from '@oclif/core/ux'\nimport {spinner} from '@sanity/cli-core/ux'\nimport partition from 'lodash-es/partition.js'\nimport {type Workspace} from 'sanity'\n\nimport {updateSchemas} from '../../services/schemas.js'\nimport {CURRENT_WORKSPACE_SCHEMA_VERSION, type StoredWorkspaceSchema} from '../manifest/types.js'\nimport {SCHEMA_PERMISSION_HELP_TEXT} from './utils/schemaStoreValidation.js'\nimport {getWorkspaceSchemaId} from './utils/workspaceSchemaId.js'\n\n/**\n * Updates the schemas for a list of workspaces.\n */\nexport async function updateWorkspacesSchemas(args: {\n tag?: string\n verbose: boolean\n workspaces: Workspace[]\n}) {\n const {tag, verbose, workspaces} = args\n\n /* Known caveat: we _don't_ rollback failed operations or partial success */\n const results = await Promise.allSettled(\n workspaces.map(async (workspace): Promise<void> => {\n await updateWorkspaceSchema({\n tag,\n verbose,\n workspace,\n })\n }),\n )\n\n const [fulfilledUpdates, rejectedUpdates] = partition(\n results,\n (result) => result.status === 'fulfilled',\n )\n\n if (rejectedUpdates.length > 0) {\n throw new Error(\n `Failed to deploy ${rejectedUpdates.length}/${workspaces.length} schemas. Successfully deployed ${fulfilledUpdates.length}/${workspaces.length} schemas.`,\n )\n }\n\n spinner(`Deployed ${fulfilledUpdates.length}/${workspaces.length} schemas`).succeed()\n}\n\n/**\n * Updates a workspace schema in the dataset.\n */\nasync function updateWorkspaceSchema(args: {tag?: string; verbose: boolean; workspace: Workspace}) {\n const {tag, verbose, workspace} = args\n\n const {dataset, projectId} = workspace\n\n const {idWarning, safeBaseId: id} = getWorkspaceSchemaId({\n tag,\n workspaceName: workspace.name,\n })\n\n if (idWarning) ux.warn(idWarning)\n\n try {\n await updateSchemas<Omit<StoredWorkspaceSchema, '_id' | '_type'>[]>(dataset, projectId, [\n {\n // the API will stringify the schema – we send as JSON\n schema: workspace.schema,\n tag,\n version: CURRENT_WORKSPACE_SCHEMA_VERSION,\n workspace: {\n name: workspace.name,\n title: workspace.title,\n },\n },\n ])\n\n if (verbose) {\n ux.stdout(\n styleText('gray', `↳ schemaId: ${id}, projectId: ${projectId}, dataset: ${dataset}`),\n )\n }\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n if (\n err instanceof Error &&\n 'statusCode' in err &&\n (err as {statusCode: unknown}).statusCode === 401\n ) {\n ux.warn(\n `↳ No permissions to write schema for workspace \"${workspace.name}\" in dataset \"${workspace.dataset}\". ${\n SCHEMA_PERMISSION_HELP_TEXT\n }:\\n ${styleText('red', message)}`,\n )\n } else {\n ux.stdout(\n styleText(\n 'red',\n `↳ Error deploying schema for workspace \"${workspace.name}\":\\n ${styleText('red', message)}`,\n ),\n )\n }\n\n throw err\n }\n}\n"],"names":["styleText","ux","spinner","partition","updateSchemas","CURRENT_WORKSPACE_SCHEMA_VERSION","SCHEMA_PERMISSION_HELP_TEXT","getWorkspaceSchemaId","updateWorkspacesSchemas","args","tag","verbose","workspaces","results","Promise","allSettled","map","workspace","updateWorkspaceSchema","fulfilledUpdates","rejectedUpdates","result","status","length","Error","succeed","dataset","projectId","idWarning","safeBaseId","id","workspaceName","name","warn","schema","version","title","stdout","err","message","String","statusCode"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,EAAE,QAAO,iBAAgB;AACjC,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,OAAOC,eAAe,yBAAwB;AAG9C,SAAQC,aAAa,QAAO,4BAA2B;AACvD,SAAQC,gCAAgC,QAAmC,uBAAsB;AACjG,SAAQC,2BAA2B,QAAO,mCAAkC;AAC5E,SAAQC,oBAAoB,QAAO,+BAA8B;AAEjE;;CAEC,GACD,OAAO,eAAeC,wBAAwBC,IAI7C;IACC,MAAM,EAACC,GAAG,EAAEC,OAAO,EAAEC,UAAU,EAAC,GAAGH;IAEnC,0EAA0E,GAC1E,MAAMI,UAAU,MAAMC,QAAQC,UAAU,CACtCH,WAAWI,GAAG,CAAC,OAAOC;QACpB,MAAMC,sBAAsB;YAC1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Aed,SACf,gBAAgBc,OAChB,AAACA,IAA8BG,UAAU,KAAK,KAC9C;YACAxC,GAAGgC,IAAI,CACL,CAAC,gDAAgD,EAAEhB,UAAUe,IAAI,CAAC,cAAc,EAAEf,UAAUS,OAAO,CAAC,GAAG,EACrGpB,4BACD,KAAK,EAAEN,UAAU,OAAOuC,UAAU;QAEvC,OAAO;YACLtC,GAAGoC,MAAM,CACPrC,UACE,OACA,CAAC,wCAAwC,EAAEiB,UAAUe,IAAI,CAAC,MAAM,EAAEhC,UAAU,OAAOuC,UAAU;QAGnG;QAEA,MAAMD;IACR;AACF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { styleText } from 'node:util';
|
|
2
|
+
import { ux } from '@oclif/core/ux';
|
|
3
|
+
import { getProjectCliClient, resolveLocalPackage, subdebug } from '@sanity/cli-core';
|
|
4
|
+
import { spinner } from '@sanity/cli-core/ux';
|
|
5
|
+
import { SCHEMA_API_VERSION } from '../../services/schemas.js';
|
|
6
|
+
import { getLocalPackageVersion } from '../../util/getLocalPackageVersion.js';
|
|
7
|
+
import { resolveIcon } from '../manifest/iconResolver.js';
|
|
8
|
+
const debug = subdebug('uploadSchemaToLexicon');
|
|
9
|
+
/**
|
|
10
|
+
* Uploads the schemas to Lexicon and returns the studio manifest
|
|
11
|
+
* @param options - The options for the uploadSchemaToLexicon function
|
|
12
|
+
* @returns The studio manifest
|
|
13
|
+
*/ export async function uploadSchemaToLexicon(options) {
|
|
14
|
+
const { projectId, verbose, workDir, workspaces } = options;
|
|
15
|
+
const spin = spinner('Generating studio manifest').start();
|
|
16
|
+
try {
|
|
17
|
+
const schemaDescriptors = new Map();
|
|
18
|
+
const client = await getProjectCliClient({
|
|
19
|
+
apiVersion: SCHEMA_API_VERSION,
|
|
20
|
+
projectId,
|
|
21
|
+
requestTagPrefix: 'sanity.cli.deploy',
|
|
22
|
+
requireUser: true
|
|
23
|
+
});
|
|
24
|
+
const [bundleVersion, { generateStudioManifest, uploadSchema }] = await Promise.all([
|
|
25
|
+
getLocalPackageVersion('sanity', workDir),
|
|
26
|
+
resolveLocalPackage('sanity', workDir)
|
|
27
|
+
]);
|
|
28
|
+
if (!bundleVersion) {
|
|
29
|
+
throw new Error('Failed to find sanity version');
|
|
30
|
+
}
|
|
31
|
+
for (const workspace of workspaces){
|
|
32
|
+
const workspaceClient = client.withConfig({
|
|
33
|
+
dataset: workspace.dataset,
|
|
34
|
+
projectId: workspace.projectId
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
debug('Uploading schema to lexicon for workspace %o', {
|
|
38
|
+
dataset: workspace.dataset,
|
|
39
|
+
projectId: workspace.projectId
|
|
40
|
+
});
|
|
41
|
+
const descriptorId = await uploadSchema(workspace.schema, workspaceClient);
|
|
42
|
+
if (!descriptorId) {
|
|
43
|
+
throw new Error(`Failed to get schema descriptor ID for workspace "${workspace.name}": upload returned empty result`);
|
|
44
|
+
}
|
|
45
|
+
schemaDescriptors.set(workspace.name, descriptorId);
|
|
46
|
+
debug(`Uploaded schema for workspace "${workspace.name}" to Lexicon with descriptor ID: ${descriptorId}`);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
debug('Error uploading schema to lexicon for workspace %o', error);
|
|
49
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
50
|
+
throw new Error(`Failed to upload schema for workspace "${workspace.name}": ${errorMessage}`, {
|
|
51
|
+
cause: error
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Generate studio manifest using the shared utility
|
|
56
|
+
const manifest = await generateStudioManifest({
|
|
57
|
+
buildId: JSON.stringify(Date.now()),
|
|
58
|
+
bundleVersion,
|
|
59
|
+
resolveIcon: async (workspace)=>// @todo replace with import from @sanity/schema/_internal in future
|
|
60
|
+
await resolveIcon({
|
|
61
|
+
icon: workspace.icon,
|
|
62
|
+
subtitle: workspace.subtitle,
|
|
63
|
+
title: workspace.title || workspace.name || 'default',
|
|
64
|
+
workDir
|
|
65
|
+
}) ?? undefined,
|
|
66
|
+
resolveSchemaDescriptorId: (workspace)=>schemaDescriptors.get(workspace.name),
|
|
67
|
+
workspaces
|
|
68
|
+
});
|
|
69
|
+
spin.succeed('Generated studio manifest');
|
|
70
|
+
const studioManifest = manifest.workspaces.length === 0 ? null : manifest;
|
|
71
|
+
if (verbose) {
|
|
72
|
+
if (studioManifest) {
|
|
73
|
+
for (const workspace of studioManifest.workspaces){
|
|
74
|
+
ux.stdout(styleText('gray', `↳ projectId: ${workspace.projectId}, dataset: ${workspace.dataset}, schemaDescriptorId: ${workspace.schemaDescriptorId}`));
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
ux.stdout(`${styleText('gray', '↳ No workspaces found')}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return studioManifest;
|
|
81
|
+
} catch (error) {
|
|
82
|
+
spin.fail(error instanceof Error ? error.message : 'Unknown error');
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=uploadSchemaToLexicon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/uploadSchemaToLexicon.ts"],"sourcesContent":["import {styleText} from 'node:util'\n\nimport {ux} from '@oclif/core/ux'\nimport {getProjectCliClient, resolveLocalPackage, subdebug} from '@sanity/cli-core'\nimport {spinner} from '@sanity/cli-core/ux'\nimport {type StudioManifest, type Workspace} from 'sanity'\n\nimport {SCHEMA_API_VERSION} from '../../services/schemas.js'\nimport {getLocalPackageVersion} from '../../util/getLocalPackageVersion.js'\nimport {resolveIcon} from '../manifest/iconResolver.js'\n\ninterface UploadSchemaToLexiconOptions {\n projectId: string\n workDir: string\n workspaces: Workspace[]\n\n verbose?: boolean\n}\n\nconst debug = subdebug('uploadSchemaToLexicon')\n\n/**\n * Uploads the schemas to Lexicon and returns the studio manifest\n * @param options - The options for the uploadSchemaToLexicon function\n * @returns The studio manifest\n */\nexport async function uploadSchemaToLexicon(\n options: UploadSchemaToLexiconOptions,\n): Promise<StudioManifest | null> {\n const {projectId, verbose, workDir, workspaces} = options\n const spin = spinner('Generating studio manifest').start()\n\n try {\n const schemaDescriptors = new Map<string, string>()\n\n const client = await getProjectCliClient({\n apiVersion: SCHEMA_API_VERSION,\n projectId,\n requestTagPrefix: 'sanity.cli.deploy',\n requireUser: true,\n })\n\n const [bundleVersion, {generateStudioManifest, uploadSchema}] = await Promise.all([\n getLocalPackageVersion('sanity', workDir),\n resolveLocalPackage<typeof import('sanity')>('sanity', workDir),\n ])\n\n if (!bundleVersion) {\n throw new Error('Failed to find sanity version')\n }\n\n for (const workspace of workspaces) {\n const workspaceClient = client.withConfig({\n dataset: workspace.dataset,\n projectId: workspace.projectId,\n })\n\n try {\n debug('Uploading schema to lexicon for workspace %o', {\n dataset: workspace.dataset,\n projectId: workspace.projectId,\n })\n const descriptorId = await uploadSchema(workspace.schema, workspaceClient)\n\n if (!descriptorId) {\n throw new Error(\n `Failed to get schema descriptor ID for workspace \"${workspace.name}\": upload returned empty result`,\n )\n }\n\n schemaDescriptors.set(workspace.name, descriptorId)\n debug(\n `Uploaded schema for workspace \"${workspace.name}\" to Lexicon with descriptor ID: ${descriptorId}`,\n )\n } catch (error) {\n debug('Error uploading schema to lexicon for workspace %o', error)\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n throw new Error(\n `Failed to upload schema for workspace \"${workspace.name}\": ${errorMessage}`,\n {cause: error},\n )\n }\n }\n\n // Generate studio manifest using the shared utility\n const manifest = await generateStudioManifest({\n buildId: JSON.stringify(Date.now()),\n bundleVersion,\n resolveIcon: async (workspace) =>\n // @todo replace with import from @sanity/schema/_internal in future\n (await resolveIcon({\n icon: workspace.icon,\n subtitle: workspace.subtitle,\n title: workspace.title || workspace.name || 'default',\n workDir,\n })) ?? undefined,\n resolveSchemaDescriptorId: (workspace) => schemaDescriptors.get(workspace.name),\n workspaces,\n })\n\n spin.succeed('Generated studio manifest')\n\n const studioManifest = manifest.workspaces.length === 0 ? null : manifest\n\n if (verbose) {\n if (studioManifest) {\n for (const workspace of studioManifest.workspaces) {\n ux.stdout(\n styleText(\n 'gray',\n `↳ projectId: ${workspace.projectId}, dataset: ${workspace.dataset}, schemaDescriptorId: ${workspace.schemaDescriptorId}`,\n ),\n )\n }\n } else {\n ux.stdout(`${styleText('gray', '↳ No workspaces found')}`)\n }\n }\n\n return studioManifest\n } catch (error) {\n spin.fail(error instanceof Error ? error.message : 'Unknown error')\n throw error\n }\n}\n"],"names":["styleText","ux","getProjectCliClient","resolveLocalPackage","subdebug","spinner","SCHEMA_API_VERSION","getLocalPackageVersion","resolveIcon","debug","uploadSchemaToLexicon","options","projectId","verbose","workDir","workspaces","spin","start","schemaDescriptors","Map","client","apiVersion","requestTagPrefix","requireUser","bundleVersion","generateStudioManifest","uploadSchema","Promise","all","Error","workspace","workspaceClient","withConfig","dataset","descriptorId","schema","name","set","error","errorMessage","message","cause","manifest","buildId","JSON","stringify","Date","now","icon","subtitle","title","undefined","resolveSchemaDescriptorId","get","succeed","studioManifest","length","stdout","schemaDescriptorId","fail"],"mappings":"AAAA,SAAQA,SAAS,QAAO,YAAW;AAEnC,SAAQC,EAAE,QAAO,iBAAgB;AACjC,SAAQC,mBAAmB,EAAEC,mBAAmB,EAAEC,QAAQ,QAAO,mBAAkB;AACnF,SAAQC,OAAO,QAAO,sBAAqB;AAG3C,SAAQC,kBAAkB,QAAO,4BAA2B;AAC5D,SAAQC,sBAAsB,QAAO,uCAAsC;AAC3E,SAAQC,WAAW,QAAO,8BAA6B;AAUvD,MAAMC,QAAQL,SAAS;AAEvB;;;;CAIC,GACD,OAAO,eAAeM,sBACpBC,OAAqC;IAErC,MAAM,EAACC,SAAS,EAAEC,OAAO,EAAEC,OAAO,EAAEC,UAAU,EAAC,GAAGJ;IAClD,MAAMK,OAAOX,QAAQ,8BAA8BY,KAAK;IAExD,IAAI;QACF,MAAMC,oBAAoB,IAAIC;QAE9B,MAAM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YAAY;oBACjBwC,MAAMlB,UAAUkB,IAAI;oBACpBC,UAAUnB,UAAUmB,QAAQ;oBAC5BC,OAAOpB,UAAUoB,KAAK,IAAIpB,UAAUM,IAAI,IAAI;oBAC5CtB;gBACF,MAAOqC;YACTC,2BAA2B,CAACtB,YAAcZ,kBAAkBmC,GAAG,CAACvB,UAAUM,IAAI;YAC9ErB;QACF;QAEAC,KAAKsC,OAAO,CAAC;QAEb,MAAMC,iBAAiBb,SAAS3B,UAAU,CAACyC,MAAM,KAAK,IAAI,OAAOd;QAEjE,IAAI7B,SAAS;YACX,IAAI0C,gBAAgB;gBAClB,KAAK,MAAMzB,aAAayB,eAAexC,UAAU,CAAE;oBACjDd,GAAGwD,MAAM,CACPzD,UACE,QACA,CAAC,aAAa,EAAE8B,UAAUlB,SAAS,CAAC,WAAW,EAAEkB,UAAUG,OAAO,CAAC,sBAAsB,EAAEH,UAAU4B,kBAAkB,EAAE;gBAG/H;YACF,OAAO;gBACLzD,GAAGwD,MAAM,CAAC,GAAGzD,UAAU,QAAQ,0BAA0B;YAC3D;QACF;QAEA,OAAOuD;IACT,EAAE,OAAOjB,OAAO;QACdtB,KAAK2C,IAAI,CAACrB,iBAAiBT,QAAQS,MAAME,OAAO,GAAG;QACnD,MAAMF;IACR;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/schema/utils/SchemaExtractionError.ts"],"sourcesContent":["import {type SchemaValidationProblemGroup} from '@sanity/types'\n\nexport class SchemaExtractionError extends Error {\n validation?: SchemaValidationProblemGroup[]\n\n constructor(message: string, validation?: SchemaValidationProblemGroup[]) {\n super(message)\n this.name = 'SchemaExtractionError'\n this.validation = validation\n }\n}\n"],"names":["SchemaExtractionError","Error","validation","message","name"],"mappings":"AAEA,OAAO,MAAMA,8BAA8BC;IACzCC,WAA2C;IAE3C,YAAYC,OAAe,EAAED,UAA2C,CAAE;QACxE,KAAK,CAACC;QACN,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACF,UAAU,GAAGA;IACpB;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CLIError } from '@oclif/core/errors';
|
|
2
|
-
import
|
|
2
|
+
import uniqBy from 'lodash-es/uniqBy.js';
|
|
3
3
|
import { isDefined } from '../../manifest/schemaTypeHelpers.js';
|
|
4
4
|
import { SANITY_WORKSPACE_SCHEMA_ID_PREFIX } from '../../manifest/types.js';
|
|
5
5
|
const validForIdChars = 'a-zA-Z0-9._-';
|
|
@@ -11,12 +11,6 @@ const requiredInId = SANITY_WORKSPACE_SCHEMA_ID_PREFIX.replaceAll(/[.]/g, String
|
|
|
11
11
|
const idIdPatternString = String.raw`^${requiredInId}\.([${validForNamesChars}]+)`;
|
|
12
12
|
const baseIdPattern = new RegExp(`${idIdPatternString}$`);
|
|
13
13
|
const taggedIdIdPattern = new RegExp(String.raw`${idIdPatternString}\.tag\.([${validForNamesChars}]+)$`);
|
|
14
|
-
export class FlagValidationError extends Error {
|
|
15
|
-
constructor(message){
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = 'FlagValidationError';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
14
|
export function parseIds(ids) {
|
|
21
15
|
if (!ids) {
|
|
22
16
|
throw new CLIError('ids argument is empty');
|
|
@@ -95,14 +89,6 @@ export function parseWorkspaceSchemaId(errors, id) {
|
|
|
95
89
|
}
|
|
96
90
|
return tag;
|
|
97
91
|
}
|
|
98
|
-
function getProjectIdMismatchMessage(workspace, operation) {
|
|
99
|
-
return `No permissions to ${operation} schema for workspace "${workspace.name}" with projectId "${workspace.projectId}"`;
|
|
100
|
-
}
|
|
101
|
-
export function filterLogReadProjectIdMismatch(workspace, projectId, output) {
|
|
102
|
-
const canRead = workspace.projectId === projectId;
|
|
103
|
-
if (!canRead) output.warn(`${getProjectIdMismatchMessage(workspace, 'read')} – ignoring it.`);
|
|
104
|
-
return canRead;
|
|
105
|
-
}
|
|
106
92
|
export const SCHEMA_PERMISSION_HELP_TEXT = 'For multi-project workspaces, set SANITY_AUTH_TOKEN environment variable to a token with access to the workspace projects.';
|
|
107
93
|
|
|
108
94
|
//# sourceMappingURL=schemaStoreValidation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/schema/utils/schemaStoreValidation.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/schema/utils/schemaStoreValidation.ts"],"sourcesContent":["import {CLIError} from '@oclif/core/errors'\nimport uniqBy from 'lodash-es/uniqBy.js'\n\nimport {isDefined} from '../../manifest/schemaTypeHelpers.js'\nimport {SANITY_WORKSPACE_SCHEMA_ID_PREFIX} from '../../manifest/types.js'\n\nconst validForIdChars = 'a-zA-Z0-9._-'\nconst validForIdPattern = new RegExp(`^[${validForIdChars}]+$`)\n\n//no periods allowed in workspaceName or tag in ids\nexport const validForNamesChars = 'a-zA-Z0-9_-'\nexport const validForNamesPattern = new RegExp(`^[${validForNamesChars}]+$`)\n\nconst requiredInId = SANITY_WORKSPACE_SCHEMA_ID_PREFIX.replaceAll(/[.]/g, String.raw`\\.`)\n\nconst idIdPatternString = String.raw`^${requiredInId}\\.([${validForNamesChars}]+)`\nconst baseIdPattern = new RegExp(`${idIdPatternString}$`)\nconst taggedIdIdPattern = new RegExp(\n String.raw`${idIdPatternString}\\.tag\\.([${validForNamesChars}]+)$`,\n)\n\nexport interface WorkspaceSchemaId {\n schemaId: string\n workspace: string\n}\n\nexport function parseIds(ids?: string): WorkspaceSchemaId[] {\n if (!ids) {\n throw new CLIError('ids argument is empty')\n }\n\n const errors: string[] = []\n\n const parsedIds = ids\n .split(',')\n .map((id) => id.trim())\n .filter((id) => !!id)\n .map((id) => parseWorkspaceSchemaId(errors, id))\n .filter((item) => isDefined(item))\n\n if (errors.length > 0) {\n throw new CLIError(`Invalid arguments:\\n${errors.map((error) => ` - ${error}`).join('\\n')}`)\n }\n\n if (parsedIds.length === 0) {\n throw new CLIError(`ids contains no valid id strings`)\n }\n\n const uniqueIds = uniqBy(parsedIds, 'schemaId' satisfies keyof (typeof parsedIds)[number])\n if (uniqueIds.length < parsedIds.length) {\n throw new CLIError(`ids contains duplicates`)\n }\n\n return uniqueIds\n}\n\nexport function parseWorkspaceSchemaId(errors: string[], id?: string) {\n if (id === undefined) {\n return\n }\n\n if (!id) {\n errors.push('id argument is empty')\n return\n }\n\n const trimmedId = id.trim()\n\n if (!validForIdPattern.test(trimmedId)) {\n errors.push(`id can only contain characters in [${validForIdChars}] but found: \"${trimmedId}\"`)\n return\n }\n\n if (trimmedId.startsWith('-')) {\n errors.push(`id cannot start with - (dash) but found: \"${trimmedId}\"`)\n return\n }\n\n if (/\\.\\./g.test(trimmedId)) {\n errors.push(`id cannot have consecutive . (period) characters, but found: \"${trimmedId}\"`)\n return\n }\n\n const [, workspace] = trimmedId.match(taggedIdIdPattern) ?? trimmedId.match(baseIdPattern) ?? []\n if (!workspace) {\n errors.push(\n [\n `id must either match ${SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.<workspaceName> `,\n `or ${SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.<workspaceName>.tag.<tag> but found: \"${trimmedId}\". `,\n `Note that workspace name characters not in [${validForNamesChars}] has to be replaced with _ for schema id.`,\n ].join(''),\n )\n return\n }\n return {\n schemaId: trimmedId,\n workspace,\n }\n}\n\n/**\n *\n * @param tag - The tag to parse\n * Throws an error if the tag is empty\n * Throws an error if the tag contains a period\n * Throws an error if the tag starts with a dash\n * Returns the parsed tag\n */\nexport async function parseTag(tag?: string) {\n if (tag === undefined) {\n return tag\n }\n\n if (!tag) {\n throw new CLIError('tag argument is empty')\n }\n\n if (tag.includes('.')) {\n throw new CLIError(`tag cannot contain . (period), but was: \"${tag}\"`)\n }\n\n if (!validForNamesPattern.test(tag)) {\n throw new CLIError(\n `tag can only contain characters in [${validForNamesChars}], but was: \"${tag}\"`,\n )\n }\n\n if (tag.startsWith('-')) {\n throw new CLIError(`tag cannot start with - (dash) but was: \"${tag}\"`)\n }\n\n return tag\n}\n\nexport const SCHEMA_PERMISSION_HELP_TEXT =\n 'For multi-project workspaces, set SANITY_AUTH_TOKEN environment variable to a token with access to the workspace projects.'\n"],"names":["CLIError","uniqBy","isDefined","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","validForIdChars","validForIdPattern","RegExp","validForNamesChars","validForNamesPattern","requiredInId","replaceAll","String","raw","idIdPatternString","baseIdPattern","taggedIdIdPattern","parseIds","ids","errors","parsedIds","split","map","id","trim","filter","parseWorkspaceSchemaId","item","length","error","join","uniqueIds","undefined","push","trimmedId","test","startsWith","workspace","match","schemaId","parseTag","tag","includes","SCHEMA_PERMISSION_HELP_TEXT"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,qBAAoB;AAC3C,OAAOC,YAAY,sBAAqB;AAExC,SAAQC,SAAS,QAAO,sCAAqC;AAC7D,SAAQC,iCAAiC,QAAO,0BAAyB;AAEzE,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB,IAAIC,OAAO,CAAC,EAAE,EAAEF,gBAAgB,GAAG,CAAC;AAE9D,mDAAmD;AACnD,OAAO,MAAMG,qBAAqB,cAAa;AAC/C,OAAO,MAAMC,uBAAuB,IAAIF,OAAO,CAAC,EAAE,EAAEC,mBAAmB,GAAG,CAAC,EAAC;AAE5E,MAAME,eAAeN,kCAAkCO,UAAU,CAAC,QAAQC,OAAOC,GAAG,CAAC,EAAE,CAAC;AAExF,MAAMC,oBAAoBF,OAAOC,GAAG,CAAC,CAAC,EAAEH,aAAa,IAAI,EAAEF,mBAAmB,GAAG,CAAC;AAClF,MAAMO,gBAAgB,IAAIR,OAAO,GAAGO,kBAAkB,CAAC,CAAC;AACxD,MAAME,oBAAoB,IAAIT,OAC5BK,OAAOC,GAAG,CAAC,EAAEC,kBAAkB,SAAS,EAAEN,mBAAmB,IAAI,CAAC;AAQpE,OAAO,SAASS,SAASC,GAAY;IACnC,IAAI,CAACA,K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AC,CAAC,8DAA8D,EAAEC,UAAU,CAAC,CAAC;QACzF;IACF;IAEA,MAAM,GAAGG,UAAU,GAAGH,UAAUI,KAAK,CAACtB,sBAAsBkB,UAAUI,KAAK,CAACvB,kBAAkB,EAAE;IAChG,IAAI,CAACsB,WAAW;QACdlB,OAAOc,IAAI,CACT;YACE,CAAC,qBAAqB,EAAE7B,kCAAkC,iBAAiB,CAAC;YAC5E,CAAC,GAAG,EAAEA,kCAAkC,uCAAuC,EAAE8B,UAAU,GAAG,CAAC;YAC/F,CAAC,4CAA4C,EAAE1B,mBAAmB,0CAA0C,CAAC;SAC9G,CAACsB,IAAI,CAAC;QAET;IACF;IACA,OAAO;QACLS,UAAUL;QACVG;IACF;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,eAAeG,SAASC,GAAY;IACzC,IAAIA,QAAQT,WAAW;QACrB,OAAOS;IACT;IAEA,IAAI,CAACA,KAAK;QACR,MAAM,IAAIxC,SAAS;IACrB;IAEA,IAAIwC,IAAIC,QAAQ,CAAC,MAAM;QACrB,MAAM,IAAIzC,SAAS,CAAC,yCAAyC,EAAEwC,IAAI,CAAC,CAAC;IACvE;IAEA,IAAI,CAAChC,qBAAqB0B,IAAI,CAACM,MAAM;QACnC,MAAM,IAAIxC,SACR,CAAC,oCAAoC,EAAEO,mBAAmB,aAAa,EAAEiC,IAAI,CAAC,CAAC;IAEnF;IAEA,IAAIA,IAAIL,UAAU,CAAC,MAAM;QACvB,MAAM,IAAInC,SAAS,CAAC,yCAAyC,EAAEwC,IAAI,CAAC,CAAC;IACvE;IAEA,OAAOA;AACT;AAEA,OAAO,MAAME,8BACX,6HAA4H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/actions/schema/utils/uniqByProjectIdDataset.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/actions/schema/utils/uniqByProjectIdDataset.ts"],"sourcesContent":["import uniqBy from 'lodash-es/uniqBy.js'\nimport {type Workspace} from 'sanity'\n\nexport function uniqByProjectIdDataset(workspaces: Workspace[]) {\n return uniqBy<Workspace & {key: string}>(\n workspaces.map((w) => ({\n ...w,\n key: `${w.projectId}-${w.dataset}`,\n })),\n 'key',\n )\n}\n"],"names":["uniqBy","uniqByProjectIdDataset","workspaces","map","w","key","projectId","dataset"],"mappings":"AAAA,OAAOA,YAAY,sBAAqB;AAGxC,OAAO,SAASC,uBAAuBC,UAAuB;IAC5D,OAAOF,OACLE,WAAWC,GAAG,CAAC,CAACC,IAAO,CAAA;YACrB,GAAGA,CAAC;YACJC,KAAK,GAAGD,EAAEE,SAAS,CAAC,CAAC,EAAEF,EAAEG,OAAO,EAAE;QACpC,CAAA,IACA;AAEJ"}
|
|
@@ -2,6 +2,7 @@ import { isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
|
2
2
|
import { findStudioConfigPath, getStudioWorkspaces } from '@sanity/cli-core';
|
|
3
3
|
import { DescriptorConverter } from '@sanity/schema/_internal';
|
|
4
4
|
import { getWorkspace } from '../../util/getWorkspace.js';
|
|
5
|
+
import { isSchemaError } from '../../util/isSchemaError.js';
|
|
5
6
|
const { debugSerialize, level = 'warning', workDir, workspace: workspaceName } = workerData;
|
|
6
7
|
async function main() {
|
|
7
8
|
if (isMainThread || !parentPort) {
|
|
@@ -80,9 +81,6 @@ function getSerializedSchemaDebug(set) {
|
|
|
80
81
|
function isEncodableObject(val) {
|
|
81
82
|
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
|
82
83
|
}
|
|
83
|
-
function isSchemaError(err) {
|
|
84
|
-
return err !== null && typeof err === 'object' && 'schema' in err && err.schema !== null && typeof err.schema === 'object' && '_validation' in err.schema;
|
|
85
|
-
}
|
|
86
84
|
function getSerializedTypeDebug(typeDef) {
|
|
87
85
|
const ext = typeof typeDef.extends === 'string' ? typeDef.extends : '<unknown>';
|
|
88
86
|
let fields;
|
|
@@ -115,10 +113,5 @@ function getSerializedTypeDebug(typeDef) {
|
|
|
115
113
|
};
|
|
116
114
|
}
|
|
117
115
|
await main();
|
|
118
|
-
// Explicitly exit the process to avoid any dangling references from keeping
|
|
119
|
-
// the process alive after resolving it's main task
|
|
120
|
-
setImmediate(()=>{
|
|
121
|
-
process.exit(1);
|
|
122
|
-
});
|
|
123
116
|
|
|
124
117
|
//# sourceMappingURL=validateSchema.worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/schema/validateSchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getStudioWorkspaces} from '@sanity/cli-core'\nimport {\n type EncodableObject,\n type EncodableValue,\n type SetSynchronization,\n} from '@sanity/descriptors'\nimport {DescriptorConverter} from '@sanity/schema/_internal'\nimport {\n type Schema,\n type SchemaValidationProblem,\n type SchemaValidationProblemGroup,\n} from '@sanity/types'\n\nimport {getWorkspace} from '../../util/getWorkspace.js'\nimport {type SerializedSchemaDebug, type SerializedTypeDebug} from './types.js'\n\n/** @internal */\nexport interface ValidateSchemaWorkerData {\n workDir: string\n\n debugSerialize?: boolean\n level?: SchemaValidationProblem['severity']\n workspace?: string\n}\n\n/** @internal */\nexport interface ValidateSchemaWorkerResult {\n validation: SchemaValidationProblemGroup[]\n\n serializedDebug?: SerializedSchemaDebug\n}\n\nconst {\n debugSerialize,\n level = 'warning',\n workDir,\n workspace: workspaceName,\n} = workerData as ValidateSchemaWorkerData\n\nasync function main() {\n if (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n }\n\n try {\n const configPath = await findStudioConfigPath(workDir)\n const workspaces = await getStudioWorkspaces(configPath)\n const workspace = getWorkspace(workspaces, workspaceName)\n const schema = workspace.schema\n parentPort?.postMessage(await resultFromSchema(schema))\n } catch (err: unknown) {\n if (isSchemaError(err)) {\n parentPort?.postMessage(await resultFromSchema(err.schema))\n return\n }\n\n throw err\n }\n}\n\nasync function resultFromSchema(schema: Schema): Promise<ValidateSchemaWorkerResult> {\n let serializedDebug: ValidateSchemaWorkerResult['serializedDebug']\n\n if (debugSerialize) {\n const conv = new DescriptorConverter()\n const set = await conv.get(schema)\n serializedDebug = getSerializedSchemaDebug(set)\n }\n\n const validation = schema._validation ?? []\n\n const result: ValidateSchemaWorkerResult = {\n serializedDebug,\n validation: validation\n .map((group) => ({\n ...group,\n problems: group.problems.filter((problem) =>\n level === 'error' ? problem.severity === 'error' : true,\n ),\n }))\n .filter((group) => group.problems.length),\n }\n\n return result\n}\n\nfunction getSerializedSchemaDebug(set: SetSynchronization<string>): SerializedSchemaDebug {\n let size = 0\n const types: Record<string, SerializedTypeDebug> = {}\n const hoisted: Record<string, SerializedTypeDebug> = {}\n\n for (const [id, value] of Object.entries(set.objectValues)) {\n const descType = typeof value.type === 'string' ? value.type : '<unknown>'\n switch (descType) {\n case 'sanity.schema.hoisted': {\n const key = typeof value.key === 'string' ? value.key : id\n // The `hoisted` can technically hoist _anything_,\n // but we detect the common case of field + array element.\n if (isEncodableObject(value.value) && isEncodableObject(value.value.typeDef)) {\n const debug = getSerializedTypeDebug(value.value.typeDef)\n hoisted[key] = debug\n size += debug.size\n }\n break\n }\n case 'sanity.schema.namedType': {\n const typeName = typeof value.name === 'string' ? value.name : id\n if (isEncodableObject(value.typeDef)) {\n const debug = getSerializedTypeDebug(value.typeDef)\n types[typeName] = debug\n size += debug.size\n }\n break\n }\n default:\n }\n size += JSON.stringify(value).length\n }\n\n return {\n hoisted,\n size,\n types,\n }\n}\n\nfunction isEncodableObject(val: EncodableValue | undefined): val is EncodableObject {\n return typeof val === 'object' && val !== null && !Array.isArray(val)\n}\n\nfunction
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/schema/validateSchema.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getStudioWorkspaces} from '@sanity/cli-core'\nimport {\n type EncodableObject,\n type EncodableValue,\n type SetSynchronization,\n} from '@sanity/descriptors'\nimport {DescriptorConverter} from '@sanity/schema/_internal'\nimport {\n type Schema,\n type SchemaValidationProblem,\n type SchemaValidationProblemGroup,\n} from '@sanity/types'\n\nimport {getWorkspace} from '../../util/getWorkspace.js'\nimport {isSchemaError} from '../../util/isSchemaError.js'\nimport {type SerializedSchemaDebug, type SerializedTypeDebug} from './types.js'\n\n/** @internal */\nexport interface ValidateSchemaWorkerData {\n workDir: string\n\n debugSerialize?: boolean\n level?: SchemaValidationProblem['severity']\n workspace?: string\n}\n\n/** @internal */\nexport interface ValidateSchemaWorkerResult {\n validation: SchemaValidationProblemGroup[]\n\n serializedDebug?: SerializedSchemaDebug\n}\n\nconst {\n debugSerialize,\n level = 'warning',\n workDir,\n workspace: workspaceName,\n} = workerData as ValidateSchemaWorkerData\n\nasync function main() {\n if (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n }\n\n try {\n const configPath = await findStudioConfigPath(workDir)\n const workspaces = await getStudioWorkspaces(configPath)\n const workspace = getWorkspace(workspaces, workspaceName)\n const schema = workspace.schema\n parentPort?.postMessage(await resultFromSchema(schema))\n } catch (err: unknown) {\n if (isSchemaError(err)) {\n parentPort?.postMessage(await resultFromSchema(err.schema))\n return\n }\n\n throw err\n }\n}\n\nasync function resultFromSchema(schema: Schema): Promise<ValidateSchemaWorkerResult> {\n let serializedDebug: ValidateSchemaWorkerResult['serializedDebug']\n\n if (debugSerialize) {\n const conv = new DescriptorConverter()\n const set = await conv.get(schema)\n serializedDebug = getSerializedSchemaDebug(set)\n }\n\n const validation = schema._validation ?? []\n\n const result: ValidateSchemaWorkerResult = {\n serializedDebug,\n validation: validation\n .map((group) => ({\n ...group,\n problems: group.problems.filter((problem) =>\n level === 'error' ? problem.severity === 'error' : true,\n ),\n }))\n .filter((group) => group.problems.length),\n }\n\n return result\n}\n\nfunction getSerializedSchemaDebug(set: SetSynchronization<string>): SerializedSchemaDebug {\n let size = 0\n const types: Record<string, SerializedTypeDebug> = {}\n const hoisted: Record<string, SerializedTypeDebug> = {}\n\n for (const [id, value] of Object.entries(set.objectValues)) {\n const descType = typeof value.type === 'string' ? value.type : '<unknown>'\n switch (descType) {\n case 'sanity.schema.hoisted': {\n const key = typeof value.key === 'string' ? value.key : id\n // The `hoisted` can technically hoist _anything_,\n // but we detect the common case of field + array element.\n if (isEncodableObject(value.value) && isEncodableObject(value.value.typeDef)) {\n const debug = getSerializedTypeDebug(value.value.typeDef)\n hoisted[key] = debug\n size += debug.size\n }\n break\n }\n case 'sanity.schema.namedType': {\n const typeName = typeof value.name === 'string' ? value.name : id\n if (isEncodableObject(value.typeDef)) {\n const debug = getSerializedTypeDebug(value.typeDef)\n types[typeName] = debug\n size += debug.size\n }\n break\n }\n default:\n }\n size += JSON.stringify(value).length\n }\n\n return {\n hoisted,\n size,\n types,\n }\n}\n\nfunction isEncodableObject(val: EncodableValue | undefined): val is EncodableObject {\n return typeof val === 'object' && val !== null && !Array.isArray(val)\n}\n\nfunction getSerializedTypeDebug(typeDef: EncodableObject): SerializedTypeDebug {\n const ext = typeof typeDef.extends === 'string' ? typeDef.extends : '<unknown>'\n let fields: SerializedTypeDebug['fields']\n let of: SerializedTypeDebug['of']\n\n if (Array.isArray(typeDef.fields)) {\n fields = {}\n\n for (const field of typeDef.fields) {\n if (!isEncodableObject(field)) continue\n const name = field.name\n const fieldTypeDef = field.typeDef\n if (typeof name !== 'string' || !isEncodableObject(fieldTypeDef)) continue\n\n fields[name] = getSerializedTypeDebug(fieldTypeDef)\n }\n }\n\n if (Array.isArray(typeDef.of)) {\n of = {}\n\n for (const field of typeDef.of) {\n if (!isEncodableObject(field)) continue\n const name = field.name\n const arrayTypeDef = field.typeDef\n if (typeof name !== 'string' || !isEncodableObject(arrayTypeDef)) continue\n\n of[name] = getSerializedTypeDebug(arrayTypeDef)\n }\n }\n\n return {\n extends: ext,\n fields,\n of,\n size: JSON.stringify(typeDef).length,\n }\n}\n\nawait main()\n"],"names":["isMainThread","parentPort","workerData","findStudioConfigPath","getStudioWorkspaces","DescriptorConverter","getWorkspace","isSchemaError","debugSerialize","level","workDir","workspace","workspaceName","main","Error","configPath","workspaces","schema","postMessage","resultFromSchema","err","serializedDebug","conv","set","get","getSerializedSchemaDebug","validation","_validation","result","map","group","problems","filter","problem","severity","length","size","types","hoisted","id","value","Object","entries","objectValues","descType","type","key","isEncodableObject","typeDef","debug","getSerializedTypeDebug","typeName","name","JSON","stringify","val","Array","isArray","ext","extends","fields","of","field","fieldTypeDef","arrayTypeDef"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,oBAAoB,EAAEC,mBAAmB,QAAO,mBAAkB;AAM1E,SAAQC,mBAAmB,QAAO,2BAA0B;AAO5D,SAAQC,YAAY,QAAO,6BAA4B;AACvD,SAAQC,aAAa,QAAO,8BAA6B;AAmBzD,MAAM,EACJC,cAAc,EACdC,QAAQ,SAAS,EACjBC,OAAO,EACPC,WAAWC,aAAa,EACzB,GAAGV;AAEJ,eAAeW;IACb,IAAIb,gBAAgB,CAACC,YAAY;QAC/B,MAAM,IAAIa,MAAM;IAClB;IAEA,IAAI;QACF,MAAMC,aAAa,MAAMZ,qBAAqBO;QAC9C,MAAMM,aAAa,MAAMZ,oBAAoBW;QAC7C,MAAMJ,YAAYL,aAAaU,YAAYJ;QAC3C,MAAMK,SAASN,UAAUM,MAAM;QAC/BhB,YAAYiB,YAAY,MAAMC,iBAAiBF;IACjD,EAAE,OAAOG,KAAc;QACrB,IAAIb,cAAca,MAAM;YACtBnB,YAAYiB,YAAY,MAAMC,iBAAiBC,IAAIH,MAAM;YACzD;QACF;QAEA,MAAMG;IACR;AACF;AAEA,eAAeD,iBAAiBF,MAAc;IAC5C,IAAII;IAEJ,IAAIb,gBAAgB;QAClB,MAAMc,OAAO,IAAIjB;QACjB,MAAMkB,MAAM,MAAMD,KAAKE,GAAG,CAACP;QAC3BI,kBAAkBI,yBAAyBF;IAC7C;IAEA,MAAMG,aAAaT,OAAOU,WAAW,IAAI,EAAE;IA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