@notionhq/custom-blocks 0.2.10 → 0.2.12
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/README.md +73 -69
- package/bin/notion-custom-blocks/cli.js +0 -0
- package/dist/version.js +1 -1
- package/docs/block-location.md +71 -45
- package/docs/data-sources.md +242 -141
- package/docs/deployment.md +30 -20
- package/docs/errors.md +33 -27
- package/docs/lifecycle.md +82 -72
- package/docs/pages.md +137 -81
- package/docs/users.md +65 -51
- package/package.json +65 -65
package/docs/data-sources.md
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
# Data sources
|
|
2
2
|
|
|
3
|
-
Read the Notion rows your block needs with filters, sorts, and row limits. Your subscription keeps
|
|
3
|
+
Read the Notion rows your block needs with filters, sorts, and row limits. Your subscription keeps
|
|
4
|
+
them current as the data changes.
|
|
4
5
|
|
|
5
|
-
Use `customBlock.subscribeToDataSource(...)` with any TypeScript UI framework. For React,
|
|
6
|
+
Use `customBlock.subscribeToDataSource(...)` with any TypeScript UI framework. For React,
|
|
7
|
+
`useDataSource(key, options)` provides the latest snapshot and handles subscription cleanup.
|
|
6
8
|
|
|
7
|
-
Each snapshot contains rows, property schemas, loading and error state, and `hasMore`. Each query
|
|
9
|
+
Each snapshot contains rows, property schemas, loading and error state, and `hasMore`. Each query
|
|
10
|
+
result replaces the previous rows in the snapshot. Subscriptions remain independent, even when they
|
|
11
|
+
query the same data source.
|
|
8
12
|
|
|
9
|
-
Queries default to 20 rows and support up to 999. See [Known limitations](#known-limitations) for
|
|
13
|
+
Queries default to 20 rows and support up to 999. See [Known limitations](#known-limitations) for
|
|
14
|
+
pagination, filter, and sort restrictions.
|
|
10
15
|
|
|
11
16
|
## Bind a data source
|
|
12
17
|
|
|
13
|
-
Declare the data your block needs under `dataSources` in `worker.customBlock(...)`. Give each
|
|
18
|
+
Declare the data your block needs under `dataSources` in `worker.customBlock(...)`. Give each
|
|
19
|
+
declaration a key, such as `people`, and declare the properties your block uses.
|
|
14
20
|
|
|
15
|
-
When someone adds the block to Notion, they bind each declaration to a data source and map its
|
|
21
|
+
When someone adds the block to Notion, they bind each declaration to a data source and map its
|
|
22
|
+
properties. Your code queries the declared key and the SDK resolves the binding. This lets the same
|
|
23
|
+
block work with different data sources across workspaces.
|
|
16
24
|
|
|
17
|
-
Prefer `propertiesByKey` when reading declared properties. These keys stay the same across bindings.
|
|
25
|
+
Prefer `propertiesByKey` when reading declared properties. These keys stay the same across bindings.
|
|
26
|
+
`propertiesById` exposes values keyed by the bound data source's raw property IDs.
|
|
18
27
|
|
|
19
|
-
Use `ManifestDataSource`, `ManifestProperty`, and `ManifestIcon` for declaration metadata. To list
|
|
28
|
+
Use `ManifestDataSource`, `ManifestProperty`, and `ManifestIcon` for declaration metadata. To list
|
|
29
|
+
declared keys, use `useManifest()` in React or `customBlock.getManifest()` in TypeScript. These APIs
|
|
30
|
+
are useful for a data source switcher.
|
|
20
31
|
|
|
21
32
|
## Subscribe to rows
|
|
22
33
|
|
|
@@ -40,33 +51,42 @@ type DataSourceQueryOptions = {
|
|
|
40
51
|
};
|
|
41
52
|
```
|
|
42
53
|
|
|
43
|
-
Each call registers the `onSnapshot` listener. When you unsubscribe that listener, other listeners
|
|
54
|
+
Each call registers the `onSnapshot` listener. When you unsubscribe that listener, other listeners
|
|
55
|
+
remain subscribed. Queries start only after SDK initialization.
|
|
44
56
|
|
|
45
|
-
The listener receives the current snapshot immediately and receives later updates. Unrelated host
|
|
57
|
+
The listener receives the current snapshot immediately and receives later updates. Unrelated host
|
|
58
|
+
changes do not trigger the listener. A new query result can trigger the listener even if its row
|
|
59
|
+
values are unchanged. Each snapshot contains rows, schema, loading state, and row methods for
|
|
60
|
+
updating, archiving, and unarchiving.
|
|
46
61
|
|
|
47
|
-
The SDK calls `onSnapshot` immediately with the current snapshot, before `subscribeToDataSource`
|
|
62
|
+
The SDK calls `onSnapshot` immediately with the current snapshot, before `subscribeToDataSource`
|
|
63
|
+
returns.
|
|
48
64
|
|
|
49
65
|
```ts
|
|
50
|
-
import { customBlock, initCustomBlock } from "@notionhq/custom-blocks"
|
|
66
|
+
import { customBlock, initCustomBlock } from "@notionhq/custom-blocks"
|
|
51
67
|
|
|
52
|
-
await initCustomBlock()
|
|
68
|
+
await initCustomBlock()
|
|
53
69
|
|
|
54
70
|
const unsubscribe = customBlock.subscribeToDataSource({
|
|
55
71
|
key: "people",
|
|
56
|
-
onSnapshot:
|
|
72
|
+
onSnapshot: snapshot => render(snapshot),
|
|
57
73
|
options: {
|
|
58
74
|
limit: 50,
|
|
59
75
|
sorts: [{ key: "name", direction: "ascending" }],
|
|
60
76
|
},
|
|
61
|
-
})
|
|
62
|
-
|
|
77
|
+
})
|
|
63
78
|
```
|
|
64
79
|
|
|
65
|
-
To change the query or request more rows, unsubscribe and create a new subscription with different
|
|
80
|
+
To change the query or request more rows, unsubscribe and create a new subscription with different
|
|
81
|
+
options.
|
|
66
82
|
|
|
67
|
-
Both APIs accept the [query options](#query-options) below. The SDK copies options when you
|
|
83
|
+
Both APIs accept the [query options](#query-options) below. The SDK copies options when you
|
|
84
|
+
subscribe. Later changes to the supplied object do not affect the subscription. A change to the data
|
|
85
|
+
source definition repeats the query with the current options.
|
|
68
86
|
|
|
69
|
-
`unsubscribe()` removes this SDK subscription and its listener, then sends
|
|
87
|
+
`unsubscribe()` removes this SDK subscription and its listener, then sends
|
|
88
|
+
`unsubscribeDataSourceQuery` to the host. The host stops future refreshes and ignores pending
|
|
89
|
+
results for that subscription. Other subscriptions remain active. Repeated calls have no effect.
|
|
70
90
|
|
|
71
91
|
### `useDataSource(key, options?)`
|
|
72
92
|
|
|
@@ -74,31 +94,37 @@ Both APIs accept the [query options](#query-options) below. The SDK copies optio
|
|
|
74
94
|
function useDataSource(
|
|
75
95
|
key: string,
|
|
76
96
|
options?: {
|
|
77
|
-
limit?: number
|
|
78
|
-
filter?: NotionDataSourceFilter
|
|
79
|
-
sorts?: NotionDataSourceSort[]
|
|
97
|
+
limit?: number
|
|
98
|
+
filter?: NotionDataSourceFilter
|
|
99
|
+
sorts?: NotionDataSourceSort[]
|
|
80
100
|
},
|
|
81
|
-
): UseDataSourceResult
|
|
101
|
+
): UseDataSourceResult
|
|
82
102
|
|
|
83
103
|
type UseDataSourceResult = {
|
|
84
|
-
items: NotionDataSourcePage[]
|
|
85
|
-
collectionSchema?: NotionCollectionSchema
|
|
86
|
-
propertySchemasById: { [propertyId: string]: NotionPropertySchema }
|
|
87
|
-
propertyIdsByKey: { [key: string]: string | undefined }
|
|
88
|
-
propertySchemasByKey: { [key: string]: NotionPropertySchema | undefined }
|
|
89
|
-
isLoading: boolean
|
|
90
|
-
hasMore: boolean
|
|
91
|
-
error?: CustomBlockQueryDataSourceErrorInfo
|
|
92
|
-
}
|
|
104
|
+
items: NotionDataSourcePage[]
|
|
105
|
+
collectionSchema?: NotionCollectionSchema
|
|
106
|
+
propertySchemasById: { [propertyId: string]: NotionPropertySchema }
|
|
107
|
+
propertyIdsByKey: { [key: string]: string | undefined }
|
|
108
|
+
propertySchemasByKey: { [key: string]: NotionPropertySchema | undefined }
|
|
109
|
+
isLoading: boolean
|
|
110
|
+
hasMore: boolean
|
|
111
|
+
error?: CustomBlockQueryDataSourceErrorInfo
|
|
112
|
+
}
|
|
93
113
|
```
|
|
94
114
|
|
|
95
|
-
Reads the data source mapped to `key`. To request more rows, store the limit in component state and
|
|
115
|
+
Reads the data source mapped to `key`. To request more rows, store the limit in component state and
|
|
116
|
+
pass it to `useDataSource` again.
|
|
96
117
|
|
|
97
|
-
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to
|
|
118
|
+
`propertyIdsByKey` maps manifest property keys to raw Notion property IDs; unbound keys map to
|
|
119
|
+
`undefined`. `propertySchemasByKey` exposes the corresponding schemas and is likewise `undefined`
|
|
120
|
+
for declared-but-unbound slots.
|
|
98
121
|
|
|
99
|
-
`useDataSource` uses `customBlock.subscribeToDataSource` and returns its latest snapshot. A change
|
|
122
|
+
`useDataSource` uses `customBlock.subscribeToDataSource` and returns its latest snapshot. A change
|
|
123
|
+
to the key, limit, filter, or sorts replaces the subscription.
|
|
100
124
|
|
|
101
|
-
Each consumer has its own host subscription. On unmount, the SDK removes its local query state and
|
|
125
|
+
Each consumer has its own host subscription. On unmount, the SDK removes its local query state and
|
|
126
|
+
sends an unsubscribe message. The host stops future refreshes and ignores pending results. Other
|
|
127
|
+
consumers remain subscribed.
|
|
102
128
|
|
|
103
129
|
Query failures follow the SDK's [error-handling contract](./errors.md).
|
|
104
130
|
|
|
@@ -108,13 +134,17 @@ Both subscription APIs accept `limit`, `filter`, and `sorts`.
|
|
|
108
134
|
|
|
109
135
|
### Row limits
|
|
110
136
|
|
|
111
|
-
`limit` defaults to 20 and must be a positive integer. The SDK caps values above 999. Each query
|
|
137
|
+
`limit` defaults to 20 and must be a positive integer. The SDK caps values above 999. Each query
|
|
138
|
+
reads from the start of the matching rows. A larger limit replaces the previous snapshot with a
|
|
139
|
+
larger result.
|
|
112
140
|
|
|
113
|
-
`hasMore` indicates that more matching rows exist beyond the result. It does not provide a cursor or
|
|
141
|
+
`hasMore` indicates that more matching rows exist beyond the result. It does not provide a cursor or
|
|
142
|
+
guarantee that increasing the limit can retrieve every row.
|
|
114
143
|
|
|
115
144
|
### Filters
|
|
116
145
|
|
|
117
|
-
Use `filter` to select matching rows. Filters do not support every property type yet. Check
|
|
146
|
+
Use `filter` to select matching rows. Filters do not support every property type yet. Check
|
|
147
|
+
[Property support](#property-support) before choosing a property.
|
|
118
148
|
|
|
119
149
|
Use a single condition to match unfinished tasks:
|
|
120
150
|
|
|
@@ -136,9 +166,11 @@ filter: {
|
|
|
136
166
|
}
|
|
137
167
|
```
|
|
138
168
|
|
|
139
|
-
Here, `title` and `done` are declared property keys. Use `propertyId` instead of `key` when you have
|
|
169
|
+
Here, `title` and `done` are declared property keys. Use `propertyId` instead of `key` when you have
|
|
170
|
+
a raw property ID. The condition type, such as `checkbox`, must match the property's schema.
|
|
140
171
|
|
|
141
|
-
Pass a single condition directly, or combine up to 25 conditions with `and`. Nested groups and `or`
|
|
172
|
+
Pass a single condition directly, or combine up to 25 conditions with `and`. Nested groups and `or`
|
|
173
|
+
are unsupported. An empty `and` group applies no conditions. Both APIs accept the same filter shape.
|
|
142
174
|
|
|
143
175
|
The SDK reports invalid keys, types, operators, and values through the snapshot's `error` field.
|
|
144
176
|
|
|
@@ -153,21 +185,28 @@ The SDK reports invalid keys, types, operators, and values through the snapshot'
|
|
|
153
185
|
| `select`, `status` | `equals`, `does_not_equal`, `is_empty`, `is_not_empty` |
|
|
154
186
|
| `multi_select` | `contains`, `contains_all`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
155
187
|
| `date` | `equals`, `before`, `after`, `on_or_before`, `on_or_after`, `is_empty`, `is_not_empty` |
|
|
156
|
-
| `people`
|
|
188
|
+
| `people` | `contains`, `does_not_contain`, `is_empty`, `is_not_empty` |
|
|
157
189
|
|
|
158
190
|
- Select, multi-select, and status filters accept one option name or an array of option names.
|
|
159
|
-
- For multi-select filters, `contains` matches **any** supplied option. `contains_all` requires
|
|
160
|
-
|
|
191
|
+
- For multi-select filters, `contains` matches **any** supplied option. `contains_all` requires
|
|
192
|
+
**every** supplied option.
|
|
193
|
+
- People filters accept one explicit reference to a human user or a group. Use
|
|
194
|
+
`{ object: "user", id: "..." }` or `{ object: "group", id: "..." }`. Group filters match exact
|
|
195
|
+
group mentions. They do not expand group membership. Using bot or organization bot pointers as
|
|
196
|
+
filter references is not supported.
|
|
161
197
|
- Empty checks use `{ is_empty: true }` or `{ is_not_empty: true }`.
|
|
162
|
-
- Date comparisons accept ISO date strings or timestamps. Notion evaluates timestamps at minute
|
|
198
|
+
- Date comparisons accept ISO date strings or timestamps. Notion evaluates timestamps at minute
|
|
199
|
+
precision.
|
|
163
200
|
|
|
164
201
|
</details>
|
|
165
202
|
|
|
166
203
|
### Sorts
|
|
167
204
|
|
|
168
|
-
Use `sorts` to order matching rows. Sorts do not support every property type yet, including some
|
|
205
|
+
Use `sorts` to order matching rows. Sorts do not support every property type yet, including some
|
|
206
|
+
types that support filters. Check [Property support](#property-support) before choosing a property.
|
|
169
207
|
|
|
170
|
-
This example sorts tasks by due date, with the earliest first. Tasks with the same due date use
|
|
208
|
+
This example sorts tasks by due date, with the earliest first. Tasks with the same due date use
|
|
209
|
+
their creation time, newest first:
|
|
171
210
|
|
|
172
211
|
```tsx
|
|
173
212
|
const query = useDataSource("tasks", {
|
|
@@ -176,21 +215,28 @@ const query = useDataSource("tasks", {
|
|
|
176
215
|
{ key: "createdAt", direction: "descending" },
|
|
177
216
|
],
|
|
178
217
|
limit: 50,
|
|
179
|
-
})
|
|
218
|
+
})
|
|
180
219
|
```
|
|
181
220
|
|
|
182
|
-
Here, `due` is a declared date property key and `createdAt` is a declared key bound to a
|
|
221
|
+
Here, `due` is a declared date property key and `createdAt` is a declared key bound to a
|
|
222
|
+
created-time property in the data source schema. Sorts apply in array order, with the first property
|
|
223
|
+
taking priority. Empty values sort last in both directions.
|
|
183
224
|
|
|
184
|
-
You can sort by up to 10 unique properties. Both APIs accept the same sort shape, and you can
|
|
225
|
+
You can sort by up to 10 unique properties. Both APIs accept the same sort shape, and you can
|
|
226
|
+
combine `sorts` with `filter`.
|
|
185
227
|
|
|
186
228
|
## Pages within a data source
|
|
187
229
|
|
|
188
|
-
Each row returned by either API is a `NotionDataSourcePage` —
|
|
230
|
+
Each row returned by either API is a `NotionDataSourcePage` —
|
|
231
|
+
`{ id, propertiesById, propertiesByKey, update, archive, unarchive }`. Read property values through
|
|
232
|
+
either of the two views:
|
|
189
233
|
|
|
190
234
|
- `propertiesByKey[key]` — keyed by the semantic property keys you declared in the manifest.
|
|
191
235
|
- `propertiesById[propertyId]` — keyed by the raw Notion property ID.
|
|
192
236
|
|
|
193
|
-
The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) are always
|
|
237
|
+
The four built-ins (`created_time`, `last_edited_time`, `created_by`, `last_edited_by`) are always
|
|
238
|
+
present in `propertiesById` and `collectionSchema.propertiesById`. They have no semantic keys, so
|
|
239
|
+
they do not appear in the `*ByKey` views.
|
|
194
240
|
|
|
195
241
|
### Updating a row
|
|
196
242
|
|
|
@@ -202,35 +248,42 @@ await row.update({
|
|
|
202
248
|
score: { type: "number", number: 8 }, // semantic key
|
|
203
249
|
},
|
|
204
250
|
icon: { type: "emoji", emoji: "✅" },
|
|
205
|
-
})
|
|
251
|
+
})
|
|
206
252
|
```
|
|
207
253
|
|
|
208
|
-
Property values can be keyed by **either** semantic keys or raw IDs. The SDK resolves semantic keys
|
|
254
|
+
Property values can be keyed by **either** semantic keys or raw IDs. The SDK resolves semantic keys
|
|
255
|
+
to IDs before sending the request.
|
|
209
256
|
|
|
210
|
-
Use `row.update(...)` whenever you already have a row in hand. For pages you don't have a row for
|
|
257
|
+
Use `row.update(...)` whenever you already have a row in hand. For pages you don't have a row for
|
|
258
|
+
(e.g. you only have a `pageId`), drop down to the top-level [`pages` API](./pages.md) — it covers
|
|
259
|
+
create / get / update / archive / unarchive and accepts raw property IDs only.
|
|
211
260
|
|
|
212
261
|
### Archiving and unarchiving a row
|
|
213
262
|
|
|
214
|
-
`row.archive()` is shorthand for calling `row.update({ is_archived: true })`.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
Use `row.update` to change archive status and other fields in one request.
|
|
263
|
+
`row.archive()` is shorthand for calling `row.update({ is_archived: true })`. `row.unarchive()` is
|
|
264
|
+
shorthand for calling `row.update({ is_archived: false })`. Both methods return an
|
|
265
|
+
`UpdatePageResult`. Use `row.update` to change archive status and other fields in one request.
|
|
218
266
|
|
|
219
267
|
## Read declarations
|
|
220
268
|
|
|
221
|
-
Use the manifest when your UI needs to discover which data sources and properties the block
|
|
269
|
+
Use the manifest when your UI needs to discover which data sources and properties the block
|
|
270
|
+
declares. For example, build a data source switcher from the declared keys or table headings from
|
|
271
|
+
the declared property names.
|
|
222
272
|
|
|
223
|
-
Both APIs below return the declaration from `worker.customBlock(...)`, including its keys, names,
|
|
273
|
+
Both APIs below return the declaration from `worker.customBlock(...)`, including its keys, names,
|
|
274
|
+
descriptions, and property definitions. To query a selected data source, pass its key to either
|
|
275
|
+
subscription API. Read resolved property IDs from the query snapshot's `propertyIdsByKey` map.
|
|
224
276
|
|
|
225
277
|
Both APIs return synchronously and throw if called before `initCustomBlock()` resolves.
|
|
226
278
|
|
|
227
279
|
### `useManifest()`
|
|
228
280
|
|
|
229
281
|
```ts
|
|
230
|
-
function useManifest(): CustomBlockManifest
|
|
282
|
+
function useManifest(): CustomBlockManifest
|
|
231
283
|
```
|
|
232
284
|
|
|
233
|
-
Returns the block manifest received from the host during initialization. The manifest contains
|
|
285
|
+
Returns the block manifest received from the host during initialization. The manifest contains
|
|
286
|
+
declarations only. Resolved bindings and rows are available through query snapshots.
|
|
234
287
|
|
|
235
288
|
### `customBlock.getManifest()`
|
|
236
289
|
|
|
@@ -239,47 +292,49 @@ function customBlock.getManifest(): CustomBlockManifest;
|
|
|
239
292
|
```
|
|
240
293
|
|
|
241
294
|
Framework-neutral getter for the same manifest returned by `useManifest()`.
|
|
242
|
-
`customBlock.subscribeToManifest(callback)` follows the
|
|
243
|
-
|
|
295
|
+
`customBlock.subscribeToManifest(callback)` follows the
|
|
296
|
+
[context subscription contract](./block-location.md#reading-values-and-following-changes). The
|
|
297
|
+
manifest stays fixed for the lifetime of the running block, so each subscription delivers it once.
|
|
298
|
+
You can register before initialization without an error.
|
|
244
299
|
|
|
245
300
|
## Example: querying a data source
|
|
246
301
|
|
|
247
|
-
This example calls `useDataSource` with a declared key. It validates each row’s values before
|
|
302
|
+
This example calls `useDataSource` with a declared key. It validates each row’s values before
|
|
303
|
+
rendering:
|
|
248
304
|
|
|
249
305
|
```tsx
|
|
250
|
-
import { useState } from "react"
|
|
251
|
-
import type { NotionDataSourcePage } from "@notionhq/custom-blocks"
|
|
252
|
-
import { useDataSource } from "@notionhq/custom-blocks/react"
|
|
306
|
+
import { useState } from "react"
|
|
307
|
+
import type { NotionDataSourcePage } from "@notionhq/custom-blocks"
|
|
308
|
+
import { useDataSource } from "@notionhq/custom-blocks/react"
|
|
253
309
|
|
|
254
|
-
const KEY = "people"
|
|
310
|
+
const KEY = "people"
|
|
255
311
|
|
|
256
312
|
function isComplete(item: NotionDataSourcePage): boolean {
|
|
257
313
|
return (
|
|
258
314
|
typeof item.propertiesByKey.name === "string" &&
|
|
259
315
|
typeof item.propertiesByKey.score === "number" &&
|
|
260
316
|
Number.isFinite(item.propertiesByKey.score)
|
|
261
|
-
)
|
|
317
|
+
)
|
|
262
318
|
}
|
|
263
319
|
|
|
264
320
|
export function ScoreList() {
|
|
265
|
-
const [limit, setLimit] = useState(20)
|
|
266
|
-
const { items, isLoading, hasMore, error } = useDataSource(KEY, { limit })
|
|
321
|
+
const [limit, setLimit] = useState(20)
|
|
322
|
+
const { items, isLoading, hasMore, error } = useDataSource(KEY, { limit })
|
|
267
323
|
|
|
268
|
-
if (error) return <div role="alert">Couldn't load: {error.message}</div
|
|
269
|
-
if (isLoading && items.length === 0) return <div>Loading…</div
|
|
324
|
+
if (error) return <div role="alert">Couldn't load: {error.message}</div>
|
|
325
|
+
if (isLoading && items.length === 0) return <div>Loading…</div>
|
|
270
326
|
|
|
271
|
-
const displayItems = items.filter(isComplete)
|
|
327
|
+
const displayItems = items.filter(isComplete)
|
|
272
328
|
if (displayItems.length === 0) {
|
|
273
|
-
return <div>No rows have both a text name and a finite score.</div
|
|
329
|
+
return <div>No rows have both a text name and a finite score.</div>
|
|
274
330
|
}
|
|
275
331
|
|
|
276
332
|
return (
|
|
277
333
|
<div>
|
|
278
334
|
<ul>
|
|
279
|
-
{displayItems.map(
|
|
335
|
+
{displayItems.map(item => (
|
|
280
336
|
<li key={item.id}>
|
|
281
|
-
{String(item.propertiesByKey.name)} —{
|
|
282
|
-
{Number(item.propertiesByKey.score)}
|
|
337
|
+
{String(item.propertiesByKey.name)} — {Number(item.propertiesByKey.score)}
|
|
283
338
|
</li>
|
|
284
339
|
))}
|
|
285
340
|
</ul>
|
|
@@ -293,22 +348,31 @@ export function ScoreList() {
|
|
|
293
348
|
</button>
|
|
294
349
|
) : null}
|
|
295
350
|
</div>
|
|
296
|
-
)
|
|
351
|
+
)
|
|
297
352
|
}
|
|
298
353
|
```
|
|
299
354
|
|
|
300
355
|
## Known limitations
|
|
301
356
|
|
|
302
|
-
- **Row limits and pagination:** `limit` defaults to 20 and is capped at 999. Queries have no cursor
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
- **
|
|
357
|
+
- **Row limits and pagination:** `limit` defaults to 20 and is capped at 999. Queries have no cursor
|
|
358
|
+
or offset. Increasing the limit repeats the query from the start and replaces the snapshot.
|
|
359
|
+
`hasMore` can remain true at the cap, so use filters to narrow larger data sources.
|
|
360
|
+
- **Filter and sort rules:** Use one property condition or one `and` group with up to 25 conditions.
|
|
361
|
+
Nested groups and `or` are unsupported. You can sort by up to 10 unique properties. Empty values
|
|
362
|
+
sort last in both directions. See the table below for property support and [Filters](#filters) for
|
|
363
|
+
operators.
|
|
364
|
+
- **Changing a query:** TypeScript subscriptions copy their options when they start. To change them,
|
|
365
|
+
unsubscribe and create a new subscription. React replaces the subscription when the key or options
|
|
366
|
+
change. Previous rows are cleared while the new query loads.
|
|
367
|
+
- **Updates:** Callbacks receive complete snapshots, not individual row changes. A new result can
|
|
368
|
+
trigger a callback even when its row values are unchanged.
|
|
306
369
|
|
|
307
370
|
## Property support
|
|
308
371
|
|
|
309
372
|
This table shows property support for custom blocks running in Notion.
|
|
310
373
|
|
|
311
|
-
- **Query result** shows values in `propertiesById` and `propertiesByKey` from `useDataSource` and
|
|
374
|
+
- **Query result** shows values in `propertiesById` and `propertiesByKey` from `useDataSource` and
|
|
375
|
+
`customBlock.subscribeToDataSource`. Missing values can be `undefined`.
|
|
312
376
|
- **Update row** covers writes through `item.update({ properties: ... })`.
|
|
313
377
|
- **Filter** and **Sort** cover query options.
|
|
314
378
|
|
|
@@ -317,51 +381,67 @@ This table shows property support for custom blocks running in Notion.
|
|
|
317
381
|
- 🔴 **Unavailable:** The SDK does not expose this operation.
|
|
318
382
|
- ⚫ **Not supported in Notion:** Notion itself does not support this operation in the stated case.
|
|
319
383
|
|
|
320
|
-
| Property type
|
|
321
|
-
|
|
|
322
|
-
| `title`
|
|
323
|
-
| `rich_text`
|
|
324
|
-
| `number`
|
|
325
|
-
| `checkbox`
|
|
326
|
-
| `url`
|
|
327
|
-
| `email`
|
|
328
|
-
| `phone_number`
|
|
329
|
-
| `select`
|
|
330
|
-
| `multi_select`
|
|
331
|
-
| `status`
|
|
332
|
-
| `date`
|
|
333
|
-
| `people`
|
|
334
|
-
| `files`
|
|
335
|
-
| `unique_id`
|
|
336
|
-
| `relation`
|
|
337
|
-
| `place`
|
|
338
|
-
| `formula`
|
|
339
|
-
| `rollup`
|
|
340
|
-
| `button`
|
|
341
|
-
| `verification`
|
|
342
|
-
| `last_visited_time` | 🟡 Text fallback
|
|
343
|
-
| `location`
|
|
344
|
-
| `created_time`
|
|
345
|
-
| `last_edited_time`
|
|
346
|
-
| `created_by`
|
|
347
|
-
| `last_edited_by`
|
|
384
|
+
| Property type | Query result | Update row | Filter | Sort |
|
|
385
|
+
| ------------------- | --------------------------- | -------------------------------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
386
|
+
| `title` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
387
|
+
| `rich_text` | 🟢 Plain text | 🟡 Plain text only | 🟢 Supported | 🟢 Supported |
|
|
388
|
+
| `number` | 🟢 Number | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
389
|
+
| `checkbox` | 🟢 Boolean | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
390
|
+
| `url` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
391
|
+
| `email` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
392
|
+
| `phone_number` | 🟢 String | 🟢 Supported | 🟢 Supported | 🟢 Supported |
|
|
393
|
+
| `select` | 🟢 Option name | 🟡 Set value only | 🟢 Supported | 🔴 Unavailable |
|
|
394
|
+
| `multi_select` | 🟢 Array of option names | 🟡 Set values only | 🟢 Supported | 🔴 Unavailable |
|
|
395
|
+
| `status` | 🟢 Option name | 🟡 Set value only | 🟡 Option names or empty checks, without groups | 🔴 Unavailable |
|
|
396
|
+
| `date` | 🟢 `NotionDateValue` | 🟡 Minute precision | 🟡 Fixed start-date comparisons or empty checks, at minute precision | 🟢 Supported |
|
|
397
|
+
| `people` | 🟢 Array of record pointers | 🟢 Supported | 🟢 Supported | 🔴 Unavailable |
|
|
398
|
+
| `files` | 🟡 Text fallback | 🟡 File URLs only | 🔴 Unavailable | 🔴 Unavailable |
|
|
399
|
+
| `unique_id` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
400
|
+
| `relation` | 🟢 Array of record pointers | 🟡 Replaces value. Rejects `has_more: true`. | 🔴 Unavailable | 🔴 Unavailable for standard relations. ⚫ Notion cannot sort XLDB targets. |
|
|
401
|
+
| `place` | 🟡 Text fallback | 🟢 Supported | 🔴 Unavailable | 🔴 Unavailable |
|
|
402
|
+
| `formula` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
403
|
+
| `rollup` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable for numeric targets or numeric aggregations. ⚫ Notion cannot sort other rollups. |
|
|
404
|
+
| `button` | 🟡 Text fallback | 🔴 Unavailable | ⚫ Not supported in Notion | ⚫ Not supported in Notion |
|
|
405
|
+
| `verification` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
406
|
+
| `last_visited_time` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
407
|
+
| `location` | 🟡 Text fallback | 🔴 Unavailable | 🔴 Unavailable elsewhere. ⚫ Notion disables filters in My Meetings and Library system collections. | 🔴 Unavailable elsewhere. ⚫ Notion disables sorts in Library system collections. |
|
|
408
|
+
| `created_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
409
|
+
| `last_edited_time` | 🟢 `NotionDateTime` in UTC | 🔴 Unavailable | 🔴 Unavailable | 🟡 Schema property only |
|
|
410
|
+
| `created_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
411
|
+
| `last_edited_by` | 🟢 Array of record pointers | 🔴 Unavailable | 🔴 Unavailable | 🔴 Unavailable |
|
|
348
412
|
|
|
349
413
|
### Notes
|
|
350
414
|
|
|
351
|
-
- Text values omit formatting, mention tokens, and annotations. A text fallback can be empty and
|
|
415
|
+
- Text values omit formatting, mention tokens, and annotations. A text fallback can be empty and
|
|
416
|
+
does not preserve the property's structured value. It does not provide structured formula or
|
|
417
|
+
rollup results.
|
|
352
418
|
- Record pointers contain a table name and a record ID.
|
|
353
|
-
- Every row includes four built-in properties in `propertiesById`: `created_time`,
|
|
354
|
-
|
|
419
|
+
- Every row includes four built-in properties in `propertiesById`: `created_time`,
|
|
420
|
+
`last_edited_time`, `created_by`, and `last_edited_by`. The data source does not need matching
|
|
421
|
+
schema properties. These values are read-only. Timestamps use `NotionDateTime` in UTC. Creator and
|
|
422
|
+
editor values use arrays of record pointers.
|
|
423
|
+
- The SDK accepts timestamp sorts, but the current Notion host requires a property ID in the data
|
|
424
|
+
source's actual schema. Sort using a configured created-time or last-edited-time property. The
|
|
425
|
+
synthetic IDs `created_time` and `last_edited_time` alone are not sufficient.
|
|
355
426
|
- You can sort by up to 10 unique properties.
|
|
356
|
-
- Date-time filter values may include seconds or milliseconds, but the Notion host currently
|
|
427
|
+
- Date-time filter values may include seconds or milliseconds, but the Notion host currently
|
|
428
|
+
evaluates them at minute precision. Date filters do not expose relative dates or end-date
|
|
429
|
+
targeting.
|
|
357
430
|
- Status filters accept option names and empty checks, but not status groups.
|
|
358
|
-
- People properties return record pointers with table values of `notion_user`,
|
|
359
|
-
|
|
360
|
-
|
|
431
|
+
- People properties return record pointers with table values of `notion_user`,
|
|
432
|
+
`space_permission_group`, `bot`, or `organization_bot`. Group IDs use the composite form
|
|
433
|
+
`groupId|workspaceId`. People filters support users and groups. Bot and organization bot filtering
|
|
434
|
+
is not supported.
|
|
435
|
+
- Filters accept one condition or an `and` group of up to 25 conditions. The SDK does not support
|
|
436
|
+
`or` or nested groups.
|
|
437
|
+
- Select, multi-select, and status query values contain option names. Their schemas provide option
|
|
438
|
+
IDs and colors separately. Writes set the selected values. They do not edit option definitions or
|
|
439
|
+
colors.
|
|
361
440
|
|
|
362
441
|
### Writing values
|
|
363
442
|
|
|
364
|
-
The value you read has a different shape from the value you write. For example, a query returns a
|
|
443
|
+
The value you read has a different shape from the value you write. For example, a query returns a
|
|
444
|
+
status as a string:
|
|
365
445
|
|
|
366
446
|
```ts
|
|
367
447
|
item.propertiesByKey.status // "Done"
|
|
@@ -374,18 +454,20 @@ const result = await item.update({
|
|
|
374
454
|
properties: {
|
|
375
455
|
status: { type: "status", status: { name: "Done" } },
|
|
376
456
|
},
|
|
377
|
-
})
|
|
457
|
+
})
|
|
378
458
|
|
|
379
459
|
if (result.status === "error") {
|
|
380
|
-
console.error(result.error.message)
|
|
460
|
+
console.error(result.error.message)
|
|
381
461
|
}
|
|
382
462
|
```
|
|
383
463
|
|
|
384
464
|
Other write restrictions:
|
|
385
465
|
|
|
386
466
|
- **Text:** Title and rich text writes preserve plain text, but not formatting or mentions.
|
|
387
|
-
- **Files:** Supply external or existing hosted file URLs. The host stores them as links and does
|
|
388
|
-
|
|
467
|
+
- **Files:** Supply external or existing hosted file URLs. The host stores them as links and does
|
|
468
|
+
not support upload references.
|
|
469
|
+
- **Relations:** Supply the complete replacement list of related pages. The host rejects
|
|
470
|
+
`has_more: true`, which indicates an incomplete list.
|
|
389
471
|
|
|
390
472
|
See [Pages property support](./pages.md#property-support) for the page-property read shapes.
|
|
391
473
|
|
|
@@ -393,37 +475,54 @@ See [Pages property support](./pages.md#property-support) for the page-property
|
|
|
393
475
|
|
|
394
476
|
### Rows & values
|
|
395
477
|
|
|
396
|
-
- `NotionDataSource` — a resolved data source: semantic key, optional `collectionSchema`,
|
|
397
|
-
|
|
478
|
+
- `NotionDataSource` — a resolved data source: semantic key, optional `collectionSchema`,
|
|
479
|
+
`propertyIdsByKey`, and `propertySchemasById`.
|
|
480
|
+
- `NotionDataSourcePage` — a single row exposed to app code:
|
|
481
|
+
`{ id, propertiesById, propertiesByKey, update, archive, unarchive }`.
|
|
398
482
|
- `NotionDataSourceValue` — the value union for `propertiesById` and `propertiesByKey`.
|
|
399
|
-
- `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page
|
|
400
|
-
|
|
483
|
+
- `NotionDataSourcePageUpdateArgs` / `UpdatePageResult` — arguments and result for the per-page
|
|
484
|
+
`update` helper.
|
|
485
|
+
- `UseDataSourceOptions` — options accepted by `useDataSource`: `limit?: number`,
|
|
486
|
+
`filter?: NotionDataSourceFilter`, and `sorts?: NotionDataSourceSort[]`.
|
|
401
487
|
- `NotionDataSourceFilter` — one property condition or one shallow `and` group.
|
|
402
488
|
- `NotionDataSourcePropertyFilter` — one property address combined with a type-specific operator.
|
|
403
489
|
- `NotionDataSourcePropertyAddress` — either a semantic property `key` or a raw `propertyId`.
|
|
404
490
|
- `NotionDataSourceSort` — a property address with an `ascending` or `descending` direction.
|
|
405
|
-
- `NotionDataSourceTextFilterOperator`, `NotionDataSourceNumberFilterOperator`,
|
|
406
|
-
|
|
491
|
+
- `NotionDataSourceTextFilterOperator`, `NotionDataSourceNumberFilterOperator`,
|
|
492
|
+
`NotionDataSourceCheckboxFilterOperator`, `NotionDataSourceOptionFilterOperator`,
|
|
493
|
+
`NotionDataSourceContainsFilterOperator`, `NotionDataSourceDateFilterOperator`, and
|
|
494
|
+
`NotionDataSourcePeopleFilterOperator` — the operators accepted for each property type.
|
|
495
|
+
- `NotionDataSourcePersonFilterValue` — an explicit `{ object: "user" | "group", id }` reference
|
|
496
|
+
used by a people filter.
|
|
407
497
|
- `DataSourceSnapshot` — current rows, schema, and status for one live data-source query.
|
|
408
498
|
- `DataSourceQueryOptions` — the row limit, filter, and sorts shared by both query APIs.
|
|
409
|
-
- `SubscribeToDataSourceArgs` — the key, `onSnapshot` listener, and optional query options for
|
|
499
|
+
- `SubscribeToDataSourceArgs` — the key, `onSnapshot` listener, and optional query options for
|
|
500
|
+
`customBlock.subscribeToDataSource`.
|
|
410
501
|
|
|
411
502
|
### Property schemas
|
|
412
503
|
|
|
413
|
-
- `NotionPropertySchema` — schema for a single property (type plus type-specific config like
|
|
504
|
+
- `NotionPropertySchema` — schema for a single property (type plus type-specific config like
|
|
505
|
+
`select` options).
|
|
414
506
|
- `NotionPropertyType` — string-literal union of every supported property type.
|
|
415
|
-
- `NOTION_PROPERTY_TYPES` — runtime list of those literals (handy for switch coverage and
|
|
416
|
-
|
|
507
|
+
- `NOTION_PROPERTY_TYPES` — runtime list of those literals (handy for switch coverage and
|
|
508
|
+
validation).
|
|
509
|
+
- `NotionPropertyOption` — a single `select` / `multi_select` / `status` option
|
|
510
|
+
(`{ id, name, color }`).
|
|
417
511
|
- `NotionPropertyColor` — the color literal used by options and groups.
|
|
418
512
|
- `NotionStatusGroup` — the `status` property's "To do / In progress / Done" grouping.
|
|
419
|
-
- `NotionDualProperty` — properties that have both a primary and a secondary axis (e.g. `unique_id`
|
|
420
|
-
|
|
513
|
+
- `NotionDualProperty` — properties that have both a primary and a secondary axis (e.g. `unique_id`
|
|
514
|
+
prefix + number).
|
|
515
|
+
- `NotionBuiltinPropertyId` — string-literal union of the four synthetic property IDs
|
|
516
|
+
(`created_time`, `last_edited_time`, `created_by`, `last_edited_by`).
|
|
421
517
|
- `NOTION_BUILTIN_PROPERTY_IDS` — runtime list of the four built-in IDs.
|
|
422
518
|
|
|
423
519
|
### Collection schema & pointers
|
|
424
520
|
|
|
425
|
-
- `NotionCollectionSchema` — host-supplied schema for the bound collection, including raw property
|
|
426
|
-
|
|
521
|
+
- `NotionCollectionSchema` — host-supplied schema for the bound collection, including raw property
|
|
522
|
+
schemas.
|
|
523
|
+
- `NotionRecordPointer` — `{ id, table }`. Generic reference to any Notion record (page, block,
|
|
524
|
+
collection row). Exported for convenience; `useDataSource` and the `pages` API don't take one as
|
|
525
|
+
input.
|
|
427
526
|
|
|
428
527
|
### IDs
|
|
429
528
|
|
|
@@ -434,7 +533,9 @@ Branded string types — they're plain strings at runtime but TypeScript disting
|
|
|
434
533
|
|
|
435
534
|
### Date values
|
|
436
535
|
|
|
437
|
-
Returned wherever a date / date-range value appears (e.g. inside `propertiesByKey` for a `date`
|
|
536
|
+
Returned wherever a date / date-range value appears (e.g. inside `propertiesByKey` for a `date`
|
|
537
|
+
property). All-day values use `NotionDate*` shapes; values with a time component use
|
|
538
|
+
`NotionDateTime*`.
|
|
438
539
|
|
|
439
540
|
- `NotionDateValue` — discriminated union covering every date-shaped value below.
|
|
440
541
|
- `NotionDate`
|