@notionhq/custom-blocks 0.2.15 → 0.2.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.
Files changed (49) hide show
  1. package/dist/bridge/SandboxBridge.d.ts +7 -8
  2. package/dist/bridge/SandboxBridge.d.ts.map +1 -1
  3. package/dist/bridge/SandboxBridge.js +49 -44
  4. package/dist/bridge/dataSources/query.d.ts +2 -1
  5. package/dist/bridge/dataSources/query.d.ts.map +1 -1
  6. package/dist/bridge/dataSources/query.js +39 -8
  7. package/dist/bridge/dataSources/resolve.d.ts +10 -10
  8. package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
  9. package/dist/bridge/dataSources/resolve.js +17 -5
  10. package/dist/index.d.ts +1 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/protocol/dataSources/dataSource.d.ts +61 -6
  13. package/dist/protocol/dataSources/dataSource.js +35 -6
  14. package/dist/protocol/dataSources/propertySchema.d.ts +2 -0
  15. package/dist/protocol/dataSources/propertySchema.js +7 -0
  16. package/dist/protocol/messages/createPageResult.d.ts +1 -1
  17. package/dist/protocol/messages/getPage.d.ts +1 -1
  18. package/dist/protocol/messages/hostToSandbox.d.ts +10 -4
  19. package/dist/protocol/messages/init.d.ts +5 -2
  20. package/dist/protocol/messages/openPage.d.ts +1 -1
  21. package/dist/protocol/messages/pageChanged.d.ts +5 -2
  22. package/dist/protocol/messages/queryDataSource.d.ts +485 -485
  23. package/dist/protocol/messages/queryDataSource.js +43 -43
  24. package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
  25. package/dist/protocol/messages/sandboxToHost.d.ts +178 -178
  26. package/dist/protocol/messages/updatePageResult.d.ts +1 -1
  27. package/dist/protocol/pages/page.d.ts +5 -2
  28. package/dist/protocol/pages/page.js +15 -9
  29. package/dist/protocol/protocolVersion.d.ts +1 -1
  30. package/dist/protocol/protocolVersion.js +1 -1
  31. package/dist/react/standalonePreview.d.ts.map +1 -1
  32. package/dist/react/standalonePreview.js +5 -1
  33. package/dist/typeUtils.d.ts +10 -0
  34. package/dist/typeUtils.d.ts.map +1 -0
  35. package/dist/typeUtils.js +1 -0
  36. package/dist/types.d.ts +18 -15
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/version.js +1 -1
  39. package/docs/block-location.md +28 -15
  40. package/docs/data-sources.md +60 -35
  41. package/docs/errors.md +17 -1
  42. package/package.json +1 -1
  43. package/src/bridge/SandboxBridge.ts +62 -50
  44. package/src/bridge/dataSources/query.ts +47 -9
  45. package/src/bridge/dataSources/resolve.ts +30 -13
  46. package/src/index.ts +1 -0
  47. package/src/react/standalonePreview.ts +5 -1
  48. package/src/typeUtils.ts +10 -0
  49. package/src/types.ts +22 -16
@@ -60,7 +60,10 @@ import {
60
60
  NOTION_LIGHT_BACKGROUND_BASE,
61
61
  } from "./appearance.js"
62
62
  import { resolveDataSourceQuery } from "./dataSources/query.js"
63
- import { resolveDataSources } from "./dataSources/resolve.js"
63
+ import {
64
+ getDataSourceReadSchemas,
65
+ resolveDataSources,
66
+ } from "./dataSources/resolve.js"
64
67
  import { resolvePropertyWriteMapForDataSource } from "./dataSources/resolveProperty.js"
65
68
  import {
66
69
  type CustomBlockHostState,
@@ -73,8 +76,8 @@ import { PendingRequests } from "./pendingRequests.js"
73
76
  import { globalPrimedResponsesCache } from "./primedResponses.js"
74
77
 
75
78
  /**
76
- * A single entry in the bridge message log. Kept intentionally plain so the log
77
- * is copy-pasteable to a local coding agent without needing extra context.
79
+ * A single entry in the bridge message log. Kept intentionally plain so the log is copy-pasteable
80
+ * to a local coding agent without needing extra context.
78
81
  */
79
82
  export type MessageLogEntry = {
80
83
  timestamp: string
@@ -309,10 +312,9 @@ export class SandboxBridge {
309
312
  this.sendInitResultError(invalidInitPayloadError(parsed.issues))
310
313
  return
311
314
  }
312
- // Loop guard: never NACK a NACK. Excludes both directions —
313
- // `invalidSandboxMessage` is what the host normally sends, but
314
- // a buggy host that echoes our own `invalidHostMessage` back
315
- // would otherwise spin a NACK feedback loop.
315
+ // Loop guard: never NACK a NACK. Excludes both directions — `invalidSandboxMessage` is
316
+ // what the host normally sends, but a buggy host that echoes our own
317
+ // `invalidHostMessage` back would otherwise spin a NACK feedback loop.
316
318
  if (
317
319
  incomingType !== "invalidSandboxMessage" &&
318
320
  incomingType !== "invalidHostMessage"
@@ -327,8 +329,8 @@ export class SandboxBridge {
327
329
  }
328
330
  const message = parsed.output
329
331
 
330
- // If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back
331
- // an `invalidSandboxMessage` NACK with a human-readable `reason`. Log it for developer
332
+ // If the host couldn't parse one of our outbound sandbox-to-host messages, it sends back an
333
+ // `invalidSandboxMessage` NACK with a human-readable `reason`. Log it for developer
332
334
  // visibility and stop. We don't retry as the sandbox can't recover from a host-side parse
333
335
  // failure on its own.
334
336
  if (message.type === "invalidSandboxMessage") {
@@ -339,8 +341,8 @@ export class SandboxBridge {
339
341
  return
340
342
  }
341
343
 
342
- // `init` is the only message valid before initialization. Handle it up
343
- // front so every later case can assume `status === "initialized"`.
344
+ // `init` is the only message valid before initialization. Handle it up front so every later
345
+ // case can assume `status === "initialized"`.
344
346
  if (message.type === "init") {
345
347
  if (message.initializationId !== this.initializationId) {
346
348
  console.warn(
@@ -357,8 +359,8 @@ export class SandboxBridge {
357
359
  return
358
360
  }
359
361
 
360
- // Alias to keep TS's narrowed `InitializedHostState` across the switch
361
- // below. Reading `this.hostState` repeatedly would re-widen it.
362
+ // Alias to keep TS's narrowed `InitializedHostState` across the switch below. Reading
363
+ // `this.hostState` repeatedly would re-widen it.
362
364
  const hostState = this.hostState
363
365
 
364
366
  if (hostState.status !== "initialized") {
@@ -595,10 +597,9 @@ export class SandboxBridge {
595
597
  }
596
598
 
597
599
  /**
598
- * Apply an `init` payload as if it had arrived from the host. Lets callers
599
- * seed the bridge directly (e.g. the React provider's standalone preview
600
- * fallback) without going through `postMessage`. The bridge stays unaware
601
- * of why it's being seeded.
600
+ * Apply an `init` payload as if it had arrived from the host. Lets callers seed the bridge
601
+ * directly (e.g. the React provider's standalone preview fallback) without going through
602
+ * `postMessage`. The bridge stays unaware of why it's being seeded.
602
603
  */
603
604
  setMockState(message: InitMessage) {
604
605
  this.isMockState = true
@@ -648,12 +649,12 @@ export class SandboxBridge {
648
649
  this.isMockState = false
649
650
  }
650
651
  if (message.status === "error") {
651
- // The host couldn't construct block location for this block (most commonly the parent record
652
- // failed to resolve). Surface the failure through the `awaitInit` promise so callers see
653
- // it through `useCustomBlockInit().error` instead of timing out. We also log here
654
- // because not every consumer renders the error UI, and we want the failure visible in
655
- // the browser console either way. We deliberately don't NACK the host or post anything
656
- // back over the bridge since the host has already given up.
652
+ // The host couldn't construct block location for this block (most commonly the parent
653
+ // record failed to resolve). Surface the failure through the `awaitInit` promise so
654
+ // callers see it through `useCustomBlockInit().error` instead of timing out. We also
655
+ // log here because not every consumer renders the error UI, and we want the failure
656
+ // visible in the browser console either way. We deliberately don't NACK the host or
657
+ // post anything back over the bridge since the host has already given up.
657
658
  console.error(
658
659
  `[custom-blocks-sdk] host reported init error (${message.error.code}): ${message.error.message}`,
659
660
  )
@@ -696,9 +697,8 @@ export class SandboxBridge {
696
697
  contrastMode: message.contrastMode,
697
698
  })
698
699
  this.notify()
699
- // Resolve the awaitInit promise once. Subsequent `init` messages
700
- // (the host shouldn't send these, but be tolerant) update state but
701
- // don't re-resolve.
700
+ // Resolve the awaitInit promise once. Subsequent `init` messages (the host shouldn't send
701
+ // these, but be tolerant) update state but don't re-resolve.
702
702
  if (this.resolveInit) {
703
703
  this.resolveInit()
704
704
  this.resolveInit = undefined
@@ -761,18 +761,26 @@ export class SandboxBridge {
761
761
  ? subscriptionState
762
762
  : createEmptyDataSourceQueryState(key)
763
763
  if (dataSource === undefined) {
764
- this.setDataSourceQueryError(subscriptionId, currentState, {
765
- code: "unknown_data_source_key",
766
- message: `Unknown data source key "${key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
767
- isRetryable: false,
764
+ this.setDataSourceQueryError({
765
+ subscriptionId,
766
+ currentState,
767
+ error: {
768
+ code: "unknown_data_source_key",
769
+ message: `Unknown data source key "${key}". Known keys: [${this.hostState.dataSources.map(entry => entry.key).join(", ")}].`,
770
+ isRetryable: false,
771
+ },
768
772
  })
769
773
  return
770
774
  }
771
775
  if (dataSource.collectionPointer === undefined) {
772
- this.setDataSourceQueryError(subscriptionId, currentState, {
773
- code: "unmapped_data_source",
774
- message: `Data source "${key}" has not been mapped to a database yet.`,
775
- isRetryable: false,
776
+ this.setDataSourceQueryError({
777
+ subscriptionId,
778
+ currentState,
779
+ error: {
780
+ code: "unmapped_data_source",
781
+ message: `Data source "${key}" has not been mapped to a database yet.`,
782
+ isRetryable: false,
783
+ },
776
784
  })
777
785
  return
778
786
  }
@@ -783,10 +791,10 @@ export class SandboxBridge {
783
791
  options,
784
792
  })
785
793
  if (resolvedQuery.status === "error") {
786
- this.setDataSourceQueryError(subscriptionId, currentState, {
787
- code: "invalid_data_source_query",
788
- message: resolvedQuery.error,
789
- isRetryable: false,
794
+ this.setDataSourceQueryError({
795
+ subscriptionId,
796
+ currentState,
797
+ error: resolvedQuery.error,
790
798
  })
791
799
  return
792
800
  }
@@ -826,11 +834,15 @@ export class SandboxBridge {
826
834
  this.notify()
827
835
  }
828
836
 
829
- private setDataSourceQueryError(
830
- subscriptionId: string,
831
- currentState: DataSourceQueryState,
832
- error: CustomBlockQueryDataSourceErrorInfo,
833
- ) {
837
+ private setDataSourceQueryError({
838
+ subscriptionId,
839
+ currentState,
840
+ error,
841
+ }: {
842
+ subscriptionId: string
843
+ currentState: DataSourceQueryState
844
+ error: CustomBlockQueryDataSourceErrorInfo
845
+ }) {
834
846
  if (this.hostState.status !== "initialized") {
835
847
  return
836
848
  }
@@ -1043,8 +1055,8 @@ export class SandboxBridge {
1043
1055
 
1044
1056
  /**
1045
1057
  * Translates the public `CreatePageArgs["parent"]` into the bridge-native
1046
- * `CreatePageMessageParent`. The `data_source_key` variant is resolved sandbox-side against
1047
- * the data source mapping the host delivered in `init` / `dataSourcesChanged`.
1058
+ * `CreatePageMessageParent`. The `data_source_key` variant is resolved sandbox-side against the
1059
+ * data source mapping the host delivered in `init` / `dataSourcesChanged`.
1048
1060
  */
1049
1061
  private resolveCreatePageParent(parent: CreatePageArgs["parent"]):
1050
1062
  | {
@@ -1151,11 +1163,11 @@ function syncDocumentAppearance(args: {
1151
1163
  }
1152
1164
 
1153
1165
  /**
1154
- * `postMessage` cloning creates new objects even for bindings that did not change.
1155
- * Preserve their resolved object identity so React effects only run for changed bindings.
1166
+ * `postMessage` cloning creates new objects even for bindings that did not change. Preserve their
1167
+ * resolved object identity so React effects only run for changed bindings.
1156
1168
  *
1157
- * This comparison runs when the host sends an update instead of on every component render.
1158
- * Bindings are validated JSON-like bridge payloads, so serialization is sufficient here.
1169
+ * This comparison runs when the host sends an update instead of on every component render. Bindings
1170
+ * are validated JSON-like bridge payloads, so serialization is sufficient here.
1159
1171
  */
1160
1172
  function reuseDataSourcesForUnchangedBindings(args: {
1161
1173
  previousDataSources: NotionDataSource[]
@@ -1243,7 +1255,7 @@ function resolveMockDataSources(
1243
1255
  collectionPointer: binding.collectionPointer,
1244
1256
  collectionSchema: binding.collectionSchema,
1245
1257
  propertyIdsByKey: { ...(binding.propertyIdsByKey ?? {}) },
1246
- propertySchemasById: binding.collectionSchema?.propertiesById ?? {},
1258
+ propertySchemasById: getDataSourceReadSchemas(binding.collectionSchema),
1247
1259
  }))
1248
1260
  }
1249
1261
 
@@ -14,6 +14,7 @@ import {
14
14
  type ResolvedCustomBlockDataSourcePropertyFilter,
15
15
  type ResolvedCustomBlockDataSourceSort,
16
16
  } from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
17
+ import type { CustomBlockQueryDataSourceErrorInfo } from "@notionhq/custom-blocks-protocol/messages/queryDataSourceResult.js"
17
18
  import * as v from "valibot"
18
19
  import type { UseDataSourceOptions } from "../../types.js"
19
20
  import { unreachable } from "../../utils.js"
@@ -34,7 +35,7 @@ export type ResolvedDataSourceQuery = {
34
35
  }
35
36
 
36
37
  export type ResolveDataSourceQueryResult =
37
- | { status: "error"; error: string }
38
+ | { status: "error"; error: CustomBlockQueryDataSourceErrorInfo }
38
39
  | {
39
40
  status: "ok"
40
41
  dataSource: NotionDataSource
@@ -60,34 +61,63 @@ export function resolveDataSourceQuery(args: {
60
61
  const { dataSources, key, options, warn } = args
61
62
  const resolvedOptions = resolveDataSourceQueryOptions(options)
62
63
  if (resolvedOptions.status === "error") {
63
- return resolvedOptions
64
+ return {
65
+ status: "error",
66
+ error: getInvalidQueryError(resolvedOptions.error),
67
+ }
64
68
  }
65
69
  const queryOptions = resolvedOptions.options
66
70
  const dataSource = dataSources.find(entry => entry.key === key)
67
71
  if (dataSource === undefined) {
68
72
  return {
69
73
  status: "error",
70
- error: `Unknown data source key "${key}". Known keys: [${dataSources.map(entry => entry.key).join(", ")}].`,
74
+ error: {
75
+ code: "unknown_data_source_key",
76
+ message: `Unknown data source key "${key}". Known keys: [${dataSources.map(entry => entry.key).join(", ")}].`,
77
+ // The query key or manifest must change before the query can succeed.
78
+ isRetryable: false,
79
+ },
71
80
  }
72
81
  }
73
82
  if (dataSource.collectionPointer === undefined) {
74
83
  return {
75
84
  status: "error",
76
- error: `Data source "${key}" has not been mapped to a database yet.`,
85
+ error: {
86
+ code: "unmapped_data_source",
87
+ message: `Data source "${key}" has not been mapped to a database yet.`,
88
+ // The host must supply a database binding before the query can succeed.
89
+ isRetryable: false,
90
+ },
91
+ }
92
+ }
93
+
94
+ if (
95
+ (queryOptions?.filter !== undefined ||
96
+ (Array.isArray(queryOptions?.sorts) && queryOptions.sorts.length > 0)) &&
97
+ dataSource.collectionSchema === undefined
98
+ ) {
99
+ return {
100
+ status: "error",
101
+ error: {
102
+ code: "data_source_schema_unavailable",
103
+ message: `You cannot query data source "${key}" with filters or sorts because its schema is unavailable.`,
104
+ // Retrying cannot load the schema. A host binding update must supply it.
105
+ isRetryable: false,
106
+ },
77
107
  }
78
108
  }
79
109
 
80
110
  const limit = resolveDataSourceQueryLimit(queryOptions?.limit, warn)
81
111
  if (limit.status === "error") {
82
- return limit
112
+ return { status: "error", error: getInvalidQueryError(limit.error) }
83
113
  }
84
114
  const filter = resolveFilter(queryOptions?.filter, dataSource)
85
115
  if (filter.status === "error") {
86
- return filter
116
+ return { status: "error", error: getInvalidQueryError(filter.error) }
87
117
  }
88
118
  const sorts = resolveSorts(queryOptions?.sorts, dataSource)
89
119
  if (sorts.status === "error") {
90
- return sorts
120
+ return { status: "error", error: getInvalidQueryError(sorts.error) }
91
121
  }
92
122
 
93
123
  const identity = stableJsonStringify({
@@ -109,6 +139,13 @@ export function resolveDataSourceQuery(args: {
109
139
  }
110
140
  }
111
141
 
142
+ function getInvalidQueryError(
143
+ message: string,
144
+ ): CustomBlockQueryDataSourceErrorInfo {
145
+ // The query, schema, or bindings must change before the query can succeed.
146
+ return { code: "invalid_data_source_query", message, isRetryable: false }
147
+ }
148
+
112
149
  function resolveDataSourceQueryOptions(
113
150
  options: unknown,
114
151
  ):
@@ -610,13 +647,14 @@ function resolvePropertyAddress(
610
647
  }
611
648
  propertyId = value.propertyId
612
649
  }
613
- if (!Object.hasOwn(dataSource.propertySchemasById, propertyId)) {
650
+ const properties = dataSource.collectionSchema?.propertiesById ?? {}
651
+ if (!Object.hasOwn(properties, propertyId)) {
614
652
  return {
615
653
  status: "error",
616
654
  error: `Unknown property ID "${propertyId}" for data source "${dataSource.key}".`,
617
655
  }
618
656
  }
619
- const propertySchema = dataSource.propertySchemasById[propertyId]
657
+ const propertySchema = properties[propertyId]
620
658
  return {
621
659
  status: "ok",
622
660
  propertyId,
@@ -1,29 +1,33 @@
1
1
  import type {
2
+ NotionCollectionSchema,
2
3
  NotionDataSource,
3
4
  NotionDataSourceBindings,
4
5
  } from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
6
+ import {
7
+ NOTION_BUILTIN_PROPERTY_SCHEMAS,
8
+ type NotionPropertySchema,
9
+ } from "@notionhq/custom-blocks-protocol/dataSources/propertySchema.js"
5
10
  import type { CustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest.js"
6
11
 
7
- type ResolveDataSourcesArgs = {
8
- manifest: CustomBlockManifest
9
- dataSourceBindings: NotionDataSourceBindings
10
- }
11
-
12
12
  /**
13
13
  * Builds the public {@link NotionDataSource} list the SDK exposes to consumers.
14
14
  *
15
- * Combines the host-supplied bindings (collection pointers + schemas) with the
16
- * manifest's declared data source keys. The host owns every mapping; the SDK
17
- * validates supplied IDs but never infers omitted bindings.
15
+ * Combines the host-supplied bindings (database pointers + schemas) with the manifest's declared
16
+ * data source keys. The host owns every mapping; the SDK validates supplied IDs but never infers
17
+ * omitted bindings.
18
18
  */
19
- export function resolveDataSources(
20
- args: ResolveDataSourcesArgs,
21
- ): NotionDataSource[] {
19
+ export function resolveDataSources(args: {
20
+ manifest: CustomBlockManifest
21
+ dataSourceBindings: NotionDataSourceBindings
22
+ }): NotionDataSource[] {
22
23
  return Object.entries(args.manifest.dataSources).map(
23
24
  ([key, manifestDataSource]) => {
24
25
  const binding = args.dataSourceBindings[key]
25
- const propertySchemasById =
26
+ const collectionProperties =
26
27
  binding?.collectionSchema?.propertiesById ?? {}
28
+ const propertySchemasById = getDataSourceReadSchemas(
29
+ binding?.collectionSchema,
30
+ )
27
31
 
28
32
  const bindingPropertyIdsByKey = binding?.propertyIdsByKey ?? {}
29
33
  const propertyIdsByKey: Record<string, string | undefined> = {}
@@ -33,7 +37,9 @@ export function resolveDataSources(
33
37
  for (const [propertyKey, manifestProperty] of manifestProperties) {
34
38
  const propertyId = bindingPropertyIdsByKey[propertyKey]
35
39
  const propertySchema =
36
- propertyId === undefined ? undefined : propertySchemasById[propertyId]
40
+ propertyId === undefined
41
+ ? undefined
42
+ : collectionProperties[propertyId]
37
43
  propertyIdsByKey[propertyKey] =
38
44
  propertySchema?.type === manifestProperty.type
39
45
  ? propertyId
@@ -50,3 +56,14 @@ export function resolveDataSources(
50
56
  },
51
57
  )
52
58
  }
59
+
60
+ export function getDataSourceReadSchemas(
61
+ collectionSchema: NotionCollectionSchema | undefined,
62
+ ): Record<string, NotionPropertySchema> {
63
+ // Queries without filters or sorts can return metadata without a database schema. Keep
64
+ // metadata schemas available for reading those values.
65
+ return {
66
+ ...collectionSchema?.propertiesById,
67
+ ...NOTION_BUILTIN_PROPERTY_SCHEMAS,
68
+ }
69
+ }
package/src/index.ts CHANGED
@@ -94,6 +94,7 @@ export type {
94
94
  CustomBlockUpdatePageErrorInfo,
95
95
  } from "@notionhq/custom-blocks-protocol/messages/updatePageResult.js"
96
96
  export type {
97
+ CustomBlockPage,
97
98
  NotionPage,
98
99
  NotionPageCover,
99
100
  NotionPageIcon,
@@ -20,7 +20,11 @@ export function seedStandalonePreviewState() {
20
20
  contrastMode: DEFAULT_CONTRAST_MODE,
21
21
  blockId: previewBlockId,
22
22
  parent: { type: "page_id", page_id: previewPageId },
23
- page: { id: previewPageId, parent: { type: "workspace", workspace: true } },
23
+ page: {
24
+ type: "page",
25
+ id: previewPageId,
26
+ parent: { type: "workspace", workspace: true },
27
+ },
24
28
  manifest: { version: 1, dataSources: {} },
25
29
  dataSources: { bindings: {} },
26
30
  currentUser: {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Returns a union of the keys from every member of `T`. Includes keys that only one union member
3
+ * defines.
4
+ */
5
+ export type UnionKeys<T> = T extends unknown ? keyof T : never
6
+
7
+ /** Allows one union member and prohibits fields from the other members. */
8
+ export type ExclusiveUnion<T, Whole = T> = T extends unknown
9
+ ? T & { [K in Exclude<UnionKeys<Whole>, keyof T>]?: never }
10
+ : never
package/src/types.ts CHANGED
@@ -51,6 +51,8 @@ import type {
51
51
  NotionPagePropertyValue,
52
52
  } from "@notionhq/custom-blocks-protocol/pages/page.js"
53
53
 
54
+ import type { ExclusiveUnion } from "./typeUtils.js"
55
+
54
56
  export type { CustomBlockErrorInfo } from "@notionhq/custom-blocks-protocol/errors.js"
55
57
  export type {
56
58
  NotionDataSourceId,
@@ -127,26 +129,28 @@ export type NotionDataSourcePageUpdateArgs = {
127
129
  is_archived?: boolean
128
130
  }
129
131
 
130
- export type NotionDataSourceTextFilterOperator = CustomBlockTextFilterOperator
132
+ export type NotionDataSourceTextFilterOperator =
133
+ ExclusiveUnion<CustomBlockTextFilterOperator>
131
134
  export type NotionDataSourceNumberFilterOperator =
132
- CustomBlockNumberFilterOperator
135
+ ExclusiveUnion<CustomBlockNumberFilterOperator>
133
136
  export type NotionDataSourceCheckboxFilterOperator =
134
- CustomBlockCheckboxFilterOperator
137
+ ExclusiveUnion<CustomBlockCheckboxFilterOperator>
135
138
  export type NotionDataSourceOptionFilterOperator =
136
- CustomBlockOptionFilterOperator
139
+ ExclusiveUnion<CustomBlockOptionFilterOperator>
137
140
  export type NotionDataSourceContainsFilterOperator =
138
- CustomBlockContainsFilterOperator
139
- export type NotionDataSourceDateFilterOperator = CustomBlockDateFilterOperator
141
+ ExclusiveUnion<CustomBlockContainsFilterOperator>
142
+ export type NotionDataSourceDateFilterOperator =
143
+ ExclusiveUnion<CustomBlockDateFilterOperator>
140
144
  export type NotionDataSourcePersonFilterValue = CustomBlockPersonFilterValue
141
145
  export type NotionDataSourcePeopleFilterOperator =
142
- CustomBlockPeopleFilterOperator
146
+ ExclusiveUnion<CustomBlockPeopleFilterOperator>
143
147
 
144
148
  export type NotionDataSourcePropertyAddress =
145
149
  | { key: string; propertyId?: never }
146
150
  | { propertyId: string; key?: never }
147
151
 
148
152
  export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
149
- (
153
+ ExclusiveUnion<
150
154
  | { title: NotionDataSourceTextFilterOperator }
151
155
  | { rich_text: NotionDataSourceTextFilterOperator }
152
156
  | { url: NotionDataSourceTextFilterOperator }
@@ -159,15 +163,15 @@ export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
159
163
  | { status: NotionDataSourceOptionFilterOperator }
160
164
  | { date: NotionDataSourceDateFilterOperator }
161
165
  | { people: NotionDataSourcePeopleFilterOperator }
162
- )
166
+ >
163
167
 
164
168
  export type NotionDataSourceSort = NotionDataSourcePropertyAddress & {
165
169
  direction: "ascending" | "descending"
166
170
  }
167
171
 
168
- export type NotionDataSourceFilter =
169
- | NotionDataSourcePropertyFilter
170
- | { and: NotionDataSourcePropertyFilter[] }
172
+ export type NotionDataSourceFilter = ExclusiveUnion<
173
+ NotionDataSourcePropertyFilter | { and: NotionDataSourcePropertyFilter[] }
174
+ >
171
175
 
172
176
  /**
173
177
  * Latest live snapshot of a data source query.
@@ -180,13 +184,15 @@ export type NotionDataSourceFilter =
180
184
  export type DataSourceSnapshot = {
181
185
  items: NotionDataSourcePage[]
182
186
  /**
183
- * Collection/data source schema for the bound Notion data source, including raw property
184
- * schemas. Undefined when the semantic data source key has not been bound.
187
+ * Contains only properties in the database schema.
188
+ * Use this map to resolve property bindings and validate filter and sort references.
189
+ * Undefined when the host does not provide a schema.
185
190
  */
186
191
  collectionSchema?: NotionCollectionSchema
187
192
  /**
188
- * Per-property schemas keyed by raw property ID, including the four synthetic built-ins
189
- * (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
193
+ * Contains database properties and four synthetic metadata fields.
194
+ * Use this map to describe values in query snapshots.
195
+ * Synthetic entries do not establish filter or sort support.
190
196
  */
191
197
  propertySchemasById: { [propertyId: string]: NotionPropertySchema }
192
198
  /**