@notionhq/custom-blocks 0.5.0 → 0.5.1

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseHostToSandboxMessage.d.ts","sourceRoot":"","sources":["../../src/bridge/parseHostToSandboxMessage.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMtD"}
@@ -0,0 +1,47 @@
1
+ import { bridgeDataSourceBindingSchema } from "../protocol/dataSources/bridgeDataSourceBinding.js";
2
+ import { dataSourcePointerValidator } from "../protocol/dataSources/dataSourcePointer.js";
3
+ import { notionDataSourceSchemaValidator } from "../protocol/dataSources/dataSourceSchema.js";
4
+ import { initMessageSchema } from "../protocol/handshake/init.js";
5
+ import { hostToSandboxMessageSchema } from "../protocol/messages/hostToSandbox.js";
6
+ import { readIncomingType } from "../protocol/messages/incomingType.js";
7
+ import * as v from "valibot";
8
+ /**
9
+ * Older hosts such as 0.9.0 send `collectionPointer` and `collectionSchema` during
10
+ * initialization and live updates. Normalize these pre-protocol-11 names to
11
+ * `dataSourcePointer` and `dataSourceSchema` before exposing bindings to SDK consumers.
12
+ * Current fields take precedence when both names are present. Malformed fields and
13
+ * invalid property mappings still fail validation; this compatibility does not add
14
+ * host operations or repair bindings the Notion client cannot read from storage.
15
+ */
16
+ export function parseHostToSandboxMessage(data) {
17
+ const type = readIncomingType(data);
18
+ if (type === "init" || type === "dataSourcesChanged") {
19
+ return v.safeParse(bindingMessageSchema, data);
20
+ }
21
+ return v.safeParse(hostToSandboxMessageSchema, data);
22
+ }
23
+ const bindingSchema = v.pipe(v.object({
24
+ ...bridgeDataSourceBindingSchema.entries,
25
+ collectionPointer: v.optional(dataSourcePointerValidator),
26
+ collectionSchema: v.optional(notionDataSourceSchemaValidator),
27
+ }), v.transform(({ collectionPointer, collectionSchema, ...binding }) => ({
28
+ ...binding,
29
+ dataSourcePointer: binding.dataSourcePointer ?? collectionPointer,
30
+ dataSourceSchema: binding.dataSourceSchema ?? collectionSchema,
31
+ })));
32
+ const dataSourcesSchema = v.object({
33
+ bindings: v.record(v.string(), bindingSchema),
34
+ });
35
+ const bindingMessageSchema = v.variant("type", [
36
+ v.variant("status", [
37
+ v.object({
38
+ ...initMessageSchema.options[0].entries,
39
+ dataSources: dataSourcesSchema,
40
+ }),
41
+ initMessageSchema.options[1],
42
+ ]),
43
+ v.object({
44
+ type: v.literal("dataSourcesChanged"),
45
+ dataSources: dataSourcesSchema,
46
+ }),
47
+ ]);
@@ -9,7 +9,7 @@ import { resolveDataSourceBinding } from "../../protocol/dataSources/resolveData
9
9
  export function resolveDataSources(args) {
10
10
  return Object.entries(args.manifest.dataSources).map(([key, manifestDataSource]) => {
11
11
  const binding = args.dataSourceBindings[key];
12
- const collectionProperties = binding?.dataSourceSchema?.propertiesById ?? {};
12
+ const dataSourceProperties = binding?.dataSourceSchema?.propertiesById ?? {};
13
13
  const resolvedBinding = resolveDataSourceBinding({
14
14
  manifestDataSource,
15
15
  dataSourceSchema: binding?.dataSourceSchema,
@@ -25,7 +25,7 @@ export function resolveDataSources(args) {
25
25
  dataSourcePointer: binding?.dataSourcePointer,
26
26
  dataSourceSchema: binding?.dataSourceSchema,
27
27
  propertyIdsByKey,
28
- propertySchemasById: collectionProperties,
28
+ propertySchemasById: dataSourceProperties,
29
29
  ...(binding?.inaccessible === true && { inaccessible: true }),
30
30
  };
31
31
  });
@@ -4,4 +4,4 @@
4
4
  *
5
5
  * WARNING: Generated during SDK publish. Do not edit in the published package.
6
6
  */
7
- export const CUSTOM_BLOCKS_SDK_VERSION = "0.5.0"
7
+ export const CUSTOM_BLOCKS_SDK_VERSION = "0.5.1"
@@ -546,20 +546,20 @@ Property values can be `null` when empty or unavailable.
546
546
  | `select` | 🟢 Selected option | 🟢 Supported | 🔴 Unavailable |
547
547
  | `multi_select` | 🟢 Selected options | 🟢 Supported | 🔴 Unavailable |
548
548
  | `status` | 🟢 Selected option | 🟢 Supported | 🔴 Unavailable |
549
- | `date` | 🟢 `start` and optional `end` strings | 🟡 Minute precision | 🟢 Supported |
549
+ | `date` | 🟢 `start` and optional `end` strings | 🟢 Supported | 🟢 Supported |
550
550
  | `people` | 🟢 Array of user or group ID objects | 🟢 Supported | 🟢 Supported |
551
- | `files` | 🟢 External links and hosted files | 🔴 Unavailable | 🔴 Unavailable |
552
- | `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
553
551
  | `relation` | 🟢 Array of page ID objects | 🟢 Supported | 🔴 Unavailable |
552
+ | `created_time` | 🟢 Timestamp | 🟢 Supported | 🟢 Supported |
553
+ | `last_edited_time` | 🟢 Timestamp | 🟢 Supported | 🟢 Supported |
554
+ | `created_by` | 🟢 Actor reference | 🟢 Supported | 🟢 Supported |
555
+ | `last_edited_by` | 🟢 Actor reference | 🟢 Supported | 🟢 Supported |
556
+ | `files` | 🟢 External links and hosted files | 🔴 Unavailable | 🔴 Unavailable |
554
557
  | `place` | 🟢 Coordinates and optional place details | 🔴 Unavailable | 🔴 Unavailable |
558
+ | `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
555
559
  | `formula` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
556
560
  | `rollup` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
557
561
  | `button` | 🟡 Button label | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
558
562
  | `verification` | 🟡 Status text | 🔴 Unavailable | 🔴 Unavailable |
559
- | `created_time` | 🟢 Timestamp | 🟢 Supported | 🟢 Supported |
560
- | `last_edited_time` | 🟢 Timestamp | 🟢 Supported | 🟢 Supported |
561
- | `created_by` | 🟢 Actor reference | 🟢 Supported | 🟢 Supported |
562
- | `last_edited_by` | 🟢 Actor reference | 🟢 Supported | 🟢 Supported |
563
563
 
564
564
  ### Notes
565
565
 
@@ -576,8 +576,9 @@ Property values can be `null` when empty or unavailable.
576
576
  - Text values omit formatting, mention tokens, and annotations.
577
577
  - People properties return references with `object: "user"` or `object: "group"` and an `id`. Group
578
578
  IDs use the composite form `groupId|workspaceId`.
579
- - Date filters support comparisons, relative ranges, and start or end dates. They accept seconds and
580
- milliseconds but compare values at minute precision.
579
+ - Date filters support comparisons, relative ranges, and start or end dates.
580
+ - Date, Created time, and Last edited time filters use minute precision. Seconds and milliseconds
581
+ are not preserved.
581
582
  - Select, multi-select, and status query values contain option names and colors when available, and
582
583
  IDs when matched to the schema.
583
584
  - Query results use typed property objects. Narrow each object by its `type` field.
package/docs/pages.md CHANGED
@@ -135,32 +135,32 @@ Property values can be `null` when empty or unavailable.
135
135
  - 🔒 **Read-only:** Notion sets this value. You cannot set it when creating or updating a page.
136
136
  - 🔴 **Unavailable:** The SDK does not support this operation.
137
137
 
138
- | Property type | Read page | Create page | Update page |
139
- | ------------------ | ----------------------------------------- | ------------------- | ------------------- |
140
- | `title` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
141
- | `rich_text` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
142
- | `number` | 🟢 Number | 🟢 Supported | 🟢 Supported |
143
- | `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported |
144
- | `url` | 🟢 String | 🟢 Supported | 🟢 Supported |
145
- | `email` | 🟢 String | 🟢 Supported | 🟢 Supported |
146
- | `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported |
147
- | `select` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
148
- | `multi_select` | 🟢 Selected options | 🟢 Supported | 🟢 Supported |
149
- | `status` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
150
- | `date` | 🟢 `start` and optional `end` strings | 🟡 Minute precision | 🟡 Minute precision |
151
- | `people` | 🟢 Array of user or group ID objects | 🟢 Supported | 🟢 Supported |
152
- | `files` | 🟢 External links and hosted files | 🟡 File URLs only | 🟡 File URLs only |
153
- | `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
154
- | `relation` | 🟢 Array of page ID objects | 🟡 Replaces value | 🟡 Replaces value |
155
- | `place` | 🟢 Coordinates and optional place details | 🟢 Supported | 🟢 Supported |
156
- | `formula` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
157
- | `rollup` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
158
- | `button` | 🟡 Button label | 🔴 Unavailable | 🔴 Unavailable |
159
- | `verification` | 🟡 Status text | 🔴 Unavailable | 🔴 Unavailable |
160
- | `created_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
161
- | `last_edited_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
162
- | `created_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
163
- | `last_edited_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
138
+ | Property type | Read page | Create page | Update page |
139
+ | ------------------ | ----------------------------------------- | ------------------ | ------------------ |
140
+ | `title` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
141
+ | `rich_text` | 🟡 Plain text array | 🟡 Plain text only | 🟡 Plain text only |
142
+ | `number` | 🟢 Number | 🟢 Supported | 🟢 Supported |
143
+ | `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported |
144
+ | `url` | 🟢 String | 🟢 Supported | 🟢 Supported |
145
+ | `email` | 🟢 String | 🟢 Supported | 🟢 Supported |
146
+ | `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported |
147
+ | `select` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
148
+ | `multi_select` | 🟢 Selected options | 🟢 Supported | 🟢 Supported |
149
+ | `status` | 🟢 Selected option | 🟢 Supported | 🟢 Supported |
150
+ | `date` | 🟢 `start` and optional `end` strings | 🟢 Supported | 🟢 Supported |
151
+ | `people` | 🟢 Array of user or group ID objects | 🟢 Supported | 🟢 Supported |
152
+ | `relation` | 🟢 Array of page ID objects | 🟡 Replaces value | 🟡 Replaces value |
153
+ | `place` | 🟢 Coordinates and optional place details | 🟢 Supported | 🟢 Supported |
154
+ | `files` | 🟢 External links and hosted files | 🔴 Unavailable | 🔴 Unavailable |
155
+ | `unique_id` | 🟡 Formatted ID | 🔴 Unavailable | 🔴 Unavailable |
156
+ | `formula` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
157
+ | `rollup` | 🟡 Stored text | 🔴 Unavailable | 🔴 Unavailable |
158
+ | `button` | 🟡 Button label | 🔴 Unavailable | 🔴 Unavailable |
159
+ | `verification` | 🟡 Status text | 🔴 Unavailable | 🔴 Unavailable |
160
+ | `created_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
161
+ | `last_edited_time` | 🟢 Timestamp | 🔒 Read-only | 🔒 Read-only |
162
+ | `created_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
163
+ | `last_edited_by` | 🟢 Actor reference | 🔒 Read-only | 🔒 Read-only |
164
164
 
165
165
  ### Notes
166
166
 
@@ -178,12 +178,10 @@ Property values can be `null` when empty or unavailable.
178
178
  - Select, multi-select, and status writes select existing options by ID or name. They do not create
179
179
  or edit schema options. If you supply both an ID and a name, the host uses the ID. The host
180
180
  rejects unknown IDs.
181
- - Date-time writes preserve hours and minutes but discard seconds and milliseconds.
181
+ - Date-time writes support minute precision. Seconds and milliseconds are not preserved.
182
182
  - Title and rich text use text arrays, but reads and writes preserve only plain text. Reads and
183
183
  writes do not preserve formatting, links, mentions, or equations as structured rich text.
184
- - Files reads return external links and signed URLs for Notion-hosted files, including create and
185
- update responses. File writes accept `external` URLs and existing `file` URLs and store them as
186
- links. Upload references (`file_upload`) are unsupported.
184
+ - Files reads return external links and signed URLs for Notion-hosted files.
187
185
  - Relation writes replace the value and reject `has_more: true`.
188
186
  - Top-level `created_time` and `last_edited_time` do not depend on the data source schema.
189
187
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/custom-blocks",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -3,12 +3,11 @@ import type { BridgeDataSourceBindings } from "@notionhq/custom-blocks-protocol/
3
3
  import type { QueryDataSourceResultMessage } from "@notionhq/custom-blocks-protocol/dataSources/messages/queryDataSource.js"
4
4
  import type { InitMessage } from "@notionhq/custom-blocks-protocol/handshake/init.js"
5
5
  import type { CustomBlockInitResultErrorInfo } from "@notionhq/custom-blocks-protocol/handshake/initResult.js"
6
- import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
7
6
  import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
8
7
  import type { InvalidHostMessage } from "@notionhq/custom-blocks-protocol/messages/invalidHostMessage.js"
9
8
  import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/messages/sandboxToHost.js"
10
9
  import { readRequestId } from "@notionhq/custom-blocks-protocol/utils/readRequestId.js"
11
- import * as v from "valibot"
10
+ import type * as v from "valibot"
12
11
  import { applyContextMessage } from "../context/applyContextMessage.js"
13
12
  import type { CustomBlockHostState } from "../context/hostState.js"
14
13
  import { syncDocumentAppearance } from "../context/syncDocumentAppearance.js"
@@ -19,6 +18,7 @@ import { notifyListener } from "../utils/notifyListener.js"
19
18
  import { unreachable } from "../utils/unreachable.js"
20
19
  import { SandboxInitialization } from "./initialization/SandboxInitialization.js"
21
20
  import type { MessageInterceptor } from "./messageInterceptor.js"
21
+ import { parseHostToSandboxMessage } from "./parseHostToSandboxMessage.js"
22
22
  import {
23
23
  type RequestMessage,
24
24
  Requests,
@@ -113,7 +113,7 @@ export class SandboxBridge {
113
113
  return
114
114
  }
115
115
 
116
- const parsed = v.safeParse(hostToSandboxMessageSchema, data)
116
+ const parsed = parseHostToSandboxMessage(data)
117
117
  if (!parsed.success) {
118
118
  console.warn(
119
119
  "[custom-blocks-sdk] ignoring malformed host message",
@@ -0,0 +1,54 @@
1
+ import { bridgeDataSourceBindingSchema } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBinding.js"
2
+ import { dataSourcePointerValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourcePointer.js"
3
+ import { notionDataSourceSchemaValidator } from "@notionhq/custom-blocks-protocol/dataSources/dataSourceSchema.js"
4
+ import { initMessageSchema } from "@notionhq/custom-blocks-protocol/handshake/init.js"
5
+ import { hostToSandboxMessageSchema } from "@notionhq/custom-blocks-protocol/messages/hostToSandbox.js"
6
+ import { readIncomingType } from "@notionhq/custom-blocks-protocol/messages/incomingType.js"
7
+ import * as v from "valibot"
8
+
9
+ /**
10
+ * Older hosts such as 0.9.0 send `collectionPointer` and `collectionSchema` during
11
+ * initialization and live updates. Normalize these pre-protocol-11 names to
12
+ * `dataSourcePointer` and `dataSourceSchema` before exposing bindings to SDK consumers.
13
+ * Current fields take precedence when both names are present. Malformed fields and
14
+ * invalid property mappings still fail validation; this compatibility does not add
15
+ * host operations or repair bindings the Notion client cannot read from storage.
16
+ */
17
+ export function parseHostToSandboxMessage(data: unknown) {
18
+ const type = readIncomingType(data)
19
+ if (type === "init" || type === "dataSourcesChanged") {
20
+ return v.safeParse(bindingMessageSchema, data)
21
+ }
22
+ return v.safeParse(hostToSandboxMessageSchema, data)
23
+ }
24
+
25
+ const bindingSchema = v.pipe(
26
+ v.object({
27
+ ...bridgeDataSourceBindingSchema.entries,
28
+ collectionPointer: v.optional(dataSourcePointerValidator),
29
+ collectionSchema: v.optional(notionDataSourceSchemaValidator),
30
+ }),
31
+ v.transform(({ collectionPointer, collectionSchema, ...binding }) => ({
32
+ ...binding,
33
+ dataSourcePointer: binding.dataSourcePointer ?? collectionPointer,
34
+ dataSourceSchema: binding.dataSourceSchema ?? collectionSchema,
35
+ })),
36
+ )
37
+
38
+ const dataSourcesSchema = v.object({
39
+ bindings: v.record(v.string(), bindingSchema),
40
+ })
41
+
42
+ const bindingMessageSchema = v.variant("type", [
43
+ v.variant("status", [
44
+ v.object({
45
+ ...initMessageSchema.options[0].entries,
46
+ dataSources: dataSourcesSchema,
47
+ }),
48
+ initMessageSchema.options[1],
49
+ ]),
50
+ v.object({
51
+ type: v.literal("dataSourcesChanged"),
52
+ dataSources: dataSourcesSchema,
53
+ }),
54
+ ])
@@ -17,7 +17,7 @@ export function resolveDataSources(args: {
17
17
  return Object.entries(args.manifest.dataSources).map(
18
18
  ([key, manifestDataSource]) => {
19
19
  const binding = args.dataSourceBindings[key]
20
- const collectionProperties =
20
+ const dataSourceProperties =
21
21
  binding?.dataSourceSchema?.propertiesById ?? {}
22
22
 
23
23
  const resolvedBinding = resolveDataSourceBinding({
@@ -36,7 +36,7 @@ export function resolveDataSources(args: {
36
36
  dataSourcePointer: binding?.dataSourcePointer,
37
37
  dataSourceSchema: binding?.dataSourceSchema,
38
38
  propertyIdsByKey,
39
- propertySchemasById: collectionProperties,
39
+ propertySchemasById: dataSourceProperties,
40
40
  ...(binding?.inaccessible === true && { inaccessible: true }),
41
41
  }
42
42
  },