@sanity/sdk 2.9.0 → 2.11.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/dist/_chunks-dts/utils.d.ts +295 -69
- package/dist/_chunks-es/_internal.js +3 -14
- package/dist/_chunks-es/_internal.js.map +1 -1
- package/dist/_chunks-es/createGroqSearchFilter.js +129 -59
- package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
- package/dist/_chunks-es/version.js +1 -1
- package/dist/_exports/_internal.d.ts +16 -2
- package/dist/_exports/_internal.js +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +275 -149
- package/dist/index.js.map +1 -1
- package/package.json +11 -15
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/index.ts +33 -2
- package/src/agent/agentActions.ts +21 -25
- package/src/client/clientStore.test.ts +24 -60
- package/src/client/clientStore.ts +49 -56
- package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
- package/src/comlink/node/actions/getOrCreateNode.test.ts +5 -2
- package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
- package/src/comlink/node/actions/releaseNode.test.ts +3 -3
- package/src/config/sanityConfig.ts +72 -13
- package/src/document/applyDocumentActions.test.ts +7 -7
- package/src/document/applyDocumentActions.ts +5 -5
- package/src/document/documentStore.test.ts +68 -62
- package/src/document/documentStore.ts +33 -38
- package/src/document/processActions.ts +2 -2
- package/src/document/reducers.ts +4 -4
- package/src/document/sharedListener.ts +5 -7
- package/src/organization/organization.test-d.ts +102 -0
- package/src/organization/organization.test.ts +138 -0
- package/src/organization/organization.ts +166 -0
- package/src/organizations/organizations.test-d.ts +77 -0
- package/src/organizations/organizations.test.ts +150 -0
- package/src/organizations/organizations.ts +132 -0
- package/src/presence/bifurTransport.test.ts +46 -6
- package/src/presence/bifurTransport.ts +13 -1
- package/src/presence/presenceStore.test.ts +101 -5
- package/src/presence/presenceStore.ts +96 -24
- package/src/preview/getPreviewState.ts +1 -1
- package/src/preview/previewProjectionUtils.test.ts +4 -4
- package/src/preview/previewProjectionUtils.ts +6 -7
- package/src/preview/resolvePreview.ts +5 -1
- package/src/project/project.test-d.ts +93 -0
- package/src/project/project.test.ts +108 -10
- package/src/project/project.ts +152 -26
- package/src/projection/getProjectionState.ts +4 -4
- package/src/projection/projectionStore.test.ts +2 -2
- package/src/projection/resolveProjection.ts +2 -2
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
- package/src/projection/subscribeToStateAndFetchBatches.ts +11 -15
- package/src/projects/projects.test-d.ts +38 -0
- package/src/projects/projects.test.ts +104 -38
- package/src/projects/projects.ts +74 -14
- package/src/query/queryStore.test.ts +12 -12
- package/src/query/queryStore.ts +10 -11
- package/src/query/reducers.ts +3 -3
- package/src/releases/getPerspectiveState.ts +5 -5
- package/src/releases/releasesStore.test.ts +6 -6
- package/src/releases/releasesStore.ts +9 -9
- package/src/store/createActionBinder.test.ts +31 -31
- package/src/store/createActionBinder.ts +43 -38
- package/src/store/createSanityInstance.ts +5 -6
- package/src/telemetry/devMode.test.ts +8 -0
- package/src/telemetry/devMode.ts +10 -9
- package/src/telemetry/initTelemetry.test.ts +0 -17
- package/src/telemetry/initTelemetry.ts +2 -12
- package/src/users/reducers.ts +3 -4
- package/src/utils/createFetcherStore.ts +6 -4
- package/src/utils/isImportError.test.ts +72 -0
- package/src/utils/isImportError.ts +34 -0
- package/src/utils/object.test.ts +95 -0
- package/src/utils/object.ts +142 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true when the input is a non-null object.
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export function isObject(value: unknown): value is object {
|
|
7
|
+
return typeof value === 'object' && value !== null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const hasOwn = (value: object, key: PropertyKey) => Object.prototype.hasOwnProperty.call(value, key)
|
|
11
|
+
|
|
12
|
+
const isPlainObject = (value: unknown): value is Record<string, unknown> => {
|
|
13
|
+
if (!isObject(value)) return false
|
|
14
|
+
|
|
15
|
+
const prototype = Object.getPrototypeOf(value)
|
|
16
|
+
return prototype === Object.prototype || prototype === null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a shallow copy without the provided property.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function omitProperty<T extends object, K extends keyof T>(
|
|
25
|
+
value: T | null | undefined,
|
|
26
|
+
key: K,
|
|
27
|
+
): Omit<T, K> {
|
|
28
|
+
if (!value) return {} as Omit<T, K>
|
|
29
|
+
|
|
30
|
+
const {[key]: _omitted, ...rest} = value
|
|
31
|
+
return rest
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a shallow copy containing only the provided properties.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export function pickProperties<T extends object, K extends keyof T>(
|
|
40
|
+
value: T,
|
|
41
|
+
keys: readonly K[],
|
|
42
|
+
): Pick<T, K> {
|
|
43
|
+
const result = {} as Pick<T, K>
|
|
44
|
+
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
if (hasOwn(value, key)) {
|
|
47
|
+
result[key] = value[key]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const areSetsEqual = (left: Set<unknown>, right: Set<unknown>): boolean => {
|
|
55
|
+
if (left.size !== right.size) return false
|
|
56
|
+
|
|
57
|
+
const unmatched = [...right]
|
|
58
|
+
|
|
59
|
+
outer: for (const leftValue of left) {
|
|
60
|
+
for (let index = 0; index < unmatched.length; index++) {
|
|
61
|
+
if (isDeepEqual(leftValue, unmatched[index])) {
|
|
62
|
+
unmatched.splice(index, 1)
|
|
63
|
+
continue outer
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return unmatched.length === 0
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const areMapsEqual = (left: Map<unknown, unknown>, right: Map<unknown, unknown>): boolean => {
|
|
74
|
+
if (left.size !== right.size) return false
|
|
75
|
+
|
|
76
|
+
const unmatched = [...right.entries()]
|
|
77
|
+
|
|
78
|
+
outer: for (const [leftKey, leftValue] of left) {
|
|
79
|
+
for (let index = 0; index < unmatched.length; index++) {
|
|
80
|
+
const [rightKey, rightValue] = unmatched[index]
|
|
81
|
+
|
|
82
|
+
if (isDeepEqual(leftKey, rightKey) && isDeepEqual(leftValue, rightValue)) {
|
|
83
|
+
unmatched.splice(index, 1)
|
|
84
|
+
continue outer
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return unmatched.length === 0
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Compares values deeply across the plain object, array, map, and set shapes used by the SDK.
|
|
96
|
+
* This helper is intended for acyclic SDK data structures and does not guard against circular
|
|
97
|
+
* references.
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export function isDeepEqual<T>(left: T, right: T): boolean {
|
|
102
|
+
if (Object.is(left, right)) return true
|
|
103
|
+
|
|
104
|
+
if (!isObject(left) || !isObject(right)) return false
|
|
105
|
+
|
|
106
|
+
if (left instanceof Date && right instanceof Date) {
|
|
107
|
+
return left.getTime() === right.getTime()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (left instanceof RegExp && right instanceof RegExp) {
|
|
111
|
+
return left.source === right.source && left.flags === right.flags
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (left instanceof Set && right instanceof Set) {
|
|
115
|
+
return areSetsEqual(left, right)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (left instanceof Map && right instanceof Map) {
|
|
119
|
+
return areMapsEqual(left, right)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
123
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false
|
|
124
|
+
|
|
125
|
+
return left.every((value, index) => isDeepEqual(value, right[index]))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!isPlainObject(left) || !isPlainObject(right)) return false
|
|
129
|
+
|
|
130
|
+
const leftKeys = Object.keys(left)
|
|
131
|
+
const rightKeys = Object.keys(right)
|
|
132
|
+
|
|
133
|
+
if (leftKeys.length !== rightKeys.length) return false
|
|
134
|
+
|
|
135
|
+
for (const key of leftKeys) {
|
|
136
|
+
if (!hasOwn(right, key) || !isDeepEqual(left[key], right[key])) {
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return true
|
|
142
|
+
}
|