@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.
Files changed (157) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Feature.js +11 -9
  3. package/dist/cmp/Feature.js.map +1 -1
  4. package/dist/cmp/Main.js +6 -2
  5. package/dist/cmp/Main.js.map +1 -1
  6. package/model/sdkgen.jsonic +1 -1
  7. package/package.json +3 -3
  8. package/project/.sdk/model/feature/log.jsonic +1 -1
  9. package/project/.sdk/model/feature/test.jsonic +1 -1
  10. package/project/.sdk/model/target/go.jsonic +19 -4
  11. package/project/.sdk/model/target/ts.jsonic +3 -3
  12. package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
  13. package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
  14. package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
  15. package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
  16. package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
  17. package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
  18. package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
  19. package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
  20. package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
  21. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
  22. package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
  23. package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
  24. package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
  25. package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
  26. package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
  27. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
  28. package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
  29. package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
  30. package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
  31. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
  32. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
  33. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
  34. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
  35. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
  36. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
  37. package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +1 -1
  38. package/project/.sdk/src/cmp/ts/Main_ts.ts +4 -4
  39. package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
  40. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
  41. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +14 -6
  42. package/project/.sdk/src/cmp/ts/Test_ts.ts +2 -0
  43. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
  44. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +12 -12
  45. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +12 -12
  46. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +12 -12
  47. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +13 -13
  48. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +12 -12
  49. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +102 -6
  50. package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
  51. package/project/.sdk/tm/go/Makefile +10 -0
  52. package/project/.sdk/tm/go/core/context.go +267 -0
  53. package/project/.sdk/tm/go/core/control.go +7 -0
  54. package/project/.sdk/tm/go/core/error.go +25 -0
  55. package/project/.sdk/tm/go/core/helpers.go +33 -0
  56. package/project/.sdk/tm/go/core/operation.go +61 -0
  57. package/project/.sdk/tm/go/core/response.go +55 -0
  58. package/project/.sdk/tm/go/core/result.go +73 -0
  59. package/project/.sdk/tm/go/core/spec.go +97 -0
  60. package/project/.sdk/tm/go/core/target.go +102 -0
  61. package/project/.sdk/tm/go/core/types.go +44 -0
  62. package/project/.sdk/tm/go/core/utility_type.go +54 -0
  63. package/project/.sdk/tm/go/feature/base_feature.go +40 -0
  64. package/project/.sdk/tm/go/feature/test_feature.go +196 -0
  65. package/project/.sdk/tm/go/src/feature/README.md +1 -0
  66. package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
  67. package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
  68. package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
  69. package/project/.sdk/tm/go/test/exists_test.go +16 -0
  70. package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
  71. package/project/.sdk/tm/go/test/runner_test.go +428 -0
  72. package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
  73. package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
  74. package/project/.sdk/tm/go/utility/clean.go +7 -0
  75. package/project/.sdk/tm/go/utility/done.go +20 -0
  76. package/project/.sdk/tm/go/utility/feature_add.go +10 -0
  77. package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
  78. package/project/.sdk/tm/go/utility/feature_init.go +30 -0
  79. package/project/.sdk/tm/go/utility/fetcher.go +102 -0
  80. package/project/.sdk/tm/go/utility/make_context.go +7 -0
  81. package/project/.sdk/tm/go/utility/make_error.go +69 -0
  82. package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
  83. package/project/.sdk/tm/go/utility/make_options.go +130 -0
  84. package/project/.sdk/tm/go/utility/make_request.go +59 -0
  85. package/project/.sdk/tm/go/utility/make_response.go +46 -0
  86. package/project/.sdk/tm/go/utility/make_result.go +55 -0
  87. package/project/.sdk/tm/go/utility/make_spec.go +68 -0
  88. package/project/.sdk/tm/go/utility/make_target.go +95 -0
  89. package/project/.sdk/tm/go/utility/make_url.go +41 -0
  90. package/project/.sdk/tm/go/utility/param.go +66 -0
  91. package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
  92. package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
  93. package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
  94. package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
  95. package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
  96. package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
  97. package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
  98. package/project/.sdk/tm/go/utility/register.go +39 -0
  99. package/project/.sdk/tm/go/utility/result_basic.go +31 -0
  100. package/project/.sdk/tm/go/utility/result_body.go +17 -0
  101. package/project/.sdk/tm/go/utility/result_headers.go +22 -0
  102. package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
  103. package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
  104. package/project/.sdk/tm/go/utility/transform_request.go +32 -0
  105. package/project/.sdk/tm/go/utility/transform_response.go +45 -0
  106. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
  107. package/project/.sdk/tm/ts/src/Context.ts +144 -0
  108. package/project/.sdk/tm/ts/src/Control.ts +20 -0
  109. package/project/.sdk/tm/ts/src/Operation.ts +24 -0
  110. package/project/.sdk/tm/ts/src/Response.ts +26 -0
  111. package/project/.sdk/tm/ts/src/Result.ts +30 -0
  112. package/project/.sdk/tm/ts/src/Spec.ts +40 -0
  113. package/project/.sdk/tm/ts/src/Target.ts +36 -0
  114. package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
  115. package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
  116. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +7 -7
  117. package/project/.sdk/tm/ts/src/types.ts +15 -205
  118. package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +2 -3
  119. package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
  120. package/project/.sdk/tm/ts/src/utility/{InitfeatureUtility.ts → FeatureInitUtility.ts} +2 -2
  121. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +5 -3
  122. package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +4 -4
  123. package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
  124. package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +10 -7
  125. package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
  126. package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
  127. package/project/.sdk/tm/ts/src/utility/{ResultUtility.ts → MakeResultUtility.ts} +6 -6
  128. package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
  129. package/project/.sdk/tm/ts/src/utility/{SelectionUtility.ts → MakeTargetUtility.ts} +22 -24
  130. package/project/.sdk/tm/ts/src/utility/{FullurlUtility.ts → MakeUrlUtility.ts} +7 -8
  131. package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +21 -8
  132. package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +4 -4
  133. package/project/.sdk/tm/ts/src/utility/{BodyUtility.ts → PrepareBodyUtility.ts} +7 -7
  134. package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
  135. package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
  136. package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
  137. package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +3 -4
  138. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
  139. package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +11 -6
  140. package/project/.sdk/tm/ts/src/utility/{ResbodyUtility.ts → ResultBodyUtility.ts} +4 -3
  141. package/project/.sdk/tm/ts/src/utility/{ResheadersUtility.ts → ResultHeadersUtility.ts} +4 -3
  142. package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
  143. package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +10 -7
  144. package/project/.sdk/tm/ts/src/utility/Utility.ts +47 -62
  145. package/project/.sdk/tm/ts/test/runner.ts +25 -4
  146. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +386 -175
  147. package/src/cmp/Feature.ts +11 -9
  148. package/src/cmp/Main.ts +8 -2
  149. package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
  150. package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +0 -23
  151. package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
  152. package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
  153. package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -83
  154. package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -61
  155. package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -68
  156. /package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +0 -0
  157. /package/project/.sdk/tm/ts/src/utility/{ContextUtility.ts → MakeContextUtility.ts} +0 -0
@@ -0,0 +1,73 @@
1
+ package core
2
+
3
+ import (
4
+ vs "github.com/voxgig/struct"
5
+ )
6
+
7
+ type Result struct {
8
+ Ok bool
9
+ Status int
10
+ StatusText string
11
+ Headers map[string]any
12
+ Body any
13
+ Err error
14
+ Resdata any
15
+ Resmatch map[string]any
16
+ }
17
+
18
+ func NewResult(resmap map[string]any) *Result {
19
+ ok := false
20
+ if o := vs.GetProp(resmap, "ok"); o != nil {
21
+ if b, is := o.(bool); is {
22
+ ok = b
23
+ }
24
+ }
25
+
26
+ status := -1
27
+ if s := vs.GetProp(resmap, "status"); s != nil {
28
+ status = ToInt(s)
29
+ }
30
+
31
+ statusText := ""
32
+ if st := vs.GetProp(resmap, "statusText"); st != nil {
33
+ if s, ok := st.(string); ok {
34
+ statusText = s
35
+ }
36
+ }
37
+
38
+ headers := map[string]any{}
39
+ if h := vs.GetProp(resmap, "headers"); h != nil {
40
+ if hm, ok := h.(map[string]any); ok {
41
+ headers = hm
42
+ }
43
+ }
44
+
45
+ body := vs.GetProp(resmap, "body")
46
+
47
+ var err error
48
+ if e := vs.GetProp(resmap, "err"); e != nil {
49
+ if er, ok := e.(error); ok {
50
+ err = er
51
+ }
52
+ }
53
+
54
+ resdata := vs.GetProp(resmap, "resdata")
55
+
56
+ var resmatch map[string]any
57
+ if rm := vs.GetProp(resmap, "resmatch"); rm != nil {
58
+ if rmm, ok := rm.(map[string]any); ok {
59
+ resmatch = rmm
60
+ }
61
+ }
62
+
63
+ return &Result{
64
+ Ok: ok,
65
+ Status: status,
66
+ StatusText: statusText,
67
+ Headers: headers,
68
+ Body: body,
69
+ Err: err,
70
+ Resdata: resdata,
71
+ Resmatch: resmatch,
72
+ }
73
+ }
@@ -0,0 +1,97 @@
1
+ package core
2
+
3
+ type Spec struct {
4
+ Parts []any
5
+ Headers map[string]any
6
+ Alias map[string]any
7
+ Base string
8
+ Prefix string
9
+ Suffix string
10
+ Params map[string]any
11
+ Query map[string]any
12
+ Step string
13
+ Method string
14
+ Body any
15
+ Url string
16
+ Path string
17
+ }
18
+
19
+ func NewSpec(specmap map[string]any) *Spec {
20
+ s := &Spec{
21
+ Headers: map[string]any{},
22
+ Alias: map[string]any{},
23
+ Params: map[string]any{},
24
+ Query: map[string]any{},
25
+ Method: "GET",
26
+ }
27
+
28
+ if specmap == nil {
29
+ return s
30
+ }
31
+
32
+ if v, ok := specmap["parts"]; ok && v != nil {
33
+ if parts, ok := v.([]any); ok {
34
+ s.Parts = parts
35
+ }
36
+ }
37
+ if v, ok := specmap["headers"]; ok && v != nil {
38
+ if h, ok := v.(map[string]any); ok {
39
+ s.Headers = h
40
+ }
41
+ }
42
+ if v, ok := specmap["alias"]; ok && v != nil {
43
+ if a, ok := v.(map[string]any); ok {
44
+ s.Alias = a
45
+ }
46
+ }
47
+ if v, ok := specmap["base"]; ok && v != nil {
48
+ if b, ok := v.(string); ok {
49
+ s.Base = b
50
+ }
51
+ }
52
+ if v, ok := specmap["prefix"]; ok && v != nil {
53
+ if p, ok := v.(string); ok {
54
+ s.Prefix = p
55
+ }
56
+ }
57
+ if v, ok := specmap["suffix"]; ok && v != nil {
58
+ if sf, ok := v.(string); ok {
59
+ s.Suffix = sf
60
+ }
61
+ }
62
+ if v, ok := specmap["params"]; ok && v != nil {
63
+ if p, ok := v.(map[string]any); ok {
64
+ s.Params = p
65
+ }
66
+ }
67
+ if v, ok := specmap["query"]; ok && v != nil {
68
+ if q, ok := v.(map[string]any); ok {
69
+ s.Query = q
70
+ }
71
+ }
72
+ if v, ok := specmap["step"]; ok && v != nil {
73
+ if st, ok := v.(string); ok {
74
+ s.Step = st
75
+ }
76
+ }
77
+ if v, ok := specmap["method"]; ok && v != nil {
78
+ if m, ok := v.(string); ok {
79
+ s.Method = m
80
+ }
81
+ }
82
+ if v, ok := specmap["body"]; ok {
83
+ s.Body = v
84
+ }
85
+ if v, ok := specmap["url"]; ok && v != nil {
86
+ if u, ok := v.(string); ok {
87
+ s.Url = u
88
+ }
89
+ }
90
+ if v, ok := specmap["path"]; ok && v != nil {
91
+ if p, ok := v.(string); ok {
92
+ s.Path = p
93
+ }
94
+ }
95
+
96
+ return s
97
+ }
@@ -0,0 +1,102 @@
1
+ package core
2
+
3
+ import (
4
+ vs "github.com/voxgig/struct"
5
+ )
6
+
7
+ type Target struct {
8
+ Args map[string]any
9
+ Rename map[string]any
10
+ Method string
11
+ Orig string
12
+ Parts []any
13
+ Params []any
14
+ Select map[string]any
15
+ Active bool
16
+ Relations []any
17
+ Alias map[string]any
18
+ Transform map[string]any
19
+ }
20
+
21
+ func NewTarget(altmap map[string]any) *Target {
22
+ t := &Target{}
23
+
24
+ if args := vs.GetProp(altmap, "args"); args != nil {
25
+ if am, ok := args.(map[string]any); ok {
26
+ t.Args = am
27
+ }
28
+ }
29
+ if t.Args == nil {
30
+ t.Args = map[string]any{"params": []any{}}
31
+ }
32
+
33
+ if rename := vs.GetProp(altmap, "rename"); rename != nil {
34
+ if rm, ok := rename.(map[string]any); ok {
35
+ t.Rename = rm
36
+ }
37
+ }
38
+ if t.Rename == nil {
39
+ t.Rename = map[string]any{"params": map[string]any{}}
40
+ }
41
+
42
+ if m := vs.GetProp(altmap, "method"); m != nil {
43
+ t.Method, _ = m.(string)
44
+ }
45
+
46
+ if o := vs.GetProp(altmap, "orig"); o != nil {
47
+ t.Orig, _ = o.(string)
48
+ }
49
+
50
+ if p := vs.GetProp(altmap, "parts"); p != nil {
51
+ if pl, ok := p.([]any); ok {
52
+ t.Parts = pl
53
+ }
54
+ }
55
+ if t.Parts == nil {
56
+ t.Parts = []any{}
57
+ }
58
+
59
+ if p := vs.GetProp(altmap, "params"); p != nil {
60
+ if pl, ok := p.([]any); ok {
61
+ t.Params = pl
62
+ }
63
+ }
64
+
65
+ if s := vs.GetProp(altmap, "select"); s != nil {
66
+ if sm, ok := s.(map[string]any); ok {
67
+ t.Select = sm
68
+ }
69
+ }
70
+
71
+ if a := vs.GetProp(altmap, "active"); a != nil {
72
+ if ab, ok := a.(bool); ok {
73
+ t.Active = ab
74
+ }
75
+ }
76
+
77
+ if r := vs.GetProp(altmap, "relations"); r != nil {
78
+ if rl, ok := r.([]any); ok {
79
+ t.Relations = rl
80
+ }
81
+ }
82
+
83
+ if a := vs.GetProp(altmap, "alias"); a != nil {
84
+ if am, ok := a.(map[string]any); ok {
85
+ t.Alias = am
86
+ }
87
+ }
88
+ if t.Alias == nil {
89
+ t.Alias = map[string]any{}
90
+ }
91
+
92
+ if tf := vs.GetProp(altmap, "transform"); tf != nil {
93
+ if tm, ok := tf.(map[string]any); ok {
94
+ t.Transform = tm
95
+ }
96
+ }
97
+ if t.Transform == nil {
98
+ t.Transform = map[string]any{}
99
+ }
100
+
101
+ return t
102
+ }
@@ -0,0 +1,44 @@
1
+ package core
2
+
3
+ type Feature interface {
4
+ GetVersion() string
5
+ GetName() string
6
+ GetActive() bool
7
+
8
+ Init(ctx *Context, options map[string]any)
9
+
10
+ PostConstruct(ctx *Context)
11
+ PostConstructEntity(ctx *Context)
12
+ SetData(ctx *Context)
13
+ GetData(ctx *Context)
14
+ GetMatch(ctx *Context)
15
+
16
+ PreTarget(ctx *Context)
17
+ PreSelection(ctx *Context)
18
+ PreSpec(ctx *Context)
19
+ PreRequest(ctx *Context)
20
+ PreResponse(ctx *Context)
21
+ PreResult(ctx *Context)
22
+ PreDone(ctx *Context)
23
+ PreUnexpected(ctx *Context)
24
+ PostOperation(ctx *Context)
25
+ SetMatch(ctx *Context)
26
+ }
27
+
28
+ type Entity interface {
29
+ GetName() string
30
+ Make() Entity
31
+ Data(data ...any) any
32
+ Match(match ...any) any
33
+ }
34
+
35
+ type ProjectNameEntity interface {
36
+ Entity
37
+ Load(reqmatch map[string]any, ctrl map[string]any) (any, error)
38
+ List(reqmatch map[string]any, ctrl map[string]any) (any, error)
39
+ Create(reqdata map[string]any, ctrl map[string]any) (any, error)
40
+ Update(reqdata map[string]any, ctrl map[string]any) (any, error)
41
+ Remove(reqmatch map[string]any, ctrl map[string]any) (any, error)
42
+ }
43
+
44
+ type FetcherFunc func(ctx *Context, fullurl string, fetchdef map[string]any) (any, error)
@@ -0,0 +1,54 @@
1
+ package core
2
+
3
+ type Utility struct {
4
+ Clean func(ctx *Context, val any) any
5
+ Done func(ctx *Context) (any, error)
6
+ MakeError func(ctx *Context, err error) (any, error)
7
+ FeatureAdd func(ctx *Context, f Feature)
8
+ FeatureHook func(ctx *Context, name string)
9
+ FeatureInit func(ctx *Context, f Feature)
10
+ Fetcher FetcherFunc
11
+ MakeFetchDef func(ctx *Context) (map[string]any, error)
12
+ MakeContext func(ctxmap map[string]any, basectx *Context) *Context
13
+ MakeOptions func(ctx *Context) map[string]any
14
+ MakeRequest func(ctx *Context) (*Response, error)
15
+ MakeResponse func(ctx *Context) (*Response, error)
16
+ MakeResult func(ctx *Context) (*Result, error)
17
+ MakeTarget func(ctx *Context) (map[string]any, error)
18
+ MakeSpec func(ctx *Context) (*Spec, error)
19
+ MakeUrl func(ctx *Context) (string, error)
20
+ Param func(ctx *Context, paramdef any) any
21
+ PrepareAuth func(ctx *Context) (*Spec, error)
22
+ PrepareBody func(ctx *Context) any
23
+ PrepareHeaders func(ctx *Context) map[string]any
24
+ PrepareMethod func(ctx *Context) string
25
+ PrepareParams func(ctx *Context) map[string]any
26
+ PreparePath func(ctx *Context) string
27
+ PrepareQuery func(ctx *Context) map[string]any
28
+ ResultBasic func(ctx *Context) *Result
29
+ ResultBody func(ctx *Context) *Result
30
+ ResultHeaders func(ctx *Context) *Result
31
+ TransformRequest func(ctx *Context) any
32
+ TransformResponse func(ctx *Context) any
33
+ Custom map[string]any
34
+ }
35
+
36
+ func NewUtility() *Utility {
37
+ u := &Utility{
38
+ Custom: map[string]any{},
39
+ }
40
+ if UtilityRegistrar != nil {
41
+ UtilityRegistrar(u)
42
+ }
43
+ return u
44
+ }
45
+
46
+ func CopyUtility(src *Utility) *Utility {
47
+ u := &Utility{}
48
+ *u = *src
49
+ u.Custom = map[string]any{}
50
+ for k, v := range src.Custom {
51
+ u.Custom[k] = v
52
+ }
53
+ return u
54
+ }
@@ -0,0 +1,40 @@
1
+ package feature
2
+
3
+ import (
4
+ "GOMODULE/core"
5
+ )
6
+
7
+ type BaseFeature struct {
8
+ Version string
9
+ Name string
10
+ Active bool
11
+ }
12
+
13
+ func NewBaseFeature() *BaseFeature {
14
+ return &BaseFeature{
15
+ Version: "0.0.1",
16
+ Name: "base",
17
+ Active: true,
18
+ }
19
+ }
20
+
21
+ func (f *BaseFeature) GetVersion() string { return f.Version }
22
+ func (f *BaseFeature) GetName() string { return f.Name }
23
+ func (f *BaseFeature) GetActive() bool { return f.Active }
24
+
25
+ func (f *BaseFeature) Init(ctx *core.Context, options map[string]any) {}
26
+ func (f *BaseFeature) PostConstruct(ctx *core.Context) {}
27
+ func (f *BaseFeature) PostConstructEntity(ctx *core.Context) {}
28
+ func (f *BaseFeature) SetData(ctx *core.Context) {}
29
+ func (f *BaseFeature) GetData(ctx *core.Context) {}
30
+ func (f *BaseFeature) GetMatch(ctx *core.Context) {}
31
+ func (f *BaseFeature) SetMatch(ctx *core.Context) {}
32
+ func (f *BaseFeature) PreTarget(ctx *core.Context) {}
33
+ func (f *BaseFeature) PreSelection(ctx *core.Context) {}
34
+ func (f *BaseFeature) PreSpec(ctx *core.Context) {}
35
+ func (f *BaseFeature) PreRequest(ctx *core.Context) {}
36
+ func (f *BaseFeature) PreResponse(ctx *core.Context) {}
37
+ func (f *BaseFeature) PreResult(ctx *core.Context) {}
38
+ func (f *BaseFeature) PreDone(ctx *core.Context) {}
39
+ func (f *BaseFeature) PreUnexpected(ctx *core.Context) {}
40
+ func (f *BaseFeature) PostOperation(ctx *core.Context) {}
@@ -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
+ }