@voxgig/sdkgen 0.26.1 → 0.28.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.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/model/sdkgen.jsonic +1 -1
- package/package.json +3 -3
- package/project/.sdk/model/feature/log.jsonic +1 -1
- package/project/.sdk/model/feature/test.jsonic +1 -1
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/ts.jsonic +3 -3
- package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
- package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
- package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
- package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
- package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
- package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
- package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
- package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
- package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/Main_ts.ts +4 -4
- package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +14 -6
- package/project/.sdk/src/cmp/ts/Test_ts.ts +2 -0
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +13 -13
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +102 -6
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/tm/go/Makefile +10 -0
- package/project/.sdk/tm/go/core/context.go +267 -0
- package/project/.sdk/tm/go/core/control.go +7 -0
- package/project/.sdk/tm/go/core/error.go +25 -0
- package/project/.sdk/tm/go/core/helpers.go +33 -0
- package/project/.sdk/tm/go/core/operation.go +61 -0
- package/project/.sdk/tm/go/core/response.go +55 -0
- package/project/.sdk/tm/go/core/result.go +73 -0
- package/project/.sdk/tm/go/core/spec.go +97 -0
- package/project/.sdk/tm/go/core/target.go +102 -0
- package/project/.sdk/tm/go/core/types.go +44 -0
- package/project/.sdk/tm/go/core/utility_type.go +54 -0
- package/project/.sdk/tm/go/feature/base_feature.go +40 -0
- package/project/.sdk/tm/go/feature/test_feature.go +196 -0
- package/project/.sdk/tm/go/src/feature/README.md +1 -0
- package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
- package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
- package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
- package/project/.sdk/tm/go/test/exists_test.go +16 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
- package/project/.sdk/tm/go/test/runner_test.go +428 -0
- package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
- package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
- package/project/.sdk/tm/go/utility/clean.go +7 -0
- package/project/.sdk/tm/go/utility/done.go +20 -0
- package/project/.sdk/tm/go/utility/feature_add.go +10 -0
- package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
- package/project/.sdk/tm/go/utility/feature_init.go +30 -0
- package/project/.sdk/tm/go/utility/fetcher.go +102 -0
- package/project/.sdk/tm/go/utility/make_context.go +7 -0
- package/project/.sdk/tm/go/utility/make_error.go +69 -0
- package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
- package/project/.sdk/tm/go/utility/make_options.go +130 -0
- package/project/.sdk/tm/go/utility/make_request.go +59 -0
- package/project/.sdk/tm/go/utility/make_response.go +46 -0
- package/project/.sdk/tm/go/utility/make_result.go +55 -0
- package/project/.sdk/tm/go/utility/make_spec.go +68 -0
- package/project/.sdk/tm/go/utility/make_target.go +95 -0
- package/project/.sdk/tm/go/utility/make_url.go +41 -0
- package/project/.sdk/tm/go/utility/param.go +66 -0
- package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
- package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
- package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
- package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
- package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
- package/project/.sdk/tm/go/utility/register.go +39 -0
- package/project/.sdk/tm/go/utility/result_basic.go +31 -0
- package/project/.sdk/tm/go/utility/result_body.go +17 -0
- package/project/.sdk/tm/go/utility/result_headers.go +22 -0
- package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
- package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
- package/project/.sdk/tm/go/utility/transform_request.go +32 -0
- package/project/.sdk/tm/go/utility/transform_response.go +45 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
- package/project/.sdk/tm/ts/src/Context.ts +144 -0
- package/project/.sdk/tm/ts/src/Control.ts +20 -0
- package/project/.sdk/tm/ts/src/Operation.ts +24 -0
- package/project/.sdk/tm/ts/src/Response.ts +26 -0
- package/project/.sdk/tm/ts/src/Result.ts +30 -0
- package/project/.sdk/tm/ts/src/Spec.ts +40 -0
- package/project/.sdk/tm/ts/src/Target.ts +36 -0
- package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +7 -7
- package/project/.sdk/tm/ts/src/types.ts +15 -205
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +2 -3
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{InitfeatureUtility.ts → FeatureInitUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +5 -3
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +4 -4
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +10 -7
- package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
- package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{ResultUtility.ts → MakeResultUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{SelectionUtility.ts → MakeTargetUtility.ts} +22 -24
- package/project/.sdk/tm/ts/src/utility/{FullurlUtility.ts → MakeUrlUtility.ts} +7 -8
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +21 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +4 -4
- package/project/.sdk/tm/ts/src/utility/{BodyUtility.ts → PrepareBodyUtility.ts} +7 -7
- package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
- package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +11 -6
- package/project/.sdk/tm/ts/src/utility/{ResbodyUtility.ts → ResultBodyUtility.ts} +4 -3
- package/project/.sdk/tm/ts/src/utility/{ResheadersUtility.ts → ResultHeadersUtility.ts} +4 -3
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +10 -7
- package/project/.sdk/tm/ts/src/utility/Utility.ts +47 -62
- package/project/.sdk/tm/ts/test/runner.ts +25 -4
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +386 -175
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/Main.ts +8 -2
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -83
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -61
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -68
- /package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +0 -0
- /package/project/.sdk/tm/ts/src/utility/{ContextUtility.ts → MakeContextUtility.ts} +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
|
|
6
|
+
vs "github.com/voxgig/struct"
|
|
7
|
+
|
|
8
|
+
"GOMODULE/core"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func makeTargetUtil(ctx *core.Context) (map[string]any, error) {
|
|
12
|
+
if ctx.Out["target"] != nil {
|
|
13
|
+
if tm, ok := ctx.Out["target"].(map[string]any); ok {
|
|
14
|
+
ctx.Target = tm
|
|
15
|
+
return tm, nil
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
op := ctx.Op
|
|
20
|
+
options := ctx.Options
|
|
21
|
+
|
|
22
|
+
allowOp, _ := vs.GetPath([]any{"allow", "op"}, options).(string)
|
|
23
|
+
if !strings.Contains(allowOp, op.Name) {
|
|
24
|
+
return nil, ctx.MakeError("target_op_allow",
|
|
25
|
+
"Operation \""+op.Name+
|
|
26
|
+
"\" not allowed by SDK option allow.op value: \""+allowOp+"\"")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if len(op.Targets) == 1 {
|
|
30
|
+
ctx.Target = op.Targets[0]
|
|
31
|
+
} else {
|
|
32
|
+
var reqselector map[string]any
|
|
33
|
+
var selector map[string]any
|
|
34
|
+
|
|
35
|
+
if op.Input == "data" {
|
|
36
|
+
reqselector = ctx.Reqdata
|
|
37
|
+
selector = ctx.Data
|
|
38
|
+
} else {
|
|
39
|
+
reqselector = ctx.Reqmatch
|
|
40
|
+
selector = ctx.Match
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
var target map[string]any
|
|
44
|
+
for i := 0; i < len(op.Targets); i++ {
|
|
45
|
+
target = op.Targets[i]
|
|
46
|
+
selectDef := core.ToMapAny(vs.GetProp(target, "select"))
|
|
47
|
+
found := true
|
|
48
|
+
|
|
49
|
+
if selector != nil && selectDef != nil {
|
|
50
|
+
if exist := vs.GetProp(selectDef, "exist"); exist != nil {
|
|
51
|
+
if existList, ok := exist.([]any); ok {
|
|
52
|
+
for _, ek := range existList {
|
|
53
|
+
existkey, _ := ek.(string)
|
|
54
|
+
rv := vs.GetProp(reqselector, existkey)
|
|
55
|
+
sv := vs.GetProp(selector, existkey)
|
|
56
|
+
if rv == nil && sv == nil {
|
|
57
|
+
found = false
|
|
58
|
+
break
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if found {
|
|
66
|
+
reqAction := vs.GetProp(reqselector, "$action")
|
|
67
|
+
selectAction := vs.GetProp(selectDef, "$action")
|
|
68
|
+
if reqAction != selectAction {
|
|
69
|
+
found = false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if found {
|
|
74
|
+
break
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if reqselector != nil {
|
|
79
|
+
reqAction := vs.GetProp(reqselector, "$action")
|
|
80
|
+
if reqAction != nil && target != nil {
|
|
81
|
+
targetSelect := core.ToMapAny(vs.GetProp(target, "select"))
|
|
82
|
+
targetAction := vs.GetProp(targetSelect, "$action")
|
|
83
|
+
if reqAction != targetAction {
|
|
84
|
+
return nil, ctx.MakeError("target_action_invalid",
|
|
85
|
+
"Operation \""+op.Name+
|
|
86
|
+
"\" action \""+vs.Stringify(reqAction)+"\" is not valid.")
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ctx.Target = target
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return ctx.Target, nil
|
|
95
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"regexp"
|
|
5
|
+
|
|
6
|
+
vs "github.com/voxgig/struct"
|
|
7
|
+
|
|
8
|
+
"GOMODULE/core"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func makeUrlUtil(ctx *core.Context) (string, error) {
|
|
12
|
+
spec := ctx.Spec
|
|
13
|
+
result := ctx.Result
|
|
14
|
+
|
|
15
|
+
if spec == nil {
|
|
16
|
+
return "", ctx.MakeError("url_no_spec",
|
|
17
|
+
"Expected context spec property to be defined.")
|
|
18
|
+
}
|
|
19
|
+
if result == nil {
|
|
20
|
+
return "", ctx.MakeError("url_no_result",
|
|
21
|
+
"Expected context result property to be defined.")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
url := vs.Join([]any{spec.Base, spec.Prefix, spec.Path, spec.Suffix}, "/", true)
|
|
25
|
+
resmatch := map[string]any{}
|
|
26
|
+
|
|
27
|
+
params := spec.Params
|
|
28
|
+
for _, item := range vs.Items(params) {
|
|
29
|
+
key, _ := item[0].(string)
|
|
30
|
+
val := item[1]
|
|
31
|
+
if val != nil {
|
|
32
|
+
re := regexp.MustCompile("\\{" + vs.EscRe(key) + "\\}")
|
|
33
|
+
url = re.ReplaceAllString(url, vs.EscUrl(vs.Stringify(val)))
|
|
34
|
+
resmatch[key] = val
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
result.Resmatch = resmatch
|
|
39
|
+
|
|
40
|
+
return url, nil
|
|
41
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func paramUtil(ctx *core.Context, paramdef any) any {
|
|
10
|
+
target := ctx.Target
|
|
11
|
+
spec := ctx.Spec
|
|
12
|
+
match := ctx.Match
|
|
13
|
+
reqmatch := ctx.Reqmatch
|
|
14
|
+
data := ctx.Data
|
|
15
|
+
reqdata := ctx.Reqdata
|
|
16
|
+
|
|
17
|
+
pt := vs.Typify(paramdef)
|
|
18
|
+
|
|
19
|
+
var key string
|
|
20
|
+
if 0 < (vs.T_string & pt) {
|
|
21
|
+
key, _ = paramdef.(string)
|
|
22
|
+
} else {
|
|
23
|
+
k := vs.GetProp(paramdef, "name")
|
|
24
|
+
key, _ = k.(string)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var akey string
|
|
28
|
+
if target != nil {
|
|
29
|
+
alias := core.ToMapAny(vs.GetProp(target, "alias"))
|
|
30
|
+
if alias != nil {
|
|
31
|
+
if ak := vs.GetProp(alias, key); ak != nil {
|
|
32
|
+
akey, _ = ak.(string)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
val := vs.GetProp(reqmatch, key)
|
|
38
|
+
|
|
39
|
+
if val == nil {
|
|
40
|
+
val = vs.GetProp(match, key)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if val == nil && akey != "" {
|
|
44
|
+
if spec != nil {
|
|
45
|
+
spec.Alias[akey] = key
|
|
46
|
+
}
|
|
47
|
+
val = vs.GetProp(reqmatch, akey)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if val == nil {
|
|
51
|
+
val = vs.GetProp(reqdata, key)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if val == nil {
|
|
55
|
+
val = vs.GetProp(data, key)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if val == nil && akey != "" {
|
|
59
|
+
val = vs.GetProp(reqdata, akey)
|
|
60
|
+
if val == nil {
|
|
61
|
+
val = vs.GetProp(data, akey)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return val
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
const headerAuth = "authorization"
|
|
10
|
+
const optionApikey = "apikey"
|
|
11
|
+
const notFound = "__NOTFOUND__"
|
|
12
|
+
|
|
13
|
+
func prepareAuthUtil(ctx *core.Context) (*core.Spec, error) {
|
|
14
|
+
spec := ctx.Spec
|
|
15
|
+
if spec == nil {
|
|
16
|
+
return nil, ctx.MakeError("auth_no_spec",
|
|
17
|
+
"Expected context spec property to be defined.")
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
headers := spec.Headers
|
|
21
|
+
options := ctx.Client.OptionsMap()
|
|
22
|
+
|
|
23
|
+
apikey := vs.GetProp(options, optionApikey, notFound)
|
|
24
|
+
|
|
25
|
+
if apikeyStr, ok := apikey.(string); ok && apikeyStr == notFound {
|
|
26
|
+
delete(headers, headerAuth)
|
|
27
|
+
} else {
|
|
28
|
+
authPrefix := ""
|
|
29
|
+
if ap := vs.GetPath([]any{"auth", "prefix"}, options); ap != nil {
|
|
30
|
+
authPrefix, _ = ap.(string)
|
|
31
|
+
}
|
|
32
|
+
apikeyVal := ""
|
|
33
|
+
if av, ok := apikey.(string); ok {
|
|
34
|
+
apikeyVal = av
|
|
35
|
+
}
|
|
36
|
+
headers[headerAuth] = authPrefix + " " + apikeyVal
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return spec, nil
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func prepareHeadersUtil(ctx *core.Context) map[string]any {
|
|
10
|
+
options := ctx.Client.OptionsMap()
|
|
11
|
+
|
|
12
|
+
headers := vs.GetProp(options, "headers")
|
|
13
|
+
if headers == nil {
|
|
14
|
+
return map[string]any{}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
out := vs.Clone(headers)
|
|
18
|
+
if om, ok := out.(map[string]any); ok {
|
|
19
|
+
return om
|
|
20
|
+
}
|
|
21
|
+
return map[string]any{}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func prepareMethodUtil(ctx *core.Context) string {
|
|
6
|
+
opname := ctx.Op.Name
|
|
7
|
+
|
|
8
|
+
methodMap := map[string]string{
|
|
9
|
+
"create": "POST",
|
|
10
|
+
"update": "PUT",
|
|
11
|
+
"load": "GET",
|
|
12
|
+
"list": "GET",
|
|
13
|
+
"remove": "DELETE",
|
|
14
|
+
"patch": "PATCH",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if m, ok := methodMap[opname]; ok {
|
|
18
|
+
return m
|
|
19
|
+
}
|
|
20
|
+
return "GET"
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func prepareParamsUtil(ctx *core.Context) map[string]any {
|
|
10
|
+
utility := ctx.Utility
|
|
11
|
+
target := ctx.Target
|
|
12
|
+
|
|
13
|
+
var params []any
|
|
14
|
+
if args := vs.GetProp(target, "args"); args != nil {
|
|
15
|
+
if argsMap, ok := args.(map[string]any); ok {
|
|
16
|
+
if p := vs.GetProp(argsMap, "params"); p != nil {
|
|
17
|
+
if pl, ok := p.([]any); ok {
|
|
18
|
+
params = pl
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if params == nil {
|
|
24
|
+
params = []any{}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
out := map[string]any{}
|
|
28
|
+
for _, pd := range params {
|
|
29
|
+
val := utility.Param(ctx, pd)
|
|
30
|
+
if val != nil {
|
|
31
|
+
if pdm, ok := pd.(map[string]any); ok {
|
|
32
|
+
name, _ := vs.GetProp(pdm, "name").(string)
|
|
33
|
+
if name != "" {
|
|
34
|
+
out[name] = val
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return out
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func preparePathUtil(ctx *core.Context) string {
|
|
10
|
+
target := ctx.Target
|
|
11
|
+
|
|
12
|
+
var parts []any
|
|
13
|
+
if p := vs.GetProp(target, "parts"); p != nil {
|
|
14
|
+
if pl, ok := p.([]any); ok {
|
|
15
|
+
parts = pl
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
path := vs.Join(parts, "/", true)
|
|
20
|
+
return path
|
|
21
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func prepareQueryUtil(ctx *core.Context) map[string]any {
|
|
10
|
+
target := ctx.Target
|
|
11
|
+
reqmatch := ctx.Reqmatch
|
|
12
|
+
if reqmatch == nil {
|
|
13
|
+
reqmatch = map[string]any{}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var params []any
|
|
17
|
+
if target != nil {
|
|
18
|
+
if p := vs.GetProp(target, "params"); p != nil {
|
|
19
|
+
if pl, ok := p.([]any); ok {
|
|
20
|
+
params = pl
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if params == nil {
|
|
25
|
+
params = []any{}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
out := map[string]any{}
|
|
29
|
+
for _, item := range vs.Items(reqmatch) {
|
|
30
|
+
key, _ := item[0].(string)
|
|
31
|
+
val := item[1]
|
|
32
|
+
if val != nil && !containsStr(params, key) {
|
|
33
|
+
out[key] = val
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return out
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func containsStr(list []any, s string) bool {
|
|
41
|
+
for _, v := range list {
|
|
42
|
+
if vs, ok := v.(string); ok && vs == s {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func init() {
|
|
6
|
+
core.UtilityRegistrar = registerAll
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
func registerAll(u *core.Utility) {
|
|
10
|
+
u.Clean = cleanUtil
|
|
11
|
+
u.Done = doneUtil
|
|
12
|
+
u.MakeError = makeErrorUtil
|
|
13
|
+
u.FeatureAdd = featureAddUtil
|
|
14
|
+
u.FeatureHook = featureHookUtil
|
|
15
|
+
u.FeatureInit = featureInitUtil
|
|
16
|
+
u.Fetcher = fetcherUtil
|
|
17
|
+
u.MakeFetchDef = makeFetchDefUtil
|
|
18
|
+
u.MakeContext = makeContextUtil
|
|
19
|
+
u.MakeOptions = makeOptionsUtil
|
|
20
|
+
u.MakeRequest = makeRequestUtil
|
|
21
|
+
u.MakeResponse = makeResponseUtil
|
|
22
|
+
u.MakeResult = makeResultUtil
|
|
23
|
+
u.MakeTarget = makeTargetUtil
|
|
24
|
+
u.MakeSpec = makeSpecUtil
|
|
25
|
+
u.MakeUrl = makeUrlUtil
|
|
26
|
+
u.Param = paramUtil
|
|
27
|
+
u.PrepareAuth = prepareAuthUtil
|
|
28
|
+
u.PrepareBody = prepareBodyUtil
|
|
29
|
+
u.PrepareHeaders = prepareHeadersUtil
|
|
30
|
+
u.PrepareMethod = prepareMethodUtil
|
|
31
|
+
u.PrepareParams = prepareParamsUtil
|
|
32
|
+
u.PreparePath = preparePathUtil
|
|
33
|
+
u.PrepareQuery = prepareQueryUtil
|
|
34
|
+
u.ResultBasic = resultBasicUtil
|
|
35
|
+
u.ResultBody = resultBodyUtil
|
|
36
|
+
u.ResultHeaders = resultHeadersUtil
|
|
37
|
+
u.TransformRequest = transformRequestUtil
|
|
38
|
+
u.TransformResponse = transformResponseUtil
|
|
39
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func resultBasicUtil(ctx *core.Context) *core.Result {
|
|
10
|
+
response := ctx.Response
|
|
11
|
+
result := ctx.Result
|
|
12
|
+
|
|
13
|
+
if result != nil && response != nil {
|
|
14
|
+
result.Status = response.Status
|
|
15
|
+
result.StatusText = response.StatusText
|
|
16
|
+
|
|
17
|
+
if result.Status >= 400 {
|
|
18
|
+
msg := "request: " + fmt.Sprintf("%d", result.Status) + ": " + result.StatusText
|
|
19
|
+
if result.Err != nil {
|
|
20
|
+
prevmsg := result.Err.Error()
|
|
21
|
+
result.Err = ctx.MakeError("request_status", prevmsg+": "+msg)
|
|
22
|
+
} else {
|
|
23
|
+
result.Err = ctx.MakeError("request_status", msg)
|
|
24
|
+
}
|
|
25
|
+
} else if response.Err != nil {
|
|
26
|
+
result.Err = response.Err
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func resultBodyUtil(ctx *core.Context) *core.Result {
|
|
6
|
+
response := ctx.Response
|
|
7
|
+
result := ctx.Result
|
|
8
|
+
|
|
9
|
+
if result != nil {
|
|
10
|
+
if response != nil && response.JsonFunc != nil && response.Body != nil {
|
|
11
|
+
json := response.JsonFunc()
|
|
12
|
+
result.Body = json
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func resultHeadersUtil(ctx *core.Context) *core.Result {
|
|
6
|
+
response := ctx.Response
|
|
7
|
+
result := ctx.Result
|
|
8
|
+
|
|
9
|
+
if result != nil {
|
|
10
|
+
if response != nil && response.Headers != nil {
|
|
11
|
+
if hm, ok := response.Headers.(map[string]any); ok {
|
|
12
|
+
result.Headers = hm
|
|
13
|
+
} else {
|
|
14
|
+
result.Headers = map[string]any{}
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
result.Headers = map[string]any{}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return result
|
|
22
|
+
}
|