@sanity/cli 6.0.0-alpha.5 → 6.0.0-alpha.7

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.
Files changed (527) hide show
  1. package/README.md +2907 -109
  2. package/dist/actions/dataset/create.d.ts +49 -0
  3. package/dist/actions/dataset/create.js +48 -0
  4. package/dist/actions/dataset/create.js.map +1 -0
  5. package/dist/actions/dataset/determineDatasetAclMode.d.ts +37 -0
  6. package/dist/actions/dataset/determineDatasetAclMode.js +36 -0
  7. package/dist/actions/dataset/determineDatasetAclMode.js.map +1 -0
  8. package/dist/actions/debug/gatherDebugInfo.js +15 -21
  9. package/dist/actions/debug/gatherDebugInfo.js.map +1 -1
  10. package/dist/actions/debug/types.d.ts +0 -2
  11. package/dist/actions/debug/types.js.map +1 -1
  12. package/dist/actions/deploy/deployApp.js +13 -0
  13. package/dist/actions/deploy/deployApp.js.map +1 -1
  14. package/dist/actions/init/remoteTemplate.js +1 -1
  15. package/dist/actions/init/remoteTemplate.js.map +1 -1
  16. package/dist/actions/manifest/extractAppManifest.d.ts +20 -0
  17. package/dist/actions/manifest/extractAppManifest.js +51 -0
  18. package/dist/actions/manifest/extractAppManifest.js.map +1 -0
  19. package/dist/actions/manifest/extractManifest.js +1 -1
  20. package/dist/actions/manifest/extractManifest.js.map +1 -1
  21. package/dist/actions/manifest/types.d.ts +6 -1
  22. package/dist/actions/manifest/types.js.map +1 -1
  23. package/dist/actions/media/importAspects.js +2 -1
  24. package/dist/actions/media/importAspects.js.map +1 -1
  25. package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +1 -1
  26. package/dist/actions/telemetry/resolveConsent.d.ts +1 -9
  27. package/dist/actions/telemetry/resolveConsent.js +2 -2
  28. package/dist/actions/telemetry/resolveConsent.js.map +1 -1
  29. package/dist/actions/telemetry/setConsent.d.ts +1 -4
  30. package/dist/actions/telemetry/setConsent.js +4 -8
  31. package/dist/actions/telemetry/setConsent.js.map +1 -1
  32. package/dist/commands/dataset/create.d.ts +0 -2
  33. package/dist/commands/dataset/create.js +8 -54
  34. package/dist/commands/dataset/create.js.map +1 -1
  35. package/dist/commands/debug.js +5 -9
  36. package/dist/commands/debug.js.map +1 -1
  37. package/dist/commands/init.d.ts +6 -1
  38. package/dist/commands/init.js +358 -20
  39. package/dist/commands/init.js.map +1 -1
  40. package/dist/commands/manifest/extract.js +7 -8
  41. package/dist/commands/manifest/extract.js.map +1 -1
  42. package/dist/commands/telemetry/disable.js +0 -1
  43. package/dist/commands/telemetry/disable.js.map +1 -1
  44. package/dist/commands/telemetry/enable.js +0 -1
  45. package/dist/commands/telemetry/enable.js.map +1 -1
  46. package/dist/commands/telemetry/status.js +1 -3
  47. package/dist/commands/telemetry/status.js.map +1 -1
  48. package/dist/config/createCliConfig.d.ts +9 -0
  49. package/dist/hooks/prerun/flushTelemetry.worker.d.ts +2 -0
  50. package/dist/hooks/prerun/flushTelemetry.worker.js +22 -0
  51. package/dist/hooks/prerun/flushTelemetry.worker.js.map +1 -0
  52. package/dist/hooks/prerun/setupTelemetry.js +65 -1
  53. package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
  54. package/dist/prompts/init/promptForTypescript.d.ts +2 -0
  55. package/dist/prompts/init/promptForTypescript.js +15 -0
  56. package/dist/prompts/init/promptForTypescript.js.map +1 -0
  57. package/dist/prompts/promptForDatasetAclMode.d.ts +9 -0
  58. package/dist/prompts/promptForDatasetAclMode.js +27 -0
  59. package/dist/prompts/promptForDatasetAclMode.js.map +1 -0
  60. package/dist/prompts/promptForDatasetName.d.ts +1 -1
  61. package/dist/prompts/promptForDatasetName.js +4 -1
  62. package/dist/prompts/promptForDatasetName.js.map +1 -1
  63. package/dist/services/organizations.d.ts +3 -1
  64. package/dist/services/organizations.js +2 -1
  65. package/dist/services/organizations.js.map +1 -1
  66. package/dist/services/telemetry.d.ts +2 -0
  67. package/dist/services/telemetry.js +20 -0
  68. package/dist/services/telemetry.js.map +1 -0
  69. package/dist/services/user.d.ts +5 -0
  70. package/dist/services/user.js +12 -1
  71. package/dist/services/user.js.map +1 -1
  72. package/dist/services/userApplications.d.ts +3 -1
  73. package/dist/services/userApplications.js +5 -1
  74. package/dist/services/userApplications.js.map +1 -1
  75. package/dist/telemetry/cli.telemetry.d.ts +20 -0
  76. package/dist/telemetry/cli.telemetry.js +8 -0
  77. package/dist/telemetry/cli.telemetry.js.map +1 -0
  78. package/dist/telemetry/store/cleanupOldTelemetryFiles.d.ts +5 -0
  79. package/dist/telemetry/store/cleanupOldTelemetryFiles.js +30 -0
  80. package/dist/telemetry/store/cleanupOldTelemetryFiles.js.map +1 -0
  81. package/dist/telemetry/store/createTelemetryStore.d.ts +39 -0
  82. package/dist/telemetry/store/createTelemetryStore.js +95 -0
  83. package/dist/telemetry/store/createTelemetryStore.js.map +1 -0
  84. package/dist/telemetry/store/createTraceId.d.ts +10 -0
  85. package/dist/telemetry/store/createTraceId.js +10 -0
  86. package/dist/telemetry/store/createTraceId.js.map +1 -0
  87. package/dist/telemetry/store/debug.d.ts +5 -0
  88. package/dist/telemetry/store/debug.js +7 -0
  89. package/dist/telemetry/store/debug.js.map +1 -0
  90. package/dist/telemetry/store/findTelemetryFiles.d.ts +13 -0
  91. package/dist/telemetry/store/findTelemetryFiles.js +34 -0
  92. package/dist/telemetry/store/findTelemetryFiles.js.map +1 -0
  93. package/dist/telemetry/store/flushTelemetryFiles.d.ts +20 -0
  94. package/dist/telemetry/store/flushTelemetryFiles.js +107 -0
  95. package/dist/telemetry/store/flushTelemetryFiles.js.map +1 -0
  96. package/dist/telemetry/store/generateTelemetryFilePath.d.ts +17 -0
  97. package/dist/telemetry/store/generateTelemetryFilePath.js +30 -0
  98. package/dist/telemetry/store/generateTelemetryFilePath.js.map +1 -0
  99. package/dist/telemetry/store/getTelemetryBaseInfo.d.ts +27 -0
  100. package/dist/telemetry/store/getTelemetryBaseInfo.js +34 -0
  101. package/dist/telemetry/store/getTelemetryBaseInfo.js.map +1 -0
  102. package/dist/telemetry/store/logger.d.ts +6 -0
  103. package/dist/telemetry/store/logger.js +54 -0
  104. package/dist/telemetry/store/logger.js.map +1 -0
  105. package/dist/telemetry/store/trace.d.ts +6 -0
  106. package/dist/telemetry/store/trace.js +150 -0
  107. package/dist/telemetry/store/trace.js.map +1 -0
  108. package/dist/telemetry/utils/readNDJSON.d.ts +10 -0
  109. package/dist/telemetry/utils/readNDJSON.js +18 -0
  110. package/dist/telemetry/utils/readNDJSON.js.map +1 -0
  111. package/dist/util/detectRuntime.d.ts +8 -0
  112. package/dist/util/detectRuntime.js +20 -0
  113. package/dist/util/detectRuntime.js.map +1 -0
  114. package/dist/util/isStaging.d.ts +7 -0
  115. package/dist/util/isStaging.js +10 -0
  116. package/dist/util/isStaging.js.map +1 -0
  117. package/dist/util/parseArguments.d.ts +35 -0
  118. package/dist/util/parseArguments.js +42 -0
  119. package/dist/util/parseArguments.js.map +1 -0
  120. package/oclif.manifest.json +7 -1
  121. package/package.json +25 -18
  122. package/templates/app-quickstart/src/App.css +20 -0
  123. package/templates/app-quickstart/src/App.tsx +25 -0
  124. package/templates/app-quickstart/src/ExampleComponent.css +90 -0
  125. package/templates/app-quickstart/src/ExampleComponent.tsx +37 -0
  126. package/templates/app-sanity-ui/src/App.tsx +34 -0
  127. package/templates/app-sanity-ui/src/ExampleComponent.tsx +34 -0
  128. package/templates/app-sanity-ui/src/SanityUI.tsx +23 -0
  129. package/templates/blog/README.md +11 -0
  130. package/templates/blog/schemaTypes/author.js +50 -0
  131. package/templates/blog/schemaTypes/blockContent.js +67 -0
  132. package/templates/blog/schemaTypes/category.js +19 -0
  133. package/templates/blog/schemaTypes/index.js +6 -0
  134. package/templates/blog/schemaTypes/post.js +65 -0
  135. package/templates/blog/static/.gitkeep +1 -0
  136. package/templates/clean/README.md +9 -0
  137. package/templates/clean/schemaTypes/index.js +1 -0
  138. package/templates/clean/static/.gitkeep +1 -0
  139. package/templates/ecommerce/README.md +11 -0
  140. package/templates/ecommerce/plugins/.gitkeep +1 -0
  141. package/templates/ecommerce/plugins/barcode-input/BarcodeInput.js +62 -0
  142. package/templates/ecommerce/plugins/barcode-input/index.js +9 -0
  143. package/templates/ecommerce/plugins/barcode-input/schemaType.js +60 -0
  144. package/templates/ecommerce/schemaTypes/blockContent.js +67 -0
  145. package/templates/ecommerce/schemaTypes/category.js +39 -0
  146. package/templates/ecommerce/schemaTypes/index.js +23 -0
  147. package/templates/ecommerce/schemaTypes/locale/localeBlockContent.js +19 -0
  148. package/templates/ecommerce/schemaTypes/locale/localeString.js +19 -0
  149. package/templates/ecommerce/schemaTypes/locale/localeText.js +19 -0
  150. package/templates/ecommerce/schemaTypes/locale/supportedLanguages.js +5 -0
  151. package/templates/ecommerce/schemaTypes/product.js +83 -0
  152. package/templates/ecommerce/schemaTypes/productVariant.js +52 -0
  153. package/templates/ecommerce/schemaTypes/vendor.js +39 -0
  154. package/templates/ecommerce/static/.gitkeep +1 -0
  155. package/templates/get-started/README.md +9 -0
  156. package/templates/get-started/plugins/.gitkeep +1 -0
  157. package/templates/get-started/plugins/sanity-plugin-tutorial/CustomDefaultLayout.tsx +16 -0
  158. package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +104 -0
  159. package/templates/get-started/plugins/sanity-plugin-tutorial/index.ts +11 -0
  160. package/templates/get-started/schemaTypes/index.ts +1 -0
  161. package/templates/get-started/static/.gitkeep +1 -0
  162. package/templates/moviedb/README.md +10 -0
  163. package/templates/moviedb/schemaTypes/blockContent.js +67 -0
  164. package/templates/moviedb/schemaTypes/castMember.js +37 -0
  165. package/templates/moviedb/schemaTypes/crewMember.js +52 -0
  166. package/templates/moviedb/schemaTypes/index.js +22 -0
  167. package/templates/moviedb/schemaTypes/movie.js +85 -0
  168. package/templates/moviedb/schemaTypes/person.js +37 -0
  169. package/templates/moviedb/schemaTypes/plotSummaries.js +20 -0
  170. package/templates/moviedb/schemaTypes/plotSummary.js +24 -0
  171. package/templates/moviedb/schemaTypes/screening.js +81 -0
  172. package/templates/moviedb/static/.gitkeep +1 -0
  173. package/templates/quickstart/README.md +9 -0
  174. package/templates/quickstart/schemaTypes/index.js +1 -0
  175. package/templates/quickstart/static/.gitkeep +1 -0
  176. package/templates/shared/gitignore.txt +29 -0
  177. package/templates/shared/tsconfig.json +17 -0
  178. package/templates/shopify/README.md +85 -0
  179. package/templates/shopify/components/hotspots/ProductTooltip.tsx +38 -0
  180. package/templates/shopify/components/icons/Shopify.tsx +20 -0
  181. package/templates/shopify/components/inputs/CollectionHidden.tsx +23 -0
  182. package/templates/shopify/components/inputs/PlaceholderString.tsx +20 -0
  183. package/templates/shopify/components/inputs/ProductHidden.tsx +64 -0
  184. package/templates/shopify/components/inputs/ProductVariantHidden.tsx +24 -0
  185. package/templates/shopify/components/inputs/ProxyString.tsx +32 -0
  186. package/templates/shopify/components/media/ColorTheme.tsx +38 -0
  187. package/templates/shopify/components/media/ShopifyDocumentStatus.tsx +82 -0
  188. package/templates/shopify/components/studio/Navbar.tsx +29 -0
  189. package/templates/shopify/constants.ts +61 -0
  190. package/templates/shopify/docs/features.md +158 -0
  191. package/templates/shopify/plugins/customDocumentActions/index.ts +55 -0
  192. package/templates/shopify/plugins/customDocumentActions/shopifyDelete.tsx +144 -0
  193. package/templates/shopify/plugins/customDocumentActions/shopifyLink.ts +39 -0
  194. package/templates/shopify/plugins/customDocumentActions/types.ts +14 -0
  195. package/templates/shopify/schemaTypes/documents/collection.tsx +142 -0
  196. package/templates/shopify/schemaTypes/documents/colorTheme.tsx +44 -0
  197. package/templates/shopify/schemaTypes/documents/page.ts +70 -0
  198. package/templates/shopify/schemaTypes/documents/product.tsx +132 -0
  199. package/templates/shopify/schemaTypes/documents/productVariant.tsx +67 -0
  200. package/templates/shopify/schemaTypes/index.ts +108 -0
  201. package/templates/shopify/schemaTypes/objects/collection/collectionGroupType.ts +27 -0
  202. package/templates/shopify/schemaTypes/objects/collection/collectionLinksType.ts +16 -0
  203. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorObjectType.tsx +48 -0
  204. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorType.tsx +50 -0
  205. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeObjectType.ts +40 -0
  206. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeType.ts +49 -0
  207. package/templates/shopify/schemaTypes/objects/global/footerType.ts +22 -0
  208. package/templates/shopify/schemaTypes/objects/global/menuLinksType.ts +21 -0
  209. package/templates/shopify/schemaTypes/objects/global/menuType.ts +17 -0
  210. package/templates/shopify/schemaTypes/objects/global/notFoundPageType.ts +37 -0
  211. package/templates/shopify/schemaTypes/objects/hotspot/imageWithProductHotspotsType.ts +48 -0
  212. package/templates/shopify/schemaTypes/objects/hotspot/productHotspotsType.tsx +17 -0
  213. package/templates/shopify/schemaTypes/objects/hotspot/spotType.tsx +60 -0
  214. package/templates/shopify/schemaTypes/objects/link/linkEmailType.tsx +34 -0
  215. package/templates/shopify/schemaTypes/objects/link/linkExternalType.tsx +37 -0
  216. package/templates/shopify/schemaTypes/objects/link/linkInternalType.tsx +33 -0
  217. package/templates/shopify/schemaTypes/objects/link/linkProductType.tsx +60 -0
  218. package/templates/shopify/schemaTypes/objects/module/accordionGroupType.ts +33 -0
  219. package/templates/shopify/schemaTypes/objects/module/accordionType.ts +28 -0
  220. package/templates/shopify/schemaTypes/objects/module/callToActionType.tsx +85 -0
  221. package/templates/shopify/schemaTypes/objects/module/calloutType.ts +38 -0
  222. package/templates/shopify/schemaTypes/objects/module/collectionReferenceType.tsx +47 -0
  223. package/templates/shopify/schemaTypes/objects/module/gridItemType.ts +41 -0
  224. package/templates/shopify/schemaTypes/objects/module/gridType.ts +28 -0
  225. package/templates/shopify/schemaTypes/objects/module/heroType.tsx +40 -0
  226. package/templates/shopify/schemaTypes/objects/module/imageCallToActionType.tsx +19 -0
  227. package/templates/shopify/schemaTypes/objects/module/imageFeatureType.ts +80 -0
  228. package/templates/shopify/schemaTypes/objects/module/imageFeaturesType.tsx +51 -0
  229. package/templates/shopify/schemaTypes/objects/module/instagramType.ts +35 -0
  230. package/templates/shopify/schemaTypes/objects/module/productFeaturesType.tsx +50 -0
  231. package/templates/shopify/schemaTypes/objects/module/productReferenceType.tsx +42 -0
  232. package/templates/shopify/schemaTypes/objects/seoType.ts +31 -0
  233. package/templates/shopify/schemaTypes/objects/shopify/collectionRuleType.tsx +37 -0
  234. package/templates/shopify/schemaTypes/objects/shopify/inventoryType.ts +25 -0
  235. package/templates/shopify/schemaTypes/objects/shopify/optionType.tsx +31 -0
  236. package/templates/shopify/schemaTypes/objects/shopify/placeholderStringType.ts +11 -0
  237. package/templates/shopify/schemaTypes/objects/shopify/priceRangeType.ts +20 -0
  238. package/templates/shopify/schemaTypes/objects/shopify/productWithVariantType.tsx +142 -0
  239. package/templates/shopify/schemaTypes/objects/shopify/proxyStringType.ts +12 -0
  240. package/templates/shopify/schemaTypes/objects/shopify/shopType.ts +15 -0
  241. package/templates/shopify/schemaTypes/objects/shopify/shopifyCollectionType.ts +84 -0
  242. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductType.ts +131 -0
  243. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductVariantType.ts +121 -0
  244. package/templates/shopify/schemaTypes/portableText/portableTextSimpleType.tsx +45 -0
  245. package/templates/shopify/schemaTypes/portableText/portableTextType.tsx +52 -0
  246. package/templates/shopify/schemaTypes/singletons/homeType.ts +49 -0
  247. package/templates/shopify/schemaTypes/singletons/settingsType.ts +96 -0
  248. package/templates/shopify/static/.gitkeep +1 -0
  249. package/templates/shopify/structure/collectionStructure.ts +9 -0
  250. package/templates/shopify/structure/colorThemeStructure.ts +9 -0
  251. package/templates/shopify/structure/homeStructure.ts +9 -0
  252. package/templates/shopify/structure/index.ts +57 -0
  253. package/templates/shopify/structure/pageStructure.ts +11 -0
  254. package/templates/shopify/structure/productStructure.ts +51 -0
  255. package/templates/shopify/structure/settingStructure.ts +9 -0
  256. package/templates/shopify/utils/blocksToText.ts +20 -0
  257. package/templates/shopify/utils/defineStructure.ts +11 -0
  258. package/templates/shopify/utils/getPriceRange.ts +24 -0
  259. package/templates/shopify/utils/shopifyUrls.ts +22 -0
  260. package/templates/shopify/utils/validateSlug.ts +18 -0
  261. package/templates/shopify-online-storefront/README.md +54 -0
  262. package/templates/shopify-online-storefront/components/icons/Shopify.tsx +22 -0
  263. package/templates/shopify-online-storefront/components/inputs/CollectionHidden.tsx +23 -0
  264. package/templates/shopify-online-storefront/components/inputs/PlaceholderString.tsx +25 -0
  265. package/templates/shopify-online-storefront/components/inputs/ProductHidden.tsx +66 -0
  266. package/templates/shopify-online-storefront/components/inputs/ProductVariantHidden.tsx +25 -0
  267. package/templates/shopify-online-storefront/components/inputs/ProxyString.tsx +38 -0
  268. package/templates/shopify-online-storefront/components/media/ShopifyDocumentStatus.tsx +83 -0
  269. package/templates/shopify-online-storefront/constants.ts +18 -0
  270. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/index.ts +45 -0
  271. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyDelete.tsx +144 -0
  272. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyLink.ts +39 -0
  273. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/types.ts +14 -0
  274. package/templates/shopify-online-storefront/schemaTypes/blocks/blockContent.ts +32 -0
  275. package/templates/shopify-online-storefront/schemaTypes/documents/collection.tsx +83 -0
  276. package/templates/shopify-online-storefront/schemaTypes/documents/product.tsx +102 -0
  277. package/templates/shopify-online-storefront/schemaTypes/documents/productVariant.tsx +82 -0
  278. package/templates/shopify-online-storefront/schemaTypes/index.ts +43 -0
  279. package/templates/shopify-online-storefront/schemaTypes/objects/accordion.ts +31 -0
  280. package/templates/shopify-online-storefront/schemaTypes/objects/accordionGroup.ts +35 -0
  281. package/templates/shopify-online-storefront/schemaTypes/objects/callout.ts +40 -0
  282. package/templates/shopify-online-storefront/schemaTypes/objects/inventory.ts +30 -0
  283. package/templates/shopify-online-storefront/schemaTypes/objects/option.ts +30 -0
  284. package/templates/shopify-online-storefront/schemaTypes/objects/priceRange.ts +22 -0
  285. package/templates/shopify-online-storefront/schemaTypes/objects/proxyString.ts +11 -0
  286. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollection.ts +109 -0
  287. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollectionRule.tsx +45 -0
  288. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProduct.ts +165 -0
  289. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProductVariant.ts +151 -0
  290. package/templates/shopify-online-storefront/structure/collectionStructure.ts +9 -0
  291. package/templates/shopify-online-storefront/structure/index.ts +37 -0
  292. package/templates/shopify-online-storefront/structure/productStructure.ts +35 -0
  293. package/templates/shopify-online-storefront/utils/defineStructure.ts +11 -0
  294. package/templates/shopify-online-storefront/utils/getPriceRange.ts +24 -0
  295. package/templates/shopify-online-storefront/utils/shopifyUrls.ts +22 -0
  296. package/dist/actions/build/__tests__/buildApp.test.js +0 -367
  297. package/dist/actions/build/__tests__/buildApp.test.js.map +0 -1
  298. package/dist/actions/build/__tests__/buildStudio.test.js +0 -561
  299. package/dist/actions/build/__tests__/buildStudio.test.js.map +0 -1
  300. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js +0 -233
  301. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js.map +0 -1
  302. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js +0 -414
  303. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js.map +0 -1
  304. package/dist/actions/build/__tests__/determineBasePath.test.js +0 -24
  305. package/dist/actions/build/__tests__/determineBasePath.test.js.map +0 -1
  306. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js +0 -109
  307. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js.map +0 -1
  308. package/dist/actions/build/__tests__/getViteConfig.test.js +0 -493
  309. package/dist/actions/build/__tests__/getViteConfig.test.js.map +0 -1
  310. package/dist/actions/build/__tests__/renderDocument.test.js +0 -278
  311. package/dist/actions/build/__tests__/renderDocument.test.js.map +0 -1
  312. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js +0 -153
  313. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js.map +0 -1
  314. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js +0 -657
  315. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js.map +0 -1
  316. package/dist/actions/dataset/__tests__/validateDatasetName.test.js +0 -182
  317. package/dist/actions/dataset/__tests__/validateDatasetName.test.js.map +0 -1
  318. package/dist/actions/deploy/__tests__/checkDir.test.js +0 -120
  319. package/dist/actions/deploy/__tests__/checkDir.test.js.map +0 -1
  320. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js +0 -16
  321. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js.map +0 -1
  322. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js +0 -124
  323. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js.map +0 -1
  324. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +0 -274
  325. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +0 -1
  326. package/dist/actions/media/__tests__/importMedia.test.js +0 -182
  327. package/dist/actions/media/__tests__/importMedia.test.js.map +0 -1
  328. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js +0 -174
  329. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js.map +0 -1
  330. package/dist/actions/schema/__tests__/validateAction.test.js +0 -281
  331. package/dist/actions/schema/__tests__/validateAction.test.js.map +0 -1
  332. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js +0 -27
  333. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js.map +0 -1
  334. package/dist/actions/users/__tests__/validateEmail.test.js +0 -16
  335. package/dist/actions/users/__tests__/validateEmail.test.js.map +0 -1
  336. package/dist/commands/__tests__/blueprints.test.js +0 -54
  337. package/dist/commands/__tests__/blueprints.test.js.map +0 -1
  338. package/dist/commands/__tests__/build.test.js +0 -132
  339. package/dist/commands/__tests__/build.test.js.map +0 -1
  340. package/dist/commands/__tests__/codemod.test.js +0 -271
  341. package/dist/commands/__tests__/codemod.test.js.map +0 -1
  342. package/dist/commands/__tests__/debug.test.js +0 -590
  343. package/dist/commands/__tests__/debug.test.js.map +0 -1
  344. package/dist/commands/__tests__/deploy.test.js +0 -1945
  345. package/dist/commands/__tests__/deploy.test.js.map +0 -1
  346. package/dist/commands/__tests__/dev.test.js +0 -453
  347. package/dist/commands/__tests__/dev.test.js.map +0 -1
  348. package/dist/commands/__tests__/exec.test.js +0 -207
  349. package/dist/commands/__tests__/exec.test.js.map +0 -1
  350. package/dist/commands/__tests__/init/init.authentication.test.js +0 -73
  351. package/dist/commands/__tests__/init/init.authentication.test.js.map +0 -1
  352. package/dist/commands/__tests__/init/init.create-new-project.test.js +0 -195
  353. package/dist/commands/__tests__/init/init.create-new-project.test.js.map +0 -1
  354. package/dist/commands/__tests__/init/init.plan.test.js +0 -279
  355. package/dist/commands/__tests__/init/init.plan.test.js.map +0 -1
  356. package/dist/commands/__tests__/init/init.setup.test.js +0 -335
  357. package/dist/commands/__tests__/init/init.setup.test.js.map +0 -1
  358. package/dist/commands/__tests__/install.test.js +0 -282
  359. package/dist/commands/__tests__/install.test.js.map +0 -1
  360. package/dist/commands/__tests__/learn.test.js +0 -29
  361. package/dist/commands/__tests__/learn.test.js.map +0 -1
  362. package/dist/commands/__tests__/logout.test.js +0 -91
  363. package/dist/commands/__tests__/logout.test.js.map +0 -1
  364. package/dist/commands/__tests__/manage.test.js +0 -110
  365. package/dist/commands/__tests__/manage.test.js.map +0 -1
  366. package/dist/commands/__tests__/migration.test.js +0 -119
  367. package/dist/commands/__tests__/migration.test.js.map +0 -1
  368. package/dist/commands/__tests__/preview.test.js +0 -261
  369. package/dist/commands/__tests__/preview.test.js.map +0 -1
  370. package/dist/commands/__tests__/start.test.js +0 -253
  371. package/dist/commands/__tests__/start.test.js.map +0 -1
  372. package/dist/commands/__tests__/undeploy.test.js +0 -382
  373. package/dist/commands/__tests__/undeploy.test.js.map +0 -1
  374. package/dist/commands/__tests__/versions.test.js +0 -142
  375. package/dist/commands/__tests__/versions.test.js.map +0 -1
  376. package/dist/commands/backup/__tests__/disable.test.js +0 -204
  377. package/dist/commands/backup/__tests__/disable.test.js.map +0 -1
  378. package/dist/commands/backup/__tests__/download.test.js +0 -768
  379. package/dist/commands/backup/__tests__/download.test.js.map +0 -1
  380. package/dist/commands/backup/__tests__/enable.test.js +0 -286
  381. package/dist/commands/backup/__tests__/enable.test.js.map +0 -1
  382. package/dist/commands/backup/__tests__/list.test.js +0 -330
  383. package/dist/commands/backup/__tests__/list.test.js.map +0 -1
  384. package/dist/commands/cors/__tests__/add.test.js +0 -376
  385. package/dist/commands/cors/__tests__/add.test.js.map +0 -1
  386. package/dist/commands/cors/__tests__/delete.test.js +0 -308
  387. package/dist/commands/cors/__tests__/delete.test.js.map +0 -1
  388. package/dist/commands/cors/__tests__/list.test.js +0 -241
  389. package/dist/commands/cors/__tests__/list.test.js.map +0 -1
  390. package/dist/commands/dataset/__tests__/copy.test.js +0 -628
  391. package/dist/commands/dataset/__tests__/copy.test.js.map +0 -1
  392. package/dist/commands/dataset/__tests__/create.test.js +0 -342
  393. package/dist/commands/dataset/__tests__/create.test.js.map +0 -1
  394. package/dist/commands/dataset/__tests__/delete.test.js +0 -231
  395. package/dist/commands/dataset/__tests__/delete.test.js.map +0 -1
  396. package/dist/commands/dataset/__tests__/export.test.js +0 -601
  397. package/dist/commands/dataset/__tests__/export.test.js.map +0 -1
  398. package/dist/commands/dataset/__tests__/import.test.js +0 -53
  399. package/dist/commands/dataset/__tests__/import.test.js.map +0 -1
  400. package/dist/commands/dataset/__tests__/list.test.js +0 -216
  401. package/dist/commands/dataset/__tests__/list.test.js.map +0 -1
  402. package/dist/commands/dataset/alias/__tests__/create.test.js +0 -339
  403. package/dist/commands/dataset/alias/__tests__/create.test.js.map +0 -1
  404. package/dist/commands/dataset/alias/__tests__/delete.test.js +0 -247
  405. package/dist/commands/dataset/alias/__tests__/delete.test.js.map +0 -1
  406. package/dist/commands/dataset/alias/__tests__/link.test.js +0 -376
  407. package/dist/commands/dataset/alias/__tests__/link.test.js.map +0 -1
  408. package/dist/commands/dataset/alias/__tests__/unlink.test.js +0 -313
  409. package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +0 -1
  410. package/dist/commands/dataset/visibility/__tests__/get.test.js +0 -128
  411. package/dist/commands/dataset/visibility/__tests__/get.test.js.map +0 -1
  412. package/dist/commands/dataset/visibility/__tests__/set.test.js +0 -198
  413. package/dist/commands/dataset/visibility/__tests__/set.test.js.map +0 -1
  414. package/dist/commands/docs/__tests__/browse.test.js +0 -29
  415. package/dist/commands/docs/__tests__/browse.test.js.map +0 -1
  416. package/dist/commands/docs/__tests__/read.test.js +0 -78
  417. package/dist/commands/docs/__tests__/read.test.js.map +0 -1
  418. package/dist/commands/docs/__tests__/search.test.js +0 -255
  419. package/dist/commands/docs/__tests__/search.test.js.map +0 -1
  420. package/dist/commands/documents/__tests__/create.test.js +0 -1030
  421. package/dist/commands/documents/__tests__/create.test.js.map +0 -1
  422. package/dist/commands/documents/__tests__/delete.test.js +0 -300
  423. package/dist/commands/documents/__tests__/delete.test.js.map +0 -1
  424. package/dist/commands/documents/__tests__/get.test.js +0 -182
  425. package/dist/commands/documents/__tests__/get.test.js.map +0 -1
  426. package/dist/commands/documents/__tests__/query.test.js +0 -300
  427. package/dist/commands/documents/__tests__/query.test.js.map +0 -1
  428. package/dist/commands/documents/__tests__/validate.test.js +0 -249
  429. package/dist/commands/documents/__tests__/validate.test.js.map +0 -1
  430. package/dist/commands/graphql/__tests__/list.test.js +0 -240
  431. package/dist/commands/graphql/__tests__/list.test.js.map +0 -1
  432. package/dist/commands/graphql/__tests__/undeploy.test.js +0 -410
  433. package/dist/commands/graphql/__tests__/undeploy.test.js.map +0 -1
  434. package/dist/commands/hook/__tests__/attempt.test.js +0 -275
  435. package/dist/commands/hook/__tests__/attempt.test.js.map +0 -1
  436. package/dist/commands/hook/__tests__/create.test.js +0 -119
  437. package/dist/commands/hook/__tests__/create.test.js.map +0 -1
  438. package/dist/commands/hook/__tests__/delete.test.js +0 -233
  439. package/dist/commands/hook/__tests__/delete.test.js.map +0 -1
  440. package/dist/commands/hook/__tests__/list.test.js +0 -145
  441. package/dist/commands/hook/__tests__/list.test.js.map +0 -1
  442. package/dist/commands/hook/__tests__/logs.test.js +0 -798
  443. package/dist/commands/hook/__tests__/logs.test.js.map +0 -1
  444. package/dist/commands/manifest/__tests__/extract.test.js +0 -132
  445. package/dist/commands/manifest/__tests__/extract.test.js.map +0 -1
  446. package/dist/commands/mcp/__tests__/configure.test.js +0 -397
  447. package/dist/commands/mcp/__tests__/configure.test.js.map +0 -1
  448. package/dist/commands/media/__tests__/create-aspect.test.js +0 -173
  449. package/dist/commands/media/__tests__/create-aspect.test.js.map +0 -1
  450. package/dist/commands/media/__tests__/delete-aspect.test.js +0 -342
  451. package/dist/commands/media/__tests__/delete-aspect.test.js.map +0 -1
  452. package/dist/commands/media/__tests__/deploy-aspect.test.js +0 -619
  453. package/dist/commands/media/__tests__/deploy-aspect.test.js.map +0 -1
  454. package/dist/commands/media/__tests__/export.test.js +0 -697
  455. package/dist/commands/media/__tests__/export.test.js.map +0 -1
  456. package/dist/commands/media/__tests__/import.test.js +0 -347
  457. package/dist/commands/media/__tests__/import.test.js.map +0 -1
  458. package/dist/commands/openapi/__tests__/get.test.js +0 -149
  459. package/dist/commands/openapi/__tests__/get.test.js.map +0 -1
  460. package/dist/commands/openapi/__tests__/list.test.js +0 -113
  461. package/dist/commands/openapi/__tests__/list.test.js.map +0 -1
  462. package/dist/commands/projects/__tests__/list.test.js +0 -154
  463. package/dist/commands/projects/__tests__/list.test.js.map +0 -1
  464. package/dist/commands/schema/__tests__/delete.test.js +0 -454
  465. package/dist/commands/schema/__tests__/delete.test.js.map +0 -1
  466. package/dist/commands/schema/__tests__/deploy.test.js +0 -348
  467. package/dist/commands/schema/__tests__/deploy.test.js.map +0 -1
  468. package/dist/commands/schema/__tests__/extract.test.js +0 -121
  469. package/dist/commands/schema/__tests__/extract.test.js.map +0 -1
  470. package/dist/commands/schema/__tests__/list.test.js +0 -399
  471. package/dist/commands/schema/__tests__/list.test.js.map +0 -1
  472. package/dist/commands/schema/__tests__/validate.test.js +0 -121
  473. package/dist/commands/schema/__tests__/validate.test.js.map +0 -1
  474. package/dist/commands/telemetry/__tests__/disable.test.js +0 -147
  475. package/dist/commands/telemetry/__tests__/disable.test.js.map +0 -1
  476. package/dist/commands/telemetry/__tests__/enable.test.js +0 -133
  477. package/dist/commands/telemetry/__tests__/enable.test.js.map +0 -1
  478. package/dist/commands/telemetry/__tests__/status.test.js +0 -155
  479. package/dist/commands/telemetry/__tests__/status.test.js.map +0 -1
  480. package/dist/commands/tokens/__tests__/add.test.js +0 -435
  481. package/dist/commands/tokens/__tests__/add.test.js.map +0 -1
  482. package/dist/commands/tokens/__tests__/delete.test.js +0 -405
  483. package/dist/commands/tokens/__tests__/delete.test.js.map +0 -1
  484. package/dist/commands/tokens/__tests__/list.test.js +0 -395
  485. package/dist/commands/tokens/__tests__/list.test.js.map +0 -1
  486. package/dist/commands/users/__tests__/invite.test.js +0 -362
  487. package/dist/commands/users/__tests__/invite.test.js.map +0 -1
  488. package/dist/commands/users/__tests__/list.test.js +0 -407
  489. package/dist/commands/users/__tests__/list.test.js.map +0 -1
  490. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js +0 -77
  491. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js.map +0 -1
  492. package/dist/services/__tests__/datasetAliases.test.js +0 -131
  493. package/dist/services/__tests__/datasetAliases.test.js.map +0 -1
  494. package/dist/services/__tests__/datasets.test.js +0 -436
  495. package/dist/services/__tests__/datasets.test.js.map +0 -1
  496. package/dist/services/__tests__/graphql.test.js +0 -43
  497. package/dist/services/__tests__/graphql.test.js.map +0 -1
  498. package/dist/services/__tests__/mediaLibraries.test.js +0 -88
  499. package/dist/services/__tests__/mediaLibraries.test.js.map +0 -1
  500. package/dist/services/__tests__/projects.test.js +0 -41
  501. package/dist/services/__tests__/projects.test.js.map +0 -1
  502. package/dist/services/__tests__/userApplications.test.js +0 -113
  503. package/dist/services/__tests__/userApplications.test.js.map +0 -1
  504. package/dist/util/__tests__/appId.test.js +0 -31
  505. package/dist/util/__tests__/appId.test.js.map +0 -1
  506. package/dist/util/__tests__/cliClient.test.js +0 -184
  507. package/dist/util/__tests__/cliClient.test.js.map +0 -1
  508. package/dist/util/__tests__/compareDependencyVersions.test.js +0 -426
  509. package/dist/util/__tests__/compareDependencyVersions.test.js.map +0 -1
  510. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js +0 -74
  511. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js.map +0 -1
  512. package/dist/util/__tests__/findNdjsonEntry.test.js +0 -54
  513. package/dist/util/__tests__/findNdjsonEntry.test.js.map +0 -1
  514. package/dist/util/__tests__/getCliVersion.test.js +0 -28
  515. package/dist/util/__tests__/getCliVersion.test.js.map +0 -1
  516. package/dist/util/__tests__/getLocalPackageVersion.test.js +0 -84
  517. package/dist/util/__tests__/getLocalPackageVersion.test.js.map +0 -1
  518. package/dist/util/__tests__/getWorkspace.test.js +0 -37
  519. package/dist/util/__tests__/getWorkspace.test.js.map +0 -1
  520. package/dist/util/__tests__/readPackageJson.test.js +0 -69
  521. package/dist/util/__tests__/readPackageJson.test.js.map +0 -1
  522. package/dist/util/__tests__/warnAboutMissingAppId.test.js +0 -28
  523. package/dist/util/__tests__/warnAboutMissingAppId.test.js.map +0 -1
  524. package/dist/util/packageManager/__tests__/installPackages.test.js +0 -388
  525. package/dist/util/packageManager/__tests__/installPackages.test.js.map +0 -1
  526. package/dist/util/validation/ __tests__/validateDocuments.test.js +0 -274
  527. package/dist/util/validation/ __tests__/validateDocuments.test.js.map +0 -1
@@ -1,1030 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import fs from 'node:fs/promises';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { runCommand } from '@oclif/test';
6
- import { getProjectCliClient } from '@sanity/cli-core';
7
- import { testCommand } from '@sanity/cli-test';
8
- import { watch as chokidarWatch } from 'chokidar';
9
- import { execa, execaSync } from 'execa';
10
- import json5 from 'json5';
11
- import { afterEach, describe, expect, test, vi } from 'vitest';
12
- import { NO_PROJECT_ID } from '../../../util/errorMessages.js';
13
- import { CreateDocumentCommand } from '../create.js';
14
- vi.mock('node:fs/promises');
15
- vi.mock('node:os');
16
- vi.mock('chokidar', ()=>({
17
- watch: vi.fn()
18
- }));
19
- vi.mock('execa');
20
- vi.mock('json5');
21
- vi.mock('node:crypto', async ()=>{
22
- return {
23
- randomUUID: vi.fn()
24
- };
25
- });
26
- vi.mock('@sanity/cli-core', async ()=>{
27
- const actual = await vi.importActual('@sanity/cli-core');
28
- return {
29
- ...actual,
30
- getProjectCliClient: vi.fn()
31
- };
32
- });
33
- const mockFs = vi.mocked(fs);
34
- const mockOs = vi.mocked(os);
35
- const mockChokidarWatch = vi.mocked(chokidarWatch);
36
- const mockExeca = vi.mocked(execa);
37
- const mockExecaSync = vi.mocked(execaSync);
38
- const mockJson5 = vi.mocked(json5);
39
- const mockRandomUUID = vi.mocked(randomUUID);
40
- const mockGetProjectCliClient = vi.mocked(getProjectCliClient);
41
- const testProjectId = 'test-project';
42
- const testDataset = 'production';
43
- // Helper to set environment variable for tests
44
- function withEditorEnv(testFn) {
45
- return async ()=>{
46
- vi.stubEnv('EDITOR', 'vim');
47
- try {
48
- await testFn();
49
- } finally{
50
- vi.unstubAllEnvs();
51
- }
52
- };
53
- }
54
- // Base configuration used across tests
55
- const baseConfig = {
56
- api: {
57
- dataset: testDataset,
58
- projectId: testProjectId
59
- }
60
- };
61
- const defaultMocks = {
62
- cliConfig: baseConfig,
63
- projectRoot: {
64
- directory: '/test/path',
65
- path: '/test/path/sanity.config.ts',
66
- type: 'studio'
67
- },
68
- token: 'test-token'
69
- };
70
- // Helper functions
71
- const setupEditorMocks = ()=>{
72
- mockOs.tmpdir.mockReturnValue('/tmp');
73
- mockFs.mkdir.mockResolvedValue(undefined);
74
- mockFs.writeFile.mockResolvedValue(undefined);
75
- mockFs.unlink.mockResolvedValue(undefined);
76
- mockExecaSync.mockReturnValue(undefined);
77
- };
78
- const setupWatchMocks = ()=>{
79
- mockOs.tmpdir.mockReturnValue('/tmp');
80
- mockFs.mkdir.mockResolvedValue(undefined);
81
- mockFs.writeFile.mockResolvedValue(undefined);
82
- mockFs.unlink.mockResolvedValue(undefined);
83
- };
84
- describe('#documents:create', ()=>{
85
- afterEach(()=>{
86
- vi.clearAllMocks();
87
- });
88
- test('--help works', async ()=>{
89
- const { stdout } = await runCommand([
90
- 'documents create',
91
- '--help'
92
- ]);
93
- expect(stdout).toMatchInlineSnapshot(`
94
- "Create one or more documents
95
-
96
- USAGE
97
- $ sanity documents create [FILE] [-d <value>] [--id <value>] [--json5]
98
- [--missing] [--replace] [--watch]
99
-
100
- ARGUMENTS
101
- [FILE] JSON file to create document(s) from
102
-
103
- FLAGS
104
- -d, --dataset=<value> Dataset to create document(s) in (overrides config)
105
- --id=<value> Specify a document ID to use. Will fetch remote
106
- document ID and populate editor.
107
- --json5 Use JSON5 file type to allow a "simplified" version of
108
- JSON
109
- --missing On duplicate document IDs, don't modify the target
110
- document(s)
111
- --replace On duplicate document IDs, replace existing document
112
- with specified document(s)
113
- --watch Write the documents whenever the target file or buffer
114
- changes
115
-
116
- DESCRIPTION
117
- Create one or more documents
118
-
119
- EXAMPLES
120
- Create the document specified in "myDocument.json"
121
-
122
- $ sanity documents create myDocument.json
123
-
124
- Open configured $EDITOR and create the specified document(s)
125
-
126
- $ sanity documents create
127
-
128
- Fetch document with the ID "myDocId" and open configured $EDITOR with the
129
- current document content (if any). Replace document with the edited version
130
- when the editor closes
131
-
132
- $ sanity documents create --id myDocId --replace
133
-
134
- Open configured $EDITOR and replace the document with the given content on
135
- each save. Use JSON5 file extension and parser for simplified syntax.
136
-
137
- $ sanity documents create --id myDocId --watch --replace --json5
138
-
139
- "
140
- `);
141
- });
142
- test('creates document from JSON file and displays success message', async ()=>{
143
- const mockDoc = {
144
- _id: 'test-doc',
145
- _type: 'post',
146
- title: 'Test Post'
147
- };
148
- const mockTransaction = vi.fn().mockReturnValue({
149
- commit: vi.fn().mockResolvedValue({
150
- results: [
151
- {
152
- id: 'test-doc',
153
- operation: 'create'
154
- }
155
- ]
156
- })
157
- });
158
- mockGetProjectCliClient.mockResolvedValue({
159
- transaction: mockTransaction
160
- });
161
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
162
- mockJson5.parse.mockReturnValue(mockDoc);
163
- const { stdout } = await testCommand(CreateDocumentCommand, [
164
- 'test-doc.json'
165
- ], {
166
- mocks: {
167
- ...defaultMocks
168
- }
169
- });
170
- expect(stdout).toContain('Created:');
171
- expect(stdout).toContain('test-doc');
172
- expect(mockFs.readFile).toHaveBeenCalledWith(path.resolve(process.cwd(), 'test-doc.json'), 'utf8');
173
- expect(mockTransaction).toHaveBeenCalledWith([
174
- {
175
- create: mockDoc
176
- }
177
- ]);
178
- });
179
- test('creates document with replace flag', async ()=>{
180
- const mockDoc = {
181
- _id: 'test-doc',
182
- _type: 'post',
183
- title: 'Test Post'
184
- };
185
- const mockTransaction = vi.fn().mockReturnValue({
186
- commit: vi.fn().mockResolvedValue({
187
- results: [
188
- {
189
- id: 'test-doc',
190
- operation: 'update'
191
- }
192
- ]
193
- })
194
- });
195
- mockGetProjectCliClient.mockResolvedValue({
196
- transaction: mockTransaction
197
- });
198
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
199
- mockJson5.parse.mockReturnValue(mockDoc);
200
- const { stdout } = await testCommand(CreateDocumentCommand, [
201
- 'test-doc.json',
202
- '--replace'
203
- ], {
204
- mocks: {
205
- ...defaultMocks
206
- }
207
- });
208
- expect(stdout).toContain('Upserted:');
209
- expect(stdout).toContain('test-doc');
210
- expect(mockTransaction).toHaveBeenCalledWith([
211
- {
212
- createOrReplace: mockDoc
213
- }
214
- ]);
215
- });
216
- test('creates document with missing flag', async ()=>{
217
- const mockDoc = {
218
- _id: 'test-doc',
219
- _type: 'post',
220
- title: 'Test Post'
221
- };
222
- const mockTransaction = vi.fn().mockReturnValue({
223
- commit: vi.fn().mockResolvedValue({
224
- results: [
225
- {
226
- id: 'test-doc',
227
- operation: 'update'
228
- }
229
- ]
230
- })
231
- });
232
- mockGetProjectCliClient.mockResolvedValue({
233
- transaction: mockTransaction
234
- });
235
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
236
- mockJson5.parse.mockReturnValue(mockDoc);
237
- const { stdout } = await testCommand(CreateDocumentCommand, [
238
- 'test-doc.json',
239
- '--missing'
240
- ], {
241
- mocks: {
242
- ...defaultMocks
243
- }
244
- });
245
- expect(stdout).toContain('Skipped (already exists):');
246
- expect(stdout).toContain('test-doc');
247
- expect(mockTransaction).toHaveBeenCalledWith([
248
- {
249
- createIfNotExists: mockDoc
250
- }
251
- ]);
252
- });
253
- test('opens editor when no file specified and creates document from editor content', withEditorEnv(async ()=>{
254
- const mockTransaction = vi.fn().mockReturnValue({
255
- commit: vi.fn().mockResolvedValue({
256
- results: [
257
- {
258
- id: 'generated-id',
259
- operation: 'create'
260
- }
261
- ]
262
- })
263
- });
264
- mockGetProjectCliClient.mockResolvedValue({
265
- getDocument: vi.fn().mockResolvedValue(null),
266
- transaction: mockTransaction
267
- });
268
- setupEditorMocks();
269
- mockFs.readFile.mockResolvedValue('{"_id": "generated-id", "_type": "updated-type"}');
270
- mockJson5.stringify.mockReturnValue('{"_id": "generated-id", "_type": "specify-me"}');
271
- mockJson5.parse.mockReturnValue({
272
- _id: 'generated-id',
273
- _type: 'updated-type'
274
- });
275
- const { stdout } = await testCommand(CreateDocumentCommand, [], {
276
- mocks: {
277
- ...defaultMocks
278
- }
279
- });
280
- expect(stdout).toContain('Created:');
281
- expect(mockFs.mkdir).toHaveBeenCalledWith('/tmp/sanity-cli', {
282
- mode: 0o700,
283
- recursive: true
284
- });
285
- expect(mockExecaSync).toHaveBeenCalled();
286
- }));
287
- test('uses custom dataset from --dataset flag instead of config', async ()=>{
288
- const mockDoc = {
289
- _id: 'test-doc',
290
- _type: 'post',
291
- title: 'Test Post'
292
- };
293
- const mockTransaction = vi.fn().mockReturnValue({
294
- commit: vi.fn().mockResolvedValue({
295
- results: [
296
- {
297
- id: 'test-doc',
298
- operation: 'create'
299
- }
300
- ]
301
- })
302
- });
303
- mockGetProjectCliClient.mockResolvedValue({
304
- transaction: mockTransaction
305
- });
306
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
307
- mockJson5.parse.mockReturnValue(mockDoc);
308
- const { stdout } = await testCommand(CreateDocumentCommand, [
309
- 'test-doc.json',
310
- '--dataset',
311
- 'staging'
312
- ], {
313
- mocks: {
314
- ...defaultMocks
315
- }
316
- });
317
- expect(stdout).toContain('Created:');
318
- expect(mockGetProjectCliClient).toHaveBeenCalledWith(expect.objectContaining({
319
- dataset: 'staging'
320
- }));
321
- });
322
- test('throws error when both --replace and --missing flags are used', async ()=>{
323
- const { error } = await testCommand(CreateDocumentCommand, [
324
- 'test-doc.json',
325
- '--replace',
326
- '--missing'
327
- ], {
328
- mocks: defaultMocks
329
- });
330
- expect(error).toBeInstanceOf(Error);
331
- expect(error?.message).toContain('Cannot use both --replace and --missing');
332
- expect(error?.oclif?.exit).toBe(1);
333
- });
334
- test('throws error when --id and file path are both provided', async ()=>{
335
- const { error } = await testCommand(CreateDocumentCommand, [
336
- 'test-doc.json',
337
- '--id',
338
- 'myDocId'
339
- ], {
340
- mocks: defaultMocks
341
- });
342
- expect(error).toBeInstanceOf(Error);
343
- expect(error?.message).toContain('Cannot use --id when specifying a file path');
344
- expect(error?.oclif?.exit).toBe(1);
345
- });
346
- test('throws error when no project ID is configured', async ()=>{
347
- const { error } = await testCommand(CreateDocumentCommand, [
348
- 'test-doc.json'
349
- ], {
350
- mocks: {
351
- ...defaultMocks,
352
- cliConfig: {
353
- api: {
354
- dataset: 'production',
355
- projectId: undefined
356
- }
357
- }
358
- }
359
- });
360
- expect(error).toBeInstanceOf(Error);
361
- expect(error?.message).toEqual(NO_PROJECT_ID);
362
- expect(error?.oclif?.exit).toBe(1);
363
- });
364
- test('throws error when no dataset is configured and none provided', async ()=>{
365
- const { error } = await testCommand(CreateDocumentCommand, [
366
- 'test-doc.json'
367
- ], {
368
- mocks: {
369
- ...defaultMocks,
370
- cliConfig: {
371
- api: {
372
- dataset: undefined,
373
- projectId: testProjectId
374
- }
375
- }
376
- }
377
- });
378
- expect(error).toBeInstanceOf(Error);
379
- expect(error?.message).toContain('No dataset specified');
380
- expect(error?.oclif?.exit).toBe(1);
381
- });
382
- test('displays error message when file cannot be read', async ()=>{
383
- mockFs.readFile.mockRejectedValue(new Error('File not found'));
384
- const { error } = await testCommand(CreateDocumentCommand, [
385
- 'nonexistent.json'
386
- ], {
387
- mocks: {
388
- ...defaultMocks
389
- }
390
- });
391
- expect(error).toBeInstanceOf(Error);
392
- expect(error?.message).toContain('Failed to create documents');
393
- expect(error?.oclif?.exit).toBe(1);
394
- });
395
- test('validates document has required _type property', async ()=>{
396
- const invalidDoc = {
397
- title: 'Test Post'
398
- } // Missing _type
399
- ;
400
- mockFs.readFile.mockResolvedValue(JSON.stringify(invalidDoc));
401
- mockJson5.parse.mockReturnValue(invalidDoc);
402
- const { error } = await testCommand(CreateDocumentCommand, [
403
- 'invalid-doc.json'
404
- ], {
405
- mocks: {
406
- ...defaultMocks
407
- }
408
- });
409
- expect(error).toBeInstanceOf(Error);
410
- expect(error?.message).toContain('Failed to create documents');
411
- expect(error?.oclif?.exit).toBe(1);
412
- });
413
- test('uses JSON5 when --json5 flag is provided', withEditorEnv(async ()=>{
414
- const mockTransaction = vi.fn().mockReturnValue({
415
- commit: vi.fn().mockResolvedValue({
416
- results: [
417
- {
418
- id: 'generated-id',
419
- operation: 'create'
420
- }
421
- ]
422
- })
423
- });
424
- mockGetProjectCliClient.mockResolvedValue({
425
- getDocument: vi.fn().mockResolvedValue(null),
426
- transaction: mockTransaction
427
- });
428
- setupEditorMocks();
429
- mockFs.readFile.mockResolvedValue('{"_id": "generated-id", "_type": "updated-type"}');
430
- mockJson5.stringify.mockReturnValue('{"_id": "generated-id", "_type": "specify-me"}');
431
- mockJson5.parse.mockReturnValue({
432
- _id: 'generated-id',
433
- _type: 'updated-type'
434
- });
435
- await testCommand(CreateDocumentCommand, [
436
- '--json5'
437
- ], {
438
- mocks: {
439
- ...defaultMocks
440
- }
441
- });
442
- expect(mockJson5.stringify).toHaveBeenCalled();
443
- expect(mockFs.writeFile).toHaveBeenCalledWith(expect.stringContaining('.json5'), expect.any(String), {
444
- encoding: 'utf8',
445
- mode: 0o600
446
- });
447
- }));
448
- describe('validation', ()=>{
449
- test.each([
450
- [
451
- 'non-object document',
452
- 'not an object',
453
- 'Document must be an object'
454
- ],
455
- [
456
- 'document without _type',
457
- {
458
- title: 'Test'
459
- },
460
- 'Document must have a `_type` property of type string'
461
- ],
462
- [
463
- 'document with empty _type',
464
- {
465
- _type: '',
466
- title: 'Test'
467
- },
468
- 'Document _type cannot be empty'
469
- ],
470
- [
471
- 'document with invalid _type format (starts with number)',
472
- {
473
- _type: '1invalid',
474
- title: 'Test'
475
- },
476
- 'Document _type must start with a letter'
477
- ],
478
- [
479
- 'document with invalid _type format (special chars)',
480
- {
481
- _type: 'invalid@type',
482
- title: 'Test'
483
- },
484
- 'Document _type must start with a letter and contain only alphanumeric characters'
485
- ],
486
- [
487
- 'document with empty _id',
488
- {
489
- _id: ' ',
490
- _type: 'test',
491
- title: 'Test'
492
- },
493
- 'Document _id cannot be empty'
494
- ],
495
- [
496
- 'document with invalid _id format',
497
- {
498
- _id: 'invalid@id',
499
- _type: 'test',
500
- title: 'Test'
501
- },
502
- 'Document _id can only contain alphanumeric characters'
503
- ],
504
- [
505
- 'document with _id too long',
506
- {
507
- _id: 'a'.repeat(201),
508
- _type: 'test',
509
- title: 'Test'
510
- },
511
- 'Document _id cannot be longer than 200 characters'
512
- ]
513
- ])('validates %s', async (description, doc, expectedErrorSubstring)=>{
514
- const mockTransaction = vi.fn().mockReturnValue({
515
- commit: vi.fn().mockResolvedValue({
516
- results: [
517
- {
518
- id: 'test-doc',
519
- operation: 'create'
520
- }
521
- ]
522
- })
523
- });
524
- mockGetProjectCliClient.mockResolvedValue({
525
- transaction: mockTransaction
526
- });
527
- mockFs.readFile.mockResolvedValue(JSON.stringify(doc));
528
- mockJson5.parse.mockReturnValue(doc);
529
- const { error } = await testCommand(CreateDocumentCommand, [
530
- 'invalid-doc.json'
531
- ], {
532
- mocks: {
533
- ...defaultMocks
534
- }
535
- });
536
- expect(error).toBeInstanceOf(Error);
537
- expect(error?.message).toContain(expectedErrorSubstring);
538
- expect(error?.oclif?.exit).toBe(1);
539
- });
540
- test.each([
541
- [
542
- 'multiple documents with invalid first document',
543
- [
544
- {
545
- title: 'Invalid'
546
- },
547
- {
548
- _type: 'valid',
549
- title: 'Valid'
550
- }
551
- ],
552
- 'Document at index 0 must have a `_type` property of type string'
553
- ],
554
- [
555
- 'multiple documents with invalid second document',
556
- [
557
- {
558
- _type: 'valid',
559
- title: 'Valid'
560
- },
561
- {
562
- title: 'Invalid'
563
- }
564
- ],
565
- 'Document at index 1 must have a `_type` property of type string'
566
- ]
567
- ])('validates %s', async (description, docs, expectedErrorSubstring)=>{
568
- const mockTransaction = vi.fn().mockReturnValue({
569
- commit: vi.fn().mockResolvedValue({
570
- results: [
571
- {
572
- id: 'test-doc',
573
- operation: 'create'
574
- }
575
- ]
576
- })
577
- });
578
- mockGetProjectCliClient.mockResolvedValue({
579
- transaction: mockTransaction
580
- });
581
- mockFs.readFile.mockResolvedValue(JSON.stringify(docs));
582
- mockJson5.parse.mockReturnValue(docs);
583
- const { error } = await testCommand(CreateDocumentCommand, [
584
- 'invalid-docs.json'
585
- ], {
586
- mocks: {
587
- ...defaultMocks
588
- }
589
- });
590
- expect(error).toBeInstanceOf(Error);
591
- expect(error?.message).toContain(expectedErrorSubstring);
592
- expect(error?.oclif?.exit).toBe(1);
593
- });
594
- test('allows documents with reserved fields but logs debug warning', async ()=>{
595
- const docWithReservedFields = {
596
- _createdAt: '2024-01-01T00:00:00Z',
597
- _id: 'test-doc',
598
- _rev: 'some-revision',
599
- _type: 'post',
600
- _updatedAt: '2024-01-02T00:00:00Z',
601
- title: 'Test Post'
602
- };
603
- const mockTransaction = vi.fn().mockReturnValue({
604
- commit: vi.fn().mockResolvedValue({
605
- results: [
606
- {
607
- id: 'test-doc',
608
- operation: 'create'
609
- }
610
- ]
611
- })
612
- });
613
- mockGetProjectCliClient.mockResolvedValue({
614
- transaction: mockTransaction
615
- });
616
- mockFs.readFile.mockResolvedValue(JSON.stringify(docWithReservedFields));
617
- mockJson5.parse.mockReturnValue(docWithReservedFields);
618
- // Should not throw error, but should proceed with document creation
619
- const { stdout } = await testCommand(CreateDocumentCommand, [
620
- 'doc.json'
621
- ], {
622
- mocks: {
623
- ...defaultMocks
624
- }
625
- });
626
- expect(stdout).toContain('Created:');
627
- expect(stdout).toContain('test-doc');
628
- expect(mockTransaction).toHaveBeenCalledWith([
629
- {
630
- create: docWithReservedFields
631
- }
632
- ]);
633
- });
634
- test('validates empty document array throws error', async ()=>{
635
- const emptyArray = [];
636
- const mockTransaction = vi.fn().mockReturnValue({
637
- commit: vi.fn().mockResolvedValue({
638
- results: [
639
- {
640
- id: 'test-doc',
641
- operation: 'create'
642
- }
643
- ]
644
- })
645
- });
646
- mockGetProjectCliClient.mockResolvedValue({
647
- transaction: mockTransaction
648
- });
649
- mockFs.readFile.mockResolvedValue(JSON.stringify(emptyArray));
650
- mockJson5.parse.mockReturnValue(emptyArray);
651
- const { error } = await testCommand(CreateDocumentCommand, [
652
- 'empty-docs.json'
653
- ], {
654
- mocks: {
655
- ...defaultMocks
656
- }
657
- });
658
- expect(error).toBeInstanceOf(Error);
659
- expect(error?.message).toContain('No documents provided');
660
- expect(error?.oclif?.exit).toBe(1);
661
- });
662
- });
663
- describe('batch operations', ()=>{
664
- test.each([
665
- [
666
- 'create',
667
- 'create',
668
- 'Created:'
669
- ],
670
- [
671
- 'createOrReplace',
672
- 'replace',
673
- 'Upserted:'
674
- ],
675
- [
676
- 'createIfNotExists',
677
- 'missing',
678
- 'Skipped (already exists):'
679
- ]
680
- ])('handles multiple documents with %s operation', async (operation, flag, expectedMessage)=>{
681
- const mockDocs = [
682
- {
683
- _id: 'doc1',
684
- _type: 'post',
685
- title: 'Post 1'
686
- },
687
- {
688
- _id: 'doc2',
689
- _type: 'post',
690
- title: 'Post 2'
691
- }
692
- ];
693
- const mockTransaction = vi.fn().mockReturnValue({
694
- commit: vi.fn().mockResolvedValue({
695
- results: [
696
- {
697
- id: 'doc1',
698
- operation: operation === 'createIfNotExists' ? 'update' : 'create'
699
- },
700
- {
701
- id: 'doc2',
702
- operation: operation === 'createIfNotExists' ? 'update' : 'create'
703
- }
704
- ]
705
- })
706
- });
707
- mockGetProjectCliClient.mockResolvedValue({
708
- transaction: mockTransaction
709
- });
710
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDocs));
711
- mockJson5.parse.mockReturnValue(mockDocs);
712
- const args = [
713
- 'docs.json'
714
- ];
715
- if (flag !== 'create') args.push(`--${flag}`);
716
- const { stdout } = await testCommand(CreateDocumentCommand, args, {
717
- mocks: {
718
- ...defaultMocks
719
- }
720
- });
721
- expect(stdout).toContain(expectedMessage);
722
- expect(stdout).toContain('doc1');
723
- expect(stdout).toContain('doc2');
724
- const expectedMutations = mockDocs.map((doc)=>({
725
- [operation]: doc
726
- }));
727
- expect(mockTransaction).toHaveBeenCalledWith(expectedMutations);
728
- });
729
- test('handles mixed results for createIfNotExists', async ()=>{
730
- const mockDocs = [
731
- {
732
- _id: 'doc1',
733
- _type: 'post',
734
- title: 'Post 1'
735
- },
736
- {
737
- _id: 'doc2',
738
- _type: 'post',
739
- title: 'Post 2'
740
- },
741
- {
742
- _id: 'doc3',
743
- _type: 'post',
744
- title: 'Post 3'
745
- }
746
- ];
747
- const mockTransaction = vi.fn().mockReturnValue({
748
- commit: vi.fn().mockResolvedValue({
749
- results: [
750
- {
751
- id: 'doc1',
752
- operation: 'create'
753
- },
754
- {
755
- id: 'doc2',
756
- operation: 'update'
757
- },
758
- {
759
- id: 'doc3',
760
- operation: 'create'
761
- }
762
- ]
763
- })
764
- });
765
- mockGetProjectCliClient.mockResolvedValue({
766
- transaction: mockTransaction
767
- });
768
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDocs));
769
- mockJson5.parse.mockReturnValue(mockDocs);
770
- const { stdout } = await testCommand(CreateDocumentCommand, [
771
- 'docs.json',
772
- '--missing'
773
- ], {
774
- mocks: {
775
- ...defaultMocks
776
- }
777
- });
778
- expect(stdout).toContain('Created:');
779
- expect(stdout).toContain('doc1');
780
- expect(stdout).toContain('doc3');
781
- expect(stdout).toContain('Skipped (already exists):');
782
- expect(stdout).toContain('doc2');
783
- });
784
- });
785
- describe('editor workflow', ()=>{
786
- test('fetches existing document with --id flag', withEditorEnv(async ()=>{
787
- const existingDoc = {
788
- _id: 'existing-doc',
789
- _type: 'post',
790
- title: 'Existing Post'
791
- };
792
- const mockTransaction = vi.fn().mockReturnValue({
793
- commit: vi.fn().mockResolvedValue({
794
- results: [
795
- {
796
- id: 'existing-doc',
797
- operation: 'update'
798
- }
799
- ]
800
- })
801
- });
802
- const mockGetDocument = vi.fn().mockResolvedValue(existingDoc);
803
- mockGetProjectCliClient.mockResolvedValue({
804
- getDocument: mockGetDocument,
805
- transaction: mockTransaction
806
- });
807
- setupEditorMocks();
808
- mockFs.readFile.mockResolvedValue(JSON.stringify({
809
- ...existingDoc,
810
- title: 'Updated Post'
811
- }));
812
- mockJson5.parse.mockReturnValue({
813
- ...existingDoc,
814
- title: 'Updated Post'
815
- });
816
- mockJson5.stringify.mockReturnValue(JSON.stringify(existingDoc, null, 2));
817
- const { stdout } = await testCommand(CreateDocumentCommand, [
818
- '--id',
819
- 'existing-doc'
820
- ], {
821
- mocks: {
822
- ...defaultMocks
823
- }
824
- });
825
- expect(mockGetDocument).toHaveBeenCalledWith('existing-doc');
826
- expect(mockFs.writeFile).toHaveBeenCalledWith(expect.stringContaining('existing-doc.json'), JSON.stringify(existingDoc, null, 2), expect.objectContaining({
827
- mode: 0o600
828
- }));
829
- expect(stdout).toContain('Created:');
830
- }));
831
- test('handles no changes made in editor', withEditorEnv(async ()=>{
832
- const mockTransaction = vi.fn();
833
- mockGetProjectCliClient.mockResolvedValue({
834
- getDocument: vi.fn().mockResolvedValue(null),
835
- transaction: mockTransaction
836
- });
837
- setupEditorMocks();
838
- // Set up a predictable UUID so the test can verify no changes were made
839
- const testUuid = '123e4567-e89b-12d3-a456-426614174000';
840
- mockRandomUUID.mockReturnValue(testUuid);
841
- const defaultDoc = {
842
- _id: testUuid,
843
- _type: 'specify-me'
844
- };
845
- // First mock the writeFile call for initial template
846
- const writeFileContent = JSON.stringify(defaultDoc, null, 2);
847
- mockJson5.stringify.mockReturnValue(writeFileContent);
848
- // Set up the file read to return the exact same content structure
849
- mockFs.readFile.mockResolvedValue(writeFileContent);
850
- // Return the exact same object structure that was written
851
- mockJson5.parse.mockReturnValue(defaultDoc);
852
- await testCommand(CreateDocumentCommand, [], {
853
- mocks: {
854
- ...defaultMocks
855
- }
856
- });
857
- // The key test - transaction should not have been called since no changes were made
858
- expect(mockTransaction).not.toHaveBeenCalled();
859
- }));
860
- test('handles write error with already exists hint', withEditorEnv(async ()=>{
861
- const mockDoc = {
862
- _id: 'test-doc',
863
- _type: 'post',
864
- title: 'Test Post'
865
- };
866
- const mockTransaction = vi.fn().mockReturnValue({
867
- commit: vi.fn().mockRejectedValue(new Error('Document already exists'))
868
- });
869
- mockGetProjectCliClient.mockResolvedValue({
870
- getDocument: vi.fn().mockResolvedValue(null),
871
- transaction: mockTransaction
872
- });
873
- setupEditorMocks();
874
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
875
- mockJson5.parse.mockReturnValue(mockDoc);
876
- mockJson5.stringify.mockReturnValue(JSON.stringify({
877
- _id: 'test-doc',
878
- _type: 'specify-me'
879
- }, null, 2));
880
- const { error } = await testCommand(CreateDocumentCommand, [], {
881
- mocks: {
882
- ...defaultMocks
883
- }
884
- });
885
- expect(error).toBeInstanceOf(Error);
886
- expect(error?.message).toContain('Failed to write documents: Document already exists');
887
- expect(error?.message).toContain('Perhaps you want to use `--replace` or `--missing`?');
888
- expect(error?.oclif?.exit).toBe(1);
889
- }));
890
- test('handles file cleanup errors silently', withEditorEnv(async ()=>{
891
- const mockDoc = {
892
- _id: 'test-doc',
893
- _type: 'post',
894
- title: 'Test Post'
895
- };
896
- const mockTransaction = vi.fn().mockReturnValue({
897
- commit: vi.fn().mockResolvedValue({
898
- results: [
899
- {
900
- id: 'test-doc',
901
- operation: 'create'
902
- }
903
- ]
904
- })
905
- });
906
- mockGetProjectCliClient.mockResolvedValue({
907
- getDocument: vi.fn().mockResolvedValue(null),
908
- transaction: mockTransaction
909
- });
910
- setupEditorMocks();
911
- // Mock unlink to throw an error (should be caught silently)
912
- mockFs.unlink.mockRejectedValue(new Error('Permission denied'));
913
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
914
- mockJson5.parse.mockReturnValue(mockDoc);
915
- mockJson5.stringify.mockReturnValue(JSON.stringify({
916
- _id: 'test-doc',
917
- _type: 'specify-me'
918
- }, null, 2));
919
- const { stdout } = await testCommand(CreateDocumentCommand, [], {
920
- mocks: {
921
- ...defaultMocks
922
- }
923
- });
924
- // Should still succeed despite file cleanup error
925
- expect(stdout).toContain('Created:');
926
- expect(stdout).toContain('test-doc');
927
- expect(mockFs.unlink).toHaveBeenCalled();
928
- }));
929
- });
930
- describe('watch mode', ()=>{
931
- test('enables watch mode and logs appropriate messages', withEditorEnv(async ()=>{
932
- const mockWatcher = {
933
- on: vi.fn().mockReturnThis()
934
- };
935
- mockChokidarWatch.mockReturnValue(mockWatcher);
936
- const mockTransaction = vi.fn().mockReturnValue({
937
- commit: vi.fn().mockResolvedValue({
938
- results: [
939
- {
940
- id: 'test-doc',
941
- operation: 'create'
942
- }
943
- ]
944
- })
945
- });
946
- mockGetProjectCliClient.mockResolvedValue({
947
- getDocument: vi.fn().mockResolvedValue(null),
948
- transaction: mockTransaction
949
- });
950
- setupWatchMocks();
951
- mockJson5.stringify.mockReturnValue(JSON.stringify({
952
- _id: 'test-doc',
953
- _type: 'specify-me'
954
- }, null, 2));
955
- mockExeca.mockResolvedValue({});
956
- const { stdout } = await testCommand(CreateDocumentCommand, [
957
- '--watch'
958
- ], {
959
- mocks: {
960
- ...defaultMocks
961
- }
962
- });
963
- expect(stdout).toContain('Watch mode:');
964
- expect(stdout).toContain('Will write documents on each save.');
965
- expect(stdout).toContain('Press Ctrl + C to cancel watch mode.');
966
- expect(mockWatcher.on).toHaveBeenCalledWith('change', expect.any(Function));
967
- expect(mockExeca).toHaveBeenCalledWith('vim', expect.any(Array), {
968
- stdio: 'inherit'
969
- });
970
- expect(mockChokidarWatch).toHaveBeenCalledWith(expect.stringContaining('.json'));
971
- }));
972
- test('handles file change events in watch mode', withEditorEnv(async ()=>{
973
- const mockDoc = {
974
- _id: 'test-doc',
975
- _type: 'post',
976
- title: 'Updated Post'
977
- };
978
- let changeHandler;
979
- const mockWatcher = {
980
- on: vi.fn().mockImplementation((event, handler)=>{
981
- if (event === 'change') {
982
- changeHandler = handler;
983
- }
984
- return mockWatcher;
985
- })
986
- };
987
- mockChokidarWatch.mockReturnValue(mockWatcher);
988
- const mockTransaction = vi.fn().mockReturnValue({
989
- commit: vi.fn().mockResolvedValue({
990
- results: [
991
- {
992
- id: 'test-doc',
993
- operation: 'create'
994
- }
995
- ]
996
- })
997
- });
998
- mockGetProjectCliClient.mockResolvedValue({
999
- getDocument: vi.fn().mockResolvedValue(null),
1000
- transaction: mockTransaction
1001
- });
1002
- setupWatchMocks();
1003
- mockJson5.stringify.mockReturnValue(JSON.stringify({
1004
- _id: 'test-doc',
1005
- _type: 'specify-me'
1006
- }, null, 2));
1007
- mockExeca.mockResolvedValue({});
1008
- // Mock file read to return different content for file change
1009
- mockFs.readFile.mockResolvedValue(JSON.stringify(mockDoc));
1010
- mockJson5.parse.mockReturnValue(mockDoc);
1011
- await testCommand(CreateDocumentCommand, [
1012
- '--watch'
1013
- ], {
1014
- mocks: {
1015
- ...defaultMocks
1016
- }
1017
- });
1018
- // Simulate file change
1019
- expect(changeHandler).toBeDefined();
1020
- await changeHandler();
1021
- expect(mockTransaction).toHaveBeenCalledWith([
1022
- {
1023
- create: mockDoc
1024
- }
1025
- ]);
1026
- }));
1027
- });
1028
- });
1029
-
1030
- //# sourceMappingURL=create.test.js.map