@voxgig/sdkgen 0.22.0 → 0.23.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 +12 -4
- package/dist/action/action.d.ts +4 -0
- package/dist/action/action.js +35 -0
- package/dist/action/action.js.map +1 -0
- package/dist/action/feature.d.ts +4 -2
- package/dist/action/feature.js +57 -38
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.d.ts +4 -2
- package/dist/action/target.js +136 -45
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/Entity.js +5 -0
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +5 -0
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/Main.js +4 -1
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/Top.d.ts +2 -0
- package/dist/cmp/Top.js +23 -0
- package/dist/cmp/Top.js.map +1 -0
- package/dist/sdkgen.d.ts +10 -3
- package/dist/sdkgen.js +53 -8
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utility.d.ts +3 -3
- package/dist/utility.js +7 -8
- package/dist/utility.js.map +1 -1
- package/package.json +6 -10
- package/project/.sdk/model/feature/README.md +2 -0
- package/project/.sdk/model/feature/log.jsonic +7 -4
- package/project/.sdk/model/feature/test.jsonic +26 -0
- package/project/.sdk/model/target/ts.jsonic +1 -0
- package/project/.sdk/src/cmp/ts/Config_ts.ts +7 -2
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +67 -0
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +180 -0
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +41 -66
- package/project/.sdk/src/cmp/ts/MainEntity_ts.ts +22 -0
- package/project/.sdk/src/cmp/ts/Main_ts.ts +52 -53
- package/project/.sdk/src/cmp/ts/Package_ts.ts +12 -7
- package/project/.sdk/src/cmp/ts/ReadmeInstall_ts.ts +19 -0
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +24 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +13 -0
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +19 -0
- package/project/.sdk/src/cmp/ts/Test_ts.ts +20 -0
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +8 -1
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +164 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +37 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +91 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +92 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +96 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +96 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +95 -0
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +107 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +10 -0
- package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +43 -0
- package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +109 -0
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +159 -0
- package/project/.sdk/tm/ts/src/tsconfig.json +1 -1
- package/project/.sdk/tm/ts/src/types.ts +114 -0
- package/project/.sdk/tm/ts/src/utility/AddfeatureUtility.ts +47 -0
- package/project/.sdk/tm/ts/src/utility/AuthUtility.ts +42 -0
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +50 -0
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +67 -0
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +28 -0
- package/project/.sdk/tm/ts/src/utility/ErrorUtility.ts +59 -0
- package/project/.sdk/tm/ts/src/utility/FeaturehookUtility.ts +26 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +17 -0
- package/project/.sdk/tm/ts/src/utility/FindparamUtility.ts +54 -0
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/HeadersUtility.ts +24 -0
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +13 -0
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +15 -0
- package/project/.sdk/tm/ts/src/utility/MethodUtility.ts +25 -0
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +90 -0
- package/project/.sdk/tm/ts/src/utility/OptionsUtility.ts +72 -0
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +37 -0
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +27 -0
- package/project/.sdk/tm/ts/src/utility/ReqformUtility.ts +33 -0
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +66 -0
- package/project/.sdk/tm/ts/src/utility/ResbasicUtility.ts +34 -0
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +19 -0
- package/project/.sdk/tm/ts/src/utility/ResformUtility.ts +36 -0
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +23 -0
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +36 -0
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +2499 -0
- package/project/.sdk/tm/ts/src/utility/Utility.ts +88 -0
- package/project/.sdk/tm/ts/test/exists.test.ts +17 -0
- package/project/.sdk/tm/ts/test/runner.ts +402 -0
- package/project/.sdk/tm/ts/test/tsconfig.json +1 -1
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +62 -0
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +244 -0
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +678 -0
- package/project/.sdk/tm/ts/test/utility/index.ts +9 -0
- package/project/.sdk/tm/ts/test/utility.ts +86 -0
- package/src/action/action.ts +54 -0
- package/src/action/feature.ts +83 -47
- package/src/action/target.ts +173 -53
- package/src/cmp/Entity.ts +6 -0
- package/src/cmp/Feature.ts +6 -3
- package/src/cmp/Main.ts +4 -1
- package/src/sdkgen.ts +86 -11
- package/src/types.ts +33 -0
- package/src/utility.ts +5 -3
- package/project/.sdk/model/feature/limit.jsonic +0 -12
- package/project/.sdk/model/feature/page.jsonic +0 -9
- package/project/.sdk/model/feature/telemetry.jsonic +0 -10
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.js +0 -79
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.js +0 -61
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.js +0 -57
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.js +0 -61
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.js +0 -61
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.js +0 -61
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.js +0 -67
- package/project/.sdk/tm/ts/test/README.md~ +0 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
walk, getpath, escre, getprop, size, pad, slice, setprop, clone
|
|
7
|
+
} from './StructUtility'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// Clean request data by partially hiding sensitive values.
|
|
11
|
+
function clean(ctx: Context, val: any) {
|
|
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
|
+
|
|
35
|
+
const out = walk(clone(val), (_k: any, v: any) => {
|
|
36
|
+
if ('string' === typeof v) {
|
|
37
|
+
cleaners.map((p: any) => {
|
|
38
|
+
v = v.replace(p.re, p.v)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
return v
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return out
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
clean
|
|
50
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
import { getprop } from './StructUtility'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function contextify(ctxmap: Record<string, any>, basectx?: Context): any {
|
|
6
|
+
const ctx = new Context()
|
|
7
|
+
|
|
8
|
+
ctx.ctrl = getprop(ctxmap, 'ctrl', getprop(basectx, 'ctrl', {}))
|
|
9
|
+
ctx.meta = getprop(ctxmap, 'meta', getprop(basectx, 'meta', {}))
|
|
10
|
+
ctx.work = getprop(ctxmap, 'work', getprop(basectx, 'work', {}))
|
|
11
|
+
|
|
12
|
+
ctx.client = getprop(ctxmap, 'client', getprop(basectx, 'client'))
|
|
13
|
+
ctx.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
|
|
14
|
+
ctx.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
|
|
15
|
+
ctx.op = getprop(ctxmap, 'op', getprop(basectx, 'op'))
|
|
16
|
+
ctx.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
|
|
17
|
+
ctx.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
|
|
18
|
+
ctx.response = getprop(ctxmap, 'response', getprop(basectx, 'response'))
|
|
19
|
+
ctx.result = getprop(ctxmap, 'result', getprop(basectx, 'result'))
|
|
20
|
+
ctx.spec = getprop(ctxmap, 'spec', getprop(basectx, 'spec'))
|
|
21
|
+
ctx.utility = getprop(ctxmap, 'utility', getprop(basectx, 'utility'))
|
|
22
|
+
ctx.data = getprop(ctxmap, 'data', getprop(basectx, 'data'))
|
|
23
|
+
ctx.reqdata = getprop(ctxmap, 'reqdata', getprop(basectx, 'reqdata'))
|
|
24
|
+
ctx.match = getprop(ctxmap, 'match', getprop(basectx, 'match'))
|
|
25
|
+
ctx.reqmatch = getprop(ctxmap, 'reqmatch', getprop(basectx, 'reqmatch'))
|
|
26
|
+
|
|
27
|
+
return ctx
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Context {
|
|
32
|
+
|
|
33
|
+
ctrl = {}
|
|
34
|
+
meta = {}
|
|
35
|
+
work = {}
|
|
36
|
+
|
|
37
|
+
client = undefined
|
|
38
|
+
config = undefined
|
|
39
|
+
entity = undefined
|
|
40
|
+
op = undefined
|
|
41
|
+
entopts = undefined
|
|
42
|
+
options = undefined
|
|
43
|
+
response = undefined
|
|
44
|
+
result = undefined
|
|
45
|
+
spec = undefined
|
|
46
|
+
utility = undefined
|
|
47
|
+
data = undefined
|
|
48
|
+
reqdata = undefined
|
|
49
|
+
match = undefined
|
|
50
|
+
reqmatch = undefined
|
|
51
|
+
|
|
52
|
+
toJSON() {
|
|
53
|
+
return {
|
|
54
|
+
op: this.op,
|
|
55
|
+
spec: this.spec,
|
|
56
|
+
entity: this.entity,
|
|
57
|
+
result: this.result,
|
|
58
|
+
meta: this.meta,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
contextify,
|
|
66
|
+
Context
|
|
67
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { clean } from './CleanUtility'
|
|
6
|
+
|
|
7
|
+
import { delprop } from './StructUtility'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function done(ctx: Context) {
|
|
11
|
+
const { error } = ctx.utility
|
|
12
|
+
|
|
13
|
+
if (ctx.ctrl.explain) {
|
|
14
|
+
ctx.ctrl.explain = clean(ctx, ctx.ctrl.explain)
|
|
15
|
+
delprop(ctx.ctrl.explain.result, 'err')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (ctx.result.ok) {
|
|
19
|
+
return ctx.result.resdata
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return error(ctx)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
done
|
|
28
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { clean } from './CleanUtility'
|
|
6
|
+
|
|
7
|
+
import { clone, delprop } from './StructUtility'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function error(ctx: Context, err?: any) {
|
|
11
|
+
|
|
12
|
+
ctx = ctx || {}
|
|
13
|
+
const op = ctx.op || {}
|
|
14
|
+
op.name = op.name || 'unknown operation'
|
|
15
|
+
|
|
16
|
+
const result = ctx.result = ctx.result || {}
|
|
17
|
+
result.ok = false
|
|
18
|
+
|
|
19
|
+
const reserr = result.err
|
|
20
|
+
|
|
21
|
+
err = undefined === err ? reserr : err
|
|
22
|
+
err = err || new Error('unknown error')
|
|
23
|
+
|
|
24
|
+
const errmsg = err.message || 'unknown error'
|
|
25
|
+
const msg = 'ProjectNameSDK: ' + op.name + ': ' + errmsg
|
|
26
|
+
err.message = clean(ctx, msg)
|
|
27
|
+
|
|
28
|
+
if (result.err) {
|
|
29
|
+
delprop(result, 'err')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const spec = ctx.spec || {}
|
|
33
|
+
|
|
34
|
+
if (ctx.ctrl.explain) {
|
|
35
|
+
ctx.ctrl.explain.err = {
|
|
36
|
+
...clone({ err }).err,
|
|
37
|
+
message: err.message,
|
|
38
|
+
stack: err.stack,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
err.result = clean(ctx, result)
|
|
43
|
+
err.spec = clean(ctx, spec)
|
|
44
|
+
|
|
45
|
+
ctx.ctrl.err = err
|
|
46
|
+
|
|
47
|
+
// TODO: model option to return instead
|
|
48
|
+
if (false === ctx.ctrl.throw) {
|
|
49
|
+
return ctx.result.resdata
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw err
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
error
|
|
59
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context, Feature } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function featurehook(ctx: Context, name: string) {
|
|
6
|
+
const client = ctx.client
|
|
7
|
+
|
|
8
|
+
let resp: Promise<any>[] = []
|
|
9
|
+
const features: Feature[] = client._features || []
|
|
10
|
+
|
|
11
|
+
for (let f of features) {
|
|
12
|
+
let fres = (f as any)[name](ctx)
|
|
13
|
+
if (fres instanceof Promise) {
|
|
14
|
+
resp.push(fres)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (0 < resp.length) {
|
|
19
|
+
return Promise.all(resp)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
featurehook
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
// Make HTTP call using library. Replace this utility for mocking etc.
|
|
5
|
+
async function fetcher(ctx: Context, fullurl: string, fetchdef: Record<string, any>) {
|
|
6
|
+
const options = ctx.client.options()
|
|
7
|
+
const fetch = options.system.fetch
|
|
8
|
+
|
|
9
|
+
const response = await fetch(fullurl, fetchdef)
|
|
10
|
+
|
|
11
|
+
return response
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
fetcher
|
|
17
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
import { getprop } from './StructUtility'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/* Find value of a match parameter, possibly using an alias.
|
|
8
|
+
*
|
|
9
|
+
* The match parameter may have an alias key. For example, the parameter `foo_id` may be
|
|
10
|
+
* aliased to `id` in the entity data.
|
|
11
|
+
*
|
|
12
|
+
* This function returns `undefined` rather than failing.
|
|
13
|
+
*/
|
|
14
|
+
function findparam(ctx: Context, key: string) {
|
|
15
|
+
let { op, spec, match, reqmatch, data, reqdata } = ctx
|
|
16
|
+
|
|
17
|
+
let akey = op.alias[key]
|
|
18
|
+
|
|
19
|
+
let val = getprop(reqmatch, key)
|
|
20
|
+
|
|
21
|
+
if (null == val) {
|
|
22
|
+
val = getprop(match, key)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (null == val && null != akey) {
|
|
26
|
+
spec.alias[akey] = key
|
|
27
|
+
|
|
28
|
+
val = getprop(reqmatch, akey)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (null == val) {
|
|
32
|
+
val = getprop(reqdata, key)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (null == val) {
|
|
36
|
+
val = getprop(data, key)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (null == val && null != akey) {
|
|
40
|
+
val = getprop(reqdata, akey)
|
|
41
|
+
|
|
42
|
+
if (null == val) {
|
|
43
|
+
val = getprop(data, akey)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return val
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
findparam
|
|
53
|
+
}
|
|
54
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
function fullurl(ctx: Context) {
|
|
5
|
+
const utility = ctx.utility
|
|
6
|
+
// const findparam = utility.findparam
|
|
7
|
+
|
|
8
|
+
const struct = utility.struct
|
|
9
|
+
const { escurl, escre, joinurl } = struct
|
|
10
|
+
|
|
11
|
+
const { spec, result } = ctx
|
|
12
|
+
|
|
13
|
+
let url = joinurl([spec.base, spec.prefix, spec.path, spec.suffix])
|
|
14
|
+
let resmatch: Record<string, any> = {}
|
|
15
|
+
|
|
16
|
+
const params = spec.params
|
|
17
|
+
|
|
18
|
+
for (let key in params) {
|
|
19
|
+
const val = params[key]
|
|
20
|
+
if (null != val) {
|
|
21
|
+
url = url.replace(RegExp('{' + escre(key) + '}'), escurl(val))
|
|
22
|
+
resmatch[key] = val
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let qsep = '?'
|
|
27
|
+
for (let key in spec.query) {
|
|
28
|
+
if (null == spec.alias[key]) {
|
|
29
|
+
const val = spec.query[key]
|
|
30
|
+
if (null != val) {
|
|
31
|
+
url += qsep + escurl(key) + '=' + escurl(val)
|
|
32
|
+
qsep = '&'
|
|
33
|
+
resmatch[key] = val
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
result.resmatch = resmatch
|
|
39
|
+
|
|
40
|
+
return url
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
fullurl
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { getprop } from './StructUtility'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function headers(ctx: Context) {
|
|
9
|
+
const utility = ctx.utility
|
|
10
|
+
const clone = utility.struct.clone
|
|
11
|
+
|
|
12
|
+
const client = ctx.client
|
|
13
|
+
|
|
14
|
+
const options = client.options()
|
|
15
|
+
|
|
16
|
+
let out = clone(getprop(options, 'headers', {}))
|
|
17
|
+
|
|
18
|
+
return out
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
headers
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
|
|
2
|
+
// TODO: MOVE TO STRUCT
|
|
3
|
+
function joinurl(...s: string[]) {
|
|
4
|
+
return s
|
|
5
|
+
.filter(s => null != s && '' !== s)
|
|
6
|
+
.map((s, i) => 0 === i ? s.replace(/([^\/])\/+/, '$1/').replace(/\/+$/, '') :
|
|
7
|
+
s.replace(/([^\/])\/+/, '$1/').replace(/^\/+/, '').replace(/\/+$/, ''))
|
|
8
|
+
.filter(s => '' !== s)
|
|
9
|
+
.join('/')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
joinurl
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
function method(ctx: Context) {
|
|
5
|
+
const { op } = ctx
|
|
6
|
+
const opname = op.name
|
|
7
|
+
|
|
8
|
+
let key = opname
|
|
9
|
+
|
|
10
|
+
// TODO: options
|
|
11
|
+
const mmap: any = {
|
|
12
|
+
create: 'POST',
|
|
13
|
+
update: 'PUT',
|
|
14
|
+
load: 'GET',
|
|
15
|
+
list: 'GET',
|
|
16
|
+
remove: 'DELETE',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return mmap[key]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
method
|
|
25
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context, Operation } from '../types'
|
|
3
|
+
|
|
4
|
+
import { getprop } from './StructUtility'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const OPKIND: any = {
|
|
8
|
+
create: 'req',
|
|
9
|
+
update: 'req',
|
|
10
|
+
remove: 'req',
|
|
11
|
+
load: 'res',
|
|
12
|
+
list: 'res',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function opify(opmap: Record<string, any>) {
|
|
17
|
+
|
|
18
|
+
const validate = getprop(opmap, 'validate', {})
|
|
19
|
+
|
|
20
|
+
const op: Operation = {
|
|
21
|
+
name: getprop(opmap, 'name', '_'),
|
|
22
|
+
kind: getprop(opmap, 'kind', '_'),
|
|
23
|
+
path: getprop(opmap, 'path', '_'),
|
|
24
|
+
pathalt: getprop(opmap, 'pathalt', []),
|
|
25
|
+
entity: getprop(opmap, 'entity', '_'),
|
|
26
|
+
reqform: getprop(opmap, 'reqform', '_'),
|
|
27
|
+
resform: getprop(opmap, 'resform', '_'),
|
|
28
|
+
validate: {
|
|
29
|
+
params: getprop(validate, 'params', { '`$OPEN`': true }),
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
params: getprop(opmap, 'params', []),
|
|
33
|
+
alias: getprop(opmap, 'alias', {}),
|
|
34
|
+
state: getprop(opmap, 'state', {}),
|
|
35
|
+
check: getprop(opmap, 'check', {}),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return op
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// Ensure standard operation definition.
|
|
43
|
+
function operator(ctx: Context): Operation {
|
|
44
|
+
const { op, utility } = ctx
|
|
45
|
+
const { validate } = utility.struct
|
|
46
|
+
|
|
47
|
+
const opspec = {
|
|
48
|
+
|
|
49
|
+
// Required.
|
|
50
|
+
name: '`$STRING`',
|
|
51
|
+
kind: ['`$ONE`', 'req', 'res'],
|
|
52
|
+
path: '`$STRING`',
|
|
53
|
+
entity: '`$STRING`',
|
|
54
|
+
reqform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
|
|
55
|
+
resform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
|
|
56
|
+
validate: {
|
|
57
|
+
params: '`$OBJECT`'
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// Optional.
|
|
61
|
+
pathalt: ['`$CHILD`', {
|
|
62
|
+
path: '`$STRING`',
|
|
63
|
+
'`$OPEN`': true,
|
|
64
|
+
// '`$CHILD`': '`$BOOLEAN`'
|
|
65
|
+
}],
|
|
66
|
+
params: ['`$CHILD`', '`$STRING`'],
|
|
67
|
+
alias: { '`$CHILD`': '`$STRING`' },
|
|
68
|
+
state: {},
|
|
69
|
+
check: {},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ctx.op.kind = OPKIND[op.name]
|
|
73
|
+
|
|
74
|
+
const opv = ctx.op.validate
|
|
75
|
+
ctx.op = validate(ctx.op, opspec)
|
|
76
|
+
|
|
77
|
+
ctx.op.validate = opv
|
|
78
|
+
|
|
79
|
+
if (ctx.ctrl.explain) {
|
|
80
|
+
ctx.ctrl.explain.op = ctx.op
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return ctx.op
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
opify,
|
|
89
|
+
operator,
|
|
90
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function options(ctx: Context) {
|
|
6
|
+
const { options, utility } = ctx
|
|
7
|
+
const struct = utility.struct
|
|
8
|
+
const setprop = struct.setprop
|
|
9
|
+
|
|
10
|
+
let opts = { ...(options || {}) }
|
|
11
|
+
|
|
12
|
+
const customUtils = opts.utility || {}
|
|
13
|
+
for (let key of Object.keys(customUtils)) {
|
|
14
|
+
setprop(utility, key, customUtils[key])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { merge, validate } = utility.struct
|
|
18
|
+
|
|
19
|
+
let config = ctx.config || {}
|
|
20
|
+
let cfgopts = config.options || {}
|
|
21
|
+
|
|
22
|
+
// Standard SDK option values.
|
|
23
|
+
const optspec = {
|
|
24
|
+
apikey: '',
|
|
25
|
+
base: 'http://localhost:8000',
|
|
26
|
+
prefix: '',
|
|
27
|
+
suffix: '',
|
|
28
|
+
auth: {
|
|
29
|
+
prefix: ''
|
|
30
|
+
},
|
|
31
|
+
headers: {
|
|
32
|
+
'`$CHILD`': '`$STRING`'
|
|
33
|
+
},
|
|
34
|
+
entity: {
|
|
35
|
+
'`$CHILD`': {
|
|
36
|
+
'`$OPEN`': true,
|
|
37
|
+
active: false,
|
|
38
|
+
alias: {}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
feature: {
|
|
42
|
+
'`$CHILD`': {
|
|
43
|
+
'`$OPEN`': true,
|
|
44
|
+
active: false,
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
utility: {},
|
|
48
|
+
system: {
|
|
49
|
+
fetch: undefined as any
|
|
50
|
+
},
|
|
51
|
+
test: {
|
|
52
|
+
active: false,
|
|
53
|
+
entity: {
|
|
54
|
+
'`$OPEN`': true,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// JavaScript specific option values.
|
|
60
|
+
optspec.system.fetch = opts.system?.fetch || global.fetch
|
|
61
|
+
|
|
62
|
+
opts = merge([{}, cfgopts, opts])
|
|
63
|
+
|
|
64
|
+
opts = validate(opts, optspec)
|
|
65
|
+
|
|
66
|
+
return opts
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
options
|
|
72
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function params(ctx: Context) {
|
|
6
|
+
const utility = ctx.utility
|
|
7
|
+
const findparam = utility.findparam
|
|
8
|
+
|
|
9
|
+
const struct = utility.struct
|
|
10
|
+
const { validate } = struct
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
const { op } = ctx
|
|
14
|
+
|
|
15
|
+
let { params } = op
|
|
16
|
+
let { reqmatch } = ctx
|
|
17
|
+
|
|
18
|
+
params = params || []
|
|
19
|
+
reqmatch = reqmatch || {}
|
|
20
|
+
|
|
21
|
+
let out: any = {}
|
|
22
|
+
for (let key of params) {
|
|
23
|
+
let val = findparam(ctx, key)
|
|
24
|
+
if (null != val) {
|
|
25
|
+
out[key] = val
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// out = validate(out, op.validate.params)
|
|
30
|
+
|
|
31
|
+
return out
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
params
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function query(ctx: Context) {
|
|
6
|
+
const { op } = ctx
|
|
7
|
+
let { params } = op
|
|
8
|
+
let { reqmatch } = ctx
|
|
9
|
+
|
|
10
|
+
params = params || []
|
|
11
|
+
reqmatch = reqmatch || {}
|
|
12
|
+
|
|
13
|
+
const out: any = {}
|
|
14
|
+
for (let key of Object.keys(reqmatch)) {
|
|
15
|
+
let val = reqmatch[key]
|
|
16
|
+
if (null != val && !params.includes(key)) {
|
|
17
|
+
out[key] = val
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return out
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
query
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
/* Convert entity data or match query into a srtucture suitable for use as request data.
|
|
5
|
+
*
|
|
6
|
+
* The operation (op) property `reqform` is used to perform the data preparation.
|
|
7
|
+
*/
|
|
8
|
+
function reqform(ctx: Context) {
|
|
9
|
+
const { spec, utility } = ctx
|
|
10
|
+
const { struct, error } = utility
|
|
11
|
+
const { isfunc, transform } = struct
|
|
12
|
+
|
|
13
|
+
if (spec) {
|
|
14
|
+
spec.step = 'reqform'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const reqform = ctx.op.reqform
|
|
19
|
+
const reqdata = isfunc(reqform) ? reqform(ctx) : transform({
|
|
20
|
+
reqdata: ctx.reqdata
|
|
21
|
+
}, reqform)
|
|
22
|
+
|
|
23
|
+
return reqdata
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
return error(ctx, err)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
reqform
|
|
33
|
+
}
|