@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
|
@@ -19,6 +19,7 @@ export class SandboxBridge {
|
|
|
19
19
|
theme: "light",
|
|
20
20
|
contrastMode: DEFAULT_CONTRAST_MODE,
|
|
21
21
|
};
|
|
22
|
+
pendingPageUpdates = new Map();
|
|
22
23
|
listeners = new Set();
|
|
23
24
|
messageInterceptors = new Set();
|
|
24
25
|
messageLog = [];
|
|
@@ -545,16 +546,30 @@ export class SandboxBridge {
|
|
|
545
546
|
};
|
|
546
547
|
this.postToHost(outbound);
|
|
547
548
|
}
|
|
548
|
-
createPage(
|
|
549
|
+
createPage(args) {
|
|
550
|
+
const { dataSource } = args;
|
|
551
|
+
const dataSourceKey = dataSource?.key;
|
|
549
552
|
return new Promise(resolve => {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
553
|
+
let parent;
|
|
554
|
+
let propertyDataSource = dataSource;
|
|
555
|
+
if (dataSource?.collectionPointer) {
|
|
556
|
+
parent = {
|
|
557
|
+
type: "data_source_id",
|
|
558
|
+
data_source_id: dataSource.collectionPointer.id,
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
const resolvedParent = this.resolveCreatePageParent(args.parent);
|
|
563
|
+
if (resolvedParent.status === "error") {
|
|
564
|
+
resolve(resolvedParent);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
parent = resolvedParent.parent;
|
|
568
|
+
propertyDataSource = resolvedParent.dataSource;
|
|
554
569
|
}
|
|
555
570
|
const resolvedProperties = resolvePropertyWriteMapForDataSource({
|
|
556
|
-
dataSource:
|
|
557
|
-
properties:
|
|
571
|
+
dataSource: propertyDataSource,
|
|
572
|
+
properties: args.properties,
|
|
558
573
|
operationName: "createPage",
|
|
559
574
|
});
|
|
560
575
|
if (resolvedProperties.status === "error") {
|
|
@@ -566,34 +581,63 @@ export class SandboxBridge {
|
|
|
566
581
|
resolve(result);
|
|
567
582
|
return;
|
|
568
583
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
584
|
+
const update = async (args) => {
|
|
585
|
+
const result = await this.updatePage(args);
|
|
586
|
+
if (result.status === "error") {
|
|
587
|
+
return result;
|
|
588
|
+
}
|
|
589
|
+
Object.assign(page, result.page);
|
|
590
|
+
return { status: "success", page };
|
|
591
|
+
};
|
|
592
|
+
const page = toNotionPageFromNotionPageData({
|
|
593
|
+
page: result.page,
|
|
594
|
+
dataSourceKey,
|
|
595
|
+
getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
|
|
596
|
+
getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
597
|
+
updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
598
|
+
updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
572
599
|
});
|
|
600
|
+
resolve({ status: "success", page });
|
|
573
601
|
});
|
|
574
602
|
const outbound = {
|
|
575
603
|
type: "createPage",
|
|
576
604
|
requestId,
|
|
577
|
-
parent
|
|
605
|
+
parent,
|
|
578
606
|
properties: resolvedProperties.properties,
|
|
579
607
|
};
|
|
580
|
-
if (
|
|
581
|
-
outbound.position =
|
|
608
|
+
if (args.position !== undefined) {
|
|
609
|
+
outbound.position = args.position;
|
|
582
610
|
}
|
|
583
611
|
this.postToHost(outbound);
|
|
584
612
|
});
|
|
585
613
|
}
|
|
586
|
-
getPage(
|
|
614
|
+
getPage(args) {
|
|
615
|
+
const { pageId, dataSource } = args;
|
|
616
|
+
const dataSourceId = dataSource?.collectionPointer?.id;
|
|
617
|
+
const dataSourceKey = dataSource?.key;
|
|
587
618
|
return new Promise(resolve => {
|
|
588
619
|
const requestId = this.pendingGetPage.allocate(result => {
|
|
589
620
|
if (result.status === "error") {
|
|
590
621
|
resolve(result);
|
|
591
622
|
return;
|
|
592
623
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
624
|
+
const update = async (args) => {
|
|
625
|
+
const result = await this.updatePage(args);
|
|
626
|
+
if (result.status === "error") {
|
|
627
|
+
return result;
|
|
628
|
+
}
|
|
629
|
+
Object.assign(page, result.page);
|
|
630
|
+
return { status: "success", page };
|
|
631
|
+
};
|
|
632
|
+
const page = toNotionPageFromNotionPageData({
|
|
633
|
+
page: result.page,
|
|
634
|
+
dataSourceKey,
|
|
635
|
+
getPropertyById: propertyId => this.getPropertyById({ page, propertyId }),
|
|
636
|
+
getPropertyByKey: propertyKey => this.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
637
|
+
updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
638
|
+
updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
596
639
|
});
|
|
640
|
+
resolve({ status: "success", page });
|
|
597
641
|
});
|
|
598
642
|
const outbound = {
|
|
599
643
|
type: "getPage",
|
|
@@ -650,57 +694,74 @@ export class SandboxBridge {
|
|
|
650
694
|
this.postToHost(outbound);
|
|
651
695
|
});
|
|
652
696
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
697
|
+
getPropertyById(args) {
|
|
698
|
+
return (Object.values(args.page.properties).find(value => value?.id === args.propertyId) ?? null);
|
|
699
|
+
}
|
|
700
|
+
getPropertyByKey(args) {
|
|
701
|
+
const { page, dataSource, propertyKey } = args;
|
|
702
|
+
const currentDataSource = this.hostState.status === "initialized"
|
|
703
|
+
? this.hostState.dataSources.find(source => source.key === dataSource?.key)
|
|
656
704
|
: undefined;
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
705
|
+
// Keep the captured mapping valid only while its key remains bound to the original database.
|
|
706
|
+
if (!dataSource?.collectionPointer ||
|
|
707
|
+
currentDataSource?.collectionPointer?.id !==
|
|
708
|
+
dataSource.collectionPointer.id) {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
const propertyId = Object.hasOwn(dataSource.propertyIdsByKey, propertyKey)
|
|
712
|
+
? dataSource.propertyIdsByKey[propertyKey]
|
|
713
|
+
: undefined;
|
|
714
|
+
return propertyId === undefined
|
|
715
|
+
? null
|
|
716
|
+
: this.getPropertyById({ page, propertyId });
|
|
717
|
+
}
|
|
718
|
+
updatePage(args) {
|
|
719
|
+
const operation = async () => {
|
|
720
|
+
const { dataSource } = args;
|
|
721
|
+
const dataSourceId = dataSource?.collectionPointer?.id;
|
|
722
|
+
const propertyIdsByKey = dataSource?.propertyIdsByKey ?? {};
|
|
723
|
+
if (dataSource !== undefined) {
|
|
724
|
+
for (const propertyKey of Object.keys(args.properties ?? {})) {
|
|
725
|
+
const propertyId = Object.hasOwn(propertyIdsByKey, propertyKey)
|
|
726
|
+
? propertyIdsByKey[propertyKey]
|
|
727
|
+
: undefined;
|
|
728
|
+
if (propertyId &&
|
|
729
|
+
dataSource?.collectionSchema?.propertiesById[propertyId]) {
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
return {
|
|
733
|
+
status: "error",
|
|
734
|
+
error: {
|
|
735
|
+
code: "unmapped_property",
|
|
736
|
+
message: `Cannot resolve property key "${propertyKey}" on this page.`,
|
|
737
|
+
isRetryable: false,
|
|
738
|
+
},
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
const resolved = resolvePropertyWriteMapForDataSource({
|
|
743
|
+
dataSource,
|
|
744
|
+
properties: args.properties ?? {},
|
|
745
|
+
operationName: "page.update",
|
|
663
746
|
});
|
|
664
|
-
if (
|
|
665
|
-
return
|
|
666
|
-
status: "error",
|
|
667
|
-
error: {
|
|
668
|
-
code: "unmapped_property",
|
|
669
|
-
message: `Cannot resolve property key "${unmappedKey}" on this page.`,
|
|
670
|
-
isRetryable: false,
|
|
671
|
-
},
|
|
672
|
-
});
|
|
747
|
+
if (resolved.status === "error") {
|
|
748
|
+
return resolved;
|
|
673
749
|
}
|
|
674
|
-
|
|
675
|
-
const resolved = resolvePropertyWriteMapForDataSource({
|
|
676
|
-
dataSource,
|
|
677
|
-
properties: args.properties ?? {},
|
|
678
|
-
operationName: "page.update",
|
|
679
|
-
});
|
|
680
|
-
if (resolved.status === "error") {
|
|
681
|
-
return Promise.resolve(resolved);
|
|
682
|
-
}
|
|
683
|
-
const isArchived = args.is_archived;
|
|
684
|
-
return new Promise(resolve => {
|
|
685
|
-
if ((args.properties === undefined ||
|
|
686
|
-
Object.keys(args.properties).length === 0) &&
|
|
750
|
+
if (Object.keys(args.properties ?? {}).length === 0 &&
|
|
687
751
|
args.icon === undefined &&
|
|
688
752
|
args.cover === undefined &&
|
|
689
|
-
|
|
690
|
-
|
|
753
|
+
args.is_archived === undefined) {
|
|
754
|
+
return {
|
|
691
755
|
status: "error",
|
|
692
756
|
error: {
|
|
693
757
|
code: "invalid_page_update",
|
|
694
758
|
message: "updatePage requires at least one property.",
|
|
695
759
|
isRetryable: false,
|
|
696
760
|
},
|
|
697
|
-
}
|
|
698
|
-
return;
|
|
761
|
+
};
|
|
699
762
|
}
|
|
700
|
-
const requestId = this.pendingUpdatePage.allocate(resolve);
|
|
701
763
|
const outbound = {
|
|
702
764
|
type: "updatePage",
|
|
703
|
-
requestId,
|
|
704
765
|
dataSourceId,
|
|
705
766
|
pageId: args.pageId,
|
|
706
767
|
};
|
|
@@ -713,34 +774,24 @@ export class SandboxBridge {
|
|
|
713
774
|
if (args.cover !== undefined) {
|
|
714
775
|
outbound.cover = args.cover;
|
|
715
776
|
}
|
|
716
|
-
if (
|
|
717
|
-
outbound.archived =
|
|
777
|
+
if (args.is_archived !== undefined) {
|
|
778
|
+
outbound.archived = args.is_archived;
|
|
779
|
+
}
|
|
780
|
+
return new Promise(resolve => {
|
|
781
|
+
const requestId = this.pendingUpdatePage.allocate(resolve);
|
|
782
|
+
this.postToHost({ ...outbound, requestId });
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
const pending = this.pendingPageUpdates.get(args.pageId);
|
|
786
|
+
const result = pending ? pending.then(operation) : operation();
|
|
787
|
+
const finished = result.then(() => undefined, () => undefined);
|
|
788
|
+
this.pendingPageUpdates.set(args.pageId, finished);
|
|
789
|
+
void finished.then(() => {
|
|
790
|
+
if (this.pendingPageUpdates.get(args.pageId) === finished) {
|
|
791
|
+
this.pendingPageUpdates.delete(args.pageId);
|
|
718
792
|
}
|
|
719
|
-
this.postToHost(outbound);
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
/**
|
|
723
|
-
* Builds an SDK page object from loaded page data and wires its methods to the bridge.
|
|
724
|
-
* Unlike `pages.create`, this does not send a create request or create a page in Notion.
|
|
725
|
-
*/
|
|
726
|
-
buildNotionPage(args) {
|
|
727
|
-
const { page, dataSourceId } = args;
|
|
728
|
-
const dataSource = this.hostState.status === "initialized" && dataSourceId !== undefined
|
|
729
|
-
? this.hostState.dataSources.find(source => source.collectionPointer?.id === dataSourceId)
|
|
730
|
-
: undefined;
|
|
731
|
-
return toNotionPageFromNotionPageData({
|
|
732
|
-
page,
|
|
733
|
-
dataSource,
|
|
734
|
-
getDataSource: () => {
|
|
735
|
-
if (this.hostState.status !== "initialized" ||
|
|
736
|
-
dataSourceId === undefined) {
|
|
737
|
-
return undefined;
|
|
738
|
-
}
|
|
739
|
-
return this.hostState.dataSources.find(source => source.key === dataSource?.key &&
|
|
740
|
-
source.collectionPointer?.id === dataSourceId);
|
|
741
|
-
},
|
|
742
|
-
update: (payload, updateDataSourceId) => this.updatePage({ ...payload, pageId: page.id }, updateDataSourceId),
|
|
743
793
|
});
|
|
794
|
+
return result;
|
|
744
795
|
}
|
|
745
796
|
/**
|
|
746
797
|
* Translates the public `CreatePageArgs["parent"]` into the bridge-native
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CustomBlockQueryDataSourceErrorInfo } from "../../protocol/messages/queryDataSourceResult.js";
|
|
2
2
|
import type { SubscribeToDataSourceArgs } from "../../types.js";
|
|
3
|
-
export declare function subscribeToDataSource(
|
|
3
|
+
export declare function subscribeToDataSource(args: SubscribeToDataSourceArgs): () => void;
|
|
4
|
+
/** @deprecated Pass onError in the first argument instead. */
|
|
5
|
+
export declare function subscribeToDataSource(args: SubscribeToDataSourceArgs, onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void): () => void;
|
|
4
6
|
//# sourceMappingURL=subscribe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAQ/D,wBAAgB,qBAAqB,CACpC,EAAE,
|
|
1
|
+
{"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/subscribe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAQ/D,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,yBAAyB,GAC7B,MAAM,IAAI,CAAA;AACb,8DAA8D;AAC9D,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,yBAAyB,EAC/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,mCAAmC,KAAK,IAAI,GAC5D,MAAM,IAAI,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { notifyListener } from "../notifyListener.js";
|
|
2
2
|
import { customBlockDataSources, customBlockHost } from "../sandboxClient.js";
|
|
3
|
-
export function subscribeToDataSource({ key, onSnapshot, options: providedOptions = {} },
|
|
3
|
+
export function subscribeToDataSource({ key, onSnapshot, onError: providedOnError, options: providedOptions = {}, }, legacyOnError) {
|
|
4
|
+
const onError = providedOnError ?? legacyOnError;
|
|
4
5
|
const options = structuredClone(providedOptions);
|
|
5
6
|
const subscriptionId = customBlockDataSources.createSubscriptionId();
|
|
6
7
|
let active = true;
|
|
@@ -14,10 +15,17 @@ export function subscribeToDataSource({ key, onSnapshot, options: providedOption
|
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
17
|
const snapshot = customBlockDataSources.getView(hostState, key, subscriptionId);
|
|
18
|
+
const backingSourceChanged = lastSnapshotInputs !== undefined &&
|
|
19
|
+
lastSnapshotInputs.dataSource?.collectionPointer?.id !==
|
|
20
|
+
dataSource?.collectionPointer?.id;
|
|
17
21
|
// Record inputs before calling consumer code, which can trigger another notification.
|
|
18
22
|
lastSnapshotInputs = { status: hostState.status, dataSource, queryState };
|
|
19
23
|
const error = queryState?.error;
|
|
20
24
|
if (error && onError) {
|
|
25
|
+
if (backingSourceChanged) {
|
|
26
|
+
// Sync failures skip loading, so deliver the bridge's reset before the error.
|
|
27
|
+
notifyListener(() => onSnapshot(snapshot));
|
|
28
|
+
}
|
|
21
29
|
notifyListener(() => onError(error));
|
|
22
30
|
return;
|
|
23
31
|
}
|
package/dist/bridge/page.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import type { NotionDataSource } from "../protocol/dataSources/dataSource.js";
|
|
2
|
-
import type { NotionDataSourceId } from "../protocol/ids.js";
|
|
3
|
-
import type { BridgeMessagePayload } from "../protocol/messages/messagePayload.js";
|
|
4
|
-
import type { UpdatePageResultMessage } from "../protocol/messages/updatePageResult.js";
|
|
5
1
|
import type { notionPageDataSchema } from "../protocol/pages/page.js";
|
|
6
2
|
import type { InferOutput } from "valibot";
|
|
7
|
-
import type { NotionPage
|
|
3
|
+
import type { NotionPage } from "../types.js";
|
|
8
4
|
export declare function toNotionPageFromNotionPageData(args: {
|
|
9
5
|
page: InferOutput<typeof notionPageDataSchema>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
dataSourceKey: string | undefined;
|
|
7
|
+
getPropertyById: NotionPage["getPropertyById"];
|
|
8
|
+
getPropertyByKey: NotionPage["getPropertyByKey"];
|
|
9
|
+
updateById: NotionPage["updateById"];
|
|
10
|
+
updateByKey: NotionPage["updateByKey"];
|
|
13
11
|
}): NotionPage;
|
|
14
12
|
//# sourceMappingURL=page.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/bridge/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/bridge/page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAA;AAC1F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,wBAAgB,8BAA8B,CAAC,IAAI,EAAE;IACpD,IAAI,EAAE,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAA;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,eAAe,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC9C,gBAAgB,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAChD,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;IACpC,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACtC,GAAG,UAAU,CAWb"}
|
package/dist/bridge/page.js
CHANGED
|
@@ -1,59 +1,12 @@
|
|
|
1
1
|
export function toNotionPageFromNotionPageData(args) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.assign(sdkPage, result.page);
|
|
12
|
-
return { status: "success", page: sdkPage };
|
|
13
|
-
};
|
|
14
|
-
const result = pending ? pending.then(operation) : operation();
|
|
15
|
-
const finished = result.then(() => undefined, () => undefined);
|
|
16
|
-
pending = finished;
|
|
17
|
-
void finished.then(() => {
|
|
18
|
-
if (pending === finished) {
|
|
19
|
-
pending = undefined;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return result;
|
|
2
|
+
return {
|
|
3
|
+
...args.page,
|
|
4
|
+
dataSourceKey: args.dataSourceKey ?? null,
|
|
5
|
+
getPropertyById: args.getPropertyById,
|
|
6
|
+
getPropertyByKey: args.getPropertyByKey,
|
|
7
|
+
updateById: args.updateById,
|
|
8
|
+
updateByKey: args.updateByKey,
|
|
9
|
+
archive: () => args.updateById({ is_archived: true }),
|
|
10
|
+
unarchive: () => args.updateById({ is_archived: false }),
|
|
23
11
|
};
|
|
24
|
-
const updateById = (payload) => updatePage(payload, undefined);
|
|
25
|
-
const updateByKey = (payload) => {
|
|
26
|
-
const dataSourceId = dataSource?.collectionPointer?.id;
|
|
27
|
-
if (dataSourceId === undefined) {
|
|
28
|
-
return Promise.resolve({
|
|
29
|
-
status: "error",
|
|
30
|
-
error: {
|
|
31
|
-
code: "unmapped_data_source",
|
|
32
|
-
message: "This page has no bound data source context.",
|
|
33
|
-
isRetryable: false,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return updatePage(payload, dataSourceId);
|
|
38
|
-
};
|
|
39
|
-
const methods = {
|
|
40
|
-
getPropertyById,
|
|
41
|
-
getPropertyByKey: (key) => {
|
|
42
|
-
const source = args.getDataSource();
|
|
43
|
-
const id = source && Object.hasOwn(source.propertyIdsByKey, key)
|
|
44
|
-
? source.propertyIdsByKey[key]
|
|
45
|
-
: undefined;
|
|
46
|
-
return id === undefined ? null : getPropertyById(id);
|
|
47
|
-
},
|
|
48
|
-
updateById,
|
|
49
|
-
updateByKey,
|
|
50
|
-
archive: () => updateById({ is_archived: true }),
|
|
51
|
-
unarchive: () => updateById({ is_archived: false }),
|
|
52
|
-
};
|
|
53
|
-
const sdkPage = {
|
|
54
|
-
...bridgePage,
|
|
55
|
-
dataSourceKey: dataSource?.key ?? null,
|
|
56
|
-
...methods,
|
|
57
|
-
};
|
|
58
|
-
return sdkPage;
|
|
59
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACpF,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,
|
|
1
|
+
{"version":3,"file":"sandboxClient.d.ts","sourceRoot":"","sources":["../../src/bridge/sandboxClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mDAAmD,CAAA;AACpF,OAAO,KAAK,EACX,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EAEf,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,cAAc,EAEd,MAAM,aAAa,CAAA;AACpB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,aAAa,EACb,MAAM,oBAAoB,CAAA;AAI3B,wBAAgB,SAAS,IAAI,aAAa,CAKzC;AAED,eAAO,MAAM,eAAe;IAC3B,0BAA0B,gBACZ,kBAAkB,KAC7B,CAAC,MAAM,IAAI,CAAC;IAIf,WAAW,mBAAmB,kBAAkB;IAIhD,UAAU;IAEV,SAAS,aAAa,MAAM,IAAI;IAIhC,QAAQ,QAAM,oBAAoB;IAIlC;;;OAGG;IACH,YAAY,YAAY,WAAW;IAInC,sBAAsB;IAItB,UAAU,WAAW,MAAM;CAG3B,CAAA;AAED,eAAO,MAAM,sBAAsB;IAClC,oBAAoB;IAIpB,KAAK,SAAS,mBAAmB;IAIjC,OAAO,mBAAmB,MAAM;IAIhC,OAAO,cACK,oBAAoB,OAC1B,MAAM,kBACK,MAAM,KACpB,mBAAmB;CAiCtB,CAAA;AAED,eAAO,MAAM,UAAU;IACtB,WAAW,QAAM,SAAS,eAAe,EAAE;IAI3C,SAAS,aAAa,MAAM,IAAI;CAGhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,MAAM,UAAU,cAAc,KAAG,OAAO,CAAC,gBAAgB,CAAC;IAO1D;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;IAOnD;;OAEG;IACH,IAAI,WACK,YAAY,WACX,eAAe,KACtB,OAAO,CAAC,cAAc,CAAC;CAG1B,CAAA;AAED,sDAAsD;AACtD,eAAO,MAAM,KAAK;IACjB,gEAAgE;IAChE,IAAI,QAAQ,MAAM,KAAG,OAAO,CAAC,qBAAqB,CAAC;CAGnD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK;IACjB;;OAEG;IACH,IAAI,WAAW,aAAa,KAAG,OAAO,CAAC,eAAe,CAAC;IAIvD;;OAEG;IACH,GAAG,WAAW,YAAY,KAAG,OAAO,CAAC,aAAa,CAAC;CAGnD,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getDataSourceQueryView as getDataSourceQueryViewWithBridge, } from "./hostState.js";
|
|
2
|
+
import { toNotionPageFromNotionPageData } from "./page.js";
|
|
2
3
|
import { SandboxBridge, } from "./SandboxBridge.js";
|
|
3
4
|
let bridge;
|
|
4
5
|
export function getBridge() {
|
|
@@ -46,10 +47,26 @@ export const customBlockDataSources = {
|
|
|
46
47
|
getBridge().releaseDataSourceSubscription(subscriptionId);
|
|
47
48
|
},
|
|
48
49
|
getView: (hostState, key, subscriptionId) => {
|
|
49
|
-
return getDataSourceQueryViewWithBridge(hostState, key, subscriptionId, ({ page, dataSource }) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
return getDataSourceQueryViewWithBridge(hostState, key, subscriptionId, ({ page: pageData, dataSource }) => {
|
|
51
|
+
const bridge = getBridge();
|
|
52
|
+
const update = async (args) => {
|
|
53
|
+
const result = await bridge.updatePage(args);
|
|
54
|
+
if (result.status === "error") {
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
Object.assign(page, result.page);
|
|
58
|
+
return { status: "success", page };
|
|
59
|
+
};
|
|
60
|
+
const page = toNotionPageFromNotionPageData({
|
|
61
|
+
page: pageData,
|
|
62
|
+
dataSourceKey: key,
|
|
63
|
+
getPropertyById: propertyId => bridge.getPropertyById({ page, propertyId }),
|
|
64
|
+
getPropertyByKey: propertyKey => bridge.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
65
|
+
updateById: payload => update({ ...payload, pageId: page.id, dataSource: undefined }),
|
|
66
|
+
updateByKey: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
67
|
+
});
|
|
68
|
+
return page;
|
|
69
|
+
});
|
|
53
70
|
},
|
|
54
71
|
};
|
|
55
72
|
export const messageLog = {
|
|
@@ -68,13 +85,19 @@ export const pages = {
|
|
|
68
85
|
* Creates a new Notion page.
|
|
69
86
|
*/
|
|
70
87
|
create: (input) => {
|
|
71
|
-
return getBridge().createPage(
|
|
88
|
+
return getBridge().createPage({
|
|
89
|
+
...input,
|
|
90
|
+
dataSource: undefined,
|
|
91
|
+
});
|
|
72
92
|
},
|
|
73
93
|
/**
|
|
74
94
|
* Fetches a page by id.
|
|
75
95
|
*/
|
|
76
96
|
get: (pageId) => {
|
|
77
|
-
return getBridge().getPage(
|
|
97
|
+
return getBridge().getPage({
|
|
98
|
+
pageId,
|
|
99
|
+
dataSource: undefined,
|
|
100
|
+
});
|
|
78
101
|
},
|
|
79
102
|
/**
|
|
80
103
|
* Requests that the Notion host open a page.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataSources.d.ts","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAIhD,OAAO,KAAK,EACX,cAAc,EAEd,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,WAAW;IACjB,OAAO,MACP,MAAM,UACH,YAAY,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAW3B,MAAM,MACN,MAAM,WACF,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,GAClD,OAAO,CAAC,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"dataSources.d.ts","sourceRoot":"","sources":["../src/dataSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,YAAY,EACZ,MAAM,yCAAyC,CAAA;AAIhD,OAAO,KAAK,EACX,cAAc,EAEd,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,WAAW;IACjB,OAAO,MACP,MAAM,UACH,YAAY,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAW3B,MAAM,MACN,MAAM,WACF,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,UAAU,CAAC,GAClD,OAAO,CAAC,qBAAqB,CAAC;IAe3B,KAAK,MACL,MAAM,YACD,sBAAsB,GAC9B,OAAO,CAAC,sBAAsB,CAAC;CAsDlC,CAAA"}
|
package/dist/dataSources.js
CHANGED
|
@@ -7,8 +7,8 @@ export const dataSources = {
|
|
|
7
7
|
if (resolved.status === "error") {
|
|
8
8
|
return resolved;
|
|
9
9
|
}
|
|
10
|
-
const { dataSource
|
|
11
|
-
const result = await getBridge().getPage(pageId,
|
|
10
|
+
const { dataSource } = resolved;
|
|
11
|
+
const result = await getBridge().getPage({ pageId, dataSource });
|
|
12
12
|
return result.status === "error"
|
|
13
13
|
? result
|
|
14
14
|
: { ...result, propertyIdsByKey: dataSource.propertyIdsByKey };
|
|
@@ -22,7 +22,8 @@ export const dataSources = {
|
|
|
22
22
|
const result = await getBridge().createPage({
|
|
23
23
|
...payload,
|
|
24
24
|
parent: { type: "data_source_id", data_source_id: dataSourceId },
|
|
25
|
-
|
|
25
|
+
dataSource,
|
|
26
|
+
});
|
|
26
27
|
return result.status === "error"
|
|
27
28
|
? result
|
|
28
29
|
: { ...result, propertyIdsByKey: dataSource.propertyIdsByKey };
|
|
@@ -66,13 +67,14 @@ export const dataSources = {
|
|
|
66
67
|
unsubscribe();
|
|
67
68
|
resolve({ status: "success", ...snapshot });
|
|
68
69
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
onError: error => {
|
|
71
|
+
if (completed) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
completed = true;
|
|
75
|
+
unsubscribe();
|
|
76
|
+
resolve({ status: "error", error });
|
|
77
|
+
},
|
|
76
78
|
});
|
|
77
79
|
if (completed) {
|
|
78
80
|
unsubscribe();
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export type { NotionContrastMode } from "./protocol/contrast.js";
|
|
10
10
|
export type { NotionCollectionSchema, NotionDataSource, } from "./protocol/dataSources/dataSource.js";
|
|
11
|
+
export type { NotionDateReminder, NotionDateTimeReminder, NotionDisabledReminder, NotionTimeReminder, } from "./protocol/dataSources/dateValue.js";
|
|
11
12
|
export type { CustomBlockDataSourceResolutionErrorCode, CustomBlockDataSourceResolutionErrorInfo, CustomBlockPropertyErrorCode, CustomBlockPropertyErrorInfo, } from "./protocol/dataSources/errors.js";
|
|
12
13
|
export type { NotionDualProperty, NotionPropertyColor, NotionPropertyOption, NotionPropertySchema, NotionPropertyType, NotionStatusGroup, } from "./protocol/dataSources/propertySchema.js";
|
|
13
14
|
export { NOTION_PROPERTY_TYPES } from "./protocol/dataSources/propertySchema.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,YAAY,EACX,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,4DAA4D,CAAA;AACnE,YAAY,EACX,wCAAwC,EACxC,wCAAwC,EACxC,4BAA4B,EAC5B,4BAA4B,GAC5B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,gEAAgE,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gEAAgE,CAAA;AACtG,YAAY,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,YAAY,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACb,MAAM,yCAAyC,CAAA;AAChD,YAAY,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,GAChB,MAAM,8CAA8C,CAAA;AACrD,YAAY,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,YAAY,EACX,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,+DAA+D,CAAA;AACtE,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sDAAsD,CAAA;AAC7D,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sDAAsD,CAAA;AAC7D,YAAY,EACX,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,mDAAmD,CAAA;AAC1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,mDAAmD,CAAA;AAClG,YAAY,EACX,6BAA6B,EAC7B,6BAA6B,GAC7B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,mCAAmC,EACnC,mCAAmC,GACnC,MAAM,8DAA8D,CAAA;AACrE,YAAY,EACX,4BAA4B,EAC5B,4BAA4B,EAC5B,YAAY,GACZ,MAAM,uDAAuD,CAAA;AAC9D,YAAY,EACX,mCAAmC,EACnC,mCAAmC,GACnC,MAAM,oEAAoE,CAAA;AAC3E,YAAY,EACX,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,+DAA+D,CAAA;AACtE,YAAY,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,GAC1B,MAAM,gDAAgD,CAAA;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EACN,KAAK,sBAAsB,EAC3B,eAAe,EACf,gBAAgB,GAChB,MAAM,WAAW,CAAA;AAClB,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,YAAY,EACX,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,4DAA4D,CAAA;AACnE,YAAY,EACX,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,2DAA2D,CAAA;AAClE,YAAY,EACX,wCAAwC,EACxC,wCAAwC,EACxC,4BAA4B,EAC5B,4BAA4B,GAC5B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,gEAAgE,CAAA;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gEAAgE,CAAA;AACtG,YAAY,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,YAAY,EAAE,mBAAmB,EAAE,MAAM,+DAA+D,CAAA;AACxG,YAAY,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AACtF,YAAY,EACX,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,aAAa,GACb,MAAM,yCAAyC,CAAA;AAChD,YAAY,EACX,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,GAChB,MAAM,8CAA8C,CAAA;AACrD,YAAY,EAAE,wBAAwB,EAAE,MAAM,yDAAyD,CAAA;AACvG,YAAY,EACX,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,+DAA+D,CAAA;AACtE,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sDAAsD,CAAA;AAC7D,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,sDAAsD,CAAA;AAC7D,YAAY,EACX,kCAAkC,EAClC,kCAAkC,GAClC,MAAM,mDAAmD,CAAA;AAC1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,mDAAmD,CAAA;AAClG,YAAY,EACX,6BAA6B,EAC7B,6BAA6B,GAC7B,MAAM,wDAAwD,CAAA;AAC/D,YAAY,EACX,mCAAmC,EACnC,mCAAmC,GACnC,MAAM,8DAA8D,CAAA;AACrE,YAAY,EACX,4BAA4B,EAC5B,4BAA4B,EAC5B,YAAY,GACZ,MAAM,uDAAuD,CAAA;AAC9D,YAAY,EACX,mCAAmC,EACnC,mCAAmC,GACnC,MAAM,oEAAoE,CAAA;AAC3E,YAAY,EACX,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,+DAA+D,CAAA;AACtE,YAAY,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,uBAAuB,EACvB,0BAA0B,GAC1B,MAAM,gDAAgD,CAAA;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,YAAY,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EACN,KAAK,sBAAsB,EAC3B,eAAe,EACf,gBAAgB,GAChB,MAAM,WAAW,CAAA;AAClB,cAAc,YAAY,CAAA"}
|
|
@@ -11,10 +11,10 @@ export declare const notionTimeReminderSchema: v.ObjectSchema<{
|
|
|
11
11
|
readonly value: v.NumberSchema<undefined>;
|
|
12
12
|
}, undefined>;
|
|
13
13
|
export type NotionTimeReminder = v.InferOutput<typeof notionTimeReminderSchema>;
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const notionDisabledReminderSchema: v.ObjectSchema<{
|
|
15
15
|
readonly unit: v.LiteralSchema<"none", undefined>;
|
|
16
16
|
}, undefined>;
|
|
17
|
-
export type
|
|
17
|
+
export type NotionDisabledReminder = v.InferOutput<typeof notionDisabledReminderSchema>;
|
|
18
18
|
/**
|
|
19
19
|
* Possible types for a Notion `datetime` reminder.
|
|
20
20
|
*/
|
|
@@ -9,7 +9,9 @@ export const notionTimeReminderSchema = v.object({
|
|
|
9
9
|
unit: v.picklist(["hour", "minute"]),
|
|
10
10
|
value: v.number(),
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
// An omitted reminder can inherit the date property's default reminder.
|
|
13
|
+
// "none" explicitly disables reminders instead.
|
|
14
|
+
export const notionDisabledReminderSchema = v.object({
|
|
13
15
|
unit: v.literal("none"),
|
|
14
16
|
});
|
|
15
17
|
/**
|
|
@@ -19,25 +21,25 @@ export const notionDateTimeReminderSchema = v.union([
|
|
|
19
21
|
notionDateReminderSchema,
|
|
20
22
|
notionTimeReminderSchema,
|
|
21
23
|
]);
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
+
const dateOrDisabledReminder = v.optional(v.union([notionDateReminderSchema, notionDisabledReminderSchema]));
|
|
25
|
+
const dateTimeOrDisabledReminder = v.optional(v.union([notionDateTimeReminderSchema, notionDisabledReminderSchema]));
|
|
24
26
|
export const notionDateSchema = v.object({
|
|
25
27
|
type: v.literal("date"),
|
|
26
28
|
start_date: v.string(),
|
|
27
|
-
reminder:
|
|
29
|
+
reminder: dateOrDisabledReminder,
|
|
28
30
|
});
|
|
29
31
|
export const notionDateRangeSchema = v.object({
|
|
30
32
|
type: v.literal("daterange"),
|
|
31
33
|
start_date: v.string(),
|
|
32
34
|
end_date: v.string(),
|
|
33
|
-
reminder:
|
|
35
|
+
reminder: dateOrDisabledReminder,
|
|
34
36
|
});
|
|
35
37
|
export const notionDateTimeSchema = v.object({
|
|
36
38
|
type: v.literal("datetime"),
|
|
37
39
|
start_date: v.string(),
|
|
38
40
|
start_time: v.string(),
|
|
39
41
|
time_zone: v.optional(v.string()),
|
|
40
|
-
reminder:
|
|
42
|
+
reminder: dateTimeOrDisabledReminder,
|
|
41
43
|
});
|
|
42
44
|
export const notionDateTimeRangeSchema = v.object({
|
|
43
45
|
type: v.literal("datetimerange"),
|
|
@@ -46,7 +48,7 @@ export const notionDateTimeRangeSchema = v.object({
|
|
|
46
48
|
end_date: v.string(),
|
|
47
49
|
end_time: v.string(),
|
|
48
50
|
time_zone: v.optional(v.string()),
|
|
49
|
-
reminder:
|
|
51
|
+
reminder: dateTimeOrDisabledReminder,
|
|
50
52
|
});
|
|
51
53
|
/**
|
|
52
54
|
* Possible types for a Notion `date` value.
|