@@ -21,7 +21,7 @@ local gen_arguments = {}
21
21
--- key (and, then, offset) type
22
22
---
23
23
--- @treturn table `offset_type` is a record in case of compound (multi-part)
24
- --- primary key
24
+ --- primary key (is not nil)
25
25
local function get_primary_key_type (db_schema , collection_name )
26
26
-- get name of field of primary key
27
27
local _ , index_meta = db_schema_helpers .get_primary_index_meta (
@@ -47,10 +47,12 @@ local function get_primary_key_type(db_schema, collection_name)
47
47
assert (type (field_type ) == ' string' ,
48
48
' field type must be a string, got ' ..
49
49
type (field_type ))
50
- offset_fields [# offset_fields + 1 ] = {
51
- name = field_name ,
52
- type = field_type ,
53
- }
50
+ if field_type ~= nil then
51
+ offset_fields [# offset_fields + 1 ] = {
52
+ name = field_name ,
53
+ type = field_type ,
54
+ }
55
+ end
54
56
end
55
57
56
58
local offset_type
79
81
---
80
82
--- @tparam [opt] function skip_cond
81
83
---
82
- --- @return transformed avro-schema or nil (when mathed by skip_cond )
84
+ --- @return transformed avro-schema or nil (when the type or all its fields are
85
+ --- matched by skip_cond)
83
86
local function recursive_nullable (e_schema , skip_cond )
84
87
local avro_t = avro_helpers .avro_type (e_schema )
85
88
@@ -103,6 +106,7 @@ local function recursive_nullable(e_schema, skip_cond)
103
106
end
104
107
end
105
108
109
+ if # res .fields == 0 then return nil end
106
110
return res
107
111
elseif avro_t == ' union' or
108
112
avro_t == ' array' or avro_t == ' array*' or
121
125
---
122
126
--- @param e_schema (table or string ) avro-schema with expanded references
123
127
---
124
- --- @return transformed avro-schema
128
+ --- @return transformed avro-schema or nil ( empty fields case )
125
129
local function recursive_replace_default_with_nullable (e_schema )
126
130
local avro_t = avro_helpers .avro_type (e_schema )
127
131
@@ -142,6 +146,7 @@ local function recursive_replace_default_with_nullable(e_schema)
142
146
table.insert (res .fields , field )
143
147
end
144
148
149
+ if # res .fields == 0 then return nil end
145
150
return res
146
151
elseif avro_t == ' union' then
147
152
local res = {}
@@ -152,14 +157,17 @@ local function recursive_replace_default_with_nullable(e_schema)
152
157
table.insert (res , new_child_type )
153
158
end
154
159
160
+ if # res == 0 then return nil end
155
161
return res
156
162
elseif avro_t == ' array' or avro_t == ' array*' then
157
163
local res = table .copy (e_schema )
158
164
res .items = recursive_replace_default_with_nullable (e_schema .items )
165
+ if res .items == nil then return nil end
159
166
return res
160
167
elseif avro_t == ' map' or avro_t == ' map*' then
161
168
local res = table .copy (e_schema )
162
169
res .values = recursive_replace_default_with_nullable (e_schema .values )
170
+ if res .values == nil then return nil end
163
171
return res
164
172
end
165
173
@@ -223,6 +231,7 @@ local function get_pcre_argument_type(db_schema, collection_name)
223
231
return is_non_string_scalar or is_non_record_compound
224
232
225
233
end )
234
+ if res == nil then return nil end
226
235
res .name = collection_name .. ' _pcre'
227
236
return res
228
237
end
@@ -268,10 +277,14 @@ local function get_update_argument_type(db_schema, collection_name)
268
277
if not is_field_part_of_primary_key then
269
278
local field = table .copy (field )
270
279
field .type = recursive_nullable (field .type )
271
- table.insert (schema_update .fields , field )
280
+ if field .type ~= nil then
281
+ table.insert (schema_update .fields , field )
282
+ end
272
283
end
273
284
end
274
285
286
+ if schema_update .fields == nil then return nil end
287
+
275
288
return schema_update
276
289
end
277
290
@@ -303,6 +316,9 @@ function gen_arguments.object_args(db_schema, collection_name)
303
316
and (avro_t ~= ' record' and avro_t ~= ' record*' )
304
317
return is_non_comparable_scalar or is_non_record_compound
305
318
end )
319
+
320
+ if res == nil then return {} end
321
+
306
322
return res .fields
307
323
end
308
324
@@ -324,7 +340,9 @@ function gen_arguments.list_args(db_schema, collection_name)
324
340
local pcre_field
325
341
if rex ~= nil then
326
342
local pcre_type = get_pcre_argument_type (db_schema , collection_name )
327
- pcre_field = {name = ' pcre' , type = pcre_type }
343
+ if pcre_type ~= nil then
344
+ pcre_field = {name = ' pcre' , type = pcre_type }
345
+ end
328
346
end
329
347
330
348
return {
@@ -374,30 +392,42 @@ function gen_arguments.extra_args(db_schema, collection_name, opts)
374
392
local e_schema = db_schema .e_schemas [schema_name ]
375
393
376
394
local schema_insert = recursive_replace_default_with_nullable (e_schema )
377
- schema_insert .name = collection_name .. ' _insert'
378
- schema_insert .type = ' record*' -- make the record nullable
395
+ if schema_insert ~= nil then
396
+ schema_insert .name = collection_name .. ' _insert'
397
+ schema_insert .type = ' record*' -- make the record nullable
398
+ end
379
399
380
400
local schema_update = get_update_argument_type (db_schema , collection_name )
381
401
local schema_delete = ' boolean*'
382
402
383
- return {
384
- { name = ' insert ' , type = schema_insert },
385
- { name = ' update ' , type = schema_update },
386
- { name = ' delete ' , type = schema_delete },
387
- } , {
388
- insert = {
403
+ local args = {}
404
+ local args_meta = {}
405
+
406
+ if schema_insert ~= nil then
407
+ table.insert ( args , {name = ' insert ' , type = schema_insert })
408
+ args_meta . insert = {
389
409
add_to_mutations_only = true ,
390
410
add_to_top_fields_only = true ,
391
- },
392
- update = {
411
+ }
412
+ end
413
+
414
+ if schema_update ~= nil then
415
+ table.insert (args , {name = ' update' , type = schema_update })
416
+ args_meta .update = {
393
417
add_to_mutations_only = true ,
394
418
add_to_top_fields_only = false ,
395
- },
396
- delete = {
419
+ }
420
+ end
421
+
422
+ if schema_delete ~= nil then
423
+ table.insert (args , {name = ' delete' , type = schema_delete })
424
+ args_meta .delete = {
397
425
add_to_mutations_only = true ,
398
426
add_to_top_fields_only = false ,
399
- },
400
- }
427
+ }
428
+ end
429
+
430
+ return args , args_meta
401
431
end
402
432
403
433
return gen_arguments
0 commit comments