sanity 3.72.2-server-side-schemas.21 → 3.72.2-server-side-schemas.24
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 +1 -1
- package/lib/_chunks-cjs/_internal.js.map +1 -1
- package/lib/_chunks-cjs/storeSchemasAction.js +29 -12
- package/lib/_chunks-cjs/storeSchemasAction.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/storeSchemasAction.ts +43 -22
- package/src/_internal/cli/commands/schema/storeSchemaCommand.ts +1 -1
@@ -5,7 +5,7 @@ function _interopDefaultCompat(e) {
|
|
5
5
|
}
|
6
6
|
var path__default = /* @__PURE__ */ _interopDefaultCompat(path);
|
7
7
|
async function storeManifestSchemas(args, context) {
|
8
|
-
const flags = args.extOptions, workspaceName = flags.workspace,
|
8
|
+
const flags = args.extOptions, workspaceName = flags.workspace, idPrefix = flags["id-prefix"], {
|
9
9
|
output,
|
10
10
|
workDir,
|
11
11
|
apiClient
|
@@ -16,11 +16,18 @@ async function storeManifestSchemas(args, context) {
|
|
16
16
|
requireProject: !0
|
17
17
|
}).withConfig({
|
18
18
|
apiVersion: "v2024-08-01"
|
19
|
-
}), projectId = client.config().projectId
|
20
|
-
|
19
|
+
}), projectId = client.config().projectId;
|
20
|
+
let manifest;
|
21
|
+
try {
|
22
|
+
manifest = JSON.parse(fs.readFileSync(`${manifestPath}/create-manifest.json`, "utf-8"));
|
23
|
+
} catch (error) {
|
24
|
+
throw output.error(`Manifest not found at ${manifestPath}/create-manifest.json`), error;
|
25
|
+
}
|
26
|
+
const saveSchema = async (workspace) => {
|
27
|
+
const spinner = output.spinner({}).start("Storing schemas"), id = `${idPrefix || "sanity.workspace.schema"}.${workspace.name}`;
|
21
28
|
try {
|
22
29
|
if (workspace.projectId !== projectId && workspaceName !== workspace.name) {
|
23
|
-
spinner.fail(`
|
30
|
+
spinner.fail(`Mismatch between cli config and manifest projectId in workspace ${workspace.name}: ${projectId} !== ${workspace.projectId}`);
|
24
31
|
return;
|
25
32
|
}
|
26
33
|
const schema = JSON.parse(fs.readFileSync(`${manifestPath}/${workspace.schema}`, "utf-8"));
|
@@ -32,18 +39,28 @@ async function storeManifestSchemas(args, context) {
|
|
32
39
|
_id: id,
|
33
40
|
workspace,
|
34
41
|
schema
|
35
|
-
}).commit(), spinner.succeed(`Schema stored for workspace ${workspace.name}
|
42
|
+
}).commit(), spinner.succeed(`Schema stored for workspace ${workspace.name}`);
|
36
43
|
} catch (error) {
|
37
|
-
spinner.fail(`Error storing schema for workspace
|
44
|
+
throw spinner.fail(`Error storing schema for workspace: ${error}`), error;
|
45
|
+
} finally {
|
46
|
+
output.print(JSON.stringify({
|
47
|
+
workspace: workspace.name,
|
48
|
+
schemaId: id,
|
49
|
+
projectId: workspace.projectId,
|
50
|
+
dataset: workspace.dataset
|
51
|
+
}, null, 2));
|
38
52
|
}
|
39
53
|
};
|
40
54
|
if (workspaceName) {
|
41
|
-
const
|
42
|
-
|
43
|
-
|
44
|
-
await
|
45
|
-
|
46
|
-
|
55
|
+
const workspaceToSave = manifest.workspaces.find((workspace) => workspace.name === workspaceName);
|
56
|
+
if (!workspaceToSave)
|
57
|
+
return output.error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`), new Error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`);
|
58
|
+
await saveSchema(workspaceToSave);
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
await Promise.all(manifest.workspaces.map(async (workspace) => {
|
62
|
+
await saveSchema(workspace);
|
63
|
+
}));
|
47
64
|
return;
|
48
65
|
} catch (err) {
|
49
66
|
if (output.error(err), flags["schema-required"])
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"storeSchemasAction.js","sources":["../../src/_internal/cli/actions/schema/storeSchemasAction.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path, {join, resolve} from 'node:path'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\n\nimport {\n type CreateManifest,\n type ManifestSchemaType,\n type ManifestWorkspaceFile,\n} from '../../../manifest/manifestTypes'\n\nexport interface StoreManifestSchemasFlags {\n 'path'?: string\n 'workspace'?: string\n '
|
1
|
+
{"version":3,"file":"storeSchemasAction.js","sources":["../../src/_internal/cli/actions/schema/storeSchemasAction.ts"],"sourcesContent":["import {readFileSync} from 'node:fs'\nimport path, {join, resolve} from 'node:path'\n\nimport {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'\n\nimport {\n type CreateManifest,\n type ManifestSchemaType,\n type ManifestWorkspaceFile,\n} from '../../../manifest/manifestTypes'\n\nexport interface StoreManifestSchemasFlags {\n 'path'?: string\n 'workspace'?: string\n 'id-prefix'?: string\n 'schema-required'?: boolean\n}\n\nexport default async function storeManifestSchemas(\n args: CliCommandArguments<StoreManifestSchemasFlags>,\n context: CliCommandContext,\n): Promise<Error | undefined> {\n const flags = args.extOptions\n const workspaceName = flags.workspace\n const idPrefix = flags['id-prefix']\n const {output, workDir, apiClient} = context\n\n const defaultOutputDir = resolve(join(workDir, 'dist'))\n\n const outputDir = resolve(defaultOutputDir)\n const defaultStaticPath = join(outputDir, 'static')\n\n const staticPath = flags.path ?? defaultStaticPath\n\n try {\n const manifestPath = path.resolve(process.cwd(), staticPath)\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 let manifest: CreateManifest\n\n try {\n manifest = JSON.parse(readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'))\n } catch (error) {\n output.error(`Manifest not found at ${manifestPath}/create-manifest.json`)\n throw error\n }\n\n const saveSchema = async (workspace: ManifestWorkspaceFile) => {\n const spinner = output.spinner({}).start('Storing schemas')\n const id = `${idPrefix || 'sanity.workspace.schema'}.${workspace.name}`\n try {\n if (workspace.projectId !== projectId && workspaceName !== workspace.name) {\n spinner.fail(\n `Mismatch between cli config and manifest projectId in workspace ${workspace.name}: ${projectId} !== ${workspace.projectId}`,\n )\n return\n }\n const schema = JSON.parse(\n readFileSync(`${manifestPath}/${workspace.schema}`, 'utf-8'),\n ) as ManifestSchemaType\n await client\n .withConfig({\n dataset: workspace.dataset,\n projectId: workspace.projectId,\n })\n .transaction()\n .createOrReplace({_type: 'sanity.workspace.schema', _id: id, workspace, schema})\n .commit()\n spinner.succeed(`Schema stored for workspace ${workspace.name}`)\n } catch (error) {\n spinner.fail(`Error storing schema for workspace: ${error}`)\n throw error\n } finally {\n output.print(\n JSON.stringify(\n {\n workspace: workspace.name,\n schemaId: id,\n projectId: workspace.projectId,\n dataset: workspace.dataset,\n },\n null,\n 2,\n ),\n )\n }\n }\n // If workspace name is provided, we only need to save one schema\n if (workspaceName) {\n const workspaceToSave = manifest.workspaces.find(\n (workspace) => workspace.name === workspaceName,\n )\n if (!workspaceToSave) {\n output.error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`)\n return new Error(\n `Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`,\n )\n }\n await saveSchema(workspaceToSave)\n return undefined\n }\n await Promise.all(\n manifest.workspaces.map(async (workspace): Promise<void> => {\n await saveSchema(workspace)\n }),\n )\n return undefined\n } catch (err) {\n output.error(err)\n if (flags['schema-required']) {\n throw err\n }\n return err\n }\n}\n"],"names":["storeManifestSchemas","args","context","flags","extOptions","workspaceName","workspace","idPrefix","output","workDir","apiClient","defaultOutputDir","resolve","join","outputDir","defaultStaticPath","staticPath","path","manifestPath","process","cwd","client","requireUser","requireProject","withConfig","apiVersion","projectId","config","manifest","JSON","parse","readFileSync","error","saveSchema","spinner","start","id","name","fail","schema","dataset","transaction","createOrReplace","_type","_id","commit","succeed","print","stringify","schemaId","workspaceToSave","workspaces","find","Error","Promise","all","map","err"],"mappings":";;;;;;AAkB8BA,eAAAA,qBAC5BC,MACAC,SAC4B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side-schemas.24+1696463708",
|
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.72.2-server-side-schemas.
|
163
|
+
"@sanity/cli": "3.72.2-server-side-schemas.24+1696463708",
|
164
164
|
"@sanity/client": "^6.27.2",
|
165
165
|
"@sanity/color": "^3.0.0",
|
166
166
|
"@sanity/comlink": "^3.0.1",
|
167
|
-
"@sanity/diff": "3.72.2-server-side-schemas.
|
167
|
+
"@sanity/diff": "3.72.2-server-side-schemas.24+1696463708",
|
168
168
|
"@sanity/diff-match-patch": "^3.1.1",
|
169
169
|
"@sanity/eventsource": "^5.0.0",
|
170
170
|
"@sanity/export": "^3.42.2",
|
@@ -173,15 +173,15 @@
|
|
173
173
|
"@sanity/import": "^3.37.9",
|
174
174
|
"@sanity/insert-menu": "1.0.20",
|
175
175
|
"@sanity/logos": "^2.1.13",
|
176
|
-
"@sanity/migrate": "3.72.2-server-side-schemas.
|
177
|
-
"@sanity/mutator": "3.72.2-server-side-schemas.
|
176
|
+
"@sanity/migrate": "3.72.2-server-side-schemas.24+1696463708",
|
177
|
+
"@sanity/mutator": "3.72.2-server-side-schemas.24+1696463708",
|
178
178
|
"@sanity/presentation-comlink": "^1.0.4",
|
179
179
|
"@sanity/preview-url-secret": "^2.1.4",
|
180
|
-
"@sanity/schema": "3.72.2-server-side-schemas.
|
180
|
+
"@sanity/schema": "3.72.2-server-side-schemas.24+1696463708",
|
181
181
|
"@sanity/telemetry": "^0.7.7",
|
182
|
-
"@sanity/types": "3.72.2-server-side-schemas.
|
182
|
+
"@sanity/types": "3.72.2-server-side-schemas.24+1696463708",
|
183
183
|
"@sanity/ui": "^2.11.7",
|
184
|
-
"@sanity/util": "3.72.2-server-side-schemas.
|
184
|
+
"@sanity/util": "3.72.2-server-side-schemas.24+1696463708",
|
185
185
|
"@sanity/uuid": "^3.0.2",
|
186
186
|
"@sentry/react": "^8.33.0",
|
187
187
|
"@tanstack/react-table": "^8.16.0",
|
@@ -280,7 +280,7 @@
|
|
280
280
|
"@repo/dev-aliases": "3.72.1",
|
281
281
|
"@repo/package.config": "3.72.1",
|
282
282
|
"@repo/test-config": "3.72.1",
|
283
|
-
"@sanity/codegen": "3.72.2-server-side-schemas.
|
283
|
+
"@sanity/codegen": "3.72.2-server-side-schemas.24+1696463708",
|
284
284
|
"@sanity/generate-help-url": "^3.0.0",
|
285
285
|
"@sanity/pkg-utils": "6.13.4",
|
286
286
|
"@sanity/tsdoc": "1.0.169",
|
@@ -324,5 +324,5 @@
|
|
324
324
|
"engines": {
|
325
325
|
"node": ">=18"
|
326
326
|
},
|
327
|
-
"gitHead": "
|
327
|
+
"gitHead": "1696463708d56265882916836e6bb062c6c022c0"
|
328
328
|
}
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
export interface StoreManifestSchemasFlags {
|
13
13
|
'path'?: string
|
14
14
|
'workspace'?: string
|
15
|
-
'
|
15
|
+
'id-prefix'?: string
|
16
16
|
'schema-required'?: boolean
|
17
17
|
}
|
18
18
|
|
@@ -22,7 +22,7 @@ export default async function storeManifestSchemas(
|
|
22
22
|
): Promise<Error | undefined> {
|
23
23
|
const flags = args.extOptions
|
24
24
|
const workspaceName = flags.workspace
|
25
|
-
const
|
25
|
+
const idPrefix = flags['id-prefix']
|
26
26
|
const {output, workDir, apiClient} = context
|
27
27
|
|
28
28
|
const defaultOutputDir = resolve(join(workDir, 'dist'))
|
@@ -41,17 +41,22 @@ export default async function storeManifestSchemas(
|
|
41
41
|
|
42
42
|
const projectId = client.config().projectId
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
let manifest: CreateManifest
|
45
|
+
|
46
|
+
try {
|
47
|
+
manifest = JSON.parse(readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'))
|
48
|
+
} catch (error) {
|
49
|
+
output.error(`Manifest not found at ${manifestPath}/create-manifest.json`)
|
50
|
+
throw error
|
51
|
+
}
|
47
52
|
|
48
53
|
const saveSchema = async (workspace: ManifestWorkspaceFile) => {
|
49
54
|
const spinner = output.spinner({}).start('Storing schemas')
|
50
|
-
const id =
|
55
|
+
const id = `${idPrefix || 'sanity.workspace.schema'}.${workspace.name}`
|
51
56
|
try {
|
52
57
|
if (workspace.projectId !== projectId && workspaceName !== workspace.name) {
|
53
58
|
spinner.fail(
|
54
|
-
`
|
59
|
+
`Mismatch between cli config and manifest projectId in workspace ${workspace.name}: ${projectId} !== ${workspace.projectId}`,
|
55
60
|
)
|
56
61
|
return
|
57
62
|
}
|
@@ -66,28 +71,44 @@ export default async function storeManifestSchemas(
|
|
66
71
|
.transaction()
|
67
72
|
.createOrReplace({_type: 'sanity.workspace.schema', _id: id, workspace, schema})
|
68
73
|
.commit()
|
69
|
-
spinner.succeed(
|
70
|
-
`Schema stored for workspace ${workspace.name} (shcemaId: ${id}, projectId: ${projectId}, dataset: ${workspace.dataset})`,
|
71
|
-
)
|
74
|
+
spinner.succeed(`Schema stored for workspace ${workspace.name}`)
|
72
75
|
} catch (error) {
|
73
|
-
spinner.fail(`Error storing schema for workspace
|
76
|
+
spinner.fail(`Error storing schema for workspace: ${error}`)
|
77
|
+
throw error
|
78
|
+
} finally {
|
79
|
+
output.print(
|
80
|
+
JSON.stringify(
|
81
|
+
{
|
82
|
+
workspace: workspace.name,
|
83
|
+
schemaId: id,
|
84
|
+
projectId: workspace.projectId,
|
85
|
+
dataset: workspace.dataset,
|
86
|
+
},
|
87
|
+
null,
|
88
|
+
2,
|
89
|
+
),
|
90
|
+
)
|
74
91
|
}
|
75
92
|
}
|
76
|
-
|
93
|
+
// If workspace name is provided, we only need to save one schema
|
77
94
|
if (workspaceName) {
|
78
|
-
const
|
79
|
-
|
80
|
-
|
81
|
-
|
95
|
+
const workspaceToSave = manifest.workspaces.find(
|
96
|
+
(workspace) => workspace.name === workspaceName,
|
97
|
+
)
|
98
|
+
if (!workspaceToSave) {
|
82
99
|
output.error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`)
|
100
|
+
return new Error(
|
101
|
+
`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`,
|
102
|
+
)
|
83
103
|
}
|
84
|
-
|
85
|
-
|
86
|
-
manifest.workspaces.map(async (workspace): Promise<void> => {
|
87
|
-
await saveSchema(workspace)
|
88
|
-
}),
|
89
|
-
)
|
104
|
+
await saveSchema(workspaceToSave)
|
105
|
+
return undefined
|
90
106
|
}
|
107
|
+
await Promise.all(
|
108
|
+
manifest.workspaces.map(async (workspace): Promise<void> => {
|
109
|
+
await saveSchema(workspace)
|
110
|
+
}),
|
111
|
+
)
|
91
112
|
return undefined
|
92
113
|
} catch (err) {
|
93
114
|
output.error(err)
|
@@ -10,7 +10,7 @@ const helpText = `
|
|
10
10
|
Options:
|
11
11
|
--workspace The name of the workspace to fetch the stored schema for
|
12
12
|
--path If you are not using the default static file path, you can specify it here.
|
13
|
-
--
|
13
|
+
--id-prefix you can specify a custom id prefix for the stored schemas. Useful if you want to store the schema in a different path than the default one.
|
14
14
|
|
15
15
|
Examples
|
16
16
|
# if no options are provided all workspace schemas will be stored
|