@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,20 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func doneUtil(ctx *core.Context) (any, error) {
|
|
6
|
+
if ctx.Ctrl.Explain != nil {
|
|
7
|
+
ctx.Ctrl.Explain = cleanUtil(ctx, ctx.Ctrl.Explain).(map[string]any)
|
|
8
|
+
if explainResult, ok := ctx.Ctrl.Explain["result"]; ok {
|
|
9
|
+
if rm, ok := explainResult.(map[string]any); ok {
|
|
10
|
+
delete(rm, "err")
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if ctx.Result != nil && ctx.Result.Ok {
|
|
16
|
+
return ctx.Result.Resdata, nil
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return makeErrorUtil(ctx, nil)
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"reflect"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func featureHookUtil(ctx *core.Context, name string) {
|
|
10
|
+
client := ctx.Client
|
|
11
|
+
if client == nil {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
features := client.Features
|
|
15
|
+
if features == nil {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
for _, f := range features {
|
|
20
|
+
callFeatureMethod(f, name, ctx)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func callFeatureMethod(f core.Feature, name string, ctx *core.Context) {
|
|
25
|
+
v := reflect.ValueOf(f)
|
|
26
|
+
m := v.MethodByName(name)
|
|
27
|
+
if m.IsValid() {
|
|
28
|
+
m.Call([]reflect.Value{reflect.ValueOf(ctx)})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func featureInitUtil(ctx *core.Context, f core.Feature) {
|
|
10
|
+
fname := f.GetName()
|
|
11
|
+
fopts := map[string]any{}
|
|
12
|
+
|
|
13
|
+
if ctx.Options != nil {
|
|
14
|
+
if featureOpts := vs.GetProp(ctx.Options, "feature"); featureOpts != nil {
|
|
15
|
+
if fm, ok := featureOpts.(map[string]any); ok {
|
|
16
|
+
if fo := vs.GetProp(fm, fname); fo != nil {
|
|
17
|
+
if fom, ok := fo.(map[string]any); ok {
|
|
18
|
+
fopts = fom
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if active, ok := fopts["active"]; ok {
|
|
26
|
+
if ab, ok := active.(bool); ok && ab {
|
|
27
|
+
f.Init(ctx, fopts)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"encoding/json"
|
|
5
|
+
"io"
|
|
6
|
+
"net/http"
|
|
7
|
+
"strings"
|
|
8
|
+
|
|
9
|
+
vs "github.com/voxgig/struct"
|
|
10
|
+
|
|
11
|
+
"GOMODULE/core"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
func defaultHTTPFetch(fullurl string, fetchdef map[string]any) (map[string]any, error) {
|
|
15
|
+
method, _ := fetchdef["method"].(string)
|
|
16
|
+
if method == "" {
|
|
17
|
+
method = "GET"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var bodyReader io.Reader
|
|
21
|
+
if body, ok := fetchdef["body"].(string); ok && body != "" {
|
|
22
|
+
bodyReader = strings.NewReader(body)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
req, err := http.NewRequest(method, fullurl, bodyReader)
|
|
26
|
+
if err != nil {
|
|
27
|
+
return nil, err
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if headers, ok := fetchdef["headers"].(map[string]any); ok {
|
|
31
|
+
for k, v := range headers {
|
|
32
|
+
if sv, ok := v.(string); ok {
|
|
33
|
+
req.Header.Set(k, sv)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
resp, err := http.DefaultClient.Do(req)
|
|
39
|
+
if err != nil {
|
|
40
|
+
return nil, err
|
|
41
|
+
}
|
|
42
|
+
defer resp.Body.Close()
|
|
43
|
+
|
|
44
|
+
bodyBytes, err := io.ReadAll(resp.Body)
|
|
45
|
+
if err != nil {
|
|
46
|
+
return nil, err
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
headers := map[string]any{}
|
|
50
|
+
for k, vals := range resp.Header {
|
|
51
|
+
if len(vals) == 1 {
|
|
52
|
+
headers[strings.ToLower(k)] = vals[0]
|
|
53
|
+
} else {
|
|
54
|
+
headers[strings.ToLower(k)] = strings.Join(vals, ", ")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var jsonBody any
|
|
59
|
+
if len(bodyBytes) > 0 {
|
|
60
|
+
json.Unmarshal(bodyBytes, &jsonBody)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
statusText := resp.Status
|
|
64
|
+
if idx := strings.Index(statusText, " "); idx >= 0 {
|
|
65
|
+
statusText = statusText[idx+1:]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return map[string]any{
|
|
69
|
+
"status": resp.StatusCode,
|
|
70
|
+
"statusText": statusText,
|
|
71
|
+
"headers": headers,
|
|
72
|
+
"json": (func() any)(func() any { return jsonBody }),
|
|
73
|
+
"body": string(bodyBytes),
|
|
74
|
+
}, nil
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func fetcherUtil(ctx *core.Context, fullurl string, fetchdef map[string]any) (any, error) {
|
|
78
|
+
if ctx.Client.Mode != "live" {
|
|
79
|
+
return nil, ctx.MakeError("fetch_mode_block",
|
|
80
|
+
"Request blocked by mode: \""+ctx.Client.Mode+
|
|
81
|
+
"\" (URL was: \""+fullurl+"\")")
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
options := ctx.Client.OptionsMap()
|
|
85
|
+
if vs.GetPath([]any{"feature", "test", "active"}, options) == true {
|
|
86
|
+
return nil, ctx.MakeError("fetch_test_block",
|
|
87
|
+
"Request blocked as test feature is active"+
|
|
88
|
+
" (URL was: \""+fullurl+"\")")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
sysFetch := vs.GetPath([]any{"system", "fetch"}, options)
|
|
92
|
+
|
|
93
|
+
if sysFetch == nil {
|
|
94
|
+
return defaultHTTPFetch(fullurl, fetchdef)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if fetchFunc, ok := sysFetch.(func(string, map[string]any) (map[string]any, error)); ok {
|
|
98
|
+
return fetchFunc(fullurl, fetchdef)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return nil, ctx.MakeError("fetch_invalid", "system.fetch is not a valid function")
|
|
102
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func makeErrorUtil(ctx *core.Context, err error) (any, error) {
|
|
6
|
+
if ctx == nil {
|
|
7
|
+
ctx = &core.Context{
|
|
8
|
+
Ctrl: &core.Control{},
|
|
9
|
+
Op: core.NewOperation(map[string]any{}),
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
op := ctx.Op
|
|
14
|
+
if op == nil {
|
|
15
|
+
op = core.NewOperation(map[string]any{})
|
|
16
|
+
}
|
|
17
|
+
opname := op.Name
|
|
18
|
+
if opname == "" || opname == "_" {
|
|
19
|
+
opname = "unknown operation"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
result := ctx.Result
|
|
23
|
+
if result == nil {
|
|
24
|
+
result = core.NewResult(map[string]any{})
|
|
25
|
+
}
|
|
26
|
+
result.Ok = false
|
|
27
|
+
|
|
28
|
+
if err == nil {
|
|
29
|
+
err = result.Err
|
|
30
|
+
}
|
|
31
|
+
if err == nil {
|
|
32
|
+
err = ctx.MakeError("unknown", "unknown error")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
errmsg := err.Error()
|
|
36
|
+
msg := "ProjectNameSDK: " + opname + ": " + errmsg
|
|
37
|
+
msg = cleanUtil(ctx, msg).(string)
|
|
38
|
+
|
|
39
|
+
result.Err = nil
|
|
40
|
+
|
|
41
|
+
spec := ctx.Spec
|
|
42
|
+
|
|
43
|
+
if ctx.Ctrl.Explain != nil {
|
|
44
|
+
ctx.Ctrl.Explain["err"] = map[string]any{
|
|
45
|
+
"message": msg,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sdkErr := &core.ProjectNameError{
|
|
50
|
+
IsProjectNameError: true,
|
|
51
|
+
Sdk: "ProjectName",
|
|
52
|
+
Code: "",
|
|
53
|
+
Msg: msg,
|
|
54
|
+
Ctx: ctx,
|
|
55
|
+
Result: cleanUtil(ctx, result),
|
|
56
|
+
Spec: cleanUtil(ctx, spec),
|
|
57
|
+
}
|
|
58
|
+
if se, ok := err.(*core.ProjectNameError); ok {
|
|
59
|
+
sdkErr.Code = se.Code
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ctx.Ctrl.Err = sdkErr
|
|
63
|
+
|
|
64
|
+
if ctx.Ctrl.Throw != nil && *ctx.Ctrl.Throw == false {
|
|
65
|
+
return result.Resdata, nil
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return nil, sdkErr
|
|
69
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
|
|
6
|
+
"GOMODULE/core"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func makeFetchDefUtil(ctx *core.Context) (map[string]any, error) {
|
|
10
|
+
spec := ctx.Spec
|
|
11
|
+
if spec == nil {
|
|
12
|
+
return nil, ctx.MakeError("fetchdef_no_spec",
|
|
13
|
+
"Expected context spec property to be defined.")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if ctx.Result == nil {
|
|
17
|
+
ctx.Result = core.NewResult(map[string]any{})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
spec.Step = "prepare"
|
|
21
|
+
|
|
22
|
+
url, err := ctx.Utility.MakeUrl(ctx)
|
|
23
|
+
if err != nil {
|
|
24
|
+
return nil, err
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
spec.Url = url
|
|
28
|
+
|
|
29
|
+
fetchdef := map[string]any{
|
|
30
|
+
"url": url,
|
|
31
|
+
"method": spec.Method,
|
|
32
|
+
"headers": spec.Headers,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if spec.Body != nil {
|
|
36
|
+
if _, ok := spec.Body.(map[string]any); ok {
|
|
37
|
+
fetchdef["body"] = vs.Jsonify(spec.Body)
|
|
38
|
+
} else {
|
|
39
|
+
fetchdef["body"] = spec.Body
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return fetchdef, nil
|
|
44
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
|
|
6
|
+
vs "github.com/voxgig/struct"
|
|
7
|
+
|
|
8
|
+
"GOMODULE/core"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func makeOptionsUtil(ctx *core.Context) map[string]any {
|
|
12
|
+
options := ctx.Options
|
|
13
|
+
if options == nil {
|
|
14
|
+
options = map[string]any{}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Merge custom utility overrides onto the utility object.
|
|
18
|
+
// Read from original options before clone, since vs.Clone strips functions.
|
|
19
|
+
if customUtils := core.ToMapAny(options["utility"]); customUtils != nil {
|
|
20
|
+
utility := ctx.Utility
|
|
21
|
+
if utility != nil {
|
|
22
|
+
for key, val := range customUtils {
|
|
23
|
+
utility.Custom[key] = val
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
opts := vs.Clone(options).(map[string]any)
|
|
29
|
+
|
|
30
|
+
config := ctx.Config
|
|
31
|
+
if config == nil {
|
|
32
|
+
config = map[string]any{}
|
|
33
|
+
}
|
|
34
|
+
cfgopts := map[string]any{}
|
|
35
|
+
if co, ok := config["options"]; ok && co != nil {
|
|
36
|
+
if cm, ok := co.(map[string]any); ok {
|
|
37
|
+
cfgopts = cm
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
optspec := map[string]any{
|
|
42
|
+
"apikey": "",
|
|
43
|
+
"base": "http://localhost:8000",
|
|
44
|
+
"prefix": "",
|
|
45
|
+
"suffix": "",
|
|
46
|
+
"auth": map[string]any{
|
|
47
|
+
"prefix": "",
|
|
48
|
+
},
|
|
49
|
+
"headers": map[string]any{
|
|
50
|
+
"`$CHILD`": "`$STRING`",
|
|
51
|
+
},
|
|
52
|
+
"allow": map[string]any{
|
|
53
|
+
"method": "GET,PUT,POST,PATCH,DELETE,OPTIONS",
|
|
54
|
+
"op": "create,update,load,list,remove,command,direct",
|
|
55
|
+
},
|
|
56
|
+
"entity": map[string]any{
|
|
57
|
+
"`$CHILD`": map[string]any{
|
|
58
|
+
"`$OPEN`": true,
|
|
59
|
+
"active": false,
|
|
60
|
+
"alias": map[string]any{},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
"feature": map[string]any{
|
|
64
|
+
"`$CHILD`": map[string]any{
|
|
65
|
+
"`$OPEN`": true,
|
|
66
|
+
"active": false,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
"utility": map[string]any{},
|
|
70
|
+
"system": map[string]any{},
|
|
71
|
+
"test": map[string]any{
|
|
72
|
+
"active": false,
|
|
73
|
+
"entity": map[string]any{
|
|
74
|
+
"`$OPEN`": true,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
"clean": map[string]any{
|
|
78
|
+
"keys": "key,token,id",
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Preserve system.fetch before merge/validate.
|
|
83
|
+
var sysFetch any
|
|
84
|
+
if sf := vs.GetPath([]any{"system", "fetch"}, opts); sf != nil {
|
|
85
|
+
sysFetch = sf
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
merged := vs.Merge([]any{map[string]any{}, cfgopts, opts})
|
|
89
|
+
validated, _ := vs.Validate(merged, optspec)
|
|
90
|
+
opts = validated.(map[string]any)
|
|
91
|
+
|
|
92
|
+
// Restore system.fetch.
|
|
93
|
+
if sysFetch != nil {
|
|
94
|
+
if sys, ok := opts["system"]; ok {
|
|
95
|
+
if sm, ok := sys.(map[string]any); ok {
|
|
96
|
+
sm["fetch"] = sysFetch
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
opts["system"] = map[string]any{"fetch": sysFetch}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Derived clean config.
|
|
104
|
+
cleanKeys := "key,token,id"
|
|
105
|
+
if ck := vs.GetPath([]any{"clean", "keys"}, opts); ck != nil {
|
|
106
|
+
if cks, ok := ck.(string); ok {
|
|
107
|
+
cleanKeys = cks
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
parts := strings.Split(cleanKeys, ",")
|
|
112
|
+
var filtered []string
|
|
113
|
+
for _, p := range parts {
|
|
114
|
+
p = strings.TrimSpace(p)
|
|
115
|
+
if p != "" {
|
|
116
|
+
filtered = append(filtered, vs.EscRe(p))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
keyre := strings.Join(filtered, "|")
|
|
120
|
+
|
|
121
|
+
derived := map[string]any{
|
|
122
|
+
"clean": map[string]any{},
|
|
123
|
+
}
|
|
124
|
+
if keyre != "" {
|
|
125
|
+
derived["clean"] = map[string]any{"keyre": keyre}
|
|
126
|
+
}
|
|
127
|
+
opts["__derived__"] = derived
|
|
128
|
+
|
|
129
|
+
return opts
|
|
130
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func makeRequestUtil(ctx *core.Context) (*core.Response, error) {
|
|
6
|
+
if ctx.Out["request"] != nil {
|
|
7
|
+
if resp, ok := ctx.Out["request"].(*core.Response); ok {
|
|
8
|
+
return resp, nil
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
spec := ctx.Spec
|
|
13
|
+
utility := ctx.Utility
|
|
14
|
+
|
|
15
|
+
response := core.NewResponse(map[string]any{})
|
|
16
|
+
result := core.NewResult(map[string]any{})
|
|
17
|
+
ctx.Result = result
|
|
18
|
+
|
|
19
|
+
if spec == nil {
|
|
20
|
+
return nil, ctx.MakeError("request_no_spec",
|
|
21
|
+
"Expected context spec property to be defined.")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fetchdef, err := utility.MakeFetchDef(ctx)
|
|
25
|
+
if err != nil {
|
|
26
|
+
response.Err = err
|
|
27
|
+
ctx.Response = response
|
|
28
|
+
spec.Step = "postrequest"
|
|
29
|
+
return response, nil
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if ctx.Ctrl.Explain != nil {
|
|
33
|
+
ctx.Ctrl.Explain["fetchdef"] = fetchdef
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
spec.Step = "prerequest"
|
|
37
|
+
|
|
38
|
+
url, _ := fetchdef["url"].(string)
|
|
39
|
+
fetched, fetchErr := utility.Fetcher(ctx, url, fetchdef)
|
|
40
|
+
|
|
41
|
+
if fetchErr != nil {
|
|
42
|
+
response.Err = fetchErr
|
|
43
|
+
} else if fetched == nil {
|
|
44
|
+
response = core.NewResponse(map[string]any{
|
|
45
|
+
"err": ctx.MakeError("request_no_response", "response: undefined"),
|
|
46
|
+
})
|
|
47
|
+
} else {
|
|
48
|
+
if fm, ok := fetched.(map[string]any); ok {
|
|
49
|
+
response = core.NewResponse(fm)
|
|
50
|
+
} else {
|
|
51
|
+
response.Err = ctx.MakeError("request_invalid_response", "response: invalid type")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
spec.Step = "postrequest"
|
|
56
|
+
ctx.Response = response
|
|
57
|
+
|
|
58
|
+
return response, nil
|
|
59
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func makeResponseUtil(ctx *core.Context) (*core.Response, error) {
|
|
6
|
+
if ctx.Out["response"] != nil {
|
|
7
|
+
if resp, ok := ctx.Out["response"].(*core.Response); ok {
|
|
8
|
+
return resp, nil
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
utility := ctx.Utility
|
|
13
|
+
spec := ctx.Spec
|
|
14
|
+
result := ctx.Result
|
|
15
|
+
response := ctx.Response
|
|
16
|
+
|
|
17
|
+
if spec == nil {
|
|
18
|
+
return nil, ctx.MakeError("response_no_spec",
|
|
19
|
+
"Expected context spec property to be defined.")
|
|
20
|
+
}
|
|
21
|
+
if response == nil {
|
|
22
|
+
return nil, ctx.MakeError("response_no_response",
|
|
23
|
+
"Expected context response property to be defined.")
|
|
24
|
+
}
|
|
25
|
+
if result == nil {
|
|
26
|
+
return nil, ctx.MakeError("response_no_result",
|
|
27
|
+
"Expected context result property to be defined.")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
spec.Step = "response"
|
|
31
|
+
|
|
32
|
+
utility.ResultBasic(ctx)
|
|
33
|
+
utility.ResultHeaders(ctx)
|
|
34
|
+
utility.ResultBody(ctx)
|
|
35
|
+
utility.TransformResponse(ctx)
|
|
36
|
+
|
|
37
|
+
if result.Err == nil {
|
|
38
|
+
result.Ok = true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ctx.Ctrl.Explain != nil {
|
|
42
|
+
ctx.Ctrl.Explain["result"] = result
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return response, nil
|
|
46
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import "GOMODULE/core"
|
|
4
|
+
|
|
5
|
+
func makeResultUtil(ctx *core.Context) (*core.Result, error) {
|
|
6
|
+
if ctx.Out["result"] != nil {
|
|
7
|
+
if res, ok := ctx.Out["result"].(*core.Result); ok {
|
|
8
|
+
return res, nil
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
utility := ctx.Utility
|
|
13
|
+
op := ctx.Op
|
|
14
|
+
entity := ctx.Entity
|
|
15
|
+
spec := ctx.Spec
|
|
16
|
+
result := ctx.Result
|
|
17
|
+
|
|
18
|
+
if spec == nil {
|
|
19
|
+
return nil, ctx.MakeError("result_no_spec",
|
|
20
|
+
"Expected context spec property to be defined.")
|
|
21
|
+
}
|
|
22
|
+
if result == nil {
|
|
23
|
+
return nil, ctx.MakeError("result_no_result",
|
|
24
|
+
"Expected context result property to be defined.")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
spec.Step = "result"
|
|
28
|
+
|
|
29
|
+
utility.TransformResponse(ctx)
|
|
30
|
+
|
|
31
|
+
if op.Name == "list" {
|
|
32
|
+
resdata := result.Resdata
|
|
33
|
+
result.Resdata = []any{}
|
|
34
|
+
|
|
35
|
+
if resdata != nil {
|
|
36
|
+
if list, ok := resdata.([]any); ok && len(list) > 0 && entity != nil {
|
|
37
|
+
var entities []any
|
|
38
|
+
for _, entry := range list {
|
|
39
|
+
ent := entity.Make()
|
|
40
|
+
if entryMap, ok := entry.(map[string]any); ok {
|
|
41
|
+
ent.Data(entryMap)
|
|
42
|
+
}
|
|
43
|
+
entities = append(entities, ent)
|
|
44
|
+
}
|
|
45
|
+
result.Resdata = entities
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ctx.Ctrl.Explain != nil {
|
|
51
|
+
ctx.Ctrl.Explain["result"] = result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return result, nil
|
|
55
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package utility
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
|
|
6
|
+
vs "github.com/voxgig/struct"
|
|
7
|
+
|
|
8
|
+
"GOMODULE/core"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func makeSpecUtil(ctx *core.Context) (*core.Spec, error) {
|
|
12
|
+
if ctx.Out["spec"] != nil {
|
|
13
|
+
if sp, ok := ctx.Out["spec"].(*core.Spec); ok {
|
|
14
|
+
ctx.Spec = sp
|
|
15
|
+
return sp, nil
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
target := ctx.Target
|
|
20
|
+
options := ctx.Options
|
|
21
|
+
utility := ctx.Utility
|
|
22
|
+
|
|
23
|
+
base, _ := vs.GetProp(options, "base").(string)
|
|
24
|
+
prefix, _ := vs.GetProp(options, "prefix").(string)
|
|
25
|
+
suffix, _ := vs.GetProp(options, "suffix").(string)
|
|
26
|
+
|
|
27
|
+
var parts []any
|
|
28
|
+
if p := vs.GetProp(target, "parts"); p != nil {
|
|
29
|
+
if pl, ok := p.([]any); ok {
|
|
30
|
+
parts = pl
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
ctx.Spec = core.NewSpec(map[string]any{
|
|
35
|
+
"base": base,
|
|
36
|
+
"prefix": prefix,
|
|
37
|
+
"parts": parts,
|
|
38
|
+
"suffix": suffix,
|
|
39
|
+
"step": "start",
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
ctx.Spec.Method = utility.PrepareMethod(ctx)
|
|
43
|
+
|
|
44
|
+
allowMethod, _ := vs.GetPath([]any{"allow", "method"}, options).(string)
|
|
45
|
+
if !strings.Contains(allowMethod, ctx.Spec.Method) {
|
|
46
|
+
return nil, ctx.MakeError("spec_method_allow",
|
|
47
|
+
"Method \""+ctx.Spec.Method+
|
|
48
|
+
"\" not allowed by SDK option allow.method value: \""+allowMethod+"\"")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
ctx.Spec.Params = utility.PrepareParams(ctx)
|
|
52
|
+
ctx.Spec.Query = utility.PrepareQuery(ctx)
|
|
53
|
+
ctx.Spec.Headers = utility.PrepareHeaders(ctx)
|
|
54
|
+
ctx.Spec.Body = utility.PrepareBody(ctx)
|
|
55
|
+
ctx.Spec.Path = utility.PreparePath(ctx)
|
|
56
|
+
|
|
57
|
+
if ctx.Ctrl.Explain != nil {
|
|
58
|
+
ctx.Ctrl.Explain["spec"] = ctx.Spec
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
spec, err := utility.PrepareAuth(ctx)
|
|
62
|
+
if err != nil {
|
|
63
|
+
return nil, err
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ctx.Spec = spec
|
|
67
|
+
return spec, nil
|
|
68
|
+
}
|