@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
|
@@ -5,6 +5,9 @@ import type { ProjectNameSDK } from '../../ProjectNameSDK'
|
|
|
5
5
|
import { BaseFeature } from '../base/BaseFeature'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
const S_NOT_FOUND = 'Not found'
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
class TestFeature extends BaseFeature {
|
|
9
12
|
version = '0.0.1'
|
|
10
13
|
name = 'test'
|
|
@@ -18,137 +21,188 @@ class TestFeature extends BaseFeature {
|
|
|
18
21
|
this._client = ctx.client
|
|
19
22
|
this._options = options
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
24
|
+
const struct = ctx.utility.struct
|
|
25
|
+
const walk = struct.walk
|
|
26
|
+
const size = struct.size
|
|
27
|
+
const setprop = struct.setprop
|
|
25
28
|
|
|
26
29
|
const entity = this._options.entity
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
this._client._mode = 'test'
|
|
32
|
+
|
|
33
|
+
// Ensure entity ids are correct.
|
|
34
|
+
walk(entity, (k: any, v: any, _parent: any, path: any) => {
|
|
30
35
|
if (2 === size(path)) {
|
|
31
36
|
setprop(v, 'id', k)
|
|
32
37
|
}
|
|
33
38
|
return v
|
|
34
39
|
})
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
const self = this
|
|
42
|
+
|
|
43
|
+
function testFetcher(ctx: any, _fullurl: string, _fetchdef: any) {
|
|
44
|
+
const struct = ctx.utility.struct
|
|
45
|
+
const param = ctx.utility.param
|
|
46
|
+
|
|
47
|
+
const getprop = struct.getprop
|
|
48
|
+
const clone = struct.clone
|
|
49
|
+
const merge = struct.merge
|
|
50
|
+
const getelem = struct.getelem
|
|
51
|
+
const select = struct.select
|
|
52
|
+
const delprop = struct.delprop
|
|
53
|
+
const getdef = struct.getdef
|
|
54
|
+
|
|
55
|
+
function respond(status: number, data?: any, res?: any) {
|
|
56
|
+
const out = merge([
|
|
57
|
+
{
|
|
58
|
+
status,
|
|
59
|
+
statusText: 'OK',
|
|
60
|
+
json: async () => data,
|
|
61
|
+
body: 'not-used',
|
|
62
|
+
},
|
|
63
|
+
getdef(res, {})
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
const headers: any = getprop(out, 'headers', {})
|
|
67
|
+
|
|
68
|
+
// JS specific iterator.
|
|
69
|
+
out.headers = {
|
|
70
|
+
forEach(callback: any) {
|
|
71
|
+
Object.keys(headers).forEach((key) => {
|
|
72
|
+
callback(headers[key], key, this)
|
|
73
|
+
})
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
return out
|
|
62
75
|
}
|
|
63
76
|
|
|
77
|
+
return out
|
|
78
|
+
}
|
|
64
79
|
|
|
65
|
-
const op = ctx.op
|
|
66
|
-
const entmap = entity[op.entity]
|
|
67
|
-
|
|
68
|
-
const qand: any[] = []
|
|
69
|
-
const q = { '`$AND`': qand }
|
|
70
|
-
|
|
71
|
-
for (let k of keysof(ctx.reqmatch)) {
|
|
72
|
-
const v = findparam(ctx, k)
|
|
73
|
-
const ka = getprop(op.alias, k)
|
|
74
|
-
|
|
75
|
-
let qor: any = [{ [k]: v }]
|
|
76
|
-
if (null != ka) {
|
|
77
|
-
qor.push({ [ka]: v })
|
|
78
|
-
}
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
const op = ctx.op
|
|
82
|
+
const entmap = getprop(entity, op.entity, {})
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
if ('load' === op.name) {
|
|
85
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
86
|
+
const found = select(entmap, args)
|
|
87
|
+
const ent = getelem(found, 0)
|
|
88
|
+
if (null == ent) {
|
|
89
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
83
90
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
else {
|
|
92
|
+
delprop(ent, '$KEY')
|
|
93
|
+
const out = clone(ent)
|
|
94
|
+
return respond(200, out)
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
delprop(ent, '$KEY')
|
|
97
|
-
return respond(200, clone(ent))
|
|
98
|
-
}
|
|
96
|
+
}
|
|
97
|
+
else if ('list' === op.name) {
|
|
98
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
99
|
+
const found = select(entmap, args)
|
|
100
|
+
if (null == found) {
|
|
101
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
99
102
|
}
|
|
100
|
-
else
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
found.map((ent: any) => delprop(ent, '$KEY'))
|
|
107
|
-
return respond(200, clone(found))
|
|
108
|
-
}
|
|
103
|
+
else {
|
|
104
|
+
found.map((ent: any) => delprop(ent, '$KEY'))
|
|
105
|
+
const out = clone(found)
|
|
106
|
+
return respond(200, out)
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
merge([ent, (ctx.reqdata || {})])
|
|
118
|
-
delprop(ent, '$KEY')
|
|
119
|
-
return respond(200, clone(ent))
|
|
120
|
-
}
|
|
108
|
+
}
|
|
109
|
+
else if ('update' === op.name) {
|
|
110
|
+
const args = self.buildArgs(ctx, op, ctx.reqdata)
|
|
111
|
+
const found = select(entmap, args)
|
|
112
|
+
const ent = getelem(found, 0)
|
|
113
|
+
if (null == ent) {
|
|
114
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
121
115
|
}
|
|
122
|
-
else
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
delprop(entmap, getprop(ent, 'id'))
|
|
130
|
-
return respond(200)
|
|
131
|
-
}
|
|
116
|
+
else {
|
|
117
|
+
merge([ent, (ctx.reqdata || {})])
|
|
118
|
+
delprop(ent, '$KEY')
|
|
119
|
+
const out = clone(ent)
|
|
120
|
+
return respond(200, out)
|
|
132
121
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
}
|
|
123
|
+
else if ('remove' === op.name) {
|
|
124
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
125
|
+
const found = select(entmap, args)
|
|
126
|
+
const ent = getelem(found, 0)
|
|
127
|
+
if (null == ent) {
|
|
128
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
delprop(entmap, getprop(ent, 'id'))
|
|
132
|
+
return respond(200)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if ('create' === op.name) {
|
|
136
|
+
const args = self.buildArgs(ctx, op, ctx.reqdata)
|
|
137
|
+
let id = param(ctx, 'id')
|
|
138
|
+
if (null == id) {
|
|
139
|
+
id = ((1e4 * Math.random() | 0).toString(16) +
|
|
140
|
+
(1e4 * Math.random() | 0).toString(16) +
|
|
141
|
+
(1e4 * Math.random() | 0).toString(16) +
|
|
142
|
+
(1e4 * Math.random() | 0).toString(16)).padEnd(16, '0')
|
|
145
143
|
}
|
|
144
|
+
|
|
145
|
+
const ent = clone(ctx.reqdata)
|
|
146
|
+
setprop(ent, 'id', id)
|
|
147
|
+
setprop(entmap, id, ent)
|
|
148
|
+
delprop(ent, '$KEY')
|
|
149
|
+
const out = clone(ent)
|
|
150
|
+
return respond(200, out)
|
|
146
151
|
}
|
|
147
152
|
}
|
|
153
|
+
|
|
154
|
+
ctx.utility.fetcher = testFetcher
|
|
148
155
|
}
|
|
149
|
-
}
|
|
150
156
|
|
|
151
157
|
|
|
158
|
+
buildArgs(ctx: any, op: any, args: any): any {
|
|
159
|
+
const struct = ctx.utility.struct
|
|
160
|
+
const param = ctx.utility.param
|
|
161
|
+
|
|
162
|
+
const getprop = struct.getprop
|
|
163
|
+
const keysof = struct.keysof
|
|
164
|
+
const getpath = struct.getpath
|
|
165
|
+
const getelem = struct.getelem
|
|
166
|
+
const select = struct.select
|
|
167
|
+
const transform = struct.transform
|
|
168
|
+
const isempty = struct.isempty
|
|
169
|
+
|
|
170
|
+
const opname = getprop(op, 'name')
|
|
171
|
+
const target =
|
|
172
|
+
getelem(getpath(ctx.config, [
|
|
173
|
+
'entity', getprop(ctx.entity, 'name'), 'op', opname, 'targets']), -1)
|
|
174
|
+
|
|
175
|
+
const reqd = transform(
|
|
176
|
+
select(getpath(target, ['args', 'params']), { reqd: true }),
|
|
177
|
+
['`$EACH`', '', '`$KEY.name`']
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const qand: any[] = []
|
|
181
|
+
const q = { '`$AND`': qand }
|
|
182
|
+
|
|
183
|
+
for (let k of keysof(args)) {
|
|
184
|
+
if ('id' === k || !isempty(select(reqd, k))) {
|
|
185
|
+
const v = param(ctx, k)
|
|
186
|
+
const ka = getprop(op.alias, k)
|
|
187
|
+
|
|
188
|
+
let qor: any = [{ [k]: v }]
|
|
189
|
+
if (null != ka) {
|
|
190
|
+
qor.push({ [ka]: v })
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
qor = { '`$OR`': qor }
|
|
194
|
+
|
|
195
|
+
qand.push(qor)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (ctx.ctrl.explain) {
|
|
200
|
+
ctx.ctrl.explain.test = { query: q }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return q
|
|
204
|
+
}
|
|
205
|
+
}
|
|
152
206
|
|
|
153
207
|
|
|
154
208
|
export {
|
|
@@ -1,79 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import { ProjectNameSDK } from './ProjectNameSDK'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
result: Result
|
|
12
|
-
utility: Utility
|
|
13
|
-
entopts: any
|
|
14
|
-
options: any
|
|
15
|
-
config: any
|
|
16
|
-
response: any
|
|
17
|
-
entity: any
|
|
18
|
-
data: any
|
|
19
|
-
match: any
|
|
20
|
-
reqdata: any
|
|
21
|
-
reqmatch: any
|
|
22
|
-
work: any
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type Operation = {
|
|
27
|
-
kind: string
|
|
28
|
-
entity: string
|
|
29
|
-
name: string
|
|
30
|
-
path: string
|
|
31
|
-
pathalt: ({ path: string } & Record<string, boolean>)[],
|
|
32
|
-
params: string[],
|
|
33
|
-
alias: Record<string, string>
|
|
34
|
-
state: Record<string, any>
|
|
35
|
-
reqform: any
|
|
36
|
-
resform: any
|
|
37
|
-
validate: {
|
|
38
|
-
params: Record<string, any>
|
|
39
|
-
}
|
|
40
|
-
check: Record<string, any>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type Spec = {
|
|
45
|
-
headers: Record<string, string>
|
|
46
|
-
alias: any
|
|
47
|
-
base: string
|
|
48
|
-
prefix: string
|
|
49
|
-
suffix: string
|
|
50
|
-
params: Record<string, string>
|
|
51
|
-
query: Record<string, string>
|
|
52
|
-
step: string
|
|
53
|
-
method: string
|
|
54
|
-
body: any
|
|
55
|
-
path: string
|
|
56
|
-
url?: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
type Result = {
|
|
61
|
-
ok: boolean
|
|
62
|
-
status: number
|
|
63
|
-
statusText: string
|
|
64
|
-
headers: Record<string, string>
|
|
65
|
-
body?: any
|
|
66
|
-
err?: any
|
|
67
|
-
resdata?: any
|
|
68
|
-
resmatch?: any
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
type Control = {
|
|
73
|
-
throw?: boolean
|
|
74
|
-
err?: any
|
|
75
|
-
explain?: any
|
|
76
|
-
}
|
|
4
|
+
import { Target } from './Target'
|
|
5
|
+
import { Context } from './Context'
|
|
6
|
+
import { Control } from './Control'
|
|
7
|
+
import { Operation } from './Operation'
|
|
8
|
+
import { Response } from './Response'
|
|
9
|
+
import { Result } from './Result'
|
|
10
|
+
import { Spec } from './Spec'
|
|
77
11
|
|
|
78
12
|
|
|
79
13
|
type FeatureOptions = Record<string, any> | {
|
|
@@ -94,7 +28,7 @@ interface Feature {
|
|
|
94
28
|
GetData: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
95
29
|
GetMatch: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
96
30
|
|
|
97
|
-
|
|
31
|
+
PreTarget: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
98
32
|
PreSpec: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
99
33
|
PreRequest: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
100
34
|
PreResponse: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
@@ -103,12 +37,18 @@ interface Feature {
|
|
|
103
37
|
}
|
|
104
38
|
|
|
105
39
|
|
|
106
|
-
|
|
107
|
-
|
|
40
|
+
export {
|
|
41
|
+
Target,
|
|
108
42
|
Context,
|
|
43
|
+
Control,
|
|
109
44
|
Operation,
|
|
45
|
+
Response,
|
|
46
|
+
Result,
|
|
110
47
|
Spec,
|
|
111
|
-
|
|
112
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export type {
|
|
113
52
|
Feature,
|
|
53
|
+
FeatureOptions,
|
|
114
54
|
}
|
|
@@ -3,45 +3,31 @@ import { Context } from '../types'
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
walk,
|
|
6
|
+
walk, size, pad, slice, clone
|
|
7
7
|
} from './StructUtility'
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// Clean request data by partially hiding sensitive values.
|
|
11
11
|
function clean(ctx: Context, val: any) {
|
|
12
12
|
const options = ctx.options
|
|
13
|
-
const work = ctx.work
|
|
14
|
-
|
|
15
|
-
let cleaners = getprop(work, 'cleaners')
|
|
16
|
-
|
|
17
|
-
if (null == cleaners) {
|
|
18
|
-
cleaners =
|
|
19
|
-
[
|
|
20
|
-
{ p: 'apikey', s: 4 }
|
|
21
|
-
]
|
|
22
|
-
.map((p: any) => (p.v = getpath(options, p.p), p))
|
|
23
|
-
.filter(p => null != p.v && 'string' === typeof p.v)
|
|
24
|
-
.map(
|
|
25
|
-
p => (
|
|
26
|
-
p.re = new RegExp(escre(p.v)),
|
|
27
|
-
p.v = pad(slice(p.v, 0, p.s), size(p.v), '*'),
|
|
28
|
-
p
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setprop(work, 'cleaners', cleaners)
|
|
34
13
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
14
|
+
const cleankeyre = options.__derived__.clean.keyre
|
|
15
|
+
const hintsize = 4
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
if (null != cleankeyre) {
|
|
19
|
+
val = walk(clone(val), (key: any, subval: any) => {
|
|
20
|
+
if (cleankeyre.exec(key) && 'string' === typeof subval) {
|
|
21
|
+
const len = size(subval)
|
|
22
|
+
const hint = (hintsize * 4) < len ? slice(subval, 0, hintsize) : ''
|
|
23
|
+
subval = pad(hint, len, '*')
|
|
24
|
+
}
|
|
25
|
+
return subval
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
*/
|
|
43
29
|
|
|
44
|
-
return
|
|
30
|
+
return val
|
|
45
31
|
}
|
|
46
32
|
|
|
47
33
|
|
|
@@ -4,18 +4,17 @@ import { Context } from '../types'
|
|
|
4
4
|
|
|
5
5
|
import { clean } from './CleanUtility'
|
|
6
6
|
|
|
7
|
-
import { delprop } from './StructUtility'
|
|
8
|
-
|
|
9
7
|
|
|
10
8
|
function done(ctx: Context) {
|
|
11
|
-
const
|
|
9
|
+
const error = ctx.utility.makeError
|
|
10
|
+
const delprop = ctx.utility.struct.delprop
|
|
12
11
|
|
|
13
12
|
if (ctx.ctrl.explain) {
|
|
14
13
|
ctx.ctrl.explain = clean(ctx, ctx.ctrl.explain)
|
|
15
14
|
delprop(ctx.ctrl.explain.result, 'err')
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
if (ctx.result.ok) {
|
|
17
|
+
if (ctx.result && ctx.result.ok) {
|
|
19
18
|
return ctx.result.resdata
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Context, Feature } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function featureAdd(ctx: Context, f: Feature) {
|
|
6
6
|
const client = ctx.client
|
|
7
7
|
const struct = ctx.utility.struct
|
|
8
8
|
const setprop = struct.setprop
|
|
@@ -43,5 +43,5 @@ function addfeature(ctx: Context, f: Feature) {
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
export {
|
|
46
|
-
|
|
46
|
+
featureAdd
|
|
47
47
|
}
|
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
import { Context, Feature } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function featureHook(ctx: Context, name: string) {
|
|
6
6
|
const client = ctx.client
|
|
7
7
|
|
|
8
8
|
let resp: Promise<any>[] = []
|
|
9
9
|
const features: Feature[] = client._features || []
|
|
10
10
|
|
|
11
11
|
for (let f of features) {
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
12
|
+
const fh = (f as any)[name]
|
|
13
|
+
if (null != fh) {
|
|
14
|
+
const fres = fh(ctx)
|
|
15
|
+
if (fres instanceof Promise) {
|
|
16
|
+
resp.push(fres)
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -22,5 +25,5 @@ function featurehook(ctx: Context, name: string) {
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
export {
|
|
25
|
-
|
|
28
|
+
featureHook
|
|
26
29
|
}
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Context, Response } from '../types'
|
|
3
3
|
|
|
4
4
|
// Make HTTP call using library. Replace this utility for mocking etc.
|
|
5
|
-
async function fetcher(
|
|
5
|
+
async function fetcher(
|
|
6
|
+
ctx: Context,
|
|
7
|
+
fullurl: string,
|
|
8
|
+
fetchdef: Record<string, any>
|
|
9
|
+
): Promise<Response | Error> {
|
|
10
|
+
|
|
11
|
+
if ('live' !== ctx.client._mode) {
|
|
12
|
+
return ctx.error('fetch_mode_block', 'Request blocked by mode: "' + ctx.client._mode +
|
|
13
|
+
'" (URL was: "' + fullurl + '")')
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
const options = ctx.client.options()
|
|
17
|
+
|
|
18
|
+
const getpath = ctx.utility.struct.getpath
|
|
19
|
+
|
|
20
|
+
if (true === getpath(options, 'feature.test.active')) {
|
|
21
|
+
return ctx.error('fetch_test_block', 'Request blocked as test feature is active' +
|
|
22
|
+
' (URL was: "' + fullurl + '")')
|
|
23
|
+
}
|
|
24
|
+
|
|
7
25
|
const fetch = options.system.fetch
|
|
8
26
|
|
|
9
27
|
const response = await fetch(fullurl, fetchdef)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { ProjectNameSDK } from '../ProjectNameSDK'
|
|
3
|
+
|
|
4
|
+
import { Utility } from './Utility'
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
Operation,
|
|
8
|
+
Spec,
|
|
9
|
+
Response,
|
|
10
|
+
Result,
|
|
11
|
+
} from '../types'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
Context
|
|
15
|
+
} from '../types'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function makeContext(ctxmap: Record<string, any>, basectx?: Context): any {
|
|
19
|
+
const ctx = new Context(ctxmap, basectx)
|
|
20
|
+
return ctx
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
makeContext,
|
|
27
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Result, Context } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
import { clean } from './CleanUtility'
|
|
@@ -7,21 +7,25 @@ import { clean } from './CleanUtility'
|
|
|
7
7
|
import { clone, delprop } from './StructUtility'
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
function
|
|
10
|
+
function makeError(ctx: Context, err?: any) {
|
|
11
11
|
|
|
12
12
|
ctx = ctx || {}
|
|
13
13
|
const op = ctx.op || {}
|
|
14
14
|
op.name = op.name || 'unknown operation'
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
const result = ctx.result || new Result({})
|
|
17
18
|
result.ok = false
|
|
18
19
|
|
|
19
20
|
const reserr = result.err
|
|
20
21
|
|
|
21
22
|
err = undefined === err ? reserr : err
|
|
22
|
-
err = err ||
|
|
23
|
+
err = err || ctx.error('unknown', 'unknown error')
|
|
23
24
|
|
|
24
25
|
const errmsg = err.message || 'unknown error'
|
|
26
|
+
// TODO: project name should come from config
|
|
27
|
+
// avoids spurious changes between template and generated utility
|
|
28
|
+
// applies for all utility files
|
|
25
29
|
const msg = 'ProjectNameSDK: ' + op.name + ': ' + errmsg
|
|
26
30
|
err.message = clean(ctx, msg)
|
|
27
31
|
|
|
@@ -46,7 +50,7 @@ function error(ctx: Context, err?: any) {
|
|
|
46
50
|
|
|
47
51
|
// TODO: model option to return instead
|
|
48
52
|
if (false === ctx.ctrl.throw) {
|
|
49
|
-
return
|
|
53
|
+
return result.resdata
|
|
50
54
|
}
|
|
51
55
|
else {
|
|
52
56
|
throw err
|
|
@@ -55,5 +59,5 @@ function error(ctx: Context, err?: any) {
|
|
|
55
59
|
|
|
56
60
|
|
|
57
61
|
export {
|
|
58
|
-
|
|
62
|
+
makeError
|
|
59
63
|
}
|