sanity 3.77.3-server-side-schemas.16 → 3.77.3-server-side-schemas.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/_internal.js +29 -22
- package/lib/_chunks-cjs/_internal.js.map +1 -1
- package/lib/_chunks-cjs/deleteSchemaAction.js +7 -3
- package/lib/_chunks-cjs/deleteSchemaAction.js.map +1 -1
- package/lib/_chunks-cjs/version.js +1 -1
- package/lib/_chunks-es/version.mjs +1 -1
- package/lib/_legacy/version.esm.js +1 -1
- package/package.json +10 -10
- package/src/_internal/cli/actions/schema/deleteSchemaAction.ts +8 -2
- package/src/_internal/cli/actions/schema/schemaListAction.ts +5 -1
- package/src/_internal/cli/actions/schema/storeSchemasAction.ts +8 -14
@@ -9,8 +9,8 @@ async function deleteSchemaAction(args, context) {
|
|
9
9
|
return;
|
10
10
|
const flags = args.extOptions;
|
11
11
|
if (typeof flags.dataset == "boolean") throw new Error("Dataset is empty");
|
12
|
-
if (typeof flags.ids == "boolean") throw new Error("Ids are empty");
|
13
12
|
if (typeof flags["manifest-dir"] == "boolean") throw new Error("Manifest directory is empty");
|
13
|
+
if (typeof flags.ids != "string") throw new Error("--ids is required");
|
14
14
|
const {
|
15
15
|
apiClient,
|
16
16
|
output
|
@@ -31,7 +31,7 @@ async function deleteSchemaAction(args, context) {
|
|
31
31
|
return _internal.throwIfProjectIdMismatch(workspace, projectId), (await client.withConfig({
|
32
32
|
dataset: flags.dataset || workspace.dataset,
|
33
33
|
projectId: workspace.projectId
|
34
|
-
}).delete(schemaId.trim())).results.length ? (output.success(`Schema ${schemaId} deleted from workspace: ${workspace.name}`), !0) : !1;
|
34
|
+
}).delete(schemaId.trim())).results.length ? (output.success(`Schema ${schemaId} deleted from workspace: ${workspace.name}`), !0) : (output.error(`Schema ${schemaId} not found in workspace: ${workspace.name}`), !1);
|
35
35
|
} catch (err) {
|
36
36
|
throw output.error(`Failed to delete schema ${schemaId} from workspace ${workspace.name}:
|
37
37
|
${err.message}`), err;
|
@@ -44,7 +44,11 @@ ${result.reason.message}`)), !1;
|
|
44
44
|
}
|
45
45
|
return result.value;
|
46
46
|
}).filter(Boolean).length;
|
47
|
-
|
47
|
+
if (deletedCount === 0) {
|
48
|
+
output.error("No schemas were deleted");
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
output.success(`Successfully deleted ${deletedCount} schemas`);
|
48
52
|
}
|
49
53
|
exports.default = deleteSchemaAction;
|
50
54
|
//# sourceMappingURL=deleteSchemaAction.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deleteSchemaAction.js","sources":["../../src/_internal/cli/actions/schema/deleteSchemaAction.ts"],"sourcesContent":["import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport chalk from 'chalk'\n\nimport {type ManifestWorkspaceFile} from '../../../manifest/manifestTypes'\nimport {\n getManifestPath,\n readManifest,\n SCHEMA_STORE_ENABLED,\n throwIfProjectIdMismatch,\n} from './storeSchemasAction'\n\nexport interface DeleteSchemaFlags {\n 'ids': string\n 'manifest-dir': string\n 'dataset': string\n}\n\nexport default async function deleteSchemaAction(\n args: CliCommandArguments<DeleteSchemaFlags>,\n context: CliCommandContext,\n): Promise<void> {\n if (!SCHEMA_STORE_ENABLED) {\n return\n }\n const flags = args.extOptions\n if (typeof flags.dataset === 'boolean') throw new Error('Dataset is empty')\n if (typeof flags
|
1
|
+
{"version":3,"file":"deleteSchemaAction.js","sources":["../../src/_internal/cli/actions/schema/deleteSchemaAction.ts"],"sourcesContent":["import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\nimport chalk from 'chalk'\n\nimport {type ManifestWorkspaceFile} from '../../../manifest/manifestTypes'\nimport {\n getManifestPath,\n readManifest,\n SCHEMA_STORE_ENABLED,\n throwIfProjectIdMismatch,\n} from './storeSchemasAction'\n\nexport interface DeleteSchemaFlags {\n 'ids': string\n 'manifest-dir': string\n 'dataset': string\n}\n\nexport default async function deleteSchemaAction(\n args: CliCommandArguments<DeleteSchemaFlags>,\n context: CliCommandContext,\n): Promise<void> {\n if (!SCHEMA_STORE_ENABLED) {\n return\n }\n const flags = args.extOptions\n if (typeof flags.dataset === 'boolean') throw new Error('Dataset is empty')\n if (typeof flags['manifest-dir'] === 'boolean') throw new Error('Manifest directory is empty')\n if (typeof flags.ids !== 'string') throw new Error('--ids is required')\n\n const {apiClient, output} = context\n\n //split ids by comma\n const schemaIds = flags.ids.split(',')\n\n const client = apiClient({\n requireUser: true,\n requireProject: true,\n }).withConfig({apiVersion: 'v2024-08-01'})\n\n const projectId = client.config().projectId\n\n if (!projectId) {\n output.error('Project ID must be defined.')\n return\n }\n\n const manifestDir = flags['manifest-dir']\n const manifestPath = getManifestPath(context, manifestDir)\n const manifest = await readManifest(manifestPath, context)\n\n const results = await Promise.allSettled(\n manifest.workspaces.flatMap((workspace: ManifestWorkspaceFile) => {\n if (flags.dataset && workspace.dataset !== flags.dataset) {\n return []\n }\n return schemaIds.map(async (schemaId) => {\n const idWorkspace = schemaId.split('.').at(-1)\n if (idWorkspace !== workspace.name && !flags.dataset) {\n return false\n }\n try {\n throwIfProjectIdMismatch(workspace, projectId)\n const deletedSchema = await client\n .withConfig({\n dataset: flags.dataset || workspace.dataset,\n projectId: workspace.projectId,\n })\n .delete(schemaId.trim())\n\n if (!deletedSchema.results.length) {\n output.error(`Schema ${schemaId} not found in workspace: ${workspace.name}`)\n return false\n }\n\n output.success(`Schema ${schemaId} deleted from workspace: ${workspace.name}`)\n return true\n } catch (err) {\n output.error(\n `Failed to delete schema ${schemaId} from workspace ${workspace.name}:\\n ${err.message}`,\n )\n throw err\n }\n })\n }),\n )\n\n // Log errors and collect results\n const deletedCount = results\n .map((result, index) => {\n if (result.status === 'rejected') {\n const schemaId = schemaIds[index]\n output.error(chalk.red(`Failed to delete schema '${schemaId}':\\n${result.reason.message}`))\n return false\n }\n return result.value\n })\n .filter(Boolean).length\n\n if (deletedCount === 0) {\n output.error('No schemas were deleted')\n return\n }\n\n output.success(`Successfully deleted ${deletedCount} schemas`)\n}\n"],"names":["deleteSchemaAction","args","context","SCHEMA_STORE_ENABLED","flags","extOptions","dataset","Error","ids","apiClient","output","schemaIds","split","client","requireUser","requireProject","withConfig","apiVersion","projectId","config","error","manifestDir","manifestPath","getManifestPath","manifest","readManifest","deletedCount","Promise","allSettled","workspaces","flatMap","workspace","map","schemaId","at","name","throwIfProjectIdMismatch","delete","trim","results","length","success","err","message","result","index","status","chalk","red","reason","value","filter","Boolean"],"mappings":";;;;;;AAiB8BA,eAAAA,mBAC5BC,MACAC,SACe;AACf,MAAI,CAACC,UAAAA;AACH;AAEF,QAAMC,QAAQH,KAAKI;AACnB,MAAI,OAAOD,MAAME,WAAY,UAAiB,OAAA,IAAIC,MAAM,kBAAkB;AACtE,MAAA,OAAOH,MAAM,cAAc,KAAM,UAAiB,OAAA,IAAIG,MAAM,6BAA6B;AAC7F,MAAI,OAAOH,MAAMI,OAAQ,SAAgB,OAAA,IAAID,MAAM,mBAAmB;AAEhE,QAAA;AAAA,IAACE;AAAAA,IAAWC;AAAAA,EAAAA,IAAUR,SAGtBS,YAAYP,MAAMI,IAAII,MAAM,GAAG,GAE/BC,SAASJ,UAAU;AAAA,IACvBK,aAAa;AAAA,IACbC,gBAAgB;AAAA,EACjB,CAAA,EAAEC,WAAW;AAAA,IAACC,YAAY;AAAA,EAAc,CAAA,GAEnCC,YAAYL,OAAOM,OAASD,EAAAA;AAElC,MAAI,CAACA,WAAW;AACdR,WAAOU,MAAM,6BAA6B;AAC1C;AAAA,EAAA;AAGF,QAAMC,cAAcjB,MAAM,cAAc,GAClCkB,eAAeC,UAAgBrB,gBAAAA,SAASmB,WAAW,GACnDG,WAAW,MAAMC,UAAAA,aAAaH,cAAcpB,OAAO,GAuCnDwB,gBArCU,MAAMC,QAAQC,WAC5BJ,SAASK,WAAWC,QAASC,CAAAA,cACvB3B,MAAME,WAAWyB,UAAUzB,YAAYF,MAAME,UACxC,CAAA,IAE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.20+98354d9a54",
|
4
4
|
"description": "Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -160,11 +160,11 @@
|
|
160
160
|
"@rexxars/react-json-inspector": "^9.0.1",
|
161
161
|
"@sanity/asset-utils": "^2.0.6",
|
162
162
|
"@sanity/bifur-client": "^0.4.1",
|
163
|
-
"@sanity/cli": "3.77.3-server-side-schemas.
|
163
|
+
"@sanity/cli": "3.77.3-server-side-schemas.20+98354d9a54",
|
164
164
|
"@sanity/client": "^6.28.1",
|
165
165
|
"@sanity/color": "^3.0.0",
|
166
166
|
"@sanity/comlink": "^3.0.1",
|
167
|
-
"@sanity/diff": "3.77.3-server-side-schemas.
|
167
|
+
"@sanity/diff": "3.77.3-server-side-schemas.20+98354d9a54",
|
168
168
|
"@sanity/diff-match-patch": "^3.1.1",
|
169
169
|
"@sanity/diff-patch": "^5.0.0",
|
170
170
|
"@sanity/eventsource": "^5.0.0",
|
@@ -174,15 +174,15 @@
|
|
174
174
|
"@sanity/import": "^3.37.9",
|
175
175
|
"@sanity/insert-menu": "^1.1.3",
|
176
176
|
"@sanity/logos": "^2.1.13",
|
177
|
-
"@sanity/migrate": "3.77.3-server-side-schemas.
|
178
|
-
"@sanity/mutator": "3.77.3-server-side-schemas.
|
177
|
+
"@sanity/migrate": "3.77.3-server-side-schemas.20+98354d9a54",
|
178
|
+
"@sanity/mutator": "3.77.3-server-side-schemas.20+98354d9a54",
|
179
179
|
"@sanity/presentation-comlink": "^1.0.8",
|
180
180
|
"@sanity/preview-url-secret": "^2.1.4",
|
181
|
-
"@sanity/schema": "3.77.3-server-side-schemas.
|
181
|
+
"@sanity/schema": "3.77.3-server-side-schemas.20+98354d9a54",
|
182
182
|
"@sanity/telemetry": "^0.7.7",
|
183
|
-
"@sanity/types": "3.77.3-server-side-schemas.
|
183
|
+
"@sanity/types": "3.77.3-server-side-schemas.20+98354d9a54",
|
184
184
|
"@sanity/ui": "^2.14.3",
|
185
|
-
"@sanity/util": "3.77.3-server-side-schemas.
|
185
|
+
"@sanity/util": "3.77.3-server-side-schemas.20+98354d9a54",
|
186
186
|
"@sanity/uuid": "^3.0.2",
|
187
187
|
"@sentry/react": "^8.33.0",
|
188
188
|
"@tanstack/react-table": "^8.16.0",
|
@@ -280,7 +280,7 @@
|
|
280
280
|
"@repo/dev-aliases": "3.77.2",
|
281
281
|
"@repo/package.config": "3.77.2",
|
282
282
|
"@repo/test-config": "3.77.2",
|
283
|
-
"@sanity/codegen": "3.77.3-server-side-schemas.
|
283
|
+
"@sanity/codegen": "3.77.3-server-side-schemas.20+98354d9a54",
|
284
284
|
"@sanity/generate-help-url": "^3.0.0",
|
285
285
|
"@sanity/pkg-utils": "6.13.4",
|
286
286
|
"@sanity/tsdoc": "1.0.169",
|
@@ -325,5 +325,5 @@
|
|
325
325
|
"engines": {
|
326
326
|
"node": ">=18"
|
327
327
|
},
|
328
|
-
"gitHead": "
|
328
|
+
"gitHead": "98354d9a54e0adbedd489c794db794cd8e220df4"
|
329
329
|
}
|
@@ -24,8 +24,8 @@ export default async function deleteSchemaAction(
|
|
24
24
|
}
|
25
25
|
const flags = args.extOptions
|
26
26
|
if (typeof flags.dataset === 'boolean') throw new Error('Dataset is empty')
|
27
|
-
if (typeof flags.ids === 'boolean') throw new Error('Ids are empty')
|
28
27
|
if (typeof flags['manifest-dir'] === 'boolean') throw new Error('Manifest directory is empty')
|
28
|
+
if (typeof flags.ids !== 'string') throw new Error('--ids is required')
|
29
29
|
|
30
30
|
const {apiClient, output} = context
|
31
31
|
|
@@ -68,6 +68,7 @@ export default async function deleteSchemaAction(
|
|
68
68
|
.delete(schemaId.trim())
|
69
69
|
|
70
70
|
if (!deletedSchema.results.length) {
|
71
|
+
output.error(`Schema ${schemaId} not found in workspace: ${workspace.name}`)
|
71
72
|
return false
|
72
73
|
}
|
73
74
|
|
@@ -95,5 +96,10 @@ export default async function deleteSchemaAction(
|
|
95
96
|
})
|
96
97
|
.filter(Boolean).length
|
97
98
|
|
98
|
-
|
99
|
+
if (deletedCount === 0) {
|
100
|
+
output.error('No schemas were deleted')
|
101
|
+
return
|
102
|
+
}
|
103
|
+
|
104
|
+
output.success(`Successfully deleted ${deletedCount} schemas`)
|
99
105
|
}
|
@@ -87,12 +87,16 @@ export default async function schemaListAction(
|
|
87
87
|
throwIfProjectIdMismatch(workspace, projectId)
|
88
88
|
if (flags.id) {
|
89
89
|
// Fetch a specific schema by id
|
90
|
-
|
90
|
+
const schemaRes = await client
|
91
91
|
.withConfig({
|
92
92
|
dataset: workspace.dataset,
|
93
93
|
projectId: workspace.projectId,
|
94
94
|
})
|
95
95
|
.getDocument(flags.id)
|
96
|
+
if (!schemaRes) {
|
97
|
+
throw new Error(`Schema "${flags.id}" not found in dataset "${workspace.dataset}"`)
|
98
|
+
}
|
99
|
+
return schemaRes
|
96
100
|
}
|
97
101
|
// Fetch all schemas
|
98
102
|
return await client
|
@@ -3,7 +3,6 @@ import path, {join, resolve} from 'node:path'
|
|
3
3
|
|
4
4
|
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
5
5
|
import chalk from 'chalk'
|
6
|
-
import {type Ora} from 'ora'
|
7
6
|
|
8
7
|
import {type ManifestSchemaType, type ManifestWorkspaceFile} from '../../../manifest/manifestTypes'
|
9
8
|
import {
|
@@ -43,19 +42,19 @@ const readAndParseManifest = (manifestPath: string, context: CliCommandContext)
|
|
43
42
|
const stats = statSync(manifestPath)
|
44
43
|
const lastModified = stats.mtime.toISOString()
|
45
44
|
context.output.print(
|
46
|
-
chalk.gray(
|
45
|
+
chalk.gray(`↳ Read manifest from ${manifestPath} (last modified: ${lastModified})`),
|
47
46
|
)
|
48
47
|
return JSON.parse(content)
|
49
48
|
}
|
50
49
|
|
51
|
-
export const readManifest = async (readPath: string, context: CliCommandContext
|
50
|
+
export const readManifest = async (readPath: string, context: CliCommandContext) => {
|
52
51
|
const manifestPath = `${readPath}/${MANIFEST_FILENAME}`
|
53
52
|
|
54
53
|
try {
|
55
54
|
return readAndParseManifest(manifestPath, context)
|
56
55
|
} catch (error) {
|
57
56
|
// Still log that we're attempting extraction
|
58
|
-
|
57
|
+
context.output.error(`Manifest not found, attempting to extract it...${manifestPath}`)
|
59
58
|
|
60
59
|
await extractManifestSafe(
|
61
60
|
{
|
@@ -73,7 +72,6 @@ export const readManifest = async (readPath: string, context: CliCommandContext,
|
|
73
72
|
return readAndParseManifest(manifestPath, context)
|
74
73
|
} catch (retryError) {
|
75
74
|
const errorMessage = `Failed to read manifest at ${manifestPath}`
|
76
|
-
spinner?.fail(errorMessage)
|
77
75
|
// We should log the error too for consistency
|
78
76
|
context.output.error(errorMessage)
|
79
77
|
throw retryError
|
@@ -115,8 +113,6 @@ export default async function storeSchemasAction(
|
|
115
113
|
|
116
114
|
const {output, apiClient} = context
|
117
115
|
|
118
|
-
const spinner = output.spinner({}).start('Storing schemas')
|
119
|
-
|
120
116
|
const manifestPath = getManifestPath(context, manifestDir)
|
121
117
|
|
122
118
|
try {
|
@@ -128,7 +124,7 @@ export default async function storeSchemasAction(
|
|
128
124
|
const projectId = client.config().projectId
|
129
125
|
if (!projectId) throw new Error('Project ID is not defined')
|
130
126
|
|
131
|
-
const manifest = await readManifest(manifestPath, context
|
127
|
+
const manifest = await readManifest(manifestPath, context)
|
132
128
|
|
133
129
|
let storedCount = 0
|
134
130
|
|
@@ -150,11 +146,9 @@ export default async function storeSchemasAction(
|
|
150
146
|
.createOrReplace({_type: SANITY_WORKSPACE_SCHEMA_TYPE, _id: id, workspace, schema})
|
151
147
|
.commit()
|
152
148
|
storedCount++
|
153
|
-
spinner.text = `Stored ${storedCount} schemas so far...`
|
154
|
-
if (verbose) spinner.succeed(`Schema stored for workspace '${workspace.name}'`)
|
155
149
|
} catch (err) {
|
156
150
|
error = err
|
157
|
-
|
151
|
+
output.error(
|
158
152
|
`Error storing schema for workspace '${workspace.name}':\n${chalk.red(`${err.message}`)}`,
|
159
153
|
)
|
160
154
|
if (schemaRequired) throw err
|
@@ -173,18 +167,18 @@ export default async function storeSchemasAction(
|
|
173
167
|
(workspace: ManifestWorkspaceFile) => workspace.name === workspaceName,
|
174
168
|
)
|
175
169
|
if (!workspaceToSave) {
|
176
|
-
|
170
|
+
output.error(`Workspace ${workspaceName} not found in manifest`)
|
177
171
|
throw new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`)
|
178
172
|
}
|
179
173
|
await saveSchema(workspaceToSave as ManifestWorkspaceFile)
|
180
|
-
|
174
|
+
output.success(`Stored 1 schemas`)
|
181
175
|
} else {
|
182
176
|
await Promise.all(
|
183
177
|
manifest.workspaces.map(async (workspace: ManifestWorkspaceFile): Promise<void> => {
|
184
178
|
await saveSchema(workspace)
|
185
179
|
}),
|
186
180
|
)
|
187
|
-
|
181
|
+
output.success(`Stored ${storedCount}/${manifest.workspaces.length} schemas`)
|
188
182
|
}
|
189
183
|
|
190
184
|
if (error) throw error
|