gatsby-source-notion-churnotion 1.0.34 → 1.0.36

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.
@@ -1,2 +1,2 @@
1
1
  import { IGetBooksParams } from "../types";
2
- export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, }: IGetBooksParams) => Promise<void>;
2
+ export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, }: IGetBooksParams) => Promise<void>;
@@ -7,7 +7,7 @@ exports.getBooks = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const constants_1 = require("../constants");
9
9
  const fetchData_1 = require("../util/fetchData");
10
- const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, }) => {
10
+ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, }) => {
11
11
  const databaseUrl = `databases/${bookDatabaseId}/query`;
12
12
  const body = {};
13
13
  const result = await (0, fetchData_1.fetchPostWithRetry)(databaseUrl, body);
@@ -19,6 +19,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, })
19
19
  const nodeId = createNodeId(`${page.id}-book`);
20
20
  const slug = page.properties?.slug?.rich_text?.[0]?.plain_text || `unnamed-slug`;
21
21
  const bookCategoryId = page.properties?.category?.relation?.[0]?.id || null;
22
+ const categoryNode = getNode(bookCategoryId);
22
23
  const bookNode = {
23
24
  id: nodeId,
24
25
  book_name: page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`,
@@ -35,7 +36,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, })
35
36
  create_date: page.created_time,
36
37
  update_date: page.last_edited_time,
37
38
  url: `${constants_1.COMMON_URI}/${constants_1.BOOK_URI}/${slug}`,
38
- book_category: bookCategoryId,
39
+ book_category: categoryNode,
39
40
  };
40
41
  reporter.info(`[DEBUG] Book ${bookNode.book_name} has book_category: ${bookNode.book_category}`);
41
42
  createNode(bookNode);
@@ -57,22 +57,6 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
57
57
  books: [],
58
58
  };
59
59
  await createNode(categoryNode);
60
- // Find Book
61
- const bookRelations = page.properties?.books?.relation || null;
62
- if (bookRelations) {
63
- bookRelations.forEach((relation) => {
64
- const bookId = relation.id;
65
- const bookNodeId = createNodeId(`${bookId}-book`);
66
- const bookNode = getNode(bookNodeId);
67
- if (bookNode) {
68
- createParentChildLink({
69
- parent: categoryNode,
70
- child: bookNode,
71
- });
72
- reporter.info(`[SUCCESS] Linked Category-Book: ${categoryNode.category_name} -> child: ${bookNode.book_name}`);
73
- }
74
- });
75
- }
76
60
  if (parentCategoryId && categoryNode) {
77
61
  const parentNode = getNode(parentCategoryId); // Gatsby에서 노드를 검색
78
62
  if (parentNode) {
@@ -40,7 +40,7 @@ const createSchemaCustomization = ({ actions }) => {
40
40
  children: [${constants_1.NODE_TYPE.Category}!]! @link(by: "parent")
41
41
  churnotions: [${constants_1.NODE_TYPE.Post}] @link(by: "category", from: "id")
42
42
  url: String!
43
- books: [${constants_1.NODE_TYPE.Book}] @link(by: "id")
43
+ books: [${constants_1.NODE_TYPE.Book}] @link(by: "book_category", from: "id")
44
44
  }
45
45
 
46
46
  type ${constants_1.NODE_TYPE.Book} implements Node {
@@ -50,7 +50,7 @@ const createSchemaCustomization = ({ actions }) => {
50
50
  update_date: Date! @dateformat
51
51
  children: [${constants_1.NODE_TYPE.Post}] @link(by: "book", from: "id")
52
52
  url: String!
53
- book_category: ${constants_1.NODE_TYPE.Category} @link(by: "id", from: "books")
53
+ book_category: ${constants_1.NODE_TYPE.Category} @link(by: "id")
54
54
  }
55
55
  `);
56
56
  };
@@ -13,12 +13,6 @@ const sourceNodes = async (gatsbyApi, options) => {
13
13
  }
14
14
  reporter.info(`[INFO] Fetching pages from Notion database...`);
15
15
  try {
16
- await (0, getBooks_1.getBooks)({
17
- bookDatabaseId,
18
- reporter,
19
- createNode,
20
- createNodeId,
21
- });
22
16
  await (0, getPages_1.getPages)({
23
17
  token,
24
18
  databaseId,
@@ -30,6 +24,13 @@ const sourceNodes = async (gatsbyApi, options) => {
30
24
  createParentChildLink,
31
25
  getNode,
32
26
  });
27
+ await (0, getBooks_1.getBooks)({
28
+ bookDatabaseId,
29
+ reporter,
30
+ createNode,
31
+ createNodeId,
32
+ getNode,
33
+ });
33
34
  }
34
35
  catch (e) {
35
36
  reporter.error(`[ERROR] ${e}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatsby-source-notion-churnotion",
3
3
  "description": "Gatsby plugin that can connect with One Notion Database RECURSIVELY using official API",
4
- "version": "1.0.34",
4
+ "version": "1.0.36",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",