@notionhq/custom-blocks 0.3.0 → 0.3.2
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/bridge/SandboxBridge.d.ts +469 -15
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +131 -80
- package/dist/bridge/dataSources/subscribe.d.ts +3 -1
- package/dist/bridge/dataSources/subscribe.d.ts.map +1 -1
- package/dist/bridge/dataSources/subscribe.js +9 -1
- package/dist/bridge/page.d.ts +6 -8
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +9 -56
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +29 -6
- package/dist/dataSources.d.ts.map +1 -1
- package/dist/dataSources.js +12 -10
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol/dataSources/dateValue.d.ts +2 -2
- package/dist/protocol/dataSources/dateValue.js +9 -7
- package/dist/protocol/messages/createPage.d.ts +64 -2
- package/dist/protocol/messages/createPageResult.d.ts +192 -6
- package/dist/protocol/messages/getPage.d.ts +192 -6
- package/dist/protocol/messages/hostToSandbox.d.ts +704 -22
- package/dist/protocol/messages/queryDataSourceResult.d.ts +128 -4
- package/dist/protocol/messages/sandboxToHost.d.ts +128 -4
- package/dist/protocol/messages/updatePage.d.ts +64 -2
- package/dist/protocol/messages/updatePageResult.d.ts +192 -6
- package/dist/protocol/pages/page.d.ts +360 -12
- package/dist/protocol/pages/page.js +48 -2
- package/dist/react/useDataSource.d.ts +1 -1
- package/dist/react/useDataSource.d.ts.map +1 -1
- package/dist/react/useDataSource.js +19 -2
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/data-sources.md +16 -12
- package/docs/errors.md +4 -0
- package/docs/pages.md +10 -7
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +181 -117
- package/src/bridge/dataSources/subscribe.ts +23 -1
- package/src/bridge/page.ts +15 -82
- package/src/bridge/sandboxClient.ts +37 -7
- package/src/dataSources.ts +19 -23
- package/src/index.ts +6 -0
- package/src/react/useDataSource.ts +20 -2
- package/src/types.ts +10 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,OAAO,KAAK,EACX,kBAAkB,EAClB,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,+DAA+D,CAAA;AACnH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sDAAsD,CAAA;AACvG,OAAO,KAAK,EACX,2BAA2B,EAC3B,oBAAoB,EACpB,MAAM,sDAAsD,CAAA;AAC7D,OAAO,KAAK,EACX,6BAA6B,EAC7B,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,wDAAwD,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAA;AACvG,OAAO,KAAK,EACX,mCAAmC,EACnC,4BAA4B,EAC5B,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EACX,4BAA4B,EAC5B,YAAY,EACZ,qBAAqB,EACrB,MAAM,uDAAuD,CAAA;AAC9D,OAAO,KAAK,EACX,iCAAiC,EACjC,iCAAiC,EACjC,kCAAkC,EAClC,6BAA6B,EAC7B,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,EAC5B,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;A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BAAiB,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3C;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,gBAAgB,CAAA;IACxB,UAAU,EAAE,0BAA0B,CAAA;IACtC,QAAQ,CAAC,EAAE,wBAAwB,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,YAAY,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,oBAAoB,CAChD,qBAAqB,EACrB,4BAA4B,CAC5B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,oBAAoB,CACvD,4BAA4B,EAC5B,mCAAmC,CACnC,CAAA;AAED,MAAM,MAAM,gBAAgB,GACzB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GACvC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,8BAA8B,CAAA;CAAE,CAAA;AAE7D,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,CAAA;AAExE,MAAM,MAAM,eAAe,GAAG,oBAAoB,CACjD,sBAAsB,EACtB,6BAA6B,CAC7B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,oBAAoB,CAC/C,oBAAoB,EACpB,2BAA2B,CAC3B,CAAA"}
|
package/dist/version.js
CHANGED
package/docs/data-sources.md
CHANGED
|
@@ -37,12 +37,12 @@ are useful for a data source switcher.
|
|
|
37
37
|
```ts
|
|
38
38
|
function customBlock.subscribeToDataSource(
|
|
39
39
|
args: SubscribeToDataSourceArgs,
|
|
40
|
-
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
41
40
|
): () => void;
|
|
42
41
|
|
|
43
42
|
type SubscribeToDataSourceArgs = {
|
|
44
43
|
key: string;
|
|
45
44
|
onSnapshot: (snapshot: DataSourceSnapshot) => void;
|
|
45
|
+
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void;
|
|
46
46
|
options?: DataSourceQueryOptions;
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -79,6 +79,7 @@ await initCustomBlock()
|
|
|
79
79
|
const unsubscribe = customBlock.subscribeToDataSource({
|
|
80
80
|
key: "people",
|
|
81
81
|
onSnapshot: snapshot => render(snapshot),
|
|
82
|
+
onError: error => showError(error.message),
|
|
82
83
|
options: {
|
|
83
84
|
limit: 50,
|
|
84
85
|
sorts: [{ key: "name", direction: "ascending" }],
|
|
@@ -114,6 +115,7 @@ type UseDataSourceResult = {
|
|
|
114
115
|
propertyIdsByKey: { [key: string]: string | undefined }
|
|
115
116
|
isLoading: boolean
|
|
116
117
|
hasMore: boolean
|
|
118
|
+
error: CustomBlockQueryDataSourceErrorInfo | undefined
|
|
117
119
|
}
|
|
118
120
|
```
|
|
119
121
|
|
|
@@ -130,9 +132,10 @@ Each consumer has its own host subscription. On unmount, the SDK removes its loc
|
|
|
130
132
|
sends an unsubscribe message. The host stops future refreshes and ignores pending results. Other
|
|
131
133
|
consumers remain subscribed.
|
|
132
134
|
|
|
133
|
-
Query failures stop loading.
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
Query failures set `error` and stop loading. The hook retains the last successful rows and bindings
|
|
136
|
+
for the same query. A later snapshot clears the error, including when a changed binding restarts the
|
|
137
|
+
query. Changing the key or options starts a separate query without the previous query's rows or
|
|
138
|
+
error.
|
|
136
139
|
|
|
137
140
|
## Query options
|
|
138
141
|
|
|
@@ -530,15 +533,15 @@ refer to the core values inside each property object. For example, “Number”
|
|
|
530
533
|
| `date` | 🟢 Date object | 🟡 Minute precision | 🟢 Supported | 🟢 Supported |
|
|
531
534
|
| `people` | 🟢 User or group references | 🟢 Supported | 🟢 Supported | 🟢 Native name ordering |
|
|
532
535
|
| `files` | 🟡 External files only | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
533
|
-
| `unique_id` |
|
|
536
|
+
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
534
537
|
| `relation` | 🟢 Page reference array | 🟡 Replaces value. Rejects `has_more: true`. | 🟢 Supported | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
|
|
535
538
|
| `place` | 🟢 Place object | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
536
|
-
| `formula` |
|
|
537
|
-
| `rollup` |
|
|
538
|
-
| `button` |
|
|
539
|
-
| `verification` |
|
|
539
|
+
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
540
|
+
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
541
|
+
| `button` | 🟡 Text fallback | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
|
|
542
|
+
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
540
543
|
| `last_visited_time` | 🟡 Viewer timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
541
|
-
| `location` |
|
|
544
|
+
| `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system databases. | 🔴 Unavailable elsewhere. ⚫ Notion disables sorts in Library system databases. |
|
|
542
545
|
| `created_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
543
546
|
| `last_edited_time` | 🟢 Timestamp or null | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
544
547
|
| `created_by` | 🟢 Actor reference or null | 🔴 Unavailable | 🟡 Schema-backed creator filters | 🟡 Schema property only |
|
|
@@ -674,8 +677,9 @@ if (date?.type === "date" && date.date) {
|
|
|
674
677
|
}
|
|
675
678
|
```
|
|
676
679
|
|
|
677
|
-
`NotionDateInput` describes this date shape for reads and writes
|
|
678
|
-
|
|
680
|
+
`NotionDateInput` describes this date shape for reads and writes, including an optional `reminder`.
|
|
681
|
+
Reminder types are `NotionDateReminder`, `NotionTimeReminder`, `NotionDateTimeReminder`, and
|
|
682
|
+
`NotionDisabledReminder`.
|
|
679
683
|
|
|
680
684
|
## Shared page results
|
|
681
685
|
|
package/docs/errors.md
CHANGED
|
@@ -52,6 +52,10 @@ newer hosts may send codes that an older SDK does not list.
|
|
|
52
52
|
- `invalid_data_source_query_sort`: The host rejects a sort, for example, because its property ID is
|
|
53
53
|
unknown, its property type is unsupported, or the query repeats a sort property.
|
|
54
54
|
|
|
55
|
+
`useDataSource` exposes query failures as `error` and sets `isLoading` to `false`. It retains the
|
|
56
|
+
last successful rows for the same query. A later snapshot clears the error. Framework-neutral
|
|
57
|
+
subscriptions report failures through their optional error callback.
|
|
58
|
+
|
|
55
59
|
Data source subscriptions repeat the query when the host supplies a changed schema or binding. This
|
|
56
60
|
recovery does not depend on `isRetryable`.
|
|
57
61
|
|
package/docs/pages.md
CHANGED
|
@@ -138,15 +138,15 @@ and a property in its schema.
|
|
|
138
138
|
| `date` | 🟢 `start` and optional `end` strings, or `null` | 🟡 Minute precision | 🟡 Minute precision |
|
|
139
139
|
| `people` | 🟢 Array of user/group ID objects | 🟢 Supported | 🟢 Supported |
|
|
140
140
|
| `files` | 🟢 External links and hosted files | 🟡 File URLs only | 🟡 File URLs only |
|
|
141
|
-
| `unique_id` |
|
|
141
|
+
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
142
142
|
| `relation` | 🟢 Array of page ID objects | 🟡 Replaces value. Rejects `has_more: true`. | 🟡 Replaces value. Rejects `has_more: true`. |
|
|
143
143
|
| `place` | 🟢 Coordinates and optional place details, or `null` | 🟢 Supported | 🟢 Supported |
|
|
144
|
-
| `formula` |
|
|
145
|
-
| `rollup` |
|
|
146
|
-
| `button` |
|
|
147
|
-
| `verification` |
|
|
144
|
+
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
145
|
+
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
146
|
+
| `button` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
147
|
+
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
148
148
|
| `last_visited_time` | 🟡 Current viewer’s ISO timestamp | 🔴 Unavailable | 🔴 Unavailable |
|
|
149
|
-
| `location` |
|
|
149
|
+
| `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable |
|
|
150
150
|
| `created_time` | 🟢 ISO timestamp in UTC | 🔴 Unavailable | 🔴 Unavailable |
|
|
151
151
|
| `last_edited_time` | 🟢 ISO timestamp in UTC | 🔴 Unavailable | 🔴 Unavailable |
|
|
152
152
|
| `created_by` | 🟢 Actor record pointer | 🔴 Unavailable | 🔴 Unavailable |
|
|
@@ -167,7 +167,10 @@ and a property in its schema.
|
|
|
167
167
|
- Relation writes replace the value and reject `has_more: true`.
|
|
168
168
|
- Top-level `created_time` and `last_edited_time` remain available independently of schema
|
|
169
169
|
properties.
|
|
170
|
-
- Formula, rollup, unique ID,
|
|
170
|
+
- Formula, rollup, unique ID, button, verification, and location reads retain their type with a
|
|
171
|
+
string value.
|
|
172
|
+
- These strings contain stored text only. Formulas and rollups are not evaluated. Missing values
|
|
173
|
+
return `""`.
|
|
171
174
|
|
|
172
175
|
For query properties, filters, and sorts, see
|
|
173
176
|
[Data source property support](./data-sources.md#property-support).
|
package/package.json
CHANGED
|
@@ -4,10 +4,7 @@ import type {
|
|
|
4
4
|
NotionDataSource,
|
|
5
5
|
NotionDataSourceBindings,
|
|
6
6
|
} from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
|
|
7
|
-
import type {
|
|
8
|
-
NotionDataSourceId,
|
|
9
|
-
NotionPageId,
|
|
10
|
-
} from "@notionhq/custom-blocks-protocol/ids.js"
|
|
7
|
+
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/ids.js"
|
|
11
8
|
import type { CustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest.js"
|
|
12
9
|
import type {
|
|
13
10
|
CreatePageMessage,
|
|
@@ -41,9 +38,7 @@ import type { SandboxToHostMessage } from "@notionhq/custom-blocks-protocol/mess
|
|
|
41
38
|
import type { UnsubscribeDataSourceQueryMessage } from "@notionhq/custom-blocks-protocol/messages/unsubscribeDataSourceQuery.js"
|
|
42
39
|
import type { UpdatePageMessage } from "@notionhq/custom-blocks-protocol/messages/updatePage.js"
|
|
43
40
|
import type { UpdatePageResultMessage } from "@notionhq/custom-blocks-protocol/messages/updatePageResult.js"
|
|
44
|
-
import type { notionPageDataSchema } from "@notionhq/custom-blocks-protocol/pages/page.js"
|
|
45
41
|
import type { NotionTheme } from "@notionhq/custom-blocks-protocol/theme.js"
|
|
46
|
-
import type { InferOutput } from "valibot"
|
|
47
42
|
import * as v from "valibot"
|
|
48
43
|
import type {
|
|
49
44
|
CreatePageArgs,
|
|
@@ -59,6 +54,7 @@ import type {
|
|
|
59
54
|
OpenPageOptions,
|
|
60
55
|
OpenPageResult,
|
|
61
56
|
PageUpdatePayload,
|
|
57
|
+
UpdatePageResult,
|
|
62
58
|
} from "../types.js"
|
|
63
59
|
import { unreachable } from "../utils.js"
|
|
64
60
|
import {
|
|
@@ -103,6 +99,7 @@ export class SandboxBridge {
|
|
|
103
99
|
theme: "light",
|
|
104
100
|
contrastMode: DEFAULT_CONTRAST_MODE,
|
|
105
101
|
}
|
|
102
|
+
private pendingPageUpdates = new Map<NotionPageId, Promise<void>>()
|
|
106
103
|
private listeners = new Set<() => void>()
|
|
107
104
|
private messageInterceptors = new Set<MessageInterceptor>()
|
|
108
105
|
private messageLog: MessageLogEntry[] = []
|
|
@@ -758,19 +755,34 @@ export class SandboxBridge {
|
|
|
758
755
|
this.postToHost(outbound)
|
|
759
756
|
}
|
|
760
757
|
|
|
761
|
-
createPage(
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
758
|
+
createPage(args: {
|
|
759
|
+
parent: CreatePageArgs["parent"]
|
|
760
|
+
properties: CreatePageArgs["properties"]
|
|
761
|
+
position?: CreatePageArgs["position"]
|
|
762
|
+
dataSource: NotionDataSource | undefined
|
|
763
|
+
}): Promise<CreatePageResult> {
|
|
764
|
+
const { dataSource } = args
|
|
765
|
+
const dataSourceKey = dataSource?.key
|
|
765
766
|
return new Promise(resolve => {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
767
|
+
let parent: CreatePageMessageParent
|
|
768
|
+
let propertyDataSource = dataSource
|
|
769
|
+
if (dataSource?.collectionPointer) {
|
|
770
|
+
parent = {
|
|
771
|
+
type: "data_source_id",
|
|
772
|
+
data_source_id: dataSource.collectionPointer.id,
|
|
773
|
+
}
|
|
774
|
+
} else {
|
|
775
|
+
const resolvedParent = this.resolveCreatePageParent(args.parent)
|
|
776
|
+
if (resolvedParent.status === "error") {
|
|
777
|
+
resolve(resolvedParent)
|
|
778
|
+
return
|
|
779
|
+
}
|
|
780
|
+
parent = resolvedParent.parent
|
|
781
|
+
propertyDataSource = resolvedParent.dataSource
|
|
770
782
|
}
|
|
771
783
|
const resolvedProperties = resolvePropertyWriteMapForDataSource({
|
|
772
|
-
dataSource:
|
|
773
|
-
properties:
|
|
784
|
+
dataSource: propertyDataSource,
|
|
785
|
+
properties: args.properties,
|
|
774
786
|
operationName: "createPage",
|
|
775
787
|
})
|
|
776
788
|
if (resolvedProperties.status === "error") {
|
|
@@ -782,38 +794,79 @@ export class SandboxBridge {
|
|
|
782
794
|
resolve(result)
|
|
783
795
|
return
|
|
784
796
|
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
797
|
+
const update = async (
|
|
798
|
+
args: Parameters<SandboxBridge["updatePage"]>[0],
|
|
799
|
+
): Promise<UpdatePageResult> => {
|
|
800
|
+
const result = await this.updatePage(args)
|
|
801
|
+
if (result.status === "error") {
|
|
802
|
+
return result
|
|
803
|
+
}
|
|
804
|
+
Object.assign(page, result.page)
|
|
805
|
+
return { status: "success", page }
|
|
806
|
+
}
|
|
807
|
+
const page: NotionPage = toNotionPageFromNotionPageData({
|
|
808
|
+
page: result.page,
|
|
809
|
+
dataSourceKey,
|
|
810
|
+
getPropertyById: propertyId =>
|
|
811
|
+
this.getPropertyById({ page, propertyId }),
|
|
812
|
+
getPropertyByKey: propertyKey =>
|
|
813
|
+
this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
814
|
+
updateById: payload =>
|
|
815
|
+
update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
816
|
+
updateByKey: payload =>
|
|
817
|
+
update({ ...payload, pageId: page.id, dataSource }),
|
|
788
818
|
})
|
|
819
|
+
resolve({ status: "success", page })
|
|
789
820
|
})
|
|
790
821
|
const outbound: CreatePageMessage = {
|
|
791
822
|
type: "createPage",
|
|
792
823
|
requestId,
|
|
793
|
-
parent
|
|
824
|
+
parent,
|
|
794
825
|
properties: resolvedProperties.properties,
|
|
795
826
|
}
|
|
796
|
-
if (
|
|
797
|
-
outbound.position =
|
|
827
|
+
if (args.position !== undefined) {
|
|
828
|
+
outbound.position = args.position
|
|
798
829
|
}
|
|
799
830
|
this.postToHost(outbound)
|
|
800
831
|
})
|
|
801
832
|
}
|
|
802
833
|
|
|
803
|
-
getPage(
|
|
804
|
-
pageId: NotionPageId
|
|
805
|
-
|
|
806
|
-
): Promise<GetPageResult> {
|
|
834
|
+
getPage(args: {
|
|
835
|
+
pageId: NotionPageId
|
|
836
|
+
dataSource: NotionDataSource | undefined
|
|
837
|
+
}): Promise<GetPageResult> {
|
|
838
|
+
const { pageId, dataSource } = args
|
|
839
|
+
const dataSourceId = dataSource?.collectionPointer?.id
|
|
840
|
+
const dataSourceKey = dataSource?.key
|
|
807
841
|
return new Promise(resolve => {
|
|
808
842
|
const requestId = this.pendingGetPage.allocate(result => {
|
|
809
843
|
if (result.status === "error") {
|
|
810
844
|
resolve(result)
|
|
811
845
|
return
|
|
812
846
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
847
|
+
const update = async (
|
|
848
|
+
args: Parameters<SandboxBridge["updatePage"]>[0],
|
|
849
|
+
): Promise<UpdatePageResult> => {
|
|
850
|
+
const result = await this.updatePage(args)
|
|
851
|
+
if (result.status === "error") {
|
|
852
|
+
return result
|
|
853
|
+
}
|
|
854
|
+
Object.assign(page, result.page)
|
|
855
|
+
return { status: "success", page }
|
|
856
|
+
}
|
|
857
|
+
const page: NotionPage = toNotionPageFromNotionPageData({
|
|
858
|
+
page: result.page,
|
|
859
|
+
dataSourceKey,
|
|
860
|
+
getPropertyById: propertyId =>
|
|
861
|
+
this.getPropertyById({ page, propertyId }),
|
|
862
|
+
getPropertyByKey: propertyKey =>
|
|
863
|
+
this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
864
|
+
updateById: payload =>
|
|
865
|
+
update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
866
|
+
updateByKey: payload =>
|
|
867
|
+
update({ ...payload, pageId: page.id, dataSource }),
|
|
816
868
|
})
|
|
869
|
+
resolve({ status: "success", page })
|
|
817
870
|
})
|
|
818
871
|
const outbound: GetPageMessage = {
|
|
819
872
|
type: "getPage",
|
|
@@ -878,67 +931,102 @@ export class SandboxBridge {
|
|
|
878
931
|
})
|
|
879
932
|
}
|
|
880
933
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
934
|
+
getPropertyById(args: { page: NotionPage; propertyId: string }) {
|
|
935
|
+
return (
|
|
936
|
+
Object.values(args.page.properties).find(
|
|
937
|
+
value => value?.id === args.propertyId,
|
|
938
|
+
) ?? null
|
|
939
|
+
)
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
getPropertyByKey(args: {
|
|
943
|
+
page: NotionPage
|
|
944
|
+
dataSource: NotionDataSource | undefined
|
|
945
|
+
propertyKey: string
|
|
946
|
+
}) {
|
|
947
|
+
const { page, dataSource, propertyKey } = args
|
|
948
|
+
const currentDataSource =
|
|
949
|
+
this.hostState.status === "initialized"
|
|
887
950
|
? this.hostState.dataSources.find(
|
|
888
|
-
source => source.
|
|
951
|
+
source => source.key === dataSource?.key,
|
|
889
952
|
)
|
|
890
953
|
: undefined
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
954
|
+
// Keep the captured mapping valid only while its key remains bound to the original database.
|
|
955
|
+
if (
|
|
956
|
+
!dataSource?.collectionPointer ||
|
|
957
|
+
currentDataSource?.collectionPointer?.id !==
|
|
958
|
+
dataSource.collectionPointer.id
|
|
959
|
+
) {
|
|
960
|
+
return null
|
|
961
|
+
}
|
|
962
|
+
const propertyId = Object.hasOwn(dataSource.propertyIdsByKey, propertyKey)
|
|
963
|
+
? dataSource.propertyIdsByKey[propertyKey]
|
|
964
|
+
: undefined
|
|
965
|
+
return propertyId === undefined
|
|
966
|
+
? null
|
|
967
|
+
: this.getPropertyById({ page, propertyId })
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
updatePage(args: {
|
|
971
|
+
pageId: NotionPageId
|
|
972
|
+
properties?: PageUpdatePayload["properties"]
|
|
973
|
+
icon?: PageUpdatePayload["icon"]
|
|
974
|
+
cover?: PageUpdatePayload["cover"]
|
|
975
|
+
is_archived?: PageUpdatePayload["is_archived"]
|
|
976
|
+
dataSource: NotionDataSource | undefined
|
|
977
|
+
}): Promise<BridgeMessagePayload<UpdatePageResultMessage>> {
|
|
978
|
+
const operation = async (): Promise<
|
|
979
|
+
BridgeMessagePayload<UpdatePageResultMessage>
|
|
980
|
+
> => {
|
|
981
|
+
const { dataSource } = args
|
|
982
|
+
const dataSourceId = dataSource?.collectionPointer?.id
|
|
983
|
+
const propertyIdsByKey = dataSource?.propertyIdsByKey ?? {}
|
|
984
|
+
if (dataSource !== undefined) {
|
|
985
|
+
for (const propertyKey of Object.keys(args.properties ?? {})) {
|
|
986
|
+
const propertyId = Object.hasOwn(propertyIdsByKey, propertyKey)
|
|
987
|
+
? propertyIdsByKey[propertyKey]
|
|
896
988
|
: undefined
|
|
897
|
-
|
|
989
|
+
if (
|
|
990
|
+
propertyId &&
|
|
991
|
+
dataSource?.collectionSchema?.propertiesById[propertyId]
|
|
992
|
+
) {
|
|
993
|
+
continue
|
|
994
|
+
}
|
|
995
|
+
return {
|
|
996
|
+
status: "error",
|
|
997
|
+
error: {
|
|
998
|
+
code: "unmapped_property",
|
|
999
|
+
message: `Cannot resolve property key "${propertyKey}" on this page.`,
|
|
1000
|
+
isRetryable: false,
|
|
1001
|
+
},
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
const resolved = resolvePropertyWriteMapForDataSource({
|
|
1006
|
+
dataSource,
|
|
1007
|
+
properties: args.properties ?? {},
|
|
1008
|
+
operationName: "page.update",
|
|
898
1009
|
})
|
|
899
|
-
if (
|
|
900
|
-
return
|
|
901
|
-
status: "error",
|
|
902
|
-
error: {
|
|
903
|
-
code: "unmapped_property",
|
|
904
|
-
message: `Cannot resolve property key "${unmappedKey}" on this page.`,
|
|
905
|
-
isRetryable: false,
|
|
906
|
-
},
|
|
907
|
-
})
|
|
1010
|
+
if (resolved.status === "error") {
|
|
1011
|
+
return resolved
|
|
908
1012
|
}
|
|
909
|
-
}
|
|
910
|
-
const resolved = resolvePropertyWriteMapForDataSource({
|
|
911
|
-
dataSource,
|
|
912
|
-
properties: args.properties ?? {},
|
|
913
|
-
operationName: "page.update",
|
|
914
|
-
})
|
|
915
|
-
if (resolved.status === "error") {
|
|
916
|
-
return Promise.resolve(resolved)
|
|
917
|
-
}
|
|
918
|
-
const isArchived = args.is_archived
|
|
919
|
-
return new Promise(resolve => {
|
|
920
1013
|
if (
|
|
921
|
-
(args.properties ===
|
|
922
|
-
Object.keys(args.properties).length === 0) &&
|
|
1014
|
+
Object.keys(args.properties ?? {}).length === 0 &&
|
|
923
1015
|
args.icon === undefined &&
|
|
924
1016
|
args.cover === undefined &&
|
|
925
|
-
|
|
1017
|
+
args.is_archived === undefined
|
|
926
1018
|
) {
|
|
927
|
-
|
|
1019
|
+
return {
|
|
928
1020
|
status: "error",
|
|
929
1021
|
error: {
|
|
930
1022
|
code: "invalid_page_update",
|
|
931
1023
|
message: "updatePage requires at least one property.",
|
|
932
1024
|
isRetryable: false,
|
|
933
1025
|
},
|
|
934
|
-
}
|
|
935
|
-
return
|
|
1026
|
+
}
|
|
936
1027
|
}
|
|
937
|
-
|
|
938
|
-
const requestId = this.pendingUpdatePage.allocate(resolve)
|
|
939
|
-
const outbound: UpdatePageMessage = {
|
|
1028
|
+
const outbound: Omit<UpdatePageMessage, "requestId"> = {
|
|
940
1029
|
type: "updatePage",
|
|
941
|
-
requestId,
|
|
942
1030
|
dataSourceId,
|
|
943
1031
|
pageId: args.pageId,
|
|
944
1032
|
}
|
|
@@ -951,47 +1039,29 @@ export class SandboxBridge {
|
|
|
951
1039
|
if (args.cover !== undefined) {
|
|
952
1040
|
outbound.cover = args.cover
|
|
953
1041
|
}
|
|
954
|
-
if (
|
|
955
|
-
outbound.archived =
|
|
1042
|
+
if (args.is_archived !== undefined) {
|
|
1043
|
+
outbound.archived = args.is_archived
|
|
1044
|
+
}
|
|
1045
|
+
return new Promise<BridgeMessagePayload<UpdatePageResultMessage>>(
|
|
1046
|
+
resolve => {
|
|
1047
|
+
const requestId = this.pendingUpdatePage.allocate(resolve)
|
|
1048
|
+
this.postToHost({ ...outbound, requestId })
|
|
1049
|
+
},
|
|
1050
|
+
)
|
|
1051
|
+
}
|
|
1052
|
+
const pending = this.pendingPageUpdates.get(args.pageId)
|
|
1053
|
+
const result = pending ? pending.then(operation) : operation()
|
|
1054
|
+
const finished = result.then(
|
|
1055
|
+
() => undefined,
|
|
1056
|
+
() => undefined,
|
|
1057
|
+
)
|
|
1058
|
+
this.pendingPageUpdates.set(args.pageId, finished)
|
|
1059
|
+
void finished.then(() => {
|
|
1060
|
+
if (this.pendingPageUpdates.get(args.pageId) === finished) {
|
|
1061
|
+
this.pendingPageUpdates.delete(args.pageId)
|
|
956
1062
|
}
|
|
957
|
-
this.postToHost(outbound)
|
|
958
|
-
})
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
/**
|
|
962
|
-
* Builds an SDK page object from loaded page data and wires its methods to the bridge.
|
|
963
|
-
* Unlike `pages.create`, this does not send a create request or create a page in Notion.
|
|
964
|
-
*/
|
|
965
|
-
buildNotionPage(args: {
|
|
966
|
-
page: InferOutput<typeof notionPageDataSchema>
|
|
967
|
-
dataSourceId: NotionDataSourceId | undefined
|
|
968
|
-
}): NotionPage {
|
|
969
|
-
const { page, dataSourceId } = args
|
|
970
|
-
const dataSource =
|
|
971
|
-
this.hostState.status === "initialized" && dataSourceId !== undefined
|
|
972
|
-
? this.hostState.dataSources.find(
|
|
973
|
-
source => source.collectionPointer?.id === dataSourceId,
|
|
974
|
-
)
|
|
975
|
-
: undefined
|
|
976
|
-
return toNotionPageFromNotionPageData({
|
|
977
|
-
page,
|
|
978
|
-
dataSource,
|
|
979
|
-
getDataSource: () => {
|
|
980
|
-
if (
|
|
981
|
-
this.hostState.status !== "initialized" ||
|
|
982
|
-
dataSourceId === undefined
|
|
983
|
-
) {
|
|
984
|
-
return undefined
|
|
985
|
-
}
|
|
986
|
-
return this.hostState.dataSources.find(
|
|
987
|
-
source =>
|
|
988
|
-
source.key === dataSource?.key &&
|
|
989
|
-
source.collectionPointer?.id === dataSourceId,
|
|
990
|
-
)
|
|
991
|
-
},
|
|
992
|
-
update: (payload, updateDataSourceId) =>
|
|
993
|
-
this.updatePage({ ...payload, pageId: page.id }, updateDataSourceId),
|
|
994
1063
|
})
|
|
1064
|
+
return result
|
|
995
1065
|
}
|
|
996
1066
|
|
|
997
1067
|
/**
|
|
@@ -1235,9 +1305,3 @@ function formatInvalidHostReason(
|
|
|
1235
1305
|
const extra = issues.length > 1 ? ` (+${issues.length - 1} more)` : ""
|
|
1236
1306
|
return `Could not parse ${labelled}: ${detail}${extra}`
|
|
1237
1307
|
}
|
|
1238
|
-
|
|
1239
|
-
type UpdatePageArgs = Omit<
|
|
1240
|
-
UpdatePageMessage,
|
|
1241
|
-
"type" | "requestId" | "archived" | "properties" | "dataSourceId"
|
|
1242
|
-
> &
|
|
1243
|
-
PageUpdatePayload
|
|
@@ -8,9 +8,23 @@ import { notifyListener } from "../notifyListener.js"
|
|
|
8
8
|
import { customBlockDataSources, customBlockHost } from "../sandboxClient.js"
|
|
9
9
|
|
|
10
10
|
export function subscribeToDataSource(
|
|
11
|
-
|
|
11
|
+
args: SubscribeToDataSourceArgs,
|
|
12
|
+
): () => void
|
|
13
|
+
/** @deprecated Pass onError in the first argument instead. */
|
|
14
|
+
export function subscribeToDataSource(
|
|
15
|
+
args: SubscribeToDataSourceArgs,
|
|
12
16
|
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
17
|
+
): () => void
|
|
18
|
+
export function subscribeToDataSource(
|
|
19
|
+
{
|
|
20
|
+
key,
|
|
21
|
+
onSnapshot,
|
|
22
|
+
onError: providedOnError,
|
|
23
|
+
options: providedOptions = {},
|
|
24
|
+
}: SubscribeToDataSourceArgs,
|
|
25
|
+
legacyOnError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
13
26
|
): () => void {
|
|
27
|
+
const onError = providedOnError ?? legacyOnError
|
|
14
28
|
const options = structuredClone(providedOptions)
|
|
15
29
|
const subscriptionId = customBlockDataSources.createSubscriptionId()
|
|
16
30
|
let active = true
|
|
@@ -41,10 +55,18 @@ export function subscribeToDataSource(
|
|
|
41
55
|
key,
|
|
42
56
|
subscriptionId,
|
|
43
57
|
)
|
|
58
|
+
const backingSourceChanged =
|
|
59
|
+
lastSnapshotInputs !== undefined &&
|
|
60
|
+
lastSnapshotInputs.dataSource?.collectionPointer?.id !==
|
|
61
|
+
dataSource?.collectionPointer?.id
|
|
44
62
|
// Record inputs before calling consumer code, which can trigger another notification.
|
|
45
63
|
lastSnapshotInputs = { status: hostState.status, dataSource, queryState }
|
|
46
64
|
const error = queryState?.error
|
|
47
65
|
if (error && onError) {
|
|
66
|
+
if (backingSourceChanged) {
|
|
67
|
+
// Sync failures skip loading, so deliver the bridge's reset before the error.
|
|
68
|
+
notifyListener(() => onSnapshot(snapshot))
|
|
69
|
+
}
|
|
48
70
|
notifyListener(() => onError(error))
|
|
49
71
|
return
|
|
50
72
|
}
|