@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.
Files changed (268) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/.turbo/turbo-lint$colon$ts.log +1 -0
  3. package/README.md +12 -12
  4. package/{constants → dist/constants}/index.d.mts +1 -1
  5. package/{constants → dist/constants}/index.d.mts.map +1 -1
  6. package/dist/constants/index.mjs.map +1 -0
  7. package/dist/get-types-7QEbhRzY.mjs +2 -0
  8. package/dist/get-types-7QEbhRzY.mjs.map +1 -0
  9. package/{index-CQ1IEP2W.d.mts → dist/index-BAoq6yHe.d.mts} +7 -7
  10. package/{index-CQ1IEP2W.d.mts.map → dist/index-BAoq6yHe.d.mts.map} +1 -1
  11. package/{index.d.mts → dist/index.d.mts} +1 -1
  12. package/dist/index.d.mts.map +1 -0
  13. package/dist/index.mjs +2 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/{queries/getBlocksByIdChildren → dist/queries/get-blocks-by-id-children}/index.d.mts +1 -1
  16. package/dist/queries/get-blocks-by-id-children/index.d.mts.map +1 -0
  17. package/dist/queries/get-blocks-by-id-children/index.mjs.map +1 -0
  18. package/{queries/getDatabasesByIdQuery → dist/queries/get-databases-by-id-query}/index.d.mts +2 -2
  19. package/dist/queries/get-databases-by-id-query/index.d.mts.map +1 -0
  20. package/dist/queries/get-databases-by-id-query/index.mjs.map +1 -0
  21. package/{queries/getDeepFetchAllChildren → dist/queries/get-deep-fetch-all-children}/index.d.mts +1 -1
  22. package/dist/queries/get-deep-fetch-all-children/index.d.mts.map +1 -0
  23. package/dist/queries/get-deep-fetch-all-children/index.mjs.map +1 -0
  24. package/{queries/getInfoType → dist/queries/get-info-type}/index.d.mts +1 -3
  25. package/dist/queries/get-info-type/index.d.mts.map +1 -0
  26. package/dist/queries/get-info-type/index.mjs.map +1 -0
  27. package/{queries/getNotionListing → dist/queries/get-notion-listing}/index.d.mts +1 -1
  28. package/dist/queries/get-notion-listing/index.d.mts.map +1 -0
  29. package/dist/queries/get-notion-listing/index.mjs +2 -0
  30. package/dist/queries/get-notion-listing/index.mjs.map +1 -0
  31. package/{queries/getNotionListingByDate → dist/queries/get-notion-listing-by-date}/index.d.mts +1 -1
  32. package/dist/queries/get-notion-listing-by-date/index.d.mts.map +1 -0
  33. package/dist/queries/get-notion-listing-by-date/index.mjs +2 -0
  34. package/dist/queries/get-notion-listing-by-date/index.mjs.map +1 -0
  35. package/{queries/getNotionSlug → dist/queries/get-notion-slug}/index.d.mts +1 -1
  36. package/dist/queries/get-notion-slug/index.d.mts.map +1 -0
  37. package/dist/queries/get-notion-slug/index.mjs +2 -0
  38. package/dist/queries/get-notion-slug/index.mjs.map +1 -0
  39. package/{queries/getNotionSlugByRoute → dist/queries/get-notion-slug-by-route}/index.d.mts +1 -1
  40. package/dist/queries/get-notion-slug-by-route/index.d.mts.map +1 -0
  41. package/dist/queries/get-notion-slug-by-route/index.mjs +2 -0
  42. package/dist/queries/get-notion-slug-by-route/index.mjs.map +1 -0
  43. package/{queries/getPagesById → dist/queries/get-pages-by-id}/index.d.mts +1 -1
  44. package/dist/queries/get-pages-by-id/index.d.mts.map +1 -0
  45. package/dist/queries/get-pages-by-id/index.mjs.map +1 -0
  46. package/{queries/getPathVariables → dist/queries/get-path-variables}/index.d.mts +2 -2
  47. package/dist/queries/get-path-variables/index.d.mts.map +1 -0
  48. package/dist/queries/get-path-variables/index.mjs +2 -0
  49. package/dist/queries/get-path-variables/index.mjs.map +1 -0
  50. package/{queries/getQuery → dist/queries/get-query}/index.d.mts +1 -1
  51. package/dist/queries/get-query/index.d.mts.map +1 -0
  52. package/dist/queries/get-query/index.mjs +2 -0
  53. package/dist/queries/get-query/index.mjs.map +1 -0
  54. package/dist/queries/index.d.mts +12 -0
  55. package/dist/queries/index.mjs +1 -0
  56. package/{schema → dist/schema}/index.d.mts +1 -1
  57. package/{utils/addTime → dist/utils/add-time}/index.d.mts +1 -1
  58. package/dist/utils/add-time/index.d.mts.map +1 -0
  59. package/dist/utils/add-time/index.mjs.map +1 -0
  60. package/{utils/dataNormalized → dist/utils/data-normalized}/index.d.mts +1 -1
  61. package/dist/utils/data-normalized/index.d.mts.map +1 -0
  62. package/dist/utils/data-normalized/index.mjs +1 -0
  63. package/{utils/dataNormalizedResults → dist/utils/data-normalized-results}/index.d.mts +1 -1
  64. package/dist/utils/data-normalized-results/index.d.mts.map +1 -0
  65. package/dist/utils/data-normalized-results/index.mjs +1 -0
  66. package/{utils/getDataType → dist/utils/get-data-type}/index.d.mts +2 -2
  67. package/dist/utils/get-data-type/index.d.mts.map +1 -0
  68. package/dist/utils/get-data-type/index.mjs.map +1 -0
  69. package/{utils/getTitle → dist/utils/get-title}/index.d.mts +1 -1
  70. package/dist/utils/get-title/index.d.mts.map +1 -0
  71. package/dist/utils/get-title/index.mjs.map +1 -0
  72. package/dist/utils/get-types/_unsupported.d.mts +5 -0
  73. package/dist/utils/get-types/_unsupported.d.mts.map +1 -0
  74. package/dist/utils/get-types/_unsupported.mjs.map +1 -0
  75. package/{utils/getTypes → dist/utils/get-types}/checkbox.d.mts +1 -1
  76. package/dist/utils/get-types/checkbox.d.mts.map +1 -0
  77. package/dist/utils/get-types/checkbox.mjs.map +1 -0
  78. package/{utils/getTypes → dist/utils/get-types}/date.d.mts +1 -1
  79. package/dist/utils/get-types/date.d.mts.map +1 -0
  80. package/dist/utils/get-types/date.mjs.map +1 -0
  81. package/{utils/getTypes → dist/utils/get-types}/email.d.mts +1 -1
  82. package/dist/utils/get-types/email.d.mts.map +1 -0
  83. package/dist/utils/get-types/email.mjs.map +1 -0
  84. package/{utils/getTypes → dist/utils/get-types}/files.d.mts +1 -1
  85. package/dist/utils/get-types/files.d.mts.map +1 -0
  86. package/dist/utils/get-types/files.mjs.map +1 -0
  87. package/{utils/getTypes → dist/utils/get-types}/index.d.mts +1 -1
  88. package/{utils/getTypes → dist/utils/get-types}/index.d.mts.map +1 -1
  89. package/dist/utils/get-types/index.mjs +1 -0
  90. package/{utils/getTypes/multi_select.d.mts → dist/utils/get-types/multi-select.d.mts} +2 -2
  91. package/dist/utils/get-types/multi-select.d.mts.map +1 -0
  92. package/{utils/getTypes/multi_select.mjs → dist/utils/get-types/multi-select.mjs} +1 -1
  93. package/dist/utils/get-types/multi-select.mjs.map +1 -0
  94. package/{utils/getTypes → dist/utils/get-types}/number.d.mts +1 -1
  95. package/dist/utils/get-types/number.d.mts.map +1 -0
  96. package/dist/utils/get-types/number.mjs.map +1 -0
  97. package/{utils/getTypes → dist/utils/get-types}/people.d.mts +1 -1
  98. package/dist/utils/get-types/people.d.mts.map +1 -0
  99. package/dist/utils/get-types/people.mjs.map +1 -0
  100. package/{utils/getTypes/phone_number.d.mts → dist/utils/get-types/phone-number.d.mts} +2 -2
  101. package/dist/utils/get-types/phone-number.d.mts.map +1 -0
  102. package/{utils/getTypes/phone_number.mjs → dist/utils/get-types/phone-number.mjs} +1 -1
  103. package/dist/utils/get-types/phone-number.mjs.map +1 -0
  104. package/{utils/getTypes → dist/utils/get-types}/relation.d.mts +1 -1
  105. package/dist/utils/get-types/relation.d.mts.map +1 -0
  106. package/dist/utils/get-types/relation.mjs +1 -0
  107. package/{utils/getTypes/rich_text.d.mts → dist/utils/get-types/rich-text.d.mts} +2 -2
  108. package/dist/utils/get-types/rich-text.d.mts.map +1 -0
  109. package/{utils/getTypes/rich_text.mjs → dist/utils/get-types/rich-text.mjs} +1 -1
  110. package/dist/utils/get-types/rich-text.mjs.map +1 -0
  111. package/{utils/getTypes → dist/utils/get-types}/rollup.d.mts +1 -1
  112. package/dist/utils/get-types/rollup.d.mts.map +1 -0
  113. package/dist/utils/get-types/rollup.mjs +1 -0
  114. package/{utils/getTypes → dist/utils/get-types}/select.d.mts +1 -1
  115. package/dist/utils/get-types/select.d.mts.map +1 -0
  116. package/dist/utils/get-types/select.mjs.map +1 -0
  117. package/{utils/getTypes → dist/utils/get-types}/title.d.mts +1 -1
  118. package/dist/utils/get-types/title.d.mts.map +1 -0
  119. package/dist/utils/get-types/title.mjs.map +1 -0
  120. package/{utils/getTypes → dist/utils/get-types}/url.d.mts +1 -1
  121. package/{utils/getTypes → dist/utils/get-types}/url.d.mts.map +1 -1
  122. package/dist/utils/get-types/url.mjs.map +1 -0
  123. package/dist/utils/index.d.mts +7 -0
  124. package/dist/utils/index.mjs +1 -0
  125. package/dist/utils-SxsCJsDP.mjs +2 -0
  126. package/dist/utils-SxsCJsDP.mjs.map +1 -0
  127. package/package.json +213 -64
  128. package/release.config.js +25 -0
  129. package/src/constants/index.ts +1326 -0
  130. package/src/index.ts +151 -0
  131. package/src/queries/get-blocks-by-id-children/index.ts +12 -0
  132. package/src/queries/get-databases-by-id-query/index.ts +28 -0
  133. package/src/queries/get-deep-fetch-all-children/index.ts +35 -0
  134. package/src/queries/get-info-type/index.ts +40 -0
  135. package/src/queries/get-notion-listing/index.ts +91 -0
  136. package/src/queries/get-notion-listing-by-date/index.ts +190 -0
  137. package/src/queries/get-notion-slug/index.ts +64 -0
  138. package/src/queries/get-notion-slug-by-route/index.ts +201 -0
  139. package/src/queries/get-pages-by-id/index.ts +12 -0
  140. package/src/queries/get-path-variables/index.ts +60 -0
  141. package/src/queries/get-query/index.ts +140 -0
  142. package/src/queries/index.ts +25 -0
  143. package/src/schema/index.ts +386 -0
  144. package/src/utils/add-time/index.ts +16 -0
  145. package/src/utils/data-normalized/index.ts +49 -0
  146. package/src/utils/data-normalized-results/index.ts +29 -0
  147. package/src/utils/get-data-type/index.ts +62 -0
  148. package/src/utils/get-title/index.ts +21 -0
  149. package/src/utils/get-types/_unsupported.ts +7 -0
  150. package/src/utils/get-types/checkbox.ts +3 -0
  151. package/src/utils/get-types/date.ts +6 -0
  152. package/src/utils/get-types/email.ts +3 -0
  153. package/src/utils/get-types/files.ts +67 -0
  154. package/src/utils/get-types/index.ts +41 -0
  155. package/src/utils/get-types/multi-select.ts +16 -0
  156. package/src/utils/get-types/number.ts +6 -0
  157. package/src/utils/get-types/people.ts +22 -0
  158. package/src/utils/get-types/phone-number.ts +3 -0
  159. package/src/utils/get-types/relation.ts +18 -0
  160. package/src/utils/get-types/rich-text.ts +5 -0
  161. package/src/utils/get-types/rollup.ts +30 -0
  162. package/src/utils/get-types/select.ts +21 -0
  163. package/src/utils/get-types/title.ts +4 -0
  164. package/src/utils/get-types/url.ts +3 -0
  165. package/src/utils/index.ts +16 -0
  166. package/tsconfig.json +15 -0
  167. package/tsdown.config.ts +14 -0
  168. package/constants/index.mjs.map +0 -1
  169. package/getTypes-D-cwjcBl.mjs +0 -2
  170. package/getTypes-D-cwjcBl.mjs.map +0 -1
  171. package/index.d.mts.map +0 -1
  172. package/index.mjs +0 -2
  173. package/index.mjs.map +0 -1
  174. package/queries/getBlocksByIdChildren/index.d.mts.map +0 -1
  175. package/queries/getBlocksByIdChildren/index.mjs.map +0 -1
  176. package/queries/getDatabasesByIdQuery/index.d.mts.map +0 -1
  177. package/queries/getDatabasesByIdQuery/index.mjs.map +0 -1
  178. package/queries/getDeepFetchAllChildren/index.d.mts.map +0 -1
  179. package/queries/getDeepFetchAllChildren/index.mjs.map +0 -1
  180. package/queries/getInfoType/index.d.mts.map +0 -1
  181. package/queries/getInfoType/index.mjs.map +0 -1
  182. package/queries/getNotionListing/index.d.mts.map +0 -1
  183. package/queries/getNotionListing/index.mjs +0 -2
  184. package/queries/getNotionListing/index.mjs.map +0 -1
  185. package/queries/getNotionListingByDate/index.d.mts.map +0 -1
  186. package/queries/getNotionListingByDate/index.mjs +0 -2
  187. package/queries/getNotionListingByDate/index.mjs.map +0 -1
  188. package/queries/getNotionSlug/index.d.mts.map +0 -1
  189. package/queries/getNotionSlug/index.mjs +0 -2
  190. package/queries/getNotionSlug/index.mjs.map +0 -1
  191. package/queries/getNotionSlugByRoute/index.d.mts.map +0 -1
  192. package/queries/getNotionSlugByRoute/index.mjs +0 -2
  193. package/queries/getNotionSlugByRoute/index.mjs.map +0 -1
  194. package/queries/getPagesById/index.d.mts.map +0 -1
  195. package/queries/getPagesById/index.mjs.map +0 -1
  196. package/queries/getPathVariables/index.d.mts.map +0 -1
  197. package/queries/getPathVariables/index.mjs +0 -2
  198. package/queries/getPathVariables/index.mjs.map +0 -1
  199. package/queries/getQuery/index.d.mts.map +0 -1
  200. package/queries/getQuery/index.mjs +0 -2
  201. package/queries/getQuery/index.mjs.map +0 -1
  202. package/queries/index.d.mts +0 -12
  203. package/queries/index.mjs +0 -1
  204. package/utils/addTime/index.d.mts.map +0 -1
  205. package/utils/addTime/index.mjs.map +0 -1
  206. package/utils/dataNormalized/index.d.mts.map +0 -1
  207. package/utils/dataNormalized/index.mjs +0 -1
  208. package/utils/dataNormalizedResults/index.d.mts.map +0 -1
  209. package/utils/dataNormalizedResults/index.mjs +0 -1
  210. package/utils/getDataType/index.d.mts.map +0 -1
  211. package/utils/getDataType/index.mjs.map +0 -1
  212. package/utils/getTitle/index.d.mts.map +0 -1
  213. package/utils/getTitle/index.mjs.map +0 -1
  214. package/utils/getTypes/_unsupported.d.mts +0 -6
  215. package/utils/getTypes/_unsupported.d.mts.map +0 -1
  216. package/utils/getTypes/_unsupported.mjs.map +0 -1
  217. package/utils/getTypes/checkbox.d.mts.map +0 -1
  218. package/utils/getTypes/checkbox.mjs.map +0 -1
  219. package/utils/getTypes/date.d.mts.map +0 -1
  220. package/utils/getTypes/date.mjs.map +0 -1
  221. package/utils/getTypes/email.d.mts.map +0 -1
  222. package/utils/getTypes/email.mjs.map +0 -1
  223. package/utils/getTypes/files.d.mts.map +0 -1
  224. package/utils/getTypes/files.mjs.map +0 -1
  225. package/utils/getTypes/index.mjs +0 -1
  226. package/utils/getTypes/multi_select.d.mts.map +0 -1
  227. package/utils/getTypes/multi_select.mjs.map +0 -1
  228. package/utils/getTypes/number.d.mts.map +0 -1
  229. package/utils/getTypes/number.mjs.map +0 -1
  230. package/utils/getTypes/people.d.mts.map +0 -1
  231. package/utils/getTypes/people.mjs.map +0 -1
  232. package/utils/getTypes/phone_number.d.mts.map +0 -1
  233. package/utils/getTypes/phone_number.mjs.map +0 -1
  234. package/utils/getTypes/relation.d.mts.map +0 -1
  235. package/utils/getTypes/relation.mjs +0 -1
  236. package/utils/getTypes/rich_text.d.mts.map +0 -1
  237. package/utils/getTypes/rich_text.mjs.map +0 -1
  238. package/utils/getTypes/rollup.d.mts.map +0 -1
  239. package/utils/getTypes/rollup.mjs +0 -1
  240. package/utils/getTypes/select.d.mts.map +0 -1
  241. package/utils/getTypes/select.mjs.map +0 -1
  242. package/utils/getTypes/title.d.mts.map +0 -1
  243. package/utils/getTypes/title.mjs.map +0 -1
  244. package/utils/getTypes/url.mjs.map +0 -1
  245. package/utils/index.d.mts +0 -7
  246. package/utils/index.mjs +0 -1
  247. package/utils-VfbevQkn.mjs +0 -2
  248. package/utils-VfbevQkn.mjs.map +0 -1
  249. /package/{constants → dist/constants}/index.mjs +0 -0
  250. /package/{queries/getBlocksByIdChildren → dist/queries/get-blocks-by-id-children}/index.mjs +0 -0
  251. /package/{queries/getDatabasesByIdQuery → dist/queries/get-databases-by-id-query}/index.mjs +0 -0
  252. /package/{queries/getDeepFetchAllChildren → dist/queries/get-deep-fetch-all-children}/index.mjs +0 -0
  253. /package/{queries/getInfoType → dist/queries/get-info-type}/index.mjs +0 -0
  254. /package/{queries/getPagesById → dist/queries/get-pages-by-id}/index.mjs +0 -0
  255. /package/{schema → dist/schema}/index.mjs +0 -0
  256. /package/{utils/addTime → dist/utils/add-time}/index.mjs +0 -0
  257. /package/{utils/getDataType → dist/utils/get-data-type}/index.mjs +0 -0
  258. /package/{utils/getTitle → dist/utils/get-title}/index.mjs +0 -0
  259. /package/{utils/getTypes → dist/utils/get-types}/_unsupported.mjs +0 -0
  260. /package/{utils/getTypes → dist/utils/get-types}/checkbox.mjs +0 -0
  261. /package/{utils/getTypes → dist/utils/get-types}/date.mjs +0 -0
  262. /package/{utils/getTypes → dist/utils/get-types}/email.mjs +0 -0
  263. /package/{utils/getTypes → dist/utils/get-types}/files.mjs +0 -0
  264. /package/{utils/getTypes → dist/utils/get-types}/number.mjs +0 -0
  265. /package/{utils/getTypes → dist/utils/get-types}/people.mjs +0 -0
  266. /package/{utils/getTypes → dist/utils/get-types}/select.mjs +0 -0
  267. /package/{utils/getTypes → dist/utils/get-types}/title.mjs +0 -0
  268. /package/{utils/getTypes → dist/utils/get-types}/url.mjs +0 -0
@@ -0,0 +1,201 @@
1
+ import { sortObject } from "@jeromefitz/utils";
2
+ import { omit as _omit, size as _size } from "lodash-es";
3
+
4
+ import { DATA_TYPES, PROPERTIES, QUERIES } from "../../constants/index";
5
+ import { addTime, dataNormalized } from "../../utils/index";
6
+
7
+ /**
8
+ * @note Determine if PARENT|CHILD should be returned:
9
+ *
10
+ * PARENT
11
+ * - /[parent-routeType]/[slug]
12
+ * - /podcasts/jer-and-ky-and-guest
13
+ *
14
+ * CHILD
15
+ * - /[parent-routeType]/[child-routeType]/[slug]
16
+ * - /podcasts/jer-and-ky-and-guest/am-i-dracula-greg-gillotti
17
+
18
+ *
19
+ */
20
+ const getNotionSlugByRoute__getDataByParentRouteType = async ({
21
+ config,
22
+ getBlocksByIdChildren,
23
+ getDatabasesByIdQuery,
24
+ getQuery,
25
+ pathVariables,
26
+ routeType,
27
+ // slug,
28
+ }) => {
29
+ const { NOTION } = config;
30
+ const { meta } = pathVariables;
31
+
32
+ const ROUTE_TYPE = routeType.toUpperCase();
33
+
34
+ const [parentSlug, slug] = meta;
35
+ const isChild = _size(meta) === 2;
36
+
37
+ const CHILD = NOTION[ROUTE_TYPE]?.hasChild?.toUpperCase();
38
+
39
+ const __info: any = await getDatabasesByIdQuery({
40
+ database_id: NOTION[isChild ? NOTION[CHILD].routeType.toUpperCase() : ROUTE_TYPE].database_id,
41
+ filter: {
42
+ and: [
43
+ {
44
+ ...QUERIES.slug,
45
+ rich_text: { equals: isChild ? slug : parentSlug },
46
+ },
47
+ ],
48
+ },
49
+ });
50
+
51
+ const _info = __info?.object === "list" && __info.results[0];
52
+ // @refactor(404)
53
+ if (!_info) {
54
+ return { content: {}, images: {}, info: {}, items: {} };
55
+ }
56
+ const info = _omit(_info, "properties");
57
+ info.properties = sortObject(
58
+ dataNormalized({ config, data: _info, pageId: info.id, pathVariables }),
59
+ );
60
+ const content = await getBlocksByIdChildren({ block_id: info.id });
61
+ let items = {};
62
+
63
+ /**
64
+ * @note if PARENT then get CHILDREN via `items`
65
+ */
66
+ if (!isChild) {
67
+ items = await getQuery({
68
+ config,
69
+ reqQuery: {
70
+ databaseType: NOTION[CHILD].routeType.toUpperCase(),
71
+ podcasts: info.id,
72
+ },
73
+ });
74
+ }
75
+
76
+ return { content, images: {}, info, items };
77
+ };
78
+
79
+ /**
80
+ * @note This is unique because the following are different:
81
+ *
82
+ * - /events/2020/05/01/jerome-and
83
+ * - /events/2020/05/08/jerome-and
84
+ * - /[routeType]/[yyyy/mm/dd]/[slug]
85
+ *
86
+ * We actually _do_ use the date for this.
87
+ *
88
+ */
89
+ const getNotionSlugByRoute__getDataByListingDate = async ({
90
+ config,
91
+ getBlocksByIdChildren,
92
+ getDatabasesByIdQuery,
93
+ // getQuery,
94
+ pathVariables,
95
+ routeType,
96
+ slug,
97
+ }) => {
98
+ const dateTimestamp = new Date().toISOString();
99
+
100
+ const { NOTION } = config;
101
+ const { meta } = pathVariables;
102
+
103
+ const [year, month, day] = meta;
104
+ /**
105
+ * @hack uh... nothing to see here, haha
106
+ */
107
+ const timestampQuery = new Date(
108
+ `${year ? year : dateTimestamp.slice(0, 4)}-${month ? month : "01"}-${day ? day : "01"}`,
109
+ );
110
+ const property =
111
+ NOTION[routeType.toUpperCase()]?.infoType?.notion ?? PROPERTIES.datePublished.notion;
112
+
113
+ const __info: any = await getDatabasesByIdQuery({
114
+ database_id: NOTION[routeType.toUpperCase()].database_id,
115
+ filter: {
116
+ and: [
117
+ {
118
+ date: {
119
+ on_or_after: addTime(timestampQuery, ""),
120
+ },
121
+ property,
122
+ },
123
+ {
124
+ date: {
125
+ before: addTime(timestampQuery, "day"),
126
+ },
127
+ property,
128
+ },
129
+ {
130
+ ...QUERIES.slug,
131
+ rich_text: { equals: slug },
132
+ },
133
+ ],
134
+ },
135
+ });
136
+
137
+ const _info = __info?.object === "list" && __info.results[0];
138
+ // @refactor(404)
139
+ if (!_info) {
140
+ return { content: {}, images: {}, info: {}, items: {} };
141
+ }
142
+
143
+ const info = _omit(_info, "properties");
144
+ info.properties = sortObject(
145
+ dataNormalized({ config, data: _info, pageId: info.id, pathVariables }),
146
+ );
147
+ const content = await getBlocksByIdChildren({ block_id: info.id });
148
+
149
+ return { content, images: {}, info, items: {} };
150
+ };
151
+
152
+ const getNotionSlugByRoute = async ({
153
+ config,
154
+ getBlocksByIdChildren,
155
+ getDatabasesByIdQuery,
156
+ getQuery,
157
+ pathVariables,
158
+ routeType,
159
+ slug,
160
+ }) => {
161
+ const { NOTION, ROUTE_TYPES_BY_DATA_TYPES } = config;
162
+
163
+ /**
164
+ * @custom (notion) DATA_TYPES.SLUG_BY_ROUTE -- but customized:
165
+ * Determine if `routeType` is a parent|child
166
+ *
167
+ * // @todo(next-notion) move to `isChild`
168
+ *
169
+ */
170
+ if (NOTION[routeType?.toUpperCase()]?.hasChild) {
171
+ return await getNotionSlugByRoute__getDataByParentRouteType({
172
+ config,
173
+ getBlocksByIdChildren,
174
+ getDatabasesByIdQuery,
175
+ getQuery,
176
+ pathVariables,
177
+ routeType,
178
+ // slug,
179
+ });
180
+ }
181
+
182
+ /**
183
+ * @custom (notion) DATA_TYPES.LISTING_BY_DATE
184
+ *
185
+ */
186
+ if (ROUTE_TYPES_BY_DATA_TYPES[DATA_TYPES.LISTING_BY_DATE].includes(routeType.toUpperCase())) {
187
+ return await getNotionSlugByRoute__getDataByListingDate({
188
+ config,
189
+ getBlocksByIdChildren,
190
+ getDatabasesByIdQuery,
191
+ // getQuery,
192
+ pathVariables,
193
+ routeType,
194
+ slug,
195
+ });
196
+ }
197
+
198
+ return { content: {}, images: {}, info: {}, items: {} };
199
+ };
200
+
201
+ export default getNotionSlugByRoute;
@@ -0,0 +1,12 @@
1
+ import { avoidRateLimit, isUndefined } from "@jeromefitz/utils";
2
+
3
+ // @todo(types)
4
+ const getPagesById = async ({ getPagesRetrieve, page_id }) => {
5
+ if (isUndefined(page_id)) return [];
6
+ await avoidRateLimit(0);
7
+ return await getPagesRetrieve({
8
+ page_id,
9
+ });
10
+ };
11
+
12
+ export default getPagesById;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @refactor(lodash)
3
+ */
4
+ import {
5
+ drop as _drop,
6
+ dropRight as _dropRight,
7
+ first as _first,
8
+ includes as _includes,
9
+ isInteger as _isInteger,
10
+ join as _join,
11
+ last as _last,
12
+ size as _size,
13
+ } from "lodash-es";
14
+
15
+ // import { DATA_TYPES } from '../../constants/index'
16
+ import { getDataType } from "../../utils/index";
17
+
18
+ const getPathVariables = ({ catchAll, config }) => {
19
+ const { NOTION, PAGES__HOMEPAGE, ROUTE_META, ROUTE_TYPES } = config;
20
+ const size: number = _size(catchAll);
21
+ const first: any = _first(catchAll);
22
+ const FIRST = first.toUpperCase();
23
+ const last: any = _last(catchAll);
24
+ // const LAST = last.toUpperCase()
25
+
26
+ const meta =
27
+ size > 1 && _includes(ROUTE_META, FIRST) ? _drop(catchAll) : _drop(_dropRight(catchAll));
28
+
29
+ const routeType =
30
+ first === last && !_includes(ROUTE_TYPES, FIRST) ? NOTION.PAGES.routeType : first;
31
+ const slug = first !== last && !_isInteger(parseInt(last)) ? last : first;
32
+
33
+ const isPage = routeType === NOTION.PAGES.routeType.toLowerCase();
34
+ const isIndex = slug === first;
35
+ const hasMeta = !!meta && _size(meta) !== 0;
36
+
37
+ const url = isPage && first === PAGES__HOMEPAGE ? "" : _join(catchAll, "/");
38
+
39
+ const pathVariables = {
40
+ hasMeta,
41
+ isIndex,
42
+ isPage,
43
+ meta,
44
+ routeType,
45
+ slug,
46
+ url,
47
+ };
48
+
49
+ // console.dir(`> pathVariables`)
50
+ // console.dir(pathVariables)
51
+
52
+ const dataType = getDataType(pathVariables);
53
+
54
+ return {
55
+ ...pathVariables,
56
+ dataType,
57
+ };
58
+ };
59
+
60
+ export default getPathVariables;
@@ -0,0 +1,140 @@
1
+ import { avoidRateLimit, isObjectEmpty } from "@jeromefitz/utils";
2
+ import { map as _map, omit as _omit, size as _size } from "lodash-es";
3
+
4
+ import { PROPERTIES } from "../../constants/index";
5
+ import type { SortItem } from "../../schema/index";
6
+ import dataNormalizedResults from "../../utils/data-normalized-results/index";
7
+
8
+ // const useCache = process.env.NEXT_PUBLIC__NOTION_USE_CACHE
9
+ // const useCache = false
10
+
11
+ const SORTS: SortItem[] = [
12
+ {
13
+ direction: "ascending",
14
+ property: PROPERTIES.slug.notion,
15
+ },
16
+ ];
17
+
18
+ // @todo(complexity) 12
19
+ // oxlint-disable-next-line complexity
20
+ const getQuery = async ({ config, notionDatabasesQuery, reqQuery }) => {
21
+ const { NOTION } = config;
22
+ const { databaseType } = reqQuery;
23
+ const routeType = databaseType;
24
+ let hasError = false;
25
+
26
+ /**
27
+ * @setup
28
+ */
29
+ const DATABASE_TYPE = databaseType.toUpperCase();
30
+ const database_id = NOTION[DATABASE_TYPE].database_id;
31
+ if (!database_id) return [];
32
+
33
+ // @todo(types) any
34
+ let data: any = {},
35
+ items: any = {};
36
+ let filter: any, sorts: any;
37
+
38
+ /**
39
+ * @todo(notion) move this to the api so it can be re-used
40
+ * not hidden in here all hacky
41
+ *
42
+ * @note(notion) right now only need this for episodes of podcasts
43
+ * _OR_ Related Databases (PODCASTS => EPISODES)
44
+ *
45
+ * This is not needed often and can/should probably be handled instead
46
+ * with Relations & Rollups rather than this customization
47
+ */
48
+
49
+ if (databaseType === "EPISODES") {
50
+ sorts = SORTS;
51
+ const { podcasts } = reqQuery;
52
+
53
+ // @todo(types)
54
+ const filterTagEpisodesByPodcasts: any = [];
55
+ const podcastIds: any = [];
56
+
57
+ // oxlint-disable-next-line no-unused-expressions
58
+ !!podcasts && podcastIds.push(...podcasts?.split(","));
59
+ // oxlint-disable-next-line no-unused-expressions
60
+ _size(podcastIds) > 0 &&
61
+ _map(podcastIds, (id) =>
62
+ filterTagEpisodesByPodcasts.push({
63
+ property: PROPERTIES.relationEpisodes__Podcasts.notion,
64
+ relation: {
65
+ contains: id,
66
+ },
67
+ }),
68
+ );
69
+ filter = { or: [...filterTagEpisodesByPodcasts] };
70
+ } else {
71
+ // console.dir(`no filter`)
72
+ hasError = true;
73
+ }
74
+
75
+ // /**
76
+ // * @cache pre
77
+ // */
78
+ // if (useCache) {
79
+ // const url = catchAll.join('/')
80
+ // const cacheData = await getCache(url)
81
+ // if (!!cacheData) {
82
+ // data = cacheData
83
+ // }
84
+ // }
85
+
86
+ if (!hasError && (!data || isObjectEmpty(data))) {
87
+ await avoidRateLimit(0);
88
+ // @todo(types) any
89
+ let contentData: Pick<any, number | string | symbol>;
90
+
91
+ // oxlint-disable-next-line no-extra-boolean-cast
92
+ if (!!filter) {
93
+ // @hack(notion)-do-not-return'
94
+ if (filter?.or.length === 0) {
95
+ filter = {
96
+ and: [
97
+ {
98
+ property: PROPERTIES.slug.notion,
99
+ rich_text: { equals: "@hack(notion)-do-not-return" },
100
+ },
101
+ ],
102
+ };
103
+ }
104
+ contentData = await notionDatabasesQuery({
105
+ database_id,
106
+ filter,
107
+ sorts,
108
+ });
109
+
110
+ data = contentData;
111
+ items = dataNormalizedResults({
112
+ config,
113
+ results: contentData.results,
114
+ routeType,
115
+ });
116
+ data = _omit(data, "results");
117
+ data.results = items;
118
+ } else {
119
+ // console.dir(`no filter`)
120
+ hasError = true;
121
+ }
122
+
123
+ // /**
124
+ // * @cache post
125
+ // */
126
+ // if (useCache && !!data) {
127
+ // const url = catchAll.join('/')
128
+ // // console.dir(url)
129
+ // const isCacheExists = await getCache(url)
130
+ // // console.dir(isCacheExists)
131
+ // if (!isCacheExists || isCacheExists === undefined) {
132
+ // setCache(data, url)
133
+ // }
134
+ // }
135
+ }
136
+
137
+ return data;
138
+ };
139
+
140
+ export default getQuery;
@@ -0,0 +1,25 @@
1
+ import getBlocksByIdChildren from "./get-blocks-by-id-children/index";
2
+ import getDatabasesByIdQuery from "./get-databases-by-id-query/index";
3
+ import getDeepFetchAllChildren from "./get-deep-fetch-all-children/index";
4
+ import getInfoType from "./get-info-type/index";
5
+ import getNotionListingByDate from "./get-notion-listing-by-date/index";
6
+ import getNotionListing from "./get-notion-listing/index";
7
+ import getNotionSlugByRoute from "./get-notion-slug-by-route/index";
8
+ import getNotionSlug from "./get-notion-slug/index";
9
+ import getPagesById from "./get-pages-by-id/index";
10
+ import getPathVariables from "./get-path-variables/index";
11
+ import getQuery from "./get-query/index";
12
+
13
+ export {
14
+ getBlocksByIdChildren,
15
+ getDatabasesByIdQuery,
16
+ getDeepFetchAllChildren,
17
+ getInfoType,
18
+ getNotionListing,
19
+ getNotionListingByDate,
20
+ getNotionSlug,
21
+ getNotionSlugByRoute,
22
+ getPagesById,
23
+ getPathVariables,
24
+ getQuery,
25
+ };