sanity 5.2.1-next.2 → 5.3.0-next.10

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.
@@ -4,54 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
  import { Worker } from "node:worker_threads";
5
5
  import logSymbols from "log-symbols";
6
6
  import readPkgUp from "read-pkg-up";
7
- import { isatty } from "node:tty";
8
- import chalk from "chalk";
9
- const isTty = isatty(1), headers = {
10
- error: isTty ? chalk.bold(chalk.bgRed(chalk.black(" ERROR "))) : chalk.red("[ERROR]"),
11
- warning: isTty ? chalk.bold(chalk.bgYellow(chalk.black(" WARN "))) : chalk.yellow("[WARN]")
12
- }, severityValues = {
13
- error: 0,
14
- warning: 1
15
- };
16
- function formatPath(pathSegments) {
17
- const format = ([curr, ...next], mode = "object") => {
18
- if (!curr) return "";
19
- if (curr.kind === "property") return format(next, curr.name === "of" ? "array" : "object");
20
- const name = curr.name ? curr.name : `<anonymous_${curr.type}>`;
21
- return `${mode === "array" ? `[${name}]` : `.${name}`}${format(next)}`;
22
- };
23
- return format(pathSegments.slice(1)).slice(1);
24
- }
25
- function getAggregatedSeverity(groupOrGroups) {
26
- return (Array.isArray(groupOrGroups) ? groupOrGroups : [groupOrGroups]).flatMap((group) => group.problems.map((problem) => problem.severity)).find((severity) => severity === "error") ? "error" : "warning";
27
- }
28
- function formatSchemaValidation(validation) {
29
- let unnamedTopLevelTypeCount = 0;
30
- return Object.entries(validation.reduce((acc, next) => {
31
- const [firstSegment] = next.path;
32
- if (!firstSegment || firstSegment.kind !== "type") return acc;
33
- const topLevelType = firstSegment.name || `<unnamed_${firstSegment.type}_type_${unnamedTopLevelTypeCount++}>`, problems = acc[topLevelType] ?? [];
34
- return problems.push(next), acc[topLevelType] = problems, acc;
35
- }, {})).sort((a, b) => {
36
- const [aType, aGroups] = a, [bType, bGroups] = b, aValue = severityValues[getAggregatedSeverity(aGroups)], bValue = severityValues[getAggregatedSeverity(bGroups)];
37
- return aValue === bValue ? aType.localeCompare(bType, "en-US") : aValue - bValue;
38
- }).map(([topLevelType, groups]) => {
39
- const formattedTopLevelType = isTty ? chalk.bgWhite(chalk.black(` ${topLevelType} `)) : `[${topLevelType}]`, header = `${headers[getAggregatedSeverity(groups)]} ${formattedTopLevelType}`, body = groups.sort((a, b) => severityValues[getAggregatedSeverity(a)] - severityValues[getAggregatedSeverity(b)]).map((group) => {
40
- const formattedPath = ` ${chalk.bold(formatPath(group.path) || "(root)")}`, formattedMessages = group.problems.sort((a, b) => severityValues[a.severity] - severityValues[b.severity]).map(({
41
- severity,
42
- message
43
- }) => ` ${logSymbols[severity]} ${message}`).join(`
44
- `);
45
- return `${formattedPath}
46
- ${formattedMessages}`;
47
- }).join(`
48
- `);
49
- return `${header}
50
- ${body}`;
51
- }).join(`
52
-
53
- `);
54
- }
7
+ import { getAggregatedSeverity, formatSchemaValidation } from "./formatSchemaValidation.js";
55
8
  function generateMetafile(schema) {
56
9
  const output = {
57
10
  imports: [],
@@ -1 +1 @@
1
- {"version":3,"file":"validateAction.js","sources":["../../src/_internal/cli/actions/schema/formatSchemaValidation.ts","../../src/_internal/cli/actions/schema/metafile.ts","../../src/_internal/cli/actions/schema/validateAction.ts"],"sourcesContent":["import {isatty} from 'node:tty'\n\nimport {type SchemaValidationProblemGroup, type SchemaValidationProblemPath} from '@sanity/types'\nimport chalk from 'chalk'\nimport logSymbols from 'log-symbols'\n\nconst isTty = isatty(1)\n\nconst headers = {\n error: isTty ? chalk.bold(chalk.bgRed(chalk.black(' ERROR '))) : chalk.red('[ERROR]'),\n warning: isTty ? chalk.bold(chalk.bgYellow(chalk.black(' WARN '))) : chalk.yellow('[WARN]'),\n}\n\nconst severityValues = {error: 0, warning: 1}\n\nfunction formatPath(pathSegments: SchemaValidationProblemPath) {\n const format = (\n [curr, ...next]: SchemaValidationProblemPath,\n mode: 'object' | 'array' = 'object',\n ): string => {\n if (!curr) return ''\n if (curr.kind === 'property') return format(next, curr.name === 'of' ? 'array' : 'object')\n\n const name = curr.name ? curr.name : `<anonymous_${curr.type}>`\n return `${mode === 'array' ? `[${name}]` : `.${name}`}${format(next)}`\n }\n\n return format(pathSegments.slice(1)).slice(1) // removes the top-level type and leading `.`\n}\n\nexport function getAggregatedSeverity(\n groupOrGroups: SchemaValidationProblemGroup | SchemaValidationProblemGroup[],\n): 'error' | 'warning' {\n const groups = Array.isArray(groupOrGroups) ? groupOrGroups : [groupOrGroups]\n return groups\n .flatMap((group) => group.problems.map((problem) => problem.severity))\n .find((severity) => severity === 'error')\n ? 'error'\n : 'warning'\n}\n\nexport function formatSchemaValidation(validation: SchemaValidationProblemGroup[]): string {\n let unnamedTopLevelTypeCount = 0\n const validationByType = Object.entries(\n validation.reduce<Record<string, SchemaValidationProblemGroup[]>>((acc, next) => {\n const [firstSegment] = next.path\n if (!firstSegment) return acc\n if (firstSegment.kind !== 'type') return acc\n\n const topLevelType =\n firstSegment.name || `<unnamed_${firstSegment.type}_type_${unnamedTopLevelTypeCount++}>`\n const problems = acc[topLevelType] ?? []\n\n problems.push(next)\n\n acc[topLevelType] = problems\n return acc\n }, {}),\n )\n\n const formatted = validationByType\n .sort((a, b) => {\n const [aType, aGroups] = a\n const [bType, bGroups] = b\n const aValue = severityValues[getAggregatedSeverity(aGroups)]\n const bValue = severityValues[getAggregatedSeverity(bGroups)]\n if (aValue === bValue) return aType.localeCompare(bType, 'en-US')\n return aValue - bValue\n })\n .map(([topLevelType, groups]) => {\n const formattedTopLevelType = isTty\n ? chalk.bgWhite(chalk.black(` ${topLevelType} `))\n : `[${topLevelType}]`\n\n const header = `${headers[getAggregatedSeverity(groups)]} ${formattedTopLevelType}`\n const body = groups\n .sort(\n (a, b) =>\n severityValues[getAggregatedSeverity(a)] - severityValues[getAggregatedSeverity(b)],\n )\n .map((group) => {\n const formattedPath = ` ${chalk.bold(formatPath(group.path) || '(root)')}`\n const formattedMessages = group.problems\n .sort((a, b) => severityValues[a.severity] - severityValues[b.severity])\n .map(({severity, message}) => ` ${logSymbols[severity]} ${message}`)\n .join('\\n')\n\n return `${formattedPath}\\n${formattedMessages}`\n })\n .join('\\n')\n\n return `${header}\\n${body}`\n })\n .join('\\n\\n')\n\n return formatted\n}\n","import {type SeralizedSchemaDebug, type SerializedTypeDebug} from '../../threads/validateSchema'\n\n// This implements the metafile format of ESBuild.\ntype Metafile = {\n inputs: Record<string, MetafileInput>\n outputs: Record<string, MetafileOutput>\n}\n\ntype MetafileOutput = {\n imports: []\n exports: []\n inputs: Record<string, {bytesInOutput: number}>\n bytes: number\n}\n\ntype MetafileInput = {\n bytes: number\n imports: []\n format: 'esm' | 'csj'\n}\n\n/** Converts the */\nexport function generateMetafile(schema: SeralizedSchemaDebug): Metafile {\n const output: MetafileOutput = {\n imports: [],\n exports: [],\n inputs: {},\n bytes: 0,\n }\n\n // Generate a esbuild metafile\n const inputs: Record<string, MetafileInput> = {}\n\n function processType(path: string, entry: SerializedTypeDebug) {\n let childSize = 0\n\n if (entry.fields) {\n for (const [name, fieldEntry] of Object.entries(entry.fields)) {\n processType(`${path}/${name}`, fieldEntry)\n childSize += fieldEntry.size\n }\n }\n\n if (entry.of) {\n for (const [name, fieldEntry] of Object.entries(entry.of)) {\n processType(`${path}/${name}`, fieldEntry)\n childSize += fieldEntry.size\n }\n }\n\n const selfSize = entry.size - childSize\n\n inputs[path] = {\n bytes: selfSize,\n imports: [],\n format: 'esm',\n }\n\n output.inputs[path] = {\n bytesInOutput: selfSize,\n }\n\n output.bytes += selfSize\n }\n\n for (const [name, entry] of Object.entries(schema.types)) {\n const fakePath = `schema/${entry.extends}/${name}`\n processType(fakePath, entry)\n }\n\n for (const [name, entry] of Object.entries(schema.hoisted)) {\n const fakePath = `hoisted/${name}`\n processType(fakePath, entry)\n }\n\n return {outputs: {root: output}, inputs}\n}\n","import {writeFileSync} from 'node:fs'\nimport path from 'node:path'\nimport {fileURLToPath} from 'node:url'\nimport {Worker} from 'node:worker_threads'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport logSymbols from 'log-symbols'\nimport readPkgUp from 'read-pkg-up'\n\nimport {\n type ValidateSchemaWorkerData,\n type ValidateSchemaWorkerResult,\n} from '../../threads/validateSchema'\nimport {formatSchemaValidation, getAggregatedSeverity} from './formatSchemaValidation'\nimport {generateMetafile} from './metafile'\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url))\n\ninterface ValidateFlags {\n 'workspace'?: string\n 'format'?: string\n 'level'?: 'error' | 'warning'\n 'debug-metafile-path'?: string\n}\n\nexport type SchemaValidationFormatter = (result: ValidateSchemaWorkerResult) => string\n\nexport default async function validateAction(\n args: CliCommandArguments<ValidateFlags>,\n {workDir, output}: CliCommandContext,\n): Promise<void> {\n const flags = args.extOptions\n\n const rootPkgPath = readPkgUp.sync({cwd: __dirname})?.path\n if (!rootPkgPath) {\n throw new Error('Could not find root directory for `sanity` package')\n }\n\n const workerPath = path.join(\n path.dirname(rootPkgPath),\n 'lib',\n '_internal',\n 'cli',\n 'threads',\n 'validateSchema.cjs',\n )\n\n const level = flags.level || 'warning'\n\n if (level !== 'error' && level !== 'warning') {\n throw new Error(`Invalid level. Available levels are 'error' and 'warning'.`)\n }\n\n const format = flags.format || 'pretty'\n\n if (!['pretty', 'ndjson', 'json'].includes(format)) {\n throw new Error(\n `Did not recognize format '${flags.format}'. Available formats are 'pretty', 'ndjson', and 'json'.`,\n )\n }\n\n let spinner\n\n if (format === 'pretty') {\n spinner = output\n .spinner(\n flags.workspace\n ? `Validating schema from workspace '${flags.workspace}'…`\n : 'Validating schema…',\n )\n .start()\n }\n\n const worker = new Worker(workerPath, {\n workerData: {\n workDir,\n level,\n workspace: flags.workspace,\n debugSerialize: Boolean(flags['debug-metafile-path']),\n } satisfies ValidateSchemaWorkerData,\n env: process.env,\n })\n\n const {validation, serializedDebug} = await new Promise<ValidateSchemaWorkerResult>(\n (resolve, reject) => {\n worker.addListener('message', resolve)\n worker.addListener('error', reject)\n },\n )\n\n const problems = validation.flatMap((group) => group.problems)\n const errorCount = problems.filter((problem) => problem.severity === 'error').length\n const warningCount = problems.filter((problem) => problem.severity === 'warning').length\n\n const overallSeverity = getAggregatedSeverity(validation)\n const didFail = overallSeverity === 'error'\n\n if (flags['debug-metafile-path'] && !didFail) {\n if (!serializedDebug) throw new Error('serializedDebug should always be produced')\n const metafile = generateMetafile(serializedDebug)\n writeFileSync(flags['debug-metafile-path'], JSON.stringify(metafile), 'utf8')\n }\n\n switch (format) {\n case 'ndjson': {\n for (const group of validation) {\n output.print(JSON.stringify(group))\n }\n break\n }\n case 'json': {\n output.print(JSON.stringify(validation))\n break\n }\n default: {\n spinner?.succeed('Validated schema')\n output.print(`\\nValidation results:`)\n output.print(\n `${logSymbols.error} Errors: ${errorCount.toLocaleString('en-US')} error${\n errorCount === 1 ? '' : 's'\n }`,\n )\n if (level !== 'error') {\n output.print(\n `${logSymbols.warning} Warnings: ${warningCount.toLocaleString('en-US')} warning${\n warningCount === 1 ? '' : 's'\n }`,\n )\n }\n output.print()\n\n output.print(formatSchemaValidation(validation))\n\n if (flags['debug-metafile-path']) {\n output.print()\n if (didFail) {\n output.print(`${logSymbols.info} Metafile not written due to validation errors`)\n } else {\n output.print(`${logSymbols.info} Metafile written to: ${flags['debug-metafile-path']}`)\n output.print(` This can be analyzed at https://esbuild.github.io/analyze/`)\n }\n }\n }\n }\n\n process.exitCode = didFail ? 1 : 0\n}\n"],"names":["isTty","isatty","headers","error","chalk","bold","bgRed","black","red","warning","bgYellow","yellow","severityValues","formatPath","pathSegments","format","curr","next","mode","kind","name","type","slice","getAggregatedSeverity","groupOrGroups","Array","isArray","flatMap","group","problems","map","problem","severity","find","formatSchemaValidation","validation","unnamedTopLevelTypeCount","Object","entries","reduce","acc","firstSegment","path","topLevelType","push","sort","a","b","aType","aGroups","bType","bGroups","aValue","bValue","localeCompare","groups","formattedTopLevelType","bgWhite","header","body","formattedPath","formattedMessages","message","logSymbols","join","generateMetafile","schema","output","imports","exports","inputs","bytes","processType","entry","childSize","fields","fieldEntry","size","of","selfSize","bytesInOutput","types","fakePath","extends","hoisted","outputs","root","__dirname","dirname","fileURLToPath","import","url","validateAction","args","workDir","flags","extOptions","rootPkgPath","readPkgUp","sync","cwd","Error","workerPath","level","includes","spinner","workspace","start","worker","Worker","workerData","debugSerialize","Boolean","env","process","serializedDebug","Promise","resolve","reject","addListener","errorCount","filter","length","warningCount","didFail","metafile","writeFileSync","JSON","stringify","print","succeed","toLocaleString","info","exitCode"],"mappings":";;;;;;;;AAMA,MAAMA,QAAQC,OAAO,CAAC,GAEhBC,UAAU;AAAA,EACdC,OAAOH,QAAQI,MAAMC,KAAKD,MAAME,MAAMF,MAAMG,MAAM,SAAS,CAAC,CAAC,IAAIH,MAAMI,IAAI,SAAS;AAAA,EACpFC,SAAST,QAAQI,MAAMC,KAAKD,MAAMM,SAASN,MAAMG,MAAM,QAAQ,CAAC,CAAC,IAAIH,MAAMO,OAAO,QAAQ;AAC5F,GAEMC,iBAAiB;AAAA,EAACT,OAAO;AAAA,EAAGM,SAAS;AAAC;AAE5C,SAASI,WAAWC,cAA2C;AAC7D,QAAMC,SAASA,CACb,CAACC,MAASC,OAAI,GACdC,OAA2B,aAChB;AACX,QAAI,CAACF,KAAM,QAAO;AAClB,QAAIA,KAAKG,SAAS,WAAY,QAAOJ,OAAOE,MAAMD,KAAKI,SAAS,OAAO,UAAU,QAAQ;AAEzF,UAAMA,OAAOJ,KAAKI,OAAOJ,KAAKI,OAAO,cAAcJ,KAAKK,IAAI;AAC5D,WAAO,GAAGH,SAAS,UAAU,IAAIE,IAAI,MAAM,IAAIA,IAAI,EAAE,GAAGL,OAAOE,IAAI,CAAC;AAAA,EACtE;AAEA,SAAOF,OAAOD,aAAaQ,MAAM,CAAC,CAAC,EAAEA,MAAM,CAAC;AAC9C;AAEO,SAASC,sBACdC,eACqB;AAErB,UADeC,MAAMC,QAAQF,aAAa,IAAIA,gBAAgB,CAACA,aAAa,GAEzEG,QAASC,CAAAA,UAAUA,MAAMC,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AA,oBAAuB,GACpC9D,OAAO8D,MACL,GAAGlE,WAAW5D,KAAK,cAAcqH,WAAWW,eAAe,OAAO,CAAC,SACjEX,eAAe,IAAI,KAAK,GAAG,EAE/B,GACIjB,UAAU,WACZpC,OAAO8D,MACL,GAAGlE,WAAWtD,OAAO,cAAckH,aAAaQ,eAAe,OAAO,CAAC,WACrER,iBAAiB,IAAI,KAAK,GAAG,EAEjC,GAEFxD,OAAO8D,MAAAA,GAEP9D,OAAO8D,MAAM/F,uBAAuBC,UAAU,CAAC,GAE3C4D,MAAM,qBAAqB,MAC7B5B,OAAO8D,MAAAA,GACHL,UACFzD,OAAO8D,MAAM,GAAGlE,WAAWqE,IAAI,gDAAgD,KAE/EjE,OAAO8D,MAAM,GAAGlE,WAAWqE,IAAI,yBAAyBrC,MAAM,qBAAqB,CAAC,EAAE,GACtF5B,OAAO8D,MAAM,8DAA8D;AAAA,EAAA;AAMnFf,UAAQmB,WAAWT,UAAU,IAAI;AACnC;"}
1
+ {"version":3,"file":"validateAction.js","sources":["../../src/_internal/cli/actions/schema/metafile.ts","../../src/_internal/cli/actions/schema/validateAction.ts"],"sourcesContent":["import {type SeralizedSchemaDebug, type SerializedTypeDebug} from '../../threads/validateSchema'\n\n// This implements the metafile format of ESBuild.\ntype Metafile = {\n inputs: Record<string, MetafileInput>\n outputs: Record<string, MetafileOutput>\n}\n\ntype MetafileOutput = {\n imports: []\n exports: []\n inputs: Record<string, {bytesInOutput: number}>\n bytes: number\n}\n\ntype MetafileInput = {\n bytes: number\n imports: []\n format: 'esm' | 'csj'\n}\n\n/** Converts the */\nexport function generateMetafile(schema: SeralizedSchemaDebug): Metafile {\n const output: MetafileOutput = {\n imports: [],\n exports: [],\n inputs: {},\n bytes: 0,\n }\n\n // Generate a esbuild metafile\n const inputs: Record<string, MetafileInput> = {}\n\n function processType(path: string, entry: SerializedTypeDebug) {\n let childSize = 0\n\n if (entry.fields) {\n for (const [name, fieldEntry] of Object.entries(entry.fields)) {\n processType(`${path}/${name}`, fieldEntry)\n childSize += fieldEntry.size\n }\n }\n\n if (entry.of) {\n for (const [name, fieldEntry] of Object.entries(entry.of)) {\n processType(`${path}/${name}`, fieldEntry)\n childSize += fieldEntry.size\n }\n }\n\n const selfSize = entry.size - childSize\n\n inputs[path] = {\n bytes: selfSize,\n imports: [],\n format: 'esm',\n }\n\n output.inputs[path] = {\n bytesInOutput: selfSize,\n }\n\n output.bytes += selfSize\n }\n\n for (const [name, entry] of Object.entries(schema.types)) {\n const fakePath = `schema/${entry.extends}/${name}`\n processType(fakePath, entry)\n }\n\n for (const [name, entry] of Object.entries(schema.hoisted)) {\n const fakePath = `hoisted/${name}`\n processType(fakePath, entry)\n }\n\n return {outputs: {root: output}, inputs}\n}\n","import {writeFileSync} from 'node:fs'\nimport path from 'node:path'\nimport {fileURLToPath} from 'node:url'\nimport {Worker} from 'node:worker_threads'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport logSymbols from 'log-symbols'\nimport readPkgUp from 'read-pkg-up'\n\nimport {\n type ValidateSchemaWorkerData,\n type ValidateSchemaWorkerResult,\n} from '../../threads/validateSchema'\nimport {formatSchemaValidation, getAggregatedSeverity} from './formatSchemaValidation'\nimport {generateMetafile} from './metafile'\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url))\n\ninterface ValidateFlags {\n 'workspace'?: string\n 'format'?: string\n 'level'?: 'error' | 'warning'\n 'debug-metafile-path'?: string\n}\n\nexport type SchemaValidationFormatter = (result: ValidateSchemaWorkerResult) => string\n\nexport default async function validateAction(\n args: CliCommandArguments<ValidateFlags>,\n {workDir, output}: CliCommandContext,\n): Promise<void> {\n const flags = args.extOptions\n\n const rootPkgPath = readPkgUp.sync({cwd: __dirname})?.path\n if (!rootPkgPath) {\n throw new Error('Could not find root directory for `sanity` package')\n }\n\n const workerPath = path.join(\n path.dirname(rootPkgPath),\n 'lib',\n '_internal',\n 'cli',\n 'threads',\n 'validateSchema.cjs',\n )\n\n const level = flags.level || 'warning'\n\n if (level !== 'error' && level !== 'warning') {\n throw new Error(`Invalid level. Available levels are 'error' and 'warning'.`)\n }\n\n const format = flags.format || 'pretty'\n\n if (!['pretty', 'ndjson', 'json'].includes(format)) {\n throw new Error(\n `Did not recognize format '${flags.format}'. Available formats are 'pretty', 'ndjson', and 'json'.`,\n )\n }\n\n let spinner\n\n if (format === 'pretty') {\n spinner = output\n .spinner(\n flags.workspace\n ? `Validating schema from workspace '${flags.workspace}'…`\n : 'Validating schema…',\n )\n .start()\n }\n\n const worker = new Worker(workerPath, {\n workerData: {\n workDir,\n level,\n workspace: flags.workspace,\n debugSerialize: Boolean(flags['debug-metafile-path']),\n } satisfies ValidateSchemaWorkerData,\n env: process.env,\n })\n\n const {validation, serializedDebug} = await new Promise<ValidateSchemaWorkerResult>(\n (resolve, reject) => {\n worker.addListener('message', resolve)\n worker.addListener('error', reject)\n },\n )\n\n const problems = validation.flatMap((group) => group.problems)\n const errorCount = problems.filter((problem) => problem.severity === 'error').length\n const warningCount = problems.filter((problem) => problem.severity === 'warning').length\n\n const overallSeverity = getAggregatedSeverity(validation)\n const didFail = overallSeverity === 'error'\n\n if (flags['debug-metafile-path'] && !didFail) {\n if (!serializedDebug) throw new Error('serializedDebug should always be produced')\n const metafile = generateMetafile(serializedDebug)\n writeFileSync(flags['debug-metafile-path'], JSON.stringify(metafile), 'utf8')\n }\n\n switch (format) {\n case 'ndjson': {\n for (const group of validation) {\n output.print(JSON.stringify(group))\n }\n break\n }\n case 'json': {\n output.print(JSON.stringify(validation))\n break\n }\n default: {\n spinner?.succeed('Validated schema')\n output.print(`\\nValidation results:`)\n output.print(\n `${logSymbols.error} Errors: ${errorCount.toLocaleString('en-US')} error${\n errorCount === 1 ? '' : 's'\n }`,\n )\n if (level !== 'error') {\n output.print(\n `${logSymbols.warning} Warnings: ${warningCount.toLocaleString('en-US')} warning${\n warningCount === 1 ? '' : 's'\n }`,\n )\n }\n output.print()\n\n output.print(formatSchemaValidation(validation))\n\n if (flags['debug-metafile-path']) {\n output.print()\n if (didFail) {\n output.print(`${logSymbols.info} Metafile not written due to validation errors`)\n } else {\n output.print(`${logSymbols.info} Metafile written to: ${flags['debug-metafile-path']}`)\n output.print(` This can be analyzed at https://esbuild.github.io/analyze/`)\n }\n }\n }\n }\n\n process.exitCode = didFail ? 1 : 0\n}\n"],"names":["generateMetafile","schema","output","imports","exports","inputs","bytes","processType","path","entry","childSize","fields","name","fieldEntry","Object","entries","size","of","selfSize","format","bytesInOutput","types","fakePath","extends","hoisted","outputs","root","__dirname","dirname","fileURLToPath","import","url","validateAction","args","workDir","flags","extOptions","rootPkgPath","readPkgUp","sync","cwd","Error","workerPath","join","level","includes","spinner","workspace","start","worker","Worker","workerData","debugSerialize","Boolean","env","process","validation","serializedDebug","Promise","resolve","reject","addListener","problems","flatMap","group","errorCount","filter","problem","severity","length","warningCount","didFail","getAggregatedSeverity","metafile","writeFileSync","JSON","stringify","print","succeed","logSymbols","error","toLocaleString","warning","formatSchemaValidation","info","exitCode"],"mappings":";;;;;;;AAsBO,SAASA,iBAAiBC,QAAwC;AACvE,QAAMC,SAAyB;AAAA,IAC7BC,SAAS,CAAA;AAAA,IACTC,SAAS,CAAA;AAAA,IACTC,QAAQ,CAAA;AAAA,IACRC,OAAO;AAAA,EAAA,GAIHD,SAAwC,CAAA;AAE9C,WAASE,YAAYC,OAAcC,OAA4B;AAC7D,QAAIC,YAAY;AAEhB,QAAID,MAAME;AACR,iBAAW,CAACC,MAAMC,UAAU,KAAKC,OAAOC,QAAQN,MAAME,MAAM;AAC1DJ,oBAAY,GAAGC,KAAI,IAAII,IAAI,IAAIC,UAAU,GACzCH,aAAaG,WAAWG;AAI5B,QAAIP,MAAMQ;AACR,iBAAW,CAACL,MAAMC,UAAU,KAAKC,OAAOC,QAAQN,MAAMQ,EAAE;AACtDV,oBAAY,GAAGC,KAAI,IAAII,IAAI,IAAIC,UAAU,GACzCH,aAAaG,WAAWG;AAI5B,UAAME,WAAWT,MAAMO,OAAON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ACF;AAAA,IACA;AACEV,eAASgC,QAAQ,kBAAkB,GACnC5E,OAAO2E,MAAM;AAAA,oBAAuB,GACpC3E,OAAO2E,MACL,GAAGE,WAAWC,KAAK,cAAcf,WAAWgB,eAAe,OAAO,CAAC,SACjEhB,eAAe,IAAI,KAAK,GAAG,EAE/B,GACIrB,UAAU,WACZ1C,OAAO2E,MACL,GAAGE,WAAWG,OAAO,cAAcZ,aAAaW,eAAe,OAAO,CAAC,WACrEX,iBAAiB,IAAI,KAAK,GAAG,EAEjC,GAEFpE,OAAO2E,MAAAA,GAEP3E,OAAO2E,MAAMM,uBAAuB3B,UAAU,CAAC,GAE3CrB,MAAM,qBAAqB,MAC7BjC,OAAO2E,MAAAA,GACHN,UACFrE,OAAO2E,MAAM,GAAGE,WAAWK,IAAI,gDAAgD,KAE/ElF,OAAO2E,MAAM,GAAGE,WAAWK,IAAI,yBAAyBjD,MAAM,qBAAqB,CAAC,EAAE,GACtFjC,OAAO2E,MAAM,8DAA8D;AAAA,EAAA;AAMnFtB,UAAQ8B,WAAWd,UAAU,IAAI;AACnC;"}
@@ -7,7 +7,7 @@ try {
7
7
  try {
8
8
  buildVersion = buildVersion || // This is replaced by `@sanity/pkg-utils` at build time
9
9
  // and must always be references by its full static name, e.g. no optional chaining, no `if (process && process.env)` etc.
10
- "5.2.1-next.2+a87917c6e4";
10
+ "5.3.0-next.10+f9c1350392";
11
11
  } catch {
12
12
  }
13
13
  const SANITY_VERSION = buildVersion || `${version}-dev`;
package/lib/index.js CHANGED
@@ -54600,14 +54600,22 @@ const ReleaseDocumentsCounter = (t0) => {
54600
54600
  id: "error",
54601
54601
  sorting: !1,
54602
54602
  width: 40,
54603
- header: () => /* @__PURE__ */ jsx(Fragment, {}),
54603
+ header: ({
54604
+ headerProps
54605
+ }) => /* @__PURE__ */ jsx(Flex, { ...headerProps, paddingY: 3, sizing: "border" }),
54604
54606
  cell: ({
54605
- datum: {
54607
+ datum,
54608
+ cellProps
54609
+ }) => {
54610
+ const {
54606
54611
  error,
54607
54612
  state
54608
- },
54609
- cellProps
54610
- }) => /* @__PURE__ */ jsx(Flex, { ...cellProps, align: "center", paddingX: 2, paddingY: 3, sizing: "border", "data-testid": "error-indicator", children: typeof error < "u" && state === "active" && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text$1, { size: 1, children: t("failed-publish-title") }), portal: !0, children: /* @__PURE__ */ jsx(Text$1, { size: 1, children: /* @__PURE__ */ jsx(ToneIcon, { icon: ErrorOutlineIcon, tone: "critical" }) }) }) })
54613
+ } = datum, hasError = typeof error < "u" && state === "active", hasWarning = state === "active" && getIsScheduledDateInPast(datum);
54614
+ return /* @__PURE__ */ jsxs(Flex, { ...cellProps, align: "center", gap: 2, paddingX: 2, paddingY: 3, sizing: "border", "data-testid": "error-indicator", children: [
54615
+ hasError && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text$1, { size: 1, children: t("failed-publish-title") }), portal: !0, children: /* @__PURE__ */ jsx(Text$1, { size: 1, children: /* @__PURE__ */ jsx(ToneIcon, { icon: ErrorOutlineIcon, tone: "critical" }) }) }),
54616
+ hasWarning && /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text$1, { size: 1, children: t("passed-intended-publish-date") }), portal: !0, children: /* @__PURE__ */ jsx(Text$1, { size: 1, children: /* @__PURE__ */ jsx(ToneIcon, { icon: WarningOutlineIcon, tone: "caution" }) }) })
54617
+ ] });
54618
+ }
54611
54619
  }, "all"),
54612
54620
  checkColumnMode({
54613
54621
  id: "documentCount",
@@ -55600,8 +55608,12 @@ function ReleasesOverview() {
55600
55608
  let t6;
55601
55609
  $[16] !== selectedPerspective ? (t6 = (datum) => datum.isDeleted ? {
55602
55610
  tone: "transparent"
55611
+ } : isReleaseDocument(selectedPerspective) && selectedPerspective._id === datum._id ? {
55612
+ tone: getReleaseTone(datum)
55613
+ } : datum.state === "active" && getIsScheduledDateInPast(datum) ? {
55614
+ tone: "caution"
55603
55615
  } : {
55604
- tone: isReleaseDocument(selectedPerspective) && selectedPerspective._id === datum._id ? getReleaseTone(datum) : "default"
55616
+ tone: "default"
55605
55617
  }, $[16] = selectedPerspective, $[17] = t6) : t6 = $[17];
55606
55618
  const getRowProps = t6, [scrollContainerRef, setScrollContainerRef] = useState(null), hasReleases = releases2.length > 0 || archivedReleases.length > 0, showDraftsDisabledBanner = cardinalityView === "drafts" && (!isDraftModelEnabled || !isScheduledDraftsEnabled);
55607
55619
  let t7;