@notionhq/custom-blocks 0.2.15 → 0.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge/SandboxBridge.d.ts +7 -8
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +49 -44
- package/dist/bridge/dataSources/query.d.ts +2 -1
- package/dist/bridge/dataSources/query.d.ts.map +1 -1
- package/dist/bridge/dataSources/query.js +39 -8
- package/dist/bridge/dataSources/resolve.d.ts +10 -10
- package/dist/bridge/dataSources/resolve.d.ts.map +1 -1
- package/dist/bridge/dataSources/resolve.js +17 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol/dataSources/dataSource.d.ts +61 -6
- package/dist/protocol/dataSources/dataSource.js +35 -6
- package/dist/protocol/dataSources/propertySchema.d.ts +2 -0
- package/dist/protocol/dataSources/propertySchema.js +7 -0
- package/dist/protocol/messages/createPageResult.d.ts +1 -1
- package/dist/protocol/messages/getPage.d.ts +1 -1
- package/dist/protocol/messages/hostToSandbox.d.ts +10 -4
- package/dist/protocol/messages/init.d.ts +5 -2
- package/dist/protocol/messages/openPage.d.ts +1 -1
- package/dist/protocol/messages/pageChanged.d.ts +5 -2
- package/dist/protocol/messages/queryDataSource.d.ts +485 -485
- package/dist/protocol/messages/queryDataSource.js +43 -43
- package/dist/protocol/messages/queryDataSourceResult.d.ts +1 -1
- package/dist/protocol/messages/sandboxToHost.d.ts +178 -178
- package/dist/protocol/messages/updatePageResult.d.ts +1 -1
- package/dist/protocol/pages/page.d.ts +5 -2
- package/dist/protocol/pages/page.js +15 -9
- package/dist/protocol/protocolVersion.d.ts +1 -1
- package/dist/protocol/protocolVersion.js +1 -1
- package/dist/react/standalonePreview.d.ts.map +1 -1
- package/dist/react/standalonePreview.js +5 -1
- package/dist/typeUtils.d.ts +10 -0
- package/dist/typeUtils.d.ts.map +1 -0
- package/dist/typeUtils.js +1 -0
- package/dist/types.d.ts +18 -15
- package/dist/types.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/docs/block-location.md +28 -15
- package/docs/data-sources.md +60 -35
- package/docs/errors.md +17 -1
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +62 -50
- package/src/bridge/dataSources/query.ts +47 -9
- package/src/bridge/dataSources/resolve.ts +30 -13
- package/src/index.ts +1 -0
- package/src/react/standalonePreview.ts +5 -1
- package/src/typeUtils.ts +10 -0
- package/src/types.ts +22 -16
|
@@ -8,30 +8,59 @@ const collectionPointerValidator = v.object({
|
|
|
8
8
|
});
|
|
9
9
|
export const notionCollectionSchemaValidator = v.object({
|
|
10
10
|
id: v.optional(notionDataSourceIdSchema),
|
|
11
|
+
/**
|
|
12
|
+
* Describes actual database properties in protocol 5. Protocol 3/4 payloads can also include
|
|
13
|
+
* synthetic metadata for compatibility. Use this map to resolve property bindings. Use this map
|
|
14
|
+
* to validate filter and sort references.
|
|
15
|
+
*/
|
|
11
16
|
propertiesById: v.record(v.string(), notionPropertySchemaSchema),
|
|
12
17
|
});
|
|
13
18
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
19
|
+
* Describes a data source, its optional database binding, and its property schemas. The
|
|
20
|
+
* database schema validates query references. The read schemas describe snapshot values.
|
|
16
21
|
*/
|
|
17
22
|
export const notionDataSourceSchema = v.object({
|
|
18
23
|
key: v.string(),
|
|
19
24
|
collectionPointer: v.optional(collectionPointerValidator),
|
|
25
|
+
/**
|
|
26
|
+
* Describes database properties. Use this schema to resolve property bindings. Use this
|
|
27
|
+
* schema to validate filter and sort references. Undefined when the host does not provide a
|
|
28
|
+
* database schema.
|
|
29
|
+
*/
|
|
20
30
|
collectionSchema: v.optional(notionCollectionSchemaValidator),
|
|
21
31
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
32
|
+
* Maps user-defined property keys to database property IDs. Use this map to resolve a key
|
|
33
|
+
* such as `name` to its database property ID. A value of `undefined` marks a declared
|
|
34
|
+
* property without a valid binding. Synthetic metadata does not add entries to this map.
|
|
24
35
|
*/
|
|
25
36
|
propertyIdsByKey: v.record(v.string(), v.optional(v.string())),
|
|
26
37
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
38
|
+
* Describes property values in query snapshots. Keys use the same property IDs as a snapshot's
|
|
39
|
+
* `propertiesById` map.
|
|
40
|
+
*
|
|
41
|
+
* Includes four synthetic metadata fields, even when the database schema is unavailable:
|
|
42
|
+
* `created_time`, `last_edited_time`, `created_by`, and `last_edited_by`. Also includes
|
|
43
|
+
* database properties when the host provides their schema.
|
|
44
|
+
*
|
|
45
|
+
* Use `propertiesById` to read a value. Use this map to read the value's schema. Use
|
|
46
|
+
* `collectionSchema` to validate filter and sort references.
|
|
29
47
|
*/
|
|
30
48
|
propertySchemasById: v.record(v.string(), notionPropertySchemaSchema),
|
|
31
49
|
});
|
|
32
50
|
export const notionDataSourceBindingSchema = v.object({
|
|
33
51
|
collectionPointer: v.optional(collectionPointerValidator),
|
|
52
|
+
/**
|
|
53
|
+
* Describes database properties. Use this schema to resolve property bindings. Use this
|
|
54
|
+
* schema to validate filter and sort references. Undefined when the host does not provide a
|
|
55
|
+
* database schema.
|
|
56
|
+
*/
|
|
34
57
|
collectionSchema: v.optional(notionCollectionSchemaValidator),
|
|
58
|
+
/**
|
|
59
|
+
* Maps user-defined property keys to database property IDs. Use this map to resolve a key
|
|
60
|
+
* such as `name` to its database property ID. A value of `undefined` marks a declared
|
|
61
|
+
* property without a binding. Omitted when the host does not provide property mappings.
|
|
62
|
+
* Synthetic metadata does not add entries to this map.
|
|
63
|
+
*/
|
|
35
64
|
propertyIdsByKey: v.optional(v.record(v.string(), v.optional(v.string()))),
|
|
36
65
|
});
|
|
37
66
|
export const notionDataSourceBindingsSchema = v.record(v.string(), notionDataSourceBindingSchema);
|
|
@@ -195,3 +195,5 @@ export type NotionPropertySchema = v.InferOutput<typeof notionPropertySchemaSche
|
|
|
195
195
|
*/
|
|
196
196
|
export declare const NOTION_BUILTIN_PROPERTY_IDS: readonly ["created_time", "last_edited_time", "created_by", "last_edited_by"];
|
|
197
197
|
export type NotionBuiltinPropertyId = (typeof NOTION_BUILTIN_PROPERTY_IDS)[number];
|
|
198
|
+
/** Schemas for synthetic metadata values in query snapshots. */
|
|
199
|
+
export declare const NOTION_BUILTIN_PROPERTY_SCHEMAS: Record<NotionBuiltinPropertyId, NotionPropertySchema>;
|
|
@@ -163,3 +163,10 @@ export const NOTION_BUILTIN_PROPERTY_IDS = [
|
|
|
163
163
|
"created_by",
|
|
164
164
|
"last_edited_by",
|
|
165
165
|
];
|
|
166
|
+
/** Schemas for synthetic metadata values in query snapshots. */
|
|
167
|
+
export const NOTION_BUILTIN_PROPERTY_SCHEMAS = {
|
|
168
|
+
created_time: { type: "created_time", name: "Created time" },
|
|
169
|
+
last_edited_time: { type: "last_edited_time", name: "Last edited time" },
|
|
170
|
+
created_by: { type: "created_by", name: "Created by" },
|
|
171
|
+
last_edited_by: { type: "last_edited_by", name: "Last edited by" },
|
|
172
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
export declare const customBlockCreatePageErrorCodeSchema: v.StringSchema<undefined>;
|
|
4
|
-
export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "
|
|
4
|
+
export type CustomBlockCreatePageErrorCode = CustomBlockErrorCode<"create_page_failed" | "invalid_page_parent" | "page_unavailable" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value">;
|
|
5
5
|
export type CustomBlockCreatePageErrorInfo = CustomBlockErrorInfo<CustomBlockCreatePageErrorCode>;
|
|
6
6
|
export declare const customBlockCreatePageErrorInfoSchema: v.ObjectSchema<{
|
|
7
7
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
3
3
|
export declare const customBlockGetPageErrorCodeSchema: v.StringSchema<undefined>;
|
|
4
|
-
export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "
|
|
4
|
+
export type CustomBlockGetPageErrorCode = CustomBlockErrorCode<"get_page_failed" | "page_unavailable">;
|
|
5
5
|
export type CustomBlockGetPageErrorInfo = CustomBlockErrorInfo<CustomBlockGetPageErrorCode>;
|
|
6
6
|
export declare const customBlockGetPageErrorInfoSchema: v.ObjectSchema<{
|
|
7
7
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -27,7 +27,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
27
27
|
}, undefined>, v.ObjectSchema<{
|
|
28
28
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
29
29
|
}, undefined>], undefined>;
|
|
30
|
-
readonly page: v.ObjectSchema<{
|
|
30
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
31
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
32
|
+
}, undefined>, v.ObjectSchema<{
|
|
33
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
31
34
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
32
35
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
33
36
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -47,7 +50,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
47
50
|
}, undefined>, v.ObjectSchema<{
|
|
48
51
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
49
52
|
}, undefined>], undefined>;
|
|
50
|
-
}, undefined>;
|
|
53
|
+
}, undefined>], undefined>;
|
|
51
54
|
readonly manifest: v.ObjectSchema<{
|
|
52
55
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
53
56
|
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
@@ -261,7 +264,10 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
261
264
|
}, undefined>], undefined>;
|
|
262
265
|
}, undefined>, v.ObjectSchema<{
|
|
263
266
|
readonly type: v.LiteralSchema<"pageChanged", undefined>;
|
|
264
|
-
readonly page: v.ObjectSchema<{
|
|
267
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
268
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
269
|
+
}, undefined>, v.ObjectSchema<{
|
|
270
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
265
271
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
266
272
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
267
273
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -281,7 +287,7 @@ export declare const hostToSandboxMessageSchema: v.VariantSchema<"type", [v.Vari
|
|
|
281
287
|
}, undefined>, v.ObjectSchema<{
|
|
282
288
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
283
289
|
}, undefined>], undefined>;
|
|
284
|
-
}, undefined>;
|
|
290
|
+
}, undefined>], undefined>;
|
|
285
291
|
}, undefined>, v.ObjectSchema<{
|
|
286
292
|
readonly type: v.LiteralSchema<"currentUserChanged", undefined>;
|
|
287
293
|
readonly currentUser: v.ObjectSchema<{
|
|
@@ -53,7 +53,10 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
53
53
|
}, undefined>, v.ObjectSchema<{
|
|
54
54
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
55
55
|
}, undefined>], undefined>;
|
|
56
|
-
readonly page: v.ObjectSchema<{
|
|
56
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
57
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
58
|
+
}, undefined>, v.ObjectSchema<{
|
|
59
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
57
60
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
58
61
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
59
62
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -73,7 +76,7 @@ export declare const initMessageSchema: v.VariantSchema<"status", [v.ObjectSchem
|
|
|
73
76
|
}, undefined>, v.ObjectSchema<{
|
|
74
77
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
75
78
|
}, undefined>], undefined>;
|
|
76
|
-
}, undefined>;
|
|
79
|
+
}, undefined>], undefined>;
|
|
77
80
|
readonly manifest: v.ObjectSchema<{
|
|
78
81
|
readonly version: v.LiteralSchema<1, undefined>;
|
|
79
82
|
readonly dataSources: v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
@@ -3,7 +3,7 @@ import type { CustomBlockErrorCode, CustomBlockErrorInfo } from "../errors.js";
|
|
|
3
3
|
export declare const openPageModeSchema: v.PicklistSchema<["side_peek", "center_peek"], undefined>;
|
|
4
4
|
export type OpenPageMode = v.InferOutput<typeof openPageModeSchema>;
|
|
5
5
|
export declare const customBlockOpenPageErrorCodeSchema: v.StringSchema<undefined>;
|
|
6
|
-
export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "
|
|
6
|
+
export type CustomBlockOpenPageErrorCode = CustomBlockErrorCode<"open_page_failed" | "page_unavailable" | "navigation_unavailable">;
|
|
7
7
|
export type CustomBlockOpenPageErrorInfo = CustomBlockErrorInfo<CustomBlockOpenPageErrorCode>;
|
|
8
8
|
export declare const customBlockOpenPageErrorInfoSchema: v.ObjectSchema<{
|
|
9
9
|
readonly code: v.StringSchema<undefined>;
|
|
@@ -4,7 +4,10 @@ import * as v from "valibot";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const pageChangedMessageSchema: v.ObjectSchema<{
|
|
6
6
|
readonly type: v.LiteralSchema<"pageChanged", undefined>;
|
|
7
|
-
readonly page: v.ObjectSchema<{
|
|
7
|
+
readonly page: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
8
|
+
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
9
|
+
}, undefined>, v.ObjectSchema<{
|
|
10
|
+
readonly type: v.LiteralSchema<"page", undefined>;
|
|
8
11
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.BrandAction<string, "NotionPageId">]>;
|
|
9
12
|
readonly parent: v.VariantSchema<"type", [v.ObjectSchema<{
|
|
10
13
|
readonly type: v.LiteralSchema<"page_id", undefined>;
|
|
@@ -24,6 +27,6 @@ export declare const pageChangedMessageSchema: v.ObjectSchema<{
|
|
|
24
27
|
}, undefined>, v.ObjectSchema<{
|
|
25
28
|
readonly type: v.LiteralSchema<"unavailable", undefined>;
|
|
26
29
|
}, undefined>], undefined>;
|
|
27
|
-
}, undefined>;
|
|
30
|
+
}, undefined>], undefined>;
|
|
28
31
|
}, undefined>;
|
|
29
32
|
export type PageChangedMessage = v.InferOutput<typeof pageChangedMessageSchema>;
|