@notionhq/client 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/build/package.json +1 -1
- package/build/src/Client.d.ts +3 -3
- package/build/src/Client.d.ts.map +1 -1
- package/build/src/Client.js +6 -1
- package/build/src/Client.js.map +1 -1
- package/build/src/api-endpoints.d.ts +227 -208
- package/build/src/api-endpoints.d.ts.map +1 -1
- package/build/src/api-endpoints.js +3 -3
- package/build/src/api-endpoints.js.map +1 -1
- package/build/src/errors.d.ts +3 -3
- package/build/src/errors.d.ts.map +1 -1
- package/build/src/fetch-types.d.ts +7 -7
- package/build/src/fetch-types.d.ts.map +1 -1
- package/build/src/helpers.d.ts +1 -1
- package/build/src/helpers.js +1 -1
- package/build/src/helpers.js.map +1 -1
- package/build/src/type-utils.d.ts +1 -1
- package/build/src/type-utils.d.ts.map +1 -1
- package/build/src/utils.d.ts +1 -1
- package/build/src/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/build/src/errors.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare enum ClientErrorCode {
|
|
|
25
25
|
/**
|
|
26
26
|
* Error codes on errors thrown by the `Client`.
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type NotionErrorCode = APIErrorCode | ClientErrorCode;
|
|
29
29
|
/**
|
|
30
30
|
* Base error type.
|
|
31
31
|
*/
|
|
@@ -35,7 +35,7 @@ declare abstract class NotionClientErrorBase<Code extends NotionErrorCode> exten
|
|
|
35
35
|
/**
|
|
36
36
|
* Error type that encompasses all the kinds of errors that the Notion client will throw.
|
|
37
37
|
*/
|
|
38
|
-
export
|
|
38
|
+
export type NotionClientError = RequestTimeoutError | UnknownHTTPResponseError | APIResponseError;
|
|
39
39
|
/**
|
|
40
40
|
* @param error any value, usually a caught error.
|
|
41
41
|
* @returns `true` if error is a `NotionClientError`.
|
|
@@ -51,7 +51,7 @@ export declare class RequestTimeoutError extends NotionClientErrorBase<ClientErr
|
|
|
51
51
|
static isRequestTimeoutError(error: unknown): error is RequestTimeoutError;
|
|
52
52
|
static rejectAfterTimeout<T>(promise: Promise<T>, timeoutMS: number): Promise<T>;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
type HTTPResponseErrorCode = ClientErrorCode.ResponseError | APIErrorCode;
|
|
55
55
|
declare class HTTPResponseError<Code extends HTTPResponseErrorCode> extends NotionClientErrorBase<Code> {
|
|
56
56
|
readonly name: string;
|
|
57
57
|
readonly code: Code;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAIjD;;GAEG;AACH,oBAAY,YAAY;IACtB,YAAY,iBAAiB;IAC7B,kBAAkB,wBAAwB;IAC1C,cAAc,qBAAqB;IACnC,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAC5B,iBAAiB,wBAAwB;IACzC,cAAc,oBAAoB;IAClC,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,mBAAmB,0BAA0B;IAC7C,kBAAkB,wBAAwB;CAC3C;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,cAAc,oCAAoC;IAClD,aAAa,mCAAmC;CACjD;AAED;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAIjD;;GAEG;AACH,oBAAY,YAAY;IACtB,YAAY,iBAAiB;IAC7B,kBAAkB,wBAAwB;IAC1C,cAAc,qBAAqB;IACnC,WAAW,iBAAiB;IAC5B,WAAW,iBAAiB;IAC5B,iBAAiB,wBAAwB;IACzC,cAAc,oBAAoB;IAClC,eAAe,qBAAqB;IACpC,aAAa,mBAAmB;IAChC,mBAAmB,0BAA0B;IAC7C,kBAAkB,wBAAwB;CAC3C;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,cAAc,oCAAoC;IAClD,aAAa,mCAAmC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,eAAe,CAAA;AAE5D;;GAEG;AACH,uBAAe,qBAAqB,CAClC,IAAI,SAAS,eAAe,CAC5B,SAAQ,KAAK;IACb,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,mBAAmB,GACnB,wBAAwB,GACxB,gBAAgB,CAAA;AAapB;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAE5B;AAeD;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,qBAAqB,CAAC,eAAe,CAAC,cAAc,CAAC;IAC5F,QAAQ,CAAC,IAAI,kCAAiC;IAC9C,QAAQ,CAAC,IAAI,yBAAwB;gBAEzB,OAAO,SAAwC;IAI3D,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB;IAM1E,MAAM,CAAC,kBAAkB,CAAC,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC;CAYd;AAED,KAAK,qBAAqB,GAAG,eAAe,CAAC,aAAa,GAAG,YAAY,CAAA;AAEzE,cAAM,iBAAiB,CACrB,IAAI,SAAS,qBAAqB,CAClC,SAAQ,qBAAqB,CAAC,IAAI,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAsB;IAC3C,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBAET,IAAI,EAAE;QAChB,IAAI,EAAE,IAAI,CAAA;QACV,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;QACrC,WAAW,EAAE,MAAM,CAAA;KACpB;CAQF;AAiBD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,wBAAwB,GAAG,gBAAgB,CAWtD;AAED;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,iBAAiB,CAAC,eAAe,CAAC,aAAa,CAAC;IAC5F,QAAQ,CAAC,IAAI,8BAA6B;gBAE9B,IAAI,EAAE;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;QAC3B,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAA;QACrC,WAAW,EAAE,MAAM,CAAA;KACpB;IAUD,MAAM,CAAC,0BAA0B,CAC/B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,wBAAwB;CAKrC;AAgBD;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,iBAAiB,CAAC,YAAY,CAAC;IACnE,QAAQ,CAAC,IAAI,sBAAqB;IAElC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB;CAGrE;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,iBAAiB,EAC3B,QAAQ,EAAE,MAAM,GACf,gBAAgB,GAAG,wBAAwB,CAiB7C"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import type { RequestInit as NodeRequestInit, Response as NodeResponse } from "node-fetch";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export
|
|
3
|
+
type FetchFn = typeof fetch;
|
|
4
|
+
type FetchResponse = Awaited<ReturnType<FetchFn>>;
|
|
5
|
+
type RequestInit = NonNullable<Parameters<FetchFn>[1]>;
|
|
6
|
+
export type SupportedRequestInfo = string;
|
|
7
|
+
export type SupportedRequestInit = {
|
|
8
8
|
agent?: NodeRequestInit["agent"];
|
|
9
9
|
body?: NonNullable<RequestInit["body"]> & NonNullable<NodeRequestInit["body"]>;
|
|
10
10
|
headers?: NonNullable<RequestInit["headers"]> & NonNullable<NodeRequestInit["headers"]>;
|
|
11
11
|
method?: RequestInit["method"];
|
|
12
12
|
redirect?: RequestInit["redirect"];
|
|
13
13
|
};
|
|
14
|
-
export
|
|
15
|
-
export
|
|
14
|
+
export type SupportedResponse = FetchResponse | NodeResponse;
|
|
15
|
+
export type SupportedFetch = (url: SupportedRequestInfo, init?: SupportedRequestInit) => Promise<SupportedResponse>;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=fetch-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-types.d.ts","sourceRoot":"","sources":["../../src/fetch-types.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,WAAW,IAAI,eAAe,EAC9B,QAAQ,IAAI,YAAY,EACzB,MAAM,YAAY,CAAA;AAEnB,
|
|
1
|
+
{"version":3,"file":"fetch-types.d.ts","sourceRoot":"","sources":["../../src/fetch-types.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EACV,WAAW,IAAI,eAAe,EAC9B,QAAQ,IAAI,YAAY,EACzB,MAAM,YAAY,CAAA;AAEnB,KAAK,OAAO,GAAG,OAAO,KAAK,CAAA;AAC3B,KAAK,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;AAEjD,KAAK,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAGzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAA;IAC9E,OAAO,CAAC,EAAE,WAAW,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,GAC3C,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAA;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC9B,QAAQ,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAA;CACnC,CAAA;AAGD,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,YAAY,CAAA;AAE5D,MAAM,MAAM,cAAc,GAAG,CAC3B,GAAG,EAAE,oBAAoB,EACzB,IAAI,CAAC,EAAE,oBAAoB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAAA"}
|
package/build/src/helpers.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare function iteratePaginatedAPI<Args extends PaginatedArgs, Item>(li
|
|
|
34
34
|
* Example (given a notion Client called `notion`):
|
|
35
35
|
*
|
|
36
36
|
* ```
|
|
37
|
-
* const blocks = collectPaginatedAPI(notion.blocks.children.list, {
|
|
37
|
+
* const blocks = await collectPaginatedAPI(notion.blocks.children.list, {
|
|
38
38
|
* block_id: parentBlockId,
|
|
39
39
|
* })
|
|
40
40
|
* // Do something with blocks.
|
package/build/src/helpers.js
CHANGED
|
@@ -38,7 +38,7 @@ exports.iteratePaginatedAPI = iteratePaginatedAPI;
|
|
|
38
38
|
* Example (given a notion Client called `notion`):
|
|
39
39
|
*
|
|
40
40
|
* ```
|
|
41
|
-
* const blocks = collectPaginatedAPI(notion.blocks.children.list, {
|
|
41
|
+
* const blocks = await collectPaginatedAPI(notion.blocks.children.list, {
|
|
42
42
|
* block_id: parentBlockId,
|
|
43
43
|
* })
|
|
44
44
|
* // Do something with blocks.
|
package/build/src/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;AAwBA;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,SAAS,CAAC,CAAC,mBAAmB,CACxC,MAAoD,EACpD,aAAmB;IAEnB,IAAI,UAAU,GAA8B,aAAa,CAAC,YAAY,CAAA;IACtE,GAAG;QACD,MAAM,QAAQ,GAAwB,MAAM,MAAM,CAAC;YACjD,GAAG,aAAa;YAChB,YAAY,EAAE,UAAU;SACzB,CAAC,CAAA;QACF,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAA;QACvB,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAA;KAClC,QAAQ,UAAU,EAAC;AACtB,CAAC;AAbD,kDAaC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,mBAAmB,CACvC,MAAoD,EACpD,aAAmB;IAEnB,MAAM,OAAO,GAAW,EAAE,CAAA;IAC1B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;QACnE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACnB;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AATD,kDASC;AAED;;GAEG;AACH,SAAgB,WAAW,CACzB,QAA0D;IAE1D,OAAO,MAAM,IAAI,QAAQ,CAAA;AAC3B,CAAC;AAJD,kCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,QAAwD;IAExD,OAAO,KAAK,IAAI,QAAQ,CAAA;AAC1B,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,cAAc,CAC5B,QAAgE;IAEhE,OAAO,OAAO,IAAI,QAAQ,CAAA;AAC5B,CAAC;AAJD,wCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,QAAwD;IAExD,OAAO,MAAM,IAAI,QAAQ,CAAA;AAC3B,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,aAAa,CAC3B,QAA8D;IAE9D,OAAO,YAAY,IAAI,QAAQ,CAAA;AACjC,CAAC;AAJD,sCAIC","sourcesContent":["import {\n BlockObjectResponse,\n CommentObjectResponse,\n DatabaseObjectResponse,\n PageObjectResponse,\n PartialBlockObjectResponse,\n PartialCommentObjectResponse,\n PartialDatabaseObjectResponse,\n PartialPageObjectResponse,\n PartialUserObjectResponse,\n UserObjectResponse,\n} from \"./api-endpoints\"\n\ninterface PaginatedArgs {\n start_cursor?: string\n}\n\ninterface PaginatedList<T> {\n object: \"list\"\n results: T[]\n next_cursor: string | null\n has_more: boolean\n}\n\n/**\n * Returns an async iterator over the results of any paginated Notion API.\n *\n * Example (given a notion Client called `notion`):\n *\n * ```\n * for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {\n * block_id: parentBlockId,\n * })) {\n * // Do something with block.\n * }\n * ```\n *\n * @param listFn A bound function on the Notion client that represents a conforming paginated\n * API. Example: `notion.blocks.children.list`.\n * @param firstPageArgs Arguments that should be passed to the API on the first and subsequent\n * calls to the API. Any necessary `next_cursor` will be automatically populated by\n * this function. Example: `{ block_id: \"<my block id>\" }`\n */\nexport async function* iteratePaginatedAPI<Args extends PaginatedArgs, Item>(\n listFn: (args: Args) => Promise<PaginatedList<Item>>,\n firstPageArgs: Args\n): AsyncIterableIterator<Item> {\n let nextCursor: string | null | undefined = firstPageArgs.start_cursor\n do {\n const response: PaginatedList<Item> = await listFn({\n ...firstPageArgs,\n start_cursor: nextCursor,\n })\n yield* response.results\n nextCursor = response.next_cursor\n } while (nextCursor)\n}\n\n/**\n * Collect all of the results of paginating an API into an in-memory array.\n *\n * Example (given a notion Client called `notion`):\n *\n * ```\n * const blocks = collectPaginatedAPI(notion.blocks.children.list, {\n * block_id: parentBlockId,\n * })\n * // Do something with blocks.\n * ```\n *\n * @param listFn A bound function on the Notion client that represents a conforming paginated\n * API. Example: `notion.blocks.children.list`.\n * @param firstPageArgs Arguments that should be passed to the API on the first and subsequent\n * calls to the API. Any necessary `next_cursor` will be automatically populated by\n * this function. Example: `{ block_id: \"<my block id>\" }`\n */\nexport async function collectPaginatedAPI<Args extends PaginatedArgs, Item>(\n listFn: (args: Args) => Promise<PaginatedList<Item>>,\n firstPageArgs: Args\n): Promise<Item[]> {\n const results: Item[] = []\n for await (const item of iteratePaginatedAPI(listFn, firstPageArgs)) {\n results.push(item)\n }\n return results\n}\n\n/**\n * @returns `true` if `response` is a full `BlockObjectResponse`.\n */\nexport function isFullBlock(\n response: BlockObjectResponse | PartialBlockObjectResponse\n): response is BlockObjectResponse {\n return \"type\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `PageObjectResponse`.\n */\nexport function isFullPage(\n response: PageObjectResponse | PartialPageObjectResponse\n): response is PageObjectResponse {\n return \"url\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `DatabaseObjectResponse`.\n */\nexport function isFullDatabase(\n response: DatabaseObjectResponse | PartialDatabaseObjectResponse\n): response is DatabaseObjectResponse {\n return \"title\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `UserObjectResponse`.\n */\nexport function isFullUser(\n response: UserObjectResponse | PartialUserObjectResponse\n): response is UserObjectResponse {\n return \"type\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `CommentObjectResponse`.\n */\nexport function isFullComment(\n response: CommentObjectResponse | PartialCommentObjectResponse\n): response is CommentObjectResponse {\n return \"created_by\" in response\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";;;AAwBA;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,SAAS,CAAC,CAAC,mBAAmB,CACxC,MAAoD,EACpD,aAAmB;IAEnB,IAAI,UAAU,GAA8B,aAAa,CAAC,YAAY,CAAA;IACtE,GAAG;QACD,MAAM,QAAQ,GAAwB,MAAM,MAAM,CAAC;YACjD,GAAG,aAAa;YAChB,YAAY,EAAE,UAAU;SACzB,CAAC,CAAA;QACF,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAA;QACvB,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAA;KAClC,QAAQ,UAAU,EAAC;AACtB,CAAC;AAbD,kDAaC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACI,KAAK,UAAU,mBAAmB,CACvC,MAAoD,EACpD,aAAmB;IAEnB,MAAM,OAAO,GAAW,EAAE,CAAA;IAC1B,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE;QACnE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACnB;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AATD,kDASC;AAED;;GAEG;AACH,SAAgB,WAAW,CACzB,QAA0D;IAE1D,OAAO,MAAM,IAAI,QAAQ,CAAA;AAC3B,CAAC;AAJD,kCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,QAAwD;IAExD,OAAO,KAAK,IAAI,QAAQ,CAAA;AAC1B,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,cAAc,CAC5B,QAAgE;IAEhE,OAAO,OAAO,IAAI,QAAQ,CAAA;AAC5B,CAAC;AAJD,wCAIC;AAED;;GAEG;AACH,SAAgB,UAAU,CACxB,QAAwD;IAExD,OAAO,MAAM,IAAI,QAAQ,CAAA;AAC3B,CAAC;AAJD,gCAIC;AAED;;GAEG;AACH,SAAgB,aAAa,CAC3B,QAA8D;IAE9D,OAAO,YAAY,IAAI,QAAQ,CAAA;AACjC,CAAC;AAJD,sCAIC","sourcesContent":["import {\n BlockObjectResponse,\n CommentObjectResponse,\n DatabaseObjectResponse,\n PageObjectResponse,\n PartialBlockObjectResponse,\n PartialCommentObjectResponse,\n PartialDatabaseObjectResponse,\n PartialPageObjectResponse,\n PartialUserObjectResponse,\n UserObjectResponse,\n} from \"./api-endpoints\"\n\ninterface PaginatedArgs {\n start_cursor?: string\n}\n\ninterface PaginatedList<T> {\n object: \"list\"\n results: T[]\n next_cursor: string | null\n has_more: boolean\n}\n\n/**\n * Returns an async iterator over the results of any paginated Notion API.\n *\n * Example (given a notion Client called `notion`):\n *\n * ```\n * for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {\n * block_id: parentBlockId,\n * })) {\n * // Do something with block.\n * }\n * ```\n *\n * @param listFn A bound function on the Notion client that represents a conforming paginated\n * API. Example: `notion.blocks.children.list`.\n * @param firstPageArgs Arguments that should be passed to the API on the first and subsequent\n * calls to the API. Any necessary `next_cursor` will be automatically populated by\n * this function. Example: `{ block_id: \"<my block id>\" }`\n */\nexport async function* iteratePaginatedAPI<Args extends PaginatedArgs, Item>(\n listFn: (args: Args) => Promise<PaginatedList<Item>>,\n firstPageArgs: Args\n): AsyncIterableIterator<Item> {\n let nextCursor: string | null | undefined = firstPageArgs.start_cursor\n do {\n const response: PaginatedList<Item> = await listFn({\n ...firstPageArgs,\n start_cursor: nextCursor,\n })\n yield* response.results\n nextCursor = response.next_cursor\n } while (nextCursor)\n}\n\n/**\n * Collect all of the results of paginating an API into an in-memory array.\n *\n * Example (given a notion Client called `notion`):\n *\n * ```\n * const blocks = await collectPaginatedAPI(notion.blocks.children.list, {\n * block_id: parentBlockId,\n * })\n * // Do something with blocks.\n * ```\n *\n * @param listFn A bound function on the Notion client that represents a conforming paginated\n * API. Example: `notion.blocks.children.list`.\n * @param firstPageArgs Arguments that should be passed to the API on the first and subsequent\n * calls to the API. Any necessary `next_cursor` will be automatically populated by\n * this function. Example: `{ block_id: \"<my block id>\" }`\n */\nexport async function collectPaginatedAPI<Args extends PaginatedArgs, Item>(\n listFn: (args: Args) => Promise<PaginatedList<Item>>,\n firstPageArgs: Args\n): Promise<Item[]> {\n const results: Item[] = []\n for await (const item of iteratePaginatedAPI(listFn, firstPageArgs)) {\n results.push(item)\n }\n return results\n}\n\n/**\n * @returns `true` if `response` is a full `BlockObjectResponse`.\n */\nexport function isFullBlock(\n response: BlockObjectResponse | PartialBlockObjectResponse\n): response is BlockObjectResponse {\n return \"type\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `PageObjectResponse`.\n */\nexport function isFullPage(\n response: PageObjectResponse | PartialPageObjectResponse\n): response is PageObjectResponse {\n return \"url\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `DatabaseObjectResponse`.\n */\nexport function isFullDatabase(\n response: DatabaseObjectResponse | PartialDatabaseObjectResponse\n): response is DatabaseObjectResponse {\n return \"title\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `UserObjectResponse`.\n */\nexport function isFullUser(\n response: UserObjectResponse | PartialUserObjectResponse\n): response is UserObjectResponse {\n return \"type\" in response\n}\n\n/**\n * @returns `true` if `response` is a full `CommentObjectResponse`.\n */\nexport function isFullComment(\n response: CommentObjectResponse | PartialCommentObjectResponse\n): response is CommentObjectResponse {\n return \"created_by\" in response\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../../src/type-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../../src/type-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA"}
|
package/build/src/utils.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param value The variable with no remaining values
|
|
7
7
|
*/
|
|
8
8
|
export declare function assertNever(value: never): never;
|
|
9
|
-
|
|
9
|
+
type AllKeys<T> = T extends unknown ? keyof T : never;
|
|
10
10
|
export declare function pick<O, K extends AllKeys<O>>(base: O, keys: readonly K[]): Pick<O, K>;
|
|
11
11
|
export declare function isObject(o: unknown): o is Record<PropertyKey, unknown>;
|
|
12
12
|
export {};
|
package/build/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C;AAED,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE/C;AAED,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;AAErD,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAC1C,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,SAAS,CAAC,EAAE,GACjB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAGZ;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAEtE"}
|