@voxgig/sdkgen 0.24.0 → 0.26.1
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/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- 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 +8 -8
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +2 -2
- package/project/.sdk/model/feature/test.jsonic +7 -2
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +2 -2
- 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/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 +22 -12
- package/project/.sdk/src/cmp/ts/Package_ts.ts +32 -12
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +341 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +21 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- 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 +50 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +70 -34
- 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/ts/src/feature/test/TestFeature.ts +158 -104
- package/project/.sdk/tm/ts/src/types.ts +164 -34
- package/project/.sdk/tm/ts/src/utility/AuthUtility.ts +8 -2
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +9 -6
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +14 -54
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ErrorUtility.ts +7 -3
- package/project/.sdk/tm/ts/src/utility/FeaturehookUtility.ts +8 -5
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +18 -2
- package/project/.sdk/tm/ts/src/utility/FindparamUtility.ts +12 -5
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +21 -5
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +3 -1
- package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +23 -0
- package/project/.sdk/tm/ts/src/utility/OptionsUtility.ts +25 -3
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +10 -10
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +18 -0
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/ReqformUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +20 -3
- package/project/.sdk/tm/ts/src/utility/ResbasicUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +5 -3
- package/project/.sdk/tm/ts/src/utility/ResformUtility.ts +3 -3
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +9 -7
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +35 -4
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +24 -4
- package/project/.sdk/tm/ts/src/utility/SelectionUtility.ts +78 -0
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +34 -27
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1117 -509
- package/project/.sdk/tm/ts/src/utility/Utility.ts +10 -8
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +12 -10
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +53 -47
- 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/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +4 -0
- 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/OperatorUtility.ts +0 -90
|
@@ -3,15 +3,15 @@ import { Context } from '../types'
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function options(ctx: Context) {
|
|
6
|
-
const
|
|
6
|
+
const utility = ctx.utility
|
|
7
|
+
const options = ctx.options
|
|
7
8
|
const struct = utility.struct
|
|
8
|
-
const setprop = struct.setprop
|
|
9
9
|
|
|
10
10
|
let opts = { ...(options || {}) }
|
|
11
11
|
|
|
12
12
|
const customUtils = opts.utility || {}
|
|
13
13
|
for (let key of Object.keys(customUtils)) {
|
|
14
|
-
setprop(utility, key, customUtils[key])
|
|
14
|
+
struct.setprop(utility, key, customUtils[key])
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const { merge, validate } = utility.struct
|
|
@@ -31,6 +31,10 @@ function options(ctx: Context) {
|
|
|
31
31
|
headers: {
|
|
32
32
|
'`$CHILD`': '`$STRING`'
|
|
33
33
|
},
|
|
34
|
+
allow: {
|
|
35
|
+
method: 'GET,PUT,POST,PATCH,DELETE,OPTIONS',
|
|
36
|
+
op: 'create,update,load,list,remove,command,direct'
|
|
37
|
+
},
|
|
34
38
|
entity: {
|
|
35
39
|
'`$CHILD`': {
|
|
36
40
|
'`$OPEN`': true,
|
|
@@ -53,6 +57,9 @@ function options(ctx: Context) {
|
|
|
53
57
|
entity: {
|
|
54
58
|
'`$OPEN`': true,
|
|
55
59
|
}
|
|
60
|
+
},
|
|
61
|
+
clean: {
|
|
62
|
+
keys: 'key,token,id'
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
|
|
@@ -63,6 +70,21 @@ function options(ctx: Context) {
|
|
|
63
70
|
|
|
64
71
|
opts = validate(opts, optspec)
|
|
65
72
|
|
|
73
|
+
opts.__derived__ = {
|
|
74
|
+
clean: {
|
|
75
|
+
keyre: undefined
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const keyre = opts.clean.keys
|
|
80
|
+
.split(/\s*,\s*/)
|
|
81
|
+
.filter((s: string) => null != s && '' !== s)
|
|
82
|
+
.map((key: string) => struct.escre(key)).join('|')
|
|
83
|
+
|
|
84
|
+
if ('' != keyre) {
|
|
85
|
+
opts.__derived__.clean.keyre = keyre
|
|
86
|
+
}
|
|
87
|
+
|
|
66
88
|
return opts
|
|
67
89
|
}
|
|
68
90
|
|
|
@@ -6,26 +6,26 @@ function params(ctx: Context) {
|
|
|
6
6
|
const utility = ctx.utility
|
|
7
7
|
const findparam = utility.findparam
|
|
8
8
|
|
|
9
|
-
const struct = utility.struct
|
|
10
|
-
const { validate } = struct
|
|
9
|
+
// const struct = utility.struct
|
|
10
|
+
// const { validate } = struct
|
|
11
11
|
|
|
12
|
+
const alt = ctx.alt
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
let param = alt.args.param
|
|
15
|
+
let reqmatch = ctx.reqmatch
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
let { reqmatch } = ctx
|
|
17
|
-
|
|
18
|
-
params = params || []
|
|
17
|
+
param = param || []
|
|
19
18
|
reqmatch = reqmatch || {}
|
|
20
19
|
|
|
21
20
|
let out: any = {}
|
|
22
|
-
for (let
|
|
23
|
-
let val = findparam(ctx,
|
|
21
|
+
for (let pd of param) {
|
|
22
|
+
let val = findparam(ctx, pd)
|
|
24
23
|
if (null != val) {
|
|
25
|
-
out[
|
|
24
|
+
out[pd.name] = val
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
|
|
28
|
+
// TODO: review
|
|
29
29
|
// out = validate(out, op.validate.params)
|
|
30
30
|
|
|
31
31
|
return out
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
import { join } from './StructUtility'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function preparePath(ctx: Context) {
|
|
8
|
+
const { alt } = ctx
|
|
9
|
+
|
|
10
|
+
const path = join(alt.parts, '/', true)
|
|
11
|
+
|
|
12
|
+
return path
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
preparePath
|
|
18
|
+
}
|
|
@@ -6,7 +6,7 @@ import { Context } from '../types'
|
|
|
6
6
|
* The operation (op) property `reqform` is used to perform the data preparation.
|
|
7
7
|
*/
|
|
8
8
|
function reqform(ctx: Context) {
|
|
9
|
-
const { spec, utility } = ctx
|
|
9
|
+
const { spec, utility, alt } = ctx
|
|
10
10
|
const { struct, error } = utility
|
|
11
11
|
const { isfunc, transform } = struct
|
|
12
12
|
|
|
@@ -15,7 +15,7 @@ function reqform(ctx: Context) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
try {
|
|
18
|
-
const reqform =
|
|
18
|
+
const reqform = alt.transform.req
|
|
19
19
|
const reqdata = isfunc(reqform) ? reqform(ctx) : transform({
|
|
20
20
|
reqdata: ctx.reqdata
|
|
21
21
|
}, reqform)
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Context, Response } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
async function request(ctx: Context) {
|
|
5
|
+
async function request(ctx: Context): Promise<Response | Error> {
|
|
6
|
+
// PreRequest feature hook has already provided a result.
|
|
7
|
+
if (ctx.out.request) {
|
|
8
|
+
return ctx.out.request
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
const { spec, utility } = ctx
|
|
7
12
|
const { fullurl, fetcher } = utility
|
|
8
13
|
|
|
@@ -19,11 +24,20 @@ async function request(ctx: Context) {
|
|
|
19
24
|
|
|
20
25
|
ctx.result = result
|
|
21
26
|
|
|
27
|
+
if (null == spec) {
|
|
28
|
+
return new Error('Expected context spec property to be defined.')
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
|
|
23
32
|
try {
|
|
24
33
|
spec.step = 'prepare'
|
|
25
34
|
|
|
26
|
-
const url =
|
|
35
|
+
const url = fullurl(ctx)
|
|
36
|
+
if (url instanceof Error) {
|
|
37
|
+
throw url
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
spec.url = url
|
|
27
41
|
|
|
28
42
|
const fetchdef: any = {
|
|
29
43
|
method: spec.method,
|
|
@@ -47,6 +61,9 @@ async function request(ctx: Context) {
|
|
|
47
61
|
if (null == response) {
|
|
48
62
|
response = { err: new Error('response: undefined') }
|
|
49
63
|
}
|
|
64
|
+
else if (response instanceof Error) {
|
|
65
|
+
response = { err: response }
|
|
66
|
+
}
|
|
50
67
|
}
|
|
51
68
|
catch (err) {
|
|
52
69
|
response = response || {}
|
|
@@ -5,7 +5,7 @@ import { Context } from '../types'
|
|
|
5
5
|
function resbasic(ctx: Context) {
|
|
6
6
|
const { response, result } = ctx
|
|
7
7
|
|
|
8
|
-
if (null != response) {
|
|
8
|
+
if (null != result && null != response) {
|
|
9
9
|
result.status = response.status || -1
|
|
10
10
|
result.statusText = response.statusText || 'no-status'
|
|
11
11
|
|
|
@@ -5,9 +5,11 @@ import { Context } from '../types'
|
|
|
5
5
|
async function resbody(ctx: Context) {
|
|
6
6
|
const { response, result } = ctx
|
|
7
7
|
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (result) {
|
|
9
|
+
if (response && response.json && null != response.body) {
|
|
10
|
+
const json = await response.json()
|
|
11
|
+
result.body = json
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
return result
|
|
@@ -7,7 +7,7 @@ import { Context } from '../types'
|
|
|
7
7
|
* The operation (op) property `resform` is used to perform the data extraction.
|
|
8
8
|
*/
|
|
9
9
|
function resform(ctx: Context) {
|
|
10
|
-
const { spec, result, utility } = ctx
|
|
10
|
+
const { spec, result, utility, alt } = ctx
|
|
11
11
|
const { struct, error } = utility
|
|
12
12
|
const { isfunc, transform } = struct
|
|
13
13
|
|
|
@@ -15,12 +15,12 @@ function resform(ctx: Context) {
|
|
|
15
15
|
spec.step = 'resform'
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
if (!result.ok) {
|
|
18
|
+
if (null == result || !result.ok) {
|
|
19
19
|
return undefined
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
const resform =
|
|
23
|
+
const resform = alt.transform.res
|
|
24
24
|
const resdata = isfunc(resform) ? resform(ctx) : transform(ctx.result, resform)
|
|
25
25
|
result.resdata = resdata
|
|
26
26
|
return resdata
|
|
@@ -5,13 +5,15 @@ import { Context } from '../types'
|
|
|
5
5
|
function resheaders(ctx: Context) {
|
|
6
6
|
const { response, result } = ctx
|
|
7
7
|
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
if (result) {
|
|
9
|
+
if (response && response.headers && response.headers.forEach) {
|
|
10
|
+
const headers: any = {}
|
|
11
|
+
response.headers.forEach((v: any, k: any) => headers[k] = v)
|
|
12
|
+
result.headers = headers
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
result.headers = {}
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
return result
|
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Context, Response } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
async function response(ctx: Context) {
|
|
6
|
-
|
|
5
|
+
async function response(ctx: Context): Promise<Response | Error> {
|
|
6
|
+
// PreResponse feature hook has already provided a result.
|
|
7
|
+
if (ctx.out.response) {
|
|
8
|
+
return ctx.out.response
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const utility = ctx.utility
|
|
12
|
+
const resbasic = utility.resbasic
|
|
13
|
+
const resheaders = utility.resheaders
|
|
14
|
+
const resbody = utility.resbody
|
|
15
|
+
const resform = utility.resform
|
|
16
|
+
|
|
17
|
+
const spec = ctx.spec
|
|
18
|
+
const result = ctx.result
|
|
19
|
+
const response = ctx.response
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (null == spec) {
|
|
23
|
+
return new Error('Expected context spec property to be defined.')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (null == response) {
|
|
27
|
+
return new Error('Expected context response property to be defined.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (null == result) {
|
|
31
|
+
return new Error('Expected context result property to be defined.')
|
|
32
|
+
}
|
|
7
33
|
|
|
8
|
-
const { resheaders, resbasic, resbody, resform } = utility
|
|
9
34
|
|
|
10
35
|
spec.step = 'response'
|
|
11
36
|
|
|
@@ -22,6 +47,12 @@ async function response(ctx: Context) {
|
|
|
22
47
|
catch (err) {
|
|
23
48
|
result.err = err
|
|
24
49
|
}
|
|
50
|
+
|
|
51
|
+
if (ctx.ctrl.explain) {
|
|
52
|
+
ctx.ctrl.explain.result = result
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return response
|
|
25
56
|
}
|
|
26
57
|
|
|
27
58
|
|
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Result, Context } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
function result(ctx: Context): Result | Error {
|
|
6
|
+
// PreResult feature hook has already provided a result.
|
|
7
|
+
if (ctx.out.result) {
|
|
8
|
+
return ctx.out.result
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const utility = ctx.utility
|
|
12
|
+
const resform = utility.resform
|
|
13
|
+
|
|
14
|
+
const op = ctx.op
|
|
15
|
+
const entity = ctx.entity
|
|
16
|
+
|
|
17
|
+
const spec = ctx.spec
|
|
18
|
+
const result = ctx.result
|
|
7
19
|
|
|
8
|
-
|
|
20
|
+
if (null == spec) {
|
|
21
|
+
return new Error('Expected context spec property to be defined.')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (null == result) {
|
|
25
|
+
return new Error('Expected context result property to be defined.')
|
|
26
|
+
}
|
|
9
27
|
|
|
10
28
|
spec.step = 'result'
|
|
11
29
|
|
|
@@ -28,6 +46,8 @@ async function result(ctx: Context) {
|
|
|
28
46
|
ctx.ctrl.explain.result = result
|
|
29
47
|
}
|
|
30
48
|
|
|
49
|
+
// NOTE: returns processesd result.
|
|
50
|
+
return result
|
|
31
51
|
}
|
|
32
52
|
|
|
33
53
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context, Alt } from '../types'
|
|
3
|
+
|
|
4
|
+
import { getprop } from './StructUtility'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Ensure standard operation definition.
|
|
8
|
+
// TODO: rename to alt
|
|
9
|
+
function selection(ctx: Context): Alt | Error {
|
|
10
|
+
if (ctx.out.selected) {
|
|
11
|
+
return ctx.alt = ctx.out.selected
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { op, options } = ctx
|
|
15
|
+
|
|
16
|
+
if (!options.allow.op.includes(op.name)) {
|
|
17
|
+
return Error('Operation "' + op.name +
|
|
18
|
+
'" not allowed by SDK option allow.op value: "' + options.allow.op + '"')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Choose the appropriate operation alternate based on the match or data.
|
|
22
|
+
if (1 === op.alts.length) {
|
|
23
|
+
ctx.alt = op.alts[0]
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Operation argument has priority, but also look in current data or match.
|
|
27
|
+
const reqselector = getprop(ctx, 'req' + op.select)
|
|
28
|
+
const selector = getprop(ctx, op.select)
|
|
29
|
+
|
|
30
|
+
let alt
|
|
31
|
+
for (let i = 0; i < op.alts.length; i++) {
|
|
32
|
+
alt = op.alts[i]
|
|
33
|
+
const select = alt.select
|
|
34
|
+
let found = true
|
|
35
|
+
|
|
36
|
+
if (selector && select.exist) {
|
|
37
|
+
for (let j = 0; j < select.exist.length; j++) {
|
|
38
|
+
const existkey = select.exist[j]
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
undefined === getprop(reqselector, existkey)
|
|
42
|
+
&& undefined === getprop(selector, existkey)
|
|
43
|
+
) {
|
|
44
|
+
found = false
|
|
45
|
+
break
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Action is only in operation argument.
|
|
51
|
+
if (found && reqselector.$action !== select.$action) {
|
|
52
|
+
found = false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (found) {
|
|
56
|
+
break
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
null != reqselector.$action &&
|
|
62
|
+
null != alt &&
|
|
63
|
+
reqselector.$action !== alt.select.$action
|
|
64
|
+
) {
|
|
65
|
+
return Error('Operation "' + op.name +
|
|
66
|
+
'" action "' + reqselector.$action + '" is not valid.')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
ctx.alt = alt
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return ctx.alt
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
selection,
|
|
78
|
+
}
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
|
|
2
|
-
import { Context } from '../types'
|
|
2
|
+
import { Context, Spec } from '../types'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// Create request specificaton.
|
|
6
|
-
function spec(ctx: Context) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
6
|
+
function spec(ctx: Context): Spec | Error {
|
|
7
|
+
if (ctx.out.spec) {
|
|
8
|
+
return ctx.spec = ctx.out.spec
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const alt = ctx.alt
|
|
12
|
+
const options = ctx.options
|
|
13
|
+
const utility = ctx.utility
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
const method = utility.method
|
|
16
|
+
const params = utility.params
|
|
17
|
+
const query = utility.query
|
|
18
|
+
const headers = utility.headers
|
|
19
|
+
const body = utility.body
|
|
20
|
+
// TODO: rename others to prepareNAME
|
|
21
|
+
const preparePath = utility.preparePath
|
|
22
|
+
const auth = utility.auth
|
|
14
23
|
|
|
15
24
|
ctx.spec = {
|
|
16
25
|
base: options.base, // string, URL endpoint base prefix,
|
|
17
26
|
prefix: options.prefix,
|
|
18
|
-
path: op.path,
|
|
27
|
+
// path: op.path,
|
|
28
|
+
parts: alt.parts,
|
|
19
29
|
suffix: options.suffix,
|
|
20
|
-
method: '
|
|
30
|
+
method: 'GET',
|
|
21
31
|
params: {},
|
|
22
32
|
query: {},
|
|
23
33
|
headers: {},
|
|
@@ -27,32 +37,29 @@ function spec(ctx: Context) {
|
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
ctx.spec.method = method(ctx)
|
|
40
|
+
|
|
41
|
+
if (!options.allow.method.includes(ctx.spec.method)) {
|
|
42
|
+
return Error('Method "' + ctx.spec.method +
|
|
43
|
+
'" not allowed by SDK option allow.method value: "' + options.allow.method + '"')
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
ctx.spec.params = params(ctx)
|
|
31
47
|
ctx.spec.query = query(ctx)
|
|
32
48
|
ctx.spec.headers = headers(ctx)
|
|
33
49
|
ctx.spec.body = body(ctx)
|
|
34
|
-
|
|
35
|
-
if (1 < size(op.pathalt)) {
|
|
36
|
-
let hasQuery = false
|
|
37
|
-
const paramQuery: any = {}
|
|
38
|
-
for (let paramName of op.params) {
|
|
39
|
-
paramQuery[paramName] = null == ctx.spec.params[paramName] ? undefined : true
|
|
40
|
-
hasQuery = true
|
|
41
|
-
}
|
|
42
|
-
if (hasQuery) {
|
|
43
|
-
const foundParamAlts = select(op.pathalt, paramQuery)
|
|
44
|
-
console.log('PQ', paramQuery, foundParamAlts)
|
|
45
|
-
if (0 < size(foundParamAlts)) {
|
|
46
|
-
ctx.spec.path = foundParamAlts[0].path
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
+
ctx.spec.path = preparePath(ctx)
|
|
50
51
|
|
|
51
52
|
if (ctx.ctrl.explain) {
|
|
52
53
|
ctx.ctrl.explain.spec = ctx.spec
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
auth(ctx)
|
|
56
|
+
const spec = auth(ctx)
|
|
57
|
+
|
|
58
|
+
if (!(spec instanceof Error)) {
|
|
59
|
+
ctx.spec = spec
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return spec
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
|