@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.
Files changed (73) hide show
  1. package/dist/_chunks-dts/utils.d.ts +295 -69
  2. package/dist/_chunks-es/_internal.js +3 -14
  3. package/dist/_chunks-es/_internal.js.map +1 -1
  4. package/dist/_chunks-es/createGroqSearchFilter.js +129 -59
  5. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
  6. package/dist/_chunks-es/version.js +1 -1
  7. package/dist/_exports/_internal.d.ts +16 -2
  8. package/dist/_exports/_internal.js +3 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +275 -149
  11. package/dist/index.js.map +1 -1
  12. package/package.json +11 -15
  13. package/src/_exports/_internal.ts +1 -0
  14. package/src/_exports/index.ts +33 -2
  15. package/src/agent/agentActions.ts +21 -25
  16. package/src/client/clientStore.test.ts +24 -60
  17. package/src/client/clientStore.ts +49 -56
  18. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  19. package/src/comlink/node/actions/getOrCreateNode.test.ts +5 -2
  20. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  21. package/src/comlink/node/actions/releaseNode.test.ts +3 -3
  22. package/src/config/sanityConfig.ts +72 -13
  23. package/src/document/applyDocumentActions.test.ts +7 -7
  24. package/src/document/applyDocumentActions.ts +5 -5
  25. package/src/document/documentStore.test.ts +68 -62
  26. package/src/document/documentStore.ts +33 -38
  27. package/src/document/processActions.ts +2 -2
  28. package/src/document/reducers.ts +4 -4
  29. package/src/document/sharedListener.ts +5 -7
  30. package/src/organization/organization.test-d.ts +102 -0
  31. package/src/organization/organization.test.ts +138 -0
  32. package/src/organization/organization.ts +166 -0
  33. package/src/organizations/organizations.test-d.ts +77 -0
  34. package/src/organizations/organizations.test.ts +150 -0
  35. package/src/organizations/organizations.ts +132 -0
  36. package/src/presence/bifurTransport.test.ts +46 -6
  37. package/src/presence/bifurTransport.ts +13 -1
  38. package/src/presence/presenceStore.test.ts +101 -5
  39. package/src/presence/presenceStore.ts +96 -24
  40. package/src/preview/getPreviewState.ts +1 -1
  41. package/src/preview/previewProjectionUtils.test.ts +4 -4
  42. package/src/preview/previewProjectionUtils.ts +6 -7
  43. package/src/preview/resolvePreview.ts +5 -1
  44. package/src/project/project.test-d.ts +93 -0
  45. package/src/project/project.test.ts +108 -10
  46. package/src/project/project.ts +152 -26
  47. package/src/projection/getProjectionState.ts +4 -4
  48. package/src/projection/projectionStore.test.ts +2 -2
  49. package/src/projection/resolveProjection.ts +2 -2
  50. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  51. package/src/projection/subscribeToStateAndFetchBatches.ts +11 -15
  52. package/src/projects/projects.test-d.ts +38 -0
  53. package/src/projects/projects.test.ts +104 -38
  54. package/src/projects/projects.ts +74 -14
  55. package/src/query/queryStore.test.ts +12 -12
  56. package/src/query/queryStore.ts +10 -11
  57. package/src/query/reducers.ts +3 -3
  58. package/src/releases/getPerspectiveState.ts +5 -5
  59. package/src/releases/releasesStore.test.ts +6 -6
  60. package/src/releases/releasesStore.ts +9 -9
  61. package/src/store/createActionBinder.test.ts +31 -31
  62. package/src/store/createActionBinder.ts +43 -38
  63. package/src/store/createSanityInstance.ts +5 -6
  64. package/src/telemetry/devMode.test.ts +8 -0
  65. package/src/telemetry/devMode.ts +10 -9
  66. package/src/telemetry/initTelemetry.test.ts +0 -17
  67. package/src/telemetry/initTelemetry.ts +2 -12
  68. package/src/users/reducers.ts +3 -4
  69. package/src/utils/createFetcherStore.ts +6 -4
  70. package/src/utils/isImportError.test.ts +72 -0
  71. package/src/utils/isImportError.ts +34 -0
  72. package/src/utils/object.test.ts +95 -0
  73. 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
+ }