@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
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
package utility
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
4
8
|
|
|
5
9
|
func prepareBodyUtil(ctx *core.Context) any {
|
|
6
10
|
op := ctx.Op
|
|
@@ -13,5 +17,37 @@ func prepareBodyUtil(ctx *core.Context) any {
|
|
|
13
17
|
return body
|
|
14
18
|
}
|
|
15
19
|
|
|
20
|
+
if fields, ok := vs.GetProp(ctx.Point, "fields").([]any); ok && 0 < len(fields) {
|
|
21
|
+
return matchBody(ctx, fields)
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
return nil
|
|
17
25
|
}
|
|
26
|
+
|
|
27
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
28
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
29
|
+
// cookie or query argument the body does not also declare as a field.
|
|
30
|
+
func matchBody(ctx *core.Context, fields []any) map[string]any {
|
|
31
|
+
routed := []any{}
|
|
32
|
+
if pl, ok := vs.GetProp(ctx.Point, "params").([]any); ok {
|
|
33
|
+
routed = append(routed, pl...)
|
|
34
|
+
}
|
|
35
|
+
for _, kind := range []string{"params", "header", "cookie", "query"} {
|
|
36
|
+
al, _ := vs.GetPath(ctx.Point, []any{"args", kind}).([]any)
|
|
37
|
+
for _, ad := range al {
|
|
38
|
+
if "params" == kind || true != vs.GetProp(ad, "field") {
|
|
39
|
+
routed = append(routed, vs.GetProp(ad, "name"))
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
body := map[string]any{}
|
|
45
|
+
for _, field := range fields {
|
|
46
|
+
name, _ := field.(string)
|
|
47
|
+
val := vs.GetProp(ctx.Reqmatch, name)
|
|
48
|
+
if val != nil && "" != name && "$action" != name && !containsStr(routed, name) {
|
|
49
|
+
body[name] = val
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return body
|
|
53
|
+
}
|
|
@@ -38,7 +38,9 @@ func prepareQueryUtil(ctx *core.Context) map[string]any {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// A header or cookie parameter travels in the headers, which prepareHeaders
|
|
41
|
-
// fills,
|
|
41
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
42
|
+
// prepareBody fills, unless a query parameter shares its name: then both
|
|
43
|
+
// are sent.
|
|
42
44
|
if point != nil {
|
|
43
45
|
declared := map[string]bool{}
|
|
44
46
|
if ql, ok := vs.GetPath(point, []any{"args", "query"}).([]any); ok {
|
|
@@ -62,6 +64,13 @@ func prepareQueryUtil(ctx *core.Context) map[string]any {
|
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
if fl, ok := vs.GetProp(point, "fields").([]any); ok {
|
|
68
|
+
for _, field := range fl {
|
|
69
|
+
if name, ok := field.(string); ok && !declared[name] {
|
|
70
|
+
params = append(params, name)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
// A query parameter travels under the name the definition gives it, its
|
|
@@ -24,6 +24,8 @@ public class Point {
|
|
|
24
24
|
public List<Object> relations;
|
|
25
25
|
public Map<String, Object> alias = new LinkedHashMap<>();
|
|
26
26
|
public Map<String, Object> transform = new LinkedHashMap<>();
|
|
27
|
+
// The fields a list, load or remove sends in a request body.
|
|
28
|
+
public List<Object> fields;
|
|
27
29
|
|
|
28
30
|
public Point(Map<String, Object> pointmap) {
|
|
29
31
|
Object v = Struct.getprop(pointmap, "args");
|
|
@@ -88,5 +90,10 @@ public class Point {
|
|
|
88
90
|
if (v instanceof Map) {
|
|
89
91
|
this.transform = (Map<String, Object>) v;
|
|
90
92
|
}
|
|
93
|
+
|
|
94
|
+
v = Struct.getprop(pointmap, "fields");
|
|
95
|
+
if (v instanceof List) {
|
|
96
|
+
this.fields = (List<Object>) v;
|
|
97
|
+
}
|
|
91
98
|
}
|
|
92
99
|
}
|
|
@@ -68,7 +68,7 @@ final class MakeSpec {
|
|
|
68
68
|
if ("graphql".equals(Struct.getprop(point, "kind", null))) {
|
|
69
69
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
70
70
|
// the body carries the operation. prepareBody is skipped deliberately
|
|
71
|
-
// — it only
|
|
71
|
+
// — it builds only a REST body, whereas every GraphQL op
|
|
72
72
|
// posts one, including load/list/remove.
|
|
73
73
|
ctx.spec.body = utility.graphqlBody.apply(ctx);
|
|
74
74
|
ctx.spec.path = "";
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
package JAVAPACKAGE.utility;
|
|
2
2
|
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
import java.util.LinkedHashMap;
|
|
5
|
+
import java.util.List;
|
|
6
|
+
import java.util.Map;
|
|
7
|
+
|
|
3
8
|
import JAVAPACKAGE.core.Context;
|
|
9
|
+
import JAVAPACKAGE.utility.struct.Struct;
|
|
4
10
|
|
|
5
11
|
final class PrepareBody {
|
|
6
12
|
|
|
@@ -14,6 +20,50 @@ final class PrepareBody {
|
|
|
14
20
|
return ctx.utility.transformRequest.apply(ctx);
|
|
15
21
|
}
|
|
16
22
|
|
|
23
|
+
Object fields = Struct.getprop(ctx.point, "fields");
|
|
24
|
+
if (fields instanceof List && !((List<?>) fields).isEmpty()) {
|
|
25
|
+
return matchBody(ctx, (List<?>) fields);
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
return null;
|
|
18
29
|
}
|
|
30
|
+
|
|
31
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
32
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
33
|
+
// cookie or query argument the body does not also declare as a field.
|
|
34
|
+
private static Map<String, Object> matchBody(Context ctx, List<?> fields) {
|
|
35
|
+
List<Object> routed = new ArrayList<>();
|
|
36
|
+
Object pl = Struct.getprop(ctx.point, "params");
|
|
37
|
+
if (pl instanceof List) {
|
|
38
|
+
routed.addAll((List<?>) pl);
|
|
39
|
+
}
|
|
40
|
+
Object apl = Struct.getpath(ctx.point, List.of("args", "params"));
|
|
41
|
+
if (apl instanceof List) {
|
|
42
|
+
for (Object pd : (List<?>) apl) {
|
|
43
|
+
routed.add(Struct.getprop(pd, "name"));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (String kind : List.of("header", "cookie", "query")) {
|
|
47
|
+
Object defs = Struct.getpath(ctx.point, List.of("args", kind));
|
|
48
|
+
if (defs instanceof List) {
|
|
49
|
+
for (Object ad : (List<?>) defs) {
|
|
50
|
+
if (!Boolean.TRUE.equals(Struct.getprop(ad, "field", null))) {
|
|
51
|
+
routed.add(Struct.getprop(ad, "name"));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Map<String, Object> body = new LinkedHashMap<>();
|
|
58
|
+
for (Object name : fields) {
|
|
59
|
+
if (!(name instanceof String)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
Object val = Struct.getprop(ctx.reqmatch, name, null);
|
|
63
|
+
if (val != null && !"$action".equals(name) && !routed.contains(name)) {
|
|
64
|
+
body.put((String) name, val);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return body;
|
|
68
|
+
}
|
|
19
69
|
}
|
|
@@ -38,7 +38,9 @@ final class PrepareQuery {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
// A header or cookie parameter travels in the headers, which prepareHeaders
|
|
41
|
-
// fills,
|
|
41
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
42
|
+
// prepareBody fills, unless a query parameter shares its name: then both
|
|
43
|
+
// are sent.
|
|
42
44
|
List<Object> declared = new ArrayList<>();
|
|
43
45
|
Object dl = Struct.getpath(point, List.of("args", "query"));
|
|
44
46
|
if (dl instanceof List) {
|
|
@@ -64,6 +66,14 @@ final class PrepareQuery {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
Object fl = Struct.getprop(point, "fields");
|
|
70
|
+
if (fl instanceof List) {
|
|
71
|
+
for (Object name : (List<Object>) fl) {
|
|
72
|
+
if (name instanceof String && !declared.contains(name)) {
|
|
73
|
+
params.add(name);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
// A query parameter travels under the name the definition gives it, its
|
|
@@ -22,6 +22,8 @@ class Point {
|
|
|
22
22
|
this.relations = getprop(altmap, 'relations', [])
|
|
23
23
|
this.alias = getprop(altmap, 'alias', {})
|
|
24
24
|
this.transform = getprop(altmap, 'transform', { req: undefined, res: undefined })
|
|
25
|
+
// The fields a list, load or remove sends in a request body.
|
|
26
|
+
this.fields = getprop(altmap, 'fields')
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -48,7 +48,7 @@ function makeSpec(ctx) {
|
|
|
48
48
|
if ('graphql' === point.kind) {
|
|
49
49
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
50
50
|
// the body carries the operation. prepareBody is skipped deliberately —
|
|
51
|
-
// it only
|
|
51
|
+
// it builds only a REST body, whereas every
|
|
52
52
|
// GraphQL op posts one, including load/list/remove.
|
|
53
53
|
ctx.spec.body = utility.graphqlBody(ctx)
|
|
54
54
|
ctx.spec.path = ''
|
|
@@ -23,6 +23,35 @@ function prepareBody(ctx) {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
else if (ctx.point && Array.isArray(ctx.point.fields) && 0 < ctx.point.fields.length) {
|
|
27
|
+
body = matchBody(ctx)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return body
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
35
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
36
|
+
// cookie or query argument the body does not also declare as a field.
|
|
37
|
+
function matchBody(ctx) {
|
|
38
|
+
const point = ctx.point
|
|
39
|
+
const args = point.args || {}
|
|
40
|
+
const getprop = ctx.utility.struct.getprop
|
|
41
|
+
|
|
42
|
+
const routed = (point.params || [])
|
|
43
|
+
.concat((args.params || []).map((arg) => arg && arg.name))
|
|
44
|
+
.concat(['header', 'cookie', 'query'].flatMap((kind) => (args[kind] || [])
|
|
45
|
+
.filter((arg) => !arg || true !== arg.field).map((arg) => arg && arg.name)))
|
|
46
|
+
|
|
47
|
+
const body = {}
|
|
48
|
+
for (const name of point.fields) {
|
|
49
|
+
const val = getprop(ctx.reqmatch, name)
|
|
50
|
+
if (null != val && '$action' !== name && !routed.includes(name)) {
|
|
51
|
+
body[name] = val
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
return body
|
|
27
56
|
}
|
|
28
57
|
|
|
@@ -31,11 +31,13 @@ function prepareQuery(ctx) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// A header or cookie
|
|
35
|
-
//
|
|
34
|
+
// A header or cookie argument travels in the headers, and a field the point's
|
|
35
|
+
// body declares in the body, unless a query parameter shares its name.
|
|
36
36
|
const elsewhere = ((point.args && point.args.header) || [])
|
|
37
37
|
.concat((point.args && point.args.cookie) || [])
|
|
38
|
-
.map((a) => a && a.name)
|
|
38
|
+
.map((a) => a && a.name)
|
|
39
|
+
.concat(Array.isArray(point.fields) ? point.fields : [])
|
|
40
|
+
.filter((name) => !declared.includes(name))
|
|
39
41
|
|
|
40
42
|
const out = {}
|
|
41
43
|
for (let [key, val] of items(reqmatch)) {
|
|
@@ -19,6 +19,8 @@ class Point(pointmap: Map<String, Any?>?) {
|
|
|
19
19
|
var relations: MutableList<Any?>? = null
|
|
20
20
|
var alias: MutableMap<String, Any?> = linkedMapOf()
|
|
21
21
|
var transform: MutableMap<String, Any?> = linkedMapOf()
|
|
22
|
+
// The fields a list, load or remove sends in a request body.
|
|
23
|
+
var fields: MutableList<Any?>? = null
|
|
22
24
|
|
|
23
25
|
init {
|
|
24
26
|
var v = Struct.getprop(pointmap, "args")
|
|
@@ -81,5 +83,10 @@ class Point(pointmap: Map<String, Any?>?) {
|
|
|
81
83
|
if (v is MutableMap<*, *>) {
|
|
82
84
|
this.transform = v as MutableMap<String, Any?>
|
|
83
85
|
}
|
|
86
|
+
|
|
87
|
+
v = Struct.getprop(pointmap, "fields")
|
|
88
|
+
if (v is MutableList<*>) {
|
|
89
|
+
this.fields = v as MutableList<Any?>
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
92
|
}
|
|
@@ -63,7 +63,7 @@ fun makeSpec(ctx: Context): Spec {
|
|
|
63
63
|
if ("graphql" == Struct.getprop(ctx.point, "kind") as? String) {
|
|
64
64
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
65
65
|
// the body carries the operation. prepareBody is skipped deliberately
|
|
66
|
-
// — it only
|
|
66
|
+
// — it builds only a REST body, whereas every GraphQL op
|
|
67
67
|
// posts one, including load/list/remove.
|
|
68
68
|
spec.body = utility.graphqlBody(ctx)
|
|
69
69
|
spec.path = ""
|
|
@@ -128,9 +128,42 @@ fun prepareBody(ctx: Context): Any? {
|
|
|
128
128
|
}
|
|
129
129
|
return ctx.utility!!.transformRequest(ctx)
|
|
130
130
|
}
|
|
131
|
+
val fields = Struct.getprop(ctx.point, "fields")
|
|
132
|
+
if (fields is List<*> && fields.isNotEmpty()) {
|
|
133
|
+
return matchBody(ctx, fields)
|
|
134
|
+
}
|
|
131
135
|
return null
|
|
132
136
|
}
|
|
133
137
|
|
|
138
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
139
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
140
|
+
// cookie or query argument the body does not also declare as a field.
|
|
141
|
+
private fun matchBody(ctx: Context, fields: List<*>): MutableMap<String, Any?> {
|
|
142
|
+
val point = ctx.point
|
|
143
|
+
val routed = mutableListOf<Any?>()
|
|
144
|
+
(Struct.getprop(point, "params") as? List<*>)?.let { routed.addAll(it) }
|
|
145
|
+
(Struct.getpath(point, listOf("args", "params")) as? List<*>)?.forEach {
|
|
146
|
+
routed.add(Struct.getprop(it, "name"))
|
|
147
|
+
}
|
|
148
|
+
for (kind in listOf("header", "cookie", "query")) {
|
|
149
|
+
(Struct.getpath(point, listOf("args", kind)) as? List<*>)?.forEach {
|
|
150
|
+
if (true != Struct.getprop(it, "field")) routed.add(Struct.getprop(it, "name"))
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
val body = linkedMapOf<String, Any?>()
|
|
155
|
+
for (name in fields) {
|
|
156
|
+
if (name !is String) {
|
|
157
|
+
continue
|
|
158
|
+
}
|
|
159
|
+
val v = Struct.getprop(ctx.reqmatch, name, null)
|
|
160
|
+
if (v != null && "\$action" != name && name !in routed) {
|
|
161
|
+
body[name] = v
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return body
|
|
165
|
+
}
|
|
166
|
+
|
|
134
167
|
@Suppress("UNCHECKED_CAST")
|
|
135
168
|
fun prepareHeaders(ctx: Context): MutableMap<String, Any?> {
|
|
136
169
|
val options = ctx.client!!.optionsMap()
|
|
@@ -272,19 +305,16 @@ fun prepareQuery(ctx: Context): MutableMap<String, Any?> {
|
|
|
272
305
|
}
|
|
273
306
|
}
|
|
274
307
|
// A header or cookie parameter travels in the headers, which prepareHeaders
|
|
275
|
-
// fills,
|
|
308
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
309
|
+
// prepareBody fills, unless a query parameter shares its name: then both
|
|
310
|
+
// are sent.
|
|
276
311
|
val declared = (Struct.getpath(point, listOf("args", "query")) as? List<*>)
|
|
277
312
|
?.map { Struct.getprop(it, "name") } ?: emptyList()
|
|
278
313
|
val located = listOf(Struct.getpath(point, listOf("args", "header")),
|
|
279
|
-
Struct.getpath(point, listOf("args", "cookie")))
|
|
280
|
-
for (
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
val name = Struct.getprop(hd, "name")
|
|
284
|
-
if (name is String && name !in declared) {
|
|
285
|
-
params.add(name)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
314
|
+
Struct.getpath(point, listOf("args", "cookie"))).flatMap { (it as? List<*>) ?: emptyList() }
|
|
315
|
+
for (name in located.map { Struct.getprop(it, "name") } + ((Struct.getprop(point, "fields") as? List<*>) ?: emptyList())) {
|
|
316
|
+
if (name is String && name !in declared) {
|
|
317
|
+
params.add(name)
|
|
288
318
|
}
|
|
289
319
|
}
|
|
290
320
|
}
|
|
@@ -66,7 +66,7 @@ local function make_spec_util(ctx)
|
|
|
66
66
|
if "graphql" == vs.getprop(ctx.point, "kind") then
|
|
67
67
|
-- GraphQL addresses one endpoint: no path parts, no query string, and
|
|
68
68
|
-- the body carries the operation. prepare_body is skipped deliberately
|
|
69
|
-
-- — it only
|
|
69
|
+
-- — it builds only a REST body, whereas every GraphQL op
|
|
70
70
|
-- posts one, including load/list/remove.
|
|
71
71
|
ctx.spec.body = utility.graphql_body(ctx)
|
|
72
72
|
ctx.spec.path = ""
|
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
-- ProjectName SDK utility: prepare_body
|
|
2
2
|
|
|
3
|
+
local vs = require("utility.struct.struct")
|
|
3
4
|
local media = require("utility.media")
|
|
4
5
|
|
|
6
|
+
-- A list, load or remove routed to a method with a body sends the match
|
|
7
|
+
-- fields that body declares, never a path parameter, and never a header,
|
|
8
|
+
-- cookie or query argument the body does not also declare as a field.
|
|
9
|
+
local function match_body(ctx, fields)
|
|
10
|
+
local point = ctx.point
|
|
11
|
+
local routed = {}
|
|
12
|
+
local params = vs.getprop(point, "params")
|
|
13
|
+
if type(params) == "table" then
|
|
14
|
+
for _, name in ipairs(params) do
|
|
15
|
+
routed[name] = true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
for _, kind in ipairs({ "params", "header", "cookie", "query" }) do
|
|
19
|
+
local defs = vs.getpath(point, "args." .. kind)
|
|
20
|
+
if type(defs) == "table" then
|
|
21
|
+
for _, ad in ipairs(defs) do
|
|
22
|
+
local name = vs.getprop(ad, "name")
|
|
23
|
+
if name ~= nil and (kind == "params" or vs.getprop(ad, "field") ~= true) then
|
|
24
|
+
routed[name] = true
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
local body = {}
|
|
31
|
+
for _, name in ipairs(fields) do
|
|
32
|
+
local val = vs.getprop(ctx.reqmatch or {}, name)
|
|
33
|
+
if val ~= nil and name ~= "$action" and not routed[name] then
|
|
34
|
+
body[name] = val
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
return body
|
|
38
|
+
end
|
|
39
|
+
|
|
5
40
|
local function prepare_body_util(ctx)
|
|
6
41
|
local op = ctx.op
|
|
7
42
|
|
|
@@ -13,6 +48,11 @@ local function prepare_body_util(ctx)
|
|
|
13
48
|
return body
|
|
14
49
|
end
|
|
15
50
|
|
|
51
|
+
local fields = ctx.point ~= nil and vs.getprop(ctx.point, "fields") or nil
|
|
52
|
+
if type(fields) == "table" and 0 < #fields then
|
|
53
|
+
return match_body(ctx, fields)
|
|
54
|
+
end
|
|
55
|
+
|
|
16
56
|
return nil
|
|
17
57
|
end
|
|
18
58
|
|
|
@@ -36,7 +36,9 @@ local function prepare_query_util(ctx)
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
-- A header or cookie parameter travels in the headers, which prepare_headers
|
|
39
|
-
-- fills,
|
|
39
|
+
-- fills, and a field the point's body declares travels in the body, which
|
|
40
|
+
-- prepare_body fills, unless a query parameter shares its name: then both
|
|
41
|
+
-- are sent.
|
|
40
42
|
local declared = {}
|
|
41
43
|
local ql = vs.getpath(point, "args.query")
|
|
42
44
|
if type(ql) == "table" then
|
|
@@ -59,6 +61,14 @@ local function prepare_query_util(ctx)
|
|
|
59
61
|
end
|
|
60
62
|
end
|
|
61
63
|
end
|
|
64
|
+
local fields = vs.getprop(point, "fields")
|
|
65
|
+
if type(fields) == "table" then
|
|
66
|
+
for _, name in ipairs(fields) do
|
|
67
|
+
if type(name) == "string" and not declared[name] then
|
|
68
|
+
table.insert(params, name)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
62
72
|
end
|
|
63
73
|
|
|
64
74
|
-- A query parameter travels under the name the definition gives it, its
|
|
@@ -875,8 +875,9 @@ let prepare_query_util (ctx : ctx) : value =
|
|
|
875
875
|
| _ -> []
|
|
876
876
|
in
|
|
877
877
|
(* A header or cookie parameter travels in the headers, which
|
|
878
|
-
* prepare_headers fills,
|
|
879
|
-
*
|
|
878
|
+
* prepare_headers fills, and a field the point's body declares travels in
|
|
879
|
+
* the body, which prepare_body fills, unless a query parameter shares its
|
|
880
|
+
* name: then both are sent. *)
|
|
880
881
|
let declared =
|
|
881
882
|
match getp (getp ctx.c_point "args") "query" with
|
|
882
883
|
| List r -> List.map (fun qd -> getp qd "name") !r
|
|
@@ -892,7 +893,9 @@ let prepare_query_util (ctx : ctx) : value =
|
|
|
892
893
|
| List r -> List.map (fun cd -> getp cd "name") !r
|
|
893
894
|
| _ -> []
|
|
894
895
|
in
|
|
895
|
-
let
|
|
896
|
+
let fields = match getp ctx.c_point "fields" with List r -> !r | _ -> [] in
|
|
897
|
+
let elsewhere =
|
|
898
|
+
List.filter (fun n -> not (List.mem n declared)) (header_names @ cookie_names @ fields) in
|
|
896
899
|
let params = params @ arg_names @ elsewhere in
|
|
897
900
|
let contains_param s = List.exists (fun v -> match v with Str x -> x = s | _ -> false) params in
|
|
898
901
|
(* A query parameter travels under the name the definition gives it, its
|
|
@@ -921,8 +924,40 @@ let prepare_query_util (ctx : ctx) : value =
|
|
|
921
924
|
(call_args ctx "query");
|
|
922
925
|
out
|
|
923
926
|
|
|
927
|
+
(* A list, load or remove routed to a method with a body sends the match
|
|
928
|
+
* fields that body declares, never a path parameter, and never a header,
|
|
929
|
+
* cookie or query argument the body does not also declare as a field. *)
|
|
930
|
+
let match_body (ctx : ctx) (fields : value list) : value =
|
|
931
|
+
let point = ctx.c_point in
|
|
932
|
+
let arg_names kind keep =
|
|
933
|
+
match getp (getp point "args") kind with
|
|
934
|
+
| List r ->
|
|
935
|
+
List.filter_map (fun ad ->
|
|
936
|
+
match getp ad "name" with Str n when keep ad -> Some n | _ -> None) !r
|
|
937
|
+
| _ -> []
|
|
938
|
+
in
|
|
939
|
+
let unkept ad = match getp ad "field" with Bool true -> false | _ -> true in
|
|
940
|
+
let routed =
|
|
941
|
+
(match getp point "params" with
|
|
942
|
+
| List r -> List.filter_map (function Str s -> Some s | _ -> None) !r
|
|
943
|
+
| _ -> [])
|
|
944
|
+
@ arg_names "params" (fun _ -> true)
|
|
945
|
+
@ List.concat_map (fun kind -> arg_names kind unkept) ["header"; "cookie"; "query"]
|
|
946
|
+
in
|
|
947
|
+
let body = empty_map () in
|
|
948
|
+
List.iter (function
|
|
949
|
+
| Str name when name <> "$action" && not (List.mem name routed) ->
|
|
950
|
+
(match getp ctx.c_reqmatch name with
|
|
951
|
+
| Noval | Null -> ()
|
|
952
|
+
| v -> setp body name v)
|
|
953
|
+
| _ -> ()) fields;
|
|
954
|
+
body
|
|
955
|
+
|
|
924
956
|
let prepare_body_util (ctx : ctx) : value =
|
|
925
|
-
if ctx.c_op.op_input <> "data" then
|
|
957
|
+
if ctx.c_op.op_input <> "data" then
|
|
958
|
+
(match getp ctx.c_point "fields" with
|
|
959
|
+
| List { contents = _ :: _ as fields } -> match_body ctx fields
|
|
960
|
+
| _ -> Noval)
|
|
926
961
|
else if is_raw_request ctx.c_point then raw_body ctx.c_reqdata
|
|
927
962
|
else (cu ctx).u_transform_request ctx
|
|
928
963
|
|
|
@@ -1383,7 +1418,7 @@ let make_spec_util (ctx : ctx) : (spec option * sdk_error option) =
|
|
|
1383
1418
|
if get_str_d ctx.c_point "kind" "" = "graphql" then begin
|
|
1384
1419
|
(* GraphQL addresses one endpoint: no path parts, no query string, and
|
|
1385
1420
|
* the body carries the operation. prepare_body is skipped
|
|
1386
|
-
* deliberately — it only
|
|
1421
|
+
* deliberately — it builds only a REST body, whereas
|
|
1387
1422
|
* every GraphQL op posts one, including load/list/remove. *)
|
|
1388
1423
|
sp.sp_body <- u.u_graphql_body ctx;
|
|
1389
1424
|
sp.sp_path <- "";
|
|
@@ -70,7 +70,7 @@ $REGISTRY{make_spec} = sub {
|
|
|
70
70
|
if (defined $pkind && 'graphql' eq $pkind) {
|
|
71
71
|
# GraphQL addresses one endpoint: no path parts, no query string, and
|
|
72
72
|
# the body carries the operation. prepare_body is skipped deliberately
|
|
73
|
-
# — it only
|
|
73
|
+
# — it builds only a REST body, whereas every GraphQL op
|
|
74
74
|
# posts one, including load/list/remove.
|
|
75
75
|
$ctx->{spec}{body} = $utility->{graphql_body}->($ctx);
|
|
76
76
|
$ctx->{spec}{path} = '';
|
|
@@ -8,18 +8,52 @@ use Cwd ();
|
|
|
8
8
|
|
|
9
9
|
my $__dir;
|
|
10
10
|
BEGIN { $__dir = File::Basename::dirname(Cwd::abs_path(__FILE__)) }
|
|
11
|
+
require(Cwd::abs_path("$__dir/../lib/Voxgig/Struct.pm"));
|
|
12
|
+
require(Cwd::abs_path("$__dir/../core/helpers.pm"));
|
|
11
13
|
require(Cwd::abs_path("$__dir/media.pm"));
|
|
12
14
|
|
|
13
15
|
package ProjectNameUtilities;
|
|
14
16
|
|
|
15
17
|
our %REGISTRY;
|
|
16
18
|
|
|
19
|
+
# A list, load or remove routed to a method with a body sends the match
|
|
20
|
+
# fields that body declares, never a path parameter, and never a header,
|
|
21
|
+
# cookie or query argument the body does not also declare as a field.
|
|
22
|
+
my $match_body = sub {
|
|
23
|
+
my ($ctx, $fields) = @_;
|
|
24
|
+
my $point = $ctx->{point};
|
|
25
|
+
my $params = ProjectNameHelpers::gp($point, 'params');
|
|
26
|
+
my %routed = map { defined $_ && !ref $_ ? ($_ => 1) : () }
|
|
27
|
+
Voxgig::Struct::islist($params) ? @$params : ();
|
|
28
|
+
for my $kind (qw(params header cookie query)) {
|
|
29
|
+
my $defs = ProjectNameHelpers::gpath($point, "args.$kind");
|
|
30
|
+
next unless Voxgig::Struct::islist($defs);
|
|
31
|
+
for my $ad (@$defs) {
|
|
32
|
+
next unless 'params' eq $kind || !ProjectNameHelpers::is_true(ProjectNameHelpers::gp($ad, 'field'));
|
|
33
|
+
my $name = ProjectNameHelpers::gp($ad, 'name');
|
|
34
|
+
$routed{$name} = 1 if defined $name && !ref $name;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
my $body = {};
|
|
38
|
+
for my $name (@$fields) {
|
|
39
|
+
next unless defined $name && !ref $name;
|
|
40
|
+
next if '$action' eq $name || $routed{$name};
|
|
41
|
+
my $val = ProjectNameHelpers::gp($ctx->{reqmatch} || {}, $name);
|
|
42
|
+
$body->{$name} = $val if defined $val && !Voxgig::Struct::is_jnull($val);
|
|
43
|
+
}
|
|
44
|
+
return $body;
|
|
45
|
+
};
|
|
46
|
+
|
|
17
47
|
$REGISTRY{prepare_body} = sub {
|
|
18
48
|
my ($ctx) = @_;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
49
|
+
if ('data' eq $ctx->{op}{input}) {
|
|
50
|
+
return ProjectNameUtilities::raw_body($ctx->{reqdata})
|
|
51
|
+
if ProjectNameUtilities::is_raw_request($ctx->{point});
|
|
52
|
+
return $ctx->{utility}{transform_request}->($ctx);
|
|
53
|
+
}
|
|
54
|
+
my $fields = $ctx->{point} ? ProjectNameHelpers::gp($ctx->{point}, 'fields') : undef;
|
|
55
|
+
return undef unless Voxgig::Struct::islist($fields) && @$fields;
|
|
56
|
+
return $match_body->($ctx, $fields);
|
|
23
57
|
};
|
|
24
58
|
|
|
25
59
|
1;
|
|
@@ -34,7 +34,9 @@ $REGISTRY{prepare_query} = sub {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
# A header or cookie parameter travels in the headers, which prepare_headers
|
|
37
|
-
# fills,
|
|
37
|
+
# fills, and a field the point's body declares travels in the body, which
|
|
38
|
+
# prepare_body fills, unless a query parameter shares its name: then both
|
|
39
|
+
# are sent.
|
|
38
40
|
my $ql = ProjectNameHelpers::gpath($point, 'args.query');
|
|
39
41
|
my %declared = Voxgig::Struct::islist($ql)
|
|
40
42
|
? map { my $n = ProjectNameHelpers::gp($_, 'name'); defined $n && !ref $n ? ($n => 1) : () } @$ql
|
|
@@ -47,6 +49,10 @@ $REGISTRY{prepare_query} = sub {
|
|
|
47
49
|
push @$params, $name if defined $name && !ref $name && !$declared{$name};
|
|
48
50
|
}
|
|
49
51
|
}
|
|
52
|
+
my $fields = ProjectNameHelpers::gp($point, 'fields');
|
|
53
|
+
if (Voxgig::Struct::islist($fields)) {
|
|
54
|
+
push @$params, grep { defined $_ && !ref $_ && !$declared{$_} } @$fields;
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
# A query parameter travels under the name the definition gives it, its
|
|
52
58
|
# orig, which the model may have renamed for the caller.
|
|
@@ -65,8 +65,8 @@ class ProjectNameMakeSpec
|
|
|
65
65
|
if ('graphql' === \Voxgig\Struct\Struct::getprop($point, 'kind')) {
|
|
66
66
|
// GraphQL addresses one endpoint: no path parts, no query
|
|
67
67
|
// string, and the body carries the operation. prepare_body is
|
|
68
|
-
// skipped deliberately — it only
|
|
69
|
-
//
|
|
68
|
+
// skipped deliberately — it builds only a REST body,
|
|
69
|
+
// whereas every GraphQL op posts one, including
|
|
70
70
|
// load/list/remove.
|
|
71
71
|
$ctx->spec->body = ($utility->graphql_body)($ctx);
|
|
72
72
|
$ctx->spec->path = '';
|