@voxgig/sdkgen 4.48.0 → 4.48.1
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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +9 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/tm/c/utility/make_spec.c +1 -1
- package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
- package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
- package/project/.sdk/tm/clojure/src/sdk/core.clj +40 -9
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
- package/project/.sdk/tm/csharp/core/Point.cs +6 -0
- package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
- package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
- package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
- package/project/.sdk/tm/go/core/target.go +8 -0
- package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
- package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
- package/project/.sdk/tm/java/core/Point.java +7 -0
- package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
- package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
- package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
- package/project/.sdk/tm/js/src/Point.js +2 -0
- package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
- package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
- package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
- package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
- package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
- package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
- package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
- package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
- package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
- package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
- package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
- package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
- package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
- package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
- package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
- package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
- package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
- package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
- package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
- package/project/.sdk/tm/scala/core/Point.scala +3 -0
- package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
- package/project/.sdk/tm/ts/src/Point.ts +3 -0
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
- package/project/.sdk/tm/zig/core/utility.zig +47 -4
- package/project/sdkgen-package.json +1 -1
- package/src/utility.ts +12 -1
|
@@ -23,6 +23,37 @@ class ProjectNamePrepareBody
|
|
|
23
23
|
}
|
|
24
24
|
return (is_array($body) && 0 === count($body)) ? null : $body;
|
|
25
25
|
}
|
|
26
|
+
$fields = \Voxgig\Struct\Struct::getprop($ctx->point, 'fields');
|
|
27
|
+
if (is_array($fields) && 0 < count($fields)) {
|
|
28
|
+
return self::matchBody($ctx, $fields);
|
|
29
|
+
}
|
|
26
30
|
return null;
|
|
27
31
|
}
|
|
32
|
+
|
|
33
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
34
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
35
|
+
// cookie or query argument the body does not also declare as a field.
|
|
36
|
+
// With none given it is still a JSON object, which an empty array is not.
|
|
37
|
+
private static function matchBody(ProjectNameContext $ctx, array $fields): array|\stdClass
|
|
38
|
+
{
|
|
39
|
+
$point = $ctx->point;
|
|
40
|
+
$params = \Voxgig\Struct\Struct::getprop($point, 'params');
|
|
41
|
+
$routed = is_array($params) ? $params : [];
|
|
42
|
+
foreach (['params', 'header', 'cookie', 'query'] as $kind) {
|
|
43
|
+
$defs = \Voxgig\Struct\Struct::getpath($point, 'args.' . $kind);
|
|
44
|
+
foreach (is_array($defs) ? $defs : [] as $ad) {
|
|
45
|
+
if ('params' === $kind || true !== \Voxgig\Struct\Struct::getprop($ad, 'field')) {
|
|
46
|
+
$routed[] = \Voxgig\Struct\Struct::getprop($ad, 'name');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
$body = [];
|
|
51
|
+
foreach ($fields as $name) {
|
|
52
|
+
$val = \Voxgig\Struct\Struct::getprop($ctx->reqmatch ?? [], $name);
|
|
53
|
+
if (null !== $val && '$action' !== $name && !in_array($name, $routed, true)) {
|
|
54
|
+
$body[$name] = $val;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return 0 === count($body) ? new \stdClass() : $body;
|
|
58
|
+
}
|
|
28
59
|
}
|
|
@@ -30,8 +30,9 @@ class ProjectNamePrepareQuery
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
// A header or cookie parameter travels in the headers, which
|
|
33
|
-
// prepareHeaders fills,
|
|
34
|
-
//
|
|
33
|
+
// prepareHeaders fills, and a field the point's body declares
|
|
34
|
+
// travels in the body, which prepareBody fills, unless a query
|
|
35
|
+
// parameter shares its name: then both are sent.
|
|
35
36
|
$ql = \Voxgig\Struct\Struct::getpath($point, 'args.query');
|
|
36
37
|
$declared = is_array($ql)
|
|
37
38
|
? array_map(fn($qd) => \Voxgig\Struct\Struct::getprop($qd, 'name'), $ql) : [];
|
|
@@ -46,6 +47,12 @@ class ProjectNamePrepareQuery
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
$fields = \Voxgig\Struct\Struct::getprop($point, 'fields');
|
|
51
|
+
foreach (is_array($fields) ? $fields : [] as $name) {
|
|
52
|
+
if (is_string($name) && !in_array($name, $declared, true)) {
|
|
53
|
+
$params[] = $name;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
// A query parameter travels under the name the definition gives it,
|
|
51
58
|
// its orig, which the model may have renamed for the caller.
|
|
@@ -64,7 +64,7 @@ def make_spec_util(ctx):
|
|
|
64
64
|
if "graphql" == vs.getprop(point, "kind"):
|
|
65
65
|
# GraphQL addresses one endpoint: no path parts, no query string,
|
|
66
66
|
# and the body carries the operation. prepare_body is skipped
|
|
67
|
-
# deliberately — it only
|
|
67
|
+
# deliberately — it builds only a REST body, whereas
|
|
68
68
|
# every GraphQL op posts one, including load/list/remove.
|
|
69
69
|
ctx.spec.body = utility.graphql_body(ctx)
|
|
70
70
|
ctx.spec.path = ""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# ProjectName SDK utility: prepare_body
|
|
2
2
|
|
|
3
|
+
from projectname_sdk.utility.voxgig_struct import voxgig_struct as vs
|
|
3
4
|
from projectname_sdk.utility.media import is_raw_request, raw_body
|
|
4
5
|
|
|
5
6
|
|
|
@@ -12,4 +13,29 @@ def prepare_body_util(ctx):
|
|
|
12
13
|
body = ctx.utility.transform_request(ctx)
|
|
13
14
|
return body
|
|
14
15
|
|
|
16
|
+
fields = vs.getprop(ctx.point, "fields") if ctx.point is not None else None
|
|
17
|
+
if isinstance(fields, list) and 0 < len(fields):
|
|
18
|
+
return _match_body(ctx, fields)
|
|
19
|
+
|
|
15
20
|
return None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# A list, load or remove routed to a method with a body sends the match
|
|
24
|
+
# fields that body declares, never a path parameter, and never a header,
|
|
25
|
+
# cookie or query argument the body does not also declare as a field.
|
|
26
|
+
def _match_body(ctx, fields):
|
|
27
|
+
point = ctx.point
|
|
28
|
+
params = vs.getprop(point, "params")
|
|
29
|
+
routed = list(params) if isinstance(params, list) else []
|
|
30
|
+
for kind in ("params", "header", "cookie", "query"):
|
|
31
|
+
defs = vs.getpath(point, "args." + kind)
|
|
32
|
+
if isinstance(defs, list):
|
|
33
|
+
routed += [vs.getprop(ad, "name") for ad in defs
|
|
34
|
+
if kind == "params" or vs.getprop(ad, "field") is not True]
|
|
35
|
+
|
|
36
|
+
body = {}
|
|
37
|
+
for name in fields:
|
|
38
|
+
val = vs.getprop(ctx.reqmatch or {}, name)
|
|
39
|
+
if val is not None and name != "$action" and name not in routed:
|
|
40
|
+
body[name] = val
|
|
41
|
+
return body
|
|
@@ -31,8 +31,9 @@ def prepare_query_util(ctx):
|
|
|
31
31
|
if isinstance(name, str):
|
|
32
32
|
params.append(name)
|
|
33
33
|
# A header or cookie parameter travels in the headers, which
|
|
34
|
-
# prepare_headers fills,
|
|
35
|
-
#
|
|
34
|
+
# prepare_headers fills, and a field the point's body declares travels
|
|
35
|
+
# in the body, which prepare_body fills, unless a query parameter
|
|
36
|
+
# shares its name: then both are sent.
|
|
36
37
|
ql = vs.getpath(point, "args.query")
|
|
37
38
|
declared = [vs.getprop(qd, "name") for qd in ql] if isinstance(ql, list) else []
|
|
38
39
|
for located in (vs.getpath(point, "args.header"), vs.getpath(point, "args.cookie")):
|
|
@@ -41,6 +42,10 @@ def prepare_query_util(ctx):
|
|
|
41
42
|
name = vs.getprop(hd, "name")
|
|
42
43
|
if isinstance(name, str) and name not in declared:
|
|
43
44
|
params.append(name)
|
|
45
|
+
fields = vs.getprop(point, "fields")
|
|
46
|
+
if isinstance(fields, list):
|
|
47
|
+
params += [name for name in fields
|
|
48
|
+
if isinstance(name, str) and name not in declared]
|
|
44
49
|
|
|
45
50
|
# A query parameter travels under the name the definition gives it, its
|
|
46
51
|
# orig, which the model may have renamed for the caller.
|
|
@@ -45,7 +45,7 @@ module ProjectNameUtilities
|
|
|
45
45
|
if 'graphql' == VoxgigStruct.getprop(point, 'kind')
|
|
46
46
|
# GraphQL addresses one endpoint: no path parts, no query string, and
|
|
47
47
|
# the body carries the operation. prepare_body is skipped
|
|
48
|
-
# deliberately — it only
|
|
48
|
+
# deliberately — it builds only a REST body, whereas
|
|
49
49
|
# every GraphQL op posts one, including load/list/remove.
|
|
50
50
|
ctx.spec.body = utility.graphql_body.call(ctx)
|
|
51
51
|
ctx.spec.path = ''
|
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
# ProjectName SDK utility: prepare_body
|
|
2
|
+
require_relative 'struct/voxgig_struct'
|
|
2
3
|
require_relative 'media'
|
|
3
4
|
module ProjectNameUtilities
|
|
4
5
|
PrepareBody = ->(ctx) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if ctx.op.input == "data"
|
|
7
|
+
return ProjectNameUtilities.raw_body(ctx.reqdata) if ProjectNameUtilities.raw_request?(ctx.point)
|
|
8
|
+
return ctx.utility.transform_request.call(ctx)
|
|
9
|
+
end
|
|
10
|
+
fields = ctx.point ? VoxgigStruct.getprop(ctx.point, "fields") : nil
|
|
11
|
+
return nil unless fields.is_a?(Array) && !fields.empty?
|
|
12
|
+
ProjectNameUtilities.match_body(ctx, fields)
|
|
8
13
|
}
|
|
14
|
+
|
|
15
|
+
# A list, load or remove routed to a method with a body sends the match
|
|
16
|
+
# fields that body declares, never a path parameter, and never a header,
|
|
17
|
+
# cookie or query argument the body does not also declare as a field.
|
|
18
|
+
def self.match_body(ctx, fields)
|
|
19
|
+
point = ctx.point
|
|
20
|
+
params = VoxgigStruct.getprop(point, "params")
|
|
21
|
+
routed = params.is_a?(Array) ? params.dup : []
|
|
22
|
+
["params", "header", "cookie", "query"].each do |kind|
|
|
23
|
+
defs = VoxgigStruct.getpath(point, "args.#{kind}")
|
|
24
|
+
next unless defs.is_a?(Array)
|
|
25
|
+
defs.each do |ad|
|
|
26
|
+
next unless kind == "params" || true != VoxgigStruct.getprop(ad, "field")
|
|
27
|
+
routed << VoxgigStruct.getprop(ad, "name")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
body = {}
|
|
31
|
+
fields.each do |name|
|
|
32
|
+
val = VoxgigStruct.getprop(ctx.reqmatch || {}, name)
|
|
33
|
+
body[name] = val if !val.nil? && name != "$action" && !routed.include?(name)
|
|
34
|
+
end
|
|
35
|
+
body
|
|
36
|
+
end
|
|
9
37
|
end
|
|
@@ -19,7 +19,9 @@ module ProjectNameUtilities
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
# A header or cookie parameter travels in the headers, which prepare_headers
|
|
22
|
-
# fills,
|
|
22
|
+
# fills, and a field the point's body declares travels in the body, which
|
|
23
|
+
# prepare_body fills, unless a query parameter shares its name: then both
|
|
24
|
+
# are sent.
|
|
23
25
|
ql = VoxgigStruct.getpath(point, "args.query")
|
|
24
26
|
declared = ql.is_a?(Array) ? ql.map { |qd| VoxgigStruct.getprop(qd, "name") } : []
|
|
25
27
|
[VoxgigStruct.getpath(point, "args.header"), VoxgigStruct.getpath(point, "args.cookie")].each do |hl|
|
|
@@ -29,6 +31,10 @@ module ProjectNameUtilities
|
|
|
29
31
|
params << name if name.is_a?(String) && !declared.include?(name)
|
|
30
32
|
end
|
|
31
33
|
end
|
|
34
|
+
fields = VoxgigStruct.getprop(point, "fields")
|
|
35
|
+
if fields.is_a?(Array)
|
|
36
|
+
fields.each { |name| params << name if name.is_a?(String) && !declared.include?(name) }
|
|
37
|
+
end
|
|
32
38
|
end
|
|
33
39
|
# A query parameter travels under the name the definition gives it, its
|
|
34
40
|
# orig, which the model may have renamed for the caller.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
use std::rc::Rc;
|
|
2
2
|
|
|
3
3
|
use crate::core::context::Context;
|
|
4
|
+
use crate::core::helpers::{get_bool, get_str, getp, setp};
|
|
4
5
|
use crate::utility::media::{is_raw_request, raw_body};
|
|
5
6
|
use crate::utility::voxgigstruct::Value;
|
|
6
7
|
|
|
@@ -14,5 +15,55 @@ pub fn prepare_body_util(ctx: &Rc<Context>) -> Value {
|
|
|
14
15
|
return crate::utility::transform_request::transform_request_util(ctx);
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
if !point_fields(&ctx.point.borrow()).is_empty() {
|
|
19
|
+
return match_body(ctx);
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
Value::Noval
|
|
18
23
|
}
|
|
24
|
+
|
|
25
|
+
// The names a point lists as its body fields.
|
|
26
|
+
fn point_fields(point: &Value) -> Vec<String> {
|
|
27
|
+
match getp(point, "fields") {
|
|
28
|
+
Value::List(l) => l
|
|
29
|
+
.borrow()
|
|
30
|
+
.iter()
|
|
31
|
+
.filter_map(|v| v.as_str().map(String::from))
|
|
32
|
+
.collect(),
|
|
33
|
+
_ => Vec::new(),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
38
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
39
|
+
// cookie or query argument the body does not also declare as a field.
|
|
40
|
+
fn match_body(ctx: &Rc<Context>) -> Value {
|
|
41
|
+
let point = ctx.point.borrow().clone();
|
|
42
|
+
let args = getp(&point, "args");
|
|
43
|
+
let reqmatch = ctx.reqmatch.borrow().clone();
|
|
44
|
+
|
|
45
|
+
let mut routed: Vec<String> = Vec::new();
|
|
46
|
+
if let Value::List(pl) = getp(&point, "params") {
|
|
47
|
+
routed.extend(pl.borrow().iter().filter_map(|v| v.as_str().map(String::from)));
|
|
48
|
+
}
|
|
49
|
+
for kind in ["params", "header", "cookie", "query"] {
|
|
50
|
+
if let Value::List(al) = getp(&args, kind) {
|
|
51
|
+
for arg in al.borrow().iter() {
|
|
52
|
+
if "params" == kind || Some(true) != get_bool(arg, "field") {
|
|
53
|
+
if let Some(name) = get_str(arg, "name") {
|
|
54
|
+
routed.push(name);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let body = Value::empty_map();
|
|
62
|
+
for name in point_fields(&point) {
|
|
63
|
+
let val = getp(&reqmatch, &name);
|
|
64
|
+
if !val.is_nullish() && "$action" != name && !routed.contains(&name) {
|
|
65
|
+
setp(&body, &name, val);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
body
|
|
69
|
+
}
|
|
@@ -47,11 +47,14 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
// A header or cookie parameter travels in the headers, which prepare_headers
|
|
50
|
-
// fills,
|
|
50
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
51
|
+
// prepare_body fills, unless a query parameter shares its name: then both
|
|
52
|
+
// are sent.
|
|
51
53
|
let aheader = getp(&getp(&point, "args"), "header");
|
|
52
54
|
let acookie = getp(&getp(&point, "args"), "cookie");
|
|
53
55
|
let declared = getp(&getp(&point, "args"), "query");
|
|
54
|
-
let
|
|
56
|
+
let fields = getp(&point, "fields");
|
|
57
|
+
let elsewhere = |key: &str| -> bool {
|
|
55
58
|
if let Value::List(ql) = &declared {
|
|
56
59
|
for qd in ql.borrow().iter() {
|
|
57
60
|
if let Value::Str(s) = getp(qd, "name") {
|
|
@@ -61,6 +64,11 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
if let Value::List(fl) = &fields {
|
|
68
|
+
if fl.borrow().iter().any(|f| f.as_str() == Some(key)) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
for located in [&aheader, &acookie] {
|
|
65
73
|
if let Value::List(hl) = located {
|
|
66
74
|
for hd in hl.borrow().iter() {
|
|
@@ -100,7 +108,7 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
100
108
|
.collect();
|
|
101
109
|
for (key, val) in entries {
|
|
102
110
|
if !val.is_noval() && !val.is_null() && "$action" != key && !contains(&key) && !in_args(&key)
|
|
103
|
-
&& !
|
|
111
|
+
&& !elsewhere(&key)
|
|
104
112
|
{
|
|
105
113
|
setp(&out, &wire_name(&key), val);
|
|
106
114
|
}
|
|
@@ -109,7 +117,7 @@ pub fn prepare_query_util(ctx: &Rc<Context>) -> Value {
|
|
|
109
117
|
|
|
110
118
|
// A create or update passes its query arguments in its data.
|
|
111
119
|
for (name, wire, val) in call_args(ctx, "query") {
|
|
112
|
-
if !val.is_noval() && !val.is_null() && !contains(&name) && !in_args(&name) && !
|
|
120
|
+
if !val.is_noval() && !val.is_null() && !contains(&name) && !in_args(&name) && !elsewhere(&name) {
|
|
113
121
|
setp(&out, &wire, val);
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -18,6 +18,8 @@ class Point(pointmap: JMap[String, Object]) {
|
|
|
18
18
|
var relations: JList[Object] = null
|
|
19
19
|
var alias: JMap[String, Object] = new LinkedHashMap[String, Object]()
|
|
20
20
|
var transform: JMap[String, Object] = new LinkedHashMap[String, Object]()
|
|
21
|
+
// The fields a list, load or remove sends in a request body.
|
|
22
|
+
var fields: JList[Object] = null
|
|
21
23
|
|
|
22
24
|
locally {
|
|
23
25
|
Struct.getprop(pointmap, "args") match { case m: JMap[_, _] => args = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
@@ -41,5 +43,6 @@ class Point(pointmap: JMap[String, Object]) {
|
|
|
41
43
|
Struct.getprop(pointmap, "relations") match { case l: JList[_] => relations = l.asInstanceOf[JList[Object]]; case _ => }
|
|
42
44
|
Struct.getprop(pointmap, "alias") match { case m: JMap[_, _] => alias = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
43
45
|
Struct.getprop(pointmap, "transform") match { case m: JMap[_, _] => transform = m.asInstanceOf[JMap[String, Object]]; case _ => }
|
|
46
|
+
Struct.getprop(pointmap, "fields") match { case l: JList[_] => fields = l.asInstanceOf[JList[Object]]; case _ => }
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -54,7 +54,7 @@ object MakeSpec {
|
|
|
54
54
|
if ("graphql" == pkind) {
|
|
55
55
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
56
56
|
// the body carries the operation. prepareBody is skipped deliberately
|
|
57
|
-
// — it only
|
|
57
|
+
// — it builds only a REST body, whereas every GraphQL op
|
|
58
58
|
// posts one, including load/list/remove.
|
|
59
59
|
ctx.spec.body = utility.graphqlBody(ctx)
|
|
60
60
|
ctx.spec.path = ""
|
|
@@ -80,21 +80,20 @@ object PrepareQuery {
|
|
|
80
80
|
}
|
|
81
81
|
case _ =>
|
|
82
82
|
}
|
|
83
|
-
// A header or cookie name leaves the query
|
|
83
|
+
// A header or cookie name leaves the query for the headers, and a field the point's body
|
|
84
|
+
// declares leaves it for the body, unless a query parameter shares it: then both are sent.
|
|
84
85
|
val declared = new ArrayList[Object]()
|
|
85
86
|
Struct.getpath(point, java.util.List.of("args", "query")) match {
|
|
86
87
|
case l: JList[_] => val dit = l.iterator(); while (dit.hasNext) declared.add(Struct.getprop(dit.next(), "name"))
|
|
87
88
|
case _ =>
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
Struct.getpath(point, java.util.List.of("args", "cookie")))
|
|
91
|
-
case l: JList[_] =>
|
|
92
|
-
|
|
93
|
-
while (hit.hasNext) {
|
|
94
|
-
Struct.getprop(hit.next(), "name") match { case s: String if !declared.contains(s) => params.add(s); case _ => }
|
|
95
|
-
}
|
|
96
|
-
case _ =>
|
|
90
|
+
val located = Seq(Struct.getpath(point, java.util.List.of("args", "header")),
|
|
91
|
+
Struct.getpath(point, java.util.List.of("args", "cookie"))).flatMap {
|
|
92
|
+
case l: JList[_] => l.toArray.toSeq.map(ad => Struct.getprop(ad, "name"))
|
|
93
|
+
case _ => Seq.empty
|
|
97
94
|
}
|
|
95
|
+
val fields = Struct.getprop(point, "fields") match { case l: JList[_] => l.toArray.toSeq; case _ => Seq.empty }
|
|
96
|
+
(located ++ fields).foreach { case s: String if !declared.contains(s) => params.add(s); case _ => }
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
// A query parameter travels under the name the definition gives it, its
|
|
@@ -222,9 +221,51 @@ object PrepareHeaders {
|
|
|
222
221
|
|
|
223
222
|
object PrepareBody {
|
|
224
223
|
def prepareBody(ctx: Context): Object =
|
|
225
|
-
if ("data"
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
if ("data" == ctx.op.input) {
|
|
225
|
+
if (Media.isRawRequest(ctx.point)) Media.rawBody(ctx.reqdata)
|
|
226
|
+
else ctx.utility.transformRequest(ctx)
|
|
227
|
+
}
|
|
228
|
+
else Struct.getprop(ctx.point, "fields") match {
|
|
229
|
+
case fields: JList[_] if !fields.isEmpty => matchBody(ctx, fields)
|
|
230
|
+
case _ => null
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
234
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
235
|
+
// cookie or query argument the body does not also declare as a field.
|
|
236
|
+
private def matchBody(ctx: Context, fields: JList[_]): JMap[String, Object] = {
|
|
237
|
+
val routed = new ArrayList[Object]()
|
|
238
|
+
Struct.getprop(ctx.point, "params") match { case l: JList[_] => routed.addAll(l.asInstanceOf[JList[Object]]); case _ => }
|
|
239
|
+
Struct.getpath(ctx.point, java.util.List.of("args", "params")) match {
|
|
240
|
+
case l: JList[_] =>
|
|
241
|
+
val pit = l.iterator()
|
|
242
|
+
while (pit.hasNext) routed.add(Struct.getprop(pit.next(), "name"))
|
|
243
|
+
case _ =>
|
|
244
|
+
}
|
|
245
|
+
for (kind <- Seq("header", "cookie", "query")) {
|
|
246
|
+
Struct.getpath(ctx.point, java.util.List.of("args", kind)) match {
|
|
247
|
+
case l: JList[_] =>
|
|
248
|
+
val ait = l.iterator()
|
|
249
|
+
while (ait.hasNext) {
|
|
250
|
+
val ad = ait.next()
|
|
251
|
+
if (java.lang.Boolean.TRUE != Struct.getprop(ad, "field")) routed.add(Struct.getprop(ad, "name"))
|
|
252
|
+
}
|
|
253
|
+
case _ =>
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
val body = new LinkedHashMap[String, Object]()
|
|
258
|
+
val fit = fields.iterator()
|
|
259
|
+
while (fit.hasNext) {
|
|
260
|
+
fit.next() match {
|
|
261
|
+
case name: String =>
|
|
262
|
+
val v = Struct.getprop(ctx.reqmatch, name, null)
|
|
263
|
+
if (v != null && "$action" != name && !routed.contains(name)) body.put(name, v)
|
|
264
|
+
case _ =>
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
body
|
|
268
|
+
}
|
|
228
269
|
}
|
|
229
270
|
|
|
230
271
|
// NO `object PrepareAuth` HERE, and its absence is the point.
|
|
@@ -16,6 +16,8 @@ public final class Point {
|
|
|
16
16
|
public var relations: VList? = nil
|
|
17
17
|
public var alias: VMap = VMap()
|
|
18
18
|
public var transform: VMap = VMap()
|
|
19
|
+
// The fields a list, load or remove sends in a request body.
|
|
20
|
+
public var fields: VList? = nil
|
|
19
21
|
|
|
20
22
|
public init(_ pointmap: VMap?) {
|
|
21
23
|
args = VMap()
|
|
@@ -35,5 +37,6 @@ public final class Point {
|
|
|
35
37
|
if let rl = getprop(pm, .string("relations")).asList { relations = rl }
|
|
36
38
|
if let al = getprop(pm, .string("alias")).asMap { alias = al }
|
|
37
39
|
if let tf = getprop(pm, .string("transform")).asMap { transform = tf }
|
|
40
|
+
if let fl = getprop(pm, .string("fields")).asList { fields = fl }
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -226,7 +226,7 @@ func makeSpecUtil(_ ctx: Context) throws -> Spec {
|
|
|
226
226
|
if "graphql" == gp(ctx.point, "kind").asString {
|
|
227
227
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
228
228
|
// the body carries the operation. prepareBody is skipped deliberately —
|
|
229
|
-
// it only
|
|
229
|
+
// it builds only a REST body, whereas every GraphQL op
|
|
230
230
|
// posts one, including load/list/remove.
|
|
231
231
|
ctx.spec!.body = utility.graphqlBody(ctx)
|
|
232
232
|
ctx.spec!.path = ""
|
|
@@ -148,7 +148,9 @@ func prepareQueryUtil(_ ctx: Context) -> VMap {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
// A header or cookie parameter travels in the headers, which prepareHeaders
|
|
151
|
-
// fills,
|
|
151
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
152
|
+
// prepareBody fills, unless a query parameter shares its name: then both
|
|
153
|
+
// are sent.
|
|
152
154
|
var declared: [Value] = []
|
|
153
155
|
if let dql = gpath(ctx.point, "args", "query").asList {
|
|
154
156
|
for qd in dql.items {
|
|
@@ -164,6 +166,11 @@ func prepareQueryUtil(_ ctx: Context) -> VMap {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
169
|
+
for name in gp(ctx.point, "fields").asList?.items ?? [] {
|
|
170
|
+
if let s = name.asString, !containsStr(declared, s) {
|
|
171
|
+
paramnames.append(name)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
167
174
|
|
|
168
175
|
// A query parameter travels under the name the definition gives it, its
|
|
169
176
|
// orig, which the model may have renamed for the caller.
|
|
@@ -202,9 +209,37 @@ func prepareBodyUtil(_ ctx: Context) -> Value {
|
|
|
202
209
|
if isRawRequest(ctx.point) { return rawBodyOf(ctx.reqdata) }
|
|
203
210
|
return ctx.utility!.transformRequest(ctx)
|
|
204
211
|
}
|
|
212
|
+
if let fields = gp(ctx.point, "fields").asList, !fields.items.isEmpty {
|
|
213
|
+
return .map(matchBody(ctx, fields))
|
|
214
|
+
}
|
|
205
215
|
return .noval
|
|
206
216
|
}
|
|
207
217
|
|
|
218
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
219
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
220
|
+
// cookie or query argument the body does not also declare as a field.
|
|
221
|
+
private func matchBody(_ ctx: Context, _ fields: VList) -> VMap {
|
|
222
|
+
var routed: [Value] = gp(ctx.point, "params").asList?.items ?? []
|
|
223
|
+
for pd in gpath(ctx.point, "args", "params").asList?.items ?? [] {
|
|
224
|
+
routed.append(gp(pd, "name"))
|
|
225
|
+
}
|
|
226
|
+
for kind in ["header", "cookie", "query"] {
|
|
227
|
+
for ad in gpath(ctx.point, "args", kind).asList?.items ?? [] where gp(ad, "field").asBool != true {
|
|
228
|
+
routed.append(gp(ad, "name"))
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let body = VMap()
|
|
233
|
+
for field in fields.items {
|
|
234
|
+
guard let name = field.asString else { continue }
|
|
235
|
+
let val = gp(ctx.reqmatch, name)
|
|
236
|
+
if !isNil(val) && "$action" != name && !containsStr(routed, name) {
|
|
237
|
+
body.entries[name] = val
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return body
|
|
241
|
+
}
|
|
242
|
+
|
|
208
243
|
// prepareAuth IS NOT HERE. It was, and it hardcoded
|
|
209
244
|
//
|
|
210
245
|
// private let headerAuth = "authorization"
|
|
@@ -19,6 +19,8 @@ class Point {
|
|
|
19
19
|
relations: any[]
|
|
20
20
|
alias: Record<string, string>
|
|
21
21
|
transform: { req: any, res: any }
|
|
22
|
+
// The fields a list, load or remove sends in a request body.
|
|
23
|
+
fields?: string[]
|
|
22
24
|
|
|
23
25
|
constructor(altmap: Record<string, any>) {
|
|
24
26
|
this.args = getprop(altmap, 'args', { params: [] })
|
|
@@ -36,6 +38,7 @@ class Point {
|
|
|
36
38
|
this.relations = getprop(altmap, 'relations', [])
|
|
37
39
|
this.alias = getprop(altmap, 'alias', {})
|
|
38
40
|
this.transform = getprop(altmap, 'transform', { req: undefined, res: undefined })
|
|
41
|
+
this.fields = getprop(altmap, 'fields')
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -26,6 +26,35 @@ function prepareBody(ctx: Context) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
else if (0 < (ctx.point?.fields?.length ?? 0)) {
|
|
30
|
+
body = matchBody(ctx)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return body
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
38
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
39
|
+
// cookie or query argument the body does not also declare as a field.
|
|
40
|
+
function matchBody(ctx: Context): Record<string, any> {
|
|
41
|
+
const point: any = ctx.point
|
|
42
|
+
const args = point.args || {}
|
|
43
|
+
const getprop = ctx.utility.struct.getprop
|
|
44
|
+
|
|
45
|
+
const routed: string[] = (point.params || [])
|
|
46
|
+
.concat((args.params || []).map((arg: any) => arg?.name))
|
|
47
|
+
.concat(['header', 'cookie', 'query'].flatMap((kind) => (args[kind] || [])
|
|
48
|
+
.filter((arg: any) => true !== arg?.field).map((arg: any) => arg?.name)))
|
|
49
|
+
|
|
50
|
+
const body: Record<string, any> = {}
|
|
51
|
+
for (const name of point.fields || []) {
|
|
52
|
+
const val = getprop(ctx.reqmatch, name)
|
|
53
|
+
if (null != val && '$action' !== name && !routed.includes(name)) {
|
|
54
|
+
body[name] = val
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
29
58
|
return body
|
|
30
59
|
}
|
|
31
60
|
|
|
@@ -34,10 +34,12 @@ function prepareQuery(ctx: Context) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
// A header or cookie
|
|
38
|
-
//
|
|
37
|
+
// A header or cookie argument travels in the headers, and a field the point's
|
|
38
|
+
// body declares in the body, unless a query parameter shares its name.
|
|
39
39
|
const elsewhere: string[] = (point.args?.header || []).concat(point.args?.cookie || [])
|
|
40
|
-
.map((a: any) => a?.name)
|
|
40
|
+
.map((a: any) => a?.name)
|
|
41
|
+
.concat(Array.isArray(point.fields) ? point.fields : [])
|
|
42
|
+
.filter((name: string) => !declared.includes(name))
|
|
41
43
|
|
|
42
44
|
const out: any = {}
|
|
43
45
|
for (let [key, val] of items(reqmatch)) {
|