notion-markup-utils
Advanced tools
Comparing version 1.4.3 to 1.4.4
# CHANGELOG | ||
## [v1.4.4] | ||
- Add type generics to NotionClient's `pages.update` and `pages.update` | ||
## [v1.4.3] | ||
@@ -4,0 +8,0 @@ |
@@ -147,3 +147,6 @@ import { type Color } from '../other'; | ||
} | ||
/** | ||
* @note RichText must be within **2000** characters in length. Additionally, emojis are counted as two characters. | ||
*/ | ||
export declare const r: (text: string) => RichTextRequestBuilder; | ||
//# sourceMappingURL=RichText.d.ts.map |
@@ -175,3 +175,6 @@ "use strict"; | ||
exports.RichTextRequestBuilder = RichTextRequestBuilder; | ||
/** | ||
* @note RichText must be within **2000** characters in length. Additionally, emojis are counted as two characters. | ||
*/ | ||
const r = (text) => new RichTextRequestBuilder(text); | ||
exports.r = r; |
@@ -11,3 +11,3 @@ "use strict"; | ||
databases; | ||
constructor({ NOTION_API_KEY = process.env.NOTION_API_KEY, stdTTL = 3600 } = {}) { | ||
constructor({ NOTION_API_KEY = process.env.NOTION_API_KEY, stdTTL = 0 } = {}) { | ||
this.blocks = new BlockClient_1.BlockClient({ NOTION_API_KEY, stdTTL }); | ||
@@ -14,0 +14,0 @@ this.pages = new PageClient_1.PageClient({ NOTION_API_KEY, stdTTL }); |
@@ -1,2 +0,3 @@ | ||
import { type PageResponse, Page, type PageCreateRequest, type PageUpdateRequest } from '../page/Page'; | ||
import { Page, type PageCreateRequest, type PageUpdateRequest } from '../page/Page'; | ||
import { type PageProperty } from '../page/PageProperty'; | ||
import { ClientBase, type NotionClientArgs } from './ClientBase'; | ||
@@ -31,2 +32,13 @@ import 'dotenv/config'; | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.create<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* parent: { database_id: 'XXXXXXXXXX' }, | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* Adding children blocks to the page: | ||
@@ -97,3 +109,3 @@ * ```ts | ||
*/ | ||
create(params: PageCreateRequest): Promise<PageResponse>; | ||
create<T extends Record<string, PageProperty> = Record<string, PageProperty>>(params: PageCreateRequest): Promise<Page<T>>; | ||
/** | ||
@@ -115,2 +127,13 @@ * Please note that this method does not allow editing of blocks within the page. | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.update<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* page_id: '669ffc58-9c20-4264-956b-f7f917c58400', | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* --- | ||
@@ -157,4 +180,4 @@ * | ||
*/ | ||
update(params: PageUpdateRequest): Promise<PageResponse>; | ||
update<T extends Record<string, PageProperty> = Record<string, PageProperty>>(params: PageUpdateRequest): Promise<Page>; | ||
} | ||
//# sourceMappingURL=PageClient.d.ts.map |
@@ -43,2 +43,13 @@ "use strict"; | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.create<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* parent: { database_id: 'XXXXXXXXXX' }, | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* Adding children blocks to the page: | ||
@@ -151,3 +162,3 @@ * ```ts | ||
} | ||
return res.data; | ||
return new Page_1.Page(res.data); | ||
} | ||
@@ -160,3 +171,3 @@ else { | ||
}); | ||
return res.data; | ||
return new Page_1.Page(res.data); | ||
} | ||
@@ -180,2 +191,13 @@ } | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.update<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* page_id: '669ffc58-9c20-4264-956b-f7f917c58400', | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* --- | ||
@@ -247,5 +269,5 @@ * | ||
const res = await this.client.patch(url, request); | ||
return res.data; | ||
return new Page_1.Page(res.data); | ||
} | ||
} | ||
exports.PageClient = PageClient; |
@@ -13,2 +13,6 @@ import { type RichTextResponse, RichText, type RichTextRequestBuilder } from '../block'; | ||
readonly type = "rich_text"; | ||
/** | ||
* RichText must be within **2000** characters in length. | ||
* Additionally, emojis are counted as two characters. | ||
*/ | ||
readonly rich_text: RichText[]; | ||
@@ -15,0 +19,0 @@ constructor(richTextPagePropertyResponse: RichTextPagePropertyResponse); |
@@ -9,2 +9,6 @@ "use strict"; | ||
type = 'rich_text'; | ||
/** | ||
* RichText must be within **2000** characters in length. | ||
* Additionally, emojis are counted as two characters. | ||
*/ | ||
rich_text; | ||
@@ -11,0 +15,0 @@ constructor(richTextPagePropertyResponse) { |
@@ -29,3 +29,5 @@ import { type DeepPartial } from '../utils'; | ||
* | ||
* | ||
* ### Usage | ||
* | ||
* ```ts | ||
@@ -39,4 +41,7 @@ * await notion.pages.create({ | ||
* }) | ||
* ``` | ||
* | ||
* @note The length of the URL must be less than 2000 characters. | ||
*/ | ||
export declare const url: (url: string) => DeepPartial<URLPagePropertyResponse>; | ||
//# sourceMappingURL=URLPageProperty.d.ts.map |
@@ -32,3 +32,5 @@ "use strict"; | ||
* | ||
* | ||
* ### Usage | ||
* | ||
* ```ts | ||
@@ -42,2 +44,5 @@ * await notion.pages.create({ | ||
* }) | ||
* ``` | ||
* | ||
* @note The length of the URL must be less than 2000 characters. | ||
*/ | ||
@@ -44,0 +49,0 @@ const url = (url) => { |
@@ -6,3 +6,3 @@ { | ||
"name": "notion-markup-utils", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "", | ||
@@ -9,0 +9,0 @@ "main": "dist/index.js", |
@@ -329,3 +329,6 @@ import { type Color } from '../other' | ||
/** | ||
* @note RichText must be within **2000** characters in length. Additionally, emojis are counted as two characters. | ||
*/ | ||
export const r = (text: string): RichTextRequestBuilder => | ||
new RichTextRequestBuilder(text) |
@@ -13,3 +13,3 @@ import { BlockClient } from './BlockClient' | ||
NOTION_API_KEY = process.env.NOTION_API_KEY, | ||
stdTTL = 3600 | ||
stdTTL = 0 | ||
}: NotionClientArgs = {}) { | ||
@@ -16,0 +16,0 @@ this.blocks = new BlockClient({ NOTION_API_KEY, stdTTL }) |
@@ -8,2 +8,3 @@ import { | ||
} from '../page/Page' | ||
import { type PageProperty } from '../page/PageProperty' | ||
import { ClientBase, type NotionClientArgs } from './ClientBase' | ||
@@ -59,2 +60,13 @@ import 'dotenv/config' | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.create<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* parent: { database_id: 'XXXXXXXXXX' }, | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* Adding children blocks to the page: | ||
@@ -125,3 +137,5 @@ * ```ts | ||
*/ | ||
async create(params: PageCreateRequest): Promise<PageResponse> { | ||
async create< | ||
T extends Record<string, PageProperty> = Record<string, PageProperty> | ||
>(params: PageCreateRequest): Promise<Page<T>> { | ||
const url = `/v1/pages` | ||
@@ -176,3 +190,3 @@ | ||
return res.data | ||
return new Page<T>(res.data) | ||
} else { | ||
@@ -184,3 +198,3 @@ const res = await this.client.post<PageResponse>(url, { | ||
}) | ||
return res.data | ||
return new Page<T>(res.data) | ||
} | ||
@@ -205,2 +219,13 @@ } | ||
* | ||
* ### with type generics | ||
* ```ts | ||
* const result = await notion.pages.update<{ | ||
* Name: TitlePageProperty | ||
* Description: RichTextPageProperty | ||
* }>({ | ||
* page_id: '669ffc58-9c20-4264-956b-f7f917c58400', | ||
* properties: { Name: p.title('My title'), Description: p.richText('') } | ||
* }) | ||
* ``` | ||
* | ||
* --- | ||
@@ -247,3 +272,5 @@ * | ||
*/ | ||
async update(params: PageUpdateRequest): Promise<PageResponse> { | ||
async update< | ||
T extends Record<string, PageProperty> = Record<string, PageProperty> | ||
>(params: PageUpdateRequest): Promise<Page> { | ||
const url = `/v1/pages/${params.page_id}` | ||
@@ -279,4 +306,4 @@ | ||
return res.data | ||
return new Page<T>(res.data) | ||
} | ||
} |
@@ -23,2 +23,6 @@ // @see https://developers.notion.com/reference/page-property-values#rich-text | ||
/** | ||
* RichText must be within **2000** characters in length. | ||
* Additionally, emojis are counted as two characters. | ||
*/ | ||
public readonly rich_text: RichText[] | ||
@@ -25,0 +29,0 @@ |
@@ -51,3 +51,5 @@ // @see https://developers.notion.com/reference/page-property-values#url | ||
* | ||
* | ||
* ### Usage | ||
* | ||
* ```ts | ||
@@ -61,2 +63,5 @@ * await notion.pages.create({ | ||
* }) | ||
* ``` | ||
* | ||
* @note The length of the URL must be less than 2000 characters. | ||
*/ | ||
@@ -63,0 +68,0 @@ export const url = (url: string): DeepPartial<URLPagePropertyResponse> => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
638653
16807