notion_ruby_mapping 2.0.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/README.md +19 -6
- data/exe/notionErDiagram.rb +30 -24
- data/lib/notion_ruby_mapping/blocks/base.rb +32 -4
- data/lib/notion_ruby_mapping/blocks/block.rb +0 -1
- data/lib/notion_ruby_mapping/blocks/column_block.rb +7 -2
- data/lib/notion_ruby_mapping/blocks/data_source.rb +167 -0
- data/lib/notion_ruby_mapping/blocks/database.rb +41 -21
- data/lib/notion_ruby_mapping/blocks/file_base_block.rb +3 -3
- data/lib/notion_ruby_mapping/blocks/list.rb +5 -5
- data/lib/notion_ruby_mapping/controllers/mermaid.rb +13 -13
- data/lib/notion_ruby_mapping/controllers/{mermaid_database.rb → mermaid_data_source.rb} +39 -39
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +53 -10
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +26 -4
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +11 -3
- data/lib/notion_ruby_mapping/properties/checkbox_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/created_by_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/created_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/date_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/files_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/formula_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/last_edited_by_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/last_edited_time_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/multi_select_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/number_property.rb +4 -4
- data/lib/notion_ruby_mapping/properties/people_property.rb +2 -2
- data/lib/notion_ruby_mapping/properties/phone_number_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/property.rb +23 -5
- data/lib/notion_ruby_mapping/properties/relation_property.rb +26 -14
- data/lib/notion_ruby_mapping/properties/rich_text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/rollup_property.rb +7 -7
- data/lib/notion_ruby_mapping/properties/select_property.rb +5 -5
- data/lib/notion_ruby_mapping/properties/text_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/title_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/unique_id_property.rb +1 -1
- data/lib/notion_ruby_mapping/properties/url_property.rb +1 -1
- data/lib/notion_ruby_mapping/version.rb +2 -2
- data/lib/notion_ruby_mapping.rb +3 -3
- data/tools/an +4 -4
- metadata +5 -14
- data/exe/erdToNotionDb.rb +0 -56
- data/exe/notionSitemap.rb +0 -131
- data/exe/notionTimeRecorder.rb +0 -284
- data/lib/notion_ruby_mapping/blocks/template_block.rb +0 -34
@@ -56,7 +56,7 @@ module NotionRubyMapping
|
|
56
56
|
property_cache: nil, query: nil)
|
57
57
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
58
58
|
property_cache: property_cache, query: query
|
59
|
-
@json = if
|
59
|
+
@json = if database_or_data_source?
|
60
60
|
{}
|
61
61
|
elsif people
|
62
62
|
Array(people).map { |uo| UserObject.user_object(uo) }
|
@@ -84,7 +84,7 @@ module NotionRubyMapping
|
|
84
84
|
# @return [Hash, Array]
|
85
85
|
def update_from_json(json)
|
86
86
|
@will_update = false
|
87
|
-
@json =
|
87
|
+
@json = database_or_data_source? ? {} : PeopleProperty.people_from_json(json)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -37,7 +37,7 @@ module NotionRubyMapping
|
|
37
37
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
38
38
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
39
39
|
property_cache: property_cache
|
40
|
-
@json =
|
40
|
+
@json = database_or_data_source? ? {} : json
|
41
41
|
end
|
42
42
|
|
43
43
|
## Page property only methods
|
@@ -30,14 +30,14 @@ module NotionRubyMapping
|
|
30
30
|
|
31
31
|
# @param [String] new_name
|
32
32
|
def new_name=(new_name)
|
33
|
-
|
33
|
+
assert_data_source_property __method__
|
34
34
|
@will_update = true
|
35
35
|
@new_name = new_name
|
36
36
|
end
|
37
37
|
|
38
38
|
# @return [NotionRubyMapping::Property] self
|
39
39
|
def remove
|
40
|
-
|
40
|
+
assert_data_source_property __method__
|
41
41
|
@will_update = true
|
42
42
|
@remove = true
|
43
43
|
self
|
@@ -143,6 +143,14 @@ module NotionRubyMapping
|
|
143
143
|
@base_type == "database"
|
144
144
|
end
|
145
145
|
|
146
|
+
def data_source?
|
147
|
+
@base_type == "data_source"
|
148
|
+
end
|
149
|
+
|
150
|
+
def database_or_data_source?
|
151
|
+
%w[database data_source].include? @base_type
|
152
|
+
end
|
153
|
+
|
146
154
|
# @return [TrueClass, FalseClass] true if it has Property contents
|
147
155
|
def contents?
|
148
156
|
!instance_of? Property
|
@@ -188,15 +196,25 @@ module NotionRubyMapping
|
|
188
196
|
raise StandardError, "#{method} can execute only Database property." unless database?
|
189
197
|
end
|
190
198
|
|
199
|
+
# @param [Symbol, nil] method
|
200
|
+
def assert_database_or_data_source_property(method)
|
201
|
+
raise StandardError, "#{method} can execute only Database property." if page?
|
202
|
+
end
|
203
|
+
|
191
204
|
# @return [Hash]
|
192
205
|
def property_schema_json
|
193
|
-
|
206
|
+
assert_database_or_data_source_property __method__
|
194
207
|
{@name => {type => property_schema_json_sub}}
|
195
208
|
end
|
196
209
|
|
210
|
+
## DataSource property only methods
|
211
|
+
def assert_data_source_property(method)
|
212
|
+
raise StandardError, "#{method} can execute only DataSource property." unless data_source?
|
213
|
+
end
|
214
|
+
|
197
215
|
# @return [Hash]
|
198
216
|
def update_property_schema_json
|
199
|
-
|
217
|
+
assert_database_or_data_source_property __method__
|
200
218
|
if @remove
|
201
219
|
{@name => nil}
|
202
220
|
elsif @new_name
|
@@ -210,7 +228,7 @@ module NotionRubyMapping
|
|
210
228
|
|
211
229
|
# @param [Symbol, nil] method
|
212
230
|
def assert_page_property(method)
|
213
|
-
raise StandardError, "#{method} can execute only Page property." if database?
|
231
|
+
raise StandardError, "#{method} can execute only Page property." if database? || data_source?
|
214
232
|
end
|
215
233
|
|
216
234
|
# @return [NotionRubyMapping::Property, Array<UserObject>, nil]
|
@@ -44,20 +44,20 @@ module NotionRubyMapping
|
|
44
44
|
|
45
45
|
## Database property only methods
|
46
46
|
|
47
|
-
# @return [String] relation
|
47
|
+
# @return [String] relation data_source_id
|
48
48
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#eb40f1a2ad5c4e368d343870a7e529f9
|
49
|
-
def
|
50
|
-
|
51
|
-
@json["
|
49
|
+
def relation_data_source_id
|
50
|
+
assert_data_source_property __method__
|
51
|
+
@json["data_source_id"]
|
52
52
|
end
|
53
53
|
|
54
|
-
# @param [String]
|
54
|
+
# @param [String] data_source_id
|
55
55
|
# @param [String] synced_property_name
|
56
56
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#7f5029fb7f6e4c009f22888b233e6f64
|
57
|
-
def
|
58
|
-
|
57
|
+
def replace_relation_data_source(data_source_id: nil, type: "dual_property")
|
58
|
+
assert_database_or_data_source_property __method__
|
59
59
|
@will_update = true
|
60
|
-
@json["
|
60
|
+
@json["data_source_id"] = data_source_id if data_source_id
|
61
61
|
@json["type"] = type
|
62
62
|
@json[type] = {}
|
63
63
|
@json.delete type == "dual_property" ? "single_property" : "dual_property"
|
@@ -75,7 +75,7 @@ module NotionRubyMapping
|
|
75
75
|
property_cache: nil, query: nil)
|
76
76
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
77
77
|
property_cache: property_cache, query: query
|
78
|
-
@json = if
|
78
|
+
@json = if database_or_data_source?
|
79
79
|
json || {}
|
80
80
|
elsif relation
|
81
81
|
Array(relation).map { |r| {"id" => r} }
|
@@ -88,7 +88,7 @@ module NotionRubyMapping
|
|
88
88
|
|
89
89
|
# @return [Hash]
|
90
90
|
def update_property_schema_json
|
91
|
-
|
91
|
+
assert_database_or_data_source_property __method__
|
92
92
|
ans = super
|
93
93
|
return ans if ans != {} || !@will_update
|
94
94
|
|
@@ -97,16 +97,28 @@ module NotionRubyMapping
|
|
97
97
|
ans
|
98
98
|
end
|
99
99
|
|
100
|
-
def
|
101
|
-
@json["
|
100
|
+
def data_source_id
|
101
|
+
@json["data_source_id"]
|
102
|
+
end
|
103
|
+
|
104
|
+
# @return [TrueClass, FalseClass] true if dual_property
|
105
|
+
def dual_property?
|
106
|
+
assert_database_or_data_source_property __method__
|
107
|
+
@json["type"] == "dual_property"
|
108
|
+
end
|
109
|
+
|
110
|
+
# @return [TrueClass, FalseClass] true if single_property
|
111
|
+
def single_property?
|
112
|
+
assert_database_or_data_source_property __method__
|
113
|
+
@json["type"] == "single_property"
|
102
114
|
end
|
103
115
|
|
104
116
|
def synced_property_id
|
105
|
-
|
117
|
+
dual_property? ? @json["dual_property"]["synced_property_id"] : nil
|
106
118
|
end
|
107
119
|
|
108
120
|
def synced_property_name
|
109
|
-
|
121
|
+
dual_property? ? @json["dual_property"]["synced_property_name"] : nil
|
110
122
|
end
|
111
123
|
|
112
124
|
# @return [Hash] created json
|
@@ -12,7 +12,7 @@ module NotionRubyMapping
|
|
12
12
|
# @param [Hash] json
|
13
13
|
def update_from_json(json)
|
14
14
|
@will_update = false
|
15
|
-
if
|
15
|
+
if database_or_data_source?
|
16
16
|
@json = json["rich_text"] || {}
|
17
17
|
else
|
18
18
|
@text_objects = RichTextArray.new "rich_text", json: json["rich_text"]
|
@@ -23,14 +23,14 @@ module NotionRubyMapping
|
|
23
23
|
# @return [String] new or settled function
|
24
24
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#94021d4e6c0b44519443c1e1cc6b3aba
|
25
25
|
def function
|
26
|
-
|
26
|
+
assert_database_or_data_source_property __method__
|
27
27
|
@json["function"]
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [String] func
|
31
31
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#647c74803cac49a9b79199828157e17a
|
32
32
|
def function=(func)
|
33
|
-
|
33
|
+
assert_database_or_data_source_property __method__
|
34
34
|
@will_update = true
|
35
35
|
@json["function"] = func
|
36
36
|
end
|
@@ -38,14 +38,14 @@ module NotionRubyMapping
|
|
38
38
|
# @return [String] new or settled relation_property_name
|
39
39
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#684fc4739c4f4d6a9b93687f72cd8dad
|
40
40
|
def relation_property_name
|
41
|
-
|
41
|
+
assert_database_or_data_source_property __method__
|
42
42
|
@json["relation_property_name"]
|
43
43
|
end
|
44
44
|
|
45
45
|
# @param [String] rpn
|
46
46
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#a61c2100758841c381edd820aa88ac65
|
47
47
|
def relation_property_name=(rpn)
|
48
|
-
|
48
|
+
assert_database_or_data_source_property __method__
|
49
49
|
@will_update = true
|
50
50
|
@json["relation_property_name"] = rpn
|
51
51
|
end
|
@@ -53,14 +53,14 @@ module NotionRubyMapping
|
|
53
53
|
# @return [String] new or settled rollup_property_name
|
54
54
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#8ce9ee31a2e2473ab7ba21781e4b440d
|
55
55
|
def rollup_property_name
|
56
|
-
|
56
|
+
assert_database_or_data_source_property __method__
|
57
57
|
@json["rollup_property_name"]
|
58
58
|
end
|
59
59
|
|
60
60
|
# @param [String] rpn
|
61
61
|
# @see https://www.notion.so/hkob/RollupProperty-eb10fbac3a93436289e74e5c651e9134#66503f4472f2456aa9b383f03b1fe0a6
|
62
62
|
def rollup_property_name=(rpn)
|
63
|
-
|
63
|
+
assert_database_or_data_source_property __method__
|
64
64
|
@will_update = true
|
65
65
|
@json["rollup_property_name"] = rpn
|
66
66
|
end
|
@@ -82,7 +82,7 @@ module NotionRubyMapping
|
|
82
82
|
|
83
83
|
# @return [Hash]
|
84
84
|
def update_property_schema_json
|
85
|
-
|
85
|
+
assert_database_or_data_source_property __method__
|
86
86
|
ans = super
|
87
87
|
return ans if ans != {} || !@will_update
|
88
88
|
|
@@ -38,7 +38,7 @@ module NotionRubyMapping
|
|
38
38
|
|
39
39
|
# @return [Array] copyed multi select options
|
40
40
|
def edit_select_options
|
41
|
-
|
41
|
+
assert_database_or_data_source_property __method__
|
42
42
|
@will_update = true
|
43
43
|
@json["options"] ||= []
|
44
44
|
end
|
@@ -46,14 +46,14 @@ module NotionRubyMapping
|
|
46
46
|
# @return [Array]
|
47
47
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#790a297f2c1b4ba5a4d86074d4c70a89
|
48
48
|
def select_options
|
49
|
-
|
49
|
+
assert_database_or_data_source_property __method__
|
50
50
|
@json["options"] || []
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [String]
|
54
54
|
# @see https://www.notion.so/hkob/SelectProperty-6d6a0defa70d4b26af0fdbdcfbf99f28#72da1632793c4a5296f3bc89de2df413
|
55
55
|
def select_names
|
56
|
-
|
56
|
+
assert_database_or_data_source_property __method__
|
57
57
|
@json["options"].map { |s| s["name"] }
|
58
58
|
end
|
59
59
|
|
@@ -78,7 +78,7 @@ module NotionRubyMapping
|
|
78
78
|
property_cache: nil)
|
79
79
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
80
80
|
property_cache: property_cache
|
81
|
-
@json = if
|
81
|
+
@json = if database_or_data_source?
|
82
82
|
json || {"options" => []}
|
83
83
|
else
|
84
84
|
json || {"name" => select}
|
@@ -89,7 +89,7 @@ module NotionRubyMapping
|
|
89
89
|
|
90
90
|
# @return [Hash]
|
91
91
|
def update_property_schema_json
|
92
|
-
|
92
|
+
assert_database_or_data_source_property __method__
|
93
93
|
ans = super
|
94
94
|
return ans if ans != {} || !@will_update
|
95
95
|
|
@@ -33,7 +33,7 @@ module NotionRubyMapping
|
|
33
33
|
|
34
34
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
35
35
|
property_cache: property_cache, query: query
|
36
|
-
@text_objects = if
|
36
|
+
@text_objects = if database_or_data_source?
|
37
37
|
json || {}
|
38
38
|
else
|
39
39
|
RichTextArray.new "title", json: json, text_objects: text_objects
|
@@ -30,7 +30,7 @@ module NotionRubyMapping
|
|
30
30
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
31
31
|
super name, will_update: will_update, base_type: base_type, property_id: property_id, property_cache: property_cache
|
32
32
|
@json = json
|
33
|
-
@json ||= {} if
|
33
|
+
@json ||= {} if database_or_data_source?
|
34
34
|
end
|
35
35
|
|
36
36
|
# @param [Hash] json
|
@@ -37,7 +37,7 @@ module NotionRubyMapping
|
|
37
37
|
def initialize(name, will_update: false, base_type: "page", json: nil, property_id: nil, property_cache: nil)
|
38
38
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
39
39
|
property_cache: property_cache
|
40
|
-
@json = json || (
|
40
|
+
@json = json || (database_or_data_source? ? {} : nil)
|
41
41
|
end
|
42
42
|
|
43
43
|
## Page property only methods
|
data/lib/notion_ruby_mapping.rb
CHANGED
@@ -4,16 +4,16 @@ require "yaml"
|
|
4
4
|
|
5
5
|
require_relative "notion_ruby_mapping/version"
|
6
6
|
{
|
7
|
-
blocks: %w[base block database list page url_caption_base_block bookmark_block breadcrumb_block
|
7
|
+
blocks: %w[base block database data_source list page url_caption_base_block bookmark_block breadcrumb_block
|
8
8
|
text_sub_block_color_base_block bulleted_list_item_block callout_block child_base_block
|
9
9
|
child_database_block child_page_block code_block column_list_block column_block divider_block
|
10
10
|
embed_block equation_block file_base_block file_block heading1_block heading2_block heading3_block
|
11
11
|
image_block toggle_heading1_block toggle_heading2_block toggle_heading3_block url_base_block
|
12
12
|
link_preview_block link_to_page_block numbered_list_item_block paragraph_block pdf_block quote_block
|
13
|
-
synced_block table_block table_row_block table_of_contents_block
|
13
|
+
synced_block table_block table_row_block table_of_contents_block to_do_block
|
14
14
|
toggle_block video_block],
|
15
15
|
controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread search mermaid
|
16
|
-
|
16
|
+
mermaid_data_source],
|
17
17
|
objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
|
18
18
|
comment_object file_upload_object],
|
19
19
|
properties: %w[property checkbox_property multi_property created_by_property date_base_property created_time_property
|
data/tools/an
CHANGED
@@ -8,7 +8,7 @@ module NotionRubyMapping
|
|
8
8
|
# you Notion API token
|
9
9
|
NOTION_API_TOKEN = "secret_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
|
10
10
|
# your task Database id
|
11
|
-
|
11
|
+
DATA_SOURCE_ID = "0123456789abcdef0123456789abcdef"
|
12
12
|
# your Title name
|
13
13
|
TITLE_NAME = "タスク名"
|
14
14
|
# your DateProperty name
|
@@ -75,10 +75,10 @@ module NotionRubyMapping
|
|
75
75
|
usage
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
NotionRubyMapping.configure { |c| c.token = NOTION_API_TOKEN }
|
79
79
|
|
80
|
-
# create
|
81
|
-
|
80
|
+
# create data_source object without API call and create a child page
|
81
|
+
DataSource.new id: DATA_SOURCE_ID
|
82
82
|
page = db.create_child_page TitleProperty, TITLE_NAME, DateProperty, DATE_NAME
|
83
83
|
|
84
84
|
# obtain title and date properties and set values
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion_ruby_mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki KOBAYASHI
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -154,10 +153,7 @@ description: Mapping tool from Notion Database/Page/Block to Ruby Objects.
|
|
154
153
|
email:
|
155
154
|
- hkob@metro-cit.ac.jp
|
156
155
|
executables:
|
157
|
-
- erdToNotionDb.rb
|
158
156
|
- notionErDiagram.rb
|
159
|
-
- notionSitemap.rb
|
160
|
-
- notionTimeRecorder.rb
|
161
157
|
extensions: []
|
162
158
|
extra_rdoc_files: []
|
163
159
|
files:
|
@@ -176,10 +172,7 @@ files:
|
|
176
172
|
- examples/change_title.md
|
177
173
|
- examples/renumbering_pages.md
|
178
174
|
- examples/set_icon_to_all_icon_unsettled_pages.md
|
179
|
-
- exe/erdToNotionDb.rb
|
180
175
|
- exe/notionErDiagram.rb
|
181
|
-
- exe/notionSitemap.rb
|
182
|
-
- exe/notionTimeRecorder.rb
|
183
176
|
- images/post_set_icon.png
|
184
177
|
- images/pre_set_icon.png
|
185
178
|
- images/serial_number.png
|
@@ -196,6 +189,7 @@ files:
|
|
196
189
|
- lib/notion_ruby_mapping/blocks/code_block.rb
|
197
190
|
- lib/notion_ruby_mapping/blocks/column_block.rb
|
198
191
|
- lib/notion_ruby_mapping/blocks/column_list_block.rb
|
192
|
+
- lib/notion_ruby_mapping/blocks/data_source.rb
|
199
193
|
- lib/notion_ruby_mapping/blocks/database.rb
|
200
194
|
- lib/notion_ruby_mapping/blocks/divider_block.rb
|
201
195
|
- lib/notion_ruby_mapping/blocks/embed_block.rb
|
@@ -218,7 +212,6 @@ files:
|
|
218
212
|
- lib/notion_ruby_mapping/blocks/table_block.rb
|
219
213
|
- lib/notion_ruby_mapping/blocks/table_of_contents_block.rb
|
220
214
|
- lib/notion_ruby_mapping/blocks/table_row_block.rb
|
221
|
-
- lib/notion_ruby_mapping/blocks/template_block.rb
|
222
215
|
- lib/notion_ruby_mapping/blocks/text_sub_block_color_base_block.rb
|
223
216
|
- lib/notion_ruby_mapping/blocks/to_do_block.rb
|
224
217
|
- lib/notion_ruby_mapping/blocks/toggle_block.rb
|
@@ -230,7 +223,7 @@ files:
|
|
230
223
|
- lib/notion_ruby_mapping/blocks/video_block.rb
|
231
224
|
- lib/notion_ruby_mapping/controllers/discussion_thread.rb
|
232
225
|
- lib/notion_ruby_mapping/controllers/mermaid.rb
|
233
|
-
- lib/notion_ruby_mapping/controllers/
|
226
|
+
- lib/notion_ruby_mapping/controllers/mermaid_data_source.rb
|
234
227
|
- lib/notion_ruby_mapping/controllers/notion_cache.rb
|
235
228
|
- lib/notion_ruby_mapping/controllers/payload.rb
|
236
229
|
- lib/notion_ruby_mapping/controllers/property_cache.rb
|
@@ -280,7 +273,6 @@ homepage: https://github.com/hkob/notion_ruby_mapping.git
|
|
280
273
|
licenses:
|
281
274
|
- MIT
|
282
275
|
metadata: {}
|
283
|
-
post_install_message:
|
284
276
|
rdoc_options: []
|
285
277
|
require_paths:
|
286
278
|
- lib
|
@@ -295,8 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
287
|
- !ruby/object:Gem::Version
|
296
288
|
version: '0'
|
297
289
|
requirements: []
|
298
|
-
rubygems_version: 3.
|
299
|
-
signing_key:
|
290
|
+
rubygems_version: 3.6.9
|
300
291
|
specification_version: 4
|
301
292
|
summary: Notion Ruby mapping tool
|
302
293
|
test_files: []
|
data/exe/erdToNotionDb.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
require "notion_ruby_mapping"
|
4
|
-
include NotionRubyMapping
|
5
|
-
|
6
|
-
if ARGV.length < 2
|
7
|
-
print "Usage: erdToNotion.rb code_block_id target_page_id [--inline]"
|
8
|
-
exit
|
9
|
-
end
|
10
|
-
|
11
|
-
mermaid_url, target_page_url, inline_flag = ARGV
|
12
|
-
inline = inline_flag == "--inline"
|
13
|
-
NotionRubyMapping.configure { |c| c.notion_token = ENV["NOTION_API_KEY"] }
|
14
|
-
nc = NotionCache.instance
|
15
|
-
mermaid_block = Block.find mermaid_url
|
16
|
-
unless mermaid_block.is_a? CodeBlock
|
17
|
-
print "#{mermaid_url} is not CodeBlock's id"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
# Parse mermaid ER
|
22
|
-
mermaid = Mermaid.new mermaid_block.rich_text_array.full_text
|
23
|
-
|
24
|
-
# Retrieve child databases
|
25
|
-
target_page = Page.find target_page_url
|
26
|
-
target_page_id = target_page.id
|
27
|
-
db_titles = target_page.children.select { |b| b.is_a? ChildDatabaseBlock }.map(&:title)
|
28
|
-
exist_dbs = Search.new(query: "(#{db_titles.join('|')})", database_only: true).exec.select do |db|
|
29
|
-
nc.hex_id(db.parent_id) == target_page_id
|
30
|
-
end
|
31
|
-
|
32
|
-
# Attach existing databases to mermaid database
|
33
|
-
exist_dbs.each do |db|
|
34
|
-
mermaid.attach_database db
|
35
|
-
end
|
36
|
-
|
37
|
-
mermaid.create_notion_db target_page, inline
|
38
|
-
mermaid.update_title
|
39
|
-
pass = 1
|
40
|
-
pre_remain = nil
|
41
|
-
loop do
|
42
|
-
print "=== Pass #{pass} ===\n"
|
43
|
-
mermaid.update_databases
|
44
|
-
mermaid.rename_reverse_name
|
45
|
-
count = mermaid.count
|
46
|
-
remain = mermaid.remain
|
47
|
-
print "Pass #{pass} Remain #{remain} in #{count}\n"
|
48
|
-
if pre_remain == remain
|
49
|
-
print "Dependency loop detected.\n"
|
50
|
-
exit
|
51
|
-
end
|
52
|
-
pre_remain = remain
|
53
|
-
break if remain.zero?
|
54
|
-
pass += 1
|
55
|
-
end
|
56
|
-
print "Finish!!!"
|
data/exe/notionSitemap.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
require "notion_ruby_mapping"
|
4
|
-
include NotionRubyMapping
|
5
|
-
|
6
|
-
# see https://zenn.dev/kinkinbeer135ml/articles/f08ce790091aca
|
7
|
-
def escape_title(title)
|
8
|
-
title.gsub /[(){}\[\]!”#$%&’()=^〜|¥1234567890@`「」{};:+*<>、。・?_]/, ""
|
9
|
-
end
|
10
|
-
|
11
|
-
class Sitemap
|
12
|
-
def initialize(top_page, orient, nolink)
|
13
|
-
@top_page = top_page
|
14
|
-
@code = {@top_page => "p0"}
|
15
|
-
@queue = [@top_page]
|
16
|
-
@finished = {}
|
17
|
-
@page_links = Hash.new { |h, k| h[k] = [] }
|
18
|
-
@text = ["flowchart #{orient}"]
|
19
|
-
@nolink = nolink
|
20
|
-
end
|
21
|
-
attr_reader :text
|
22
|
-
|
23
|
-
def dig_pages
|
24
|
-
until @queue.empty?
|
25
|
-
page = @queue.shift
|
26
|
-
@finished[page] = true
|
27
|
-
search_blocks(page)
|
28
|
-
@text << %(click #{@code[page]} "#{page["url"]}")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def code_with_title(page)
|
33
|
-
"#{@code[page]}(#{escape_title page.title})"
|
34
|
-
end
|
35
|
-
|
36
|
-
def search_blocks(page)
|
37
|
-
print "#{page.title}\n"
|
38
|
-
@children = []
|
39
|
-
@block_queue = page.children.to_a
|
40
|
-
search_block page, @block_queue.shift until @block_queue.empty?
|
41
|
-
unless @children.empty?
|
42
|
-
title = page == @top_page ? code_with_title(page) : @code[page]
|
43
|
-
@text << [title, @children.map { |p| code_with_title p }.join(" & ")].join(" --> ")
|
44
|
-
end
|
45
|
-
print "\n"
|
46
|
-
end
|
47
|
-
|
48
|
-
def search_block(page, block)
|
49
|
-
case block
|
50
|
-
when ChildPageBlock
|
51
|
-
child_block = block.children.first
|
52
|
-
add_child child_block.parent if child_block
|
53
|
-
when LinkToPageBlock
|
54
|
-
add_link page, block.page_id unless @nolink
|
55
|
-
else
|
56
|
-
@block_queue += block.children.to_a if block.has_children
|
57
|
-
search_link_in_rta(page, block.rich_text_array) if !@nolink && block.is_a?(TextSubBlockColorBaseBlock)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def add_child(child)
|
62
|
-
@queue << child
|
63
|
-
@children << child
|
64
|
-
set_code child
|
65
|
-
print " --> #{child.title}\n"
|
66
|
-
end
|
67
|
-
|
68
|
-
def set_code(page)
|
69
|
-
@code[page] ||= "p#{@code.length}"
|
70
|
-
end
|
71
|
-
|
72
|
-
def add_link(page, link_page_id)
|
73
|
-
return unless link_page_id
|
74
|
-
|
75
|
-
begin
|
76
|
-
link_page = Page.find link_page_id
|
77
|
-
rescue
|
78
|
-
print "\n#{link_page_id} can not read by this integration\n"
|
79
|
-
return
|
80
|
-
end
|
81
|
-
set_code link_page
|
82
|
-
@page_links[page] << link_page
|
83
|
-
print " -.-> #{link_page.title} "
|
84
|
-
end
|
85
|
-
|
86
|
-
def search_link_in_rta(page, rta)
|
87
|
-
rta.each { |to| add_link page, to.page_id if to.is_a?(MentionObject) && to.page_id }
|
88
|
-
end
|
89
|
-
|
90
|
-
def link_pages
|
91
|
-
@page_links.each do |org, array|
|
92
|
-
link_finished = {}
|
93
|
-
array.each do |lp|
|
94
|
-
link_finished[lp] = @finished[lp] ? @code[lp] : code_with_title(lp)
|
95
|
-
end
|
96
|
-
@text << [@code[org], link_finished.values.join(" & ")].join(" -.-> ")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
if ARGV.length < 3
|
102
|
-
print "Usage: notionSitemap.rb top_page_id code_block_id orient(LR or TD) [--nolink]"
|
103
|
-
exit
|
104
|
-
end
|
105
|
-
top_page_id, code_block_id, orient, nolink = ARGV
|
106
|
-
NotionCache.instance.create_client ENV["NOTION_API_KEY"]
|
107
|
-
code_block = Block.find code_block_id
|
108
|
-
unless code_block.is_a? CodeBlock
|
109
|
-
print "#{code_block_id} is not CodeBlock's id"
|
110
|
-
exit
|
111
|
-
end
|
112
|
-
|
113
|
-
top_page = Page.find top_page_id
|
114
|
-
sm = Sitemap.new top_page, orient, nolink == "--nolink"
|
115
|
-
sm.dig_pages
|
116
|
-
sm.link_pages unless nolink
|
117
|
-
text_objects = sm.text.each_with_object([]) do |str, ans|
|
118
|
-
strn = "#{str}\n"
|
119
|
-
if (last = ans.last)
|
120
|
-
if last.length + strn.length > 1999
|
121
|
-
ans << strn
|
122
|
-
else
|
123
|
-
ans[-1] += strn
|
124
|
-
end
|
125
|
-
else
|
126
|
-
ans << strn
|
127
|
-
end
|
128
|
-
end
|
129
|
-
code_block.rich_text_array.rich_text_objects = text_objects
|
130
|
-
code_block.language = "mermaid"
|
131
|
-
code_block.save
|