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

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 +20 -88
  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 +10 -3
  13. package/dist/api/dataSources.api.js +4 -1
  14. package/dist/api/databases.api.d.ts +21 -8
  15. package/dist/api/databases.api.js +8 -4
  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 +8 -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 +21 -4
  29. package/dist/errors.js +17 -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 +10 -3
  59. package/dist/models/dataSource.model.js +11 -2
  60. package/dist/models/database.model.d.ts +11 -3
  61. package/dist/models/database.model.js +14 -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 +9 -2
  69. package/dist/models/user.model.js +14 -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 +24 -3
  87. package/dist/schemas/dataSource.schema.js +15 -5
  88. package/dist/schemas/database.schema.d.ts +31 -1
  89. package/dist/schemas/database.schema.js +18 -2
  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 +8 -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 +81 -3
  105. package/dist/schemas/pageProperties.schema.js +7 -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 +46 -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 +20 -16
@@ -2,7 +2,9 @@ import type { CodeBlockLanguage, NotionColor, NotionRichText } from '../schemas'
2
2
  import { RichTextBuilder } from './richText.helpers';
3
3
  /**
4
4
  * Accepted rich text input: a plain string, a {@link RichTextBuilder}, or
5
- * a pre-built `NotionRichText` array.
5
+ * a pre-built `NotionRichText`.
6
+ *
7
+ * @category Rich Text
6
8
  */
7
9
  export type RichTextInput = string | RichTextBuilder | NotionRichText;
8
10
  /** Common options shared by text-bearing blocks. */
@@ -10,7 +12,7 @@ interface TextBlockOptions {
10
12
  color?: NotionColor;
11
13
  children?: unknown[];
12
14
  }
13
- /** The minimal block object accepted by the Notion API for creation. */
15
+ /** The Notion API accepts this minimal block object for creation. */
14
16
  interface BlockObject {
15
17
  object: 'block';
16
18
  type: string;
@@ -18,7 +20,7 @@ interface BlockObject {
18
20
  }
19
21
  /** Options for paragraph blocks. */
20
22
  interface ParagraphOptions extends TextBlockOptions {
21
- /** Icon shown alongside the paragraph. Only meaningful for paragraphs used as tab items. */
23
+ /** Icon for the paragraph. Applies only to paragraphs used as tab items. */
22
24
  icon?: unknown;
23
25
  }
24
26
  /**
@@ -72,12 +74,12 @@ declare function template(text: RichTextInput, options?: {
72
74
  children?: unknown[];
73
75
  }): BlockObject;
74
76
  /**
75
- * @deprecated Meeting-notes blocks are server-managed -- their real shape (`title`,
76
- * `status`, and child block IDs for the summary/notes/transcript) is populated by
77
- * Notion, not hand-constructed by clients. This helper's `rich_text`-based output no
78
- * longer matches `blockSchema`'s `meeting_notes` shape and is not a valid way to
79
- * create a meeting-notes block. Kept only to avoid an abrupt removal from the helper
80
- * surface; do not use for new code.
77
+ * @deprecated Notion manages meeting-notes blocks on the server. Notion populates the
78
+ * real shape (`title`, `status`, and child block IDs for the summary, notes, and
79
+ * transcript). Clients do not construct this shape by hand. This helper's
80
+ * `rich_text`-based output no longer matches the `meeting_notes` shape in
81
+ * `blockSchema`. Do not use this helper to create a meeting-notes block. It remains
82
+ * only to avoid an abrupt removal from the helper surface. Do not use it in new code.
81
83
  */
82
84
  declare function meetingNotes(text: RichTextInput, options?: {
83
85
  children?: unknown[];
@@ -129,7 +131,10 @@ declare function table(width: number, options?: TableOptions): BlockObject;
129
131
  declare function tableRow(cells: RichTextInput[]): BlockObject;
130
132
  declare function columnList(columns: unknown[][]): BlockObject;
131
133
  declare function column(children: unknown[]): BlockObject;
132
- /** A single tab: its label becomes the tab's paragraph rich text, `children` its content. */
134
+ /**
135
+ * A single tab. Its label becomes the tab's paragraph rich text.
136
+ * Its `children` become the tab's content.
137
+ */
133
138
  interface TabItem {
134
139
  label: RichTextInput;
135
140
  icon?: unknown;
@@ -137,9 +142,9 @@ interface TabItem {
137
142
  children?: unknown[];
138
143
  }
139
144
  /**
140
- * Create a tab block. Only `paragraph` blocks may be direct children of a tab block --
141
- * each tab is modeled as one paragraph, whose rich text is the tab label and whose
142
- * `children` hold the tab's content.
145
+ * Create a tab block. A tab block accepts only `paragraph` blocks as direct children.
146
+ * Each tab is one paragraph. The paragraph's rich text holds the tab label. The
147
+ * paragraph's `children` hold the tab's content.
143
148
  *
144
149
  * @example
145
150
  * ```ts
@@ -161,9 +166,9 @@ declare function syncedBlock(options?: {
161
166
  children?: unknown[];
162
167
  }): BlockObject;
163
168
  /**
164
- * Factory functions for constructing Notion block objects.
169
+ * Factory functions that create Notion block objects.
165
170
  *
166
- * Every function returns a plain object ready to pass to
171
+ * Every function returns a plain object. Pass this object to
167
172
  * `blocks.children.append()` or `pages.create()`.
168
173
  *
169
174
  * @example
@@ -189,6 +194,8 @@ declare function syncedBlock(options?: {
189
194
  * }),
190
195
  * ];
191
196
  * ```
197
+ *
198
+ * @category Helpers
192
199
  */
193
200
  export declare const block: {
194
201
  paragraph: typeof paragraph;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.block = void 0;
4
4
  const validation_1 = require("../validation");
5
5
  const richText_helpers_1 = require("./richText.helpers");
6
- /** Resolve a {@link RichTextInput} into a `NotionRichText` array. */
6
+ /** Resolve a {@link RichTextInput} into 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');
@@ -181,12 +181,12 @@ function template(text, options) {
181
181
  };
182
182
  }
183
183
  /**
184
- * @deprecated Meeting-notes blocks are server-managed -- their real shape (`title`,
185
- * `status`, and child block IDs for the summary/notes/transcript) is populated by
186
- * Notion, not hand-constructed by clients. This helper's `rich_text`-based output no
187
- * longer matches `blockSchema`'s `meeting_notes` shape and is not a valid way to
188
- * create a meeting-notes block. Kept only to avoid an abrupt removal from the helper
189
- * surface; do not use for new code.
184
+ * @deprecated Notion manages meeting-notes blocks on the server. Notion populates the
185
+ * real shape (`title`, `status`, and child block IDs for the summary, notes, and
186
+ * transcript). Clients do not construct this shape by hand. This helper's
187
+ * `rich_text`-based output no longer matches the `meeting_notes` shape in
188
+ * `blockSchema`. Do not use this helper to create a meeting-notes block. It remains
189
+ * only to avoid an abrupt removal from the helper surface. Do not use it in new code.
190
190
  */
191
191
  function meetingNotes(text, options) {
192
192
  return {
@@ -367,9 +367,9 @@ function column(children) {
367
367
  };
368
368
  }
369
369
  /**
370
- * Create a tab block. Only `paragraph` blocks may be direct children of a tab block --
371
- * each tab is modeled as one paragraph, whose rich text is the tab label and whose
372
- * `children` hold the tab's content.
370
+ * Create a tab block. A tab block accepts only `paragraph` blocks as direct children.
371
+ * Each tab is one paragraph. The paragraph's rich text holds the tab label. The
372
+ * paragraph's `children` hold the tab's content.
373
373
  *
374
374
  * @example
375
375
  * ```ts
@@ -411,9 +411,9 @@ function syncedBlock(options) {
411
411
  // Public export
412
412
  // ---------------------------------------------------------------------------
413
413
  /**
414
- * Factory functions for constructing Notion block objects.
414
+ * Factory functions that create Notion block objects.
415
415
  *
416
- * Every function returns a plain object ready to pass to
416
+ * Every function returns a plain object. Pass this object to
417
417
  * `blocks.children.append()` or `pages.create()`.
418
418
  *
419
419
  * @example
@@ -439,6 +439,8 @@ function syncedBlock(options) {
439
439
  * }),
440
440
  * ];
441
441
  * ```
442
+ *
443
+ * @category Helpers
442
444
  */
443
445
  exports.block = {
444
446
  // Text blocks
@@ -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;