@sanity/cli 6.0.0-alpha.5 → 6.0.0-alpha.6
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/dist/actions/dataset/create.d.ts +49 -0
- package/dist/actions/dataset/create.js +48 -0
- package/dist/actions/dataset/create.js.map +1 -0
- package/dist/actions/dataset/determineDatasetAclMode.d.ts +37 -0
- package/dist/actions/dataset/determineDatasetAclMode.js +36 -0
- package/dist/actions/dataset/determineDatasetAclMode.js.map +1 -0
- package/dist/actions/debug/gatherDebugInfo.js +15 -21
- package/dist/actions/debug/gatherDebugInfo.js.map +1 -1
- package/dist/actions/debug/types.d.ts +0 -2
- package/dist/actions/debug/types.js.map +1 -1
- package/dist/actions/deploy/deployApp.js +13 -0
- package/dist/actions/deploy/deployApp.js.map +1 -1
- package/dist/actions/init/remoteTemplate.js +1 -1
- package/dist/actions/init/remoteTemplate.js.map +1 -1
- package/dist/actions/manifest/extractAppManifest.d.ts +20 -0
- package/dist/actions/manifest/extractAppManifest.js +51 -0
- package/dist/actions/manifest/extractAppManifest.js.map +1 -0
- package/dist/actions/manifest/extractManifest.js +1 -1
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/manifest/types.d.ts +6 -1
- package/dist/actions/manifest/types.js.map +1 -1
- package/dist/actions/media/importAspects.js +2 -1
- package/dist/actions/media/importAspects.js.map +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +1 -1
- package/dist/commands/dataset/create.d.ts +0 -2
- package/dist/commands/dataset/create.js +8 -54
- package/dist/commands/dataset/create.js.map +1 -1
- package/dist/commands/debug.js +5 -9
- package/dist/commands/debug.js.map +1 -1
- package/dist/commands/init.d.ts +6 -1
- package/dist/commands/init.js +358 -20
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/manifest/extract.js +7 -8
- package/dist/commands/manifest/extract.js.map +1 -1
- package/dist/config/createCliConfig.d.ts +9 -0
- package/dist/prompts/init/promptForTypescript.d.ts +2 -0
- package/dist/prompts/init/promptForTypescript.js +15 -0
- package/dist/prompts/init/promptForTypescript.js.map +1 -0
- package/dist/prompts/promptForDatasetAclMode.d.ts +9 -0
- package/dist/prompts/promptForDatasetAclMode.js +27 -0
- package/dist/prompts/promptForDatasetAclMode.js.map +1 -0
- package/dist/prompts/promptForDatasetName.d.ts +1 -1
- package/dist/prompts/promptForDatasetName.js +4 -1
- package/dist/prompts/promptForDatasetName.js.map +1 -1
- package/dist/services/organizations.d.ts +3 -1
- package/dist/services/organizations.js +2 -1
- package/dist/services/organizations.js.map +1 -1
- package/dist/services/user.d.ts +5 -0
- package/dist/services/user.js +12 -1
- package/dist/services/user.js.map +1 -1
- package/dist/services/userApplications.d.ts +3 -1
- package/dist/services/userApplications.js +5 -1
- package/dist/services/userApplications.js.map +1 -1
- package/oclif.manifest.json +113 -113
- package/package.json +16 -12
- package/templates/app-quickstart/src/App.css +20 -0
- package/templates/app-quickstart/src/App.tsx +25 -0
- package/templates/app-quickstart/src/ExampleComponent.css +90 -0
- package/templates/app-quickstart/src/ExampleComponent.tsx +37 -0
- package/templates/app-sanity-ui/src/App.tsx +34 -0
- package/templates/app-sanity-ui/src/ExampleComponent.tsx +34 -0
- package/templates/app-sanity-ui/src/SanityUI.tsx +23 -0
- package/templates/blog/README.md +11 -0
- package/templates/blog/schemaTypes/author.js +50 -0
- package/templates/blog/schemaTypes/blockContent.js +67 -0
- package/templates/blog/schemaTypes/category.js +19 -0
- package/templates/blog/schemaTypes/index.js +6 -0
- package/templates/blog/schemaTypes/post.js +65 -0
- package/templates/blog/static/.gitkeep +1 -0
- package/templates/clean/README.md +9 -0
- package/templates/clean/schemaTypes/index.js +1 -0
- package/templates/clean/static/.gitkeep +1 -0
- package/templates/ecommerce/README.md +11 -0
- package/templates/ecommerce/plugins/.gitkeep +1 -0
- package/templates/ecommerce/plugins/barcode-input/BarcodeInput.js +62 -0
- package/templates/ecommerce/plugins/barcode-input/index.js +9 -0
- package/templates/ecommerce/plugins/barcode-input/schemaType.js +60 -0
- package/templates/ecommerce/schemaTypes/blockContent.js +67 -0
- package/templates/ecommerce/schemaTypes/category.js +39 -0
- package/templates/ecommerce/schemaTypes/index.js +23 -0
- package/templates/ecommerce/schemaTypes/locale/localeBlockContent.js +19 -0
- package/templates/ecommerce/schemaTypes/locale/localeString.js +19 -0
- package/templates/ecommerce/schemaTypes/locale/localeText.js +19 -0
- package/templates/ecommerce/schemaTypes/locale/supportedLanguages.js +5 -0
- package/templates/ecommerce/schemaTypes/product.js +83 -0
- package/templates/ecommerce/schemaTypes/productVariant.js +52 -0
- package/templates/ecommerce/schemaTypes/vendor.js +39 -0
- package/templates/ecommerce/static/.gitkeep +1 -0
- package/templates/get-started/README.md +9 -0
- package/templates/get-started/plugins/.gitkeep +1 -0
- package/templates/get-started/plugins/sanity-plugin-tutorial/CustomDefaultLayout.tsx +16 -0
- package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +104 -0
- package/templates/get-started/plugins/sanity-plugin-tutorial/index.ts +11 -0
- package/templates/get-started/schemaTypes/index.ts +1 -0
- package/templates/get-started/static/.gitkeep +1 -0
- package/templates/moviedb/README.md +10 -0
- package/templates/moviedb/schemaTypes/blockContent.js +67 -0
- package/templates/moviedb/schemaTypes/castMember.js +37 -0
- package/templates/moviedb/schemaTypes/crewMember.js +52 -0
- package/templates/moviedb/schemaTypes/index.js +22 -0
- package/templates/moviedb/schemaTypes/movie.js +85 -0
- package/templates/moviedb/schemaTypes/person.js +37 -0
- package/templates/moviedb/schemaTypes/plotSummaries.js +20 -0
- package/templates/moviedb/schemaTypes/plotSummary.js +24 -0
- package/templates/moviedb/schemaTypes/screening.js +81 -0
- package/templates/moviedb/static/.gitkeep +1 -0
- package/templates/quickstart/README.md +9 -0
- package/templates/quickstart/schemaTypes/index.js +1 -0
- package/templates/quickstart/static/.gitkeep +1 -0
- package/templates/shared/gitignore.txt +29 -0
- package/templates/shared/tsconfig.json +17 -0
- package/templates/shopify/README.md +85 -0
- package/templates/shopify/components/hotspots/ProductTooltip.tsx +38 -0
- package/templates/shopify/components/icons/Shopify.tsx +20 -0
- package/templates/shopify/components/inputs/CollectionHidden.tsx +23 -0
- package/templates/shopify/components/inputs/PlaceholderString.tsx +20 -0
- package/templates/shopify/components/inputs/ProductHidden.tsx +64 -0
- package/templates/shopify/components/inputs/ProductVariantHidden.tsx +24 -0
- package/templates/shopify/components/inputs/ProxyString.tsx +32 -0
- package/templates/shopify/components/media/ColorTheme.tsx +38 -0
- package/templates/shopify/components/media/ShopifyDocumentStatus.tsx +82 -0
- package/templates/shopify/components/studio/Navbar.tsx +29 -0
- package/templates/shopify/constants.ts +61 -0
- package/templates/shopify/docs/features.md +158 -0
- package/templates/shopify/plugins/customDocumentActions/index.ts +55 -0
- package/templates/shopify/plugins/customDocumentActions/shopifyDelete.tsx +144 -0
- package/templates/shopify/plugins/customDocumentActions/shopifyLink.ts +39 -0
- package/templates/shopify/plugins/customDocumentActions/types.ts +14 -0
- package/templates/shopify/schemaTypes/documents/collection.tsx +142 -0
- package/templates/shopify/schemaTypes/documents/colorTheme.tsx +44 -0
- package/templates/shopify/schemaTypes/documents/page.ts +70 -0
- package/templates/shopify/schemaTypes/documents/product.tsx +132 -0
- package/templates/shopify/schemaTypes/documents/productVariant.tsx +67 -0
- package/templates/shopify/schemaTypes/index.ts +108 -0
- package/templates/shopify/schemaTypes/objects/collection/collectionGroupType.ts +27 -0
- package/templates/shopify/schemaTypes/objects/collection/collectionLinksType.ts +16 -0
- package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorObjectType.tsx +48 -0
- package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorType.tsx +50 -0
- package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeObjectType.ts +40 -0
- package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeType.ts +49 -0
- package/templates/shopify/schemaTypes/objects/global/footerType.ts +22 -0
- package/templates/shopify/schemaTypes/objects/global/menuLinksType.ts +21 -0
- package/templates/shopify/schemaTypes/objects/global/menuType.ts +17 -0
- package/templates/shopify/schemaTypes/objects/global/notFoundPageType.ts +37 -0
- package/templates/shopify/schemaTypes/objects/hotspot/imageWithProductHotspotsType.ts +48 -0
- package/templates/shopify/schemaTypes/objects/hotspot/productHotspotsType.tsx +17 -0
- package/templates/shopify/schemaTypes/objects/hotspot/spotType.tsx +60 -0
- package/templates/shopify/schemaTypes/objects/link/linkEmailType.tsx +34 -0
- package/templates/shopify/schemaTypes/objects/link/linkExternalType.tsx +37 -0
- package/templates/shopify/schemaTypes/objects/link/linkInternalType.tsx +33 -0
- package/templates/shopify/schemaTypes/objects/link/linkProductType.tsx +60 -0
- package/templates/shopify/schemaTypes/objects/module/accordionGroupType.ts +33 -0
- package/templates/shopify/schemaTypes/objects/module/accordionType.ts +28 -0
- package/templates/shopify/schemaTypes/objects/module/callToActionType.tsx +85 -0
- package/templates/shopify/schemaTypes/objects/module/calloutType.ts +38 -0
- package/templates/shopify/schemaTypes/objects/module/collectionReferenceType.tsx +47 -0
- package/templates/shopify/schemaTypes/objects/module/gridItemType.ts +41 -0
- package/templates/shopify/schemaTypes/objects/module/gridType.ts +28 -0
- package/templates/shopify/schemaTypes/objects/module/heroType.tsx +40 -0
- package/templates/shopify/schemaTypes/objects/module/imageCallToActionType.tsx +19 -0
- package/templates/shopify/schemaTypes/objects/module/imageFeatureType.ts +80 -0
- package/templates/shopify/schemaTypes/objects/module/imageFeaturesType.tsx +51 -0
- package/templates/shopify/schemaTypes/objects/module/instagramType.ts +35 -0
- package/templates/shopify/schemaTypes/objects/module/productFeaturesType.tsx +50 -0
- package/templates/shopify/schemaTypes/objects/module/productReferenceType.tsx +42 -0
- package/templates/shopify/schemaTypes/objects/seoType.ts +31 -0
- package/templates/shopify/schemaTypes/objects/shopify/collectionRuleType.tsx +37 -0
- package/templates/shopify/schemaTypes/objects/shopify/inventoryType.ts +25 -0
- package/templates/shopify/schemaTypes/objects/shopify/optionType.tsx +31 -0
- package/templates/shopify/schemaTypes/objects/shopify/placeholderStringType.ts +11 -0
- package/templates/shopify/schemaTypes/objects/shopify/priceRangeType.ts +20 -0
- package/templates/shopify/schemaTypes/objects/shopify/productWithVariantType.tsx +142 -0
- package/templates/shopify/schemaTypes/objects/shopify/proxyStringType.ts +12 -0
- package/templates/shopify/schemaTypes/objects/shopify/shopType.ts +15 -0
- package/templates/shopify/schemaTypes/objects/shopify/shopifyCollectionType.ts +84 -0
- package/templates/shopify/schemaTypes/objects/shopify/shopifyProductType.ts +131 -0
- package/templates/shopify/schemaTypes/objects/shopify/shopifyProductVariantType.ts +121 -0
- package/templates/shopify/schemaTypes/portableText/portableTextSimpleType.tsx +45 -0
- package/templates/shopify/schemaTypes/portableText/portableTextType.tsx +52 -0
- package/templates/shopify/schemaTypes/singletons/homeType.ts +49 -0
- package/templates/shopify/schemaTypes/singletons/settingsType.ts +96 -0
- package/templates/shopify/static/.gitkeep +1 -0
- package/templates/shopify/structure/collectionStructure.ts +9 -0
- package/templates/shopify/structure/colorThemeStructure.ts +9 -0
- package/templates/shopify/structure/homeStructure.ts +9 -0
- package/templates/shopify/structure/index.ts +57 -0
- package/templates/shopify/structure/pageStructure.ts +11 -0
- package/templates/shopify/structure/productStructure.ts +51 -0
- package/templates/shopify/structure/settingStructure.ts +9 -0
- package/templates/shopify/utils/blocksToText.ts +20 -0
- package/templates/shopify/utils/defineStructure.ts +11 -0
- package/templates/shopify/utils/getPriceRange.ts +24 -0
- package/templates/shopify/utils/shopifyUrls.ts +22 -0
- package/templates/shopify/utils/validateSlug.ts +18 -0
- package/templates/shopify-online-storefront/README.md +54 -0
- package/templates/shopify-online-storefront/components/icons/Shopify.tsx +22 -0
- package/templates/shopify-online-storefront/components/inputs/CollectionHidden.tsx +23 -0
- package/templates/shopify-online-storefront/components/inputs/PlaceholderString.tsx +25 -0
- package/templates/shopify-online-storefront/components/inputs/ProductHidden.tsx +66 -0
- package/templates/shopify-online-storefront/components/inputs/ProductVariantHidden.tsx +25 -0
- package/templates/shopify-online-storefront/components/inputs/ProxyString.tsx +38 -0
- package/templates/shopify-online-storefront/components/media/ShopifyDocumentStatus.tsx +83 -0
- package/templates/shopify-online-storefront/constants.ts +18 -0
- package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/index.ts +45 -0
- package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyDelete.tsx +144 -0
- package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyLink.ts +39 -0
- package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/types.ts +14 -0
- package/templates/shopify-online-storefront/schemaTypes/blocks/blockContent.ts +32 -0
- package/templates/shopify-online-storefront/schemaTypes/documents/collection.tsx +83 -0
- package/templates/shopify-online-storefront/schemaTypes/documents/product.tsx +102 -0
- package/templates/shopify-online-storefront/schemaTypes/documents/productVariant.tsx +82 -0
- package/templates/shopify-online-storefront/schemaTypes/index.ts +43 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/accordion.ts +31 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/accordionGroup.ts +35 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/callout.ts +40 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/inventory.ts +30 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/option.ts +30 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/priceRange.ts +22 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/proxyString.ts +11 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollection.ts +109 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollectionRule.tsx +45 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProduct.ts +165 -0
- package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProductVariant.ts +151 -0
- package/templates/shopify-online-storefront/structure/collectionStructure.ts +9 -0
- package/templates/shopify-online-storefront/structure/index.ts +37 -0
- package/templates/shopify-online-storefront/structure/productStructure.ts +35 -0
- package/templates/shopify-online-storefront/utils/defineStructure.ts +11 -0
- package/templates/shopify-online-storefront/utils/getPriceRange.ts +24 -0
- package/templates/shopify-online-storefront/utils/shopifyUrls.ts +22 -0
- package/dist/actions/build/__tests__/buildApp.test.js +0 -367
- package/dist/actions/build/__tests__/buildApp.test.js.map +0 -1
- package/dist/actions/build/__tests__/buildStudio.test.js +0 -561
- package/dist/actions/build/__tests__/buildStudio.test.js.map +0 -1
- package/dist/actions/build/__tests__/checkRequiredDependencies.test.js +0 -233
- package/dist/actions/build/__tests__/checkRequiredDependencies.test.js.map +0 -1
- package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js +0 -414
- package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js.map +0 -1
- package/dist/actions/build/__tests__/determineBasePath.test.js +0 -24
- package/dist/actions/build/__tests__/determineBasePath.test.js.map +0 -1
- package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js +0 -109
- package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js.map +0 -1
- package/dist/actions/build/__tests__/getViteConfig.test.js +0 -493
- package/dist/actions/build/__tests__/getViteConfig.test.js.map +0 -1
- package/dist/actions/build/__tests__/renderDocument.test.js +0 -278
- package/dist/actions/build/__tests__/renderDocument.test.js.map +0 -1
- package/dist/actions/build/__tests__/shouldAutoUpdate.test.js +0 -153
- package/dist/actions/build/__tests__/shouldAutoUpdate.test.js.map +0 -1
- package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js +0 -657
- package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js.map +0 -1
- package/dist/actions/dataset/__tests__/validateDatasetName.test.js +0 -182
- package/dist/actions/dataset/__tests__/validateDatasetName.test.js.map +0 -1
- package/dist/actions/deploy/__tests__/checkDir.test.js +0 -120
- package/dist/actions/deploy/__tests__/checkDir.test.js.map +0 -1
- package/dist/actions/docs/__tests__/normalizeDocsPath.test.js +0 -16
- package/dist/actions/docs/__tests__/normalizeDocsPath.test.js.map +0 -1
- package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js +0 -124
- package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js.map +0 -1
- package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +0 -274
- package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +0 -1
- package/dist/actions/media/__tests__/importMedia.test.js +0 -182
- package/dist/actions/media/__tests__/importMedia.test.js.map +0 -1
- package/dist/actions/schema/__tests__/formatSchemaValidation.test.js +0 -174
- package/dist/actions/schema/__tests__/formatSchemaValidation.test.js.map +0 -1
- package/dist/actions/schema/__tests__/validateAction.test.js +0 -281
- package/dist/actions/schema/__tests__/validateAction.test.js.map +0 -1
- package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js +0 -27
- package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js.map +0 -1
- package/dist/actions/users/__tests__/validateEmail.test.js +0 -16
- package/dist/actions/users/__tests__/validateEmail.test.js.map +0 -1
- package/dist/commands/__tests__/blueprints.test.js +0 -54
- package/dist/commands/__tests__/blueprints.test.js.map +0 -1
- package/dist/commands/__tests__/build.test.js +0 -132
- package/dist/commands/__tests__/build.test.js.map +0 -1
- package/dist/commands/__tests__/codemod.test.js +0 -271
- package/dist/commands/__tests__/codemod.test.js.map +0 -1
- package/dist/commands/__tests__/debug.test.js +0 -590
- package/dist/commands/__tests__/debug.test.js.map +0 -1
- package/dist/commands/__tests__/deploy.test.js +0 -1945
- package/dist/commands/__tests__/deploy.test.js.map +0 -1
- package/dist/commands/__tests__/dev.test.js +0 -453
- package/dist/commands/__tests__/dev.test.js.map +0 -1
- package/dist/commands/__tests__/exec.test.js +0 -207
- package/dist/commands/__tests__/exec.test.js.map +0 -1
- package/dist/commands/__tests__/init/init.authentication.test.js +0 -73
- package/dist/commands/__tests__/init/init.authentication.test.js.map +0 -1
- package/dist/commands/__tests__/init/init.create-new-project.test.js +0 -195
- package/dist/commands/__tests__/init/init.create-new-project.test.js.map +0 -1
- package/dist/commands/__tests__/init/init.plan.test.js +0 -279
- package/dist/commands/__tests__/init/init.plan.test.js.map +0 -1
- package/dist/commands/__tests__/init/init.setup.test.js +0 -335
- package/dist/commands/__tests__/init/init.setup.test.js.map +0 -1
- package/dist/commands/__tests__/install.test.js +0 -282
- package/dist/commands/__tests__/install.test.js.map +0 -1
- package/dist/commands/__tests__/learn.test.js +0 -29
- package/dist/commands/__tests__/learn.test.js.map +0 -1
- package/dist/commands/__tests__/logout.test.js +0 -91
- package/dist/commands/__tests__/logout.test.js.map +0 -1
- package/dist/commands/__tests__/manage.test.js +0 -110
- package/dist/commands/__tests__/manage.test.js.map +0 -1
- package/dist/commands/__tests__/migration.test.js +0 -119
- package/dist/commands/__tests__/migration.test.js.map +0 -1
- package/dist/commands/__tests__/preview.test.js +0 -261
- package/dist/commands/__tests__/preview.test.js.map +0 -1
- package/dist/commands/__tests__/start.test.js +0 -253
- package/dist/commands/__tests__/start.test.js.map +0 -1
- package/dist/commands/__tests__/undeploy.test.js +0 -382
- package/dist/commands/__tests__/undeploy.test.js.map +0 -1
- package/dist/commands/__tests__/versions.test.js +0 -142
- package/dist/commands/__tests__/versions.test.js.map +0 -1
- package/dist/commands/backup/__tests__/disable.test.js +0 -204
- package/dist/commands/backup/__tests__/disable.test.js.map +0 -1
- package/dist/commands/backup/__tests__/download.test.js +0 -768
- package/dist/commands/backup/__tests__/download.test.js.map +0 -1
- package/dist/commands/backup/__tests__/enable.test.js +0 -286
- package/dist/commands/backup/__tests__/enable.test.js.map +0 -1
- package/dist/commands/backup/__tests__/list.test.js +0 -330
- package/dist/commands/backup/__tests__/list.test.js.map +0 -1
- package/dist/commands/cors/__tests__/add.test.js +0 -376
- package/dist/commands/cors/__tests__/add.test.js.map +0 -1
- package/dist/commands/cors/__tests__/delete.test.js +0 -308
- package/dist/commands/cors/__tests__/delete.test.js.map +0 -1
- package/dist/commands/cors/__tests__/list.test.js +0 -241
- package/dist/commands/cors/__tests__/list.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/copy.test.js +0 -628
- package/dist/commands/dataset/__tests__/copy.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/create.test.js +0 -342
- package/dist/commands/dataset/__tests__/create.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/delete.test.js +0 -231
- package/dist/commands/dataset/__tests__/delete.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/export.test.js +0 -601
- package/dist/commands/dataset/__tests__/export.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/import.test.js +0 -53
- package/dist/commands/dataset/__tests__/import.test.js.map +0 -1
- package/dist/commands/dataset/__tests__/list.test.js +0 -216
- package/dist/commands/dataset/__tests__/list.test.js.map +0 -1
- package/dist/commands/dataset/alias/__tests__/create.test.js +0 -339
- package/dist/commands/dataset/alias/__tests__/create.test.js.map +0 -1
- package/dist/commands/dataset/alias/__tests__/delete.test.js +0 -247
- package/dist/commands/dataset/alias/__tests__/delete.test.js.map +0 -1
- package/dist/commands/dataset/alias/__tests__/link.test.js +0 -376
- package/dist/commands/dataset/alias/__tests__/link.test.js.map +0 -1
- package/dist/commands/dataset/alias/__tests__/unlink.test.js +0 -313
- package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +0 -1
- package/dist/commands/dataset/visibility/__tests__/get.test.js +0 -128
- package/dist/commands/dataset/visibility/__tests__/get.test.js.map +0 -1
- package/dist/commands/dataset/visibility/__tests__/set.test.js +0 -198
- package/dist/commands/dataset/visibility/__tests__/set.test.js.map +0 -1
- package/dist/commands/docs/__tests__/browse.test.js +0 -29
- package/dist/commands/docs/__tests__/browse.test.js.map +0 -1
- package/dist/commands/docs/__tests__/read.test.js +0 -78
- package/dist/commands/docs/__tests__/read.test.js.map +0 -1
- package/dist/commands/docs/__tests__/search.test.js +0 -255
- package/dist/commands/docs/__tests__/search.test.js.map +0 -1
- package/dist/commands/documents/__tests__/create.test.js +0 -1030
- package/dist/commands/documents/__tests__/create.test.js.map +0 -1
- package/dist/commands/documents/__tests__/delete.test.js +0 -300
- package/dist/commands/documents/__tests__/delete.test.js.map +0 -1
- package/dist/commands/documents/__tests__/get.test.js +0 -182
- package/dist/commands/documents/__tests__/get.test.js.map +0 -1
- package/dist/commands/documents/__tests__/query.test.js +0 -300
- package/dist/commands/documents/__tests__/query.test.js.map +0 -1
- package/dist/commands/documents/__tests__/validate.test.js +0 -249
- package/dist/commands/documents/__tests__/validate.test.js.map +0 -1
- package/dist/commands/graphql/__tests__/list.test.js +0 -240
- package/dist/commands/graphql/__tests__/list.test.js.map +0 -1
- package/dist/commands/graphql/__tests__/undeploy.test.js +0 -410
- package/dist/commands/graphql/__tests__/undeploy.test.js.map +0 -1
- package/dist/commands/hook/__tests__/attempt.test.js +0 -275
- package/dist/commands/hook/__tests__/attempt.test.js.map +0 -1
- package/dist/commands/hook/__tests__/create.test.js +0 -119
- package/dist/commands/hook/__tests__/create.test.js.map +0 -1
- package/dist/commands/hook/__tests__/delete.test.js +0 -233
- package/dist/commands/hook/__tests__/delete.test.js.map +0 -1
- package/dist/commands/hook/__tests__/list.test.js +0 -145
- package/dist/commands/hook/__tests__/list.test.js.map +0 -1
- package/dist/commands/hook/__tests__/logs.test.js +0 -798
- package/dist/commands/hook/__tests__/logs.test.js.map +0 -1
- package/dist/commands/manifest/__tests__/extract.test.js +0 -132
- package/dist/commands/manifest/__tests__/extract.test.js.map +0 -1
- package/dist/commands/mcp/__tests__/configure.test.js +0 -397
- package/dist/commands/mcp/__tests__/configure.test.js.map +0 -1
- package/dist/commands/media/__tests__/create-aspect.test.js +0 -173
- package/dist/commands/media/__tests__/create-aspect.test.js.map +0 -1
- package/dist/commands/media/__tests__/delete-aspect.test.js +0 -342
- package/dist/commands/media/__tests__/delete-aspect.test.js.map +0 -1
- package/dist/commands/media/__tests__/deploy-aspect.test.js +0 -619
- package/dist/commands/media/__tests__/deploy-aspect.test.js.map +0 -1
- package/dist/commands/media/__tests__/export.test.js +0 -697
- package/dist/commands/media/__tests__/export.test.js.map +0 -1
- package/dist/commands/media/__tests__/import.test.js +0 -347
- package/dist/commands/media/__tests__/import.test.js.map +0 -1
- package/dist/commands/openapi/__tests__/get.test.js +0 -149
- package/dist/commands/openapi/__tests__/get.test.js.map +0 -1
- package/dist/commands/openapi/__tests__/list.test.js +0 -113
- package/dist/commands/openapi/__tests__/list.test.js.map +0 -1
- package/dist/commands/projects/__tests__/list.test.js +0 -154
- package/dist/commands/projects/__tests__/list.test.js.map +0 -1
- package/dist/commands/schema/__tests__/delete.test.js +0 -454
- package/dist/commands/schema/__tests__/delete.test.js.map +0 -1
- package/dist/commands/schema/__tests__/deploy.test.js +0 -348
- package/dist/commands/schema/__tests__/deploy.test.js.map +0 -1
- package/dist/commands/schema/__tests__/extract.test.js +0 -121
- package/dist/commands/schema/__tests__/extract.test.js.map +0 -1
- package/dist/commands/schema/__tests__/list.test.js +0 -399
- package/dist/commands/schema/__tests__/list.test.js.map +0 -1
- package/dist/commands/schema/__tests__/validate.test.js +0 -121
- package/dist/commands/schema/__tests__/validate.test.js.map +0 -1
- package/dist/commands/telemetry/__tests__/disable.test.js +0 -147
- package/dist/commands/telemetry/__tests__/disable.test.js.map +0 -1
- package/dist/commands/telemetry/__tests__/enable.test.js +0 -133
- package/dist/commands/telemetry/__tests__/enable.test.js.map +0 -1
- package/dist/commands/telemetry/__tests__/status.test.js +0 -155
- package/dist/commands/telemetry/__tests__/status.test.js.map +0 -1
- package/dist/commands/tokens/__tests__/add.test.js +0 -435
- package/dist/commands/tokens/__tests__/add.test.js.map +0 -1
- package/dist/commands/tokens/__tests__/delete.test.js +0 -405
- package/dist/commands/tokens/__tests__/delete.test.js.map +0 -1
- package/dist/commands/tokens/__tests__/list.test.js +0 -395
- package/dist/commands/tokens/__tests__/list.test.js.map +0 -1
- package/dist/commands/users/__tests__/invite.test.js +0 -362
- package/dist/commands/users/__tests__/invite.test.js.map +0 -1
- package/dist/commands/users/__tests__/list.test.js +0 -407
- package/dist/commands/users/__tests__/list.test.js.map +0 -1
- package/dist/hooks/prerun/__tests__/setupTelemetry.test.js +0 -77
- package/dist/hooks/prerun/__tests__/setupTelemetry.test.js.map +0 -1
- package/dist/services/__tests__/datasetAliases.test.js +0 -131
- package/dist/services/__tests__/datasetAliases.test.js.map +0 -1
- package/dist/services/__tests__/datasets.test.js +0 -436
- package/dist/services/__tests__/datasets.test.js.map +0 -1
- package/dist/services/__tests__/graphql.test.js +0 -43
- package/dist/services/__tests__/graphql.test.js.map +0 -1
- package/dist/services/__tests__/mediaLibraries.test.js +0 -88
- package/dist/services/__tests__/mediaLibraries.test.js.map +0 -1
- package/dist/services/__tests__/projects.test.js +0 -41
- package/dist/services/__tests__/projects.test.js.map +0 -1
- package/dist/services/__tests__/userApplications.test.js +0 -113
- package/dist/services/__tests__/userApplications.test.js.map +0 -1
- package/dist/util/__tests__/appId.test.js +0 -31
- package/dist/util/__tests__/appId.test.js.map +0 -1
- package/dist/util/__tests__/cliClient.test.js +0 -184
- package/dist/util/__tests__/cliClient.test.js.map +0 -1
- package/dist/util/__tests__/compareDependencyVersions.test.js +0 -426
- package/dist/util/__tests__/compareDependencyVersions.test.js.map +0 -1
- package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js +0 -74
- package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js.map +0 -1
- package/dist/util/__tests__/findNdjsonEntry.test.js +0 -54
- package/dist/util/__tests__/findNdjsonEntry.test.js.map +0 -1
- package/dist/util/__tests__/getCliVersion.test.js +0 -28
- package/dist/util/__tests__/getCliVersion.test.js.map +0 -1
- package/dist/util/__tests__/getLocalPackageVersion.test.js +0 -84
- package/dist/util/__tests__/getLocalPackageVersion.test.js.map +0 -1
- package/dist/util/__tests__/getWorkspace.test.js +0 -37
- package/dist/util/__tests__/getWorkspace.test.js.map +0 -1
- package/dist/util/__tests__/readPackageJson.test.js +0 -69
- package/dist/util/__tests__/readPackageJson.test.js.map +0 -1
- package/dist/util/__tests__/warnAboutMissingAppId.test.js +0 -28
- package/dist/util/__tests__/warnAboutMissingAppId.test.js.map +0 -1
- package/dist/util/packageManager/__tests__/installPackages.test.js +0 -388
- package/dist/util/packageManager/__tests__/installPackages.test.js.map +0 -1
- package/dist/util/validation/ __tests__/validateDocuments.test.js +0 -274
- package/dist/util/validation/ __tests__/validateDocuments.test.js.map +0 -1
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { runCommand } from '@oclif/test';
|
|
2
|
-
import { getCliConfig } from '@sanity/cli-core';
|
|
3
|
-
import { mockApi, testCommand } from '@sanity/cli-test';
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
-
import { extractManifestSafe } from '../../../actions/manifest/extractManifest.js';
|
|
6
|
-
import { createManifestReader } from '../../../actions/schema/utils/manifestReader.js';
|
|
7
|
-
import { SCHEMA_API_VERSION } from '../../../services/schemas.js';
|
|
8
|
-
import { NO_DATASET_ID, NO_PROJECT_ID } from '../../../util/errorMessages.js';
|
|
9
|
-
import { DeploySchemaCommand } from '../deploy.js';
|
|
10
|
-
const mockManifest = {
|
|
11
|
-
createdAt: '2024-01-01T00:00:00.000Z',
|
|
12
|
-
studioVersion: '3.0.0',
|
|
13
|
-
version: 3,
|
|
14
|
-
workspaces: [
|
|
15
|
-
{
|
|
16
|
-
basePath: '/',
|
|
17
|
-
dataset: 'production',
|
|
18
|
-
icon: null,
|
|
19
|
-
name: 'default',
|
|
20
|
-
projectId: 'test-project',
|
|
21
|
-
schema: 'default.create-schema.json',
|
|
22
|
-
tools: 'default.create-tools.json'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
basePath: '/staging',
|
|
26
|
-
dataset: 'staging',
|
|
27
|
-
icon: null,
|
|
28
|
-
name: 'staging',
|
|
29
|
-
projectId: 'test-project',
|
|
30
|
-
schema: 'staging.create-schema.json',
|
|
31
|
-
tools: 'staging.create-tools.json'
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
};
|
|
35
|
-
vi.mock('../../../../../cli-core/src/config/findProjectRoot.js', async ()=>({
|
|
36
|
-
findProjectRoot: vi.fn().mockResolvedValue({})
|
|
37
|
-
}));
|
|
38
|
-
vi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', ()=>({
|
|
39
|
-
getCliConfig: vi.fn()
|
|
40
|
-
}));
|
|
41
|
-
vi.mock('../../../actions/manifest/extractManifest.js');
|
|
42
|
-
vi.mock('../../../actions/schema/utils/manifestReader.js');
|
|
43
|
-
const mockedGetCliConfig = vi.mocked(getCliConfig);
|
|
44
|
-
const mockExtractManifestSafe = vi.mocked(extractManifestSafe);
|
|
45
|
-
const mockedCreateManifestReader = vi.mocked(createManifestReader);
|
|
46
|
-
describe('#schema:deploy', ()=>{
|
|
47
|
-
beforeEach(()=>{
|
|
48
|
-
vi.clearAllMocks();
|
|
49
|
-
mockedGetCliConfig.mockResolvedValue({
|
|
50
|
-
api: {
|
|
51
|
-
dataset: 'production',
|
|
52
|
-
projectId: 'test-project'
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
mockedCreateManifestReader.mockReturnValue({
|
|
56
|
-
getManifest: vi.fn().mockResolvedValue(mockManifest),
|
|
57
|
-
getWorkspaceSchema: vi.fn()
|
|
58
|
-
});
|
|
59
|
-
mockExtractManifestSafe.mockResolvedValue(undefined);
|
|
60
|
-
});
|
|
61
|
-
afterEach(()=>{
|
|
62
|
-
vi.clearAllMocks();
|
|
63
|
-
});
|
|
64
|
-
test('should show --help text', async ()=>{
|
|
65
|
-
const { stdout } = await runCommand('schema deploy --help');
|
|
66
|
-
expect(stdout).toMatchInlineSnapshot(`
|
|
67
|
-
"Deploy schema documents into workspace datasets.
|
|
68
|
-
|
|
69
|
-
USAGE
|
|
70
|
-
$ sanity schema deploy [--extract-manifest] [--manifest-dir <directory>]
|
|
71
|
-
[--tag <tag>] [--verbose] [--workspace <name>]
|
|
72
|
-
|
|
73
|
-
FLAGS
|
|
74
|
-
--[no-]extract-manifest Disables manifest generation - the command will
|
|
75
|
-
fail if no manifest exists
|
|
76
|
-
--manifest-dir=<directory> [default: ./dist/static] Directory containing
|
|
77
|
-
manifest file
|
|
78
|
-
--tag=<tag> Add a tag suffix to the schema id
|
|
79
|
-
--verbose Print detailed information during deployment
|
|
80
|
-
--workspace=<name> The name of the workspace to deploy a schema for
|
|
81
|
-
|
|
82
|
-
DESCRIPTION
|
|
83
|
-
Deploy schema documents into workspace datasets.
|
|
84
|
-
|
|
85
|
-
**Note**: This command is experimental and subject to change.
|
|
86
|
-
|
|
87
|
-
This operation (re-)generates a manifest file describing the sanity config
|
|
88
|
-
workspace by default.
|
|
89
|
-
To re-use an existing manifest file, use --no-extract-manifest.
|
|
90
|
-
|
|
91
|
-
EXAMPLES
|
|
92
|
-
Deploy all workspace schemas
|
|
93
|
-
|
|
94
|
-
$ sanity schema deploy
|
|
95
|
-
|
|
96
|
-
Deploy the schema for only the workspace "default"
|
|
97
|
-
|
|
98
|
-
$ sanity schema deploy --workspace default
|
|
99
|
-
|
|
100
|
-
Runs using a pre-existing manifest file. Config changes in sanity.config
|
|
101
|
-
will not be picked up in this case.
|
|
102
|
-
|
|
103
|
-
$ sanity schema deploy --no-extract-manifest
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
`);
|
|
107
|
-
});
|
|
108
|
-
test('should deploy schemas', async ()=>{
|
|
109
|
-
mockApi({
|
|
110
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
111
|
-
method: 'put',
|
|
112
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
113
|
-
}).reply(200, undefined);
|
|
114
|
-
mockApi({
|
|
115
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
116
|
-
method: 'put',
|
|
117
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
118
|
-
}).reply(200, undefined);
|
|
119
|
-
const { stdout } = await testCommand(DeploySchemaCommand);
|
|
120
|
-
expect(stdout).toContain('Deployed 2/2 schemas');
|
|
121
|
-
expect(stdout).toContain('↳ List deployed schemas with: sanity schema list');
|
|
122
|
-
});
|
|
123
|
-
test('should deploy a specific schema based on workspace flag', async ()=>{
|
|
124
|
-
mockApi({
|
|
125
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
126
|
-
method: 'put',
|
|
127
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
128
|
-
}).reply(200, undefined);
|
|
129
|
-
const { stdout } = await testCommand(DeploySchemaCommand, [
|
|
130
|
-
'--workspace',
|
|
131
|
-
'default'
|
|
132
|
-
]);
|
|
133
|
-
expect(stdout).toContain('Deployed 1/1 schemas');
|
|
134
|
-
expect(stdout).toContain('↳ List deployed schemas with: sanity schema list');
|
|
135
|
-
});
|
|
136
|
-
test('should enable verbose logging with verbose flag', async ()=>{
|
|
137
|
-
mockApi({
|
|
138
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
139
|
-
method: 'put',
|
|
140
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
141
|
-
}).reply(200, undefined);
|
|
142
|
-
mockApi({
|
|
143
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
144
|
-
method: 'put',
|
|
145
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
146
|
-
}).reply(200, undefined);
|
|
147
|
-
const { stdout } = await testCommand(DeploySchemaCommand, [
|
|
148
|
-
'--verbose'
|
|
149
|
-
]);
|
|
150
|
-
expect(stdout).toContain('↳ schemaId: _.schemas.default, projectId: test-project, dataset: production');
|
|
151
|
-
});
|
|
152
|
-
test.each([
|
|
153
|
-
{
|
|
154
|
-
desc: 'no project ID is found',
|
|
155
|
-
projectId: undefined
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
desc: 'project ID is empty string',
|
|
159
|
-
projectId: ''
|
|
160
|
-
}
|
|
161
|
-
])('throws an error if $desc', async ({ projectId })=>{
|
|
162
|
-
mockedGetCliConfig.mockResolvedValue({
|
|
163
|
-
api: {
|
|
164
|
-
dataset: 'production',
|
|
165
|
-
projectId
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
const { error } = await testCommand(DeploySchemaCommand);
|
|
169
|
-
expect(error?.message).toContain(NO_PROJECT_ID);
|
|
170
|
-
});
|
|
171
|
-
test.each([
|
|
172
|
-
{
|
|
173
|
-
dataset: undefined,
|
|
174
|
-
desc: 'no dataset is found'
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
dataset: '',
|
|
178
|
-
desc: 'dataset is empty string'
|
|
179
|
-
}
|
|
180
|
-
])('throws an error if $desc', async ({ dataset })=>{
|
|
181
|
-
mockedGetCliConfig.mockResolvedValue({
|
|
182
|
-
api: {
|
|
183
|
-
dataset,
|
|
184
|
-
projectId: 'test-project'
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
const { error } = await testCommand(DeploySchemaCommand);
|
|
188
|
-
expect(error?.message).toContain(NO_DATASET_ID);
|
|
189
|
-
});
|
|
190
|
-
test.each([
|
|
191
|
-
{
|
|
192
|
-
flag: 'tag'
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
flag: 'workspace'
|
|
196
|
-
}
|
|
197
|
-
])('throws error when $flag flag is empty string', async ({ flag })=>{
|
|
198
|
-
const { error } = await testCommand(DeploySchemaCommand, [
|
|
199
|
-
`--${flag}`,
|
|
200
|
-
''
|
|
201
|
-
]);
|
|
202
|
-
expect(error?.message).toContain(`${flag} argument is empty`);
|
|
203
|
-
});
|
|
204
|
-
test.each([
|
|
205
|
-
{
|
|
206
|
-
desc: 'contains period',
|
|
207
|
-
expectedError: 'tag cannot contain . (period)',
|
|
208
|
-
tag: 'test.tag'
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
desc: 'starts with dash',
|
|
212
|
-
expectedError: 'tag cannot start with - (dash)',
|
|
213
|
-
tag: '-testtag'
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
desc: 'contains invalid character (space)',
|
|
217
|
-
expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',
|
|
218
|
-
tag: 'test tag'
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
desc: 'contains invalid character (@)',
|
|
222
|
-
expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',
|
|
223
|
-
tag: 'test@tag'
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
desc: 'contains invalid character (!)',
|
|
227
|
-
expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',
|
|
228
|
-
tag: 'test!'
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
desc: 'contains multiple periods',
|
|
232
|
-
expectedError: 'tag cannot contain . (period)',
|
|
233
|
-
tag: 'test.tag.name'
|
|
234
|
-
}
|
|
235
|
-
])('throws error when tag $desc', async ({ expectedError, tag })=>{
|
|
236
|
-
const { error } = await testCommand(DeploySchemaCommand, [
|
|
237
|
-
'--tag',
|
|
238
|
-
tag
|
|
239
|
-
]);
|
|
240
|
-
expect(error?.message).toContain(expectedError);
|
|
241
|
-
});
|
|
242
|
-
test.each([
|
|
243
|
-
{
|
|
244
|
-
desc: 'valid tag with alphanumeric',
|
|
245
|
-
tag: 'v1'
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
desc: 'valid tag with underscore',
|
|
249
|
-
tag: 'feature_branch'
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
desc: 'valid tag with dash in middle',
|
|
253
|
-
tag: 'test-tag'
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
desc: 'valid tag with mixed case',
|
|
257
|
-
tag: 'TestTag123'
|
|
258
|
-
}
|
|
259
|
-
])('successfully parses $desc', async ({ tag })=>{
|
|
260
|
-
mockApi({
|
|
261
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
262
|
-
method: 'put',
|
|
263
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
264
|
-
}).reply(200, undefined);
|
|
265
|
-
mockApi({
|
|
266
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
267
|
-
method: 'put',
|
|
268
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
269
|
-
}).reply(200, undefined);
|
|
270
|
-
const { error } = await testCommand(DeploySchemaCommand, [
|
|
271
|
-
'--tag',
|
|
272
|
-
tag
|
|
273
|
-
]);
|
|
274
|
-
expect(error).toBeUndefined();
|
|
275
|
-
});
|
|
276
|
-
test('throw an error if some schemas fail to deploy', async ()=>{
|
|
277
|
-
mockApi({
|
|
278
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
279
|
-
method: 'put',
|
|
280
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
281
|
-
}).reply(200, undefined);
|
|
282
|
-
mockApi({
|
|
283
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
284
|
-
method: 'put',
|
|
285
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
286
|
-
}).reply(404, undefined);
|
|
287
|
-
const { error, stdout } = await testCommand(DeploySchemaCommand);
|
|
288
|
-
expect(error?.message).toContain('Failed to deploy 1/2 schemas. Successfully deployed 1/2 schemas.');
|
|
289
|
-
expect(stdout).toContain('↳ List deployed schemas with: sanity schema list');
|
|
290
|
-
});
|
|
291
|
-
test('throws an error if workspace is not found', async ()=>{
|
|
292
|
-
const { error } = await testCommand(DeploySchemaCommand, [
|
|
293
|
-
'--workspace',
|
|
294
|
-
'test'
|
|
295
|
-
]);
|
|
296
|
-
expect(error?.message).toContain('Found no workspaces named "test"');
|
|
297
|
-
});
|
|
298
|
-
test('throws an error if schema request fails', async ()=>{
|
|
299
|
-
mockApi({
|
|
300
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
301
|
-
method: 'put',
|
|
302
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
303
|
-
}).reply(400, {
|
|
304
|
-
error: 'Bad request'
|
|
305
|
-
});
|
|
306
|
-
mockApi({
|
|
307
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
308
|
-
method: 'put',
|
|
309
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
310
|
-
}).reply(400, {
|
|
311
|
-
error: 'Bad request'
|
|
312
|
-
});
|
|
313
|
-
const { error } = await testCommand(DeploySchemaCommand);
|
|
314
|
-
expect(error?.message).toContain('↳ Error when storing schemas');
|
|
315
|
-
});
|
|
316
|
-
test('throws an error if schema request fails due to permissions', async ()=>{
|
|
317
|
-
mockApi({
|
|
318
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
319
|
-
method: 'put',
|
|
320
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
321
|
-
}).reply(401);
|
|
322
|
-
mockApi({
|
|
323
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
324
|
-
method: 'put',
|
|
325
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
326
|
-
}).reply(200, undefined);
|
|
327
|
-
const { stderr } = await testCommand(DeploySchemaCommand);
|
|
328
|
-
expect(stderr).toContain('↳ No permissions to write schema for workspace "default"');
|
|
329
|
-
});
|
|
330
|
-
test('skips manifest extraction with no-extract-manifest flag', async ()=>{
|
|
331
|
-
mockApi({
|
|
332
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
333
|
-
method: 'put',
|
|
334
|
-
uri: '/projects/test-project/datasets/production/schemas'
|
|
335
|
-
}).reply(200, undefined);
|
|
336
|
-
mockApi({
|
|
337
|
-
apiVersion: SCHEMA_API_VERSION,
|
|
338
|
-
method: 'put',
|
|
339
|
-
uri: '/projects/test-project/datasets/staging/schemas'
|
|
340
|
-
}).reply(200, undefined);
|
|
341
|
-
await testCommand(DeploySchemaCommand, [
|
|
342
|
-
'--no-extract-manifest'
|
|
343
|
-
]);
|
|
344
|
-
expect(mockExtractManifestSafe).not.toHaveBeenCalled();
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
//# sourceMappingURL=deploy.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/schema/__tests__/deploy.test.ts"],"sourcesContent":["import {runCommand} from '@oclif/test'\nimport {getCliConfig} from '@sanity/cli-core'\nimport {mockApi, testCommand} from '@sanity/cli-test'\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {extractManifestSafe} from '../../../actions/manifest/extractManifest.js'\nimport {createManifestReader} from '../../../actions/schema/utils/manifestReader.js'\nimport {SCHEMA_API_VERSION} from '../../../services/schemas.js'\nimport {NO_DATASET_ID, NO_PROJECT_ID} from '../../../util/errorMessages.js'\nimport {DeploySchemaCommand} from '../deploy.js'\n\nconst mockManifest = {\n createdAt: '2024-01-01T00:00:00.000Z',\n studioVersion: '3.0.0',\n version: 3,\n workspaces: [\n {\n basePath: '/',\n dataset: 'production',\n icon: null,\n name: 'default',\n projectId: 'test-project',\n schema: 'default.create-schema.json',\n tools: 'default.create-tools.json',\n },\n {\n basePath: '/staging',\n dataset: 'staging',\n icon: null,\n name: 'staging',\n projectId: 'test-project',\n schema: 'staging.create-schema.json',\n tools: 'staging.create-tools.json',\n },\n ],\n}\n\nvi.mock('../../../../../cli-core/src/config/findProjectRoot.js', async () => ({\n findProjectRoot: vi.fn().mockResolvedValue({}),\n}))\n\nvi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', () => ({\n getCliConfig: vi.fn(),\n}))\n\nvi.mock('../../../actions/manifest/extractManifest.js')\nvi.mock('../../../actions/schema/utils/manifestReader.js')\n\nconst mockedGetCliConfig = vi.mocked(getCliConfig)\nconst mockExtractManifestSafe = vi.mocked(extractManifestSafe)\nconst mockedCreateManifestReader = vi.mocked(createManifestReader)\n\ndescribe('#schema:deploy', () => {\n beforeEach(() => {\n vi.clearAllMocks()\n\n mockedGetCliConfig.mockResolvedValue({\n api: {\n dataset: 'production',\n projectId: 'test-project',\n },\n })\n\n mockedCreateManifestReader.mockReturnValue({\n getManifest: vi.fn().mockResolvedValue(mockManifest),\n getWorkspaceSchema: vi.fn(),\n })\n\n mockExtractManifestSafe.mockResolvedValue(undefined)\n })\n\n afterEach(() => {\n vi.clearAllMocks()\n })\n\n test('should show --help text', async () => {\n const {stdout} = await runCommand('schema deploy --help')\n\n expect(stdout).toMatchInlineSnapshot(`\n \"Deploy schema documents into workspace datasets.\n\n USAGE\n $ sanity schema deploy [--extract-manifest] [--manifest-dir <directory>]\n [--tag <tag>] [--verbose] [--workspace <name>]\n\n FLAGS\n --[no-]extract-manifest Disables manifest generation - the command will\n fail if no manifest exists\n --manifest-dir=<directory> [default: ./dist/static] Directory containing\n manifest file\n --tag=<tag> Add a tag suffix to the schema id\n --verbose Print detailed information during deployment\n --workspace=<name> The name of the workspace to deploy a schema for\n\n DESCRIPTION\n Deploy schema documents into workspace datasets.\n\n **Note**: This command is experimental and subject to change.\n\n This operation (re-)generates a manifest file describing the sanity config\n workspace by default.\n To re-use an existing manifest file, use --no-extract-manifest.\n\n EXAMPLES\n Deploy all workspace schemas\n\n $ sanity schema deploy\n\n Deploy the schema for only the workspace \"default\"\n\n $ sanity schema deploy --workspace default\n\n Runs using a pre-existing manifest file. Config changes in sanity.config\n will not be picked up in this case.\n\n $ sanity schema deploy --no-extract-manifest\n\n \"\n `)\n })\n\n test('should deploy schemas', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(200, undefined)\n\n const {stdout} = await testCommand(DeploySchemaCommand)\n\n expect(stdout).toContain('Deployed 2/2 schemas')\n expect(stdout).toContain('↳ List deployed schemas with: sanity schema list')\n })\n\n test('should deploy a specific schema based on workspace flag', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n\n const {stdout} = await testCommand(DeploySchemaCommand, ['--workspace', 'default'])\n\n expect(stdout).toContain('Deployed 1/1 schemas')\n expect(stdout).toContain('↳ List deployed schemas with: sanity schema list')\n })\n\n test('should enable verbose logging with verbose flag', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(200, undefined)\n\n const {stdout} = await testCommand(DeploySchemaCommand, ['--verbose'])\n\n expect(stdout).toContain(\n '↳ schemaId: _.schemas.default, projectId: test-project, dataset: production',\n )\n })\n\n test.each([\n {desc: 'no project ID is found', projectId: undefined},\n {desc: 'project ID is empty string', projectId: ''},\n ])('throws an error if $desc', async ({projectId}) => {\n mockedGetCliConfig.mockResolvedValue({\n api: {\n dataset: 'production',\n projectId,\n },\n })\n\n const {error} = await testCommand(DeploySchemaCommand)\n\n expect(error?.message).toContain(NO_PROJECT_ID)\n })\n\n test.each([\n {dataset: undefined, desc: 'no dataset is found'},\n {dataset: '', desc: 'dataset is empty string'},\n ])('throws an error if $desc', async ({dataset}) => {\n mockedGetCliConfig.mockResolvedValue({\n api: {\n dataset,\n projectId: 'test-project',\n },\n })\n\n const {error} = await testCommand(DeploySchemaCommand)\n\n expect(error?.message).toContain(NO_DATASET_ID)\n })\n\n test.each([{flag: 'tag'}, {flag: 'workspace'}])(\n 'throws error when $flag flag is empty string',\n async ({flag}) => {\n const {error} = await testCommand(DeploySchemaCommand, [`--${flag}`, ''])\n\n expect(error?.message).toContain(`${flag} argument is empty`)\n },\n )\n\n test.each([\n {\n desc: 'contains period',\n expectedError: 'tag cannot contain . (period)',\n tag: 'test.tag',\n },\n {\n desc: 'starts with dash',\n expectedError: 'tag cannot start with - (dash)',\n tag: '-testtag',\n },\n {\n desc: 'contains invalid character (space)',\n expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',\n tag: 'test tag',\n },\n {\n desc: 'contains invalid character (@)',\n expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',\n tag: 'test@tag',\n },\n {\n desc: 'contains invalid character (!)',\n expectedError: 'tag can only contain characters in [a-zA-Z0-9_-]',\n tag: 'test!',\n },\n {\n desc: 'contains multiple periods',\n expectedError: 'tag cannot contain . (period)',\n tag: 'test.tag.name',\n },\n ])('throws error when tag $desc', async ({expectedError, tag}) => {\n const {error} = await testCommand(DeploySchemaCommand, ['--tag', tag])\n\n expect(error?.message).toContain(expectedError)\n })\n\n test.each([\n {\n desc: 'valid tag with alphanumeric',\n tag: 'v1',\n },\n {\n desc: 'valid tag with underscore',\n tag: 'feature_branch',\n },\n {\n desc: 'valid tag with dash in middle',\n tag: 'test-tag',\n },\n {\n desc: 'valid tag with mixed case',\n tag: 'TestTag123',\n },\n ])('successfully parses $desc', async ({tag}) => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(200, undefined)\n\n const {error} = await testCommand(DeploySchemaCommand, ['--tag', tag])\n\n expect(error).toBeUndefined()\n })\n\n test('throw an error if some schemas fail to deploy', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(404, undefined)\n\n const {error, stdout} = await testCommand(DeploySchemaCommand)\n\n expect(error?.message).toContain(\n 'Failed to deploy 1/2 schemas. Successfully deployed 1/2 schemas.',\n )\n expect(stdout).toContain('↳ List deployed schemas with: sanity schema list')\n })\n\n test('throws an error if workspace is not found', async () => {\n const {error} = await testCommand(DeploySchemaCommand, ['--workspace', 'test'])\n\n expect(error?.message).toContain('Found no workspaces named \"test\"')\n })\n\n test('throws an error if schema request fails', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(400, {\n error: 'Bad request',\n })\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(400, {\n error: 'Bad request',\n })\n\n const {error} = await testCommand(DeploySchemaCommand)\n\n expect(error?.message).toContain('↳ Error when storing schemas')\n })\n\n test('throws an error if schema request fails due to permissions', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(401)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(200, undefined)\n\n const {stderr} = await testCommand(DeploySchemaCommand)\n\n expect(stderr).toContain('↳ No permissions to write schema for workspace \"default\"')\n })\n\n test('skips manifest extraction with no-extract-manifest flag', async () => {\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/production/schemas',\n }).reply(200, undefined)\n mockApi({\n apiVersion: SCHEMA_API_VERSION,\n method: 'put',\n uri: '/projects/test-project/datasets/staging/schemas',\n }).reply(200, undefined)\n\n await testCommand(DeploySchemaCommand, ['--no-extract-manifest'])\n\n expect(mockExtractManifestSafe).not.toHaveBeenCalled()\n })\n})\n"],"names":["runCommand","getCliConfig","mockApi","testCommand","afterEach","beforeEach","describe","expect","test","vi","extractManifestSafe","createManifestReader","SCHEMA_API_VERSION","NO_DATASET_ID","NO_PROJECT_ID","DeploySchemaCommand","mockManifest","createdAt","studioVersion","version","workspaces","basePath","dataset","icon","name","projectId","schema","tools","mock","findProjectRoot","fn","mockResolvedValue","mockedGetCliConfig","mocked","mockExtractManifestSafe","mockedCreateManifestReader","clearAllMocks","api","mockReturnValue","getManifest","getWorkspaceSchema","undefined","stdout","toMatchInlineSnapshot","apiVersion","method","uri","reply","toContain","each","desc","error","message","flag","expectedError","tag","toBeUndefined","stderr","not","toHaveBeenCalled"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;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OC,SAASJ,SAAS,CAAC;IACnC;IAEAxC,KAAK,2CAA2C;QAC9CN,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAK;YACZI,OAAO;QACT;QACAjD,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAK;YACZI,OAAO;QACT;QAEA,MAAM,EAACA,KAAK,EAAC,GAAG,MAAMhD,YAAYY;QAElCR,OAAO4C,OAAOC,SAASJ,SAAS,CAAC;IACnC;IAEAxC,KAAK,8DAA8D;QACjEN,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC;QACT7C,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAKN;QAEd,MAAM,EAACgB,MAAM,EAAC,GAAG,MAAMtD,YAAYY;QAEnCR,OAAOkD,QAAQT,SAAS,CAAC;IAC3B;IAEAxC,KAAK,2DAA2D;QAC9DN,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAKN;QACdvC,QAAQ;YACN0C,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAKN;QAEd,MAAMtC,YAAYY,qBAAqB;YAAC;SAAwB;QAEhER,OAAO2B,yBAAyBwB,GAAG,CAACC,gBAAgB;IACtD;AACF"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { runCommand } from '@oclif/test';
|
|
3
|
-
import { testCommand } from '@sanity/cli-test';
|
|
4
|
-
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
5
|
-
import { ExtractSchemaCommand } from '../extract.js';
|
|
6
|
-
vi.mock('node:fs/promises');
|
|
7
|
-
const defaultMocks = {
|
|
8
|
-
projectRoot: {
|
|
9
|
-
directory: '/test/project',
|
|
10
|
-
path: '/test/project/sanity.config.ts',
|
|
11
|
-
type: 'studio'
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
vi.mock('../../../util/getWorkspace.js', ()=>({
|
|
15
|
-
getWorkspace: vi.fn().mockReturnValue({})
|
|
16
|
-
}));
|
|
17
|
-
vi.mock('../../../util/importStudioConfig.js', async ()=>({
|
|
18
|
-
importStudioConfig: vi.fn()
|
|
19
|
-
}));
|
|
20
|
-
vi.mock('@sanity/schema/_internal', ()=>({
|
|
21
|
-
extractSchema: vi.fn().mockReturnValue([
|
|
22
|
-
{
|
|
23
|
-
fields: [
|
|
24
|
-
{
|
|
25
|
-
name: 'type',
|
|
26
|
-
title: 'string'
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
name: 'post',
|
|
30
|
-
type: 'document'
|
|
31
|
-
}
|
|
32
|
-
])
|
|
33
|
-
}));
|
|
34
|
-
const mockMkdir = vi.mocked(mkdir);
|
|
35
|
-
const mockWriteFile = vi.mocked(writeFile);
|
|
36
|
-
describe('#schema:extract', ()=>{
|
|
37
|
-
afterEach(()=>{
|
|
38
|
-
vi.clearAllMocks();
|
|
39
|
-
});
|
|
40
|
-
test('should show --help text', async ()=>{
|
|
41
|
-
const { stdout } = await runCommand('schema extract --help');
|
|
42
|
-
expect(stdout).toMatchInlineSnapshot(`
|
|
43
|
-
"Extracts a JSON representation of a Sanity schema within a Studio context.
|
|
44
|
-
|
|
45
|
-
USAGE
|
|
46
|
-
$ sanity schema extract [--enforce-required-fields] [--format <format>]
|
|
47
|
-
[--path <value>] [--workspace <name>]
|
|
48
|
-
|
|
49
|
-
FLAGS
|
|
50
|
-
--enforce-required-fields Makes the schema generated treat fields marked as
|
|
51
|
-
required as non-optional
|
|
52
|
-
--format=<format> [default: groq-type-nodes] Format the schema as
|
|
53
|
-
GROQ type nodes. Only available format at the
|
|
54
|
-
moment.
|
|
55
|
-
--path=<value> Optional path to specify destination of the schema
|
|
56
|
-
file
|
|
57
|
-
--workspace=<name> The name of the workspace to generate a schema for
|
|
58
|
-
|
|
59
|
-
DESCRIPTION
|
|
60
|
-
Extracts a JSON representation of a Sanity schema within a Studio context.
|
|
61
|
-
|
|
62
|
-
**Note**: This command is experimental and subject to change.
|
|
63
|
-
|
|
64
|
-
EXAMPLES
|
|
65
|
-
Extracts schema types in a Sanity project with more than one workspace
|
|
66
|
-
|
|
67
|
-
$ sanity schema extract --workspace default
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
`);
|
|
71
|
-
});
|
|
72
|
-
test('should extract schema', async ()=>{
|
|
73
|
-
mockWriteFile.mockResolvedValue(undefined);
|
|
74
|
-
const { stderr } = await testCommand(ExtractSchemaCommand, [], {
|
|
75
|
-
mocks: defaultMocks
|
|
76
|
-
});
|
|
77
|
-
expect(stderr).toContain('Extracting schema');
|
|
78
|
-
expect(stderr).toContain('✔ Extracted schema');
|
|
79
|
-
expect(mockWriteFile).toHaveBeenCalledWith(expect.stringContaining('schema.json'), // eslint-disable-next-line no-useless-escape
|
|
80
|
-
expect.stringContaining(`\"name\": \"post\"`));
|
|
81
|
-
});
|
|
82
|
-
test('should extract schema with enforce-required-fields flag', async ()=>{
|
|
83
|
-
mockWriteFile.mockResolvedValue(undefined);
|
|
84
|
-
const { stderr } = await testCommand(ExtractSchemaCommand, [
|
|
85
|
-
'--enforce-required-fields'
|
|
86
|
-
], {
|
|
87
|
-
mocks: defaultMocks
|
|
88
|
-
});
|
|
89
|
-
expect(stderr).toContain('Extracting schema with enforced required fields');
|
|
90
|
-
});
|
|
91
|
-
test('should extract schema with path flag', async ()=>{
|
|
92
|
-
mockMkdir.mockResolvedValue(undefined);
|
|
93
|
-
mockWriteFile.mockResolvedValue(undefined);
|
|
94
|
-
const { stderr } = await testCommand(ExtractSchemaCommand, [
|
|
95
|
-
'--path',
|
|
96
|
-
'/test'
|
|
97
|
-
], {
|
|
98
|
-
mocks: defaultMocks
|
|
99
|
-
});
|
|
100
|
-
expect(stderr).toContain('Extracting schema');
|
|
101
|
-
expect(stderr).toContain('✔ Extracted schema');
|
|
102
|
-
expect(mockMkdir).toHaveBeenCalledWith('/test/project/test', {
|
|
103
|
-
recursive: true
|
|
104
|
-
});
|
|
105
|
-
expect(mockWriteFile).toHaveBeenCalledWith('/test/project/test/schema.json', // eslint-disable-next-line no-useless-escape
|
|
106
|
-
expect.stringContaining(`\"name\": \"post\"`));
|
|
107
|
-
});
|
|
108
|
-
test('throws an error if format flag is not groq-type-nodes', async ()=>{
|
|
109
|
-
const { error, stderr } = await testCommand(ExtractSchemaCommand, [
|
|
110
|
-
'--format',
|
|
111
|
-
'test-format'
|
|
112
|
-
], {
|
|
113
|
-
mocks: defaultMocks
|
|
114
|
-
});
|
|
115
|
-
expect(stderr).toContain('Extracting schema');
|
|
116
|
-
expect(stderr).toContain('Failed to extract schema');
|
|
117
|
-
expect(error?.message).toContain('Unsupported format: "test-format"');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
//# sourceMappingURL=extract.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/schema/__tests__/extract.test.ts"],"sourcesContent":["import {mkdir, writeFile} from 'node:fs/promises'\n\nimport {runCommand} from '@oclif/test'\nimport {testCommand} from '@sanity/cli-test'\nimport {afterEach, describe, expect, test, vi} from 'vitest'\n\nimport {ExtractSchemaCommand} from '../extract.js'\n\nvi.mock('node:fs/promises')\n\nconst defaultMocks = {\n projectRoot: {\n directory: '/test/project',\n path: '/test/project/sanity.config.ts',\n type: 'studio' as const,\n },\n}\n\nvi.mock('../../../util/getWorkspace.js', () => ({\n getWorkspace: vi.fn().mockReturnValue({}),\n}))\n\nvi.mock('../../../util/importStudioConfig.js', async () => ({\n importStudioConfig: vi.fn(),\n}))\n\nvi.mock('@sanity/schema/_internal', () => ({\n extractSchema: vi.fn().mockReturnValue([\n {\n fields: [\n {\n name: 'type',\n title: 'string',\n },\n ],\n name: 'post',\n type: 'document',\n },\n ]),\n}))\n\nconst mockMkdir = vi.mocked(mkdir)\nconst mockWriteFile = vi.mocked(writeFile)\n\ndescribe('#schema:extract', () => {\n afterEach(() => {\n vi.clearAllMocks()\n })\n\n test('should show --help text', async () => {\n const {stdout} = await runCommand('schema extract --help')\n\n expect(stdout).toMatchInlineSnapshot(`\n \"Extracts a JSON representation of a Sanity schema within a Studio context.\n\n USAGE\n $ sanity schema extract [--enforce-required-fields] [--format <format>]\n [--path <value>] [--workspace <name>]\n\n FLAGS\n --enforce-required-fields Makes the schema generated treat fields marked as\n required as non-optional\n --format=<format> [default: groq-type-nodes] Format the schema as\n GROQ type nodes. Only available format at the\n moment.\n --path=<value> Optional path to specify destination of the schema\n file\n --workspace=<name> The name of the workspace to generate a schema for\n\n DESCRIPTION\n Extracts a JSON representation of a Sanity schema within a Studio context.\n\n **Note**: This command is experimental and subject to change.\n\n EXAMPLES\n Extracts schema types in a Sanity project with more than one workspace\n\n $ sanity schema extract --workspace default\n\n \"\n `)\n })\n\n test('should extract schema', async () => {\n mockWriteFile.mockResolvedValue(undefined)\n\n const {stderr} = await testCommand(ExtractSchemaCommand, [], {mocks: defaultMocks})\n\n expect(stderr).toContain('Extracting schema')\n expect(stderr).toContain('✔ Extracted schema')\n\n expect(mockWriteFile).toHaveBeenCalledWith(\n expect.stringContaining('schema.json'),\n // eslint-disable-next-line no-useless-escape\n expect.stringContaining(`\\\"name\\\": \\\"post\\\"`),\n )\n })\n\n test('should extract schema with enforce-required-fields flag', async () => {\n mockWriteFile.mockResolvedValue(undefined)\n\n const {stderr} = await testCommand(ExtractSchemaCommand, ['--enforce-required-fields'], {mocks: defaultMocks})\n\n expect(stderr).toContain('Extracting schema with enforced required fields')\n })\n\n test('should extract schema with path flag', async () => {\n mockMkdir.mockResolvedValue(undefined)\n mockWriteFile.mockResolvedValue(undefined)\n\n const {stderr} = await testCommand(ExtractSchemaCommand, ['--path', '/test'], {mocks: defaultMocks})\n\n expect(stderr).toContain('Extracting schema')\n expect(stderr).toContain('✔ Extracted schema')\n\n expect(mockMkdir).toHaveBeenCalledWith('/test/project/test', {recursive: true})\n\n expect(mockWriteFile).toHaveBeenCalledWith(\n '/test/project/test/schema.json',\n // eslint-disable-next-line no-useless-escape\n expect.stringContaining(`\\\"name\\\": \\\"post\\\"`),\n )\n })\n\n test('throws an error if format flag is not groq-type-nodes', async () => {\n const {error, stderr} = await testCommand(ExtractSchemaCommand, ['--format', 'test-format'], {mocks: defaultMocks})\n\n expect(stderr).toContain('Extracting schema')\n expect(stderr).toContain('Failed to extract schema')\n expect(error?.message).toContain('Unsupported format: \"test-format\"')\n })\n})\n"],"names":["mkdir","writeFile","runCommand","testCommand","afterEach","describe","expect","test","vi","ExtractSchemaCommand","mock","defaultMocks","projectRoot","directory","path","type","getWorkspace","fn","mockReturnValue","importStudioConfig","extractSchema","fields","name","title","mockMkdir","mocked","mockWriteFile","clearAllMocks","stdout","toMatchInlineSnapshot","mockResolvedValue","undefined","stderr","mocks","toContain","toHaveBeenCalledWith","stringContaining","recursive","error","message"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,SAAS,QAAO,mBAAkB;AAEjD,SAAQC,UAAU,QAAO,cAAa;AACtC,SAAQC,WAAW,QAAO,mBAAkB;AAC5C,SAAQC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAE5D,SAAQC,oBAAoB,QAAO,gBAAe;AAElDD,GAAGE,IAAI,CAAC;AAER,MAAMC,eAAe;IACnBC,aAAa;QACXC,WAAW;QACXC,MAAM;QACNC,MAAM;IACR;AACF;AAEAP,GAAGE,IAAI,CAAC,iCAAiC,IAAO,CAAA;QAC9CM,cAAcR,GAAGS,EAAE,GAAGC,eAAe,CAAC,CAAC;IACzC,CAAA;AAEAV,GAAGE,IAAI,CAAC,uCAAuC,UAAa,CAAA;QAC1DS,oBAAoBX,GAAGS,EAAE;IAC3B,CAAA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