@voxgig/sdkgen 0.25.0 → 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 +6 -6
- package/dist/action/action.js +1 -2
- package/dist/action/action.js.map +1 -1
- package/dist/action/feature.js +4 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +4 -2
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/Entity.js +2 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +2 -1
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/Test.d.ts +2 -0
- package/dist/cmp/Test.js +17 -0
- package/dist/cmp/Test.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +17 -28
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/model/sdkgen.jsonic +9 -9
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +3 -3
- package/project/.sdk/model/feature/test.jsonic +8 -3
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +5 -5
- 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/Main_js.ts +3 -3
- package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
- 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/Config_ts.ts +53 -6
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
- package/project/.sdk/src/cmp/ts/Main_ts.ts +23 -13
- package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
- 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 +349 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +23 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +51 -32
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +166 -34
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
- 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 +158 -104
- package/project/.sdk/tm/ts/src/types.ts +18 -78
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +8 -5
- package/project/.sdk/tm/ts/src/utility/FeatureInitUtility.ts +15 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +20 -2
- package/project/.sdk/tm/ts/src/utility/MakeContextUtility.ts +27 -0
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +10 -6
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +32 -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/MakeResultUtility.ts +56 -0
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeTargetUtility.ts +76 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +28 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +10 -4
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +32 -0
- 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 +17 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +12 -7
- package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +22 -0
- package/project/.sdk/tm/ts/src/utility/ResultHeadersUtility.ts +26 -0
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +11 -8
- package/project/.sdk/tm/ts/src/utility/Utility.ts +52 -65
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +36 -13
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +385 -168
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
- package/src/action/action.ts +1 -2
- package/src/action/feature.ts +7 -2
- package/src/action/target.ts +7 -7
- package/src/cmp/Entity.ts +7 -1
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +12 -2
- package/src/cmp/ReadmeEntity.ts +6 -1
- package/src/cmp/Test.ts +31 -0
- package/src/sdkgen.ts +19 -34
- package/src/types.ts +10 -1
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +0 -29
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +0 -67
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +0 -46
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +0 -13
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
- 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 -66
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +0 -19
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -30
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +0 -36
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -61
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
package feature
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"math/rand"
|
|
6
|
+
|
|
7
|
+
vs "github.com/voxgig/struct"
|
|
8
|
+
|
|
9
|
+
"GOMODULE/core"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
type TestFeature struct {
|
|
13
|
+
BaseFeature
|
|
14
|
+
client *core.ProjectNameSDK
|
|
15
|
+
options map[string]any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func NewTestFeature() *TestFeature {
|
|
19
|
+
return &TestFeature{
|
|
20
|
+
BaseFeature: BaseFeature{
|
|
21
|
+
Version: "0.0.1",
|
|
22
|
+
Name: "test",
|
|
23
|
+
Active: true,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func (f *TestFeature) Init(ctx *core.Context, options map[string]any) {
|
|
29
|
+
f.client = ctx.Client
|
|
30
|
+
f.options = options
|
|
31
|
+
|
|
32
|
+
entity := core.ToMapAny(vs.GetProp(options, "entity"))
|
|
33
|
+
|
|
34
|
+
f.client.Mode = "test"
|
|
35
|
+
|
|
36
|
+
// Ensure entity ids are correct.
|
|
37
|
+
vs.Walk(entity, func(key *string, val any, parent any, path []string) any {
|
|
38
|
+
if len(path) == 2 {
|
|
39
|
+
if m, ok := val.(map[string]any); ok {
|
|
40
|
+
if key != nil {
|
|
41
|
+
m["id"] = *key
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return val
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
self := f
|
|
49
|
+
|
|
50
|
+
testFetcher := func(ctx *core.Context, _fullurl string, _fetchdef map[string]any) (any, error) {
|
|
51
|
+
respond := func(status int, data any, extra map[string]any) map[string]any {
|
|
52
|
+
out := map[string]any{
|
|
53
|
+
"status": status,
|
|
54
|
+
"statusText": "OK",
|
|
55
|
+
"json": (func() any)(func() any { return data }),
|
|
56
|
+
"body": "not-used",
|
|
57
|
+
}
|
|
58
|
+
if extra != nil {
|
|
59
|
+
for k, v := range extra {
|
|
60
|
+
out[k] = v
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
op := ctx.Op
|
|
67
|
+
entmap := core.ToMapAny(vs.GetProp(entity, op.Entity))
|
|
68
|
+
if entmap == nil {
|
|
69
|
+
entmap = map[string]any{}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if op.Name == "load" {
|
|
73
|
+
args := self.buildArgs(ctx, op, ctx.Reqmatch)
|
|
74
|
+
found := vs.Select(entmap, args)
|
|
75
|
+
ent := vs.GetElem(found, 0)
|
|
76
|
+
if ent == nil {
|
|
77
|
+
return respond(404, nil, map[string]any{"statusText": "Not found"}), nil
|
|
78
|
+
}
|
|
79
|
+
vs.DelProp(ent, "$KEY")
|
|
80
|
+
out := vs.Clone(ent)
|
|
81
|
+
return respond(200, out, nil), nil
|
|
82
|
+
} else if op.Name == "list" {
|
|
83
|
+
args := self.buildArgs(ctx, op, ctx.Reqmatch)
|
|
84
|
+
found := vs.Select(entmap, args)
|
|
85
|
+
if found == nil {
|
|
86
|
+
return respond(404, nil, map[string]any{"statusText": "Not found"}), nil
|
|
87
|
+
}
|
|
88
|
+
for _, item := range found {
|
|
89
|
+
vs.DelProp(item, "$KEY")
|
|
90
|
+
}
|
|
91
|
+
out := vs.Clone(found)
|
|
92
|
+
return respond(200, out, nil), nil
|
|
93
|
+
} else if op.Name == "update" {
|
|
94
|
+
args := self.buildArgs(ctx, op, ctx.Reqdata)
|
|
95
|
+
found := vs.Select(entmap, args)
|
|
96
|
+
ent := vs.GetElem(found, 0)
|
|
97
|
+
if ent == nil {
|
|
98
|
+
return respond(404, nil, map[string]any{"statusText": "Not found"}), nil
|
|
99
|
+
}
|
|
100
|
+
if entm, ok := ent.(map[string]any); ok {
|
|
101
|
+
reqdata := ctx.Reqdata
|
|
102
|
+
if reqdata != nil {
|
|
103
|
+
for k, v := range reqdata {
|
|
104
|
+
entm[k] = v
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
vs.DelProp(ent, "$KEY")
|
|
109
|
+
out := vs.Clone(ent)
|
|
110
|
+
return respond(200, out, nil), nil
|
|
111
|
+
} else if op.Name == "remove" {
|
|
112
|
+
args := self.buildArgs(ctx, op, ctx.Reqmatch)
|
|
113
|
+
found := vs.Select(entmap, args)
|
|
114
|
+
ent := vs.GetElem(found, 0)
|
|
115
|
+
if ent == nil {
|
|
116
|
+
return respond(404, nil, map[string]any{"statusText": "Not found"}), nil
|
|
117
|
+
}
|
|
118
|
+
if entm, ok := ent.(map[string]any); ok {
|
|
119
|
+
id := vs.GetProp(entm, "id")
|
|
120
|
+
vs.DelProp(entmap, id)
|
|
121
|
+
}
|
|
122
|
+
return respond(200, nil, nil), nil
|
|
123
|
+
} else if op.Name == "create" {
|
|
124
|
+
_ = self.buildArgs(ctx, op, ctx.Reqdata)
|
|
125
|
+
id := ctx.Utility.Param(ctx, "id")
|
|
126
|
+
if id == nil {
|
|
127
|
+
id = fmt.Sprintf("%04x%04x%04x%04x",
|
|
128
|
+
rand.Intn(0x10000), rand.Intn(0x10000),
|
|
129
|
+
rand.Intn(0x10000), rand.Intn(0x10000))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
ent := vs.Clone(ctx.Reqdata)
|
|
133
|
+
if entm, ok := ent.(map[string]any); ok {
|
|
134
|
+
entm["id"] = id
|
|
135
|
+
if idStr, ok := id.(string); ok {
|
|
136
|
+
entmap[idStr] = entm
|
|
137
|
+
}
|
|
138
|
+
vs.DelProp(entm, "$KEY")
|
|
139
|
+
out := vs.Clone(entm)
|
|
140
|
+
return respond(200, out, nil), nil
|
|
141
|
+
}
|
|
142
|
+
return respond(200, ent, nil), nil
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return respond(404, nil, map[string]any{"statusText": "Unknown operation"}), nil
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
ctx.Utility.Fetcher = testFetcher
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
func (f *TestFeature) buildArgs(ctx *core.Context, op *core.Operation, args map[string]any) any {
|
|
152
|
+
opname := op.Name
|
|
153
|
+
|
|
154
|
+
// Get last target from config.
|
|
155
|
+
targets := vs.GetPath([]any{"entity", ctx.Entity.GetName(), "op", opname, "targets"}, ctx.Config)
|
|
156
|
+
target := vs.GetElem(targets, -1)
|
|
157
|
+
|
|
158
|
+
// Get required params.
|
|
159
|
+
paramsPath := vs.GetPath([]any{"args", "params"}, target)
|
|
160
|
+
reqdParams := vs.Select(paramsPath, map[string]any{"reqd": true})
|
|
161
|
+
reqd := vs.Transform(reqdParams, []any{"`$EACH`", "", "`$KEY.name`"})
|
|
162
|
+
|
|
163
|
+
qand := []any{}
|
|
164
|
+
q := map[string]any{"`$AND`": &qand}
|
|
165
|
+
|
|
166
|
+
if args != nil {
|
|
167
|
+
for _, key := range vs.KeysOf(args) {
|
|
168
|
+
isId := key == "id"
|
|
169
|
+
selected := vs.Select(reqd, key)
|
|
170
|
+
isReqd := !vs.IsEmpty(selected)
|
|
171
|
+
|
|
172
|
+
if isId || isReqd {
|
|
173
|
+
v := ctx.Utility.Param(ctx, key)
|
|
174
|
+
ka := vs.GetProp(op.Alias, key)
|
|
175
|
+
|
|
176
|
+
qor := []any{map[string]any{key: v}}
|
|
177
|
+
if ka != nil {
|
|
178
|
+
if kas, ok := ka.(string); ok {
|
|
179
|
+
qor = append(qor, map[string]any{kas: v})
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
qand = append(qand, map[string]any{"`$OR`": qor})
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Update the slice behind the pointer.
|
|
189
|
+
q["`$AND`"] = qand
|
|
190
|
+
|
|
191
|
+
if ctx.Ctrl.Explain != nil {
|
|
192
|
+
ctx.Ctrl.Explain["test"] = map[string]any{"query": q}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return q
|
|
196
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Go Features
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
package sdktest
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
sdk "GOMODULE"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestCustomUtility(t *testing.T) {
|
|
10
|
+
t.Run("basic", func(t *testing.T) {
|
|
11
|
+
client := sdk.TestSDK(nil, map[string]any{
|
|
12
|
+
"apikey": "APIKEY01",
|
|
13
|
+
"utility": map[string]any{
|
|
14
|
+
"auth": func() map[string]any { return map[string]any{"util": "AUTH"} },
|
|
15
|
+
"body": func() map[string]any { return map[string]any{"util": "BODY"} },
|
|
16
|
+
"contextify": func() map[string]any { return map[string]any{"util": "CONTEXTIFY"} },
|
|
17
|
+
"done": func() map[string]any { return map[string]any{"util": "DONE"} },
|
|
18
|
+
"error": func() map[string]any { return map[string]any{"util": "ERROR"} },
|
|
19
|
+
"findparam": func() map[string]any { return map[string]any{"util": "FINDPARAM"} },
|
|
20
|
+
"fullurl": func() map[string]any { return map[string]any{"util": "FULLURL"} },
|
|
21
|
+
"headers": func() map[string]any { return map[string]any{"util": "HEADERS"} },
|
|
22
|
+
"method": func() map[string]any { return map[string]any{"util": "METHOD"} },
|
|
23
|
+
"operator": func() map[string]any { return map[string]any{"util": "OPERATOR"} },
|
|
24
|
+
"params": func() map[string]any { return map[string]any{"util": "PARAMS"} },
|
|
25
|
+
"query": func() map[string]any { return map[string]any{"util": "QUERY"} },
|
|
26
|
+
"reqform": func() map[string]any { return map[string]any{"util": "REQFORM"} },
|
|
27
|
+
"request": func() map[string]any { return map[string]any{"util": "REQUEST"} },
|
|
28
|
+
"resbasic": func() map[string]any { return map[string]any{"util": "RESBASIC"} },
|
|
29
|
+
"resbody": func() map[string]any { return map[string]any{"util": "RESBODY"} },
|
|
30
|
+
"resform": func() map[string]any { return map[string]any{"util": "RESFORM"} },
|
|
31
|
+
"resheaders": func() map[string]any { return map[string]any{"util": "RESHEADERS"} },
|
|
32
|
+
"response": func() map[string]any { return map[string]any{"util": "RESPONSE"} },
|
|
33
|
+
"result": func() map[string]any { return map[string]any{"util": "RESULT"} },
|
|
34
|
+
"spec": func() map[string]any { return map[string]any{"util": "SPEC"} },
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
u := client.GetUtility()
|
|
39
|
+
|
|
40
|
+
checks := map[string]string{
|
|
41
|
+
"auth": "AUTH",
|
|
42
|
+
"body": "BODY",
|
|
43
|
+
"contextify": "CONTEXTIFY",
|
|
44
|
+
"done": "DONE",
|
|
45
|
+
"error": "ERROR",
|
|
46
|
+
"findparam": "FINDPARAM",
|
|
47
|
+
"fullurl": "FULLURL",
|
|
48
|
+
"headers": "HEADERS",
|
|
49
|
+
"method": "METHOD",
|
|
50
|
+
"operator": "OPERATOR",
|
|
51
|
+
"params": "PARAMS",
|
|
52
|
+
"query": "QUERY",
|
|
53
|
+
"reqform": "REQFORM",
|
|
54
|
+
"request": "REQUEST",
|
|
55
|
+
"resbasic": "RESBASIC",
|
|
56
|
+
"resbody": "RESBODY",
|
|
57
|
+
"resform": "RESFORM",
|
|
58
|
+
"resheaders": "RESHEADERS",
|
|
59
|
+
"response": "RESPONSE",
|
|
60
|
+
"result": "RESULT",
|
|
61
|
+
"spec": "SPEC",
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for key, expected := range checks {
|
|
65
|
+
fn, ok := u.Custom[key]
|
|
66
|
+
if !ok {
|
|
67
|
+
t.Errorf("expected custom utility %q to exist", key)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
if f, ok := fn.(func() map[string]any); ok {
|
|
71
|
+
result := f()
|
|
72
|
+
if result["util"] != expected {
|
|
73
|
+
t.Errorf("custom utility %q: got %v, want %v", key, result["util"], expected)
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
t.Errorf("custom utility %q: expected func() map[string]any, got %T", key, fn)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package sdktest
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"testing"
|
|
5
|
+
|
|
6
|
+
sdk "GOMODULE"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestExists(t *testing.T) {
|
|
10
|
+
t.Run("test-mode", func(t *testing.T) {
|
|
11
|
+
testsdk := sdk.TestSDK(nil, nil)
|
|
12
|
+
if testsdk == nil {
|
|
13
|
+
t.Fatal("expected non-nil SDK")
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
}
|