@notionhq/custom-blocks 0.3.2 → 0.3.4
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/LICENSE +21 -0
- package/README.md +13 -19
- package/dist/bridge/SandboxBridge.d.ts +0 -2
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +16 -39
- package/dist/bridge/SandboxInitialization.d.ts +1 -3
- package/dist/bridge/SandboxInitialization.d.ts.map +1 -1
- package/dist/bridge/SandboxInitialization.js +13 -15
- package/dist/bridge/appearance.d.ts +2 -10
- package/dist/bridge/appearance.d.ts.map +1 -1
- package/dist/bridge/appearance.js +2 -10
- package/dist/bridge/dataSources/query.d.ts +1 -2
- package/dist/bridge/dataSources/query.d.ts.map +1 -1
- package/dist/bridge/dataSources/query.js +15 -398
- package/dist/bridge/dataSources/queryFilter.d.ts +10 -0
- package/dist/bridge/dataSources/queryFilter.d.ts.map +1 -0
- package/dist/bridge/dataSources/queryFilter.js +123 -0
- package/dist/bridge/dataSources/resolveProperty.d.ts +1 -20
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolveProperty.js +37 -32
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts +10 -0
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolvePropertyAddress.js +55 -0
- package/dist/bridge/dataSources/resolveSorts.d.ts +10 -0
- package/dist/bridge/dataSources/resolveSorts.d.ts.map +1 -0
- package/dist/bridge/dataSources/resolveSorts.js +80 -0
- package/dist/bridge/hostState.d.ts +3 -7
- package/dist/bridge/hostState.d.ts.map +1 -1
- package/dist/bridge/hostState.js +0 -24
- package/dist/bridge/page.d.ts +9 -3
- package/dist/bridge/page.d.ts.map +1 -1
- package/dist/bridge/page.js +19 -2
- package/dist/bridge/readLocalManifest.d.ts +23 -0
- package/dist/bridge/readLocalManifest.d.ts.map +1 -0
- package/dist/bridge/readLocalManifest.js +46 -0
- package/dist/bridge/sandboxClient.d.ts +0 -2
- package/dist/bridge/sandboxClient.d.ts.map +1 -1
- package/dist/bridge/sandboxClient.js +50 -24
- package/dist/protocol/dataSources/dataSourcePage.d.ts +3 -4
- package/dist/protocol/dataSources/dataSourcePage.js +2 -3
- package/dist/protocol/index.d.ts +1 -0
- package/dist/protocol/index.js +1 -0
- package/dist/protocol/isLocalBlockServerUrl.d.ts +2 -0
- package/dist/protocol/isLocalBlockServerUrl.js +9 -0
- package/dist/protocol/messages/connect.d.ts +2 -2
- package/dist/protocol/messages/connect.js +2 -2
- package/dist/protocol/messages/createPage.d.ts +1 -1
- package/dist/protocol/messages/createPage.js +1 -1
- package/dist/protocol/messages/createPageResult.d.ts +3 -3
- package/dist/protocol/messages/createPageResult.js +4 -4
- package/dist/protocol/messages/getPage.d.ts +2 -2
- package/dist/protocol/messages/getPage.js +4 -4
- package/dist/protocol/messages/hostToSandbox.d.ts +3 -3
- package/dist/protocol/messages/hostToSandbox.js +10 -10
- package/dist/protocol/messages/init.d.ts +1 -1
- package/dist/protocol/messages/queryDataSource.d.ts +24 -0
- package/dist/protocol/messages/queryDataSource.js +2 -0
- package/dist/protocol/messages/queryDataSourceResult.d.ts +3 -3
- package/dist/protocol/messages/queryDataSourceResult.js +5 -5
- package/dist/protocol/messages/sandboxToHost.d.ts +8 -0
- package/dist/protocol/messages/updatePageResult.d.ts +3 -3
- package/dist/protocol/messages/updatePageResult.js +4 -4
- package/dist/protocol/pages/page.d.ts +4 -4
- package/dist/protocol/pages/page.js +2 -2
- package/dist/protocol/parent.d.ts +1 -1
- package/dist/protocol/protocolVersion.d.ts +3 -2
- package/dist/protocol/protocolVersion.js +4 -2
- package/dist/react/useDataSource.d.ts +2 -2
- package/dist/react/useDataSource.js +2 -2
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +6 -4
- package/docs/bridge-interceptors.md +4 -0
- package/docs/build-tools.md +58 -0
- package/docs/data-sources.md +24 -18
- package/docs/deployment.md +23 -36
- package/docs/errors.md +75 -52
- package/docs/lifecycle.md +10 -3
- package/docs/pages.md +84 -76
- package/docs/users.md +4 -4
- package/package.json +4 -19
- package/src/bridge/SandboxBridge.ts +18 -48
- package/src/bridge/SandboxInitialization.ts +14 -20
- package/src/bridge/appearance.ts +2 -10
- package/src/bridge/dataSources/query.ts +17 -530
- package/src/bridge/dataSources/queryFilter.ts +181 -0
- package/src/bridge/dataSources/resolveProperty.ts +48 -39
- package/src/bridge/dataSources/resolvePropertyAddress.ts +62 -0
- package/src/bridge/dataSources/resolveSorts.ts +107 -0
- package/src/bridge/hostState.ts +3 -43
- package/src/bridge/page.ts +28 -4
- package/src/bridge/readLocalManifest.ts +60 -0
- package/src/bridge/sandboxClient.ts +63 -38
- package/src/react/useDataSource.ts +2 -2
- package/src/types.ts +5 -5
- package/dist/bridge/loadManifest.d.ts +0 -21
- package/dist/bridge/loadManifest.d.ts.map +0 -1
- package/dist/bridge/loadManifest.js +0 -85
- package/src/bridge/loadManifest.ts +0 -114
|
@@ -5,33 +5,40 @@ function makePropertyError(code, message) {
|
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Resolves a public SDK property write map into the ID-keyed bridge shape.
|
|
8
|
-
*
|
|
9
|
-
* Identifiers in `properties` may be raw property IDs or data source property keys; the latter
|
|
10
|
-
* are looked up in the `dataSource`'s `propertyIdsByKey`. Each value is re-parsed through
|
|
11
|
-
* the page property value schema with its `id` rewritten to the resolved property ID.
|
|
8
|
+
* A data source makes every identifier a property key; without one, identifiers are raw IDs.
|
|
12
9
|
*/
|
|
13
10
|
export function resolvePropertyWriteMapForDataSource(args) {
|
|
14
|
-
const { dataSource, properties
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const { dataSource, properties } = args;
|
|
12
|
+
const parsedMap = v.safeParse(v.record(v.string(), v.unknown()), properties);
|
|
13
|
+
if (Array.isArray(properties) || !parsedMap.success) {
|
|
14
|
+
return {
|
|
15
|
+
status: "error",
|
|
16
|
+
error: makePropertyError("invalid_property_value", "Property maps must be objects."),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const resolvedProperties = Object.create(null);
|
|
20
|
+
for (const [identifier, value] of Object.entries(parsedMap.output)) {
|
|
21
|
+
const propertyIdResult = resolveWriteIdentifier({
|
|
18
22
|
dataSource,
|
|
19
23
|
identifier,
|
|
20
|
-
operationName,
|
|
21
24
|
});
|
|
22
25
|
if (propertyIdResult.status === "error") {
|
|
23
26
|
return propertyIdResult;
|
|
24
27
|
}
|
|
25
28
|
const propertyId = propertyIdResult.propertyId;
|
|
26
|
-
if (value
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
30
|
+
return {
|
|
31
|
+
status: "error",
|
|
32
|
+
error: makePropertyError("invalid_property_value", `Invalid value for property ${identifier}.`),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if ("id" in value && value.id !== undefined && value.id !== propertyId) {
|
|
29
36
|
return {
|
|
30
37
|
status: "error",
|
|
31
38
|
error: makePropertyError("property_id_mismatch", `Property ${identifier} resolved to ${propertyId} but value id was ${value.id}.`),
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
|
-
if (resolvedProperties
|
|
41
|
+
if (Object.hasOwn(resolvedProperties, propertyId)) {
|
|
35
42
|
return {
|
|
36
43
|
status: "error",
|
|
37
44
|
error: makePropertyError("duplicate_property", `Cannot set property ${propertyId} more than once.`),
|
|
@@ -52,25 +59,23 @@ export function resolvePropertyWriteMapForDataSource(args) {
|
|
|
52
59
|
return { status: "success", properties: resolvedProperties };
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
|
-
*
|
|
56
|
-
* a
|
|
62
|
+
* Resolves property keys when a data source is present and raw property IDs otherwise.
|
|
63
|
+
* Property keys require a bound, loaded property so an unresolved key cannot become a raw ID.
|
|
57
64
|
*/
|
|
58
|
-
|
|
59
|
-
const { dataSource, identifier
|
|
60
|
-
if (dataSource
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
return { status: "success", propertyId };
|
|
65
|
+
function resolveWriteIdentifier(args) {
|
|
66
|
+
const { dataSource, identifier } = args;
|
|
67
|
+
if (dataSource === undefined) {
|
|
68
|
+
return { status: "success", propertyId: identifier };
|
|
69
|
+
}
|
|
70
|
+
const propertyId = Object.hasOwn(dataSource.propertyIdsByKey, identifier)
|
|
71
|
+
? dataSource.propertyIdsByKey[identifier]
|
|
72
|
+
: undefined;
|
|
73
|
+
if (propertyId === undefined ||
|
|
74
|
+
!dataSource.collectionSchema?.propertiesById[propertyId]) {
|
|
75
|
+
return {
|
|
76
|
+
status: "error",
|
|
77
|
+
error: makePropertyError("unmapped_property", `Cannot resolve property key "${identifier}" on this page.`),
|
|
78
|
+
};
|
|
74
79
|
}
|
|
75
|
-
return { status: "success", propertyId
|
|
80
|
+
return { status: "success", propertyId };
|
|
76
81
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotionDataSource } from "../../protocol/dataSources/dataSource.js";
|
|
2
|
+
export declare function resolvePropertyAddress(value: Record<string, unknown>, dataSource: NotionDataSource): {
|
|
3
|
+
status: "ok";
|
|
4
|
+
propertyId: string;
|
|
5
|
+
propertyType: string;
|
|
6
|
+
} | {
|
|
7
|
+
status: "error";
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=resolvePropertyAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePropertyAddress.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/resolvePropertyAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAElG,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,UAAU,EAAE,gBAAgB,GAE1B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAsDpC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export function resolvePropertyAddress(value, dataSource) {
|
|
2
|
+
const hasKey = Object.hasOwn(value, "key");
|
|
3
|
+
const hasPropertyId = Object.hasOwn(value, "propertyId");
|
|
4
|
+
if (hasKey === hasPropertyId) {
|
|
5
|
+
return {
|
|
6
|
+
status: "error",
|
|
7
|
+
error: "Data source query filters and sorts must use exactly one of key or propertyId.",
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
let propertyId;
|
|
11
|
+
if (hasKey) {
|
|
12
|
+
if (typeof value.key !== "string") {
|
|
13
|
+
return {
|
|
14
|
+
status: "error",
|
|
15
|
+
error: "Data source query property key must be a string.",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (!Object.hasOwn(dataSource.propertyIdsByKey, value.key)) {
|
|
19
|
+
return {
|
|
20
|
+
status: "error",
|
|
21
|
+
error: `Unknown property key "${value.key}" for data source "${dataSource.key}".`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const resolvedPropertyId = dataSource.propertyIdsByKey[value.key];
|
|
25
|
+
if (resolvedPropertyId === undefined) {
|
|
26
|
+
return {
|
|
27
|
+
status: "error",
|
|
28
|
+
error: `Property key "${value.key}" for data source "${dataSource.key}" is not bound.`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
propertyId = resolvedPropertyId;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (typeof value.propertyId !== "string") {
|
|
35
|
+
return {
|
|
36
|
+
status: "error",
|
|
37
|
+
error: "Data source query propertyId must be a string.",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
propertyId = value.propertyId;
|
|
41
|
+
}
|
|
42
|
+
const properties = dataSource.collectionSchema?.propertiesById ?? {};
|
|
43
|
+
if (!Object.hasOwn(properties, propertyId)) {
|
|
44
|
+
return {
|
|
45
|
+
status: "error",
|
|
46
|
+
error: `Unknown property ID "${propertyId}" for data source "${dataSource.key}".`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const propertySchema = properties[propertyId];
|
|
50
|
+
return {
|
|
51
|
+
status: "ok",
|
|
52
|
+
propertyId,
|
|
53
|
+
propertyType: propertySchema.type,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NotionDataSource } from "../../protocol/dataSources/dataSource.js";
|
|
2
|
+
import { type ResolvedCustomBlockDataSourceSort } from "../../protocol/messages/queryDataSource.js";
|
|
3
|
+
export declare function resolveSorts(sorts: unknown, dataSource: NotionDataSource): {
|
|
4
|
+
status: "ok";
|
|
5
|
+
sorts?: ResolvedCustomBlockDataSourceSort[];
|
|
6
|
+
} | {
|
|
7
|
+
status: "error";
|
|
8
|
+
error: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=resolveSorts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSorts.d.ts","sourceRoot":"","sources":["../../../src/bridge/dataSources/resolveSorts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAGlG,OAAO,EAEN,KAAK,iCAAiC,EACtC,MAAM,8DAA8D,CAAA;AAQrE,wBAAgB,YAAY,CAC3B,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,gBAAgB,GAE1B;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,KAAK,CAAC,EAAE,iCAAiC,EAAE,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAqCpC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES } from "../../protocol/dataSources/propertySchema.js";
|
|
2
|
+
import { notionSortDirectionSchema } from "../../protocol/dataSources/sortDirection.js";
|
|
3
|
+
import { CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS, } from "../../protocol/messages/queryDataSource.js";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
import { resolvePropertyAddress } from "./resolvePropertyAddress.js";
|
|
6
|
+
const supportedDataSourceSortPropertyTypes = new Set(CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES);
|
|
7
|
+
export function resolveSorts(sorts, dataSource) {
|
|
8
|
+
if (sorts === undefined) {
|
|
9
|
+
return { status: "ok" };
|
|
10
|
+
}
|
|
11
|
+
if (!Array.isArray(sorts)) {
|
|
12
|
+
return {
|
|
13
|
+
status: "error",
|
|
14
|
+
error: "Data source query sorts must be an array.",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (sorts.length === 0) {
|
|
18
|
+
return { status: "ok" };
|
|
19
|
+
}
|
|
20
|
+
if (sorts.length > CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS) {
|
|
21
|
+
return {
|
|
22
|
+
status: "error",
|
|
23
|
+
error: `Data source query sorts may contain at most ${CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS} entries.`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const resolvedSorts = [];
|
|
27
|
+
const seenPropertyIds = new Set();
|
|
28
|
+
for (const sort of sorts) {
|
|
29
|
+
const resolved = resolveSort(sort, dataSource);
|
|
30
|
+
if (resolved.status === "error") {
|
|
31
|
+
return resolved;
|
|
32
|
+
}
|
|
33
|
+
if (seenPropertyIds.has(resolved.sort.propertyId)) {
|
|
34
|
+
return {
|
|
35
|
+
status: "error",
|
|
36
|
+
error: `Data source query sorts cannot contain duplicate property ID "${resolved.sort.propertyId}".`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
seenPropertyIds.add(resolved.sort.propertyId);
|
|
40
|
+
resolvedSorts.push(resolved.sort);
|
|
41
|
+
}
|
|
42
|
+
return { status: "ok", sorts: resolvedSorts };
|
|
43
|
+
}
|
|
44
|
+
function resolveSort(sort, dataSource) {
|
|
45
|
+
if (typeof sort !== "object" || sort === null || Array.isArray(sort)) {
|
|
46
|
+
return {
|
|
47
|
+
status: "error",
|
|
48
|
+
error: "Data source query sort must be an object.",
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const sortObject = sort;
|
|
52
|
+
if (Object.keys(sortObject).some(key => !["key", "propertyId", "direction"].includes(key))) {
|
|
53
|
+
return {
|
|
54
|
+
status: "error",
|
|
55
|
+
error: "Data source query sort contains unsupported fields.",
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const property = resolvePropertyAddress(sortObject, dataSource);
|
|
59
|
+
if (property.status === "error") {
|
|
60
|
+
return property;
|
|
61
|
+
}
|
|
62
|
+
if (!supportedDataSourceSortPropertyTypes.has(property.propertyType)) {
|
|
63
|
+
return {
|
|
64
|
+
status: "error",
|
|
65
|
+
error: `Data source query sorts do not yet support property type "${property.propertyType}".`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const direction = sortObject.direction;
|
|
69
|
+
if (!Object.hasOwn(sortObject, "direction") ||
|
|
70
|
+
!v.is(notionSortDirectionSchema, direction)) {
|
|
71
|
+
return {
|
|
72
|
+
status: "error",
|
|
73
|
+
error: 'Data source query sort direction must be "ascending" or "descending".',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
status: "ok",
|
|
78
|
+
sort: { propertyId: property.propertyId, direction },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -3,12 +3,12 @@ import type { NotionDataSource } from "../protocol/dataSources/dataSource.js";
|
|
|
3
3
|
import type { NotionBlockId } from "../protocol/ids.js";
|
|
4
4
|
import type { CustomBlockManifest } from "../protocol/manifest.js";
|
|
5
5
|
import type { CustomBlockQueryDataSourceErrorInfo } from "../protocol/messages/queryDataSourceResult.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { bridgePageSchema, CustomBlockPage } from "../protocol/pages/page.js";
|
|
7
7
|
import type { NotionParent } from "../protocol/parent.js";
|
|
8
8
|
import type { NotionTheme } from "../protocol/theme.js";
|
|
9
9
|
import type { NotionUser } from "../protocol/users/user.js";
|
|
10
10
|
import type { InferOutput } from "valibot";
|
|
11
|
-
import type { DataSourceSnapshot
|
|
11
|
+
import type { DataSourceSnapshot } from "../types.js";
|
|
12
12
|
export type CustomBlockHostState = UninitializedHostState | InitializedHostState;
|
|
13
13
|
export type UninitializedHostState = {
|
|
14
14
|
status: "uninitialized";
|
|
@@ -30,7 +30,7 @@ export type InitializedHostState = {
|
|
|
30
30
|
export type DataSourceQueryState = {
|
|
31
31
|
dataSourceKey: string;
|
|
32
32
|
/** Latest pages from the host as parsed from the bridge. */
|
|
33
|
-
items: InferOutput<typeof
|
|
33
|
+
items: InferOutput<typeof bridgePageSchema>[];
|
|
34
34
|
isLoading: boolean;
|
|
35
35
|
hasMore: boolean;
|
|
36
36
|
error?: CustomBlockQueryDataSourceErrorInfo;
|
|
@@ -39,8 +39,4 @@ export type DataSourceQueryState = {
|
|
|
39
39
|
};
|
|
40
40
|
export declare function createEmptyDataSourceQueryState(dataSourceKey: string): DataSourceQueryState;
|
|
41
41
|
export type DataSourceQueryView = DataSourceSnapshot;
|
|
42
|
-
export declare function getDataSourceQueryView(hostState: CustomBlockHostState, key: string, subscriptionId: string, createNotionPage: (args: {
|
|
43
|
-
page: InferOutput<typeof notionPageDataSchema>;
|
|
44
|
-
dataSource: NotionDataSource | undefined;
|
|
45
|
-
}) => NotionPage): DataSourceQueryView;
|
|
46
42
|
//# sourceMappingURL=hostState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hostState.d.ts","sourceRoot":"","sources":["../../src/bridge/hostState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EACX,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"hostState.d.ts","sourceRoot":"","sources":["../../src/bridge/hostState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAA;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAA;AACvF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,oEAAoE,CAAA;AAC7H,OAAO,KAAK,EACX,gBAAgB,EAChB,eAAe,EACf,MAAM,gDAAgD,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAA;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,GAAG,oBAAoB,CAAA;AAEhF,MAAM,MAAM,sBAAsB,GAAG;IACpC,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,EAAE,kBAAkB,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,WAAW,CAAA;IAClB,YAAY,EAAE,kBAAkB,CAAA;IAChC,OAAO,EAAE,aAAa,CAAA;IACtB,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,eAAe,CAAA;IACrB,WAAW,EAAE,UAAU,CAAA;IACvB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,WAAW,EAAE,gBAAgB,EAAE,CAAA;IAC/B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAA;CACrD,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAA;IACrB,4DAA4D;IAC5D,KAAK,EAAE,WAAW,CAAC,OAAO,gBAAgB,CAAC,EAAE,CAAA;IAC7C,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,mCAAmC,CAAA;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAED,wBAAgB,+BAA+B,CAC9C,aAAa,EAAE,MAAM,GACnB,oBAAoB,CAOtB;AAED,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,CAAA"}
|
package/dist/bridge/hostState.js
CHANGED
|
@@ -6,27 +6,3 @@ export function createEmptyDataSourceQueryState(dataSourceKey) {
|
|
|
6
6
|
hasMore: false,
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
const EMPTY_QUERY_VIEW = {
|
|
10
|
-
items: [],
|
|
11
|
-
propertyIdsByKey: {},
|
|
12
|
-
isLoading: false,
|
|
13
|
-
hasMore: false,
|
|
14
|
-
};
|
|
15
|
-
export function getDataSourceQueryView(hostState, key, subscriptionId, createNotionPage) {
|
|
16
|
-
if (hostState.status !== "initialized") {
|
|
17
|
-
return EMPTY_QUERY_VIEW;
|
|
18
|
-
}
|
|
19
|
-
const dataSource = hostState.dataSources.find(entry => entry.key === key);
|
|
20
|
-
const subscriptionState = hostState.dataSourceState[subscriptionId];
|
|
21
|
-
const queryState = subscriptionState?.dataSourceKey === key
|
|
22
|
-
? subscriptionState
|
|
23
|
-
: createEmptyDataSourceQueryState(key);
|
|
24
|
-
return {
|
|
25
|
-
items: dataSource === undefined
|
|
26
|
-
? []
|
|
27
|
-
: queryState.items.map(entry => createNotionPage({ page: entry, dataSource })),
|
|
28
|
-
propertyIdsByKey: dataSource?.propertyIdsByKey ?? {},
|
|
29
|
-
isLoading: queryState.isLoading,
|
|
30
|
-
hasMore: queryState.hasMore,
|
|
31
|
-
};
|
|
32
|
-
}
|
package/dist/bridge/page.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NotionDataSource } from "../protocol/dataSources/dataSource.js";
|
|
2
|
+
import type { bridgePageSchema } from "../protocol/pages/page.js";
|
|
2
3
|
import type { InferOutput } from "valibot";
|
|
3
4
|
import type { NotionPage } from "../types.js";
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
5
|
+
export declare function toNotionPageFromBridgePage(args: {
|
|
6
|
+
bridgePage: InferOutput<typeof bridgePageSchema>;
|
|
6
7
|
dataSourceKey: string | undefined;
|
|
7
8
|
getPropertyById: NotionPage["getPropertyById"];
|
|
8
9
|
getPropertyByKey: NotionPage["getPropertyByKey"];
|
|
9
10
|
updateById: NotionPage["updateById"];
|
|
10
11
|
updateByKey: NotionPage["updateByKey"];
|
|
11
12
|
}): NotionPage;
|
|
13
|
+
/** Prevents key-based property updates from falling back to raw IDs without data source context. */
|
|
14
|
+
export declare function makeUpdatePageByKey(args: {
|
|
15
|
+
dataSource: NotionDataSource | undefined;
|
|
16
|
+
update: NotionPage["updateByKey"];
|
|
17
|
+
}): NotionPage["updateByKey"];
|
|
12
18
|
//# 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,gBAAgB,EAAE,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAChD,UAAU,EAAE,WAAW,CAAC,OAAO,gBAAgB,CAAC,CAAA;IAChD,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;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IACzC,UAAU,EAAE,gBAAgB,GAAG,SAAS,CAAA;IACxC,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACjC,GAAG,UAAU,CAAC,aAAa,CAAC,CAiB5B"}
|
package/dist/bridge/page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function
|
|
1
|
+
export function toNotionPageFromBridgePage(args) {
|
|
2
2
|
return {
|
|
3
|
-
...args.
|
|
3
|
+
...args.bridgePage,
|
|
4
4
|
dataSourceKey: args.dataSourceKey ?? null,
|
|
5
5
|
getPropertyById: args.getPropertyById,
|
|
6
6
|
getPropertyByKey: args.getPropertyByKey,
|
|
@@ -10,3 +10,20 @@ export function toNotionPageFromNotionPageData(args) {
|
|
|
10
10
|
unarchive: () => args.updateById({ is_archived: false }),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
+
/** Prevents key-based property updates from falling back to raw IDs without data source context. */
|
|
14
|
+
export function makeUpdatePageByKey(args) {
|
|
15
|
+
return async (payload) => {
|
|
16
|
+
if (args.dataSource === undefined &&
|
|
17
|
+
Object.keys(payload.properties ?? {}).length > 0) {
|
|
18
|
+
return {
|
|
19
|
+
status: "error",
|
|
20
|
+
error: {
|
|
21
|
+
code: "unmapped_property",
|
|
22
|
+
message: "Key-based property updates require data source context.",
|
|
23
|
+
isRetryable: false,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return args.update(payload);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CustomBlockErrorInfo } from "../protocol/errors.js";
|
|
2
|
+
import { type CustomBlockManifest } from "../protocol/manifest.js";
|
|
3
|
+
export type LocalManifestReadResult = {
|
|
4
|
+
status: "success";
|
|
5
|
+
manifest: CustomBlockManifest | undefined;
|
|
6
|
+
} | {
|
|
7
|
+
status: "error";
|
|
8
|
+
error: CustomBlockErrorInfo<"manifest_invalid">;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads and validates JSON from the script with ID `notion-custom-block-manifest`
|
|
12
|
+
* and type `application/json`, injected into the block HTML by dev tooling.
|
|
13
|
+
* The SDK sends this declaration in `connect` so the host can prepare bindings.
|
|
14
|
+
*
|
|
15
|
+
* The URL check limits this development metadata to supported local block servers.
|
|
16
|
+
* Deployed blocks receive their manifest from the host in `init`. Reading this
|
|
17
|
+
* metadata uses the current document and makes no network request.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readLocalManifest(args: {
|
|
20
|
+
document: Document;
|
|
21
|
+
url: URL;
|
|
22
|
+
}): LocalManifestReadResult;
|
|
23
|
+
//# sourceMappingURL=readLocalManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readLocalManifest.d.ts","sourceRoot":"","sources":["../../src/bridge/readLocalManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAA;AAEtF,OAAO,EACN,KAAK,mBAAmB,EAExB,MAAM,8CAA8C,CAAA;AAGrD,MAAM,MAAM,uBAAuB,GAChC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,CAAA;CAAE,GAChE;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,CAAA;CAAE,CAAA;AAEvE;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACvC,QAAQ,EAAE,QAAQ,CAAA;IAClB,GAAG,EAAE,GAAG,CAAA;CACR,GAAG,uBAAuB,CAwB1B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isLocalBlockServerUrl } from "../protocol/isLocalBlockServerUrl.js";
|
|
2
|
+
import { manifestSchema, } from "../protocol/manifest.js";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
/**
|
|
5
|
+
* Reads and validates JSON from the script with ID `notion-custom-block-manifest`
|
|
6
|
+
* and type `application/json`, injected into the block HTML by dev tooling.
|
|
7
|
+
* The SDK sends this declaration in `connect` so the host can prepare bindings.
|
|
8
|
+
*
|
|
9
|
+
* The URL check limits this development metadata to supported local block servers.
|
|
10
|
+
* Deployed blocks receive their manifest from the host in `init`. Reading this
|
|
11
|
+
* metadata uses the current document and makes no network request.
|
|
12
|
+
*/
|
|
13
|
+
export function readLocalManifest(args) {
|
|
14
|
+
if (!isLocalBlockServerUrl(args.url)) {
|
|
15
|
+
return { status: "success", manifest: undefined };
|
|
16
|
+
}
|
|
17
|
+
const metadata = args.document.getElementById("notion-custom-block-manifest");
|
|
18
|
+
if (metadata === null) {
|
|
19
|
+
return { status: "success", manifest: undefined };
|
|
20
|
+
}
|
|
21
|
+
if (metadata.tagName !== "SCRIPT" ||
|
|
22
|
+
metadata.getAttribute("type") !== "application/json") {
|
|
23
|
+
return invalidManifest();
|
|
24
|
+
}
|
|
25
|
+
let input;
|
|
26
|
+
try {
|
|
27
|
+
input = JSON.parse(metadata.textContent ?? "");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return invalidManifest();
|
|
31
|
+
}
|
|
32
|
+
const parsed = v.safeParse(manifestSchema, input);
|
|
33
|
+
return parsed.success
|
|
34
|
+
? { status: "success", manifest: parsed.output }
|
|
35
|
+
: invalidManifest();
|
|
36
|
+
}
|
|
37
|
+
function invalidManifest() {
|
|
38
|
+
return {
|
|
39
|
+
status: "error",
|
|
40
|
+
error: {
|
|
41
|
+
code: "manifest_invalid",
|
|
42
|
+
message: "The local custom block metadata is not a valid manifest.",
|
|
43
|
+
isRetryable: false,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -2,13 +2,11 @@ import type { NotionPageId } from "../protocol/ids.js";
|
|
|
2
2
|
import type { InitMessage } from "../protocol/messages/init.js";
|
|
3
3
|
import type { CreatePageArgs, CreatePageResult, GetPageResult, GetUserResult, ListUsersArgs, ListUsersResult, NotionUserId, OpenExternalUrlResult, OpenPageOptions, OpenPageResult } from "../types.js";
|
|
4
4
|
import { type CustomBlockHostState, type DataSourceQueryView } from "./hostState.js";
|
|
5
|
-
import type { ManifestLoadResult } from "./loadManifest.js";
|
|
6
5
|
import type { MessageInterceptor } from "./messageInterceptor.js";
|
|
7
6
|
import { type MessageLogEntry, type QueryDataSourceArgs, SandboxBridge } from "./SandboxBridge.js";
|
|
8
7
|
export declare function getBridge(): SandboxBridge;
|
|
9
8
|
export declare const customBlockHost: {
|
|
10
9
|
registerMessageInterceptor: (interceptor: MessageInterceptor) => (() => void);
|
|
11
|
-
sendConnect: (manifestResult: ManifestLoadResult) => void;
|
|
12
10
|
initialize: () => Promise<import("../initTypes.js").CustomBlockInitPayload>;
|
|
13
11
|
subscribe: (listener: () => void) => () => boolean;
|
|
14
12
|
getState: () => CustomBlockHostState;
|
|
@@ -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,EAEf,YAAY,EACZ,qBAAqB,EACrB,eAAe,EACf,cAAc,EAEd,MAAM,aAAa,CAAA;AACpB,OAAO,EACN,KAAK,oBAAoB,
|
|
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,EAEzB,KAAK,mBAAmB,EACxB,MAAM,gBAAgB,CAAA;AACvB,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,UAAU;IAEV,SAAS,aAAa,MAAM,IAAI;IAIhC,QAAQ,QAAM,oBAAoB;IAIlC;;;OAGG;IACH,YAAY,YAAY,WAAW;IAInC,sBAAsB;IAItB,UAAU,WAAW,MAAM;CAG3B,CAAA;AASD,eAAO,MAAM,sBAAsB;IAClC,oBAAoB;IAIpB,KAAK,SAAS,mBAAmB;IAIjC,OAAO,mBAAmB,MAAM;IAIhC,OAAO,cACK,oBAAoB,OAC1B,MAAM,kBACK,MAAM,KACpB,mBAAmB;CAwDtB,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,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createEmptyDataSourceQueryState, } from "./hostState.js";
|
|
2
|
+
import { makeUpdatePageByKey, toNotionPageFromBridgePage } from "./page.js";
|
|
3
3
|
import { SandboxBridge, } from "./SandboxBridge.js";
|
|
4
4
|
let bridge;
|
|
5
5
|
export function getBridge() {
|
|
@@ -12,9 +12,6 @@ export const customBlockHost = {
|
|
|
12
12
|
registerMessageInterceptor: (interceptor) => {
|
|
13
13
|
return getBridge().registerMessageInterceptor(interceptor);
|
|
14
14
|
},
|
|
15
|
-
sendConnect: (manifestResult) => {
|
|
16
|
-
getBridge().sendConnect(manifestResult);
|
|
17
|
-
},
|
|
18
15
|
initialize: () => getBridge().initialize(),
|
|
19
16
|
subscribe: (listener) => {
|
|
20
17
|
return getBridge().subscribe(listener);
|
|
@@ -36,6 +33,12 @@ export const customBlockHost = {
|
|
|
36
33
|
getBridge().postResize(height);
|
|
37
34
|
},
|
|
38
35
|
};
|
|
36
|
+
const EMPTY_QUERY_VIEW = {
|
|
37
|
+
items: [],
|
|
38
|
+
propertyIdsByKey: {},
|
|
39
|
+
isLoading: false,
|
|
40
|
+
hasMore: false,
|
|
41
|
+
};
|
|
39
42
|
export const customBlockDataSources = {
|
|
40
43
|
createSubscriptionId: () => {
|
|
41
44
|
return getBridge().createDataSourceSubscriptionId();
|
|
@@ -47,26 +50,49 @@ export const customBlockDataSources = {
|
|
|
47
50
|
getBridge().releaseDataSourceSubscription(subscriptionId);
|
|
48
51
|
},
|
|
49
52
|
getView: (hostState, key, subscriptionId) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
if (hostState.status !== "initialized") {
|
|
54
|
+
return EMPTY_QUERY_VIEW;
|
|
55
|
+
}
|
|
56
|
+
const dataSource = hostState.dataSources.find(entry => entry.key === key);
|
|
57
|
+
const subscriptionState = hostState.dataSourceState[subscriptionId];
|
|
58
|
+
const queryState = subscriptionState?.dataSourceKey === key
|
|
59
|
+
? subscriptionState
|
|
60
|
+
: createEmptyDataSourceQueryState(key);
|
|
61
|
+
const items = dataSource === undefined
|
|
62
|
+
? []
|
|
63
|
+
: queryState.items.map(bridgePage => {
|
|
64
|
+
const bridge = getBridge();
|
|
65
|
+
const update = async (args) => {
|
|
66
|
+
const result = await bridge.updatePage(args);
|
|
67
|
+
if (result.status === "error") {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
Object.assign(page, result.page);
|
|
71
|
+
return { status: "success", page };
|
|
72
|
+
};
|
|
73
|
+
const page = toNotionPageFromBridgePage({
|
|
74
|
+
bridgePage,
|
|
75
|
+
dataSourceKey: key,
|
|
76
|
+
getPropertyById: propertyId => bridge.getPropertyById({ page, propertyId }),
|
|
77
|
+
getPropertyByKey: propertyKey => bridge.getPropertyByKey({ page, dataSource, propertyKey }),
|
|
78
|
+
updateById: payload => update({
|
|
79
|
+
...payload,
|
|
80
|
+
pageId: page.id,
|
|
81
|
+
dataSource: undefined,
|
|
82
|
+
}),
|
|
83
|
+
updateByKey: makeUpdatePageByKey({
|
|
84
|
+
dataSource,
|
|
85
|
+
update: payload => update({ ...payload, pageId: page.id, dataSource }),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
return page;
|
|
67
89
|
});
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
return {
|
|
91
|
+
items,
|
|
92
|
+
propertyIdsByKey: dataSource?.propertyIdsByKey ?? {},
|
|
93
|
+
isLoading: queryState.isLoading,
|
|
94
|
+
hasMore: queryState.hasMore,
|
|
95
|
+
};
|
|
70
96
|
},
|
|
71
97
|
};
|
|
72
98
|
export const messageLog = {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* properties by raw property ID. Only actual schema properties are included.
|
|
3
|
+
* Query page shape for protocols 3–5, with flat values keyed by raw property ID.
|
|
5
4
|
*/
|
|
6
|
-
export declare const
|
|
5
|
+
export declare const notionDataSourcePageForProtocol3To5Schema: v.ObjectSchema<{
|
|
7
6
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
8
7
|
/** Whether the page or an ancestor is archived. */
|
|
9
8
|
readonly is_archived: v.BooleanSchema<undefined>;
|
|
@@ -71,4 +70,4 @@ export declare const legacyNotionDataSourcePageBridgeSchema: v.ObjectSchema<{
|
|
|
71
70
|
readonly table: v.StringSchema<undefined>;
|
|
72
71
|
}, undefined>, undefined>], undefined>, undefined>, undefined>;
|
|
73
72
|
}, undefined>;
|
|
74
|
-
export type
|
|
73
|
+
export type NotionDataSourcePageForProtocol3To5 = v.InferOutput<typeof notionDataSourcePageForProtocol3To5Schema>;
|
|
@@ -2,10 +2,9 @@ import * as v from "valibot";
|
|
|
2
2
|
import { notionPageIdSchema } from "../ids.js";
|
|
3
3
|
import { notionDataSourceValueSchema } from "./dataSourceValue.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* properties by raw property ID. Only actual schema properties are included.
|
|
5
|
+
* Query page shape for protocols 3–5, with flat values keyed by raw property ID.
|
|
7
6
|
*/
|
|
8
|
-
export const
|
|
7
|
+
export const notionDataSourcePageForProtocol3To5Schema = v.object({
|
|
9
8
|
id: notionPageIdSchema,
|
|
10
9
|
/** Whether the page or an ancestor is archived. */
|
|
11
10
|
is_archived: v.boolean(),
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./dataSources/recordPointer.js";
|
|
|
16
16
|
export * from "./dataSources/sortDirection.js";
|
|
17
17
|
export * from "./errors.js";
|
|
18
18
|
export * from "./ids.js";
|
|
19
|
+
export { isLocalBlockServerUrl } from "./isLocalBlockServerUrl.js";
|
|
19
20
|
export * from "./manifest.js";
|
|
20
21
|
export * from "./messages/connect.js";
|
|
21
22
|
export * from "./messages/contrastModeChanged.js";
|