@sanity/sdk-react 3.8.0 → 3.9.0-next.20261006164105
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0-next.20261006164105",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK React toolkit for Content OS",
|
|
6
6
|
"keywords": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@module-federation/runtime": "^2.9.2",
|
|
46
46
|
"@sanity/client": "^8.9.0",
|
|
47
47
|
"@sanity/message-protocol": "^0.24.0",
|
|
48
|
-
"@sanity/sdk": "3.
|
|
48
|
+
"@sanity/sdk": "3.9.0-next.20261006164105",
|
|
49
49
|
"@sanity/types": "^6.17.0",
|
|
50
50
|
"react-compiler-runtime": "^1.0.0",
|
|
51
51
|
"react-error-boundary": "^6.1.6",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"groq": "^6.15.0",
|
|
73
73
|
"groq-js": "^2.0.0",
|
|
74
74
|
"jsdom": "^30.1.2",
|
|
75
|
-
"oxfmt": "^0.
|
|
75
|
+
"oxfmt": "^0.72.0",
|
|
76
76
|
"react": "^19.3.0",
|
|
77
77
|
"react-dom": "^19.3.0",
|
|
78
78
|
"rolldown": "^1.2.12",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {createDocumentHandle} from '@sanity/sdk'
|
|
2
|
+
import {expectTypeOf, test} from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {useDocument} from './useDocument'
|
|
5
|
+
|
|
6
|
+
// End-to-end check that the resource-keyed lookup reaches the hook. The resolver reads
|
|
7
|
+
// `SanitySchemasByResource`; this asserts `useDocument` passes the handle's project and
|
|
8
|
+
// dataset through to it.
|
|
9
|
+
//
|
|
10
|
+
// Only covers the form where the literals are written at the call site. A handle built from
|
|
11
|
+
// a selected resource, or arriving as a `DocumentHandle<'post'>` prop, still carries `string`
|
|
12
|
+
// and resolves to nothing. That is the propagation work, tracked separately.
|
|
13
|
+
|
|
14
|
+
type HookPost = {
|
|
15
|
+
_id: string
|
|
16
|
+
_type: 'post'
|
|
17
|
+
_createdAt: string
|
|
18
|
+
_updatedAt: string
|
|
19
|
+
_rev: string
|
|
20
|
+
title: string
|
|
21
|
+
}
|
|
22
|
+
interface ProductionPost extends Omit<HookPost, 'title'> {
|
|
23
|
+
title: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Registered the way generated files do: as globals, which the interfaces `@sanity/client`
|
|
27
|
+
// exports extend. Every file in this package's type-check program sees these registrations, not
|
|
28
|
+
// only this test, so their keys must stay unique across the package's tests.
|
|
29
|
+
declare global {
|
|
30
|
+
interface SanitySchemasByResource {
|
|
31
|
+
'hook1.test': HookPost
|
|
32
|
+
'hook2.production': ProductionPost
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const testHandle = createDocumentHandle({
|
|
37
|
+
projectId: 'hook1',
|
|
38
|
+
dataset: 'test',
|
|
39
|
+
documentId: 'a',
|
|
40
|
+
documentType: 'post',
|
|
41
|
+
})
|
|
42
|
+
const productionHandle = createDocumentHandle({
|
|
43
|
+
projectId: 'hook2',
|
|
44
|
+
dataset: 'production',
|
|
45
|
+
documentId: 'a',
|
|
46
|
+
documentType: 'post',
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('useDocument resolves the document type for each handle resource', () => {
|
|
50
|
+
expectTypeOf(useDocument(testHandle).data).toEqualTypeOf<HookPost | null>()
|
|
51
|
+
expectTypeOf(useDocument(productionHandle).data).toEqualTypeOf<ProductionPost | null>()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('useDocument preserves the resource when selecting a field', () => {
|
|
55
|
+
expectTypeOf(useDocument({...testHandle, path: 'title'}).data).toEqualTypeOf<string | undefined>()
|
|
56
|
+
expectTypeOf(useDocument({...productionHandle, path: 'title'}).data).toEqualTypeOf<
|
|
57
|
+
number | undefined
|
|
58
|
+
>()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('explicit resource generics require a matching handle', () => {
|
|
62
|
+
useDocument<'title', 'post', 'test', 'hook1'>({...testHandle, path: 'title'})
|
|
63
|
+
// @ts-expect-error The handle belongs to a different project and dataset.
|
|
64
|
+
useDocument<'title', 'post', 'test', 'hook1'>({...productionHandle, path: 'title'})
|
|
65
|
+
})
|
|
@@ -61,7 +61,7 @@ interface UseDocument {
|
|
|
61
61
|
TDataset extends string = string,
|
|
62
62
|
TProjectId extends string = string,
|
|
63
63
|
>(
|
|
64
|
-
options: UseDocumentOptions<TPath, TDocumentType>,
|
|
64
|
+
options: UseDocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
|
|
65
65
|
): {
|
|
66
66
|
data: JsonMatch<ResolveDocument<TDocumentType, `${TProjectId}.${TDataset}`>, TPath> | undefined
|
|
67
67
|
}
|
|
@@ -139,7 +139,7 @@ interface UseDocument {
|
|
|
139
139
|
TDataset extends string = string,
|
|
140
140
|
TProjectId extends string = string,
|
|
141
141
|
>(
|
|
142
|
-
options: UseDocumentOptions<TPath, TDocumentType>,
|
|
142
|
+
options: UseDocumentOptions<TPath, TDocumentType, TDataset, TProjectId>,
|
|
143
143
|
): TPath extends string
|
|
144
144
|
? {
|
|
145
145
|
data:
|