@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,107 @@
|
|
|
1
|
+
|
|
2
|
+
import type { Feature } from './types'
|
|
3
|
+
|
|
4
|
+
import { Config } from './Config'
|
|
5
|
+
import { Utility } from './utility/Utility'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import { BaseFeature } from './feature/base/BaseFeature'
|
|
9
|
+
|
|
10
|
+
const utility = new Utility()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ProjectNameSDK {
|
|
14
|
+
#options: any
|
|
15
|
+
#utility = utility
|
|
16
|
+
|
|
17
|
+
_features: Feature[]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
constructor(options?: any) {
|
|
21
|
+
|
|
22
|
+
const ctx = this.#utility.contextify({
|
|
23
|
+
client: this,
|
|
24
|
+
utility: this.#utility,
|
|
25
|
+
config: Config,
|
|
26
|
+
options,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
this.#options = this.#utility.options(ctx)
|
|
30
|
+
|
|
31
|
+
ctx.options = this.#options
|
|
32
|
+
|
|
33
|
+
this._features = []
|
|
34
|
+
|
|
35
|
+
const addfeature = this.#utility.addfeature
|
|
36
|
+
const initfeature = this.#utility.initfeature
|
|
37
|
+
|
|
38
|
+
// #BuildFeatures
|
|
39
|
+
|
|
40
|
+
if (null != this.#options.extend) {
|
|
41
|
+
for (let f of this.#options.extend) {
|
|
42
|
+
addfeature(ctx, f)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (let f of this._features) {
|
|
47
|
+
initfeature(ctx, f)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const featurehook = this.#utility.featurehook
|
|
51
|
+
featurehook(ctx, 'PostConstruct')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
options() {
|
|
56
|
+
return { ...this.#options }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
utility() {
|
|
61
|
+
return { ...this.#utility }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// <[SLOT]>
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
static test(testopts?: any, sdkopts?: any) {
|
|
69
|
+
const active = null == testopts ? false : null == testopts.active ? true : !!testopts.active
|
|
70
|
+
testopts = testopts || {}
|
|
71
|
+
testopts.active = active
|
|
72
|
+
|
|
73
|
+
sdkopts = sdkopts || {}
|
|
74
|
+
sdkopts.feature = sdkopts.feature || {}
|
|
75
|
+
sdkopts.feature.test = testopts || {}
|
|
76
|
+
sdkopts.feature.test.active = true
|
|
77
|
+
|
|
78
|
+
return new ProjectNameSDK(sdkopts)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
tester(testopts?: any, sdkopts?: any) {
|
|
83
|
+
return ProjectNameSDK.test(testopts, sdkopts)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ProjectNameEntity {
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const SDK = ProjectNameSDK
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
utility,
|
|
99
|
+
|
|
100
|
+
BaseFeature,
|
|
101
|
+
ProjectNameEntity,
|
|
102
|
+
|
|
103
|
+
ProjectNameSDK,
|
|
104
|
+
SDK,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Feature, Context, FeatureOptions } from '../../types'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseFeature implements Feature {
|
|
7
|
+
version = '0.0.1'
|
|
8
|
+
name = 'base'
|
|
9
|
+
active = true
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
init(_ctx: Context, _options: FeatureOptions): void | Promise<any> { }
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
PostConstruct(this: any, _ctx: any) { }
|
|
16
|
+
|
|
17
|
+
PostConstructEntity(this: any, _ctx: any) { }
|
|
18
|
+
|
|
19
|
+
SetData(this: any, _ctx: any) { }
|
|
20
|
+
|
|
21
|
+
GetData(this: any, _ctx: any) { }
|
|
22
|
+
|
|
23
|
+
GetMatch(this: any, _ctx: any) { }
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
PreOperation(this: any, _ctx: any) { }
|
|
27
|
+
|
|
28
|
+
PreSpec(this: any, _ctx: any) { }
|
|
29
|
+
|
|
30
|
+
PreRequest(this: any, _ctx: any) { }
|
|
31
|
+
|
|
32
|
+
PreResponse(this: any, _ctx: any) { }
|
|
33
|
+
|
|
34
|
+
PreResult(this: any, _ctx: any) { }
|
|
35
|
+
|
|
36
|
+
PostOperation(this: any, _ctx: any) { }
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
BaseFeature
|
|
43
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
import type { Context, FeatureOptions } from '../../types'
|
|
3
|
+
import type { ProjectNameSDK } from '../../ProjectNameSDK'
|
|
4
|
+
|
|
5
|
+
import { BaseFeature } from '../base/BaseFeature'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import Pino from 'pino'
|
|
9
|
+
import PinoPretty from 'pino-pretty'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LogFeature extends BaseFeature {
|
|
14
|
+
version = '0.0.1'
|
|
15
|
+
name = 'log'
|
|
16
|
+
active = true
|
|
17
|
+
|
|
18
|
+
_client?: ProjectNameSDK
|
|
19
|
+
_options?: any
|
|
20
|
+
_logger?: any
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
init(ctx: Context, options: FeatureOptions): void | Promise<any> {
|
|
24
|
+
this._client = ctx.client
|
|
25
|
+
this._options = options as any
|
|
26
|
+
this.active = options.active
|
|
27
|
+
|
|
28
|
+
if (this.active) {
|
|
29
|
+
let logger = this._options.logger
|
|
30
|
+
|
|
31
|
+
if (null == logger) {
|
|
32
|
+
let pretty = PinoPretty({
|
|
33
|
+
sync: true,
|
|
34
|
+
ignore: 'ctx',
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
let level = this._options.level || 'info'
|
|
38
|
+
|
|
39
|
+
logger = Pino({ name: 'log', level }, pretty)
|
|
40
|
+
|
|
41
|
+
this._logger = logger
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
PostConstruct(this: any, ctx: any) {
|
|
48
|
+
this._loghook('PostConstruct', ctx)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
PostConstructEntity(this: any, ctx: any) {
|
|
52
|
+
this._loghook('PostConstructEntity', ctx)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
SetData(this: any, ctx: any) {
|
|
56
|
+
this._loghook('SetData', ctx)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
GetData(this: any, ctx: any) {
|
|
60
|
+
this._loghook('GetData', ctx)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
GetMatch(this: any, ctx: any) {
|
|
64
|
+
this._loghook('GetMatch', ctx)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
PreOperation(this: any, ctx: any) {
|
|
69
|
+
this._loghook('PreOperation', ctx)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
PreSpec(this: any, ctx: any) {
|
|
73
|
+
this._loghook('PreSpec', ctx)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
PreRequest(this: any, ctx: any) {
|
|
77
|
+
this._loghook('PreRequest', ctx)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
PreResponse(this: any, ctx: any) {
|
|
81
|
+
this._loghook('PreResponse', ctx)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
PreResult(this: any, ctx: any) {
|
|
85
|
+
this._loghook('PreResult', ctx)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
PostOperation(this: any, ctx: any) {
|
|
89
|
+
this._loghook('PostOperation', ctx)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
_loghook(this: any, hook: any, ctx: any, level: any) {
|
|
94
|
+
level = level || 'info'
|
|
95
|
+
if (this._logger) {
|
|
96
|
+
this._logger[level]({
|
|
97
|
+
hook,
|
|
98
|
+
op: ctx.op,
|
|
99
|
+
spec: ctx.spec,
|
|
100
|
+
ctx
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
LogFeature
|
|
109
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
|
|
2
|
+
import type { Context, FeatureOptions } from '../../types'
|
|
3
|
+
import type { ProjectNameSDK } from '../../ProjectNameSDK'
|
|
4
|
+
|
|
5
|
+
import { BaseFeature } from '../base/BaseFeature'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestFeature extends BaseFeature {
|
|
9
|
+
version = '0.0.1'
|
|
10
|
+
name = 'test'
|
|
11
|
+
active = true
|
|
12
|
+
|
|
13
|
+
_client?: ProjectNameSDK
|
|
14
|
+
_options?: any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
init(ctx: Context, options: FeatureOptions): void | Promise<any> {
|
|
18
|
+
this._client = ctx.client
|
|
19
|
+
this._options = options
|
|
20
|
+
|
|
21
|
+
// console.log('TEST FEATURE', this._options)
|
|
22
|
+
|
|
23
|
+
const { struct } = ctx.utility
|
|
24
|
+
const { walk, size, setprop, stringify } = struct
|
|
25
|
+
|
|
26
|
+
const entity = this._options.entity
|
|
27
|
+
|
|
28
|
+
// Set entity ids to correct values
|
|
29
|
+
walk(entity, (k: any, v: any, parent: any, path: any) => {
|
|
30
|
+
if (2 === size(path)) {
|
|
31
|
+
setprop(v, 'id', k)
|
|
32
|
+
}
|
|
33
|
+
return v
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (entity) {
|
|
37
|
+
ctx.utility.fetcher = (ctx: any, _fullurl: string, _fetchdef: any) => {
|
|
38
|
+
const { findparam, struct } = ctx.utility
|
|
39
|
+
const { getprop, clone, merge, keysof, size, select, delprop } = struct
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
function respond(status: number, data?: any, res?: any) {
|
|
43
|
+
const out = merge([
|
|
44
|
+
{
|
|
45
|
+
status,
|
|
46
|
+
statusText: 'OK',
|
|
47
|
+
json: async () => data,
|
|
48
|
+
},
|
|
49
|
+
res || {}
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
const headers: any = out.headers || {}
|
|
53
|
+
out.headers = {
|
|
54
|
+
forEach(callback: any) {
|
|
55
|
+
Object.keys(headers).forEach((key) => {
|
|
56
|
+
callback(headers[key], key, this)
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
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
|
+
qor = { '`$OR`': qor }
|
|
81
|
+
|
|
82
|
+
qand.push(qor)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (ctx.ctrl.explain) {
|
|
86
|
+
ctx.ctrl.explain.test = { query: q }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ('load' === op.name) {
|
|
90
|
+
const found = select(entmap, q)
|
|
91
|
+
const ent = found[0]
|
|
92
|
+
if (null == ent) {
|
|
93
|
+
return respond(404, undefined, { statusText: 'Not found' })
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
delprop(ent, '$KEY')
|
|
97
|
+
return respond(200, clone(ent))
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if ('list' === op.name) {
|
|
101
|
+
const found = select(entmap, q)
|
|
102
|
+
if (null == found) {
|
|
103
|
+
return respond(404, undefined, { statusText: 'Not found' })
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
found.map((ent: any) => delprop(ent, '$KEY'))
|
|
107
|
+
return respond(200, clone(found))
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if ('update' === op.name) {
|
|
111
|
+
const found = select(entmap, q)
|
|
112
|
+
const ent = found[0]
|
|
113
|
+
if (null == ent) {
|
|
114
|
+
return respond(404, undefined, { statusText: 'Not found' })
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
merge([ent, (ctx.reqdata || {})])
|
|
118
|
+
delprop(ent, '$KEY')
|
|
119
|
+
return respond(200, clone(ent))
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if ('remove' === op.name) {
|
|
123
|
+
const found = select(entmap, q)
|
|
124
|
+
const ent = found[0]
|
|
125
|
+
if (null == ent) {
|
|
126
|
+
return respond(404, undefined, { statusText: 'Not found' })
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
delprop(entmap, getprop(ent, 'id'))
|
|
130
|
+
return respond(200)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if ('create' === op.name) {
|
|
134
|
+
const id = findparam(ctx, 'id')
|
|
135
|
+
if (null != id) {
|
|
136
|
+
const ent = clone(ctx.reqdata)
|
|
137
|
+
ent.id = id
|
|
138
|
+
setprop(entmap, 'id', ent)
|
|
139
|
+
delprop(ent, '$KEY')
|
|
140
|
+
return respond(200, clone(ent))
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
return respond(400, undefined, { statusText: 'Missing id' })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
TestFeature
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
import { ProjectNameSDK } from './ProjectNameSDK'
|
|
3
|
+
|
|
4
|
+
import { Utility } from './utility/Utility'
|
|
5
|
+
|
|
6
|
+
type Context = {
|
|
7
|
+
ctrl: any
|
|
8
|
+
client: ProjectNameSDK
|
|
9
|
+
op: Operation
|
|
10
|
+
spec: Spec
|
|
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
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
type FeatureOptions = Record<string, any> | {
|
|
80
|
+
active: boolean
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
interface Feature {
|
|
85
|
+
version: string
|
|
86
|
+
name: string
|
|
87
|
+
active: boolean
|
|
88
|
+
|
|
89
|
+
init: (ctx: Context, options: FeatureOptions) => void | Promise<any>
|
|
90
|
+
|
|
91
|
+
PostConstruct: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
92
|
+
PostConstructEntity: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
93
|
+
SetData: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
94
|
+
GetData: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
95
|
+
GetMatch: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
96
|
+
|
|
97
|
+
PreOperation: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
98
|
+
PreSpec: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
99
|
+
PreRequest: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
100
|
+
PreResponse: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
101
|
+
PreResult: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
102
|
+
PostOperation: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
export type {
|
|
108
|
+
Context,
|
|
109
|
+
Operation,
|
|
110
|
+
Spec,
|
|
111
|
+
Control,
|
|
112
|
+
FeatureOptions,
|
|
113
|
+
Feature,
|
|
114
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context, Feature } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function addfeature(ctx: Context, f: Feature) {
|
|
6
|
+
const client = ctx.client
|
|
7
|
+
const struct = ctx.utility.struct
|
|
8
|
+
const setprop = struct.setprop
|
|
9
|
+
const getprop = struct.getprop
|
|
10
|
+
|
|
11
|
+
const fopts = getprop(f, '_options', {})
|
|
12
|
+
let added = false
|
|
13
|
+
const features = client._features
|
|
14
|
+
|
|
15
|
+
// TODO: make this a utility
|
|
16
|
+
if (fopts.__before__ || fopts.__after__ || fopts.__replace__) {
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < features.length; i++) {
|
|
19
|
+
let ef = client._features[i]
|
|
20
|
+
if (fopts.__before__ === ef.name) {
|
|
21
|
+
client._features = [...features.slice(0, i), f, ...features.slice(i)]
|
|
22
|
+
added = true
|
|
23
|
+
break
|
|
24
|
+
}
|
|
25
|
+
else if (fopts.__after__ === ef.name) {
|
|
26
|
+
client._features = [...features.slice(0, ++i), f, ...features.slice(i)]
|
|
27
|
+
added = true
|
|
28
|
+
break
|
|
29
|
+
}
|
|
30
|
+
else if (fopts.__replace__ === ef.name) {
|
|
31
|
+
client._features = setprop(features, i, f)
|
|
32
|
+
added = true
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!added) {
|
|
39
|
+
client._features = setprop(features, features.length, f)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
addfeature
|
|
47
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const HEADER_auth = 'authorization'
|
|
6
|
+
|
|
7
|
+
const OPTION_apikey = 'apikey'
|
|
8
|
+
|
|
9
|
+
const NOTFOUND = ''
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
function auth(ctx: Context) {
|
|
13
|
+
const utility = ctx.utility
|
|
14
|
+
|
|
15
|
+
const struct = utility.struct
|
|
16
|
+
const getprop = struct.getprop
|
|
17
|
+
const setprop = struct.setprop
|
|
18
|
+
const delprop = struct.delprop
|
|
19
|
+
|
|
20
|
+
const client = ctx.client
|
|
21
|
+
const spec = ctx.spec
|
|
22
|
+
|
|
23
|
+
const headers = spec.headers
|
|
24
|
+
|
|
25
|
+
const options = client.options()
|
|
26
|
+
|
|
27
|
+
const apikey = getprop(options, OPTION_apikey, NOTFOUND)
|
|
28
|
+
|
|
29
|
+
if (NOTFOUND === apikey) {
|
|
30
|
+
delprop(headers, HEADER_auth)
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
setprop(headers, HEADER_auth, options.auth.prefix + ' ' + apikey)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return spec
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
auth
|
|
42
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
import { Context } from '../types'
|
|
3
|
+
|
|
4
|
+
function body(ctx: Context) {
|
|
5
|
+
const { op, utility } = ctx
|
|
6
|
+
const { error, reqform } = utility
|
|
7
|
+
|
|
8
|
+
let body = undefined
|
|
9
|
+
|
|
10
|
+
if ('req' === op.kind) {
|
|
11
|
+
try {
|
|
12
|
+
body = reqform(ctx)
|
|
13
|
+
|
|
14
|
+
if (op.check.nobody && null == body) {
|
|
15
|
+
return error(ctx, new Error('Request body is empty.'))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return error(ctx, err)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return body
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
body
|
|
28
|
+
}
|
|
29
|
+
|