@jeromefitz/notion 6.1.0 → 6.2.0-canary.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.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint$colon$ts.log +1 -0
- package/README.md +12 -12
- package/{constants → dist/constants}/index.d.mts +1 -1
- package/{constants → dist/constants}/index.d.mts.map +1 -1
- package/dist/constants/index.mjs.map +1 -0
- package/dist/get-types-7QEbhRzY.mjs +2 -0
- package/dist/get-types-7QEbhRzY.mjs.map +1 -0
- package/{index-CQ1IEP2W.d.mts → dist/index-BAoq6yHe.d.mts} +7 -7
- package/{index-CQ1IEP2W.d.mts.map → dist/index-BAoq6yHe.d.mts.map} +1 -1
- package/{index.d.mts → dist/index.d.mts} +1 -1
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/{queries/getBlocksByIdChildren → dist/queries/get-blocks-by-id-children}/index.d.mts +1 -1
- package/dist/queries/get-blocks-by-id-children/index.d.mts.map +1 -0
- package/dist/queries/get-blocks-by-id-children/index.mjs.map +1 -0
- package/{queries/getDatabasesByIdQuery → dist/queries/get-databases-by-id-query}/index.d.mts +2 -2
- package/dist/queries/get-databases-by-id-query/index.d.mts.map +1 -0
- package/dist/queries/get-databases-by-id-query/index.mjs.map +1 -0
- package/{queries/getDeepFetchAllChildren → dist/queries/get-deep-fetch-all-children}/index.d.mts +1 -1
- package/dist/queries/get-deep-fetch-all-children/index.d.mts.map +1 -0
- package/dist/queries/get-deep-fetch-all-children/index.mjs.map +1 -0
- package/{queries/getInfoType → dist/queries/get-info-type}/index.d.mts +1 -3
- package/dist/queries/get-info-type/index.d.mts.map +1 -0
- package/dist/queries/get-info-type/index.mjs.map +1 -0
- package/{queries/getNotionListing → dist/queries/get-notion-listing}/index.d.mts +1 -1
- package/dist/queries/get-notion-listing/index.d.mts.map +1 -0
- package/dist/queries/get-notion-listing/index.mjs +2 -0
- package/dist/queries/get-notion-listing/index.mjs.map +1 -0
- package/{queries/getNotionListingByDate → dist/queries/get-notion-listing-by-date}/index.d.mts +1 -1
- package/dist/queries/get-notion-listing-by-date/index.d.mts.map +1 -0
- package/dist/queries/get-notion-listing-by-date/index.mjs +2 -0
- package/dist/queries/get-notion-listing-by-date/index.mjs.map +1 -0
- package/{queries/getNotionSlug → dist/queries/get-notion-slug}/index.d.mts +1 -1
- package/dist/queries/get-notion-slug/index.d.mts.map +1 -0
- package/dist/queries/get-notion-slug/index.mjs +2 -0
- package/dist/queries/get-notion-slug/index.mjs.map +1 -0
- package/{queries/getNotionSlugByRoute → dist/queries/get-notion-slug-by-route}/index.d.mts +1 -1
- package/dist/queries/get-notion-slug-by-route/index.d.mts.map +1 -0
- package/dist/queries/get-notion-slug-by-route/index.mjs +2 -0
- package/dist/queries/get-notion-slug-by-route/index.mjs.map +1 -0
- package/{queries/getPagesById → dist/queries/get-pages-by-id}/index.d.mts +1 -1
- package/dist/queries/get-pages-by-id/index.d.mts.map +1 -0
- package/dist/queries/get-pages-by-id/index.mjs.map +1 -0
- package/{queries/getPathVariables → dist/queries/get-path-variables}/index.d.mts +2 -2
- package/dist/queries/get-path-variables/index.d.mts.map +1 -0
- package/dist/queries/get-path-variables/index.mjs +2 -0
- package/dist/queries/get-path-variables/index.mjs.map +1 -0
- package/{queries/getQuery → dist/queries/get-query}/index.d.mts +1 -1
- package/dist/queries/get-query/index.d.mts.map +1 -0
- package/dist/queries/get-query/index.mjs +2 -0
- package/dist/queries/get-query/index.mjs.map +1 -0
- package/dist/queries/index.d.mts +12 -0
- package/dist/queries/index.mjs +1 -0
- package/{schema → dist/schema}/index.d.mts +1 -1
- package/{utils/addTime → dist/utils/add-time}/index.d.mts +1 -1
- package/dist/utils/add-time/index.d.mts.map +1 -0
- package/dist/utils/add-time/index.mjs.map +1 -0
- package/{utils/dataNormalized → dist/utils/data-normalized}/index.d.mts +1 -1
- package/dist/utils/data-normalized/index.d.mts.map +1 -0
- package/dist/utils/data-normalized/index.mjs +1 -0
- package/{utils/dataNormalizedResults → dist/utils/data-normalized-results}/index.d.mts +1 -1
- package/dist/utils/data-normalized-results/index.d.mts.map +1 -0
- package/dist/utils/data-normalized-results/index.mjs +1 -0
- package/{utils/getDataType → dist/utils/get-data-type}/index.d.mts +2 -2
- package/dist/utils/get-data-type/index.d.mts.map +1 -0
- package/dist/utils/get-data-type/index.mjs.map +1 -0
- package/{utils/getTitle → dist/utils/get-title}/index.d.mts +1 -1
- package/dist/utils/get-title/index.d.mts.map +1 -0
- package/dist/utils/get-title/index.mjs.map +1 -0
- package/dist/utils/get-types/_unsupported.d.mts +5 -0
- package/dist/utils/get-types/_unsupported.d.mts.map +1 -0
- package/dist/utils/get-types/_unsupported.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/checkbox.d.mts +1 -1
- package/dist/utils/get-types/checkbox.d.mts.map +1 -0
- package/dist/utils/get-types/checkbox.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/date.d.mts +1 -1
- package/dist/utils/get-types/date.d.mts.map +1 -0
- package/dist/utils/get-types/date.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/email.d.mts +1 -1
- package/dist/utils/get-types/email.d.mts.map +1 -0
- package/dist/utils/get-types/email.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/files.d.mts +1 -1
- package/dist/utils/get-types/files.d.mts.map +1 -0
- package/dist/utils/get-types/files.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/index.d.mts +1 -1
- package/{utils/getTypes → dist/utils/get-types}/index.d.mts.map +1 -1
- package/dist/utils/get-types/index.mjs +1 -0
- package/{utils/getTypes/multi_select.d.mts → dist/utils/get-types/multi-select.d.mts} +2 -2
- package/dist/utils/get-types/multi-select.d.mts.map +1 -0
- package/{utils/getTypes/multi_select.mjs → dist/utils/get-types/multi-select.mjs} +1 -1
- package/dist/utils/get-types/multi-select.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/number.d.mts +1 -1
- package/dist/utils/get-types/number.d.mts.map +1 -0
- package/dist/utils/get-types/number.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/people.d.mts +1 -1
- package/dist/utils/get-types/people.d.mts.map +1 -0
- package/dist/utils/get-types/people.mjs.map +1 -0
- package/{utils/getTypes/phone_number.d.mts → dist/utils/get-types/phone-number.d.mts} +2 -2
- package/dist/utils/get-types/phone-number.d.mts.map +1 -0
- package/{utils/getTypes/phone_number.mjs → dist/utils/get-types/phone-number.mjs} +1 -1
- package/dist/utils/get-types/phone-number.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/relation.d.mts +1 -1
- package/dist/utils/get-types/relation.d.mts.map +1 -0
- package/dist/utils/get-types/relation.mjs +1 -0
- package/{utils/getTypes/rich_text.d.mts → dist/utils/get-types/rich-text.d.mts} +2 -2
- package/dist/utils/get-types/rich-text.d.mts.map +1 -0
- package/{utils/getTypes/rich_text.mjs → dist/utils/get-types/rich-text.mjs} +1 -1
- package/dist/utils/get-types/rich-text.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/rollup.d.mts +1 -1
- package/dist/utils/get-types/rollup.d.mts.map +1 -0
- package/dist/utils/get-types/rollup.mjs +1 -0
- package/{utils/getTypes → dist/utils/get-types}/select.d.mts +1 -1
- package/dist/utils/get-types/select.d.mts.map +1 -0
- package/dist/utils/get-types/select.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/title.d.mts +1 -1
- package/dist/utils/get-types/title.d.mts.map +1 -0
- package/dist/utils/get-types/title.mjs.map +1 -0
- package/{utils/getTypes → dist/utils/get-types}/url.d.mts +1 -1
- package/{utils/getTypes → dist/utils/get-types}/url.d.mts.map +1 -1
- package/dist/utils/get-types/url.mjs.map +1 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils-SxsCJsDP.mjs +2 -0
- package/dist/utils-SxsCJsDP.mjs.map +1 -0
- package/package.json +213 -64
- package/release.config.js +25 -0
- package/src/constants/index.ts +1326 -0
- package/src/index.ts +151 -0
- package/src/queries/get-blocks-by-id-children/index.ts +12 -0
- package/src/queries/get-databases-by-id-query/index.ts +28 -0
- package/src/queries/get-deep-fetch-all-children/index.ts +35 -0
- package/src/queries/get-info-type/index.ts +40 -0
- package/src/queries/get-notion-listing/index.ts +91 -0
- package/src/queries/get-notion-listing-by-date/index.ts +190 -0
- package/src/queries/get-notion-slug/index.ts +64 -0
- package/src/queries/get-notion-slug-by-route/index.ts +201 -0
- package/src/queries/get-pages-by-id/index.ts +12 -0
- package/src/queries/get-path-variables/index.ts +60 -0
- package/src/queries/get-query/index.ts +140 -0
- package/src/queries/index.ts +25 -0
- package/src/schema/index.ts +386 -0
- package/src/utils/add-time/index.ts +16 -0
- package/src/utils/data-normalized/index.ts +49 -0
- package/src/utils/data-normalized-results/index.ts +29 -0
- package/src/utils/get-data-type/index.ts +62 -0
- package/src/utils/get-title/index.ts +21 -0
- package/src/utils/get-types/_unsupported.ts +7 -0
- package/src/utils/get-types/checkbox.ts +3 -0
- package/src/utils/get-types/date.ts +6 -0
- package/src/utils/get-types/email.ts +3 -0
- package/src/utils/get-types/files.ts +67 -0
- package/src/utils/get-types/index.ts +41 -0
- package/src/utils/get-types/multi-select.ts +16 -0
- package/src/utils/get-types/number.ts +6 -0
- package/src/utils/get-types/people.ts +22 -0
- package/src/utils/get-types/phone-number.ts +3 -0
- package/src/utils/get-types/relation.ts +18 -0
- package/src/utils/get-types/rich-text.ts +5 -0
- package/src/utils/get-types/rollup.ts +30 -0
- package/src/utils/get-types/select.ts +21 -0
- package/src/utils/get-types/title.ts +4 -0
- package/src/utils/get-types/url.ts +3 -0
- package/src/utils/index.ts +16 -0
- package/tsconfig.json +15 -0
- package/tsdown.config.ts +14 -0
- package/constants/index.mjs.map +0 -1
- package/getTypes-D-cwjcBl.mjs +0 -2
- package/getTypes-D-cwjcBl.mjs.map +0 -1
- package/index.d.mts.map +0 -1
- package/index.mjs +0 -2
- package/index.mjs.map +0 -1
- package/queries/getBlocksByIdChildren/index.d.mts.map +0 -1
- package/queries/getBlocksByIdChildren/index.mjs.map +0 -1
- package/queries/getDatabasesByIdQuery/index.d.mts.map +0 -1
- package/queries/getDatabasesByIdQuery/index.mjs.map +0 -1
- package/queries/getDeepFetchAllChildren/index.d.mts.map +0 -1
- package/queries/getDeepFetchAllChildren/index.mjs.map +0 -1
- package/queries/getInfoType/index.d.mts.map +0 -1
- package/queries/getInfoType/index.mjs.map +0 -1
- package/queries/getNotionListing/index.d.mts.map +0 -1
- package/queries/getNotionListing/index.mjs +0 -2
- package/queries/getNotionListing/index.mjs.map +0 -1
- package/queries/getNotionListingByDate/index.d.mts.map +0 -1
- package/queries/getNotionListingByDate/index.mjs +0 -2
- package/queries/getNotionListingByDate/index.mjs.map +0 -1
- package/queries/getNotionSlug/index.d.mts.map +0 -1
- package/queries/getNotionSlug/index.mjs +0 -2
- package/queries/getNotionSlug/index.mjs.map +0 -1
- package/queries/getNotionSlugByRoute/index.d.mts.map +0 -1
- package/queries/getNotionSlugByRoute/index.mjs +0 -2
- package/queries/getNotionSlugByRoute/index.mjs.map +0 -1
- package/queries/getPagesById/index.d.mts.map +0 -1
- package/queries/getPagesById/index.mjs.map +0 -1
- package/queries/getPathVariables/index.d.mts.map +0 -1
- package/queries/getPathVariables/index.mjs +0 -2
- package/queries/getPathVariables/index.mjs.map +0 -1
- package/queries/getQuery/index.d.mts.map +0 -1
- package/queries/getQuery/index.mjs +0 -2
- package/queries/getQuery/index.mjs.map +0 -1
- package/queries/index.d.mts +0 -12
- package/queries/index.mjs +0 -1
- package/utils/addTime/index.d.mts.map +0 -1
- package/utils/addTime/index.mjs.map +0 -1
- package/utils/dataNormalized/index.d.mts.map +0 -1
- package/utils/dataNormalized/index.mjs +0 -1
- package/utils/dataNormalizedResults/index.d.mts.map +0 -1
- package/utils/dataNormalizedResults/index.mjs +0 -1
- package/utils/getDataType/index.d.mts.map +0 -1
- package/utils/getDataType/index.mjs.map +0 -1
- package/utils/getTitle/index.d.mts.map +0 -1
- package/utils/getTitle/index.mjs.map +0 -1
- package/utils/getTypes/_unsupported.d.mts +0 -6
- package/utils/getTypes/_unsupported.d.mts.map +0 -1
- package/utils/getTypes/_unsupported.mjs.map +0 -1
- package/utils/getTypes/checkbox.d.mts.map +0 -1
- package/utils/getTypes/checkbox.mjs.map +0 -1
- package/utils/getTypes/date.d.mts.map +0 -1
- package/utils/getTypes/date.mjs.map +0 -1
- package/utils/getTypes/email.d.mts.map +0 -1
- package/utils/getTypes/email.mjs.map +0 -1
- package/utils/getTypes/files.d.mts.map +0 -1
- package/utils/getTypes/files.mjs.map +0 -1
- package/utils/getTypes/index.mjs +0 -1
- package/utils/getTypes/multi_select.d.mts.map +0 -1
- package/utils/getTypes/multi_select.mjs.map +0 -1
- package/utils/getTypes/number.d.mts.map +0 -1
- package/utils/getTypes/number.mjs.map +0 -1
- package/utils/getTypes/people.d.mts.map +0 -1
- package/utils/getTypes/people.mjs.map +0 -1
- package/utils/getTypes/phone_number.d.mts.map +0 -1
- package/utils/getTypes/phone_number.mjs.map +0 -1
- package/utils/getTypes/relation.d.mts.map +0 -1
- package/utils/getTypes/relation.mjs +0 -1
- package/utils/getTypes/rich_text.d.mts.map +0 -1
- package/utils/getTypes/rich_text.mjs.map +0 -1
- package/utils/getTypes/rollup.d.mts.map +0 -1
- package/utils/getTypes/rollup.mjs +0 -1
- package/utils/getTypes/select.d.mts.map +0 -1
- package/utils/getTypes/select.mjs.map +0 -1
- package/utils/getTypes/title.d.mts.map +0 -1
- package/utils/getTypes/title.mjs.map +0 -1
- package/utils/getTypes/url.mjs.map +0 -1
- package/utils/index.d.mts +0 -7
- package/utils/index.mjs +0 -1
- package/utils-VfbevQkn.mjs +0 -2
- package/utils-VfbevQkn.mjs.map +0 -1
- /package/{constants → dist/constants}/index.mjs +0 -0
- /package/{queries/getBlocksByIdChildren → dist/queries/get-blocks-by-id-children}/index.mjs +0 -0
- /package/{queries/getDatabasesByIdQuery → dist/queries/get-databases-by-id-query}/index.mjs +0 -0
- /package/{queries/getDeepFetchAllChildren → dist/queries/get-deep-fetch-all-children}/index.mjs +0 -0
- /package/{queries/getInfoType → dist/queries/get-info-type}/index.mjs +0 -0
- /package/{queries/getPagesById → dist/queries/get-pages-by-id}/index.mjs +0 -0
- /package/{schema → dist/schema}/index.mjs +0 -0
- /package/{utils/addTime → dist/utils/add-time}/index.mjs +0 -0
- /package/{utils/getDataType → dist/utils/get-data-type}/index.mjs +0 -0
- /package/{utils/getTitle → dist/utils/get-title}/index.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/_unsupported.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/checkbox.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/date.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/email.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/files.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/number.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/people.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/select.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/title.mjs +0 -0
- /package/{utils/getTypes → dist/utils/get-types}/url.mjs +0 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Client as _Client } from "@notionhq/client";
|
|
2
|
+
|
|
3
|
+
import { DATA_TYPES } from "./constants/index";
|
|
4
|
+
import {
|
|
5
|
+
getBlocksByIdChildren,
|
|
6
|
+
getDatabasesByIdQuery,
|
|
7
|
+
getDeepFetchAllChildren,
|
|
8
|
+
getInfoType,
|
|
9
|
+
getNotionListing,
|
|
10
|
+
getNotionListingByDate,
|
|
11
|
+
getNotionSlug,
|
|
12
|
+
getNotionSlugByRoute,
|
|
13
|
+
getPagesById,
|
|
14
|
+
getPathVariables,
|
|
15
|
+
getQuery,
|
|
16
|
+
} from "./queries/index";
|
|
17
|
+
|
|
18
|
+
type ClientProps = {
|
|
19
|
+
custom: CustomProps;
|
|
20
|
+
dataTypes: DataTypesProps;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type CredentialProps = {
|
|
24
|
+
auth: string;
|
|
25
|
+
config: any;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type CustomProps = {
|
|
29
|
+
getBlocksByIdChildren: any;
|
|
30
|
+
getDatabasesByIdQuery: any;
|
|
31
|
+
getDeepFetchAllChildren: any;
|
|
32
|
+
getInfoType: any;
|
|
33
|
+
getPagesById: any;
|
|
34
|
+
getPathVariables: any;
|
|
35
|
+
getQuery: any;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type DataTypesProps = {
|
|
39
|
+
LISTING: any;
|
|
40
|
+
LISTING_BY_DATE: any;
|
|
41
|
+
SLUG: any;
|
|
42
|
+
SLUG_BY_ROUTE: any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
class Client extends _Client {
|
|
46
|
+
#config?: any;
|
|
47
|
+
|
|
48
|
+
// @todo(notion) throw error if `config` is not passed
|
|
49
|
+
public readonly custom = {
|
|
50
|
+
getBlocksByIdChildren: async (props) =>
|
|
51
|
+
await getBlocksByIdChildren({
|
|
52
|
+
...props,
|
|
53
|
+
getBlocksChildrenList: this.blocks.children.list,
|
|
54
|
+
}),
|
|
55
|
+
|
|
56
|
+
getDatabasesByIdQuery: async (props) =>
|
|
57
|
+
await getDatabasesByIdQuery({
|
|
58
|
+
...props,
|
|
59
|
+
getDatabasesQuery: this.databases.query,
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
getDeepFetchAllChildren: async (props) =>
|
|
63
|
+
await getDeepFetchAllChildren({
|
|
64
|
+
...props,
|
|
65
|
+
getBlocksChildrenList: this.blocks.children.list,
|
|
66
|
+
}),
|
|
67
|
+
|
|
68
|
+
getInfoType: (props) => {
|
|
69
|
+
return getInfoType({ ...props, config: this.#config });
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
getPagesById: async (props) =>
|
|
73
|
+
await getPagesById({ ...props, getPagesRetrieve: this.pages.retrieve }),
|
|
74
|
+
|
|
75
|
+
getPathVariables: (props) => getPathVariables({ ...props, config: this.#config }),
|
|
76
|
+
|
|
77
|
+
getQuery: async (props) =>
|
|
78
|
+
await getQuery({
|
|
79
|
+
...props,
|
|
80
|
+
config: this.#config,
|
|
81
|
+
notionDatabasesQuery: this.databases.query,
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @info details at: ../../utils/getDataType
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
public readonly dataTypes = {
|
|
90
|
+
[DATA_TYPES.LISTING]: async (props: { pathVariables: any; routeType: any; slug?: any }) => {
|
|
91
|
+
// console.dir(`📦️ [@jeromefitz/notion] => ${DATA_TYPES.LISTING}`)
|
|
92
|
+
return await getNotionListing({
|
|
93
|
+
...props,
|
|
94
|
+
config: this.#config,
|
|
95
|
+
getBlocksByIdChildren: this.custom.getBlocksByIdChildren,
|
|
96
|
+
getDatabasesByIdQuery: this.custom.getDatabasesByIdQuery,
|
|
97
|
+
getPagesById: this.custom.getPagesById,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
[DATA_TYPES.LISTING_BY_DATE]: async (props: {
|
|
102
|
+
pathVariables: any;
|
|
103
|
+
routeType: any;
|
|
104
|
+
slug: any;
|
|
105
|
+
}) => {
|
|
106
|
+
// console.dir(`📦️ [@jeromefitz/notion] => ${DATA_TYPES.LISTING_BY_DATE}`)
|
|
107
|
+
return await getNotionListingByDate({
|
|
108
|
+
...props,
|
|
109
|
+
config: this.#config,
|
|
110
|
+
getBlocksByIdChildren: this.custom.getBlocksByIdChildren,
|
|
111
|
+
getDatabasesByIdQuery: this.custom.getDatabasesByIdQuery,
|
|
112
|
+
getPagesById: this.custom.getPagesById,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
[DATA_TYPES.SLUG]: async (props: { pathVariables: any; routeType: any; slug: any }) => {
|
|
117
|
+
// console.dir(`📦️ [@jeromefitz/notion] => ${DATA_TYPES.SLUG}`)
|
|
118
|
+
return await getNotionSlug({
|
|
119
|
+
...props,
|
|
120
|
+
config: this.#config,
|
|
121
|
+
getBlocksByIdChildren: this.custom.getBlocksByIdChildren,
|
|
122
|
+
getDatabasesByIdQuery: this.custom.getDatabasesByIdQuery,
|
|
123
|
+
getDeepFetchAllChildren: this.custom.getDeepFetchAllChildren,
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
[DATA_TYPES.SLUG_BY_ROUTE]: async (props: {
|
|
128
|
+
pathVariables: any;
|
|
129
|
+
routeType: any;
|
|
130
|
+
slug: any;
|
|
131
|
+
}) => {
|
|
132
|
+
// console.dir(`📦️ [@jeromefitz/notion] => ${DATA_TYPES.SLUG_BY_ROUTE}`)
|
|
133
|
+
return await getNotionSlugByRoute({
|
|
134
|
+
...props,
|
|
135
|
+
config: this.#config,
|
|
136
|
+
getBlocksByIdChildren: this.custom.getBlocksByIdChildren,
|
|
137
|
+
getDatabasesByIdQuery: this.custom.getDatabasesByIdQuery,
|
|
138
|
+
getQuery: this.custom.getQuery,
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// public constructor(options?: ClientOptions) {
|
|
144
|
+
public constructor(options?: any) {
|
|
145
|
+
super(options);
|
|
146
|
+
this.#config = options?.config;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type { ClientProps, CredentialProps };
|
|
151
|
+
export { Client };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { avoidRateLimit, isUndefined } from "@jeromefitz/utils";
|
|
2
|
+
|
|
3
|
+
// @todo(types)
|
|
4
|
+
const getBlocksByIdChildren = async ({ block_id, getBlocksChildrenList }) => {
|
|
5
|
+
if (isUndefined(block_id)) return [];
|
|
6
|
+
await avoidRateLimit(0);
|
|
7
|
+
return await getBlocksChildrenList({
|
|
8
|
+
block_id,
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default getBlocksByIdChildren;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PROPERTIES } from "../../constants/index";
|
|
2
|
+
import type { SortMock } from "../../schema/index";
|
|
3
|
+
|
|
4
|
+
const sortDefault: SortMock = {
|
|
5
|
+
sorts: [
|
|
6
|
+
{
|
|
7
|
+
direction: "ascending",
|
|
8
|
+
property: PROPERTIES.slug.notion,
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// @todo(types)
|
|
14
|
+
const getDatabasesByIdQuery = async ({
|
|
15
|
+
database_id,
|
|
16
|
+
filter = sortDefault?.filter,
|
|
17
|
+
getDatabasesQuery,
|
|
18
|
+
sorts = sortDefault?.sorts,
|
|
19
|
+
}) => {
|
|
20
|
+
if (!database_id) return [];
|
|
21
|
+
return await getDatabasesQuery({
|
|
22
|
+
database_id,
|
|
23
|
+
filter,
|
|
24
|
+
sorts,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default getDatabasesByIdQuery;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const getDeepFetchAllChildren = async ({
|
|
2
|
+
blocks,
|
|
3
|
+
getBlocksChildrenList,
|
|
4
|
+
}): Promise<Array<any | any[]>> => {
|
|
5
|
+
if (blocks === null || blocks === undefined) return blocks;
|
|
6
|
+
const fetchChildrenMap = blocks
|
|
7
|
+
.filter((block: { has_children: any }) => block.has_children)
|
|
8
|
+
.map((parent_block: { id: string }) => {
|
|
9
|
+
const { id: block_id } = parent_block;
|
|
10
|
+
return {
|
|
11
|
+
parent_block,
|
|
12
|
+
promise: getBlocksChildrenList({
|
|
13
|
+
block_id,
|
|
14
|
+
page_size: 100,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const results = await Promise.all<any>(fetchChildrenMap.map((value) => value.promise));
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < results.length; i++) {
|
|
22
|
+
const blocks = results[i].results;
|
|
23
|
+
await getDeepFetchAllChildren({
|
|
24
|
+
blocks,
|
|
25
|
+
getBlocksChildrenList,
|
|
26
|
+
});
|
|
27
|
+
if (fetchChildrenMap[i]) {
|
|
28
|
+
const parent: any = fetchChildrenMap[i].parent_block;
|
|
29
|
+
parent[parent.type].children = blocks;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return blocks;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default getDeepFetchAllChildren;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const getInfoType = ({ config, item, meta, routeType }) => {
|
|
2
|
+
const { NOTION } = config;
|
|
3
|
+
|
|
4
|
+
let date = "";
|
|
5
|
+
const slug = item.properties?.slug;
|
|
6
|
+
|
|
7
|
+
let as = "";
|
|
8
|
+
const href = `/[...catchAll]`;
|
|
9
|
+
|
|
10
|
+
switch (routeType) {
|
|
11
|
+
case NOTION.BLOG.routeType:
|
|
12
|
+
case NOTION.EVENTS.routeType:
|
|
13
|
+
date = item.properties[NOTION[routeType.toUpperCase()].infoType.key]?.start.slice(0, 10);
|
|
14
|
+
// oxlint-disable-next-line no-unsafe-optional-chaining
|
|
15
|
+
const [year, month, day] = date?.split("-");
|
|
16
|
+
as = `/${routeType}/${year}/${month}/${day}/${slug}`;
|
|
17
|
+
break;
|
|
18
|
+
case NOTION.EPISODES.routeType:
|
|
19
|
+
as = `/${meta?.join("/")}/${slug}`;
|
|
20
|
+
break;
|
|
21
|
+
// case NOTION.PODCASTS.routeType:
|
|
22
|
+
// case NOTION.PEOPLE.routeType:
|
|
23
|
+
// case NOTION.SHOWS.routeType:
|
|
24
|
+
// case NOTION.VENUES.routeType:
|
|
25
|
+
default:
|
|
26
|
+
as = `/${routeType}/${slug}`;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
as = as.replace("//", "/");
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
as,
|
|
34
|
+
date,
|
|
35
|
+
href,
|
|
36
|
+
slug,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default getInfoType;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { sortObject } from "@jeromefitz/utils";
|
|
2
|
+
import { map as _map, omit as _omit } from "lodash-es";
|
|
3
|
+
|
|
4
|
+
import { PROPERTIES } from "../../constants/index";
|
|
5
|
+
import { dataNormalized } from "../../utils/index";
|
|
6
|
+
|
|
7
|
+
const getNotionListing = async ({
|
|
8
|
+
config,
|
|
9
|
+
getBlocksByIdChildren,
|
|
10
|
+
getDatabasesByIdQuery,
|
|
11
|
+
getPagesById,
|
|
12
|
+
pathVariables,
|
|
13
|
+
routeType,
|
|
14
|
+
}) => {
|
|
15
|
+
const { NOTION } = config;
|
|
16
|
+
|
|
17
|
+
let info: any = {};
|
|
18
|
+
|
|
19
|
+
const page_id = NOTION[routeType.toUpperCase()].page_id__seo;
|
|
20
|
+
const _info = await getPagesById({
|
|
21
|
+
page_id,
|
|
22
|
+
});
|
|
23
|
+
// @refactor(404)
|
|
24
|
+
if (!_info) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
if (_info?.object === "page") {
|
|
28
|
+
info = _omit(_info, "properties");
|
|
29
|
+
info.properties = sortObject(
|
|
30
|
+
dataNormalized({ config, data: _info, pageId: info.id, pathVariables }),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const property =
|
|
35
|
+
NOTION[routeType.toUpperCase()].infoType.notion ?? PROPERTIES.datePublished.notion;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @todo Can we make the date dynamic?
|
|
39
|
+
* This can be considered the date you want to go back in time to on build.
|
|
40
|
+
* Can be construed as the website creation date, too I guess.
|
|
41
|
+
*
|
|
42
|
+
* For those routeTypes that do not go off of datePublished,
|
|
43
|
+
* we want to get their listing by the current date.
|
|
44
|
+
*
|
|
45
|
+
* ex) /events => Only want events that are in the future.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
const timestamp =
|
|
49
|
+
property === PROPERTIES.datePublished.notion
|
|
50
|
+
? new Date("2020-01-01").toISOString()
|
|
51
|
+
: new Date().toISOString();
|
|
52
|
+
|
|
53
|
+
const content = await getBlocksByIdChildren({ block_id: info.id });
|
|
54
|
+
const _items: any = await getDatabasesByIdQuery({
|
|
55
|
+
database_id: NOTION[routeType.toUpperCase()].database_id,
|
|
56
|
+
filter: {
|
|
57
|
+
and: [
|
|
58
|
+
{
|
|
59
|
+
date: {
|
|
60
|
+
on_or_after: timestamp,
|
|
61
|
+
},
|
|
62
|
+
property,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const results: any[] = [];
|
|
68
|
+
_map(_items.results, (item) => {
|
|
69
|
+
let itemInit = item;
|
|
70
|
+
itemInit = _omit(itemInit, "properties");
|
|
71
|
+
itemInit.properties = sortObject(
|
|
72
|
+
dataNormalized({ config, data: item, pageId: item.id, pathVariables }),
|
|
73
|
+
);
|
|
74
|
+
results.push(itemInit);
|
|
75
|
+
// console.dir(`> last_edited_time`)
|
|
76
|
+
// console.dir(item.id)
|
|
77
|
+
// console.dir(item.last_edited_time)
|
|
78
|
+
// console.dir(`---`)
|
|
79
|
+
});
|
|
80
|
+
const items = _omit(_items, "results");
|
|
81
|
+
items.results = results;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @note(plaiceholder)
|
|
85
|
+
*
|
|
86
|
+
* Pass empty `images` object for SSR/API takeover
|
|
87
|
+
*/
|
|
88
|
+
return { content, images: {}, info, items };
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default getNotionListing;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { sortObject } from "@jeromefitz/utils";
|
|
2
|
+
import { map as _map, omit as _omit, size as _size } from "lodash-es";
|
|
3
|
+
|
|
4
|
+
import { PROPERTIES, QUERIES } from "../../constants/index";
|
|
5
|
+
import type { SortItem } from "../../schema/index";
|
|
6
|
+
import { addTime, dataNormalized } from "../../utils/index";
|
|
7
|
+
|
|
8
|
+
const getNotionListingByDate__getFilter = ({ config, pathVariables, routeType, slug }) => {
|
|
9
|
+
const { NOTION } = config;
|
|
10
|
+
const { meta } = pathVariables;
|
|
11
|
+
const [year, month, day] = meta;
|
|
12
|
+
const metaCount = _size(meta);
|
|
13
|
+
// @hack nothing to see here, haha
|
|
14
|
+
const dateTimestamp = new Date().toISOString();
|
|
15
|
+
const timestampQuery = new Date(
|
|
16
|
+
`${year ? year : dateTimestamp.slice(0, 4)}-${month ? month : "01"}-${day ? day : "01"}`,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @filter
|
|
21
|
+
* @note metaCount breakdown:
|
|
22
|
+
* 1 = yyyy
|
|
23
|
+
* 2 = yyyy/mm
|
|
24
|
+
* 3 = yyyy/mm/dd
|
|
25
|
+
* ? = yyyy/mm/dd/slug (SLUG_BY_ROUTE takes this over)
|
|
26
|
+
*/
|
|
27
|
+
const property =
|
|
28
|
+
NOTION[routeType.toUpperCase()]?.infoType?.notion ?? PROPERTIES.datePublished.notion;
|
|
29
|
+
|
|
30
|
+
switch (metaCount) {
|
|
31
|
+
/**
|
|
32
|
+
* @note yyyy
|
|
33
|
+
*/
|
|
34
|
+
case 1:
|
|
35
|
+
return {
|
|
36
|
+
and: [
|
|
37
|
+
{
|
|
38
|
+
date: {
|
|
39
|
+
on_or_after: addTime(timestampQuery, ""),
|
|
40
|
+
},
|
|
41
|
+
property,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
date: {
|
|
45
|
+
before: addTime(timestampQuery, "year"),
|
|
46
|
+
},
|
|
47
|
+
property,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @note yyyy/mm
|
|
54
|
+
*/
|
|
55
|
+
case 2:
|
|
56
|
+
return {
|
|
57
|
+
and: [
|
|
58
|
+
{
|
|
59
|
+
date: {
|
|
60
|
+
on_or_after: addTime(timestampQuery, ""),
|
|
61
|
+
},
|
|
62
|
+
property,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
date: {
|
|
66
|
+
before: addTime(timestampQuery, "month"),
|
|
67
|
+
},
|
|
68
|
+
property,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @note yyyy/mm/dd
|
|
75
|
+
*/
|
|
76
|
+
case 3:
|
|
77
|
+
return {
|
|
78
|
+
and: [
|
|
79
|
+
{
|
|
80
|
+
date: {
|
|
81
|
+
on_or_after: addTime(timestampQuery, ""),
|
|
82
|
+
},
|
|
83
|
+
property,
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
date: {
|
|
87
|
+
before: addTime(timestampQuery, "day"),
|
|
88
|
+
},
|
|
89
|
+
property,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @note yyyy/mm/dd/slug
|
|
96
|
+
*
|
|
97
|
+
* Technically this is picked up by `getNotionSlugByRoute` SLUG_BY_ROUTE
|
|
98
|
+
*/
|
|
99
|
+
default:
|
|
100
|
+
return {
|
|
101
|
+
and: [
|
|
102
|
+
{
|
|
103
|
+
date: {
|
|
104
|
+
on_or_after: addTime(timestampQuery, ""),
|
|
105
|
+
},
|
|
106
|
+
property,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
date: {
|
|
110
|
+
before: addTime(timestampQuery, "day"),
|
|
111
|
+
},
|
|
112
|
+
property,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
...QUERIES.slug,
|
|
116
|
+
rich_text: { equals: slug },
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const getNotionListingByDate = async ({
|
|
124
|
+
config,
|
|
125
|
+
getBlocksByIdChildren,
|
|
126
|
+
getDatabasesByIdQuery,
|
|
127
|
+
getPagesById,
|
|
128
|
+
pathVariables,
|
|
129
|
+
routeType,
|
|
130
|
+
slug,
|
|
131
|
+
}) => {
|
|
132
|
+
const { NOTION } = config;
|
|
133
|
+
|
|
134
|
+
let content: any = {},
|
|
135
|
+
info: any = {};
|
|
136
|
+
|
|
137
|
+
const page_id = NOTION[routeType.toUpperCase()].page_id__seo;
|
|
138
|
+
const _info = await getPagesById({
|
|
139
|
+
page_id,
|
|
140
|
+
});
|
|
141
|
+
if (_info.object === "page") {
|
|
142
|
+
info = _omit(_info, "properties");
|
|
143
|
+
info.properties = sortObject(
|
|
144
|
+
dataNormalized({ config, data: _info, pageId: _info.id, pathVariables }),
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
content = await getBlocksByIdChildren({ block_id: info.id });
|
|
149
|
+
|
|
150
|
+
const sorts: SortItem[] = [
|
|
151
|
+
{
|
|
152
|
+
direction: "descending",
|
|
153
|
+
property: PROPERTIES.datePublished.notion,
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
const filter = getNotionListingByDate__getFilter({
|
|
157
|
+
config,
|
|
158
|
+
pathVariables,
|
|
159
|
+
routeType,
|
|
160
|
+
slug,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const database_id = NOTION[routeType.toUpperCase()].database_id;
|
|
164
|
+
|
|
165
|
+
const ___items: any = await getDatabasesByIdQuery({
|
|
166
|
+
database_id,
|
|
167
|
+
filter,
|
|
168
|
+
sorts,
|
|
169
|
+
});
|
|
170
|
+
const __items: any[] = [];
|
|
171
|
+
_map(___items.results, (i) => {
|
|
172
|
+
const item = _omit(i, "properties");
|
|
173
|
+
item.properties = sortObject(
|
|
174
|
+
dataNormalized({ config, data: i, pageId: item.id, pathVariables }),
|
|
175
|
+
);
|
|
176
|
+
!!item && __items.push(item);
|
|
177
|
+
});
|
|
178
|
+
const _items = _omit(___items, "results");
|
|
179
|
+
_items.results = __items;
|
|
180
|
+
const items = _omit(_items, "data");
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @note(plaiceholder)
|
|
184
|
+
*
|
|
185
|
+
* Pass empty `images` object for SSR/API takeover
|
|
186
|
+
*/
|
|
187
|
+
return { content, images: {}, info, items };
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export default getNotionListingByDate;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { sortObject } from "@jeromefitz/utils";
|
|
2
|
+
import { omit as _omit } from "lodash-es";
|
|
3
|
+
|
|
4
|
+
import { QUERIES } from "../../constants/index";
|
|
5
|
+
import { dataNormalized } from "../../utils/index";
|
|
6
|
+
|
|
7
|
+
const getNotionSlug = async ({
|
|
8
|
+
config,
|
|
9
|
+
getBlocksByIdChildren,
|
|
10
|
+
getDatabasesByIdQuery,
|
|
11
|
+
getDeepFetchAllChildren,
|
|
12
|
+
pathVariables,
|
|
13
|
+
routeType,
|
|
14
|
+
slug,
|
|
15
|
+
}) => {
|
|
16
|
+
const { NOTION } = config;
|
|
17
|
+
|
|
18
|
+
const DB_TYPE = routeType?.toUpperCase();
|
|
19
|
+
const isValid = Object.keys(NOTION).includes(DB_TYPE);
|
|
20
|
+
|
|
21
|
+
if (!isValid) return { content: {}, images: {}, info: {}, items: {} };
|
|
22
|
+
|
|
23
|
+
const __info: any = await getDatabasesByIdQuery({
|
|
24
|
+
database_id: NOTION[DB_TYPE].database_id,
|
|
25
|
+
filter: {
|
|
26
|
+
and: [
|
|
27
|
+
{
|
|
28
|
+
...QUERIES.slug,
|
|
29
|
+
rich_text: { equals: slug },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const _info = __info?.object === "list" && __info.results[0];
|
|
36
|
+
// @refactor(404)
|
|
37
|
+
if (!_info) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const info = _omit(_info, "properties");
|
|
42
|
+
info.properties = sortObject(
|
|
43
|
+
dataNormalized({ config, data: _info, pageId: info.id, pathVariables }),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const _content = await getBlocksByIdChildren({ block_id: info.id });
|
|
47
|
+
const blocks = [...(await getDeepFetchAllChildren({ blocks: _content.results }))];
|
|
48
|
+
const content = blocks;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @question if this is reached, there are no `items`
|
|
52
|
+
*/
|
|
53
|
+
// const items: any = {}
|
|
54
|
+
// items.results = _filter(items?.results, { properties: { isPublished: true } })
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @note(plaiceholder)
|
|
58
|
+
*
|
|
59
|
+
* Pass empty `images` object for SSR/API takeover
|
|
60
|
+
*/
|
|
61
|
+
return { content, images: {}, info, items: {} };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default getNotionSlug;
|