@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/manifest/extractWorkspaceManifest.tsx"],"sourcesContent":["import {\n type ArraySchemaType,\n type BlockDefinition,\n type BooleanSchemaType,\n type CrossDatasetReferenceSchemaType,\n type FileSchemaType,\n type GlobalDocumentReferenceSchemaType,\n type MultiFieldSet,\n type NumberSchemaType,\n type ObjectField,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type Rule,\n type RuleSpec,\n type Schema,\n type SchemaType,\n type SchemaValidationValue,\n type SpanSchemaType,\n type StringSchemaType,\n} from '@sanity/types'\nimport DOMPurify from 'isomorphic-dompurify'\nimport startCase from 'lodash-es/startCase.js'\nimport {renderToString} from 'react-dom/server'\nimport {ConcreteRuleClass, createSchema, type Workspace} from 'sanity'\nimport {ServerStyleSheet} from 'styled-components'\n\nimport {config} from './purifyConfig.js'\nimport {SchemaIcon, type SchemaIconProps} from './SchemaIcon.js'\nimport {\n getCustomFields,\n getDefinedTypeName,\n isCrossDatasetReference,\n isCustomized,\n isDefined,\n isGlobalDocumentReference,\n isPrimitive,\n isRecord,\n isReference,\n isString,\n isType,\n} from './schemaTypeHelpers.js'\nimport {\n type CreateWorkspaceManifest,\n type ManifestField,\n type ManifestFieldset,\n type ManifestSchemaType,\n type ManifestSerializable,\n type ManifestTitledValue,\n type ManifestTool,\n type ManifestValidationGroup,\n type ManifestValidationRule,\n} from './types'\n\ninterface Context {\n schema: Schema\n}\n\ntype SchemaTypeKey =\n | 'group' // we strip this from fields\n | keyof ArraySchemaType\n | keyof BlockDefinition\n | keyof BooleanSchemaType\n | keyof FileSchemaType\n | keyof NumberSchemaType\n | keyof ObjectSchemaType\n | keyof ReferenceSchemaType\n | keyof StringSchemaType\n\ntype Validation = Record<string, never> | {validation: ManifestValidationGroup[]}\ntype ObjectFields = Record<string, never> | {fields: ManifestField[]}\ntype SerializableProp = ManifestSerializable | ManifestSerializable[] | undefined\ntype ManifestValidationFlag = ManifestValidationRule['flag']\ntype ValidationRuleTransformer = (rule: RuleSpec) => ManifestValidationRule | undefined\n\nconst MAX_CUSTOM_PROPERTY_DEPTH = 5\n\nexport function extractWorkspaceManifest(workspaces: Workspace[]): CreateWorkspaceManifest[] {\n return workspaces.map((workspace) => {\n const serializedSchema = extractManifestSchemaTypes(workspace.schema as Schema)\n const serializedTools = extractManifestTools(workspace.tools)\n\n return {\n basePath: workspace.basePath,\n dataset: workspace.dataset,\n icon: resolveIcon({\n icon: workspace.icon,\n subtitle: workspace.subtitle,\n title: workspace.title,\n }),\n mediaLibrary: workspace.mediaLibrary,\n name: workspace.name,\n projectId: workspace.projectId,\n schema: serializedSchema,\n subtitle: workspace.subtitle,\n title: workspace.title,\n tools: serializedTools,\n }\n })\n}\n\n/**\n * Extracts all serializable properties from userland schema types,\n * so they best-effort can be used as definitions for Schema.compile\n. */\nfunction extractManifestSchemaTypes(schema: Schema): ManifestSchemaType[] {\n const typeNames = schema.getTypeNames()\n const context = {schema}\n\n const studioDefaultTypeNames = createSchema({name: 'default', types: []}).getTypeNames()\n\n return typeNames\n .filter((typeName) => !studioDefaultTypeNames.includes(typeName))\n .map((typeName) => schema.get(typeName))\n .filter((type): type is SchemaType => type !== undefined)\n .map((type) => transformType(type, context))\n}\n\nfunction transformCommonTypeFields(\n type: SchemaType & {fieldset?: string},\n typeName: string,\n context: Context,\n): Omit<ManifestSchemaType, 'name' | 'title' | 'type'> {\n const arrayProps =\n typeName === 'array' && type.jsonType === 'array' ? transformArrayMember(type, context) : {}\n\n const referenceProps = isReference(type) ? transformReference(type) : {}\n const crossDatasetRefProps = isCrossDatasetReference(type)\n ? transformCrossDatasetReference(type)\n : {}\n const globalRefProps = isGlobalDocumentReference(type)\n ? transformGlobalDocumentReference(type)\n : {}\n\n const objectFields: ObjectFields =\n type.jsonType === 'object' && type.type && isCustomized(type)\n ? {\n fields: getCustomFields(type).map((objectField) => transformField(objectField, context)),\n }\n : {}\n\n return {\n ...retainCustomTypeProps(type),\n ...transformValidation(type.validation),\n ...ensureString('description', type.description),\n ...objectFields,\n ...arrayProps,\n ...referenceProps,\n ...crossDatasetRefProps,\n ...globalRefProps,\n ...ensureConditional('readOnly', type.readOnly),\n ...ensureConditional('hidden', type.hidden),\n ...transformFieldsets(type),\n // fieldset prop gets instrumented via getCustomFields\n ...ensureString('fieldset', type.fieldset),\n ...transformBlockType(type, context),\n }\n}\n\nfunction transformFieldsets(\n type: SchemaType,\n): Record<string, never> | {fieldsets: ManifestFieldset[]} {\n if (type.jsonType !== 'object') {\n return {}\n }\n const fieldsets = type.fieldsets\n ?.filter((fs): fs is MultiFieldSet => !fs.single)\n .map((fs) => {\n const options = isRecord(fs.options) ? {options: retainSerializableProps(fs.options)} : {}\n return {\n name: fs.name,\n ...ensureCustomTitle(fs.name, fs.title),\n ...ensureString('description', fs.description),\n ...ensureConditional('readOnly', fs.readOnly),\n ...ensureConditional('hidden', fs.hidden),\n ...options,\n }\n })\n\n return fieldsets?.length ? {fieldsets} : {}\n}\n\nfunction transformType(type: SchemaType, context: Context): ManifestSchemaType {\n const typeName = type.type ? type.type.name : type.jsonType\n\n return {\n ...transformCommonTypeFields(type, typeName, context),\n name: type.name,\n type: typeName,\n ...ensureCustomTitle(type.name, type.title),\n }\n}\n\nfunction retainCustomTypeProps(type: SchemaType): Record<string, SerializableProp> {\n const manuallySerializedFields = new Set<SchemaTypeKey>([\n '__experimental_actions',\n '__experimental_formPreviewTitle',\n '__experimental_omnisearch_visibility',\n '__experimental_search',\n 'components',\n 'description',\n 'fields',\n 'fieldsets',\n //only exists on fields\n 'group',\n 'groups',\n 'hidden',\n 'icon',\n 'jsonType',\n //explicitly added\n 'name',\n 'of',\n 'orderings',\n 'preview',\n 'readOnly',\n 'title',\n 'to',\n // not serialized\n 'type',\n 'validation',\n // we know about these, but let them be generically handled\n // deprecated\n // rows (from text)\n // initialValue\n // options\n // crossDatasetReference props\n ])\n const typeWithoutManuallyHandledFields = Object.fromEntries(\n Object.entries(type).filter(\n ([key]) => !manuallySerializedFields.has(key as unknown as SchemaTypeKey),\n ),\n )\n return retainSerializableProps(typeWithoutManuallyHandledFields) as Record<\n string,\n SerializableProp\n >\n}\n\nfunction retainSerializableProps(maybeSerializable: unknown, depth = 0): SerializableProp {\n if (depth > MAX_CUSTOM_PROPERTY_DEPTH) {\n return undefined\n }\n\n if (!isDefined(maybeSerializable)) {\n return undefined\n }\n\n if (isPrimitive(maybeSerializable)) {\n // cull empty strings\n if (maybeSerializable === '') {\n return undefined\n }\n return maybeSerializable\n }\n\n // url-schemes ect..\n if (maybeSerializable instanceof RegExp) {\n return maybeSerializable.toString()\n }\n\n if (Array.isArray(maybeSerializable)) {\n const arrayItems = maybeSerializable\n .map((item) => retainSerializableProps(item, depth + 1))\n .filter((item): item is ManifestSerializable => isDefined(item))\n return arrayItems.length > 0 ? arrayItems : undefined\n }\n\n if (isRecord(maybeSerializable)) {\n const serializableEntries = Object.entries(maybeSerializable)\n .map(([key, value]) => {\n return [key, retainSerializableProps(value, depth + 1)]\n })\n .filter(([, value]) => isDefined(value))\n return serializableEntries.length > 0 ? Object.fromEntries(serializableEntries) : undefined\n }\n\n return undefined\n}\n\nfunction transformField(field: ObjectField & {fieldset?: string}, context: Context): ManifestField {\n const fieldType = field.type\n const typeName = getDefinedTypeName(fieldType) ?? fieldType.name\n return {\n ...transformCommonTypeFields(fieldType, typeName, context),\n name: field.name,\n type: typeName,\n ...ensureCustomTitle(field.name, fieldType.title),\n // this prop gets added synthetically via getCustomFields\n ...ensureString('fieldset', field.fieldset),\n }\n}\n\nfunction transformArrayMember(\n arrayMember: ArraySchemaType,\n context: Context,\n): Pick<ManifestField, 'of'> {\n return {\n of: arrayMember.of.map((type) => {\n const typeName = getDefinedTypeName(type) ?? type.name\n return {\n ...transformCommonTypeFields(type, typeName, context),\n type: typeName,\n ...(typeName === type.name ? {} : {name: type.name}),\n ...ensureCustomTitle(type.name, type.title),\n }\n }),\n }\n}\n\nfunction transformReference(reference: ReferenceSchemaType): Pick<ManifestSchemaType, 'to'> {\n return {\n to: (reference.to ?? []).map((type) => {\n return {\n ...retainCustomTypeProps(type),\n type: type.name,\n }\n }),\n }\n}\n\nfunction transformCrossDatasetReference(\n reference: CrossDatasetReferenceSchemaType,\n): Pick<ManifestSchemaType, 'preview' | 'to'> {\n return {\n to: (reference.to ?? []).map((crossDataset) => {\n const preview = crossDataset.preview?.select\n ? {preview: {select: crossDataset.preview.select}}\n : {}\n return {\n type: crossDataset.type,\n ...ensureCustomTitle(crossDataset.type, crossDataset.title),\n ...preview,\n }\n }),\n }\n}\n\nfunction transformGlobalDocumentReference(\n reference: GlobalDocumentReferenceSchemaType,\n): Pick<ManifestSchemaType, 'preview' | 'to'> {\n return {\n to: (reference.to ?? []).map((crossDataset) => {\n const preview = crossDataset.preview?.select\n ? {preview: {select: crossDataset.preview.select}}\n : {}\n return {\n type: crossDataset.type,\n ...ensureCustomTitle(crossDataset.type, crossDataset.title),\n ...preview,\n }\n }),\n }\n}\n\nconst transformTypeValidationRule: ValidationRuleTransformer = (rule) => {\n return {\n ...rule,\n constraint:\n 'constraint' in rule &&\n (typeof rule.constraint === 'string'\n ? rule.constraint.toLowerCase()\n : retainSerializableProps(rule.constraint)),\n }\n}\n\nconst validationRuleTransformers: Partial<\n Record<ManifestValidationFlag, ValidationRuleTransformer>\n> = {\n type: transformTypeValidationRule,\n}\n\nfunction transformValidation(validation: SchemaValidationValue): Validation {\n const validationArray = (Array.isArray(validation) ? validation : [validation]).filter(\n (value): value is Rule => typeof value === 'object' && '_type' in value,\n )\n\n // we dont want type in the output as that is implicitly given by the typedef itself an will only bloat the payload\n const disallowedFlags = new Set(['type'])\n\n // Validation rules that refer to other fields use symbols, which cannot be serialized. It would\n // be possible to transform these to a serializable type, but we haven't implemented that for now.\n const disallowedConstraintTypes = new Set<symbol | unknown>([ConcreteRuleClass.FIELD_REF])\n\n const serializedValidation = validationArray\n .map(({_level, _message, _rules}) => {\n const message: Partial<Pick<ManifestValidationGroup, 'message'>> =\n typeof _message === 'string' ? {message: _message} : {}\n\n const serializedRules = _rules\n .filter((rule) => {\n if (!('constraint' in rule)) {\n return false\n }\n\n const {constraint, flag} = rule\n\n if (disallowedFlags.has(flag)) {\n return false\n }\n\n return !(\n typeof constraint === 'object' &&\n 'type' in constraint &&\n disallowedConstraintTypes.has(constraint.type)\n )\n })\n .map((rule) => {\n const transformer: ValidationRuleTransformer =\n validationRuleTransformers[rule.flag] ??\n ((spec) => retainSerializableProps(spec) as ManifestValidationRule)\n\n const transformedRule = transformer(rule)\n\n if (!transformedRule) {\n return\n }\n\n return transformedRule\n })\n .filter((rule) => rule !== undefined)\n\n return {\n level: _level,\n rules: serializedRules,\n ...message,\n }\n })\n .filter((group) => group.rules.length > 0)\n\n return serializedValidation.length > 0 ? {validation: serializedValidation} : {}\n}\n\nfunction ensureCustomTitle(typeName: string, value: unknown) {\n const titleObject = ensureString('title', value)\n\n const defaultTitle = startCase(typeName)\n // omit title if its the same as default, to reduce payload\n if (titleObject.title === defaultTitle) {\n return {}\n }\n return titleObject\n}\n\nfunction ensureString<Key extends string>(key: Key, value: unknown) {\n if (typeof value === 'string') {\n return {\n [key]: value,\n }\n }\n\n return {}\n}\n\nfunction ensureConditional<const Key extends string>(key: Key, value: unknown) {\n if (typeof value === 'boolean') {\n return {\n [key]: value,\n }\n }\n\n if (typeof value === 'function') {\n return {\n [key]: 'conditional',\n }\n }\n\n return {}\n}\n\nfunction transformBlockType(\n blockType: SchemaType,\n context: Context,\n): Pick<ManifestSchemaType, 'lists' | 'marks' | 'of' | 'styles'> | Record<string, never> {\n if (blockType.jsonType !== 'object' || !isType(blockType, 'block')) {\n return {}\n }\n\n const childrenField = blockType.fields?.find((field) => field.name === 'children') as\n | {type: ArraySchemaType}\n | undefined\n\n if (!childrenField) {\n return {}\n }\n const ofType = childrenField.type.of\n if (!ofType) {\n return {}\n }\n const spanType = ofType.find((memberType) => memberType.name === 'span') as\n | ObjectSchemaType\n | undefined\n if (!spanType) {\n return {}\n }\n const inlineObjectTypes = (ofType.filter((memberType) => memberType.name !== 'span') ||\n []) as ObjectSchemaType[]\n\n return {\n lists: resolveEnabledListItems(blockType),\n marks: {\n annotations: (spanType as SpanSchemaType).annotations.map((t) => transformType(t, context)),\n decorators: resolveEnabledDecorators(spanType),\n },\n of: inlineObjectTypes.map((t) => transformType(t, context)),\n styles: resolveEnabledStyles(blockType),\n }\n}\n\nfunction resolveEnabledStyles(blockType: ObjectSchemaType): ManifestTitledValue[] | undefined {\n const styleField = blockType.fields?.find((btField) => btField.name === 'style')\n return resolveTitleValueArray(styleField?.type?.options?.list)\n}\n\nfunction resolveEnabledDecorators(spanType: ObjectSchemaType): ManifestTitledValue[] | undefined {\n return 'decorators' in spanType ? resolveTitleValueArray(spanType.decorators) : undefined\n}\n\nfunction resolveEnabledListItems(blockType: ObjectSchemaType): ManifestTitledValue[] | undefined {\n const listField = blockType.fields?.find((btField) => btField.name === 'listItem')\n return resolveTitleValueArray(listField?.type?.options?.list)\n}\n\nfunction resolveTitleValueArray(possibleArray: unknown): ManifestTitledValue[] | undefined {\n if (!possibleArray || !Array.isArray(possibleArray)) {\n return undefined\n }\n const titledValues = possibleArray\n .filter(\n (d): d is {title?: string; value: string} => isRecord(d) && !!d.value && isString(d.value),\n )\n .map((item) => {\n return {\n value: item.value,\n ...ensureString('title', item.title),\n } satisfies ManifestTitledValue\n })\n if (!titledValues?.length) {\n return undefined\n }\n\n return titledValues\n}\n\nconst extractManifestTools = (tools: Workspace['tools']): ManifestTool[] =>\n tools.map((tool) => {\n const {\n __internalApplicationType: type,\n icon,\n name,\n title,\n } = tool as Workspace['tools'][number] & {__internalApplicationType: string}\n return {\n icon: resolveIcon({\n icon: icon as SchemaIconProps['icon'],\n title,\n }),\n name,\n title,\n type: type || null,\n } satisfies ManifestTool\n })\n\nconst resolveIcon = (props: SchemaIconProps): string | null => {\n const sheet = new ServerStyleSheet()\n\n try {\n /**\n * You must render the element first so\n * the style-sheet above can be populated\n */\n const element = renderToString(sheet.collectStyles(<SchemaIcon {...props} />))\n const styleTags = sheet.getStyleTags()\n\n /**\n * We can then create a single string\n * of HTML combining our styles and element\n * before purifying below.\n */\n const html = `${styleTags}${element}`.trim()\n\n return DOMPurify.sanitize(html, config)\n } catch {\n return null\n } finally {\n sheet.seal()\n }\n}\n"],"names":["DOMPurify","startCase","renderToString","ConcreteRuleClass","createSchema","ServerStyleSheet","config","SchemaIcon","getCustomFields","getDefinedTypeName","isCrossDatasetReference","isCustomized","isDefined","isGlobalDocumentReference","isPrimitive","isRecord","isReference","isString","isType","MAX_CUSTOM_PROPERTY_DEPTH","extractWorkspaceManifest","workspaces","map","workspace","serializedSchema","extractManifestSchemaTypes","schema","serializedTools","extractManifestTools","tools","basePath","dataset","icon","resolveIcon","subtitle","title","mediaLibrary","name","projectId","typeNames","getTypeNames","context","studioDefaultTypeNames","types","filter","typeName","includes","get","type","undefined","transformType","transformCommonTypeFields","arrayProps","jsonType","transformArrayMember","referenceProps","transformReference","crossDatasetRefProps","transformCrossDatasetReference","globalRefProps","transformGlobalDocumentReference","objectFields","fields","objectField","transformField","retainCustomTypeProps","transformValidation","validation","ensureString","description","ensureConditional","readOnly","hidden","transformFieldsets","fieldset","transformBlockType","fieldsets","fs","single","options","retainSerializableProps","ensureCustomTitle","length","manuallySerializedFields","Set","typeWithoutManuallyHandledFields","Object","fromEntries","entries","key","has","maybeSerializable","depth","RegExp","toString","Array","isArray","arrayItems","item","serializableEntries","value","field","fieldType","arrayMember","of","reference","to","crossDataset","preview","select","transformTypeValidationRule","rule","constraint","toLowerCase","validationRuleTransformers","validationArray","disallowedFlags","disallowedConstraintTypes","FIELD_REF","serializedValidation","_level","_message","_rules","message","serializedRules","flag","transformer","spec","transformedRule","level","rules","group","titleObject","defaultTitle","blockType","childrenField","find","ofType","spanType","memberType","inlineObjectTypes","lists","resolveEnabledListItems","marks","annotations","t","decorators","resolveEnabledDecorators","styles","resolveEnabledStyles","styleField","btField","resolveTitleValueArray","list","listField","possibleArray","titledValues","d","tool","__internalApplicationType","props","sheet","element","collectStyles","styleTags","getStyleTags","html","trim","sanit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Manifest.ts"],"sourcesContent":["import {resolveLocalPackage} from '@sanity/cli-core'\nimport {type Schema} from '@sanity/types'\nimport {type Workspace} from 'sanity'\n\nimport {resolveIcon} from './iconResolver.js'\nimport {type SchemaIconProps} from './SchemaIcon.js'\nimport {transformType} from './schemaTypeTransformer.js'\nimport {type CreateWorkspaceManifest, type ManifestSchemaType, type ManifestTool} from './types.js'\n\n/**\n * Extracts manifest data from an array of workspaces\n */\nexport function extractWorkspaceManifest(\n workspaces: Workspace[],\n workDir: string,\n): Promise<CreateWorkspaceManifest[]> {\n return Promise.all(\n workspaces.map(async (workspace) => {\n const [icon, serializedSchema, serializedTools] = await Promise.all([\n resolveIcon({\n icon: workspace.icon,\n subtitle: workspace.subtitle,\n title: workspace.title,\n workDir,\n }),\n extractManifestSchemaTypes(workspace.schema as Schema, workDir),\n extractManifestTools(workspace.tools, workDir),\n ])\n\n return {\n basePath: workspace.basePath,\n dataset: workspace.dataset,\n icon,\n mediaLibrary: workspace.mediaLibrary,\n name: workspace.name,\n projectId: workspace.projectId,\n schema: serializedSchema,\n subtitle: workspace.subtitle,\n title: workspace.title,\n tools: serializedTools,\n }\n }),\n )\n}\n\n/**\n * Extracts all serializable properties from userland schema types,\n * so they best-effort can be used as definitions for Schema.compile.\n *\n * @internal\n */\nexport async function extractManifestSchemaTypes(\n schema: Schema,\n workDir: string,\n): Promise<ManifestSchemaType[]> {\n const typeNames = schema.getTypeNames()\n const context = {schema}\n\n const {createSchema} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n\n const studioDefaultTypeNames = createSchema({name: 'default', types: []}).getTypeNames()\n\n return typeNames\n .filter((typeName) => !studioDefaultTypeNames.includes(typeName))\n .map((typeName) => schema.get(typeName))\n .filter((type): type is NonNullable<typeof type> => type !== undefined)\n .map((type) => transformType(type, context))\n}\n\n/**\n * Extracts tool information from workspace tools\n */\nconst extractManifestTools = async (\n tools: Workspace['tools'],\n workDir: string,\n): Promise<ManifestTool[]> =>\n Promise.all(\n tools.map(async (tool) => {\n const {\n __internalApplicationType: type,\n icon,\n name,\n title,\n } = tool as Workspace['tools'][number] & {__internalApplicationType: string}\n return {\n icon: await resolveIcon({\n icon: icon as SchemaIconProps['icon'],\n title,\n workDir,\n }),\n name,\n title,\n type: type || null,\n } satisfies ManifestTool\n }),\n )\n"],"names":["resolveLocalPackage","resolveIcon","transformType","extractWorkspaceManifest","workspaces","workDir","Promise","all","map","workspace","icon","serializedSchema","serializedTools","subtitle","title","extractManifestSchemaTypes","schema","extractManifestTools","tools","basePath","dataset","mediaLibrary","name","projectId","typeNames","getTypeNames","context","createSchema","studioDefaultTypeNames","types","filter","typeName","includes","get","type","undefined","tool","__internalApplicationType"],"mappings":"AAAA,SAAQA,mBAAmB,QAAO,mBAAkB;AAIpD,SAAQC,WAAW,QAAO,oBAAmB;AAE7C,SAAQC,aAAa,QAAO,6BAA4B;AAGxD;;CAEC,GACD,OAAO,SAASC,yBACdC,UAAuB,EACvBC,OAAe;IAEf,OAAOC,QAAQC,GAAG,CAChBH,WAAWI,GAAG,CAAC,OAAOC;QACpB,MAAM,CAACC,MAAMC,kBAAkBC,gBAAgB,GAAG,MAAMN,QAAQC,GAAG,CAAC;YAClEN,YAAY;gBACVS,MAAMD,UAAUC,IAAI;gBACpBG,UAAUJ,UAAUI,QAAQ;gBAC5BC,OAAOL,UAAUK,KAAK;gBACtBT;YACF;YACAU,2BAA2BN,UAAUO,MAAM,EAAYX;YACvDY,qBAAqBR,UAAUS,KAAK,EAAEb;SACvC;QAED,OAAO;YACLc,UAAUV,UAAUU,QAAQ;YAC5BC,SAASX,UAAUW,OAAO;YAC1BV;YACAW,cAAcZ,UAAUY,YAAY;YACpCC,MAAMb,UAAUa,IAAI;YACpBC,WAAWd,UAAUc,SAAS;YAC9BP,QAAQL;YACRE,UAAUJ,UAAUI,QAAQ;YAC5BC,OAAOL,UAAUK,KAAK;YACtBI,OAAON;QACT;IACF;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,eAAeG,2BACpBC,MAAc,EACdX,OAAe;IAEf,MAAMmB,YAAYR,OAAOS,YAAY;IACrC,MAAMC,UAAU;QAACV;IAAM;IAEvB,MAAM,EAACW,YAAY,EAAC,GAAG,MAAM3B,oBAA6C,UAAUK;IAEpF,MAAMuB,yBAAyBD,aAAa;QAACL,MAAM;QAAWO,OAAO,EAAE;IAAA,GAAGJ,YAAY;IAEtF,OAAOD,UACJM,MAAM,CAAC,CAACC,WAAa,CAACH,uBAAuBI,QAAQ,CAACD,WACtDvB,GAAG,CAAC,CAACuB,WAAaf,OAAOiB,GAAG,CAACF,WAC7BD,MAAM,CAAC,CAACI,OAA2CA,SAASC,WAC5D3B,GAAG,CAAC,CAAC0B,OAAShC,cAAcgC,MAAMR;AACvC;AAEA;;CAEC,GACD,MAAMT,uBAAuB,OAC3BC,OACAb,UAEAC,QAAQC,GAAG,CACTW,MAAMV,GAAG,CAAC,OAAO4B;QACf,MAAM,EACJC,2BAA2BH,IAAI,EAC/BxB,IAAI,EACJY,IAAI,EACJR,KAAK,EACN,GAAGsB;QACJ,OAAO;YACL1B,MAAM,MAAMT,YAAY;gBACtBS,MAAMA;gBACNI;gBACAT;YACF;YACAiB;YACAR;YACAoB,MAAMA,QAAQ;QAChB;IACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import DOMPurify from 'isomorphic-dompurify';
|
|
3
|
+
import { renderToReadableStream } from 'react-dom/server';
|
|
4
|
+
import { manifestDebug } from './debug.js';
|
|
5
|
+
import { config } from './purifyConfig.js';
|
|
6
|
+
import { SchemaIcon } from './SchemaIcon.js';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves an icon to a sanitized HTML string.
|
|
9
|
+
* Uses react-dom/server to capture styles during SSR.
|
|
10
|
+
*/ export const resolveIcon = async (props)=>{
|
|
11
|
+
try {
|
|
12
|
+
const stream = await renderToReadableStream(/*#__PURE__*/ _jsx(SchemaIcon, {
|
|
13
|
+
...props
|
|
14
|
+
}));
|
|
15
|
+
const reader = stream.getReader();
|
|
16
|
+
const chunks = [];
|
|
17
|
+
while(true){
|
|
18
|
+
const { done, value } = await reader.read();
|
|
19
|
+
if (done) break;
|
|
20
|
+
chunks.push(value);
|
|
21
|
+
}
|
|
22
|
+
const html = new TextDecoder().decode(Buffer.concat(chunks));
|
|
23
|
+
return DOMPurify.sanitize(html.trim(), config);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
manifestDebug('Error resolving icon', error);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=iconResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/iconResolver.tsx"],"sourcesContent":["import DOMPurify from 'isomorphic-dompurify'\nimport {renderToReadableStream} from 'react-dom/server'\n\nimport {manifestDebug} from './debug.js'\nimport {config} from './purifyConfig.js'\nimport {SchemaIcon, type SchemaIconProps} from './SchemaIcon.js'\n\n/**\n * Resolves an icon to a sanitized HTML string.\n * Uses react-dom/server to capture styles during SSR.\n */\nexport const resolveIcon = async (props: SchemaIconProps): Promise<string | null> => {\n try {\n const stream = await renderToReadableStream(<SchemaIcon {...props} />)\n\n const reader = stream.getReader()\n const chunks: Uint8Array[] = []\n while (true) {\n const {done, value} = await reader.read()\n if (done) break\n chunks.push(value)\n }\n const html = new TextDecoder().decode(Buffer.concat(chunks))\n return DOMPurify.sanitize(html.trim(), config)\n } catch (error) {\n manifestDebug('Error resolving icon', error)\n return null\n }\n}\n"],"names":["DOMPurify","renderToReadableStream","manifestDebug","config","SchemaIcon","resolveIcon","props","stream","reader","getReader","chunks","done","value","read","push","html","TextDecoder","decode","Buffer","concat","sanitize","trim","error"],"mappings":";AAAA,OAAOA,eAAe,uBAAsB;AAC5C,SAAQC,sBAAsB,QAAO,mBAAkB;AAEvD,SAAQC,aAAa,QAAO,aAAY;AACxC,SAAQC,MAAM,QAAO,oBAAmB;AACxC,SAAQC,UAAU,QAA6B,kBAAiB;AAEhE;;;CAGC,GACD,OAAO,MAAMC,cAAc,OAAOC;IAChC,IAAI;QACF,MAAMC,SAAS,MAAMN,qCAAuB,KAACG;YAAY,GAAGE,KAAK;;QAEjE,MAAME,SAASD,OAAOE,SAAS;QAC/B,MAAMC,SAAuB,EAAE;QAC/B,MAAO,KAAM;YACX,MAAM,EAACC,IAAI,EAAEC,KAAK,EAAC,GAAG,MAAMJ,OAAOK,IAAI;YACvC,IAAIF,MAAM;YACVD,OAAOI,IAAI,CAACF;QACd;QACA,MAAMG,OAAO,IAAIC,cAAcC,MAAM,CAACC,OAAOC,MAAM,CAACT;QACpD,OAAOV,UAAUoB,QAAQ,CAACL,KAAKM,IAAI,IAAIlB;IACzC,EAAE,OAAOmB,OAAO;QACdpB,cAAc,wBAAwBoB;QACtC,OAAO;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ensureCustomTitle } from './transformerUtils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms a reference schema type to its manifest representation
|
|
4
|
+
*/ export function transformReference(reference, retainCustomTypeProps) {
|
|
5
|
+
return {
|
|
6
|
+
to: (reference.to ?? []).map((type)=>{
|
|
7
|
+
return {
|
|
8
|
+
...retainCustomTypeProps(type),
|
|
9
|
+
type: type.name
|
|
10
|
+
};
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Transforms a cross-dataset reference schema type to its manifest representation
|
|
16
|
+
*/ export function transformCrossDatasetReference(reference) {
|
|
17
|
+
return {
|
|
18
|
+
to: (reference.to ?? []).map((crossDataset)=>{
|
|
19
|
+
const preview = crossDataset.preview?.select ? {
|
|
20
|
+
preview: {
|
|
21
|
+
select: crossDataset.preview.select
|
|
22
|
+
}
|
|
23
|
+
} : {};
|
|
24
|
+
return {
|
|
25
|
+
type: crossDataset.type,
|
|
26
|
+
...ensureCustomTitle(crossDataset.type, crossDataset.title),
|
|
27
|
+
...preview
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Transforms a global document reference schema type to its manifest representation
|
|
34
|
+
*/ export function transformGlobalDocumentReference(reference) {
|
|
35
|
+
return {
|
|
36
|
+
to: (reference.to ?? []).map((crossDataset)=>{
|
|
37
|
+
const preview = crossDataset.preview?.select ? {
|
|
38
|
+
preview: {
|
|
39
|
+
select: crossDataset.preview.select
|
|
40
|
+
}
|
|
41
|
+
} : {};
|
|
42
|
+
return {
|
|
43
|
+
type: crossDataset.type,
|
|
44
|
+
...ensureCustomTitle(crossDataset.type, crossDataset.title),
|
|
45
|
+
...preview
|
|
46
|
+
};
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=referenceTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/referenceTransformer.ts"],"sourcesContent":["import {\n type CrossDatasetReferenceSchemaType,\n type GlobalDocumentReferenceSchemaType,\n type ReferenceSchemaType,\n type SchemaType,\n} from '@sanity/types'\n\nimport {ensureCustomTitle, type SerializableProp} from './transformerUtils.js'\nimport {type ManifestSchemaType} from './types.js'\n\n/**\n * Transforms a reference schema type to its manifest representation\n */\nexport function transformReference(\n reference: ReferenceSchemaType,\n retainCustomTypeProps: (type: SchemaType) => Record<string, SerializableProp>,\n): Pick<ManifestSchemaType, 'to'> {\n return {\n to: (reference.to ?? []).map((type) => {\n return {\n ...retainCustomTypeProps(type),\n type: type.name,\n }\n }),\n }\n}\n\n/**\n * Transforms a cross-dataset reference schema type to its manifest representation\n */\nexport function transformCrossDatasetReference(\n reference: CrossDatasetReferenceSchemaType,\n): Pick<ManifestSchemaType, 'preview' | 'to'> {\n return {\n to: (reference.to ?? []).map((crossDataset) => {\n const preview = crossDataset.preview?.select\n ? {preview: {select: crossDataset.preview.select}}\n : {}\n return {\n type: crossDataset.type,\n ...ensureCustomTitle(crossDataset.type, crossDataset.title),\n ...preview,\n }\n }),\n }\n}\n\n/**\n * Transforms a global document reference schema type to its manifest representation\n */\nexport function transformGlobalDocumentReference(\n reference: GlobalDocumentReferenceSchemaType,\n): Pick<ManifestSchemaType, 'preview' | 'to'> {\n return {\n to: (reference.to ?? []).map((crossDataset) => {\n const preview = crossDataset.preview?.select\n ? {preview: {select: crossDataset.preview.select}}\n : {}\n return {\n type: crossDataset.type,\n ...ensureCustomTitle(crossDataset.type, crossDataset.title),\n ...preview,\n }\n }),\n }\n}\n"],"names":["ensureCustomTitle","transformReference","reference","retainCustomTypeProps","to","map","type","name","transformCrossDatasetReference","crossDataset","preview","select","title","transformGlobalDocumentReference"],"mappings":"AAOA,SAAQA,iBAAiB,QAA8B,wBAAuB;AAG9E;;CAEC,GACD,OAAO,SAASC,mBACdC,SAA8B,EAC9BC,qBAA6E;IAE7E,OAAO;QACLC,IAAI,AAACF,CAAAA,UAAUE,EAAE,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC;YAC5B,OAAO;gBACL,GAAGH,sBAAsBG,KAAK;gBAC9BA,MAAMA,KAAKC,IAAI;YACjB;QACF;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASC,+BACdN,SAA0C;IAE1C,OAAO;QACLE,IAAI,AAACF,CAAAA,UAAUE,EAAE,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACI;YAC5B,MAAMC,UAAUD,aAAaC,OAAO,EAAEC,SAClC;gBAACD,SAAS;oBAACC,QAAQF,aAAaC,OAAO,CAACC,MAAM;gBAAA;YAAC,IAC/C,CAAC;YACL,OAAO;gBACLL,MAAMG,aAAaH,IAAI;gBACvB,GAAGN,kBAAkBS,aAAaH,IAAI,EAAEG,aAAaG,KAAK,CAAC;gBAC3D,GAAGF,OAAO;YACZ;QACF;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASG,iCACdX,SAA4C;IAE5C,OAAO;QACLE,IAAI,AAACF,CAAAA,UAAUE,EAAE,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACI;YAC5B,MAAMC,UAAUD,aAAaC,OAAO,EAAEC,SAClC;gBAACD,SAAS;oBAACC,QAAQF,aAAaC,OAAO,CAACC,MAAM;gBAAA;YAAC,IAC/C,CAAC;YACL,OAAO;gBACLL,MAAMG,aAAaH,IAAI;gBACvB,GAAGN,kBAAkBS,aAAaH,IAAI,EAAEG,aAAaG,KAAK,CAAC;gBAC3D,GAAGF,OAAO;YACZ;QACF;IACF;AACF"}
|
|
@@ -90,10 +90,10 @@ export function isString(value) {
|
|
|
90
90
|
return typeof value === 'string';
|
|
91
91
|
}
|
|
92
92
|
function isNumber(value) {
|
|
93
|
-
return typeof value === '
|
|
93
|
+
return typeof value === 'number';
|
|
94
94
|
}
|
|
95
95
|
function isBoolean(value) {
|
|
96
|
-
return typeof value === '
|
|
96
|
+
return typeof value === 'boolean';
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* _internal_ownProps contains the _definition_ for the type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/manifest/schemaTypeHelpers.ts"],"sourcesContent":["import {\n type CrossDatasetReferenceSchemaType,\n type GlobalDocumentReferenceSchemaType,\n type ObjectField,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type SchemaType,\n} from '@sanity/types'\n\nconst DEFAULT_IMAGE_FIELDS = new Set(['asset', 'crop', 'hotspot', 'media'])\nconst DEFAULT_FILE_FIELDS = new Set(['asset', 'media'])\nconst DEFAULT_GEOPOINT_FIELDS = new Set(['alt', 'lat', 'lng'])\nconst DEFAULT_SLUG_FIELDS = new Set(['current', 'source'])\n\ntype InternalOwnProps = {fields?: unknown[]; name?: string; type?: string}\n\nexport function getCustomFields(type: ObjectSchemaType): (ObjectField & {fieldset?: string})[] {\n const fields = type.fieldsets\n ? type.fieldsets.flatMap((fs) => {\n if (fs.single) {\n return fs.field\n }\n return fs.fields.map((field) => ({\n ...field,\n fieldset: fs.name,\n }))\n })\n : type.fields\n\n if (isType(type, 'block')) {\n return []\n }\n if (isType(type, 'slug')) {\n return fields.filter((f) => !DEFAULT_SLUG_FIELDS.has(f.name))\n }\n if (isType(type, 'geopoint')) {\n return fields.filter((f) => !DEFAULT_GEOPOINT_FIELDS.has(f.name))\n }\n if (isType(type, 'image')) {\n return fields.filter((f) => !DEFAULT_IMAGE_FIELDS.has(f.name))\n }\n if (isType(type, 'file')) {\n return fields.filter((f) => !DEFAULT_FILE_FIELDS.has(f.name))\n }\n return fields\n}\n\nexport function isReference(type: SchemaType): type is ReferenceSchemaType {\n return isType(type, 'reference')\n}\n\nexport function isCrossDatasetReference(type: SchemaType): type is CrossDatasetReferenceSchemaType {\n return isType(type, 'crossDatasetReference')\n}\n\nexport function isGlobalDocumentReference(\n type: SchemaType,\n): type is GlobalDocumentReferenceSchemaType {\n return isType(type, 'globalDocumentReference')\n}\n\nfunction isObjectField(maybeOjectField: unknown): boolean {\n return (\n typeof maybeOjectField === 'object' && maybeOjectField !== null && 'name' in maybeOjectField\n )\n}\n\nexport function isCustomized(maybeCustomized: SchemaType): boolean {\n const internalOwnProps = getSchemaTypeInternalOwnProps(maybeCustomized)\n\n const hasFieldsArray =\n isObjectField(maybeCustomized) &&\n !isReference(maybeCustomized) &&\n !isCrossDatasetReference(maybeCustomized) &&\n !isGlobalDocumentReference(maybeCustomized) &&\n 'fields' in maybeCustomized &&\n Array.isArray(maybeCustomized.fields) &&\n // needed to differentiate inline, named array object types from globally defined types\n // we only consider it customized if the _definition_ has fields declared\n // this holds for all customizable object-like types: object, document, image and file\n internalOwnProps?.fields\n\n if (!hasFieldsArray) {\n return false\n }\n\n const fields = getCustomFields(maybeCustomized)\n return fields.length > 0\n}\n\nexport function isType(schemaType: SchemaType, typeName: string): boolean {\n if (schemaType.name === typeName) {\n return true\n }\n if (!schemaType.type) {\n return false\n }\n return isType(schemaType.type, typeName)\n}\n\nexport function isDefined<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object'\n}\n\nexport function isPrimitive(value: unknown): value is boolean | number | string {\n return isString(value) || isBoolean(value) || isNumber(value)\n}\n\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === '
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/schemaTypeHelpers.ts"],"sourcesContent":["import {\n type CrossDatasetReferenceSchemaType,\n type GlobalDocumentReferenceSchemaType,\n type ObjectField,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type SchemaType,\n} from '@sanity/types'\n\nconst DEFAULT_IMAGE_FIELDS = new Set(['asset', 'crop', 'hotspot', 'media'])\nconst DEFAULT_FILE_FIELDS = new Set(['asset', 'media'])\nconst DEFAULT_GEOPOINT_FIELDS = new Set(['alt', 'lat', 'lng'])\nconst DEFAULT_SLUG_FIELDS = new Set(['current', 'source'])\n\ntype InternalOwnProps = {fields?: unknown[]; name?: string; type?: string}\n\nexport function getCustomFields(type: ObjectSchemaType): (ObjectField & {fieldset?: string})[] {\n const fields = type.fieldsets\n ? type.fieldsets.flatMap((fs) => {\n if (fs.single) {\n return fs.field\n }\n return fs.fields.map((field) => ({\n ...field,\n fieldset: fs.name,\n }))\n })\n : type.fields\n\n if (isType(type, 'block')) {\n return []\n }\n if (isType(type, 'slug')) {\n return fields.filter((f) => !DEFAULT_SLUG_FIELDS.has(f.name))\n }\n if (isType(type, 'geopoint')) {\n return fields.filter((f) => !DEFAULT_GEOPOINT_FIELDS.has(f.name))\n }\n if (isType(type, 'image')) {\n return fields.filter((f) => !DEFAULT_IMAGE_FIELDS.has(f.name))\n }\n if (isType(type, 'file')) {\n return fields.filter((f) => !DEFAULT_FILE_FIELDS.has(f.name))\n }\n return fields\n}\n\nexport function isReference(type: SchemaType): type is ReferenceSchemaType {\n return isType(type, 'reference')\n}\n\nexport function isCrossDatasetReference(type: SchemaType): type is CrossDatasetReferenceSchemaType {\n return isType(type, 'crossDatasetReference')\n}\n\nexport function isGlobalDocumentReference(\n type: SchemaType,\n): type is GlobalDocumentReferenceSchemaType {\n return isType(type, 'globalDocumentReference')\n}\n\nfunction isObjectField(maybeOjectField: unknown): boolean {\n return (\n typeof maybeOjectField === 'object' && maybeOjectField !== null && 'name' in maybeOjectField\n )\n}\n\nexport function isCustomized(maybeCustomized: SchemaType): boolean {\n const internalOwnProps = getSchemaTypeInternalOwnProps(maybeCustomized)\n\n const hasFieldsArray =\n isObjectField(maybeCustomized) &&\n !isReference(maybeCustomized) &&\n !isCrossDatasetReference(maybeCustomized) &&\n !isGlobalDocumentReference(maybeCustomized) &&\n 'fields' in maybeCustomized &&\n Array.isArray(maybeCustomized.fields) &&\n // needed to differentiate inline, named array object types from globally defined types\n // we only consider it customized if the _definition_ has fields declared\n // this holds for all customizable object-like types: object, document, image and file\n internalOwnProps?.fields\n\n if (!hasFieldsArray) {\n return false\n }\n\n const fields = getCustomFields(maybeCustomized)\n return fields.length > 0\n}\n\nexport function isType(schemaType: SchemaType, typeName: string): boolean {\n if (schemaType.name === typeName) {\n return true\n }\n if (!schemaType.type) {\n return false\n }\n return isType(schemaType.type, typeName)\n}\n\nexport function isDefined<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object'\n}\n\nexport function isPrimitive(value: unknown): value is boolean | number | string {\n return isString(value) || isBoolean(value) || isNumber(value)\n}\n\nexport function isString(value: unknown): value is string {\n return typeof value === 'string'\n}\n\nfunction isNumber(value: unknown): value is number {\n return typeof value === 'number'\n}\n\nfunction isBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean'\n}\n\n/**\n * _internal_ownProps contains the _definition_ for the type.\n * Without it we cannot differentiate inline array item types from globally defined types in array.of\n */\nfunction getSchemaTypeInternalOwnProps(type: SchemaType): InternalOwnProps | undefined {\n return (type as {_internal_ownProps?: InternalOwnProps})?._internal_ownProps\n}\n\n/**\n * This allows us to differentiate inline array.of type definitions vs global type names on compiled schema types\n */\nexport function getDefinedTypeName(type: SchemaType): string | undefined {\n return getSchemaTypeInternalOwnProps(type)?.type\n}\n"],"names":["DEFAULT_IMAGE_FIELDS","Set","DEFAULT_FILE_FIELDS","DEFAULT_GEOPOINT_FIELDS","DEFAULT_SLUG_FIELDS","getCustomFields","type","fields","fieldsets","flatMap","fs","single","field","map","fieldset","name","isType","filter","f","has","isReference","isCrossDatasetReference","isGlobalDocumentReference","isObjectField","maybeOjectField","isCustomized","maybeCustomized","internalOwnProps","getSchemaTypeInternalOwnProps","hasFieldsArray","Array","isArray","length","schemaType","typeName","isDefined","value","undefined","isRecord","isPrimitive","isString","isBoolean","isNumber","_internal_ownProps","getDefinedTypeName"],"mappings":"AASA,MAAMA,uBAAuB,IAAIC,IAAI;IAAC;IAAS;IAAQ;IAAW;CAAQ;AAC1E,MAAMC,sBAAsB,IAAID,IAAI;IAAC;IAAS;CAAQ;AACtD,MAAME,0BAA0B,IAAIF,IAAI;IAAC;IAAO;IAAO;CAAM;AAC7D,MAAMG,sBAAsB,IAAIH,IAAI;IAAC;IAAW;CAAS;AAIzD,OAAO,SAASI,gBAAgBC,IAAsB;IACpD,MAAMC,SAASD,KAAKE,SAAS,GACzBF,KAAKE,SAAS,CAACC,OAAO,CAAC,CAACC;QACtB,IAAIA,GAAGC,MAAM,EAAE;YACb,OAAOD,GAAGE,KAAK;QACjB;QACA,OAAOF,GAAGH,MAAM,CAACM,GAAG,CAAC,CAACD,QAAW,CAAA;gBAC/B,GAAGA,KAAK;gBACRE,UAAUJ,GAAGK,IAAI;YACnB,CAAA;IACF,KACAT,KAAKC,MAAM;IAEf,IAAIS,OAAOV,MAAM,UAAU;QACzB,OAAO,EAAE;IACX;IACA,IAAIU,OAAOV,MAAM,SAAS;QACxB,OAAOC,OAAOU,MAAM,CAAC,CA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UAAU;QAChC,OAAO;IACT;IACA,IAAI,CAACD,WAAW3B,IAAI,EAAE;QACpB,OAAO;IACT;IACA,OAAOU,OAAOiB,WAAW3B,IAAI,EAAE4B;AACjC;AAEA,OAAO,SAASC,UAAaC,KAA2B;IACtD,OAAOA,UAAU,QAAQA,UAAUC;AACrC;AAEA,OAAO,SAASC,SAASF,KAAc;IACrC,OAAO,CAAC,CAACA,SAAS,OAAOA,UAAU;AACrC;AAEA,OAAO,SAASG,YAAYH,KAAc;IACxC,OAAOI,SAASJ,UAAUK,UAAUL,UAAUM,SAASN;AACzD;AAEA,OAAO,SAASI,SAASJ,KAAc;IACrC,OAAO,OAAOA,UAAU;AAC1B;AAEA,SAASM,SAASN,KAAc;IAC9B,OAAO,OAAOA,UAAU;AAC1B;AAEA,SAASK,UAAUL,KAAc;IAC/B,OAAO,OAAOA,UAAU;AAC1B;AAEA;;;CAGC,GACD,SAASR,8BAA8BtB,IAAgB;IACrD,OAAQA,MAAkDqC;AAC5D;AAEA;;CAEC,GACD,OAAO,SAASC,mBAAmBtC,IAAgB;IACjD,OAAOsB,8BAA8BtB,OAAOA;AAC9C"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { transformBlockType } from './blockTypeTransformer.js';
|
|
2
|
+
import { transformCrossDatasetReference, transformGlobalDocumentReference, transformReference } from './referenceTransformer.js';
|
|
3
|
+
import { getCustomFields, getDefinedTypeName, isCrossDatasetReference, isCustomized, isDefined, isGlobalDocumentReference, isPrimitive, isRecord, isReference } from './schemaTypeHelpers.js';
|
|
4
|
+
import { ensureConditional, ensureCustomTitle, ensureString } from './transformerUtils.js';
|
|
5
|
+
import { transformValidation } from './validationTransformer.js';
|
|
6
|
+
const MAX_CUSTOM_PROPERTY_DEPTH = 5;
|
|
7
|
+
/**
|
|
8
|
+
* Transforms a SchemaType to its manifest representation
|
|
9
|
+
*/ export function transformType(type, context) {
|
|
10
|
+
const typeName = type.type ? type.type.name : type.jsonType;
|
|
11
|
+
return {
|
|
12
|
+
...transformCommonTypeFields(type, typeName, context),
|
|
13
|
+
name: type.name,
|
|
14
|
+
type: typeName,
|
|
15
|
+
...ensureCustomTitle(type.name, type.title)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Transforms common fields shared across all schema types
|
|
20
|
+
*/ function transformCommonTypeFields(type, typeName, context) {
|
|
21
|
+
const arrayProps = typeName === 'array' && type.jsonType === 'array' ? transformArrayMember(type, context) : {};
|
|
22
|
+
const referenceProps = isReference(type) ? transformReference(type, retainCustomTypeProps) : {};
|
|
23
|
+
const crossDatasetRefProps = isCrossDatasetReference(type) ? transformCrossDatasetReference(type) : {};
|
|
24
|
+
const globalRefProps = isGlobalDocumentReference(type) ? transformGlobalDocumentReference(type) : {};
|
|
25
|
+
const objectFields = type.jsonType === 'object' && type.type && isCustomized(type) ? {
|
|
26
|
+
fields: getCustomFields(type).map((objectField)=>transformField(objectField, context))
|
|
27
|
+
} : {};
|
|
28
|
+
return {
|
|
29
|
+
...retainCustomTypeProps(type),
|
|
30
|
+
...transformValidation(type.validation, retainSerializableProps),
|
|
31
|
+
...ensureString('description', type.description),
|
|
32
|
+
...objectFields,
|
|
33
|
+
...arrayProps,
|
|
34
|
+
...referenceProps,
|
|
35
|
+
...crossDatasetRefProps,
|
|
36
|
+
...globalRefProps,
|
|
37
|
+
...ensureConditional('readOnly', type.readOnly),
|
|
38
|
+
...ensureConditional('hidden', type.hidden),
|
|
39
|
+
...transformFieldsets(type),
|
|
40
|
+
// fieldset prop gets instrumented via getCustomFields
|
|
41
|
+
...ensureString('fieldset', type.fieldset),
|
|
42
|
+
...transformBlockType(type, context, transformType)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Transforms fieldsets from a schema type
|
|
47
|
+
*/ function transformFieldsets(type) {
|
|
48
|
+
if (type.jsonType !== 'object') {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
const fieldsets = type.fieldsets?.filter((fs)=>!fs.single).map((fs)=>{
|
|
52
|
+
const options = isRecord(fs.options) ? {
|
|
53
|
+
options: retainSerializableProps(fs.options)
|
|
54
|
+
} : {};
|
|
55
|
+
return {
|
|
56
|
+
name: fs.name,
|
|
57
|
+
...ensureCustomTitle(fs.name, fs.title),
|
|
58
|
+
...ensureString('description', fs.description),
|
|
59
|
+
...ensureConditional('readOnly', fs.readOnly),
|
|
60
|
+
...ensureConditional('hidden', fs.hidden),
|
|
61
|
+
...options
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return fieldsets?.length ? {
|
|
65
|
+
fieldsets
|
|
66
|
+
} : {};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Retains custom type properties that should be included in the manifest
|
|
70
|
+
*/ function retainCustomTypeProps(type) {
|
|
71
|
+
const manuallySerializedFields = new Set([
|
|
72
|
+
'__experimental_actions',
|
|
73
|
+
'__experimental_formPreviewTitle',
|
|
74
|
+
'__experimental_omnisearch_visibility',
|
|
75
|
+
'__experimental_search',
|
|
76
|
+
'components',
|
|
77
|
+
'description',
|
|
78
|
+
'fields',
|
|
79
|
+
'fieldsets',
|
|
80
|
+
//only exists on fields
|
|
81
|
+
'group',
|
|
82
|
+
'groups',
|
|
83
|
+
'hidden',
|
|
84
|
+
'icon',
|
|
85
|
+
'jsonType',
|
|
86
|
+
//explicitly added
|
|
87
|
+
'name',
|
|
88
|
+
'of',
|
|
89
|
+
'orderings',
|
|
90
|
+
'preview',
|
|
91
|
+
'readOnly',
|
|
92
|
+
'title',
|
|
93
|
+
'to',
|
|
94
|
+
// not serialized
|
|
95
|
+
'type',
|
|
96
|
+
'validation'
|
|
97
|
+
]);
|
|
98
|
+
const typeWithoutManuallyHandledFields = Object.fromEntries(Object.entries(type).filter(([key])=>!manuallySerializedFields.has(key)));
|
|
99
|
+
return retainSerializableProps(typeWithoutManuallyHandledFields);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Retains serializable properties from an unknown value, recursively processing objects and arrays
|
|
103
|
+
*/ function retainSerializableProps(maybeSerializable, depth = 0) {
|
|
104
|
+
if (depth > MAX_CUSTOM_PROPERTY_DEPTH) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
if (!isDefined(maybeSerializable)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
if (isPrimitive(maybeSerializable)) {
|
|
111
|
+
// cull empty strings
|
|
112
|
+
if (maybeSerializable === '') {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
return maybeSerializable;
|
|
116
|
+
}
|
|
117
|
+
// url-schemes ect..
|
|
118
|
+
if (maybeSerializable instanceof RegExp) {
|
|
119
|
+
return maybeSerializable.toString();
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(maybeSerializable)) {
|
|
122
|
+
const arrayItems = maybeSerializable.map((item)=>retainSerializableProps(item, depth + 1)).filter((item)=>isDefined(item));
|
|
123
|
+
return arrayItems.length > 0 ? arrayItems : undefined;
|
|
124
|
+
}
|
|
125
|
+
if (isRecord(maybeSerializable)) {
|
|
126
|
+
const serializableEntries = Object.entries(maybeSerializable).map(([key, value])=>{
|
|
127
|
+
return [
|
|
128
|
+
key,
|
|
129
|
+
retainSerializableProps(value, depth + 1)
|
|
130
|
+
];
|
|
131
|
+
}).filter(([, value])=>isDefined(value));
|
|
132
|
+
return serializableEntries.length > 0 ? Object.fromEntries(serializableEntries) : undefined;
|
|
133
|
+
}
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Transforms an ObjectField to its manifest representation
|
|
138
|
+
*/ function transformField(field, context) {
|
|
139
|
+
const fieldType = field.type;
|
|
140
|
+
const typeName = getDefinedTypeName(fieldType) ?? fieldType.name;
|
|
141
|
+
return {
|
|
142
|
+
...transformCommonTypeFields(fieldType, typeName, context),
|
|
143
|
+
name: field.name,
|
|
144
|
+
type: typeName,
|
|
145
|
+
...ensureCustomTitle(field.name, fieldType.title),
|
|
146
|
+
// this prop gets added synthetically via getCustomFields
|
|
147
|
+
...ensureString('fieldset', field.fieldset)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Transforms array member types to their manifest representation
|
|
152
|
+
*/ function transformArrayMember(arrayMember, context) {
|
|
153
|
+
return {
|
|
154
|
+
of: arrayMember.of.map((type)=>{
|
|
155
|
+
const typeName = getDefinedTypeName(type) ?? type.name;
|
|
156
|
+
return {
|
|
157
|
+
...transformCommonTypeFields(type, typeName, context),
|
|
158
|
+
type: typeName,
|
|
159
|
+
...typeName === type.name ? {} : {
|
|
160
|
+
name: type.name
|
|
161
|
+
},
|
|
162
|
+
...ensureCustomTitle(type.name, type.title)
|
|
163
|
+
};
|
|
164
|
+
})
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=schemaTypeTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/schemaTypeTransformer.ts"],"sourcesContent":["import {\n type ArraySchemaType,\n type BlockDefinition,\n type BooleanSchemaType,\n type FileSchemaType,\n type MultiFieldSet,\n type NumberSchemaType,\n type ObjectField,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type SchemaType,\n type StringSchemaType,\n} from '@sanity/types'\n\nimport {transformBlockType} from './blockTypeTransformer.js'\nimport {\n transformCrossDatasetReference,\n transformGlobalDocumentReference,\n transformReference,\n} from './referenceTransformer.js'\nimport {\n getCustomFields,\n getDefinedTypeName,\n isCrossDatasetReference,\n isCustomized,\n isDefined,\n isGlobalDocumentReference,\n isPrimitive,\n isRecord,\n isReference,\n} from './schemaTypeHelpers.js'\nimport {\n type Context,\n ensureConditional,\n ensureCustomTitle,\n ensureString,\n type SerializableProp,\n} from './transformerUtils.js'\nimport {\n type ManifestField,\n type ManifestFieldset,\n type ManifestSchemaType,\n type ManifestSerializable,\n} from './types.js'\nimport {transformValidation} from './validationTransformer.js'\n\ntype SchemaTypeKey =\n | 'group' // we strip this from fields\n | keyof ArraySchemaType\n | keyof BlockDefinition\n | keyof BooleanSchemaType\n | keyof FileSchemaType\n | keyof NumberSchemaType\n | keyof ObjectSchemaType\n | keyof ReferenceSchemaType\n | keyof StringSchemaType\n\ntype ObjectFields = Record<string, never> | {fields: ManifestField[]}\n\nconst MAX_CUSTOM_PROPERTY_DEPTH = 5\n\n/**\n * Transforms a SchemaType to its manifest representation\n */\nexport function transformType(type: SchemaType, context: Context): ManifestSchemaType {\n const typeName = type.type ? type.type.name : type.jsonType\n\n return {\n ...transformCommonTypeFields(type, typeName, context),\n name: type.name,\n type: typeName,\n ...ensureCustomTitle(type.name, type.title),\n }\n}\n\n/**\n * Transforms common fields shared across all schema types\n */\nfunction transformCommonTypeFields(\n type: SchemaType & {fieldset?: string},\n typeName: string,\n context: Context,\n): Omit<ManifestSchemaType, 'name' | 'title' | 'type'> {\n const arrayProps =\n typeName === 'array' && type.jsonType === 'array' ? transformArrayMember(type, context) : {}\n\n const referenceProps = isReference(type) ? transformReference(type, retainCustomTypeProps) : {}\n const crossDatasetRefProps = isCrossDatasetReference(type)\n ? transformCrossDatasetReference(type)\n : {}\n const globalRefProps = isGlobalDocumentReference(type)\n ? transformGlobalDocumentReference(type)\n : {}\n\n const objectFields: ObjectFields =\n type.jsonType === 'object' && type.type && isCustomized(type)\n ? {\n fields: getCustomFields(type).map((objectField) => transformField(objectField, context)),\n }\n : {}\n\n return {\n ...retainCustomTypeProps(type),\n ...transformValidation(type.validation, retainSerializableProps),\n ...ensureString('description', type.description),\n ...objectFields,\n ...arrayProps,\n ...referenceProps,\n ...crossDatasetRefProps,\n ...globalRefProps,\n ...ensureConditional('readOnly', type.readOnly),\n ...ensureConditional('hidden', type.hidden),\n ...transformFieldsets(type),\n // fieldset prop gets instrumented via getCustomFields\n ...ensureString('fieldset', type.fieldset),\n ...transformBlockType(type, context, transformType),\n }\n}\n\n/**\n * Transforms fieldsets from a schema type\n */\nfunction transformFieldsets(\n type: SchemaType,\n): Record<string, never> | {fieldsets: ManifestFieldset[]} {\n if (type.jsonType !== 'object') {\n return {}\n }\n const fieldsets = type.fieldsets\n ?.filter((fs): fs is MultiFieldSet => !fs.single)\n .map((fs) => {\n const options = isRecord(fs.options) ? {options: retainSerializableProps(fs.options)} : {}\n return {\n name: fs.name,\n ...ensureCustomTitle(fs.name, fs.title),\n ...ensureString('description', fs.description),\n ...ensureConditional('readOnly', fs.readOnly),\n ...ensureConditional('hidden', fs.hidden),\n ...options,\n }\n })\n\n return fieldsets?.length ? {fieldsets} : {}\n}\n\n/**\n * Retains custom type properties that should be included in the manifest\n */\nfunction retainCustomTypeProps(type: SchemaType): Record<string, SerializableProp> {\n const manuallySerializedFields = new Set<SchemaTypeKey>([\n '__experimental_actions',\n '__experimental_formPreviewTitle',\n '__experimental_omnisearch_visibility',\n '__experimental_search',\n 'components',\n 'description',\n 'fields',\n 'fieldsets',\n //only exists on fields\n 'group',\n 'groups',\n 'hidden',\n 'icon',\n 'jsonType',\n //explicitly added\n 'name',\n 'of',\n 'orderings',\n 'preview',\n 'readOnly',\n 'title',\n 'to',\n // not serialized\n 'type',\n 'validation',\n // we know about these, but let them be generically handled\n // deprecated\n // rows (from text)\n // initialValue\n // options\n // crossDatasetReference props\n ])\n const typeWithoutManuallyHandledFields = Object.fromEntries(\n Object.entries(type).filter(\n ([key]) => !manuallySerializedFields.has(key as unknown as SchemaTypeKey),\n ),\n )\n return retainSerializableProps(typeWithoutManuallyHandledFields) as Record<\n string,\n SerializableProp\n >\n}\n\n/**\n * Retains serializable properties from an unknown value, recursively processing objects and arrays\n */\nfunction retainSerializableProps(maybeSerializable: unknown, depth = 0): SerializableProp {\n if (depth > MAX_CUSTOM_PROPERTY_DEPTH) {\n return undefined\n }\n\n if (!isDefined(maybeSerializable)) {\n return undefined\n }\n\n if (isPrimitive(maybeSerializable)) {\n // cull empty strings\n if (maybeSerializable === '') {\n return undefined\n }\n return maybeSerializable\n }\n\n // url-schemes ect..\n if (maybeSerializable instanceof RegExp) {\n return maybeSerializable.toString()\n }\n\n if (Array.isArray(maybeSerializable)) {\n const arrayItems = maybeSerializable\n .map((item) => retainSerializableProps(item, depth + 1))\n .filter((item): item is ManifestSerializable => isDefined(item))\n return arrayItems.length > 0 ? arrayItems : undefined\n }\n\n if (isRecord(maybeSerializable)) {\n const serializableEntries = Object.entries(maybeSerializable)\n .map(([key, value]) => {\n return [key, retainSerializableProps(value, depth + 1)]\n })\n .filter(([, value]) => isDefined(value))\n return serializableEntries.length > 0 ? Object.fromEntries(serializableEntries) : undefined\n }\n\n return undefined\n}\n\n/**\n * Transforms an ObjectField to its manifest representation\n */\nfunction transformField(field: ObjectField & {fieldset?: string}, context: Context): ManifestField {\n const fieldType = field.type\n const typeName = getDefinedTypeName(fieldType) ?? fieldType.name\n return {\n ...transformCommonTypeFields(fieldType, typeName, context),\n name: field.name,\n type: typeName,\n ...ensureCustomTitle(field.name, fieldType.title),\n // this prop gets added synthetically via getCustomFields\n ...ensureString('fieldset', field.fieldset),\n }\n}\n\n/**\n * Transforms array member types to their manifest representation\n */\nfunction transformArrayMember(\n arrayMember: ArraySchemaType,\n context: Context,\n): Pick<ManifestField, 'of'> {\n return {\n of: arrayMember.of.map((type) => {\n const typeName = getDefinedTypeName(type) ?? type.name\n return {\n ...transformCommonTypeFields(type, typeName, context),\n type: typeName,\n ...(typeName === type.name ? {} : {name: type.name}),\n ...ensureCustomTitle(type.name, type.title),\n }\n }),\n }\n}\n"],"names":["transformBlockType","transformCrossDatasetReference","transformGlobalDocumentReference","transformReference","getCustomFields","getDefinedTypeName","isCrossDatasetReference","isCustomized","isDefined","isGlobalDocumentReference","isPrimitive","isRecord","isReference","ensureConditional","ensureCustomTitle","ensureString","transformValidation","MAX_CUSTOM_PROPERTY_DEPTH","transformType","type","context","typeName","name","jsonType","transformCommonTypeFields","title","arrayProps","transformArrayMember","referenceProps","retainCustomTypeProps","crossDatasetRefProps","globalRefProps","objectFields","fields","map","objectField","transformField","validation","retainSerializableProps","description","readOnly","hidden","transformFieldsets","fieldset","fieldsets","filter","fs","single","options","length","manuallySerializedFields","Set","typeWithoutManuallyHandledFields","Object","fromEntries","entries","key","has","maybeSerializable","depth","undefined","RegExp","toString","Array","isArray","arrayItems","item","serializableEntries","value","field","fieldType","arrayMember","of"],"mappings":"AAcA,SAAQA,kBAAkB,QAAO,4BAA2B;AAC5D,SACEC,8BAA8B,EAC9BC,gCAAgC,EAChCC,kBAAkB,QACb,4BAA2B;AAClC,SACEC,eAAe,EACfC,kBAAkB,EAClBC,uBAAuB,EACvBC,YAAY,EACZC,SAAS,EACTC,yBAAyB,EACzBC,WAAW,EACXC,QAAQ,EACRC,WAAW,QACN,yBAAwB;AAC/B,SAEEC,iBAAiB,EACjBC,iBAAiB,EACjBC,YAAY,QAEP,wBAAuB;AAO9B,SAAQC,mBAAmB,QAAO,6BAA4B;AAe9D,MAAMC,4BAA4B;AAElC;;CAEC,GACD,OAAO,SAASC,cAAcC,IAAgB,EAAEC,OAAgB;IAC9D,MAAMC,WAAWF,KAAKA,IAAI,GAAGA,KAAKA,IAAI,CAACG,IAAI,GAAGH,KAAKI,QAAQ;IAE3D,OAAO;QACL,GAAGC,0BAA0BL,MAAME,UAAUD,QAAQ;QACrDE,MAAMH,KAAKG,IAAI;QACfH,MAAME;QACN,GAAGP,kBAAkBK,KAAKG,IAAI,EAAEH,KAAKM,KAAK,CAAC;IAC7C;AACF;AAEA;;CAEC,GACD,SAASD,0BACPL,IAAsC,EACtCE,QAAgB,EAChBD,OAAgB;IAEhB,MAAMM,aACJL,aAAa,WAAWF,KAAKI,QAAQ,KAAK,UAAUI,qBAAqBR,MAAMC,WAAW,CAAC;IAE7F,MAAMQ,iBAAiBhB,YAAYO,QAAQhB,mBAAmBgB,MAAMU,yBAAyB,CAAC;IAC9F,MAAMC,uBAAuBxB,wBAAwBa,QACjDlB,+BAA+BkB,QAC/B,CAAC;IACL,MAAMY,iBAAiBtB,0BA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KAAKY,MAAM;YAChB,OAAO;gBAACZ;gBAAKlB,wBAAwB8B,OAAOT,QAAQ;aAAG;QACzD,GACCd,MAAM,CAAC,CAAC,GAAGuB,MAAM,GAAK5D,UAAU4D;QACnC,OAAOD,oBAAoBlB,MAAM,GAAG,IAAII,OAAOC,WAAW,CAACa,uBAAuBP;IACpF;IAEA,OAAOA;AACT;AAEA;;CAEC,GACD,SAASxB,eAAeiC,KAAwC,EAAEjD,OAAgB;IAChF,MAAMkD,YAAYD,MAAMlD,IAAI;IAC5B,MAAME,WAAWhB,mBAAmBiE,cAAcA,UAAUhD,IAAI;IAChE,OAAO;QACL,GAAGE,0BAA0B8C,WAAWjD,UAAUD,QAAQ;QAC1DE,MAAM+C,MAAM/C,IAAI;QAChBH,MAAME;QACN,GAAGP,kBAAkBuD,MAAM/C,IAAI,EAAEgD,UAAU7C,KAAK,CAAC;QACjD,yDAAyD;QACzD,GAAGV,aAAa,YAAYsD,MAAM1B,QAAQ,CAAC;IAC7C;AACF;AAEA;;CAEC,GACD,SAAShB,qBACP4C,WAA4B,EAC5BnD,OAAgB;IAEhB,OAAO;QACLoD,IAAID,YAAYC,EAAE,CAACtC,GAAG,CAAC,CAACf;YACtB,MAAME,WAAWhB,mBAAmBc,SAASA,KAAKG,IAAI;YACtD,OAAO;gBACL,GAAGE,0BAA0BL,MAAME,UAAUD,QAAQ;gBACrDD,MAAME;gBACN,GAAIA,aAAaF,KAAKG,IAAI,GAAG,CAAC,IAAI;oBAACA,MAAMH,KAAKG,IAAI;gBAAA,CAAC;gBACnD,GAAGR,kBAAkBK,KAAKG,IAAI,EAAEH,KAAKM,KAAK,CAAC;YAC7C;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import startCase from 'lodash-es/startCase.js';
|
|
2
|
+
/**
|
|
3
|
+
* Ensures a string value is returned for the given key, or an empty object if not a string
|
|
4
|
+
*/ export function ensureString(key, value) {
|
|
5
|
+
if (typeof value === 'string') {
|
|
6
|
+
return {
|
|
7
|
+
[key]: value
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Ensures a conditional value is returned for the given key.
|
|
14
|
+
* Returns the boolean value if it's a boolean, 'conditional' if it's a function, or empty object otherwise.
|
|
15
|
+
*/ export function ensureConditional(key, value) {
|
|
16
|
+
if (typeof value === 'boolean') {
|
|
17
|
+
return {
|
|
18
|
+
[key]: value
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'function') {
|
|
22
|
+
return {
|
|
23
|
+
[key]: 'conditional'
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ensures a custom title is returned, omitting it if it matches the default startCase title
|
|
30
|
+
*/ export function ensureCustomTitle(typeName, value) {
|
|
31
|
+
const titleObject = ensureString('title', value);
|
|
32
|
+
const defaultTitle = startCase(typeName);
|
|
33
|
+
// omit title if its the same as default, to reduce payload
|
|
34
|
+
if (titleObject.title === defaultTitle) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
return titleObject;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=transformerUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/transformerUtils.ts"],"sourcesContent":["import {type Schema} from '@sanity/types'\nimport startCase from 'lodash-es/startCase.js'\n\nimport {type ManifestSerializable} from './types.js'\n\n/**\n * Context object passed to transformer functions\n */\nexport interface Context {\n schema: Schema\n}\n\n/**\n * Type for serializable properties that can be stored in the manifest\n */\nexport type SerializableProp = ManifestSerializable | ManifestSerializable[] | undefined\n\n/**\n * Ensures a string value is returned for the given key, or an empty object if not a string\n */\nexport function ensureString<Key extends string>(key: Key, value: unknown) {\n if (typeof value === 'string') {\n return {\n [key]: value,\n }\n }\n\n return {}\n}\n\n/**\n * Ensures a conditional value is returned for the given key.\n * Returns the boolean value if it's a boolean, 'conditional' if it's a function, or empty object otherwise.\n */\nexport function ensureConditional<const Key extends string>(key: Key, value: unknown) {\n if (typeof value === 'boolean') {\n return {\n [key]: value,\n }\n }\n\n if (typeof value === 'function') {\n return {\n [key]: 'conditional',\n }\n }\n\n return {}\n}\n\n/**\n * Ensures a custom title is returned, omitting it if it matches the default startCase title\n */\nexport function ensureCustomTitle(typeName: string, value: unknown) {\n const titleObject = ensureString('title', value)\n\n const defaultTitle = startCase(typeName)\n // omit title if its the same as default, to reduce payload\n if (titleObject.title === defaultTitle) {\n return {}\n }\n return titleObject\n}\n"],"names":["startCase","ensureString","key","value","ensureConditional","ensureCustomTitle","typeName","titleObject","defaultTitle","title"],"mappings":"AACA,OAAOA,eAAe,yBAAwB;AAgB9C;;CAEC,GACD,OAAO,SAASC,aAAiCC,GAAQ,EAAEC,KAAc;IACvE,IAAI,OAAOA,UAAU,UAAU;QAC7B,OAAO;YACL,CAACD,IAAI,EAAEC;QACT;IACF;IAEA,OAAO,CAAC;AACV;AAEA;;;CAGC,GACD,OAAO,SAASC,kBAA4CF,GAAQ,EAAEC,KAAc;IAClF,IAAI,OAAOA,UAAU,WAAW;QAC9B,OAAO;YACL,CAACD,IAAI,EAAEC;QACT;IACF;IAEA,IAAI,OAAOA,UAAU,YAAY;QAC/B,OAAO;YACL,CAACD,IAAI,EAAE;QACT;IACF;IAEA,OAAO,CAAC;AACV;AAEA;;CAEC,GACD,OAAO,SAASG,kBAAkBC,QAAgB,EAAEH,KAAc;IAChE,MAAMI,cAAcN,aAAa,SAASE;IAE1C,MAAMK,eAAeR,UAAUM;IAC/B,2DAA2D;IAC3D,IAAIC,YAAYE,KAAK,KAAKD,cAAc;QACtC,OAAO,CAAC;IACV;IACA,OAAOD;AACT"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
export const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = '_.schemas';
|
|
2
3
|
export const SANITY_WORKSPACE_SCHEMA_TYPE = 'system.schema';
|
|
3
4
|
export const CURRENT_WORKSPACE_SCHEMA_VERSION = '2025-05-01';
|
|
5
|
+
export const extractManifestWorkerData = z.object({
|
|
6
|
+
configPath: z.string(),
|
|
7
|
+
workDir: z.string()
|
|
8
|
+
});
|
|
4
9
|
|
|
5
10
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/actions/manifest/types.ts"],"sourcesContent":["import {type SanityDocumentLike} from '@sanity/types'\nimport {type MediaLibraryConfig} from 'sanity'\n\nexport const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = '_.schemas'\nexport const SANITY_WORKSPACE_SCHEMA_TYPE = 'system.schema'\nexport const CURRENT_WORKSPACE_SCHEMA_VERSION = '2025-05-01'\n\nexport type ManifestSerializable =\n | boolean\n | ManifestSerializable[]\n | number\n | string\n | {[k: string]: ManifestSerializable}\n\nexport interface CreateManifest {\n createdAt: string\n studioVersion: string | null\n version: number\n workspaces: ManifestWorkspaceFile[]\n}\n\nexport interface AppManifest {\n version: '1'\n\n icon?: string\n title?: string\n}\n\nexport interface ManifestWorkspaceFile extends Omit<CreateWorkspaceManifest, 'schema' | 'tools'> {\n schema: string // filename\n tools: string // filename\n}\n\nexport interface CreateWorkspaceManifest {\n basePath: string\n dataset: string\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n projectId: string\n schema: ManifestSchemaType[]\n tools: ManifestTool[]\n\n mediaLibrary?: MediaLibraryConfig\n subtitle?: string\n title?: string\n}\n\nexport interface ManifestSchemaType {\n name: string\n type: string\n\n deprecated?: {\n reason: string\n }\n fields?: ManifestField[]\n fieldsets?: ManifestFieldset[]\n hidden?: 'conditional' | boolean\n lists?: ManifestTitledValue[]\n //portable text\n marks?: {\n annotations?: ManifestArrayMember[]\n decorators?: ManifestTitledValue[]\n }\n of?: ManifestArrayMember[]\n options?: Record<string, ManifestSerializable>\n preview?: {\n select: Record<string, string>\n }\n readOnly?: 'conditional' | boolean\n styles?: ManifestTitledValue[]\n title?: string\n to?: ManifestReferenceMember[]\n validation?: ManifestValidationGroup[]\n\n // userland (assignable to ManifestSerializable | undefined)\n // not included to add some typesafty to extractManifest\n // [index: string]: unknown\n}\n\nexport interface ManifestFieldset {\n [index: string]: ManifestSerializable | undefined\n name: string\n\n title?: string\n}\n\nexport interface ManifestTitledValue {\n value: string\n\n title?: string\n}\n\ntype ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\ntype ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\nexport type ManifestField = ManifestSchemaType & {fieldset?: string}\n\nexport interface ManifestValidationGroup {\n rules: ManifestValidationRule[]\n\n level?: 'error' | 'info' | 'warning'\n message?: string\n}\n\nexport type ManifestValidationRule = {\n [index: string]: ManifestSerializable | undefined\n constraint?: ManifestSerializable\n flag: string\n}\n\nexport interface ManifestTool {\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n title: string\n type: string | null\n}\n\nexport type DefaultWorkspaceSchemaId = `${typeof SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.${string}`\ntype PrefixedWorkspaceSchemaId = `${DefaultWorkspaceSchemaId}.${string}`\nexport type WorkspaceSchemaId = DefaultWorkspaceSchemaId | PrefixedWorkspaceSchemaId\n\nexport interface StoredWorkspaceSchema extends SanityDocumentLike {\n _id: WorkspaceSchemaId\n _type: typeof SANITY_WORKSPACE_SCHEMA_TYPE\n /**\n * The API expects JSON coming in, but will store a string to save on attribute paths.\n * Consumers must use JSON.parse on the value, put we deploy to the API using ManifestSchemaType[]\n */\n schema:
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/manifest/types.ts"],"sourcesContent":["import {type SanityDocumentLike} from '@sanity/types'\nimport {type MediaLibraryConfig, type Workspace} from 'sanity'\nimport {z} from 'zod'\n\nexport const SANITY_WORKSPACE_SCHEMA_ID_PREFIX = '_.schemas'\nexport const SANITY_WORKSPACE_SCHEMA_TYPE = 'system.schema'\nexport const CURRENT_WORKSPACE_SCHEMA_VERSION = '2025-05-01'\n\nexport type ManifestSerializable =\n | boolean\n | ManifestSerializable[]\n | number\n | string\n | {[k: string]: ManifestSerializable}\n\nexport interface CreateManifest {\n createdAt: string\n studioVersion: string | null\n version: number\n workspaces: ManifestWorkspaceFile[]\n}\n\nexport interface AppManifest {\n version: '1'\n\n icon?: string\n title?: string\n}\n\nexport interface ManifestWorkspaceFile extends Omit<CreateWorkspaceManifest, 'schema' | 'tools'> {\n schema: string // filename\n tools: string // filename\n}\n\nexport interface CreateWorkspaceManifest {\n basePath: string\n dataset: string\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n projectId: string\n schema: ManifestSchemaType[]\n tools: ManifestTool[]\n\n mediaLibrary?: MediaLibraryConfig\n subtitle?: string\n title?: string\n}\n\nexport interface ManifestSchemaType {\n name: string\n type: string\n\n deprecated?: {\n reason: string\n }\n fields?: ManifestField[]\n fieldsets?: ManifestFieldset[]\n hidden?: 'conditional' | boolean\n lists?: ManifestTitledValue[]\n //portable text\n marks?: {\n annotations?: ManifestArrayMember[]\n decorators?: ManifestTitledValue[]\n }\n of?: ManifestArrayMember[]\n options?: Record<string, ManifestSerializable>\n preview?: {\n select: Record<string, string>\n }\n readOnly?: 'conditional' | boolean\n styles?: ManifestTitledValue[]\n title?: string\n to?: ManifestReferenceMember[]\n validation?: ManifestValidationGroup[]\n\n // userland (assignable to ManifestSerializable | undefined)\n // not included to add some typesafty to extractManifest\n // [index: string]: unknown\n}\n\nexport interface ManifestFieldset {\n [index: string]: ManifestSerializable | undefined\n name: string\n\n title?: string\n}\n\nexport interface ManifestTitledValue {\n value: string\n\n title?: string\n}\n\ntype ManifestArrayMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\ntype ManifestReferenceMember = Omit<ManifestSchemaType, 'name'> & {name?: string}\nexport type ManifestField = ManifestSchemaType & {fieldset?: string}\n\nexport interface ManifestValidationGroup {\n rules: ManifestValidationRule[]\n\n level?: 'error' | 'info' | 'warning'\n message?: string\n}\n\nexport type ManifestValidationRule = {\n [index: string]: ManifestSerializable | undefined\n constraint?: ManifestSerializable\n flag: string\n}\n\nexport interface ManifestTool {\n /**\n * returns null in the case of the icon not being able to be stringified\n */\n icon: string | null\n name: string\n title: string\n type: string | null\n}\n\nexport type DefaultWorkspaceSchemaId = `${typeof SANITY_WORKSPACE_SCHEMA_ID_PREFIX}.${string}`\ntype PrefixedWorkspaceSchemaId = `${DefaultWorkspaceSchemaId}.${string}`\nexport type WorkspaceSchemaId = DefaultWorkspaceSchemaId | PrefixedWorkspaceSchemaId\n\nexport interface StoredWorkspaceSchema extends SanityDocumentLike {\n _id: WorkspaceSchemaId\n _type: typeof SANITY_WORKSPACE_SCHEMA_TYPE\n /**\n * The API expects JSON coming in, but will store a string to save on attribute paths.\n * Consumers must use JSON.parse on the value, put we deploy to the API using ManifestSchemaType[]\n */\n schema: string | Workspace['schema']\n /* api-like version string: date at which the format had a meaningful change */\n version: typeof CURRENT_WORKSPACE_SCHEMA_VERSION | undefined\n workspace: {\n name: string\n title?: string\n }\n\n tag?: string\n}\n\nexport const extractManifestWorkerData = z.object({configPath: z.string(), workDir: z.string()})\n\nexport type ExtractManifestWorkerData = z.infer<typeof extractManifestWorkerData>\n"],"names":["z","SANITY_WORKSPACE_SCHEMA_ID_PREFIX","SANITY_WORKSPACE_SCHEMA_TYPE","CURRENT_WORKSPACE_SCHEMA_VERSION","extractManifestWorkerData","object","configPath","string","workDir"],"mappings":"AAEA,SAAQA,CAAC,QAAO,MAAK;AAErB,OAAO,MAAMC,oCAAoC,YAAW;AAC5D,OAAO,MAAMC,+BAA+B,gBAAe;AAC3D,OAAO,MAAMC,mCAAmC,aAAY;AA2I5D,OAAO,MAAMC,4BAA4BJ,EAAEK,MAAM,CAAC;IAACC,YAAYN,EAAEO,MAAM;IAAIC,SAASR,EAAEO,MAAM;AAAE,GAAE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const transformTypeValidationRule = (rule)=>{
|
|
2
|
+
return {
|
|
3
|
+
...rule,
|
|
4
|
+
constraint: 'constraint' in rule && (typeof rule.constraint === 'string' ? rule.constraint.toLowerCase() : retainSerializablePropsForValidation(rule.constraint))
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
const validationRuleTransformers = {
|
|
8
|
+
type: transformTypeValidationRule
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Transforms schema validation rules to their manifest representation
|
|
12
|
+
*/ export function transformValidation(validation, retainSerializableProps) {
|
|
13
|
+
const validationArray = (Array.isArray(validation) ? validation : [
|
|
14
|
+
validation
|
|
15
|
+
]).filter((value)=>typeof value === 'object' && '_type' in value);
|
|
16
|
+
// we don't want type in the output as that is implicitly given by the typedef itself an will only bloat the payload
|
|
17
|
+
const disallowedFlags = new Set([
|
|
18
|
+
'type'
|
|
19
|
+
]);
|
|
20
|
+
const serializedValidation = validationArray.map(({ _level, _message, _rules })=>{
|
|
21
|
+
const message = typeof _message === 'string' ? {
|
|
22
|
+
message: _message
|
|
23
|
+
} : {};
|
|
24
|
+
const serializedRules = _rules.filter((rule)=>{
|
|
25
|
+
if (!('constraint' in rule)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const { constraint, flag } = rule;
|
|
29
|
+
if (disallowedFlags.has(flag)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
// Validation rules that refer to other fields use symbols, which cannot be serialized. It would
|
|
33
|
+
// be possible to transform these to a serializable type, but we haven't implemented that for now.
|
|
34
|
+
const isFieldReference = typeof constraint === 'object' && 'type' in constraint && typeof constraint.type === 'symbol' && (constraint.type.description === 'FIELD_REF' || constraint.type.description === '@sanity/schema/field-ref');
|
|
35
|
+
return !isFieldReference;
|
|
36
|
+
}).map((rule)=>{
|
|
37
|
+
const transformer = validationRuleTransformers[rule.flag] ?? ((spec)=>retainSerializableProps(spec));
|
|
38
|
+
const transformedRule = transformer(rule);
|
|
39
|
+
if (!transformedRule) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return transformedRule;
|
|
43
|
+
}).filter((rule)=>rule !== undefined);
|
|
44
|
+
return {
|
|
45
|
+
level: _level,
|
|
46
|
+
rules: serializedRules,
|
|
47
|
+
...message
|
|
48
|
+
};
|
|
49
|
+
}).filter((group)=>group.rules.length > 0);
|
|
50
|
+
return serializedValidation.length > 0 ? {
|
|
51
|
+
validation: serializedValidation
|
|
52
|
+
} : {};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Helper function to retain serializable props specifically for validation transformation.
|
|
56
|
+
* This is used internally by transformTypeValidationRule.
|
|
57
|
+
*/ function retainSerializablePropsForValidation(value) {
|
|
58
|
+
if (value === null || value === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
62
|
+
if (value === '') {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (value instanceof RegExp) {
|
|
68
|
+
return value.toString();
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(value)) {
|
|
71
|
+
const items = value.map((item)=>retainSerializablePropsForValidation(item)).filter((item)=>item !== undefined);
|
|
72
|
+
return items.length > 0 ? items : undefined;
|
|
73
|
+
}
|
|
74
|
+
if (typeof value === 'object') {
|
|
75
|
+
const entries = Object.entries(value).map(([key, val])=>[
|
|
76
|
+
key,
|
|
77
|
+
retainSerializablePropsForValidation(val)
|
|
78
|
+
]).filter(([, val])=>val !== undefined);
|
|
79
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=validationTransformer.js.map
|