notion_ruby_mapping 2.0.1 → 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 +16 -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 +42 -7
- data/lib/notion_ruby_mapping/controllers/property_cache.rb +26 -4
- data/lib/notion_ruby_mapping/objects/file_upload_object.rb +1 -1
- 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 +3 -9
- 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
@@ -1,5 +1,5 @@
|
|
1
1
|
module NotionRubyMapping
|
2
|
-
class
|
2
|
+
class MermaidDataSource
|
3
3
|
def initialize(key)
|
4
4
|
@key = key
|
5
5
|
@name = key
|
@@ -9,10 +9,10 @@ module NotionRubyMapping
|
|
9
9
|
@working = []
|
10
10
|
@relations = {}
|
11
11
|
@relation_queue = []
|
12
|
-
@
|
12
|
+
@real_ds = nil
|
13
13
|
@reverse_name_queue = {}
|
14
14
|
end
|
15
|
-
attr_reader :properties, :relation_queue, :relations, :
|
15
|
+
attr_reader :properties, :relation_queue, :relations, :real_ds, :title, :finish_flag
|
16
16
|
attr_accessor :name
|
17
17
|
|
18
18
|
def add_property(key, value)
|
@@ -27,8 +27,8 @@ module NotionRubyMapping
|
|
27
27
|
@relation_queue << [relation, other]
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
@
|
30
|
+
def attach_data_source(ds)
|
31
|
+
@real_ds = ds
|
32
32
|
end
|
33
33
|
|
34
34
|
# @param [NotionRubyMapping::Page] target_page
|
@@ -37,7 +37,7 @@ module NotionRubyMapping
|
|
37
37
|
print "Database must have a title property"
|
38
38
|
exit
|
39
39
|
end
|
40
|
-
@
|
40
|
+
@real_ds = target_page.create_child_database(@name, TitleProperty, @title) do |d, _|
|
41
41
|
d.is_inline = inline
|
42
42
|
end
|
43
43
|
end
|
@@ -55,14 +55,14 @@ module NotionRubyMapping
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def update_title
|
58
|
-
ps = @
|
58
|
+
ps = @real_ds.properties
|
59
59
|
title_property = ps.select { |p| p.is_a? TitleProperty }.first
|
60
60
|
title_property.new_name = @title unless title_property.name == @title
|
61
61
|
@finish_flag[@title] = true
|
62
62
|
end
|
63
63
|
|
64
64
|
def update_properties
|
65
|
-
ps = @
|
65
|
+
ps = @real_ds.properties
|
66
66
|
@properties.each do |(value, key)|
|
67
67
|
name, *options = value.split("|")
|
68
68
|
next if @finish_flag[name]
|
@@ -76,7 +76,7 @@ module NotionRubyMapping
|
|
76
76
|
last_edited_time: LastEditedTimeProperty, people: PeopleProperty, phone_number: PhoneNumberProperty,
|
77
77
|
rich_text: RichTextProperty, url: UrlProperty, status: StatusProperty
|
78
78
|
}[key.to_sym]
|
79
|
-
@
|
79
|
+
@real_ds.add_property klass, name unless property
|
80
80
|
@working << name
|
81
81
|
when "formula"
|
82
82
|
f_e = options.first&.gsub "@", '"'
|
@@ -86,7 +86,7 @@ module NotionRubyMapping
|
|
86
86
|
if property
|
87
87
|
property.formula_expression = f_e unless property.formula_expression == f_e
|
88
88
|
else
|
89
|
-
@
|
89
|
+
@real_ds.add_property(FormulaProperty, name) { |dp| dp.formula_expression = f_e }
|
90
90
|
end
|
91
91
|
@working << name
|
92
92
|
else
|
@@ -100,7 +100,7 @@ module NotionRubyMapping
|
|
100
100
|
property.add_multi_select_option name: select_name, color: "default"
|
101
101
|
end
|
102
102
|
else
|
103
|
-
@
|
103
|
+
@real_ds.add_property(MultiSelectProperty, name) do |dp|
|
104
104
|
options.each do |select_name|
|
105
105
|
dp.add_multi_select_option name: select_name, color: "default"
|
106
106
|
end
|
@@ -112,7 +112,7 @@ module NotionRubyMapping
|
|
112
112
|
if property
|
113
113
|
property.format = format_value unless property.format == format_value
|
114
114
|
else
|
115
|
-
@
|
115
|
+
@real_ds.add_property(NumberProperty, name) { |p| p.format = format_value }
|
116
116
|
end
|
117
117
|
@working << name
|
118
118
|
when "rollup"
|
@@ -134,7 +134,7 @@ module NotionRubyMapping
|
|
134
134
|
property.relation_property_name = relation_name unless property.relation_property_name == relation_name
|
135
135
|
property.rollup_property_name = rollup_name unless property.rollup_property_name == rollup_name
|
136
136
|
else
|
137
|
-
@
|
137
|
+
@real_ds.add_property(RollupProperty, name) do |dp|
|
138
138
|
dp.function = function
|
139
139
|
dp.relation_property_name = relation_name
|
140
140
|
dp.rollup_property_name = rollup_name
|
@@ -149,7 +149,7 @@ module NotionRubyMapping
|
|
149
149
|
property.add_select_option name: select_name, color: "default"
|
150
150
|
end
|
151
151
|
else
|
152
|
-
@
|
152
|
+
@real_ds.add_property(SelectProperty, name) do |dp|
|
153
153
|
options.each do |select_name|
|
154
154
|
dp.add_select_option name: select_name, color: "default"
|
155
155
|
end
|
@@ -159,58 +159,58 @@ module NotionRubyMapping
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
while (array = @relation_queue.shift)
|
162
|
-
value,
|
163
|
-
|
162
|
+
value, relation_ds = array
|
163
|
+
db_is = relation_ds.real_ds.id
|
164
164
|
forward, reverse = value.split("|").map(&:to_s)
|
165
165
|
property = ps.values_at(forward).first
|
166
166
|
if property
|
167
167
|
if reverse
|
168
|
-
if property.
|
169
|
-
|
170
|
-
|
168
|
+
if property.data_source_id == db_is && property.synced_property_name == reverse
|
169
|
+
relation_ds.add_property "relation", reverse
|
170
|
+
relation_ds.finish_flag[reverse] = true
|
171
171
|
else
|
172
172
|
unless @finish_flag[forward]
|
173
|
-
property.
|
174
|
-
|
173
|
+
property.replace_relation_data_source data_source_id: db_is
|
174
|
+
relation_ds.append_reverse_name_queue self, forward, reverse
|
175
175
|
end
|
176
176
|
@working << forward
|
177
177
|
add_property "relation", forward
|
178
178
|
end
|
179
|
-
|
179
|
+
relation_ds.relations[reverse] = self
|
180
180
|
else
|
181
|
-
unless property.
|
182
|
-
property.
|
181
|
+
unless property.data_source_id == db_is
|
182
|
+
property.replace_relation_data_source data_source_id: db_is, type: "single_property"
|
183
183
|
@working << forward
|
184
184
|
add_property "relation", forward
|
185
185
|
end
|
186
186
|
end
|
187
|
-
@relations[forward] =
|
187
|
+
@relations[forward] = relation_ds
|
188
188
|
else
|
189
|
-
@
|
189
|
+
@real_ds.add_property(RelationProperty, forward) do |p|
|
190
190
|
if reverse
|
191
|
-
p.
|
192
|
-
|
193
|
-
|
191
|
+
p.replace_relation_data_source data_source_id: relation_ds.real_ds.id
|
192
|
+
relation_ds.append_reverse_name_queue self, forward, reverse
|
193
|
+
relation_ds.relations[reverse] = self
|
194
194
|
else
|
195
|
-
p.
|
195
|
+
p.replace_relation_data_source data_source_id: relation_ds.real_ds.id, type: "single_property"
|
196
196
|
end
|
197
197
|
end
|
198
|
-
@relations[forward] =
|
198
|
+
@relations[forward] = relation_ds
|
199
199
|
@working << forward
|
200
200
|
add_property "relation", forward
|
201
201
|
end
|
202
202
|
end
|
203
|
-
@
|
203
|
+
@real_ds.property_schema_json
|
204
204
|
end
|
205
205
|
|
206
|
-
def append_reverse_name_queue(
|
207
|
-
@reverse_name_queue[reverse] = [
|
206
|
+
def append_reverse_name_queue(other_ds, forward, reverse)
|
207
|
+
@reverse_name_queue[reverse] = [other_ds, forward]
|
208
208
|
add_property "relation", reverse
|
209
209
|
end
|
210
210
|
|
211
211
|
def update_database
|
212
212
|
update_properties
|
213
|
-
@
|
213
|
+
@real_ds.save
|
214
214
|
while (name = @working.shift)
|
215
215
|
@finish_flag[name] = true
|
216
216
|
end
|
@@ -221,19 +221,19 @@ module NotionRubyMapping
|
|
221
221
|
reverses = []
|
222
222
|
clears = []
|
223
223
|
@reverse_name_queue.each do |reverse, (other_db, forward)|
|
224
|
-
frp = other_db.
|
224
|
+
frp = other_db.real_ds.properties[forward]
|
225
225
|
rp_id = frp.synced_property_id
|
226
|
-
rrp = @
|
226
|
+
rrp = @real_ds.properties.filter { |pp| pp.property_id == rp_id }.first
|
227
227
|
if rrp && rrp.name != reverse
|
228
228
|
rrp.new_name = reverse
|
229
|
-
reverses << other_db.
|
229
|
+
reverses << other_db.real_ds
|
230
230
|
clears << rrp
|
231
231
|
save = true
|
232
232
|
end
|
233
233
|
@finish_flag[reverse] = true
|
234
234
|
end
|
235
235
|
if save
|
236
|
-
@
|
236
|
+
@real_ds.save
|
237
237
|
clears.map(&:clear_will_update)
|
238
238
|
reverses.map(&:reload)
|
239
239
|
end
|
@@ -124,6 +124,12 @@ module NotionRubyMapping
|
|
124
124
|
request :post, databases_path, payload
|
125
125
|
end
|
126
126
|
|
127
|
+
# @param [Hash] payload
|
128
|
+
# @return [Hash] response
|
129
|
+
def create_data_source_request(payload)
|
130
|
+
request :post, data_sources_path, payload
|
131
|
+
end
|
132
|
+
|
127
133
|
# @param [Hash] payload
|
128
134
|
# @return [Hash] response
|
129
135
|
def create_file_upload_request(payload = {})
|
@@ -142,23 +148,35 @@ module NotionRubyMapping
|
|
142
148
|
object_for_key(id) { database_request id }
|
143
149
|
end
|
144
150
|
|
151
|
+
# @param [String] id data_source_id (with or without "-")
|
152
|
+
# @return [NotionRubyMapping::Base] DataSource object or nil
|
153
|
+
def data_source(id)
|
154
|
+
object_for_key(id) { data_source_request id }
|
155
|
+
end
|
156
|
+
|
145
157
|
# @param [String] database_id
|
146
|
-
# @return [String (frozen)]
|
158
|
+
# @return [String (frozen)] database_path
|
147
159
|
def database_path(database_id)
|
148
160
|
"v1/databases/#{database_id}"
|
149
161
|
end
|
150
162
|
|
163
|
+
# @param [String] database_id
|
164
|
+
# @return [String (frozen)] data_source_path
|
165
|
+
def data_source_path(data_source_id)
|
166
|
+
"v1/data_sources/#{data_source_id}"
|
167
|
+
end
|
168
|
+
|
151
169
|
# @param [String] id page_id / block_id (with or without "-")
|
152
170
|
# @param [NotionRubyMapping::Query] query query object
|
153
171
|
# @return [NotionRubyMapping::Base] List object
|
154
172
|
# def database_query(id, query)
|
155
|
-
# Base.create_from_json
|
173
|
+
# Base.create_from_json data_source_query_request(id, query.query_json)
|
156
174
|
# end
|
157
175
|
|
158
|
-
# @param [String]
|
176
|
+
# @param [String] data_source_id (with or without "-")
|
159
177
|
# @param [NotionRubyMapping::Query] query query object
|
160
|
-
def
|
161
|
-
request :post, "v1/
|
178
|
+
def data_source_query_request(data_source_id, query)
|
179
|
+
request :post, "v1/data_sources/#{data_source_id}/query#{query.database_query_string}", query.query_json
|
162
180
|
end
|
163
181
|
|
164
182
|
# @param [String] database_id
|
@@ -167,11 +185,22 @@ module NotionRubyMapping
|
|
167
185
|
request :get, database_path(database_id)
|
168
186
|
end
|
169
187
|
|
188
|
+
# @param [String] data_source_id
|
189
|
+
# @return [Hash] response
|
190
|
+
def data_source_request(data_source_id)
|
191
|
+
request :get, data_source_path(data_source_id)
|
192
|
+
end
|
193
|
+
|
170
194
|
# @return [String (frozen)] page_path
|
171
195
|
def databases_path
|
172
196
|
"v1/databases"
|
173
197
|
end
|
174
198
|
|
199
|
+
# @return [String (frozen)] page_path
|
200
|
+
def data_sources_path
|
201
|
+
"v1/data_sources"
|
202
|
+
end
|
203
|
+
|
175
204
|
# @param [String] id
|
176
205
|
# @return [NotionRubyMapping::Base]
|
177
206
|
def destroy_block(id)
|
@@ -288,8 +317,8 @@ module NotionRubyMapping
|
|
288
317
|
|
289
318
|
# @param [String] database_id
|
290
319
|
# @return [String (frozen)] page_path
|
291
|
-
def
|
292
|
-
"v1/
|
320
|
+
def query_data_source_path(data_source_id)
|
321
|
+
"v1/data_sources/#{data_source_id}/query"
|
293
322
|
end
|
294
323
|
|
295
324
|
# @param [String] block_id
|
@@ -367,6 +396,12 @@ module NotionRubyMapping
|
|
367
396
|
request :patch, database_path(database_id), payload
|
368
397
|
end
|
369
398
|
|
399
|
+
# @param [String] data_source_id
|
400
|
+
# @return [Hash] response
|
401
|
+
def update_data_source_request(data_source_id, payload)
|
402
|
+
request :patch, data_source_path(data_source_id), payload
|
403
|
+
end
|
404
|
+
|
370
405
|
# @param [String] page_id
|
371
406
|
# @param [Hash] payload
|
372
407
|
# @return [Hash] response
|
@@ -11,7 +11,7 @@ module NotionRubyMapping
|
|
11
11
|
@page_id = page_id
|
12
12
|
end
|
13
13
|
attr_writer :json
|
14
|
-
attr_reader :page_id
|
14
|
+
attr_reader :page_id, :base_type
|
15
15
|
|
16
16
|
# @param [String] key
|
17
17
|
# @return [Property] Property for key
|
@@ -33,6 +33,21 @@ module NotionRubyMapping
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# @return [TrueClass, FalseClass] true if database type
|
37
|
+
def database?
|
38
|
+
@base_type == "database"
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [TrueClass, FalseClass] true if data_source type
|
42
|
+
def data_source?
|
43
|
+
@base_type == "data_source"
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [TrueClass, FalseClass] true if database or data_source type
|
47
|
+
def database_or_data_source?
|
48
|
+
%w[database data_source].include? @base_type
|
49
|
+
end
|
50
|
+
|
36
51
|
# @return [Hash, Enumerator]
|
37
52
|
def each(&block)
|
38
53
|
return enum_for(:each) unless block_given?
|
@@ -41,7 +56,7 @@ module NotionRubyMapping
|
|
41
56
|
end
|
42
57
|
|
43
58
|
def generate_all_properties
|
44
|
-
if @json.empty?
|
59
|
+
if @json.nil? || @json.empty?
|
45
60
|
@properties.values
|
46
61
|
else
|
47
62
|
@json.keys.map { |key| self[key] }
|
@@ -52,6 +67,11 @@ module NotionRubyMapping
|
|
52
67
|
"PropertyCache"
|
53
68
|
end
|
54
69
|
|
70
|
+
# @return [TrueClass, FalseClass] true if page type
|
71
|
+
def page?
|
72
|
+
@base_type == "page"
|
73
|
+
end
|
74
|
+
|
55
75
|
# @return [Hash] created property values json
|
56
76
|
def property_values_json
|
57
77
|
@properties.each_with_object({}) do |(_, property), ans|
|
@@ -64,22 +84,24 @@ module NotionRubyMapping
|
|
64
84
|
|
65
85
|
# @return [Hash] created property schema json
|
66
86
|
def property_schema_json
|
67
|
-
@properties.each_with_object({}) do |(_, property), ans|
|
87
|
+
schema = @properties.each_with_object({}) do |(_, property), ans|
|
68
88
|
if property.will_update
|
69
89
|
ans["properties"] ||= {}
|
70
90
|
ans["properties"].merge! property.property_schema_json
|
71
91
|
end
|
72
92
|
end
|
93
|
+
database? ? {"initial_data_source" => schema} : schema
|
73
94
|
end
|
74
95
|
|
75
96
|
# @return [Hash] created update property schema json
|
76
97
|
def update_property_schema_json
|
77
|
-
@properties.each_with_object({}) do |(_, property), ans|
|
98
|
+
schema = @properties.each_with_object({}) do |(_, property), ans|
|
78
99
|
if property.will_update
|
79
100
|
ans["properties"] ||= {}
|
80
101
|
ans["properties"].merge! property.update_property_schema_json
|
81
102
|
end
|
82
103
|
end
|
104
|
+
database? ? {"initial_data_source" => schema} : schema
|
83
105
|
end
|
84
106
|
|
85
107
|
# @param [Array] key
|
@@ -36,7 +36,7 @@ module NotionRubyMapping
|
|
36
36
|
def initialize(name, will_update: false, base_type: "page", property_id: nil, property_cache: nil, json: nil)
|
37
37
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
38
38
|
property_cache: property_cache
|
39
|
-
@json = if
|
39
|
+
@json = if database_or_data_source?
|
40
40
|
json || {}
|
41
41
|
else
|
42
42
|
json || false
|
@@ -26,7 +26,7 @@ module NotionRubyMapping
|
|
26
26
|
property_cache: nil)
|
27
27
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
28
28
|
property_cache: property_cache
|
29
|
-
@json = if
|
29
|
+
@json = if database_or_data_source?
|
30
30
|
json || {}
|
31
31
|
else
|
32
32
|
UserObject.new user_id: user_id, json: json
|
@@ -37,7 +37,7 @@ module NotionRubyMapping
|
|
37
37
|
def update_from_json(json)
|
38
38
|
@will_update = false
|
39
39
|
cb = json["created_by"]
|
40
|
-
@json =
|
40
|
+
@json = database_or_data_source? ? cb : UserObject.new(json: cb)
|
41
41
|
end
|
42
42
|
|
43
43
|
## Page property only methods
|
@@ -25,7 +25,7 @@ module NotionRubyMapping
|
|
25
25
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
26
26
|
property_cache: property_cache
|
27
27
|
@json = json
|
28
|
-
@json ||= {} if
|
28
|
+
@json ||= {} if database_or_data_source?
|
29
29
|
end
|
30
30
|
|
31
31
|
## Page property only methods
|
@@ -102,7 +102,7 @@ module NotionRubyMapping
|
|
102
102
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
103
103
|
property_cache: property_cache
|
104
104
|
@json = json || {}
|
105
|
-
return if
|
105
|
+
return if database_or_data_source?
|
106
106
|
|
107
107
|
@json = json || {}
|
108
108
|
@json["start"] = start_date if start_date
|
@@ -40,7 +40,7 @@ module NotionRubyMapping
|
|
40
40
|
property_cache: nil)
|
41
41
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
42
42
|
property_cache: property_cache
|
43
|
-
if
|
43
|
+
if database_or_data_source?
|
44
44
|
@files = json || {}
|
45
45
|
elsif json
|
46
46
|
@files = json.map { |sub_json| FileObject.new json: sub_json }
|
@@ -68,7 +68,7 @@ module NotionRubyMapping
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def update_from_json(json)
|
71
|
-
return if
|
71
|
+
return if database_or_data_source?
|
72
72
|
|
73
73
|
@files = json["files"].map { |sub_json| FileObject.new json: sub_json }
|
74
74
|
@file_names = json["files"].map { |sub_json| sub_json["name"] }
|
@@ -23,14 +23,14 @@ module NotionRubyMapping
|
|
23
23
|
# @return [String] formula_expression
|
24
24
|
# @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#a24d2a7b99254d2a9226c00153f1d516
|
25
25
|
def formula_expression
|
26
|
-
|
26
|
+
assert_database_or_data_source_property __method__
|
27
27
|
@json["expression"]
|
28
28
|
end
|
29
29
|
|
30
30
|
# @param [String] f_e
|
31
31
|
# @see https://www.notion.so/hkob/FormulaProperty-d6b22ca70822407a9fef0bac8925cd0d#fdb3aaa8d0474440b7ed941673ee13b7
|
32
32
|
def formula_expression=(f_e)
|
33
|
-
|
33
|
+
assert_database_or_data_source_property __method__
|
34
34
|
@will_update = true
|
35
35
|
@json["expression"] = f_e
|
36
36
|
end
|
@@ -46,7 +46,7 @@ module NotionRubyMapping
|
|
46
46
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
47
47
|
property_cache: property_cache
|
48
48
|
@json = json || {}
|
49
|
-
return unless
|
49
|
+
return unless database_or_data_source?
|
50
50
|
|
51
51
|
@json["expression"] = formula if formula
|
52
52
|
end
|
@@ -55,7 +55,7 @@ module NotionRubyMapping
|
|
55
55
|
|
56
56
|
# @return [Hash]
|
57
57
|
def update_property_schema_json
|
58
|
-
|
58
|
+
assert_database_or_data_source_property __method__
|
59
59
|
ans = super
|
60
60
|
return ans if ans != {} || !@will_update
|
61
61
|
|
@@ -27,7 +27,7 @@ module NotionRubyMapping
|
|
27
27
|
property_cache: nil)
|
28
28
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
29
29
|
property_cache: property_cache
|
30
|
-
@json = if
|
30
|
+
@json = if database_or_data_source?
|
31
31
|
json || {}
|
32
32
|
else
|
33
33
|
UserObject.new user_id: user_id, json: json
|
@@ -39,7 +39,7 @@ module NotionRubyMapping
|
|
39
39
|
def update_from_json(json)
|
40
40
|
@will_update = false
|
41
41
|
leb = json["last_edited_by"]
|
42
|
-
@json =
|
42
|
+
@json = database_or_data_source? ? leb : UserObject.new(json: leb)
|
43
43
|
end
|
44
44
|
|
45
45
|
## Page property only methods
|
@@ -25,7 +25,7 @@ module NotionRubyMapping
|
|
25
25
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
26
26
|
property_cache: property_cache
|
27
27
|
@json = json
|
28
|
-
@json ||= {} if
|
28
|
+
@json ||= {} if database_or_data_source?
|
29
29
|
end
|
30
30
|
|
31
31
|
## Page property only methods
|
@@ -32,7 +32,7 @@ module NotionRubyMapping
|
|
32
32
|
|
33
33
|
# @return [Array] copyed multi select options
|
34
34
|
def edit_multi_select_options
|
35
|
-
|
35
|
+
assert_database_or_data_source_property __method__
|
36
36
|
@will_update = true
|
37
37
|
@json["options"] ||= []
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module NotionRubyMapping
|
|
40
40
|
# @return [Array]
|
41
41
|
# @see https://www.notion.so/hkob/MultiSelectProperty-b90bba1c55d540ba97131bb013d4ca74#5ff6ec299cf64049bde2416f61b30fa9
|
42
42
|
def multi_select_options
|
43
|
-
|
43
|
+
assert_data_source_property __method__
|
44
44
|
@json["options"] || []
|
45
45
|
end
|
46
46
|
|
@@ -65,7 +65,7 @@ module NotionRubyMapping
|
|
65
65
|
property_id: nil, property_cache: nil)
|
66
66
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
67
67
|
property_cache: property_cache
|
68
|
-
if
|
68
|
+
if database_or_data_source?
|
69
69
|
@json = json || {"options" => []}
|
70
70
|
else
|
71
71
|
@json = json || []
|
@@ -77,7 +77,7 @@ module NotionRubyMapping
|
|
77
77
|
|
78
78
|
# @return [Hash]
|
79
79
|
def update_property_schema_json
|
80
|
-
|
80
|
+
assert_database_or_data_source_property __method__
|
81
81
|
ans = super
|
82
82
|
return ans if ans != {} || !@will_update
|
83
83
|
|
@@ -23,7 +23,7 @@ module NotionRubyMapping
|
|
23
23
|
# @return [String] new or settled format
|
24
24
|
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#5e3682ed9e124d518f735b236787d7a7
|
25
25
|
def format
|
26
|
-
|
26
|
+
assert_database_or_data_source_property __method__
|
27
27
|
@json["format"]
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ module NotionRubyMapping
|
|
31
31
|
# @return [String] settled format
|
32
32
|
# @see https://www.notion.so/hkob/NumberProperty-964ebc1948074d7ca8340187aa352d40#89695432078643e48307c348e2983456
|
33
33
|
def format=(format)
|
34
|
-
|
34
|
+
assert_database_or_data_source_property __method__
|
35
35
|
@will_update = true
|
36
36
|
@json["format"] = format
|
37
37
|
end
|
@@ -58,7 +58,7 @@ module NotionRubyMapping
|
|
58
58
|
super name, will_update: will_update, base_type: base_type, property_id: property_id,
|
59
59
|
property_cache: property_cache
|
60
60
|
@json = json
|
61
|
-
@json ||= {"format" => format || "number"} if
|
61
|
+
@json ||= {"format" => format || "number"} if database_or_data_source?
|
62
62
|
end
|
63
63
|
|
64
64
|
# @param [Hash] json
|
@@ -73,7 +73,7 @@ module NotionRubyMapping
|
|
73
73
|
|
74
74
|
# @return [Hash]
|
75
75
|
def update_property_schema_json
|
76
|
-
|
76
|
+
assert_database_or_data_source_property __method__
|
77
77
|
ans = super
|
78
78
|
return ans if ans != {} || !@will_update
|
79
79
|
|
@@ -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
|