sanity 3.77.3-server-side-schemas.16 → 3.77.3-server-side-schemas.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,16 +166,24 @@ async function schemaListAction(args, context) {
166
166
  output.error("Project ID and dataset must be defined.");
167
167
  return;
168
168
  }
169
- const manifestDir = flags["manifest-dir"], manifestPath = getManifestPath(context, manifestDir), manifest = await readManifest(manifestPath, context), schemas = (await Promise.allSettled(uniqBy__default.default(manifest.workspaces, "dataset").map(async (workspace) => (throwIfProjectIdMismatch(workspace, projectId), flags.id ? await client.withConfig({
170
- dataset: workspace.dataset,
171
- projectId: workspace.projectId
172
- }).getDocument(flags.id) : await client.withConfig({
173
- dataset: workspace.dataset,
174
- projectId: workspace.projectId,
175
- useCdn: !1
176
- }).fetch("*[_type == $type]", {
177
- type: SANITY_WORKSPACE_SCHEMA_TYPE
178
- }))))).map((result, index) => {
169
+ const manifestDir = flags["manifest-dir"], manifestPath = getManifestPath(context, manifestDir), manifest = await readManifest(manifestPath, context), schemas = (await Promise.allSettled(uniqBy__default.default(manifest.workspaces, "dataset").map(async (workspace) => {
170
+ if (throwIfProjectIdMismatch(workspace, projectId), flags.id) {
171
+ const schemaRes = await client.withConfig({
172
+ dataset: workspace.dataset,
173
+ projectId: workspace.projectId
174
+ }).getDocument(flags.id);
175
+ if (!schemaRes)
176
+ throw new Error(`Schema "${flags.id}" not found in dataset "${workspace.dataset}"`);
177
+ return schemaRes;
178
+ }
179
+ return await client.withConfig({
180
+ dataset: workspace.dataset,
181
+ projectId: workspace.projectId,
182
+ useCdn: !1
183
+ }).fetch("*[_type == $type]", {
184
+ type: SANITY_WORKSPACE_SCHEMA_TYPE
185
+ });
186
+ }))).map((result, index) => {
179
187
  if (result.status === "rejected") {
180
188
  const workspace = manifest.workspaces[index];
181
189
  return output.error(chalk__default.default.red(`Failed to fetch schemas for workspace '${workspace.name}': ${result.reason.message}`)), [];
@@ -201,14 +209,13 @@ const FEATURE_ENABLED_ENV_NAME = "SANITY_CLI_SCHEMA_STORE_ENABLED", SCHEMA_STORE
201
209
  return path__default.default.resolve(process.cwd(), staticPath);
202
210
  }, readAndParseManifest = (manifestPath, context) => {
203
211
  const content = fs$1.readFileSync(manifestPath, "utf-8"), lastModified = fs$1.statSync(manifestPath).mtime.toISOString();
204
- return context.output.print(chalk__default.default.gray(`
205
- \u21B3 Read manifest from ${manifestPath} (last modified: ${lastModified})`)), JSON.parse(content);
206
- }, readManifest = async (readPath, context, spinner) => {
212
+ return context.output.print(chalk__default.default.gray(`\u21B3 Read manifest from ${manifestPath} (last modified: ${lastModified})`)), JSON.parse(content);
213
+ }, readManifest = async (readPath, context) => {
207
214
  const manifestPath = `${readPath}/${MANIFEST_FILENAME}`;
208
215
  try {
209
216
  return readAndParseManifest(manifestPath, context);
210
217
  } catch {
211
- spinner.text = "Manifest not found, attempting to extract it...", await extractManifestSafe({
218
+ await extractManifestSafe({
212
219
  extOptions: {
213
220
  path: readPath
214
221
  },
@@ -221,7 +228,7 @@ const FEATURE_ENABLED_ENV_NAME = "SANITY_CLI_SCHEMA_STORE_ENABLED", SCHEMA_STORE
221
228
  return readAndParseManifest(manifestPath, context);
222
229
  } catch (retryError) {
223
230
  const errorMessage = `Failed to read manifest at ${manifestPath}`;
224
- throw spinner?.fail(errorMessage), context.output.error(errorMessage), retryError;
231
+ throw context.output.error(errorMessage), retryError;
225
232
  }
226
233
  }
227
234
  }, throwIfProjectIdMismatch = (workspace, projectId) => {
@@ -238,7 +245,7 @@ async function storeSchemasAction(args, context) {
238
245
  const {
239
246
  output,
240
247
  apiClient
241
- } = context, spinner = output.spinner({}).start("Storing schemas"), manifestPath = getManifestPath(context, manifestDir);
248
+ } = context, manifestPath = getManifestPath(context, manifestDir);
242
249
  try {
243
250
  const client = apiClient({
244
251
  requireUser: !0,
@@ -247,7 +254,7 @@ async function storeSchemasAction(args, context) {
247
254
  apiVersion: "v2024-08-01"
248
255
  }), projectId = client.config().projectId;
249
256
  if (!projectId) throw new Error("Project ID is not defined");
250
- const manifest = await readManifest(manifestPath, context, spinner);
257
+ const manifest = await readManifest(manifestPath, context);
251
258
  let storedCount = 0, error;
252
259
  const saveSchema = async (workspace) => {
253
260
  const id = `${idPrefix ? `${idPrefix}.` : ""}${SANITY_WORKSPACE_SCHEMA_TYPE}.${workspace.name}`;
@@ -262,9 +269,9 @@ async function storeSchemasAction(args, context) {
262
269
  _id: id,
263
270
  workspace,
264
271
  schema
265
- }).commit(), storedCount++, spinner.text = `Stored ${storedCount} schemas so far...`, verbose && spinner.succeed(`Schema stored for workspace '${workspace.name}'`);
272
+ }).commit(), storedCount++;
266
273
  } catch (err) {
267
- if (error = err, spinner.fail(`Error storing schema for workspace '${workspace.name}':
274
+ if (error = err, output.error(`Error storing schema for workspace '${workspace.name}':
268
275
  ${chalk__default.default.red(`${err.message}`)}`), schemaRequired) throw err;
269
276
  } finally {
270
277
  verbose && output.print(chalk__default.default.gray(`\u21B3 schemaId: ${id}, projectId: ${projectId}, dataset: ${workspace.dataset}`));
@@ -273,12 +280,12 @@ ${chalk__default.default.red(`${err.message}`)}`), schemaRequired) throw err;
273
280
  if (workspaceName) {
274
281
  const workspaceToSave = manifest.workspaces.find((workspace) => workspace.name === workspaceName);
275
282
  if (!workspaceToSave)
276
- throw spinner.fail(`Workspace ${workspaceName} not found in manifest`), new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`);
277
- await saveSchema(workspaceToSave), spinner.succeed("Stored 1 schemas");
283
+ throw output.error(`Workspace ${workspaceName} not found in manifest`), new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`);
284
+ await saveSchema(workspaceToSave), output.success("Stored 1 schemas");
278
285
  } else
279
286
  await Promise.all(manifest.workspaces.map(async (workspace) => {
280
287
  await saveSchema(workspace);
281
- })), spinner.succeed(`Stored ${storedCount}/${manifest.workspaces.length} schemas`);
288
+ })), output.success(`Stored ${storedCount}/${manifest.workspaces.length} schemas`);
282
289
  if (error) throw error;
283
290
  return;
284
291
  } catch (err) {