@visus-io/notion-sdk-ts 3.1.0 → 3.1.1

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.
Files changed (122) hide show
  1. package/README.md +17 -85
  2. package/dist/api/asyncTasks.api.d.ts +5 -3
  3. package/dist/api/asyncTasks.api.js +5 -3
  4. package/dist/api/base.api.d.ts +15 -4
  5. package/dist/api/base.api.js +19 -8
  6. package/dist/api/blocks.api.d.ts +2 -0
  7. package/dist/api/blocks.api.js +5 -2
  8. package/dist/api/comments.api.d.ts +2 -0
  9. package/dist/api/comments.api.js +2 -0
  10. package/dist/api/customEmojis.api.d.ts +2 -0
  11. package/dist/api/customEmojis.api.js +2 -0
  12. package/dist/api/dataSources.api.d.ts +5 -3
  13. package/dist/api/dataSources.api.js +4 -1
  14. package/dist/api/databases.api.d.ts +7 -5
  15. package/dist/api/databases.api.js +4 -1
  16. package/dist/api/fileUploads.api.d.ts +7 -4
  17. package/dist/api/fileUploads.api.js +11 -7
  18. package/dist/api/pages.api.d.ts +5 -3
  19. package/dist/api/pages.api.js +5 -3
  20. package/dist/api/search.api.d.ts +4 -2
  21. package/dist/api/search.api.js +5 -2
  22. package/dist/api/users.api.d.ts +2 -0
  23. package/dist/api/users.api.js +2 -0
  24. package/dist/api/views.api.d.ts +15 -13
  25. package/dist/api/views.api.js +10 -7
  26. package/dist/client.d.ts +17 -17
  27. package/dist/client.js +22 -27
  28. package/dist/errors.d.ts +14 -4
  29. package/dist/errors.js +10 -4
  30. package/dist/helpers/block.helpers.d.ts +22 -15
  31. package/dist/helpers/block.helpers.js +14 -12
  32. package/dist/helpers/file.helpers.d.ts +12 -6
  33. package/dist/helpers/file.helpers.js +12 -6
  34. package/dist/helpers/filter.helpers.d.ts +2 -0
  35. package/dist/helpers/filter.helpers.js +2 -0
  36. package/dist/helpers/pagination.helpers.d.ts +52 -36
  37. package/dist/helpers/pagination.helpers.js +49 -29
  38. package/dist/helpers/parent.helpers.d.ts +5 -3
  39. package/dist/helpers/parent.helpers.js +5 -3
  40. package/dist/helpers/property.helpers.d.ts +2 -0
  41. package/dist/helpers/property.helpers.js +3 -1
  42. package/dist/helpers/richText.helpers.d.ts +10 -5
  43. package/dist/helpers/richText.helpers.js +11 -6
  44. package/dist/helpers/sort.helpers.d.ts +2 -0
  45. package/dist/helpers/sort.helpers.js +2 -0
  46. package/dist/helpers/webhook.helpers.d.ts +14 -12
  47. package/dist/helpers/webhook.helpers.js +17 -15
  48. package/dist/models/asyncTask.model.d.ts +8 -6
  49. package/dist/models/asyncTask.model.js +8 -6
  50. package/dist/models/base.model.d.ts +16 -4
  51. package/dist/models/base.model.js +17 -5
  52. package/dist/models/block.model.d.ts +6 -2
  53. package/dist/models/block.model.js +48 -36
  54. package/dist/models/comment.model.d.ts +4 -2
  55. package/dist/models/comment.model.js +4 -2
  56. package/dist/models/customEmoji.model.d.ts +7 -5
  57. package/dist/models/customEmoji.model.js +7 -5
  58. package/dist/models/dataSource.model.d.ts +4 -2
  59. package/dist/models/dataSource.model.js +4 -2
  60. package/dist/models/database.model.d.ts +6 -2
  61. package/dist/models/database.model.js +8 -4
  62. package/dist/models/fileUpload.model.d.ts +6 -4
  63. package/dist/models/fileUpload.model.js +6 -4
  64. package/dist/models/page.model.d.ts +6 -2
  65. package/dist/models/page.model.js +8 -4
  66. package/dist/models/richText.model.d.ts +3 -1
  67. package/dist/models/richText.model.js +3 -1
  68. package/dist/models/user.model.d.ts +4 -2
  69. package/dist/models/user.model.js +4 -2
  70. package/dist/models/view.model.d.ts +9 -7
  71. package/dist/models/view.model.js +9 -7
  72. package/dist/notion.d.ts +6 -1
  73. package/dist/notion.js +6 -1
  74. package/dist/schemas/asyncTask.schema.d.ts +11 -0
  75. package/dist/schemas/asyncTask.schema.js +5 -0
  76. package/dist/schemas/block.schema.d.ts +12 -1
  77. package/dist/schemas/block.schema.js +6 -1
  78. package/dist/schemas/codeLanguages.d.ts +7 -1
  79. package/dist/schemas/codeLanguages.js +4 -1
  80. package/dist/schemas/colors.d.ts +7 -1
  81. package/dist/schemas/colors.js +4 -1
  82. package/dist/schemas/comment.schema.d.ts +20 -2
  83. package/dist/schemas/comment.schema.js +11 -2
  84. package/dist/schemas/customEmoji.schema.d.ts +5 -0
  85. package/dist/schemas/customEmoji.schema.js +2 -0
  86. package/dist/schemas/dataSource.schema.d.ts +19 -3
  87. package/dist/schemas/dataSource.schema.js +12 -5
  88. package/dist/schemas/database.schema.d.ts +13 -1
  89. package/dist/schemas/database.schema.js +7 -1
  90. package/dist/schemas/emoji.schema.d.ts +7 -2
  91. package/dist/schemas/emoji.schema.js +4 -2
  92. package/dist/schemas/file.schema.d.ts +18 -2
  93. package/dist/schemas/file.schema.js +6 -2
  94. package/dist/schemas/fileUpload.schema.d.ts +8 -2
  95. package/dist/schemas/fileUpload.schema.js +5 -2
  96. package/dist/schemas/icon.schema.d.ts +28 -4
  97. package/dist/schemas/icon.schema.js +16 -4
  98. package/dist/schemas/meetingNotesQuery.schema.d.ts +13 -2
  99. package/dist/schemas/meetingNotesQuery.schema.js +7 -2
  100. package/dist/schemas/page.schema.d.ts +5 -0
  101. package/dist/schemas/page.schema.js +2 -0
  102. package/dist/schemas/pageMarkdown.schema.d.ts +15 -4
  103. package/dist/schemas/pageMarkdown.schema.js +9 -4
  104. package/dist/schemas/pageProperties.schema.d.ts +75 -3
  105. package/dist/schemas/pageProperties.schema.js +6 -3
  106. package/dist/schemas/pagination.schema.d.ts +33 -10
  107. package/dist/schemas/pagination.schema.js +12 -5
  108. package/dist/schemas/parent.schema.d.ts +29 -2
  109. package/dist/schemas/parent.schema.js +8 -2
  110. package/dist/schemas/propertyObjects.schema.d.ts +81 -3
  111. package/dist/schemas/propertyObjects.schema.js +11 -5
  112. package/dist/schemas/richText.schema.d.ts +15 -0
  113. package/dist/schemas/richText.schema.js +6 -3
  114. package/dist/schemas/shared.schema.d.ts +6 -3
  115. package/dist/schemas/shared.schema.js +6 -3
  116. package/dist/schemas/user.schema.d.ts +15 -0
  117. package/dist/schemas/user.schema.js +5 -2
  118. package/dist/schemas/view.schema.d.ts +43 -9
  119. package/dist/schemas/view.schema.js +28 -9
  120. package/dist/validation.d.ts +11 -4
  121. package/dist/validation.js +11 -4
  122. package/package.json +5 -2
@@ -74,8 +74,8 @@ declare function nativeIcon(name: string, color?: NativeIconColor): NativeIconRe
74
74
  */
75
75
  declare function customEmojiIcon(id: string): CustomEmojiIconRef;
76
76
  /**
77
- * Helpers for constructing icon objects (emoji, external URL, file upload,
78
- * native icon, or custom emoji).
77
+ * Helpers that create icon objects: emoji, external URL, file upload, native
78
+ * icon, or custom emoji.
79
79
  *
80
80
  * @example
81
81
  * ```ts
@@ -87,6 +87,8 @@ declare function customEmojiIcon(id: string): CustomEmojiIconRef;
87
87
  * // ...
88
88
  * });
89
89
  * ```
90
+ *
91
+ * @category Helpers
90
92
  */
91
93
  export declare const icon: {
92
94
  emoji: typeof emojiIcon;
@@ -114,7 +116,7 @@ declare function externalCover(url: string): ExternalRef;
114
116
  */
115
117
  declare function fileUploadCover(id: string): FileUploadRef;
116
118
  /**
117
- * Helpers for constructing cover image objects.
119
+ * Helpers that create cover image objects.
118
120
  *
119
121
  * @example
120
122
  * ```ts
@@ -126,6 +128,8 @@ declare function fileUploadCover(id: string): FileUploadRef;
126
128
  * // ...
127
129
  * });
128
130
  * ```
131
+ *
132
+ * @category Helpers
129
133
  */
130
134
  export declare const cover: {
131
135
  external: typeof externalCover;
@@ -150,10 +154,10 @@ declare function externalFile(url: string): ExternalRef;
150
154
  */
151
155
  declare function uploadFile(id: string): FileUploadRef;
152
156
  /**
153
- * Helpers for constructing general Notion file objects.
157
+ * Helpers that create general Notion file objects.
154
158
  *
155
- * Useful for file blocks, image blocks, audio blocks, video blocks,
156
- * and file property entries.
159
+ * Use these helpers for file blocks, image blocks, audio blocks, video
160
+ * blocks, and file property entries.
157
161
  *
158
162
  * @example
159
163
  * ```ts
@@ -162,6 +166,8 @@ declare function uploadFile(id: string): FileUploadRef;
162
166
  * notionFile.external('https://example.com/doc.pdf')
163
167
  * notionFile.upload('upload-id')
164
168
  * ```
169
+ *
170
+ * @category Helpers
165
171
  */
166
172
  export declare const notionFile: {
167
173
  external: typeof externalFile;
@@ -60,8 +60,8 @@ function customEmojiIcon(id) {
60
60
  return { type: 'custom_emoji', custom_emoji: { id } };
61
61
  }
62
62
  /**
63
- * Helpers for constructing icon objects (emoji, external URL, file upload,
64
- * native icon, or custom emoji).
63
+ * Helpers that create icon objects: emoji, external URL, file upload, native
64
+ * icon, or custom emoji.
65
65
  *
66
66
  * @example
67
67
  * ```ts
@@ -73,6 +73,8 @@ function customEmojiIcon(id) {
73
73
  * // ...
74
74
  * });
75
75
  * ```
76
+ *
77
+ * @category Helpers
76
78
  */
77
79
  exports.icon = {
78
80
  emoji: emojiIcon,
@@ -107,7 +109,7 @@ function fileUploadCover(id) {
107
109
  return { type: 'file_upload', file_upload: { id } };
108
110
  }
109
111
  /**
110
- * Helpers for constructing cover image objects.
112
+ * Helpers that create cover image objects.
111
113
  *
112
114
  * @example
113
115
  * ```ts
@@ -119,6 +121,8 @@ function fileUploadCover(id) {
119
121
  * // ...
120
122
  * });
121
123
  * ```
124
+ *
125
+ * @category Helpers
122
126
  */
123
127
  exports.cover = {
124
128
  external: externalCover,
@@ -150,10 +154,10 @@ function uploadFile(id) {
150
154
  return { type: 'file_upload', file_upload: { id } };
151
155
  }
152
156
  /**
153
- * Helpers for constructing general Notion file objects.
157
+ * Helpers that create general Notion file objects.
154
158
  *
155
- * Useful for file blocks, image blocks, audio blocks, video blocks,
156
- * and file property entries.
159
+ * Use these helpers for file blocks, image blocks, audio blocks, video
160
+ * blocks, and file property entries.
157
161
  *
158
162
  * @example
159
163
  * ```ts
@@ -162,6 +166,8 @@ function uploadFile(id) {
162
166
  * notionFile.external('https://example.com/doc.pdf')
163
167
  * notionFile.upload('upload-id')
164
168
  * ```
169
+ *
170
+ * @category Helpers
165
171
  */
166
172
  exports.notionFile = {
167
173
  external: externalFile,
@@ -157,6 +157,8 @@ declare function or(...conditions: FilterCondition[]): FilterCondition;
157
157
  * ),
158
158
  * });
159
159
  * ```
160
+ *
161
+ * @category Helpers
160
162
  */
161
163
  export declare const filter: {
162
164
  text: (property: string) => TextFilter;
@@ -305,6 +305,8 @@ function or(...conditions) {
305
305
  * ),
306
306
  * });
307
307
  * ```
308
+ *
309
+ * @category Helpers
308
310
  */
309
311
  exports.filter = {
310
312
  // Property filters
@@ -1,10 +1,10 @@
1
1
  import type { PaginatedList } from '../schemas';
2
2
  /**
3
- * Pagination helper utilities for collecting all results from paginated Notion API endpoints.
3
+ * Pagination helpers that collect all results from paginated Notion API endpoints.
4
4
  *
5
- * The Notion API uses cursor-based pagination. All list endpoints return a `PaginatedList<T>`
6
- * with `results`, `next_cursor`, and `has_more` properties. These helpers automate the process
7
- * of fetching all pages.
5
+ * The Notion API uses cursor-based pagination. Each list endpoint returns a
6
+ * `PaginatedList<T>` object with `results`, `next_cursor`, and `has_more` properties.
7
+ * These helpers fetch every page automatically.
8
8
  *
9
9
  * @example
10
10
  * ```typescript
@@ -35,14 +35,16 @@ import type { PaginatedList } from '../schemas';
35
35
  */
36
36
  /**
37
37
  * Fetch function that returns a paginated list.
38
- * Receives an optional cursor and returns the next page of results.
38
+ * This function receives an optional cursor. It returns the next page of results.
39
+ *
40
+ * @category Pagination
39
41
  */
40
42
  export type PaginatedFetchFunction<T> = (cursor?: string) => Promise<PaginatedList<T>>;
41
43
  /**
42
44
  * Collects all results from a paginated endpoint by automatically following cursors.
43
45
  *
44
- * This function will keep fetching pages until `has_more` is `false`, collecting all
45
- * results into a single array. Use this when you need all results at once.
46
+ * This function fetches pages until `has_more` is `false`. It collects all results
47
+ * into one array. Use this function when you need all results at once.
46
48
  *
47
49
  * @param fetchPage - Function that fetches a single page of results
48
50
  * @returns Array containing all results from all pages
@@ -82,14 +84,16 @@ export type PaginatedFetchFunction<T> = (cursor?: string) => Promise<PaginatedLi
82
84
  * })
83
85
  * );
84
86
  * ```
87
+ *
88
+ * @category Pagination
85
89
  */
86
90
  export declare function paginate<T>(fetchPage: PaginatedFetchFunction<T>): Promise<T[]>;
87
91
  /**
88
92
  * Creates an async iterator that yields individual items from paginated results.
89
93
  *
90
- * This function provides memory-efficient iteration over large result sets by fetching
91
- * one page at a time and yielding items as needed. Use this with `for await...of` when
92
- * you want to process results one by one without loading everything into memory.
94
+ * This function iterates over large result sets without loading everything into
95
+ * memory. It fetches one page at a time and yields items as needed. Use this function
96
+ * with `for await...of` to process results one at a time.
93
97
  *
94
98
  * @param fetchPage - Function that fetches a single page of results
95
99
  * @yields Individual items from each page
@@ -124,13 +128,15 @@ export declare function paginate<T>(fetchPage: PaginatedFetchFunction<T>): Promi
124
128
  * console.log(result.url);
125
129
  * }
126
130
  * ```
131
+ *
132
+ * @category Pagination
127
133
  */
128
134
  export declare function paginateIterator<T>(fetchPage: PaginatedFetchFunction<T>): AsyncGenerator<T, void, undefined>;
129
135
  /**
130
- * Collects all results and returns both the items and pagination metadata.
136
+ * Collects all results. Returns the items together with pagination metadata.
131
137
  *
132
- * This function is useful when you need to know how many pages were fetched
133
- * or want to track the total number of API calls made.
138
+ * Use this function when you need the page count or the total number of API
139
+ * calls.
134
140
  *
135
141
  * @param fetchPage - Function that fetches a single page of results
136
142
  * @returns Object containing all results and pagination metadata
@@ -143,6 +149,8 @@ export declare function paginateIterator<T>(fetchPage: PaginatedFetchFunction<T>
143
149
  *
144
150
  * console.log(`Fetched ${totalCount} blocks across ${pageCount} pages`);
145
151
  * ```
152
+ *
153
+ * @category Pagination
146
154
  */
147
155
  export declare function paginateWithMetadata<T>(fetchPage: PaginatedFetchFunction<T>): Promise<{
148
156
  items: T[];
@@ -150,29 +158,33 @@ export declare function paginateWithMetadata<T>(fetchPage: PaginatedFetchFunctio
150
158
  totalCount: number;
151
159
  }>;
152
160
  /**
153
- * Fetch function for windowed row collection. Same as {@link PaginatedFetchFunction} plus
154
- * a second parameter carrying the ISO 8601 `created_time` lower bound for the *next*
155
- * window, present once the previous window was capped at the query result limit
156
- * (`request_status.type === 'incomplete'`). The caller merges this into their own
157
- * created_time-ascending query, e.g. `filter.createdTime('Created time').onOrAfter(createdTimeCursor)`.
161
+ * Fetch function for windowed row collection. It extends
162
+ * {@link PaginatedFetchFunction} with a second parameter: the ISO 8601
163
+ * `created_time` lower bound for the next window. This parameter appears only
164
+ * after the previous window hits the query result limit
165
+ * (`request_status.type === 'incomplete'`). Merge this bound into your own
166
+ * created_time-ascending query, for example
167
+ * `filter.createdTime().onOrAfter(createdTimeCursor)`.
168
+ *
169
+ * @category Pagination
158
170
  */
159
171
  export type WindowedFetchFunction<T extends {
160
172
  id: string;
161
173
  createdTime: Date;
162
174
  }> = (cursor: string | undefined, createdTimeCursor: string | undefined) => Promise<PaginatedList<T>>;
163
175
  /**
164
- * Iterates over every row of a data source query, transparently working around the
165
- * API's 10,000-result-per-query cap.
166
- *
167
- * Data source (and view) queries cap at 10,000 results; when capped, the response's
168
- * `has_more` is still `false`, so following `next_cursor`/`has_more` alone silently
169
- * truncates the result set. When a window is capped (`request_status.type ===
170
- * 'incomplete'`), this starts a new query filtered to `created_time >=` the last row
171
- * seen, de-duplicating by `id` across the window boundary. Requires the query to be
172
- * sorted by `created_time` ascending.
173
- *
174
- * @param fetchWindow - Function that fetches one page, given the current cursor and
175
- * (once a window has been capped) a `created_time` lower bound for the next window
176
+ * Iterates over every row of a data source query. It works around the API's
177
+ * 10,000-result-per-query cap.
178
+ *
179
+ * Data source and view queries cap at 10,000 results. When a query hits this cap, the
180
+ * response's `has_more` field is still `false`. Following `next_cursor` and `has_more`
181
+ * alone silently truncates the result set. When a window hits the cap
182
+ * (`request_status.type === 'incomplete'`), this function starts a new query filtered
183
+ * to `created_time >=` the last row seen. It de-duplicates rows by `id` across the
184
+ * window boundary. The query must sort by `created_time` in ascending order.
185
+ *
186
+ * @param fetchWindow - Function that fetches one page. Pass the current cursor. After
187
+ * a window hits the cap, also pass a `created_time` lower bound for the next window.
176
188
  * @yields Individual rows across all windows
177
189
  *
178
190
  * @example
@@ -182,24 +194,28 @@ export type WindowedFetchFunction<T extends {
182
194
  * start_cursor: cursor,
183
195
  * sorts: [{ timestamp: 'created_time', direction: 'ascending' }],
184
196
  * filter: createdTimeCursor
185
- * ? filter.and(baseFilter, filter.createdTime('Created time').onOrAfter(createdTimeCursor))
197
+ * ? filter.and(baseFilter, filter.createdTime().onOrAfter(createdTimeCursor))
186
198
  * : baseFilter,
187
199
  * }),
188
200
  * );
189
201
  * ```
202
+ *
203
+ * @category Pagination
190
204
  */
191
205
  export declare function iterateAllDataSourceRows<T extends {
192
206
  id: string;
193
207
  createdTime: Date;
194
208
  }>(fetchWindow: WindowedFetchFunction<T>): AsyncGenerator<T, void, undefined>;
195
209
  /**
196
- * Collects every row of a data source query into an array, transparently working
197
- * around the API's 10,000-result-per-query cap. See {@link iterateAllDataSourceRows}
198
- * for the windowing behavior.
210
+ * Collects every row of a data source query into an array. It works around the API's
211
+ * 10,000-result-per-query cap. See {@link iterateAllDataSourceRows} for the windowing
212
+ * behavior.
199
213
  *
200
- * @param fetchWindow - Function that fetches one page, given the current cursor and
201
- * (once a window has been capped) a `created_time` lower bound for the next window
214
+ * @param fetchWindow - Function that fetches one page. Pass the current cursor. After
215
+ * a window hits the cap, also pass a `created_time` lower bound for the next window.
202
216
  * @returns Array containing all rows across all windows
217
+ *
218
+ * @category Pagination
203
219
  */
204
220
  export declare function collectAllDataSourceRows<T extends {
205
221
  id: string;
@@ -8,8 +8,8 @@ exports.collectAllDataSourceRows = collectAllDataSourceRows;
8
8
  /**
9
9
  * Collects all results from a paginated endpoint by automatically following cursors.
10
10
  *
11
- * This function will keep fetching pages until `has_more` is `false`, collecting all
12
- * results into a single array. Use this when you need all results at once.
11
+ * This function fetches pages until `has_more` is `false`. It collects all results
12
+ * into one array. Use this function when you need all results at once.
13
13
  *
14
14
  * @param fetchPage - Function that fetches a single page of results
15
15
  * @returns Array containing all results from all pages
@@ -49,6 +49,8 @@ exports.collectAllDataSourceRows = collectAllDataSourceRows;
49
49
  * })
50
50
  * );
51
51
  * ```
52
+ *
53
+ * @category Pagination
52
54
  */
53
55
  async function paginate(fetchPage) {
54
56
  const all = [];
@@ -63,9 +65,9 @@ async function paginate(fetchPage) {
63
65
  /**
64
66
  * Creates an async iterator that yields individual items from paginated results.
65
67
  *
66
- * This function provides memory-efficient iteration over large result sets by fetching
67
- * one page at a time and yielding items as needed. Use this with `for await...of` when
68
- * you want to process results one by one without loading everything into memory.
68
+ * This function iterates over large result sets without loading everything into
69
+ * memory. It fetches one page at a time and yields items as needed. Use this function
70
+ * with `for await...of` to process results one at a time.
69
71
  *
70
72
  * @param fetchPage - Function that fetches a single page of results
71
73
  * @yields Individual items from each page
@@ -100,6 +102,8 @@ async function paginate(fetchPage) {
100
102
  * console.log(result.url);
101
103
  * }
102
104
  * ```
105
+ *
106
+ * @category Pagination
103
107
  */
104
108
  async function* paginateIterator(fetchPage) {
105
109
  let cursor;
@@ -112,10 +116,10 @@ async function* paginateIterator(fetchPage) {
112
116
  } while (cursor);
113
117
  }
114
118
  /**
115
- * Collects all results and returns both the items and pagination metadata.
119
+ * Collects all results. Returns the items together with pagination metadata.
116
120
  *
117
- * This function is useful when you need to know how many pages were fetched
118
- * or want to track the total number of API calls made.
121
+ * Use this function when you need the page count or the total number of API
122
+ * calls.
119
123
  *
120
124
  * @param fetchPage - Function that fetches a single page of results
121
125
  * @returns Object containing all results and pagination metadata
@@ -128,6 +132,8 @@ async function* paginateIterator(fetchPage) {
128
132
  *
129
133
  * console.log(`Fetched ${totalCount} blocks across ${pageCount} pages`);
130
134
  * ```
135
+ *
136
+ * @category Pagination
131
137
  */
132
138
  async function paginateWithMetadata(fetchPage) {
133
139
  const items = [];
@@ -146,18 +152,18 @@ async function paginateWithMetadata(fetchPage) {
146
152
  };
147
153
  }
148
154
  /**
149
- * Iterates over every row of a data source query, transparently working around the
150
- * API's 10,000-result-per-query cap.
151
- *
152
- * Data source (and view) queries cap at 10,000 results; when capped, the response's
153
- * `has_more` is still `false`, so following `next_cursor`/`has_more` alone silently
154
- * truncates the result set. When a window is capped (`request_status.type ===
155
- * 'incomplete'`), this starts a new query filtered to `created_time >=` the last row
156
- * seen, de-duplicating by `id` across the window boundary. Requires the query to be
157
- * sorted by `created_time` ascending.
158
- *
159
- * @param fetchWindow - Function that fetches one page, given the current cursor and
160
- * (once a window has been capped) a `created_time` lower bound for the next window
155
+ * Iterates over every row of a data source query. It works around the API's
156
+ * 10,000-result-per-query cap.
157
+ *
158
+ * Data source and view queries cap at 10,000 results. When a query hits this cap, the
159
+ * response's `has_more` field is still `false`. Following `next_cursor` and `has_more`
160
+ * alone silently truncates the result set. When a window hits the cap
161
+ * (`request_status.type === 'incomplete'`), this function starts a new query filtered
162
+ * to `created_time >=` the last row seen. It de-duplicates rows by `id` across the
163
+ * window boundary. The query must sort by `created_time` in ascending order.
164
+ *
165
+ * @param fetchWindow - Function that fetches one page. Pass the current cursor. After
166
+ * a window hits the cap, also pass a `created_time` lower bound for the next window.
161
167
  * @yields Individual rows across all windows
162
168
  *
163
169
  * @example
@@ -167,14 +173,21 @@ async function paginateWithMetadata(fetchPage) {
167
173
  * start_cursor: cursor,
168
174
  * sorts: [{ timestamp: 'created_time', direction: 'ascending' }],
169
175
  * filter: createdTimeCursor
170
- * ? filter.and(baseFilter, filter.createdTime('Created time').onOrAfter(createdTimeCursor))
176
+ * ? filter.and(baseFilter, filter.createdTime().onOrAfter(createdTimeCursor))
171
177
  * : baseFilter,
172
178
  * }),
173
179
  * );
174
180
  * ```
181
+ *
182
+ * @category Pagination
175
183
  */
176
184
  async function* iterateAllDataSourceRows(fetchWindow) {
177
- const seenIds = new Set();
185
+ // Rows repeat across a window boundary only when they share the exact `created_time`
186
+ // used as the next window's lower bound (results are sorted ascending by created_time,
187
+ // so ties are always contiguous). Tracking only that trailing tie group -- instead of
188
+ // every id ever yielded -- keeps memory bounded regardless of result set size.
189
+ let tailTimeMs;
190
+ let tailIds = new Set();
178
191
  let cursor;
179
192
  let createdTimeCursor;
180
193
  let lastCreatedTime;
@@ -183,10 +196,15 @@ async function* iterateAllDataSourceRows(fetchWindow) {
183
196
  const response = await fetchWindow(cursor, createdTimeCursor);
184
197
  let yieldedThisWindow = false;
185
198
  for (const item of response.results) {
186
- if (seenIds.has(item.id)) {
199
+ const itemTimeMs = item.createdTime.getTime();
200
+ if (tailTimeMs !== undefined && itemTimeMs === tailTimeMs && tailIds.has(item.id)) {
187
201
  continue;
188
202
  }
189
- seenIds.add(item.id);
203
+ if (tailTimeMs === undefined || itemTimeMs > tailTimeMs) {
204
+ tailTimeMs = itemTimeMs;
205
+ tailIds = new Set();
206
+ }
207
+ tailIds.add(item.id);
190
208
  lastCreatedTime = item.createdTime;
191
209
  yieldedThisWindow = true;
192
210
  yield item;
@@ -214,13 +232,15 @@ async function* iterateAllDataSourceRows(fetchWindow) {
214
232
  }
215
233
  }
216
234
  /**
217
- * Collects every row of a data source query into an array, transparently working
218
- * around the API's 10,000-result-per-query cap. See {@link iterateAllDataSourceRows}
219
- * for the windowing behavior.
235
+ * Collects every row of a data source query into an array. It works around the API's
236
+ * 10,000-result-per-query cap. See {@link iterateAllDataSourceRows} for the windowing
237
+ * behavior.
220
238
  *
221
- * @param fetchWindow - Function that fetches one page, given the current cursor and
222
- * (once a window has been capped) a `created_time` lower bound for the next window
239
+ * @param fetchWindow - Function that fetches one page. Pass the current cursor. After
240
+ * a window hits the cap, also pass a `created_time` lower bound for the next window.
223
241
  * @returns Array containing all rows across all windows
242
+ *
243
+ * @category Pagination
224
244
  */
225
245
  async function collectAllDataSourceRows(fetchWindow) {
226
246
  const all = [];
@@ -22,8 +22,8 @@ declare function database(databaseId: string): {
22
22
  };
23
23
  /**
24
24
  * Create a data source parent object.
25
- * Both data_source_id and database_id are required when creating a page
26
- * with a data source parent.
25
+ * A page with a data source parent needs both `data_source_id` and
26
+ * `database_id`.
27
27
  *
28
28
  * @example
29
29
  * ```ts
@@ -51,7 +51,7 @@ declare function workspace(): {
51
51
  workspace: true;
52
52
  };
53
53
  /**
54
- * Create a block parent object (used for comments on blocks).
54
+ * Create a block parent object for comments on blocks.
55
55
  *
56
56
  * @example
57
57
  * ```ts
@@ -86,6 +86,8 @@ declare function blockParent(blockId: string): {
86
86
  * rich_text: [...],
87
87
  * });
88
88
  * ```
89
+ *
90
+ * @category Helpers
89
91
  */
90
92
  export declare const parent: {
91
93
  page: typeof page;
@@ -28,8 +28,8 @@ function database(databaseId) {
28
28
  }
29
29
  /**
30
30
  * Create a data source parent object.
31
- * Both data_source_id and database_id are required when creating a page
32
- * with a data source parent.
31
+ * A page with a data source parent needs both `data_source_id` and
32
+ * `database_id`.
33
33
  *
34
34
  * @example
35
35
  * ```ts
@@ -56,7 +56,7 @@ function workspace() {
56
56
  return { workspace: true };
57
57
  }
58
58
  /**
59
- * Create a block parent object (used for comments on blocks).
59
+ * Create a block parent object for comments on blocks.
60
60
  *
61
61
  * @example
62
62
  * ```ts
@@ -94,6 +94,8 @@ function blockParent(blockId) {
94
94
  * rich_text: [...],
95
95
  * });
96
96
  * ```
97
+ *
98
+ * @category Helpers
97
99
  */
98
100
  exports.parent = {
99
101
  page,
@@ -255,6 +255,8 @@ declare function files(entries: FileEntry[]): {
255
255
  * },
256
256
  * });
257
257
  * ```
258
+ *
259
+ * @category Helpers
258
260
  */
259
261
  export declare const prop: {
260
262
  title: typeof title;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prop = void 0;
4
4
  const validation_1 = require("../validation");
5
5
  const richText_helpers_1 = require("./richText.helpers");
6
- /** Resolve rich text input to a `NotionRichText` array. */
6
+ /** Resolve rich text input to a `NotionRichText`. */
7
7
  function resolveRichText(input) {
8
8
  if (typeof input === 'string') {
9
9
  (0, validation_1.validateStringLength)(input, validation_1.LIMITS.RICH_TEXT_CONTENT, 'Rich text content');
@@ -278,6 +278,8 @@ function files(entries) {
278
278
  * },
279
279
  * });
280
280
  * ```
281
+ *
282
+ * @category Helpers
281
283
  */
282
284
  exports.prop = {
283
285
  title,
@@ -5,8 +5,9 @@ import type { NotionColor, NotionRichText, NotionUser, TextRichText } from '../s
5
5
  * Do not instantiate directly — use the {@link richText} factory function or
6
6
  * the static helpers on it (`richText.mentionPage`, `richText.equation`, etc.).
7
7
  *
8
- * Call `.build()` to produce a `NotionRichText` array (single-element),
9
- * or pass builders directly to `richText.join()` which calls `.build()` for you.
8
+ * Call `.build()` to produce a single-element `NotionRichText`.
9
+ * Alternatively, pass builders directly to `richText.join()`. This method
10
+ * calls `.build()` for you.
10
11
  *
11
12
  * @example
12
13
  * ```ts
@@ -26,6 +27,8 @@ import type { NotionColor, NotionRichText, NotionUser, TextRichText } from '../s
26
27
  * richText('!'),
27
28
  * );
28
29
  * ```
30
+ *
31
+ * @category Rich Text
29
32
  */
30
33
  export declare class RichTextBuilder {
31
34
  /** @internal */
@@ -52,7 +55,7 @@ export declare class RichTextBuilder {
52
55
  */
53
56
  link(url: string): this;
54
57
  /**
55
- * Build a single-element `NotionRichText` array from this builder.
58
+ * Build a single-element `NotionRichText` from this builder.
56
59
  */
57
60
  build(): NotionRichText;
58
61
  }
@@ -99,8 +102,8 @@ declare function mentionLinkPreview(url: string): RichTextBuilder;
99
102
  */
100
103
  declare function equation(expression: string): RichTextBuilder;
101
104
  /**
102
- * Combine multiple rich text builders (or pre-built `NotionRichText` arrays)
103
- * into a single `NotionRichText` array.
105
+ * Combine multiple rich text builders (or pre-built `NotionRichText` values)
106
+ * into a single `NotionRichText`.
104
107
  *
105
108
  * @example
106
109
  * ```ts
@@ -136,6 +139,8 @@ declare function join(...parts: Array<RichTextBuilder | NotionRichText>): Notion
136
139
  * richText('italic').italic(),
137
140
  * );
138
141
  * ```
142
+ *
143
+ * @category Rich Text
139
144
  */
140
145
  export declare const richText: typeof createRichText & {
141
146
  mentionPage: typeof mentionPage;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.richText = exports.RichTextBuilder = void 0;
4
4
  const validation_1 = require("../validation");
5
5
  /**
6
- * Default annotations object with no formatting applied.
6
+ * Default annotations object with no formatting.
7
7
  */
8
8
  const DEFAULT_ANNOTATIONS = {
9
9
  bold: false,
@@ -19,8 +19,9 @@ const DEFAULT_ANNOTATIONS = {
19
19
  * Do not instantiate directly — use the {@link richText} factory function or
20
20
  * the static helpers on it (`richText.mentionPage`, `richText.equation`, etc.).
21
21
  *
22
- * Call `.build()` to produce a `NotionRichText` array (single-element),
23
- * or pass builders directly to `richText.join()` which calls `.build()` for you.
22
+ * Call `.build()` to produce a single-element `NotionRichText`.
23
+ * Alternatively, pass builders directly to `richText.join()`. This method
24
+ * calls `.build()` for you.
24
25
  *
25
26
  * @example
26
27
  * ```ts
@@ -40,6 +41,8 @@ const DEFAULT_ANNOTATIONS = {
40
41
  * richText('!'),
41
42
  * );
42
43
  * ```
44
+ *
45
+ * @category Rich Text
43
46
  */
44
47
  class RichTextBuilder {
45
48
  /** @internal */
@@ -93,7 +96,7 @@ class RichTextBuilder {
93
96
  return this;
94
97
  }
95
98
  /**
96
- * Build a single-element `NotionRichText` array from this builder.
99
+ * Build a single-element `NotionRichText` from this builder.
97
100
  */
98
101
  build() {
99
102
  return [{ ...this.segment, annotations: { ...this.annotations } }];
@@ -218,8 +221,8 @@ function equation(expression) {
218
221
  return new RichTextBuilder(segment);
219
222
  }
220
223
  /**
221
- * Combine multiple rich text builders (or pre-built `NotionRichText` arrays)
222
- * into a single `NotionRichText` array.
224
+ * Combine multiple rich text builders (or pre-built `NotionRichText` values)
225
+ * into a single `NotionRichText`.
223
226
  *
224
227
  * @example
225
228
  * ```ts
@@ -269,6 +272,8 @@ function join(...parts) {
269
272
  * richText('italic').italic(),
270
273
  * );
271
274
  * ```
275
+ *
276
+ * @category Rich Text
272
277
  */
273
278
  exports.richText = Object.assign(createRichText, {
274
279
  mentionPage,