@sanity/cli 8.26.0 → 8.28.0
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/README.md +1534 -411
- package/dist/actions/context/commandTable.js +215 -0
- package/dist/actions/context/commandTable.js.map +1 -0
- package/dist/actions/context/contextCommand.js +246 -0
- package/dist/actions/context/contextCommand.js.map +1 -0
- package/dist/actions/context/contextSpec.js +18 -0
- package/dist/actions/context/contextSpec.js.map +1 -0
- package/dist/actions/context/distillContextOperations.js +335 -0
- package/dist/actions/context/distillContextOperations.js.map +1 -0
- package/dist/actions/context/mcpEndpoint.js +165 -0
- package/dist/actions/context/mcpEndpoint.js.map +1 -0
- package/dist/actions/context/operationInput.js +226 -0
- package/dist/actions/context/operationInput.js.map +1 -0
- package/dist/actions/context/operationTypes.js +3 -0
- package/dist/actions/context/operationTypes.js.map +1 -0
- package/dist/actions/context/removedCommands.js +26 -0
- package/dist/actions/context/removedCommands.js.map +1 -0
- package/dist/actions/context/renderOperationResult.js +72 -0
- package/dist/actions/context/renderOperationResult.js.map +1 -0
- package/dist/actions/context/resolveOrganizationId.js +8 -1
- package/dist/actions/context/resolveOrganizationId.js.map +1 -1
- package/dist/actions/context/sourceFile.js +31 -0
- package/dist/actions/context/sourceFile.js.map +1 -0
- package/dist/actions/context/syncOutput.js +17 -0
- package/dist/actions/context/syncOutput.js.map +1 -0
- package/dist/actions/context/table.js +13 -0
- package/dist/actions/context/table.js.map +1 -0
- package/dist/actions/context/waitForJob.js.map +1 -1
- package/dist/actions/context/waitForSourceSync.js +48 -0
- package/dist/actions/context/waitForSourceSync.js.map +1 -0
- package/dist/actions/context/watchJob.js.map +1 -1
- package/dist/actions/context/watchSourceSync.js +40 -0
- package/dist/actions/context/watchSourceSync.js.map +1 -0
- package/dist/commands/context/build.js +19 -81
- package/dist/commands/context/build.js.map +1 -1
- package/dist/commands/context/create.js +3 -104
- package/dist/commands/context/create.js.map +1 -1
- package/dist/commands/context/delete.js +3 -73
- package/dist/commands/context/delete.js.map +1 -1
- package/dist/commands/context/documents/content.js +117 -0
- package/dist/commands/context/documents/content.js.map +1 -0
- package/dist/commands/context/documents/delete.js +5 -0
- package/dist/commands/context/documents/delete.js.map +1 -0
- package/dist/commands/context/documents/edit.js +5 -0
- package/dist/commands/context/documents/edit.js.map +1 -0
- package/dist/commands/context/documents/get.js +5 -0
- package/dist/commands/context/documents/get.js.map +1 -0
- package/dist/commands/context/documents/list.js +5 -0
- package/dist/commands/context/documents/list.js.map +1 -0
- package/dist/commands/context/entries/list.js +2 -2
- package/dist/commands/context/entries/list.js.map +1 -1
- package/dist/commands/context/entries/rebuild.js +3 -93
- package/dist/commands/context/entries/rebuild.js.map +1 -1
- package/dist/commands/context/get.js +3 -88
- package/dist/commands/context/get.js.map +1 -1
- package/dist/commands/context/instructions/create.js +5 -0
- package/dist/commands/context/instructions/create.js.map +1 -0
- package/dist/commands/context/instructions/delete.js +5 -0
- package/dist/commands/context/instructions/delete.js.map +1 -0
- package/dist/commands/context/instructions/edit.js +5 -0
- package/dist/commands/context/instructions/edit.js.map +1 -0
- package/dist/commands/context/issues/apply.js +3 -84
- package/dist/commands/context/issues/apply.js.map +1 -1
- package/dist/commands/context/issues/dismiss.js +3 -50
- package/dist/commands/context/issues/dismiss.js.map +1 -1
- package/dist/commands/context/issues/list.js +0 -5
- package/dist/commands/context/issues/list.js.map +1 -1
- package/dist/commands/context/issues/reopen.js +3 -51
- package/dist/commands/context/issues/reopen.js.map +1 -1
- package/dist/commands/context/issues/resolve.js +23 -92
- package/dist/commands/context/issues/resolve.js.map +1 -1
- package/dist/commands/context/jobs/get.js +3 -88
- package/dist/commands/context/jobs/get.js.map +1 -1
- package/dist/commands/context/list.js +3 -103
- package/dist/commands/context/list.js.map +1 -1
- package/dist/commands/context/mcp/create.js +152 -0
- package/dist/commands/context/mcp/create.js.map +1 -0
- package/dist/commands/context/mcp/delete.js +82 -0
- package/dist/commands/context/mcp/delete.js.map +1 -0
- package/dist/commands/context/mcp/get.js +42 -0
- package/dist/commands/context/mcp/get.js.map +1 -0
- package/dist/commands/context/mcp/initial-context.js +5 -0
- package/dist/commands/context/mcp/initial-context.js.map +1 -0
- package/dist/commands/context/mcp/list.js +87 -0
- package/dist/commands/context/mcp/list.js.map +1 -0
- package/dist/commands/context/mcp/status.js +98 -0
- package/dist/commands/context/mcp/status.js.map +1 -0
- package/dist/commands/context/mcp/update.js +225 -0
- package/dist/commands/context/mcp/update.js.map +1 -0
- package/dist/commands/context/query.js +6 -14
- package/dist/commands/context/query.js.map +1 -1
- package/dist/commands/context/sources/create.js +175 -0
- package/dist/commands/context/sources/create.js.map +1 -0
- package/dist/commands/context/sources/delete.js +5 -0
- package/dist/commands/context/sources/delete.js.map +1 -0
- package/dist/commands/context/sources/edit.js +29 -0
- package/dist/commands/context/sources/edit.js.map +1 -0
- package/dist/commands/context/sources/get.js +5 -0
- package/dist/commands/context/sources/get.js.map +1 -0
- package/dist/commands/context/sources/list.js +5 -0
- package/dist/commands/context/sources/list.js.map +1 -0
- package/dist/commands/context/sources/sync.js +5 -0
- package/dist/commands/context/sources/sync.js.map +1 -0
- package/dist/commands/context/sources/syncs/confirm.js +5 -0
- package/dist/commands/context/sources/syncs/confirm.js.map +1 -0
- package/dist/commands/context/sources/syncs/discard.js +5 -0
- package/dist/commands/context/sources/syncs/discard.js.map +1 -0
- package/dist/commands/context/sources/syncs/get.js +5 -0
- package/dist/commands/context/sources/syncs/get.js.map +1 -0
- package/dist/commands/context/sources/syncs/list.js +5 -0
- package/dist/commands/context/sources/syncs/list.js.map +1 -0
- package/dist/commands/context/sources/upload.js +63 -0
- package/dist/commands/context/sources/upload.js.map +1 -0
- package/dist/commands/context/sync.js +5 -0
- package/dist/commands/context/sync.js.map +1 -0
- package/dist/commands/context/update.js +3 -136
- package/dist/commands/context/update.js.map +1 -1
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js +47 -26
- package/dist/exports/invokeSanityCli/commandPolicies/mcpPolicy.js.map +1 -1
- package/dist/generated/apiRoutes.js +28 -0
- package/dist/generated/apiRoutes.js.map +1 -1
- package/dist/generated/contextOperations.js +1116 -0
- package/dist/generated/contextOperations.js.map +1 -0
- package/dist/hooks/commandNotFound/topicAliases.js +8 -2
- package/dist/hooks/commandNotFound/topicAliases.js.map +1 -1
- package/dist/prompts/promptForText.js +12 -0
- package/dist/prompts/promptForText.js.map +1 -0
- package/dist/services/context.js +276 -202
- package/dist/services/context.js.map +1 -1
- package/dist/util/sharedFlags.js.map +1 -1
- package/dist/util/telemetry/cliCommandIdentity.js +16 -18
- package/dist/util/telemetry/cliCommandIdentity.js.map +1 -1
- package/oclif.config.js +1 -1
- package/oclif.manifest.json +4854 -2834
- package/package.json +20 -19
- package/templates/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/app-quickstart/AGENTS.md +49 -0
- package/templates/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/app-sanity-ui/AGENTS.md +49 -0
- package/templates/shared/dashboard/app-quickstart/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/shared/dashboard/app-quickstart/AGENTS.md +49 -0
- package/templates/shared/dashboard/app-sanity-ui/.claude/skills/sanity-app-sdk/SKILL.md +49 -0
- package/templates/shared/dashboard/app-sanity-ui/AGENTS.md +49 -0
- package/dist/commands/context/imports/create.js +0 -270
- package/dist/commands/context/imports/create.js.map +0 -1
- package/dist/commands/context/imports/delete.js +0 -73
- package/dist/commands/context/imports/delete.js.map +0 -1
- package/dist/commands/context/imports/download.js +0 -60
- package/dist/commands/context/imports/download.js.map +0 -1
- package/dist/commands/context/imports/get.js +0 -88
- package/dist/commands/context/imports/get.js.map +0 -1
- package/dist/commands/context/imports/list.js +0 -100
- package/dist/commands/context/imports/list.js.map +0 -1
- package/dist/commands/context/refresh.js +0 -46
- package/dist/commands/context/refresh.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.28.0",
|
|
4
4
|
"description": "Sanity CLI tool for managing Sanity projects and organizations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -62,27 +62,27 @@
|
|
|
62
62
|
"@oclif/core": "^4.11.14",
|
|
63
63
|
"@oclif/plugin-help": "^6.2.53",
|
|
64
64
|
"@oclif/plugin-not-found": "^3.2.88",
|
|
65
|
-
"@sanity/blueprints": "^0.
|
|
66
|
-
"@sanity/cli-build": "^7.1.
|
|
65
|
+
"@sanity/blueprints": "^0.33.0",
|
|
66
|
+
"@sanity/cli-build": "^7.1.1",
|
|
67
67
|
"@sanity/cli-core": "^3.14.1",
|
|
68
|
-
"@sanity/client": "^8.
|
|
69
|
-
"@sanity/codegen": "^8.
|
|
68
|
+
"@sanity/client": "^8.15.0",
|
|
69
|
+
"@sanity/codegen": "^8.3.0",
|
|
70
70
|
"@sanity/descriptors": "^1.3.0",
|
|
71
71
|
"@sanity/export": "^7.1.0",
|
|
72
72
|
"@sanity/generate-help-url": "^4.0.0",
|
|
73
73
|
"@sanity/id-utils": "^1.1.0",
|
|
74
74
|
"@sanity/import": "^7.1.0",
|
|
75
75
|
"@sanity/migrate": "^8.0.5",
|
|
76
|
-
"@sanity/runtime-cli": "^17.
|
|
77
|
-
"@sanity/schema": "^6.
|
|
78
|
-
"@sanity/schema-descriptor-utils": "^1.
|
|
76
|
+
"@sanity/runtime-cli": "^17.21.0",
|
|
77
|
+
"@sanity/schema": "^6.22.0",
|
|
78
|
+
"@sanity/schema-descriptor-utils": "^1.4.0",
|
|
79
79
|
"@sanity/telemetry": "^1.1.0",
|
|
80
80
|
"@sanity/template-validator": "^3.1.1",
|
|
81
|
-
"@sanity/types": "^6.
|
|
82
|
-
"@sanity/workbench-cli": "^2.15.
|
|
81
|
+
"@sanity/types": "^6.22.0",
|
|
82
|
+
"@sanity/workbench-cli": "^2.15.1",
|
|
83
83
|
"@sanity/worker-channels": "^2.0.0",
|
|
84
|
-
"@sanity/workflow-cli": "0.
|
|
85
|
-
"@sanity/workflow-engine": "0.
|
|
84
|
+
"@sanity/workflow-cli": "^0.37.0",
|
|
85
|
+
"@sanity/workflow-engine": "^0.37.0",
|
|
86
86
|
"@vercel/frameworks": "3.29.0",
|
|
87
87
|
"chokidar": "^5.0.0",
|
|
88
88
|
"console-table-printer": "^2.15.0",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"execa": "^10.0.1",
|
|
91
91
|
"form-data": "^4.0.5",
|
|
92
92
|
"get-latest-version": "^6.0.1",
|
|
93
|
-
"groq-js": "^2.0.
|
|
93
|
+
"groq-js": "^2.0.1",
|
|
94
94
|
"gunzip-maybe": "^1.4.2",
|
|
95
95
|
"import-meta-resolve": "^4.2.0",
|
|
96
96
|
"is-installed-globally": "^1.0.0",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"tar-stream": "^3.2.0",
|
|
117
117
|
"tinyglobby": "^0.2.17",
|
|
118
118
|
"valibot": "^1.4.2",
|
|
119
|
-
"vite": "^8.3.
|
|
119
|
+
"vite": "^8.3.6",
|
|
120
120
|
"which": "^6.0.1",
|
|
121
121
|
"wrap-ansi": "^9.0.2",
|
|
122
122
|
"yaml": "^2.9.0",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"@oxc-project/types": "0.152.0",
|
|
128
128
|
"@repo/package.config": "0.0.1",
|
|
129
129
|
"@repo/tsconfig": "3.70.0",
|
|
130
|
-
"@sanity/cli-test": "24.0.
|
|
130
|
+
"@sanity/cli-test": "24.0.2",
|
|
131
131
|
"@sanity/eslint-config-cli": "1.1.3",
|
|
132
132
|
"@sanity/pkg-utils": "^12.3.4",
|
|
133
133
|
"@swc/cli": "^0.8.1",
|
|
@@ -140,20 +140,20 @@
|
|
|
140
140
|
"@types/semver": "^7.7.1",
|
|
141
141
|
"@types/tar-stream": "^3.1.4",
|
|
142
142
|
"@types/which": "^3.0.4",
|
|
143
|
-
"@vitest/coverage-istanbul": "^
|
|
143
|
+
"@vitest/coverage-istanbul": "^5.1.0",
|
|
144
144
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
145
145
|
"eslint": "^10.7.0",
|
|
146
146
|
"get-it": "^9.5.4",
|
|
147
147
|
"jsdom": "^29.1.1",
|
|
148
148
|
"nock": "^14.0.15",
|
|
149
149
|
"oclif": "^4.23.27",
|
|
150
|
-
"oxc-transform-react": "^0.
|
|
150
|
+
"oxc-transform-react": "^0.156.0",
|
|
151
151
|
"publint": "^0.3.21",
|
|
152
152
|
"rimraf": "^6.0.1",
|
|
153
|
-
"sanity": "^6.
|
|
153
|
+
"sanity": "^6.22.0",
|
|
154
154
|
"tsx": "^4.23.12",
|
|
155
155
|
"typescript": "^6.0.3",
|
|
156
|
-
"vitest": "^
|
|
156
|
+
"vitest": "^5.1.0"
|
|
157
157
|
},
|
|
158
158
|
"peerDependencies": {
|
|
159
159
|
"babel-plugin-react-compiler": "*",
|
|
@@ -178,6 +178,7 @@
|
|
|
178
178
|
"check:topic-aliases": "tsx scripts/check-topic-aliases.ts",
|
|
179
179
|
"check:types": "tsc --noEmit",
|
|
180
180
|
"generate:api-routes": "tsx scripts/generate-api-routes.ts",
|
|
181
|
+
"generate:context-commands": "tsx scripts/generate-context-commands.ts && oxfmt src/commands/context",
|
|
181
182
|
"lint": "eslint .",
|
|
182
183
|
"manifest:generate": "oclif manifest",
|
|
183
184
|
"manifest:remove": "rimraf oclif.manifest.json",
|
|
@@ -5,6 +5,55 @@ description: Build features with the Sanity App SDK (@sanity/sdk-react). Use whe
|
|
|
5
5
|
|
|
6
6
|
# Sanity App SDK
|
|
7
7
|
|
|
8
|
+
## Set up TypeGen before writing components
|
|
9
|
+
|
|
10
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
11
|
+
|
|
12
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
13
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
17
|
+
|
|
18
|
+
export const resources = {
|
|
19
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
20
|
+
} as const satisfies Record<string, DocumentResource>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {resources} from './src/resources'
|
|
27
|
+
|
|
28
|
+
export default defineCliConfig({
|
|
29
|
+
// ...existing app config
|
|
30
|
+
typegen: {
|
|
31
|
+
resources: [
|
|
32
|
+
{
|
|
33
|
+
...resources.production,
|
|
34
|
+
schema: './schema.production.json',
|
|
35
|
+
generates: './src/sanity.types.production.ts',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
43
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
47
|
+
|
|
48
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
49
|
+
|
|
50
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
51
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
52
|
+
// data is typed from the generated file
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
56
|
+
|
|
8
57
|
## Get the maintained guide first
|
|
9
58
|
|
|
10
59
|
If the Sanity MCP server is configured, call its `get_sanity_rules` tool with the `app-sdk` rule before writing SDK code. That rule is maintained by Sanity, is more detailed, and supersedes the notes below. The notes below are a fallback for when MCP is not available.
|
|
@@ -11,6 +11,55 @@ A React application built with the Sanity App SDK (`@sanity/sdk-react`). It is n
|
|
|
11
11
|
- `src/App.tsx`: entry point. The `SanityApp` component takes a `config` array with `projectId` and `dataset`. All SDK hooks must be used inside `SanityApp`.
|
|
12
12
|
- `sanity.cli.ts`: CLI config with the organization ID and app entry path.
|
|
13
13
|
|
|
14
|
+
## Set up TypeGen before writing components
|
|
15
|
+
|
|
16
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
17
|
+
|
|
18
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
19
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
23
|
+
|
|
24
|
+
export const resources = {
|
|
25
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
26
|
+
} as const satisfies Record<string, DocumentResource>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {resources} from './src/resources'
|
|
33
|
+
|
|
34
|
+
export default defineCliConfig({
|
|
35
|
+
// ...existing app config
|
|
36
|
+
typegen: {
|
|
37
|
+
resources: [
|
|
38
|
+
{
|
|
39
|
+
...resources.production,
|
|
40
|
+
schema: './schema.production.json',
|
|
41
|
+
generates: './src/sanity.types.production.ts',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
49
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
53
|
+
|
|
54
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
55
|
+
|
|
56
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
57
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
58
|
+
// data is typed from the generated file
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
62
|
+
|
|
14
63
|
## Commands
|
|
15
64
|
|
|
16
65
|
- `npm run dev`: starts the dev server on port 3333, but the app only renders inside the Sanity Dashboard. The CLI prints a Dashboard URL to open. Viewing it requires a signed-in Sanity account, so a human must complete authentication in the browser.
|
|
@@ -5,6 +5,55 @@ description: Build features with the Sanity App SDK (@sanity/sdk-react) and Sani
|
|
|
5
5
|
|
|
6
6
|
# Sanity App SDK
|
|
7
7
|
|
|
8
|
+
## Set up TypeGen before writing components
|
|
9
|
+
|
|
10
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
11
|
+
|
|
12
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
13
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
17
|
+
|
|
18
|
+
export const resources = {
|
|
19
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
20
|
+
} as const satisfies Record<string, DocumentResource>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {resources} from './src/resources'
|
|
27
|
+
|
|
28
|
+
export default defineCliConfig({
|
|
29
|
+
// ...existing app config
|
|
30
|
+
typegen: {
|
|
31
|
+
resources: [
|
|
32
|
+
{
|
|
33
|
+
...resources.production,
|
|
34
|
+
schema: './schema.production.json',
|
|
35
|
+
generates: './src/sanity.types.production.ts',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
43
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
47
|
+
|
|
48
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
49
|
+
|
|
50
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
51
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
52
|
+
// data is typed from the generated file
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
56
|
+
|
|
8
57
|
## Get the maintained guide first
|
|
9
58
|
|
|
10
59
|
If the Sanity MCP server is configured, call its `get_sanity_rules` tool with the `app-sdk` rule before writing SDK code. That rule is maintained by Sanity, is more detailed, and supersedes the notes below. The notes below are a fallback for when MCP is not available.
|
|
@@ -12,6 +12,55 @@ A React application built with the Sanity App SDK (`@sanity/sdk-react`) and Sani
|
|
|
12
12
|
- `src/SanityUI.tsx`: wraps the app in Sanity UI's `ThemeProvider` with a theme from `buildTheme()`. Sanity UI components must render inside this provider.
|
|
13
13
|
- `sanity.cli.ts`: CLI config with the organization ID and app entry path.
|
|
14
14
|
|
|
15
|
+
## Set up TypeGen before writing components
|
|
16
|
+
|
|
17
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
18
|
+
|
|
19
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
20
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
24
|
+
|
|
25
|
+
export const resources = {
|
|
26
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
27
|
+
} as const satisfies Record<string, DocumentResource>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {resources} from './src/resources'
|
|
34
|
+
|
|
35
|
+
export default defineCliConfig({
|
|
36
|
+
// ...existing app config
|
|
37
|
+
typegen: {
|
|
38
|
+
resources: [
|
|
39
|
+
{
|
|
40
|
+
...resources.production,
|
|
41
|
+
schema: './schema.production.json',
|
|
42
|
+
generates: './src/sanity.types.production.ts',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
50
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
54
|
+
|
|
55
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
56
|
+
|
|
57
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
58
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
59
|
+
// data is typed from the generated file
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
63
|
+
|
|
15
64
|
## Commands
|
|
16
65
|
|
|
17
66
|
- `npm run dev`: starts the dev server on port 3333, but the app only renders inside the Sanity Dashboard. The CLI prints a Dashboard URL to open. Viewing it requires a signed-in Sanity account, so a human must complete authentication in the browser.
|
|
@@ -5,6 +5,55 @@ description: Build features with the Sanity App SDK (@sanity/sdk-react). Use whe
|
|
|
5
5
|
|
|
6
6
|
# Sanity App SDK
|
|
7
7
|
|
|
8
|
+
## Set up TypeGen before writing components
|
|
9
|
+
|
|
10
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
11
|
+
|
|
12
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
13
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
17
|
+
|
|
18
|
+
export const resources = {
|
|
19
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
20
|
+
} as const satisfies Record<string, DocumentResource>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {resources} from './src/resources'
|
|
27
|
+
|
|
28
|
+
export default defineCliConfig({
|
|
29
|
+
// ...existing app config
|
|
30
|
+
typegen: {
|
|
31
|
+
resources: [
|
|
32
|
+
{
|
|
33
|
+
...resources.production,
|
|
34
|
+
schema: './schema.production.json',
|
|
35
|
+
generates: './src/sanity.types.production.ts',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
43
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
47
|
+
|
|
48
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
49
|
+
|
|
50
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
51
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
52
|
+
// data is typed from the generated file
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
56
|
+
|
|
8
57
|
## Get the maintained guide first
|
|
9
58
|
|
|
10
59
|
If the Sanity MCP server is configured, call its `get_sanity_rules` tool with the `app-sdk` rule before writing SDK code. That rule is maintained by Sanity, is more detailed, and supersedes the notes below. The notes below are a fallback for when MCP is not available.
|
|
@@ -13,6 +13,55 @@ The app is set up for the Sanity Dashboard beta: `sanity.cli.ts` declares it wit
|
|
|
13
13
|
- `src/App.tsx`: entry point. The `SanityApp` component takes a `config` array with `projectId` and `dataset`. All SDK hooks must be used inside `SanityApp`.
|
|
14
14
|
- `sanity.cli.ts`: CLI config. `app` is `defineApplication({title, slug, organizationId, entry})`. `slug` is the app's unique address in the organization, used to create the app on its first deploy: lowercase letters, numbers and hyphens, starting with a letter.
|
|
15
15
|
|
|
16
|
+
## Set up TypeGen before writing components
|
|
17
|
+
|
|
18
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
19
|
+
|
|
20
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
21
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
25
|
+
|
|
26
|
+
export const resources = {
|
|
27
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
28
|
+
} as const satisfies Record<string, DocumentResource>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {resources} from './src/resources'
|
|
35
|
+
|
|
36
|
+
export default defineCliConfig({
|
|
37
|
+
// ...existing app config
|
|
38
|
+
typegen: {
|
|
39
|
+
resources: [
|
|
40
|
+
{
|
|
41
|
+
...resources.production,
|
|
42
|
+
schema: './schema.production.json',
|
|
43
|
+
generates: './src/sanity.types.production.ts',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
51
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
55
|
+
|
|
56
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
57
|
+
|
|
58
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
59
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
60
|
+
// data is typed from the generated file
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
64
|
+
|
|
16
65
|
## Commands
|
|
17
66
|
|
|
18
67
|
- `npm run dev`: starts a local Sanity Dashboard on port 3333 and serves the app on the next port (3334), loaded into that Dashboard. The CLI prints a link that opens the app in the local Dashboard. The app only renders inside the Dashboard, and viewing it requires a signed-in Sanity account, so a human must complete authentication in the browser.
|
|
@@ -5,6 +5,55 @@ description: Build features with the Sanity App SDK (@sanity/sdk-react) and Sani
|
|
|
5
5
|
|
|
6
6
|
# Sanity App SDK
|
|
7
7
|
|
|
8
|
+
## Set up TypeGen before writing components
|
|
9
|
+
|
|
10
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
11
|
+
|
|
12
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
13
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
17
|
+
|
|
18
|
+
export const resources = {
|
|
19
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
20
|
+
} as const satisfies Record<string, DocumentResource>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import {resources} from './src/resources'
|
|
27
|
+
|
|
28
|
+
export default defineCliConfig({
|
|
29
|
+
// ...existing app config
|
|
30
|
+
typegen: {
|
|
31
|
+
resources: [
|
|
32
|
+
{
|
|
33
|
+
...resources.production,
|
|
34
|
+
schema: './schema.production.json',
|
|
35
|
+
generates: './src/sanity.types.production.ts',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
43
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
47
|
+
|
|
48
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
49
|
+
|
|
50
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
51
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
52
|
+
// data is typed from the generated file
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
56
|
+
|
|
8
57
|
## Get the maintained guide first
|
|
9
58
|
|
|
10
59
|
If the Sanity MCP server is configured, call its `get_sanity_rules` tool with the `app-sdk` rule before writing SDK code. That rule is maintained by Sanity, is more detailed, and supersedes the notes below. The notes below are a fallback for when MCP is not available.
|
|
@@ -14,6 +14,55 @@ The app is set up for the Sanity Dashboard beta: `sanity.cli.ts` declares it wit
|
|
|
14
14
|
- `src/SanityUI.tsx`: wraps the app in Sanity UI's `ThemeProvider` with a theme from `buildTheme()`. Sanity UI components must render inside this provider.
|
|
15
15
|
- `sanity.cli.ts`: CLI config. `app` is `defineApplication({title, slug, organizationId, entry})`. `slug` is the app's unique address in the organization, used to create the app on its first deploy: lowercase letters, numbers and hyphens, starting with a letter.
|
|
16
16
|
|
|
17
|
+
## Set up TypeGen before writing components
|
|
18
|
+
|
|
19
|
+
Set up Sanity TypeGen before you write components that read content. SDK hooks then infer document, projection and query result types from the project and dataset, so do not hand-write those types or pass them as type parameters. This workflow is in beta and needs `@sanity/cli` 8.16.0 or later. Check with `npx sanity --version`.
|
|
20
|
+
|
|
21
|
+
1. Get a schema file for each dataset the app reads. In the Studio that defines the schema, run `npx sanity schema extract --path schema.production.json` and copy the file into this app's root. If you can't reach the Studio, ask the developer for the file. If you must continue without it, extract one from a temporary Studio config that matches the schema the developer described, and tell the developer to replace it with the real extract, because types from a stand-in schema can be wrong.
|
|
22
|
+
2. Declare the datasets in `src/resources.ts`. Use the same object for the `SanityApp` config in `src/App.tsx` and in every hook call. `as const` keeps the IDs as literal types, which inference needs. The CLI loads this file in Node, so it must not use browser globals.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import type {DocumentResource} from '@sanity/sdk-react'
|
|
26
|
+
|
|
27
|
+
export const resources = {
|
|
28
|
+
production: {projectId: 'your-project-id', dataset: 'production'},
|
|
29
|
+
} as const satisfies Record<string, DocumentResource>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
3. Add `typegen.resources` to `sanity.cli.ts`, next to the existing `app` config. Each entry writes one types file for one dataset:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import {resources} from './src/resources'
|
|
36
|
+
|
|
37
|
+
export default defineCliConfig({
|
|
38
|
+
// ...existing app config
|
|
39
|
+
typegen: {
|
|
40
|
+
resources: [
|
|
41
|
+
{
|
|
42
|
+
...resources.production,
|
|
43
|
+
schema: './schema.production.json',
|
|
44
|
+
generates: './src/sanity.types.production.ts',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
4. Add `"typegen": "sanity typegen generate"` to the `package.json` scripts and run `npm run typegen`. Run it again after changing a schema, query or projection. `npm run dev` does not generate these types. While developing, run `npx sanity typegen generate --watch` (`@sanity/cli` 8.22.0 or later) alongside it.
|
|
52
|
+
5. Define queries with `defineQuery` from `groq` (`npm install groq`) and projections with `defineProjection` from `@sanity/sdk-react`, each assigned to a variable. TypeGen only generates types for those. Then call hooks without type parameters:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
export const bookRowProjection = defineProjection('book', '{title, "authorName": author->name}')
|
|
56
|
+
|
|
57
|
+
const {data: handles} = useDocuments({...resources.production, documentType: 'book'})
|
|
58
|
+
|
|
59
|
+
// in a child component receiving one handle (typed DocumentHandle<'book'>):
|
|
60
|
+
const {data} = useDocumentProjection({...handle, projection: bookRowProjection})
|
|
61
|
+
// data is typed from the generated file
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Guide: https://www.sanity.io/docs/app-sdk/sdk-typegen
|
|
65
|
+
|
|
17
66
|
## Commands
|
|
18
67
|
|
|
19
68
|
- `npm run dev`: starts a local Sanity Dashboard on port 3333 and serves the app on the next port (3334), loaded into that Dashboard. The CLI prints a link that opens the app in the local Dashboard. The app only renders inside the Dashboard, and viewing it requires a signed-in Sanity account, so a human must complete authentication in the browser.
|