@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
|
@@ -1,81 +1,200 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
2
|
+
import { inspect } from 'node:util'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { Context, Feature } from './types'
|
|
5
|
+
|
|
6
|
+
import { config } from './Config'
|
|
5
7
|
import { Utility } from './utility/Utility'
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
import { BaseFeature } from './feature/base/BaseFeature'
|
|
9
11
|
|
|
10
|
-
const utility = new Utility()
|
|
11
12
|
|
|
13
|
+
const stdutil = new Utility()
|
|
12
14
|
|
|
13
|
-
class ProjectNameSDK {
|
|
14
|
-
#options: any
|
|
15
|
-
#utility = utility
|
|
16
15
|
|
|
16
|
+
class ProjectNameSDK {
|
|
17
|
+
_mode: string = 'live'
|
|
18
|
+
_options: any
|
|
19
|
+
_utility = new Utility()
|
|
17
20
|
_features: Feature[]
|
|
18
|
-
|
|
21
|
+
_rootctx: Context
|
|
19
22
|
|
|
20
23
|
constructor(options?: any) {
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
this._rootctx = this._utility.makeContext({
|
|
23
26
|
client: this,
|
|
24
|
-
utility: this
|
|
25
|
-
config
|
|
27
|
+
utility: this._utility,
|
|
28
|
+
config,
|
|
26
29
|
options,
|
|
30
|
+
shared: new WeakMap()
|
|
27
31
|
})
|
|
28
32
|
|
|
29
|
-
this
|
|
33
|
+
this._options = this._utility.makeOptions(this._rootctx)
|
|
34
|
+
|
|
35
|
+
const struct = this._utility.struct
|
|
36
|
+
const getpath = struct.getpath
|
|
37
|
+
const items = struct.items
|
|
38
|
+
|
|
39
|
+
if (true === getpath(this._options.feature, 'test.active')) {
|
|
40
|
+
this._mode = 'test'
|
|
41
|
+
}
|
|
30
42
|
|
|
31
|
-
|
|
43
|
+
this._rootctx.options = this._options
|
|
32
44
|
|
|
33
45
|
this._features = []
|
|
34
46
|
|
|
35
|
-
const
|
|
36
|
-
const
|
|
47
|
+
const featureAdd = this._utility.featureAdd
|
|
48
|
+
const featureInit = this._utility.featureInit
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
items(this._options.feature, (fitem: [string, any]) => {
|
|
51
|
+
const fname = fitem[0]
|
|
52
|
+
const fopts = fitem[1]
|
|
53
|
+
if (fopts.active) {
|
|
54
|
+
featureAdd(this._rootctx, this._rootctx.config.makeFeature(fname))
|
|
55
|
+
}
|
|
56
|
+
})
|
|
39
57
|
|
|
40
|
-
if (null != this
|
|
41
|
-
for (let f of this
|
|
42
|
-
|
|
58
|
+
if (null != this._options.extend) {
|
|
59
|
+
for (let f of this._options.extend) {
|
|
60
|
+
featureAdd(this._rootctx, f)
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
for (let f of this._features) {
|
|
47
|
-
|
|
65
|
+
featureInit(this._rootctx, f)
|
|
48
66
|
}
|
|
49
67
|
|
|
50
|
-
const
|
|
51
|
-
|
|
68
|
+
const featureHook = this._utility.featureHook
|
|
69
|
+
featureHook(this._rootctx, 'PostConstruct')
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
|
|
55
73
|
options() {
|
|
56
|
-
return
|
|
74
|
+
return this._utility.struct.clone(this._options)
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
|
|
60
78
|
utility() {
|
|
61
|
-
return
|
|
79
|
+
return this._utility.struct.clone(this._utility)
|
|
80
|
+
}
|
|
81
|
+
|
|
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
|
+
}
|
|
62
176
|
}
|
|
63
177
|
|
|
64
178
|
|
|
65
179
|
// <[SLOT]>
|
|
66
180
|
|
|
67
181
|
|
|
68
|
-
static test(
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
182
|
+
static test(testoptsarg?: any, sdkoptsarg?: any) {
|
|
183
|
+
const struct = stdutil.struct
|
|
184
|
+
const setpath = struct.setpath
|
|
185
|
+
const getdef = struct.getdef
|
|
186
|
+
const clone = struct.clone
|
|
187
|
+
const setprop = struct.setprop
|
|
188
|
+
|
|
189
|
+
const sdkopts = getdef(clone(sdkoptsarg), {})
|
|
190
|
+
const testopts = getdef(clone(testoptsarg), {})
|
|
191
|
+
setprop(testopts, 'active', true)
|
|
192
|
+
setpath(sdkopts, 'feature.test', testopts)
|
|
72
193
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
sdkopts.feature.test = testopts || {}
|
|
76
|
-
sdkopts.feature.test.active = true
|
|
194
|
+
const testsdk = new ProjectNameSDK(sdkopts)
|
|
195
|
+
testsdk._mode = 'test'
|
|
77
196
|
|
|
78
|
-
return
|
|
197
|
+
return testsdk
|
|
79
198
|
}
|
|
80
199
|
|
|
81
200
|
|
|
@@ -83,6 +202,19 @@ class ProjectNameSDK {
|
|
|
83
202
|
return ProjectNameSDK.test(testopts, sdkopts)
|
|
84
203
|
}
|
|
85
204
|
|
|
205
|
+
|
|
206
|
+
toJSON() {
|
|
207
|
+
return { name: 'ProjectName' }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
toString() {
|
|
211
|
+
return 'ProjectName ' + this._utility.struct.jsonify(this.toJSON())
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
[inspect.custom]() {
|
|
215
|
+
return this.toString()
|
|
216
|
+
}
|
|
217
|
+
|
|
86
218
|
}
|
|
87
219
|
|
|
88
220
|
|
|
@@ -91,11 +223,11 @@ class ProjectNameEntity {
|
|
|
91
223
|
}
|
|
92
224
|
|
|
93
225
|
|
|
94
|
-
|
|
95
226
|
const SDK = ProjectNameSDK
|
|
96
227
|
|
|
228
|
+
|
|
97
229
|
export {
|
|
98
|
-
|
|
230
|
+
stdutil,
|
|
99
231
|
|
|
100
232
|
BaseFeature,
|
|
101
233
|
ProjectNameEntity,
|
|
@@ -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,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"noEmitOnError": true,
|
|
6
|
+
"outDir":"../dist",
|
|
7
|
+
"rootDir":".",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"target": "es2022",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "../dist"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,10 +1,64 @@
|
|
|
1
1
|
|
|
2
|
+
import * as Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
clone,
|
|
7
|
+
walk,
|
|
8
|
+
} from '@voxgig/struct'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function projectPath(suffix?: string): string {
|
|
12
|
+
return Path.normalize(Path.join(__dirname, '../../..', suffix ?? ''))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
2
16
|
function formatJSONSrc(jsonsrc: string) {
|
|
3
17
|
return jsonsrc
|
|
4
18
|
.replace(/([{:\[,])/g, '$1 ')
|
|
5
19
|
.replace(/([}\]])/g, ' $1')
|
|
6
20
|
}
|
|
7
21
|
|
|
22
|
+
|
|
23
|
+
function formatJson(obj: any, flags?: { line?: boolean, margin?: number }): string {
|
|
24
|
+
const marginSize = flags?.margin ?? 0
|
|
25
|
+
const marginStr = ' '.repeat(marginSize)
|
|
26
|
+
|
|
27
|
+
let json: string
|
|
28
|
+
|
|
29
|
+
if (flags?.line) {
|
|
30
|
+
// One line with spaces for clarity
|
|
31
|
+
json = JSON.stringify(obj)
|
|
32
|
+
.replace(/([{:\[,])/g, '$1 ')
|
|
33
|
+
.replace(/([}\]])/g, ' $1')
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Pretty printed with 2-space indentation
|
|
37
|
+
json = JSON.stringify(obj, null, 2)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Add margin to the left of every line
|
|
41
|
+
if (marginSize > 0) {
|
|
42
|
+
json = json.split('\n').map(line => marginStr + line).join('\n')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return json
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function clean(o: any) {
|
|
50
|
+
return walk(clone(o), (k: any, v: any, p: any) => {
|
|
51
|
+
if (null != k && k.endsWith('$')) {
|
|
52
|
+
delete p[k]
|
|
53
|
+
}
|
|
54
|
+
return v
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
8
59
|
export {
|
|
9
|
-
|
|
60
|
+
clean,
|
|
61
|
+
formatJSONSrc,
|
|
62
|
+
formatJson,
|
|
63
|
+
projectPath,
|
|
10
64
|
}
|
|
@@ -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
|
+
}
|