@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
|
@@ -19,11 +19,11 @@ class EntityOperation {
|
|
|
19
19
|
done,
|
|
20
20
|
error,
|
|
21
21
|
featureHook,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
makeTarget,
|
|
23
|
+
makeRequest,
|
|
24
|
+
makeResponse,
|
|
25
|
+
makeResult,
|
|
26
|
+
makeSpec,
|
|
27
27
|
} = utility
|
|
28
28
|
|
|
29
29
|
let fres: Promise<any> | undefined = undefined
|
|
@@ -40,15 +40,15 @@ class EntityOperation {
|
|
|
40
40
|
|
|
41
41
|
// #PreSelection-Hook
|
|
42
42
|
|
|
43
|
-
ctx.out.
|
|
44
|
-
if (ctx.out.
|
|
45
|
-
return error(ctx, ctx.out.
|
|
43
|
+
ctx.out.target = makeTarget(ctx)
|
|
44
|
+
if (ctx.out.target instanceof Error) {
|
|
45
|
+
return error(ctx, ctx.out.target)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
// #PreSpec-Hook
|
|
50
50
|
|
|
51
|
-
ctx.out.spec =
|
|
51
|
+
ctx.out.spec = makeSpec(ctx)
|
|
52
52
|
if (ctx.out.spec instanceof Error) {
|
|
53
53
|
return error(ctx, ctx.out.spec)
|
|
54
54
|
}
|
|
@@ -56,7 +56,7 @@ class EntityOperation {
|
|
|
56
56
|
|
|
57
57
|
// #PreRequest-Hook
|
|
58
58
|
|
|
59
|
-
ctx.out.request = await
|
|
59
|
+
ctx.out.request = await makeRequest(ctx)
|
|
60
60
|
if (ctx.out.request instanceof Error) {
|
|
61
61
|
return error(ctx, ctx.out.request)
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ class EntityOperation {
|
|
|
64
64
|
|
|
65
65
|
// #PreResponse-Hook
|
|
66
66
|
|
|
67
|
-
ctx.out.response = await
|
|
67
|
+
ctx.out.response = await makeResponse(ctx)
|
|
68
68
|
if (ctx.out.response instanceof Error) {
|
|
69
69
|
return error(ctx, ctx.out.response)
|
|
70
70
|
}
|
|
@@ -72,7 +72,7 @@ class EntityOperation {
|
|
|
72
72
|
|
|
73
73
|
// #PreResult-Hook
|
|
74
74
|
|
|
75
|
-
ctx.out.result = await
|
|
75
|
+
ctx.out.result = await makeResult(ctx)
|
|
76
76
|
if (ctx.out.result instanceof Error) {
|
|
77
77
|
return error(ctx, ctx.out.result)
|
|
78
78
|
}
|
|
@@ -30,7 +30,7 @@ class ProjectNameSDK {
|
|
|
30
30
|
shared: new WeakMap()
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
this._options = this._utility.
|
|
33
|
+
this._options = this._utility.makeOptions(this._rootctx)
|
|
34
34
|
|
|
35
35
|
const struct = this._utility.struct
|
|
36
36
|
const getpath = struct.getpath
|
|
@@ -44,25 +44,25 @@ class ProjectNameSDK {
|
|
|
44
44
|
|
|
45
45
|
this._features = []
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const featureAdd = this._utility.featureAdd
|
|
48
|
+
const featureInit = this._utility.featureInit
|
|
49
49
|
|
|
50
50
|
items(this._options.feature, (fitem: [string, any]) => {
|
|
51
51
|
const fname = fitem[0]
|
|
52
52
|
const fopts = fitem[1]
|
|
53
53
|
if (fopts.active) {
|
|
54
|
-
|
|
54
|
+
featureAdd(this._rootctx, this._rootctx.config.makeFeature(fname))
|
|
55
55
|
}
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
if (null != this._options.extend) {
|
|
59
59
|
for (let f of this._options.extend) {
|
|
60
|
-
|
|
60
|
+
featureAdd(this._rootctx, f)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
for (let f of this._features) {
|
|
65
|
-
|
|
65
|
+
featureInit(this._rootctx, f)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const featureHook = this._utility.featureHook
|
|
@@ -80,6 +80,102 @@ class ProjectNameSDK {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
async prepare(fetchargs?: any) {
|
|
84
|
+
const utility = this._utility
|
|
85
|
+
const struct = utility.struct
|
|
86
|
+
const clone = struct.clone
|
|
87
|
+
|
|
88
|
+
const {
|
|
89
|
+
makeContext,
|
|
90
|
+
makeFetchDef,
|
|
91
|
+
prepareHeaders,
|
|
92
|
+
prepareAuth,
|
|
93
|
+
} = utility
|
|
94
|
+
|
|
95
|
+
fetchargs = fetchargs || {}
|
|
96
|
+
|
|
97
|
+
let ctx: Context = makeContext({
|
|
98
|
+
opname: 'prepare',
|
|
99
|
+
ctrl: fetchargs.ctrl || {},
|
|
100
|
+
}, this._rootctx)
|
|
101
|
+
|
|
102
|
+
const options = this._options
|
|
103
|
+
|
|
104
|
+
// Build spec directly from SDK options + user-provided fetch args.
|
|
105
|
+
const spec: any = {
|
|
106
|
+
base: options.base,
|
|
107
|
+
prefix: options.prefix,
|
|
108
|
+
suffix: options.suffix,
|
|
109
|
+
path: fetchargs.path || '',
|
|
110
|
+
method: fetchargs.method || 'GET',
|
|
111
|
+
params: fetchargs.params || {},
|
|
112
|
+
query: fetchargs.query || {},
|
|
113
|
+
headers: prepareHeaders(ctx),
|
|
114
|
+
body: fetchargs.body,
|
|
115
|
+
step: 'start',
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
ctx.spec = spec
|
|
119
|
+
|
|
120
|
+
// Merge user-provided headers over SDK defaults.
|
|
121
|
+
if (fetchargs.headers) {
|
|
122
|
+
const uheaders = fetchargs.headers
|
|
123
|
+
for (let key in uheaders) {
|
|
124
|
+
spec.headers[key] = uheaders[key]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Apply SDK auth (apikey, auth prefix, etc.)
|
|
129
|
+
const authResult = prepareAuth(ctx)
|
|
130
|
+
if (authResult instanceof Error) {
|
|
131
|
+
return authResult
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return makeFetchDef(ctx)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async direct(fetchargs?: any) {
|
|
139
|
+
const utility = this._utility
|
|
140
|
+
const fetcher = utility.fetcher
|
|
141
|
+
const makeContext = utility.makeContext
|
|
142
|
+
|
|
143
|
+
const fetchdef = await this.prepare(fetchargs)
|
|
144
|
+
if (fetchdef instanceof Error) {
|
|
145
|
+
return fetchdef
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let ctx: Context = makeContext({
|
|
149
|
+
opname: 'direct',
|
|
150
|
+
ctrl: (fetchargs || {}).ctrl || {},
|
|
151
|
+
}, this._rootctx)
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const fetched = await fetcher(ctx, fetchdef.url, fetchdef)
|
|
155
|
+
|
|
156
|
+
if (null == fetched) {
|
|
157
|
+
return { ok: false, err: ctx.error('direct_no_response', 'response: undefined') }
|
|
158
|
+
}
|
|
159
|
+
else if (fetched instanceof Error) {
|
|
160
|
+
return { ok: false, err: fetched }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const status = fetched.status
|
|
164
|
+
const json = 'function' === typeof fetched.json ? await fetched.json() : fetched.json
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
ok: status >= 200 && status < 300,
|
|
168
|
+
status,
|
|
169
|
+
headers: fetched.headers,
|
|
170
|
+
data: json,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (err: any) {
|
|
174
|
+
return { ok: false, err }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
83
179
|
// <[SLOT]>
|
|
84
180
|
|
|
85
181
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from './Context'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ProjectNameError extends Error {
|
|
6
|
+
|
|
7
|
+
isProjectNameError = true
|
|
8
|
+
|
|
9
|
+
sdk = 'ProjectName'
|
|
10
|
+
|
|
11
|
+
code: string
|
|
12
|
+
ctx: Context
|
|
13
|
+
|
|
14
|
+
constructor(code: string, msg: string, ctx: Context) {
|
|
15
|
+
super(msg)
|
|
16
|
+
this.code = code
|
|
17
|
+
this.ctx = ctx
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
ProjectNameError
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
package core
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"math/rand"
|
|
5
|
+
"strconv"
|
|
6
|
+
|
|
7
|
+
vs "github.com/voxgig/struct"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
type Context struct {
|
|
11
|
+
Id string
|
|
12
|
+
Out map[string]any
|
|
13
|
+
Ctrl *Control
|
|
14
|
+
Meta map[string]any
|
|
15
|
+
Client *ProjectNameSDK
|
|
16
|
+
Utility *Utility
|
|
17
|
+
Op *Operation
|
|
18
|
+
Target map[string]any
|
|
19
|
+
Config map[string]any
|
|
20
|
+
Entopts map[string]any
|
|
21
|
+
Options map[string]any
|
|
22
|
+
Opmap map[string]*Operation
|
|
23
|
+
Response *Response
|
|
24
|
+
Result *Result
|
|
25
|
+
Spec *Spec
|
|
26
|
+
Data map[string]any
|
|
27
|
+
Reqdata map[string]any
|
|
28
|
+
Match map[string]any
|
|
29
|
+
Reqmatch map[string]any
|
|
30
|
+
Entity Entity
|
|
31
|
+
Shared map[string]any
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func NewContext(ctxmap map[string]any, basectx *Context) *Context {
|
|
35
|
+
ctx := &Context{
|
|
36
|
+
Id: "C" + strconv.Itoa(rand.Intn(90000000)+10000000),
|
|
37
|
+
Out: map[string]any{},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Client
|
|
41
|
+
if c := getCtxProp(ctxmap, "client"); c != nil {
|
|
42
|
+
if sdk, ok := c.(*ProjectNameSDK); ok {
|
|
43
|
+
ctx.Client = sdk
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ctx.Client == nil && basectx != nil {
|
|
47
|
+
ctx.Client = basectx.Client
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Utility
|
|
51
|
+
if u := getCtxProp(ctxmap, "utility"); u != nil {
|
|
52
|
+
if util, ok := u.(*Utility); ok {
|
|
53
|
+
ctx.Utility = util
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if ctx.Utility == nil && basectx != nil {
|
|
57
|
+
ctx.Utility = basectx.Utility
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Ctrl
|
|
61
|
+
ctx.Ctrl = &Control{}
|
|
62
|
+
if c := getCtxProp(ctxmap, "ctrl"); c != nil {
|
|
63
|
+
if cm, ok := c.(map[string]any); ok {
|
|
64
|
+
if t, ok := cm["throw"]; ok {
|
|
65
|
+
if b, ok := t.(bool); ok {
|
|
66
|
+
ctx.Ctrl.Throw = &b
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if e, ok := cm["explain"]; ok {
|
|
70
|
+
if em, ok := e.(map[string]any); ok {
|
|
71
|
+
ctx.Ctrl.Explain = em
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else if ctrl, ok := c.(*Control); ok {
|
|
75
|
+
ctx.Ctrl = ctrl
|
|
76
|
+
}
|
|
77
|
+
} else if basectx != nil && basectx.Ctrl != nil {
|
|
78
|
+
ctx.Ctrl = basectx.Ctrl
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Meta
|
|
82
|
+
ctx.Meta = map[string]any{}
|
|
83
|
+
if m := getCtxProp(ctxmap, "meta"); m != nil {
|
|
84
|
+
if mm, ok := m.(map[string]any); ok {
|
|
85
|
+
ctx.Meta = mm
|
|
86
|
+
}
|
|
87
|
+
} else if basectx != nil && basectx.Meta != nil {
|
|
88
|
+
ctx.Meta = basectx.Meta
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Config
|
|
92
|
+
if c := getCtxProp(ctxmap, "config"); c != nil {
|
|
93
|
+
if cm, ok := c.(map[string]any); ok {
|
|
94
|
+
ctx.Config = cm
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if ctx.Config == nil && basectx != nil {
|
|
98
|
+
ctx.Config = basectx.Config
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Entopts
|
|
102
|
+
if e := getCtxProp(ctxmap, "entopts"); e != nil {
|
|
103
|
+
if em, ok := e.(map[string]any); ok {
|
|
104
|
+
ctx.Entopts = em
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if ctx.Entopts == nil && basectx != nil {
|
|
108
|
+
ctx.Entopts = basectx.Entopts
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Options
|
|
112
|
+
if o := getCtxProp(ctxmap, "options"); o != nil {
|
|
113
|
+
if om, ok := o.(map[string]any); ok {
|
|
114
|
+
ctx.Options = om
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if ctx.Options == nil && basectx != nil {
|
|
118
|
+
ctx.Options = basectx.Options
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Entity
|
|
122
|
+
if e := getCtxProp(ctxmap, "entity"); e != nil {
|
|
123
|
+
if ent, ok := e.(Entity); ok {
|
|
124
|
+
ctx.Entity = ent
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if ctx.Entity == nil && basectx != nil {
|
|
128
|
+
ctx.Entity = basectx.Entity
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Shared
|
|
132
|
+
if s := getCtxProp(ctxmap, "shared"); s != nil {
|
|
133
|
+
if sm, ok := s.(map[string]any); ok {
|
|
134
|
+
ctx.Shared = sm
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if ctx.Shared == nil && basectx != nil {
|
|
138
|
+
ctx.Shared = basectx.Shared
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Opmap
|
|
142
|
+
if o := getCtxProp(ctxmap, "opmap"); o != nil {
|
|
143
|
+
if om, ok := o.(map[string]*Operation); ok {
|
|
144
|
+
ctx.Opmap = om
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if ctx.Opmap == nil && basectx != nil {
|
|
148
|
+
ctx.Opmap = basectx.Opmap
|
|
149
|
+
}
|
|
150
|
+
if ctx.Opmap == nil {
|
|
151
|
+
ctx.Opmap = map[string]*Operation{}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Data
|
|
155
|
+
ctx.Data = ToMapAny(getCtxProp(ctxmap, "data"))
|
|
156
|
+
if ctx.Data == nil {
|
|
157
|
+
ctx.Data = map[string]any{}
|
|
158
|
+
}
|
|
159
|
+
ctx.Reqdata = ToMapAny(getCtxProp(ctxmap, "reqdata"))
|
|
160
|
+
if ctx.Reqdata == nil {
|
|
161
|
+
ctx.Reqdata = map[string]any{}
|
|
162
|
+
}
|
|
163
|
+
ctx.Match = ToMapAny(getCtxProp(ctxmap, "match"))
|
|
164
|
+
if ctx.Match == nil {
|
|
165
|
+
ctx.Match = map[string]any{}
|
|
166
|
+
}
|
|
167
|
+
ctx.Reqmatch = ToMapAny(getCtxProp(ctxmap, "reqmatch"))
|
|
168
|
+
if ctx.Reqmatch == nil {
|
|
169
|
+
ctx.Reqmatch = map[string]any{}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Target
|
|
173
|
+
if t := getCtxProp(ctxmap, "target"); t != nil {
|
|
174
|
+
if tm, ok := t.(map[string]any); ok {
|
|
175
|
+
ctx.Target = tm
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if ctx.Target == nil && basectx != nil {
|
|
179
|
+
ctx.Target = basectx.Target
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Spec
|
|
183
|
+
if s := getCtxProp(ctxmap, "spec"); s != nil {
|
|
184
|
+
if sp, ok := s.(*Spec); ok {
|
|
185
|
+
ctx.Spec = sp
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if ctx.Spec == nil && basectx != nil {
|
|
189
|
+
ctx.Spec = basectx.Spec
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Result
|
|
193
|
+
if r := getCtxProp(ctxmap, "result"); r != nil {
|
|
194
|
+
if res, ok := r.(*Result); ok {
|
|
195
|
+
ctx.Result = res
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if ctx.Result == nil && basectx != nil {
|
|
199
|
+
ctx.Result = basectx.Result
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Response
|
|
203
|
+
if r := getCtxProp(ctxmap, "response"); r != nil {
|
|
204
|
+
if resp, ok := r.(*Response); ok {
|
|
205
|
+
ctx.Response = resp
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if ctx.Response == nil && basectx != nil {
|
|
209
|
+
ctx.Response = basectx.Response
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Resolve operation
|
|
213
|
+
opname, _ := getCtxProp(ctxmap, "opname").(string)
|
|
214
|
+
ctx.Op = ctx.resolveOp(opname)
|
|
215
|
+
|
|
216
|
+
return ctx
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
func (ctx *Context) resolveOp(opname string) *Operation {
|
|
220
|
+
if op, ok := ctx.Opmap[opname]; ok && op != nil {
|
|
221
|
+
return op
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if opname == "" {
|
|
225
|
+
return NewOperation(map[string]any{})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
entname := ""
|
|
229
|
+
if ctx.Entity != nil {
|
|
230
|
+
entname = ctx.Entity.GetName()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
opcfg := vs.GetPath([]any{"entity", entname, "op", opname}, ctx.Config)
|
|
234
|
+
|
|
235
|
+
input := "match"
|
|
236
|
+
if opname == "update" || opname == "create" {
|
|
237
|
+
input = "data"
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var targets []any
|
|
241
|
+
if opcfg != nil {
|
|
242
|
+
if ocm, ok := opcfg.(map[string]any); ok {
|
|
243
|
+
if t := vs.GetProp(ocm, "targets"); t != nil {
|
|
244
|
+
if tl, ok := t.([]any); ok {
|
|
245
|
+
targets = tl
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if targets == nil {
|
|
251
|
+
targets = []any{}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
op := NewOperation(map[string]any{
|
|
255
|
+
"entity": entname,
|
|
256
|
+
"name": opname,
|
|
257
|
+
"input": input,
|
|
258
|
+
"targets": targets,
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
ctx.Opmap[opname] = op
|
|
262
|
+
return op
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
func (ctx *Context) MakeError(code string, msg string) *ProjectNameError {
|
|
266
|
+
return NewProjectNameError(code, msg, ctx)
|
|
267
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package core
|
|
2
|
+
|
|
3
|
+
type ProjectNameError struct {
|
|
4
|
+
IsProjectNameError bool
|
|
5
|
+
Sdk string
|
|
6
|
+
Code string
|
|
7
|
+
Msg string
|
|
8
|
+
Ctx *Context
|
|
9
|
+
Result any
|
|
10
|
+
Spec any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func NewProjectNameError(code string, msg string, ctx *Context) *ProjectNameError {
|
|
14
|
+
return &ProjectNameError{
|
|
15
|
+
IsProjectNameError: true,
|
|
16
|
+
Sdk: "ProjectName",
|
|
17
|
+
Code: code,
|
|
18
|
+
Msg: msg,
|
|
19
|
+
Ctx: ctx,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (e *ProjectNameError) Error() string {
|
|
24
|
+
return e.Msg
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package core
|
|
2
|
+
|
|
3
|
+
func ToMapAny(v any) map[string]any {
|
|
4
|
+
if v == nil {
|
|
5
|
+
return nil
|
|
6
|
+
}
|
|
7
|
+
if m, ok := v.(map[string]any); ok {
|
|
8
|
+
return m
|
|
9
|
+
}
|
|
10
|
+
return nil
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func ToInt(v any) int {
|
|
14
|
+
switch n := v.(type) {
|
|
15
|
+
case int:
|
|
16
|
+
return n
|
|
17
|
+
case float64:
|
|
18
|
+
return int(n)
|
|
19
|
+
case float32:
|
|
20
|
+
return int(n)
|
|
21
|
+
case int64:
|
|
22
|
+
return int(n)
|
|
23
|
+
default:
|
|
24
|
+
return -1
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func getCtxProp(m map[string]any, key string) any {
|
|
29
|
+
if m == nil {
|
|
30
|
+
return nil
|
|
31
|
+
}
|
|
32
|
+
return m[key]
|
|
33
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package core
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
type Operation struct {
|
|
8
|
+
Entity string
|
|
9
|
+
Name string
|
|
10
|
+
Input string
|
|
11
|
+
Targets []map[string]any
|
|
12
|
+
Alias map[string]any
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func NewOperation(opmap map[string]any) *Operation {
|
|
16
|
+
entity, _ := vs.GetProp(opmap, "entity").(string)
|
|
17
|
+
if entity == "" {
|
|
18
|
+
entity = "_"
|
|
19
|
+
}
|
|
20
|
+
name, _ := vs.GetProp(opmap, "name").(string)
|
|
21
|
+
if name == "" {
|
|
22
|
+
name = "_"
|
|
23
|
+
}
|
|
24
|
+
input, _ := vs.GetProp(opmap, "input").(string)
|
|
25
|
+
if input == "" {
|
|
26
|
+
input = "_"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var targets []map[string]any
|
|
30
|
+
rawTargets := vs.GetProp(opmap, "targets")
|
|
31
|
+
if rawTargets != nil {
|
|
32
|
+
if tlist, ok := rawTargets.([]any); ok {
|
|
33
|
+
for _, t := range tlist {
|
|
34
|
+
if tm, ok := t.(map[string]any); ok {
|
|
35
|
+
targets = append(targets, tm)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else if tlist, ok := rawTargets.([]map[string]any); ok {
|
|
39
|
+
targets = tlist
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if targets == nil {
|
|
43
|
+
targets = []map[string]any{}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var alias map[string]any
|
|
47
|
+
rawAlias := vs.GetProp(opmap, "alias")
|
|
48
|
+
if rawAlias != nil {
|
|
49
|
+
if am, ok := rawAlias.(map[string]any); ok {
|
|
50
|
+
alias = am
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return &Operation{
|
|
55
|
+
Entity: entity,
|
|
56
|
+
Name: name,
|
|
57
|
+
Input: input,
|
|
58
|
+
Targets: targets,
|
|
59
|
+
Alias: alias,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package core
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
vs "github.com/voxgig/struct"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
type Response struct {
|
|
8
|
+
Status int
|
|
9
|
+
StatusText string
|
|
10
|
+
Headers any
|
|
11
|
+
JsonFunc func() any
|
|
12
|
+
Body any
|
|
13
|
+
Err error
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func NewResponse(resmap map[string]any) *Response {
|
|
17
|
+
status := -1
|
|
18
|
+
if s := vs.GetProp(resmap, "status"); s != nil {
|
|
19
|
+
status = ToInt(s)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
statusText := ""
|
|
23
|
+
if st := vs.GetProp(resmap, "statusText"); st != nil {
|
|
24
|
+
if s, ok := st.(string); ok {
|
|
25
|
+
statusText = s
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
headers := vs.GetProp(resmap, "headers")
|
|
30
|
+
|
|
31
|
+
var jsonFunc func() any
|
|
32
|
+
if jf := vs.GetProp(resmap, "json"); jf != nil {
|
|
33
|
+
if f, ok := jf.(func() any); ok {
|
|
34
|
+
jsonFunc = f
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
body := vs.GetProp(resmap, "body")
|
|
39
|
+
|
|
40
|
+
var err error
|
|
41
|
+
if e := vs.GetProp(resmap, "err"); e != nil {
|
|
42
|
+
if er, ok := e.(error); ok {
|
|
43
|
+
err = er
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return &Response{
|
|
48
|
+
Status: status,
|
|
49
|
+
StatusText: statusText,
|
|
50
|
+
Headers: headers,
|
|
51
|
+
JsonFunc: jsonFunc,
|
|
52
|
+
Body: body,
|
|
53
|
+
Err: err,
|
|
54
|
+
}
|
|
55
|
+
}
|