notion_ruby_mapping 0.7.1 → 0.7.3
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/.rubocop.yml +2 -0
- data/README.md +5 -2
- data/exe/erdToNotionDb.rb +56 -0
- data/exe/notionErDiagram.rb +1 -1
- data/lib/notion_ruby_mapping/blocks/base.rb +7 -0
- data/lib/notion_ruby_mapping/blocks/child_database_block.rb +4 -0
- data/lib/notion_ruby_mapping/blocks/child_page_block.rb +4 -0
- data/lib/notion_ruby_mapping/blocks/database.rb +6 -1
- data/lib/notion_ruby_mapping/blocks/list.rb +7 -0
- data/lib/notion_ruby_mapping/blocks/page.rb +4 -1
- data/lib/notion_ruby_mapping/controllers/mermaid.rb +82 -0
- data/lib/notion_ruby_mapping/controllers/mermaid_database.rb +245 -0
- data/lib/notion_ruby_mapping/controllers/notion_cache.rb +8 -0
- data/lib/notion_ruby_mapping/controllers/search.rb +29 -0
- data/lib/notion_ruby_mapping/properties/property.rb +2 -0
- data/lib/notion_ruby_mapping/properties/relation_property.rb +16 -3
- data/lib/notion_ruby_mapping/properties/text_property.rb +2 -2
- data/lib/notion_ruby_mapping/version.rb +1 -1
- data/lib/notion_ruby_mapping.rb +2 -2
- data/notion_ruby_mapping.gemspec +1 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da835af42a7f97ad54db43b0cbc8bad2e0a7374004cc5a643f2b307641e1b081
|
4
|
+
data.tar.gz: d0b5d728ea30328290c676c51cb3bbbf19508c7f2c6413f032b347989cefae12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85bc6f5b88a5a91fc951455c658c9e9e39cc806f3d772c170eafb323eedfc0fc326e601cf8d3ba79ec518f17ec3a42d9c3cec3c70639c1282eec9daed4da6415
|
7
|
+
data.tar.gz: 6af5b7f9a5da2c678826746808310e82ce53f5f60df9ea7808e9b12ac7b8b78d20b9bc81441e6a8596896921ec0d57f97c8add47d04c12c48a5b1374a41851de
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -116,8 +116,9 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
|
|
116
116
|
1. [Set icon to all icon unsettled pages / 全てのページのアイコンを同一に設定](examples/set_icon_to_all_icon_unsettled_pages.md)
|
117
117
|
2. [Renumbering pages / ページのナンバリング](examples/renumbering_pages.md)
|
118
118
|
3. [Change title / タイトルの変更](examples/change_title.md)
|
119
|
-
4. [Create ER Diagram from Notion database / Notion データベースの ER 図を作成](https://
|
120
|
-
5. [Create Sitemap from Notion pages / Notion page からサイトマップを作成](https://
|
119
|
+
4. [Create ER Diagram from Notion database / Notion データベースの ER 図を作成](https://hkob.notion.site/notionErDiagram-Sample-1720c2199c534ca08138cde38f31f710)
|
120
|
+
5. [Create Sitemap from Notion pages / Notion page からサイトマップを作成](https://hkob.notion.site/notionSitemap-sample-14e195c83d024c5382aab09210916c87)
|
121
|
+
6. [Create Notion databases from ER Diagram / ER 図から Notion データベースを作成](https://hkob.notion.site/erdToNotionDb-sample-87e5e52a6b9f46abbdeebcb3c902a516)
|
121
122
|
|
122
123
|
### 2.5 API reference / API リファレンス
|
123
124
|
|
@@ -125,6 +126,8 @@ NotionRubyMapping.configuration { |c| c.notion_token = ENV["NOTION_API_TOKEN"] }
|
|
125
126
|
|
126
127
|
## 3. ChangeLog
|
127
128
|
|
129
|
+
- 2023/1/26 [v0.7.3] release beta version of erdToNotionRb.rb script
|
130
|
+
- 2023/1/25 [v0.7.2] bug fix for creating relation property / add erdToNotionRb.rb script
|
128
131
|
- 2022/12/16 [v0.7.1] bug fix for query rollup property
|
129
132
|
- 2022/11/28 [v0.7.0] add this_week filter and NotionRubyMapping.configure
|
130
133
|
- 2022/11/13 [v0.6.8] remove error checking for start and end dates, add Users.all, and change Rollup and Formula query specification
|
@@ -0,0 +1,56 @@
|
|
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/notionErDiagram.rb
CHANGED
@@ -29,7 +29,7 @@ if ARGV.length < 2
|
|
29
29
|
exit
|
30
30
|
end
|
31
31
|
database_id, code_block_id = ARGV
|
32
|
-
|
32
|
+
NotionRubyMapping.configure { |c| c.notion_token = ENV["NOTION_API_KEY"] }
|
33
33
|
block = Block.find code_block_id
|
34
34
|
unless block.is_a? CodeBlock
|
35
35
|
print "#{code_block_id} is not CodeBlock's id"
|
@@ -256,6 +256,13 @@ module NotionRubyMapping
|
|
256
256
|
klass.find parent_json[type], dry_run: dry_run
|
257
257
|
end
|
258
258
|
|
259
|
+
def parent_id
|
260
|
+
parent_json = @json && @json["parent"]
|
261
|
+
raise StandardError, "Unknown parent" if parent_json.nil?
|
262
|
+
|
263
|
+
parent_json[parent_json["type"]]
|
264
|
+
end
|
265
|
+
|
259
266
|
# @return [NotionRubyMapping::PropertyCache] get or created PropertyCache object
|
260
267
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#8f0b28e09dd74e2a9ff06126c48d64d4
|
261
268
|
def properties
|
@@ -155,7 +155,12 @@ module NotionRubyMapping
|
|
155
155
|
if dry_run
|
156
156
|
dry_run_script :patch, @nc.database_path(@id), :update_property_schema_json
|
157
157
|
else
|
158
|
-
|
158
|
+
payload = update_property_schema_json
|
159
|
+
begin
|
160
|
+
update_json @nc.update_database_request(@id, payload)
|
161
|
+
rescue StandardError => e
|
162
|
+
raise StandardError, "#{e.message} by #{payload}"
|
163
|
+
end
|
159
164
|
end
|
160
165
|
end
|
161
166
|
end
|
@@ -21,6 +21,8 @@ module NotionRubyMapping
|
|
21
21
|
@property = value
|
22
22
|
when :user_object
|
23
23
|
@user_object = true
|
24
|
+
when :search
|
25
|
+
@search = value
|
24
26
|
end
|
25
27
|
@query = query
|
26
28
|
@index = 0
|
@@ -74,6 +76,11 @@ module NotionRubyMapping
|
|
74
76
|
query: -> { @nc.users_request @query.query_json },
|
75
77
|
create_object: ->(json) { UserObject.new json: json },
|
76
78
|
&block
|
79
|
+
elsif @search
|
80
|
+
each_sub base: @search,
|
81
|
+
query: -> { @nc.search @search.payload.merge(@query.query_json) },
|
82
|
+
create_object: ->(json) { Base.create_from_json json },
|
83
|
+
&block
|
77
84
|
end
|
78
85
|
self
|
79
86
|
end
|
@@ -53,7 +53,10 @@ module NotionRubyMapping
|
|
53
53
|
# @return [NotionRubyMapping::Database, String]
|
54
54
|
# @see https://www.notion.so/hkob/Page-d359650e3ca94424af8359a24147b9a0#e3f1d21e0f724f589e48431468772eed
|
55
55
|
def create_child_database(title, *assigns, dry_run: false)
|
56
|
-
|
56
|
+
db = Database.new json: {"title" => [TextObject.new(title).property_values_json]},
|
57
|
+
assign: assigns, parent: {"type" => "page_id", "page_id" => @id}
|
58
|
+
yield db, db.properties if block_given?
|
59
|
+
db.save dry_run: dry_run
|
57
60
|
end
|
58
61
|
|
59
62
|
# @return [String] title
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotionRubyMapping
|
4
|
+
class Mermaid
|
5
|
+
# @param [String] full_text
|
6
|
+
def initialize(full_text)
|
7
|
+
@lines = full_text.split "\n"
|
8
|
+
@databases = Hash.new {}
|
9
|
+
parse_text
|
10
|
+
end
|
11
|
+
attr_reader :lines, :databases
|
12
|
+
|
13
|
+
def parse_text
|
14
|
+
return unless @lines.shift =~ /^erDiagram/
|
15
|
+
|
16
|
+
until @lines.empty?
|
17
|
+
case @lines.shift
|
18
|
+
when / *(\w+) *[|}][|o]--[o|][|{] *(\w+) *: *"(.*)" */
|
19
|
+
db_or_create(Regexp.last_match(1)).append_relation_queue db_or_create(Regexp.last_match(2)), Regexp.last_match(3)
|
20
|
+
when / *(\w+) *{ */
|
21
|
+
append_db_with_attributes Regexp.last_match(1)
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def db_or_create(db_name)
|
29
|
+
@databases[db_name] ||= MermaidDatabase.new db_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def append_db_with_attributes(db_name)
|
33
|
+
db = db_or_create db_name
|
34
|
+
until @lines.empty?
|
35
|
+
case @lines.shift
|
36
|
+
when /^ *} *$/
|
37
|
+
break
|
38
|
+
when /^ *Database +title +"(.*)" *$/
|
39
|
+
db.name = Regexp.last_match(1)
|
40
|
+
when /^ *([^ ]+) +[^ ]+ +"(.*)" *$/
|
41
|
+
db.add_property Regexp.last_match(1), Regexp.last_match(2)
|
42
|
+
when /^ *([^ ]+) +([^ ]+) *$/
|
43
|
+
db.add_property Regexp.last_match(1), Regexp.last_match(2)
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def attach_database(db)
|
51
|
+
@databases.values.select { |mdb| mdb.name == db.database_title.full_text }.first&.attach_database(db)
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_notion_db(target_page, inline)
|
55
|
+
@databases.each_value do |mdb|
|
56
|
+
mdb.create_notion_db(target_page, inline) unless mdb.real_db
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def update_title
|
61
|
+
@databases.each_value do |mdb|
|
62
|
+
mdb.update_title
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_databases
|
67
|
+
@databases.each_value(&:update_database)
|
68
|
+
end
|
69
|
+
|
70
|
+
def rename_reverse_name
|
71
|
+
@databases.each_value(&:rename_reverse_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def count
|
75
|
+
@databases.values.map(&:count).sum
|
76
|
+
end
|
77
|
+
|
78
|
+
def remain
|
79
|
+
@databases.values.map(&:remain).sum
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
module NotionRubyMapping
|
2
|
+
class MermaidDatabase
|
3
|
+
|
4
|
+
def initialize(key)
|
5
|
+
@key = key
|
6
|
+
@name = key
|
7
|
+
@title = nil
|
8
|
+
@properties = {}
|
9
|
+
@finish_flag = {}
|
10
|
+
@working = []
|
11
|
+
@relations = {}
|
12
|
+
@relation_queue = []
|
13
|
+
@real_db = nil
|
14
|
+
@reverse_name_queue = {}
|
15
|
+
end
|
16
|
+
attr_reader :properties, :relation_queue, :relations, :real_db, :title, :finish_flag
|
17
|
+
attr_accessor :name
|
18
|
+
|
19
|
+
def add_property(key, value)
|
20
|
+
if key == "title"
|
21
|
+
@title = value
|
22
|
+
else
|
23
|
+
@properties[value] = key
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def append_relation_queue(other, relation)
|
28
|
+
@relation_queue << [relation, other]
|
29
|
+
end
|
30
|
+
|
31
|
+
def attach_database(db)
|
32
|
+
@real_db = db
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param [NotionRubyMapping::Page] target_page
|
36
|
+
def create_notion_db(target_page, inline)
|
37
|
+
unless @title
|
38
|
+
print "Database must have a title property"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
@real_db = target_page.create_child_database(@name, TitleProperty, @title) do |d, _|
|
42
|
+
d.is_inline = inline
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def blocked?(name)
|
47
|
+
@finish_flag[name].nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def count
|
51
|
+
@properties.count + @relation_queue.count
|
52
|
+
end
|
53
|
+
|
54
|
+
def remain
|
55
|
+
count - @finish_flag.count
|
56
|
+
end
|
57
|
+
|
58
|
+
def update_title
|
59
|
+
ps = @real_db.properties
|
60
|
+
title_property = ps.select { |p| p.is_a? TitleProperty }.first
|
61
|
+
title_property.new_name = @title unless title_property.name == @title
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_properties
|
65
|
+
ps = @real_db.properties
|
66
|
+
@properties.each do |(value, key)|
|
67
|
+
name, *options = value.split("|")
|
68
|
+
next if @finish_flag[name]
|
69
|
+
|
70
|
+
property = ps.values_at(name).first
|
71
|
+
case key
|
72
|
+
when /checkbox|created_by|created_time|date|email|files|last_edited_by|last_edited_time|people|phone_number|text|url|status/
|
73
|
+
klass = {
|
74
|
+
checkbox: CheckboxProperty, created_by: CreatedByProperty, created_time: CreatedTimeProperty,
|
75
|
+
date: DateProperty, email: EmailProperty, files: FilesProperty, last_edited_by: LastEditedByProperty,
|
76
|
+
last_edited_time: LastEditedTimeProperty, people: PeopleProperty, phone_number: PhoneNumberProperty,
|
77
|
+
rich_text: RichTextProperty, url: UrlProperty, status: StatusProperty
|
78
|
+
}[key.to_sym]
|
79
|
+
@real_db.add_property klass, name unless property
|
80
|
+
@working << name
|
81
|
+
when "formula"
|
82
|
+
f_e = options.first&.gsub "@", '"'
|
83
|
+
dependencies = f_e&.scan(/prop\("([^"]+)"\)/) || []
|
84
|
+
blocked_key = dependencies.select { |k| blocked? k.first }
|
85
|
+
if blocked_key.empty?
|
86
|
+
if property
|
87
|
+
property.formula_expression = f_e unless property.formula_expression == f_e
|
88
|
+
else
|
89
|
+
@real_db.add_property(FormulaProperty, name) { |dp| dp.formula_expression = f_e }
|
90
|
+
end
|
91
|
+
@working << name
|
92
|
+
else
|
93
|
+
print("#{name} blocked by #{blocked_key.flatten}\n")
|
94
|
+
next
|
95
|
+
end
|
96
|
+
|
97
|
+
when "multi_select"
|
98
|
+
if property
|
99
|
+
(options - (property.multi_select_options.map { |h| h["name"] })).each do |select_name|
|
100
|
+
property.add_multi_select_option name: select_name, color: "default"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
@real_db.add_property(MultiSelectProperty, name) do |dp|
|
104
|
+
options.each do |select_name|
|
105
|
+
dp.add_multi_select_option name: select_name, color: "default"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
@working << name
|
110
|
+
when "number"
|
111
|
+
format_value = options.empty? ? "number" : options.first
|
112
|
+
if property
|
113
|
+
property.format = format_value unless property.format == format_value
|
114
|
+
else
|
115
|
+
@real_db.add_property(NumberProperty, name) { |p| p.format = format_value }
|
116
|
+
end
|
117
|
+
@working << name
|
118
|
+
when "rollup"
|
119
|
+
name, *options = value.split("|")
|
120
|
+
relation_name, rollup_name, function = options
|
121
|
+
if blocked? relation_name
|
122
|
+
print("#{name} blocked by #{relation_name}\n")
|
123
|
+
next
|
124
|
+
else
|
125
|
+
relation_db = @relations[relation_name]
|
126
|
+
if relation_db.nil? || relation_db.blocked?(rollup_name)
|
127
|
+
print "#{name} blocked by #{relation_name}-#{rollup_name}\n"
|
128
|
+
next
|
129
|
+
else
|
130
|
+
property = ps.values_at(name).first
|
131
|
+
|
132
|
+
if property
|
133
|
+
property.function = function unless property.function == function
|
134
|
+
property.relation_property_name = relation_name unless property.relation_property_name == relation_name
|
135
|
+
property.rollup_property_name = rollup_name unless property.rollup_property_name == rollup_name
|
136
|
+
else
|
137
|
+
@real_db.add_property(RollupProperty, name) do |dp|
|
138
|
+
dp.function = function
|
139
|
+
dp.relation_property_name = relation_name
|
140
|
+
dp.rollup_property_name = rollup_name
|
141
|
+
end
|
142
|
+
end
|
143
|
+
@working << name
|
144
|
+
end
|
145
|
+
end
|
146
|
+
when "select"
|
147
|
+
if property
|
148
|
+
(options - (property.select_options.map { |h| h["name"] })).each do |select_name|
|
149
|
+
property.add_select_option name: select_name, color: "default"
|
150
|
+
end
|
151
|
+
else
|
152
|
+
@real_db.add_property(SelectProperty, name) do |dp|
|
153
|
+
options.each do |select_name|
|
154
|
+
dp.add_select_option name: select_name, color: "default"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
@working << name
|
159
|
+
else
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
end
|
163
|
+
while (array = @relation_queue.shift) do
|
164
|
+
value, relation_db = array
|
165
|
+
db_id = relation_db.real_db.id
|
166
|
+
forward, reverse = value.split "|"
|
167
|
+
property = ps.values_at(forward).first
|
168
|
+
if property
|
169
|
+
if reverse
|
170
|
+
if property.database_id == db_id && property.synced_property_name == reverse
|
171
|
+
relation_db.add_property "relation", reverse
|
172
|
+
relation_db.finish_flag[reverse] = true
|
173
|
+
else
|
174
|
+
unless @finish_flag[forward]
|
175
|
+
property.replace_relation_database database_id: db_id
|
176
|
+
relation_db.append_reverse_name_queue self, forward, reverse
|
177
|
+
end
|
178
|
+
@working << forward
|
179
|
+
add_property "relation", forward
|
180
|
+
end
|
181
|
+
relation_db.relations[reverse] = self
|
182
|
+
else
|
183
|
+
unless property.database_id == db_id
|
184
|
+
property.replace_relation_database database_id: db_id, type: "single_property"
|
185
|
+
@working << forward
|
186
|
+
add_property "relation", forward
|
187
|
+
end
|
188
|
+
end
|
189
|
+
@relations[forward] = relation_db
|
190
|
+
else
|
191
|
+
@real_db.add_property(RelationProperty, forward) do |p|
|
192
|
+
if reverse
|
193
|
+
p.replace_relation_database database_id: relation_db.real_db.id
|
194
|
+
relation_db.append_reverse_name_queue self, forward, reverse
|
195
|
+
relation_db.relations[reverse] = self
|
196
|
+
else
|
197
|
+
p.replace_relation_database database_id: relation_db.real_db.id, type: "single_property"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
@relations[forward] = relation_db
|
201
|
+
@working << forward
|
202
|
+
add_property "relation", forward
|
203
|
+
end
|
204
|
+
end
|
205
|
+
@real_db.property_schema_json
|
206
|
+
end
|
207
|
+
|
208
|
+
def append_reverse_name_queue(other_db, forward, reverse)
|
209
|
+
@reverse_name_queue[reverse] = [other_db, forward]
|
210
|
+
add_property "relation", reverse
|
211
|
+
end
|
212
|
+
|
213
|
+
def update_database
|
214
|
+
update_properties
|
215
|
+
@real_db.save
|
216
|
+
while (name = @working.shift)
|
217
|
+
@finish_flag[name] = true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def rename_reverse_name
|
222
|
+
save = false
|
223
|
+
reverses = []
|
224
|
+
clears = []
|
225
|
+
@reverse_name_queue.each do |reverse, (other_db, forward)|
|
226
|
+
frp = other_db.real_db.properties[forward]
|
227
|
+
rp_id = frp.synced_property_id
|
228
|
+
rrp = @real_db.properties.filter { |pp| pp.property_id == rp_id }.first
|
229
|
+
if rrp && rrp.name != reverse
|
230
|
+
rrp.new_name = reverse
|
231
|
+
reverses << other_db.real_db
|
232
|
+
clears << rrp
|
233
|
+
save = true
|
234
|
+
end
|
235
|
+
@finish_flag[reverse] = true
|
236
|
+
end
|
237
|
+
if save
|
238
|
+
@real_db.save
|
239
|
+
clears.map(&:clear_will_update)
|
240
|
+
reverses.map(&:reload)
|
241
|
+
end
|
242
|
+
@reverse_name_queue = {}
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -262,6 +262,14 @@ module NotionRubyMapping
|
|
262
262
|
response.body
|
263
263
|
end
|
264
264
|
|
265
|
+
def search(query)
|
266
|
+
request(:post, search_path, options = query)
|
267
|
+
end
|
268
|
+
|
269
|
+
def search_path
|
270
|
+
"v1/search"
|
271
|
+
end
|
272
|
+
|
265
273
|
def update_block_request(block_id, payload)
|
266
274
|
request :patch, block_path(block_id), payload
|
267
275
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module NotionRubyMapping
|
2
|
+
class Search
|
3
|
+
|
4
|
+
def initialize(ascending: false, database_only: false, page_only: false, query: nil)
|
5
|
+
@ascending = ascending
|
6
|
+
@database_only = database_only
|
7
|
+
@page_only = page_only
|
8
|
+
@query = query
|
9
|
+
end
|
10
|
+
|
11
|
+
def exec(dry_run: false)
|
12
|
+
if dry_run
|
13
|
+
Base.dry_run_script :post, NotionCache.instance.search_path, payload
|
14
|
+
else
|
15
|
+
response = NotionCache.instance.search payload
|
16
|
+
List.new json: response, type: :search, value: self, query: Query.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def payload
|
21
|
+
ans = {}
|
22
|
+
ans["sort"] = {"direction" => "ascending", "timestamp" => "last_edited_time"} if @ascending
|
23
|
+
ans["filter"] = {"value" => "database", "property" => "object" } if @database_only
|
24
|
+
ans["filter"] = {"value" => "page", "property" => "object" } if @page_only
|
25
|
+
ans["query"] = @query if @query
|
26
|
+
ans
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -54,12 +54,13 @@ module NotionRubyMapping
|
|
54
54
|
# @param [String] database_id
|
55
55
|
# @param [String] synced_property_name
|
56
56
|
# @see https://www.notion.so/hkob/RelationProperty-f608ab41a1f0476b98456620346fba03#7f5029fb7f6e4c009f22888b233e6f64
|
57
|
-
def replace_relation_database(database_id: nil, type: "dual_property"
|
57
|
+
def replace_relation_database(database_id: nil, type: "dual_property")
|
58
58
|
assert_database_property __method__
|
59
59
|
@will_update = true
|
60
60
|
@json["database_id"] = database_id if database_id
|
61
61
|
@json["type"] = type
|
62
|
-
@json[
|
62
|
+
@json[type] = {}
|
63
|
+
@json.delete type == "dual_property" ? "single_property" : "dual_property"
|
63
64
|
@json
|
64
65
|
end
|
65
66
|
|
@@ -96,6 +97,18 @@ module NotionRubyMapping
|
|
96
97
|
ans
|
97
98
|
end
|
98
99
|
|
100
|
+
def database_id
|
101
|
+
@json["database_id"]
|
102
|
+
end
|
103
|
+
|
104
|
+
def synced_property_id
|
105
|
+
@json["type"] == "dual_property" ? @json["dual_property"]["synced_property_id"] : nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def synced_property_name
|
109
|
+
@json["type"] == "dual_property" ? @json["dual_property"]["synced_property_name"] : nil
|
110
|
+
end
|
111
|
+
|
99
112
|
# @return [Hash] created json
|
100
113
|
def property_values_json
|
101
114
|
assert_page_property __method__
|
@@ -113,7 +126,7 @@ module NotionRubyMapping
|
|
113
126
|
|
114
127
|
# @return [Hash]
|
115
128
|
def property_schema_json_sub
|
116
|
-
|
129
|
+
@json
|
117
130
|
end
|
118
131
|
end
|
119
132
|
end
|
@@ -43,13 +43,13 @@ module NotionRubyMapping
|
|
43
43
|
# @return [FalseClass]
|
44
44
|
def clear_will_update
|
45
45
|
super
|
46
|
-
@text_objects.clear_will_update
|
46
|
+
@text_objects.clear_will_update if page?
|
47
47
|
false
|
48
48
|
end
|
49
49
|
|
50
50
|
# @return [TrueClass, FalseClass] will update?
|
51
51
|
def will_update
|
52
|
-
@will_update || page? && @text_objects.will_update
|
52
|
+
@will_update || (page? && @text_objects.will_update)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/lib/notion_ruby_mapping.rb
CHANGED
@@ -12,7 +12,8 @@ require_relative "notion_ruby_mapping/version"
|
|
12
12
|
link_preview_block link_to_page_block numbered_list_item_block paragraph_block pdf_block quote_block
|
13
13
|
synced_block table_block table_row_block table_of_contents_block template_block to_do_block
|
14
14
|
toggle_block video_block],
|
15
|
-
controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread
|
15
|
+
controllers: %w[notion_cache payload property_cache query rich_text_array discussion_thread search mermaid
|
16
|
+
mermaid_database],
|
16
17
|
objects: %w[rich_text_object emoji_object equation_object file_object mention_object text_object user_object
|
17
18
|
comment_object],
|
18
19
|
properties: %w[property checkbox_property multi_property created_by_property date_base_property created_time_property
|
@@ -32,4 +33,3 @@ module NotionRubyMapping
|
|
32
33
|
end
|
33
34
|
module_function :configure
|
34
35
|
end
|
35
|
-
|
data/notion_ruby_mapping.gemspec
CHANGED
@@ -42,6 +42,7 @@ Gem::Specification.new do |spec|
|
|
42
42
|
spec.add_development_dependency "rake"
|
43
43
|
spec.add_development_dependency "rspec"
|
44
44
|
spec.add_development_dependency "rubocop"
|
45
|
+
spec.add_development_dependency "rubocop-rspec"
|
45
46
|
spec.add_development_dependency "webmock"
|
46
47
|
|
47
48
|
# For more information and examples about making a new gem, check out our
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notion_ruby_mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki KOBAYASHI
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: webmock
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +140,7 @@ description: Mapping tool from Notion Database/Page/Block to Ruby Objects.
|
|
126
140
|
email:
|
127
141
|
- hkob@metro-cit.ac.jp
|
128
142
|
executables:
|
143
|
+
- erdToNotionDb.rb
|
129
144
|
- notionErDiagram.rb
|
130
145
|
- notionSitemap.rb
|
131
146
|
extensions: []
|
@@ -146,6 +161,7 @@ files:
|
|
146
161
|
- examples/change_title.md
|
147
162
|
- examples/renumbering_pages.md
|
148
163
|
- examples/set_icon_to_all_icon_unsettled_pages.md
|
164
|
+
- exe/erdToNotionDb.rb
|
149
165
|
- exe/notionErDiagram.rb
|
150
166
|
- exe/notionSitemap.rb
|
151
167
|
- images/post_set_icon.png
|
@@ -197,11 +213,14 @@ files:
|
|
197
213
|
- lib/notion_ruby_mapping/blocks/url_caption_base_block.rb
|
198
214
|
- lib/notion_ruby_mapping/blocks/video_block.rb
|
199
215
|
- lib/notion_ruby_mapping/controllers/discussion_thread.rb
|
216
|
+
- lib/notion_ruby_mapping/controllers/mermaid.rb
|
217
|
+
- lib/notion_ruby_mapping/controllers/mermaid_database.rb
|
200
218
|
- lib/notion_ruby_mapping/controllers/notion_cache.rb
|
201
219
|
- lib/notion_ruby_mapping/controllers/payload.rb
|
202
220
|
- lib/notion_ruby_mapping/controllers/property_cache.rb
|
203
221
|
- lib/notion_ruby_mapping/controllers/query.rb
|
204
222
|
- lib/notion_ruby_mapping/controllers/rich_text_array.rb
|
223
|
+
- lib/notion_ruby_mapping/controllers/search.rb
|
205
224
|
- lib/notion_ruby_mapping/objects/comment_object.rb
|
206
225
|
- lib/notion_ruby_mapping/objects/emoji_object.rb
|
207
226
|
- lib/notion_ruby_mapping/objects/equation_object.rb
|
@@ -257,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
276
|
- !ruby/object:Gem::Version
|
258
277
|
version: '0'
|
259
278
|
requirements: []
|
260
|
-
rubygems_version: 3.
|
279
|
+
rubygems_version: 3.4.5
|
261
280
|
signing_key:
|
262
281
|
specification_version: 4
|
263
282
|
summary: Notion Ruby mapping tool
|