sanity 3.72.2-coreui.15 → 3.72.2-server-side-schemas.17
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 +111 -69
- package/lib/_chunks-cjs/_internal.js.map +1 -1
- package/lib/_chunks-cjs/deployAction.js +10 -3
- package/lib/_chunks-cjs/deployAction.js.map +1 -1
- package/lib/_chunks-cjs/fetchSchemaAction.js +18 -0
- package/lib/_chunks-cjs/fetchSchemaAction.js.map +1 -0
- package/lib/_chunks-cjs/runtime.js +2 -6
- package/lib/_chunks-cjs/runtime.js.map +1 -1
- package/lib/_chunks-cjs/storeManifestSchemasAction.js +52 -0
- package/lib/_chunks-cjs/storeManifestSchemasAction.js.map +1 -0
- package/lib/_chunks-cjs/storeSchemaAction.js +7 -0
- package/lib/_chunks-cjs/storeSchemaAction.js.map +1 -0
- 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/deploy/deployAction.ts +14 -2
- package/src/_internal/cli/actions/manifest/storeManifestSchemasAction.ts +88 -0
- package/src/_internal/cli/actions/schema/fetchSchemaAction.ts +36 -0
- package/src/_internal/cli/actions/schema/storeSchemaAction.ts +17 -0
- package/src/_internal/cli/commands/build/buildCommand.ts +2 -0
- package/src/_internal/cli/commands/deploy/deployCommand.ts +1 -0
- package/src/_internal/cli/commands/index.ts +4 -0
- package/src/_internal/cli/commands/schema/fetchSchemaCommand.ts +32 -0
- package/src/_internal/cli/commands/schema/storeSchemaCommand.ts +33 -0
- package/src/_internal/cli/server/renderDocument.tsx +0 -12
- package/src/_internal/cli/server/runtime.ts +9 -12
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "sanity",
|
3
|
-
"version": "3.72.2-
|
3
|
+
"version": "3.72.2-server-side-schemas.17+260ef73ae7",
|
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-
|
163
|
+
"@sanity/cli": "3.72.2-server-side-schemas.17+260ef73ae7",
|
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-
|
167
|
+
"@sanity/diff": "3.72.2-server-side-schemas.17+260ef73ae7",
|
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-
|
177
|
-
"@sanity/mutator": "3.72.2-
|
176
|
+
"@sanity/migrate": "3.72.2-server-side-schemas.17+260ef73ae7",
|
177
|
+
"@sanity/mutator": "3.72.2-server-side-schemas.17+260ef73ae7",
|
178
178
|
"@sanity/presentation-comlink": "^1.0.4",
|
179
179
|
"@sanity/preview-url-secret": "^2.1.4",
|
180
|
-
"@sanity/schema": "3.72.2-
|
180
|
+
"@sanity/schema": "3.72.2-server-side-schemas.17+260ef73ae7",
|
181
181
|
"@sanity/telemetry": "^0.7.7",
|
182
|
-
"@sanity/types": "3.72.2-
|
182
|
+
"@sanity/types": "3.72.2-server-side-schemas.17+260ef73ae7",
|
183
183
|
"@sanity/ui": "^2.11.7",
|
184
|
-
"@sanity/util": "3.72.2-
|
184
|
+
"@sanity/util": "3.72.2-server-side-schemas.17+260ef73ae7",
|
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-
|
283
|
+
"@sanity/codegen": "3.72.2-server-side-schemas.17+260ef73ae7",
|
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": "260ef73ae74e1382911170da3f285ef90607faa5"
|
328
328
|
}
|
@@ -8,6 +8,7 @@ import tar from 'tar-fs'
|
|
8
8
|
import {shouldAutoUpdate} from '../../util/shouldAutoUpdate'
|
9
9
|
import buildSanityStudio, {type BuildSanityStudioCommandFlags} from '../build/buildAction'
|
10
10
|
import {extractManifestSafe} from '../manifest/extractManifestAction'
|
11
|
+
import {storeManifestSchemas} from '../manifest/storeManifestSchemasAction'
|
11
12
|
import {
|
12
13
|
checkDir,
|
13
14
|
createDeployment,
|
@@ -20,7 +21,8 @@ import {
|
|
20
21
|
} from './helpers'
|
21
22
|
|
22
23
|
export interface DeployStudioActionFlags extends BuildSanityStudioCommandFlags {
|
23
|
-
|
24
|
+
'schema-path'?: string
|
25
|
+
'build'?: boolean
|
24
26
|
}
|
25
27
|
|
26
28
|
export default async function deployStudioAction(
|
@@ -113,7 +115,7 @@ export default async function deployStudioAction(
|
|
113
115
|
return
|
114
116
|
}
|
115
117
|
|
116
|
-
await extractManifestSafe(
|
118
|
+
const extractManifestError = await extractManifestSafe(
|
117
119
|
{
|
118
120
|
...buildArgs,
|
119
121
|
extOptions: {},
|
@@ -121,6 +123,16 @@ export default async function deployStudioAction(
|
|
121
123
|
},
|
122
124
|
context,
|
123
125
|
)
|
126
|
+
|
127
|
+
const storeManifestSchemasArgs = {
|
128
|
+
...args,
|
129
|
+
extOptions: {
|
130
|
+
'schema-path': flags['schema-path'],
|
131
|
+
},
|
132
|
+
extraArguments: [],
|
133
|
+
}
|
134
|
+
|
135
|
+
if (!extractManifestError) await storeManifestSchemas(storeManifestSchemasArgs, context)
|
124
136
|
}
|
125
137
|
|
126
138
|
// Ensure that the directory exists, is a directory and seems to have valid content
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import {readFileSync} from 'node:fs'
|
2
|
+
import path from 'node:path'
|
3
|
+
|
4
|
+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
5
|
+
|
6
|
+
import {
|
7
|
+
type CreateManifest,
|
8
|
+
type ManifestSchemaType,
|
9
|
+
type ManifestWorkspaceFile,
|
10
|
+
} from '../../../manifest/manifestTypes'
|
11
|
+
|
12
|
+
export interface StoreManifestSchemasFlags {
|
13
|
+
'schema-path'?: string
|
14
|
+
'workspace-name'?: string
|
15
|
+
}
|
16
|
+
|
17
|
+
export async function storeManifestSchemas(
|
18
|
+
args: CliCommandArguments<StoreManifestSchemasFlags>,
|
19
|
+
context: CliCommandContext,
|
20
|
+
): Promise<void> {
|
21
|
+
const flags = args.extOptions
|
22
|
+
const schemaPath = flags['schema-path']
|
23
|
+
const workspaceName = flags['workspace-name']
|
24
|
+
const {output, workDir, apiClient} = context
|
25
|
+
|
26
|
+
try {
|
27
|
+
const manifestPath = path.resolve(
|
28
|
+
process.cwd(),
|
29
|
+
schemaPath || path.join(workDir, 'dist/static'),
|
30
|
+
)
|
31
|
+
const client = apiClient({
|
32
|
+
requireUser: true,
|
33
|
+
requireProject: true,
|
34
|
+
}).withConfig({apiVersion: 'v2024-08-01'})
|
35
|
+
|
36
|
+
const projectId = client.config().projectId
|
37
|
+
|
38
|
+
const manifest: CreateManifest = JSON.parse(
|
39
|
+
readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'),
|
40
|
+
)
|
41
|
+
|
42
|
+
const saveSchema = async (workspace: ManifestWorkspaceFile) => {
|
43
|
+
const spinner = output.spinner({}).start('Storing schemas')
|
44
|
+
const id = `sanity.workspace.schema.${workspace.name}`
|
45
|
+
try {
|
46
|
+
if (workspace.projectId !== projectId && workspaceName !== workspace.name) {
|
47
|
+
spinner.fail(
|
48
|
+
`Cannot store schema for ${workspace.name} because manifest projectId does not match: ${projectId} !== ${workspace.projectId}`,
|
49
|
+
)
|
50
|
+
return
|
51
|
+
}
|
52
|
+
const schema = JSON.parse(
|
53
|
+
readFileSync(`${manifestPath}/${workspace.schema}`, 'utf-8'),
|
54
|
+
) as ManifestSchemaType
|
55
|
+
await client
|
56
|
+
.withConfig({
|
57
|
+
dataset: workspace.dataset,
|
58
|
+
projectId: workspace.projectId,
|
59
|
+
})
|
60
|
+
.transaction()
|
61
|
+
.createOrReplace({_type: 'sanity.workspace.schema', _id: id, workspace, schema})
|
62
|
+
.commit()
|
63
|
+
spinner.succeed(
|
64
|
+
`Schema stored for workspace ${workspace.name} (shcemaId: ${id}, projectId: ${projectId}, dataset: ${workspace.dataset})`,
|
65
|
+
)
|
66
|
+
} catch (error) {
|
67
|
+
spinner.fail(`Error storing schema for workspace ${workspace.name}: ${error}`)
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
if (workspaceName) {
|
72
|
+
const schemaToSave = manifest.workspaces.find((workspace) => workspace.name === workspaceName)
|
73
|
+
if (schemaToSave) {
|
74
|
+
await saveSchema(schemaToSave)
|
75
|
+
} else {
|
76
|
+
output.error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`)
|
77
|
+
}
|
78
|
+
} else {
|
79
|
+
await Promise.all(
|
80
|
+
manifest.workspaces.map(async (workspace): Promise<void> => {
|
81
|
+
await saveSchema(workspace)
|
82
|
+
}),
|
83
|
+
)
|
84
|
+
}
|
85
|
+
} catch (err) {
|
86
|
+
output.error(err)
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type ManifestSchemaType} from '../../../manifest/manifestTypes'
|
4
|
+
|
5
|
+
export interface FetchSchemaFlags {
|
6
|
+
'schema-id': string
|
7
|
+
'dataset': string
|
8
|
+
}
|
9
|
+
|
10
|
+
export default async function fetchSchemaAction(
|
11
|
+
args: CliCommandArguments<FetchSchemaFlags>,
|
12
|
+
context: CliCommandContext,
|
13
|
+
): Promise<void> {
|
14
|
+
const {apiClient, output} = context
|
15
|
+
const flags = args.extOptions
|
16
|
+
const schemaId = flags['schema-id']
|
17
|
+
const dataset = flags.dataset
|
18
|
+
const spinner = output.spinner({}).start('Fetching schema')
|
19
|
+
const client = apiClient({
|
20
|
+
requireUser: true,
|
21
|
+
requireProject: true,
|
22
|
+
}).withConfig({apiVersion: 'v2024-08-01'})
|
23
|
+
|
24
|
+
const projectId = client.config().projectId
|
25
|
+
|
26
|
+
const schema = await client
|
27
|
+
.withConfig({
|
28
|
+
dataset: dataset,
|
29
|
+
projectId: projectId,
|
30
|
+
})
|
31
|
+
.fetch<ManifestSchemaType>(`*[_type == "sanity.workspace.schema" && _id == "${schemaId}"]`)
|
32
|
+
|
33
|
+
spinner.succeed('Schema fetched')
|
34
|
+
// print schema as json
|
35
|
+
output.success(JSON.stringify(schema, null, 2))
|
36
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {
|
4
|
+
storeManifestSchemas,
|
5
|
+
type StoreManifestSchemasFlags,
|
6
|
+
} from '../manifest/storeManifestSchemasAction'
|
7
|
+
|
8
|
+
export interface StoreSchemaFlags extends StoreManifestSchemasFlags {
|
9
|
+
'workspace-name': string
|
10
|
+
}
|
11
|
+
|
12
|
+
export default async function storeSchemaAction(
|
13
|
+
args: CliCommandArguments<StoreSchemaFlags>,
|
14
|
+
context: CliCommandContext,
|
15
|
+
): Promise<void> {
|
16
|
+
storeManifestSchemas(args, context)
|
17
|
+
}
|
@@ -6,7 +6,9 @@ Options
|
|
6
6
|
--source-maps Enable source maps for built bundles (increases size of bundle)
|
7
7
|
--auto-updates / --no-auto-updates Enable/disable auto updates of studio versions
|
8
8
|
--no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
|
9
|
+
--work
|
9
10
|
-y, --yes Unattended mode, answers "yes" to any "yes/no" prompt and otherwise uses defaults
|
11
|
+
--schema-path If you are storing your schemas in a different path than the default one, you need to specify it here.
|
10
12
|
|
11
13
|
Examples
|
12
14
|
sanity build
|
@@ -10,6 +10,7 @@ const helpText = `
|
|
10
10
|
Options
|
11
11
|
--source-maps Enable source maps for built bundles (increases size of bundle)
|
12
12
|
--auto-updates / --no-auto-updates Enable/disable auto updates of studio versions
|
13
|
+
--schema-path / path to schema folder if custom schema folder is used
|
13
14
|
--no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
|
14
15
|
--no-build Don't build the studio prior to deploy, instead deploying the version currently in \`dist/\`
|
15
16
|
-y, --yes Unattended mode, answers "yes" to any "yes/no" prompt and otherwise uses defaults
|
@@ -47,7 +47,9 @@ import migrationGroup from './migration/migrationGroup'
|
|
47
47
|
import runMigrationCommand from './migration/runMigrationCommand'
|
48
48
|
import previewCommand from './preview/previewCommand'
|
49
49
|
import extractSchemaCommand from './schema/extractSchemaCommand'
|
50
|
+
import fetchSchemaCommand from './schema/fetchSchemaCommand'
|
50
51
|
import schemaGroup from './schema/schemaGroup'
|
52
|
+
import storeSchemaCommand from './schema/storeSchemaCommand'
|
51
53
|
import validateSchemaCommand from './schema/validateSchemaCommand'
|
52
54
|
import startCommand from './start/startCommand'
|
53
55
|
import inviteUserCommand from './users/inviteUserCommand'
|
@@ -105,6 +107,8 @@ const commands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
|
|
105
107
|
validateSchemaCommand,
|
106
108
|
extractSchemaCommand,
|
107
109
|
previewCommand,
|
110
|
+
fetchSchemaCommand,
|
111
|
+
storeSchemaCommand,
|
108
112
|
execCommand,
|
109
113
|
manifestGroup,
|
110
114
|
extractManifestCommand,
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandDefinition} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type FetchSchemaFlags} from '../../actions/schema/fetchSchemaAction'
|
4
|
+
|
5
|
+
const description = 'Extracts a JSON representation of a Sanity schema within a Studio context.'
|
6
|
+
|
7
|
+
const helpText = `
|
8
|
+
**Note**: This command is experimental and subject to change.
|
9
|
+
|
10
|
+
Options
|
11
|
+
--workspace-name The name of the workspace to fetch the stored schema for
|
12
|
+
--dataset The dataset to fetch the schema from
|
13
|
+
|
14
|
+
Examples
|
15
|
+
# Fetch the stored schema for the workspace 'default' in the dataset 'sanity-test'
|
16
|
+
sanity schema fetch --workspaceName default --dataset sanity-test
|
17
|
+
`
|
18
|
+
|
19
|
+
const fetchSchemaCommand = {
|
20
|
+
name: 'fetch',
|
21
|
+
group: 'schema',
|
22
|
+
signature: '',
|
23
|
+
description,
|
24
|
+
helpText,
|
25
|
+
action: async (args, context) => {
|
26
|
+
const mod = await import('../../actions/schema/fetchSchemaAction')
|
27
|
+
|
28
|
+
return mod.default(args as unknown as CliCommandArguments<FetchSchemaFlags>, context)
|
29
|
+
},
|
30
|
+
} satisfies CliCommandDefinition
|
31
|
+
|
32
|
+
export default fetchSchemaCommand
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandDefinition} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type StoreSchemaFlags} from '../../actions/schema/storeSchemaAction'
|
4
|
+
|
5
|
+
const description = ''
|
6
|
+
|
7
|
+
const helpText = `
|
8
|
+
**Note**: This command is experimental and subject to change.
|
9
|
+
|
10
|
+
Required options:
|
11
|
+
--workspace-name The name of the workspace to fetch the stored schema for
|
12
|
+
Optional options:
|
13
|
+
--schema-path If you want to store the schema in a different path than the default one, you can specify it here.
|
14
|
+
|
15
|
+
Examples
|
16
|
+
# Store the schema for the workspace 'default'
|
17
|
+
sanity schema store --workspace-name default
|
18
|
+
`
|
19
|
+
|
20
|
+
const storeSchemaCommand = {
|
21
|
+
name: 'store',
|
22
|
+
group: 'schema',
|
23
|
+
signature: '',
|
24
|
+
description,
|
25
|
+
helpText,
|
26
|
+
action: async (args, context) => {
|
27
|
+
const mod = await import('../../actions/schema/storeSchemaAction')
|
28
|
+
|
29
|
+
return mod.default(args as unknown as CliCommandArguments<StoreSchemaFlags>, context)
|
30
|
+
},
|
31
|
+
} satisfies CliCommandDefinition
|
32
|
+
|
33
|
+
export default storeSchemaCommand
|
@@ -111,18 +111,6 @@ export function decorateIndexWithAutoGeneratedWarning(template: string): string
|
|
111
111
|
return template.replace(/<head/, `\n<!--\n${autoGeneratedWarning}\n-->\n<head`)
|
112
112
|
}
|
113
113
|
|
114
|
-
/**
|
115
|
-
* Decorates the given HTML template with a script
|
116
|
-
* tag that loads the bridge component to communicate
|
117
|
-
* with core-ui.
|
118
|
-
*/
|
119
|
-
export function decorateIndexWithBridgeScript(template: string): string {
|
120
|
-
return template.replace(
|
121
|
-
'</head>',
|
122
|
-
'<script src="https://core.sanity-cdn.com/bridge.js" async type="module"></script>\n</head>',
|
123
|
-
)
|
124
|
-
}
|
125
|
-
|
126
114
|
export function getPossibleDocumentComponentLocations(studioRootPath: string): string[] {
|
127
115
|
return [path.join(studioRootPath, '_document.js'), path.join(studioRootPath, '_document.tsx')]
|
128
116
|
}
|
@@ -7,7 +7,6 @@ import {debug as serverDebug} from './debug'
|
|
7
7
|
import {getEntryModule} from './getEntryModule'
|
8
8
|
import {
|
9
9
|
decorateIndexWithAutoGeneratedWarning,
|
10
|
-
decorateIndexWithBridgeScript,
|
11
10
|
getPossibleDocumentComponentLocations,
|
12
11
|
renderDocument,
|
13
12
|
} from './renderDocument'
|
@@ -45,17 +44,15 @@ export async function writeSanityRuntime({
|
|
45
44
|
|
46
45
|
async function renderAndWriteDocument() {
|
47
46
|
debug('Rendering document template')
|
48
|
-
const indexHtml =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}),
|
58
|
-
),
|
47
|
+
const indexHtml = decorateIndexWithAutoGeneratedWarning(
|
48
|
+
await renderDocument({
|
49
|
+
studioRootPath: cwd,
|
50
|
+
monorepo,
|
51
|
+
props: {
|
52
|
+
entryPath: `/${path.relative(cwd, path.join(runtimeDir, 'app.js'))}`,
|
53
|
+
basePath: basePath || '/',
|
54
|
+
},
|
55
|
+
}),
|
59
56
|
)
|
60
57
|
|
61
58
|
debug('Writing index.html to runtime directory')
|