@voxgig/sdkgen 0.17.0 → 0.18.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/dist/action/feature.js +3 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +11 -6
- 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/Main.js +23 -9
- package/dist/cmp/Main.js.map +1 -1
- package/dist/sdkgen.d.ts +7 -1
- package/dist/sdkgen.js +5 -2
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +1 -2
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.jsonic +8 -5
- package/package.json +5 -5
- package/project/{generate → .sdk}/model/feature/log.jsonic +5 -1
- package/project/{generate → .sdk}/model/target/js.jsonic +0 -1
- package/project/.sdk/model/target/ts.jsonic +25 -0
- package/project/{generate → .sdk}/src/cmp/js/Config_js.ts +17 -2
- package/project/{generate → .sdk}/src/cmp/js/Entity_js.ts +16 -15
- package/project/{generate → .sdk}/src/cmp/js/Main_js.ts +22 -16
- package/project/{generate → .sdk}/src/cmp/js/Package_js.ts +2 -1
- package/project/.sdk/src/cmp/js/TestAcceptEntity_js.ts +13 -0
- package/project/.sdk/src/cmp/js/TestAccept_js.ts +18 -0
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +13 -0
- package/project/.sdk/src/cmp/js/TestMain_js.ts +19 -0
- package/project/{generate → .sdk}/src/cmp/js/fragment/Entity.fragment.js +15 -7
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +57 -0
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +61 -0
- package/project/{generate → .sdk}/src/cmp/js/fragment/Main.fragment.js +26 -3
- package/project/.sdk/src/cmp/ts/Config_ts.ts +36 -0
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +93 -0
- package/project/.sdk/src/cmp/ts/MainEntity_ts.ts.off +22 -0
- package/project/.sdk/src/cmp/ts/Main_ts.ts +88 -0
- package/project/.sdk/src/cmp/ts/Main_ts.ts~ +88 -0
- package/project/.sdk/src/cmp/ts/Package_ts.ts +63 -0
- package/project/.sdk/src/cmp/ts/Package_ts.ts~ +58 -0
- package/project/.sdk/src/cmp/ts/Quick_ts.ts.off +82 -0
- package/project/.sdk/src/cmp/ts/ReadmeInstall_ts.ts.off +19 -0
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts.off +25 -0
- package/project/.sdk/src/cmp/ts/TestAcceptEntity_ts.ts.off +13 -0
- package/project/.sdk/src/cmp/ts/TestAccept_ts.ts.off +18 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts.off +13 -0
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts.off +19 -0
- package/project/.sdk/src/cmp/ts/Test_ts.ts.off +24 -0
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +15 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.js +79 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.js +57 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.js +61 -0
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.js +67 -0
- package/project/{generate → .sdk}/tm/js/src/feature/log/LogFeature.js +14 -10
- package/project/.sdk/tm/js/src/utility/AuthUtility.js +21 -0
- package/project/.sdk/tm/js/src/utility/BodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/DoneUtility.js +15 -0
- package/project/.sdk/tm/js/src/utility/ErrorUtility.js +33 -0
- package/project/.sdk/tm/js/src/utility/FindparamUtility.js +31 -0
- package/project/.sdk/tm/js/src/utility/FullurlUtility.js +39 -0
- package/project/{generate → .sdk}/tm/js/src/utility/HeadersUtility.js +2 -1
- package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +14 -0
- package/project/{generate → .sdk}/tm/js/src/utility/MethodUtility.js +2 -1
- package/project/.sdk/tm/js/src/utility/OperatorUtility.js +44 -0
- package/project/.sdk/tm/js/src/utility/OptionsUtility.js +54 -0
- package/project/{generate → .sdk}/tm/js/src/utility/ParamsUtility.js +5 -4
- package/project/{generate → .sdk}/tm/js/src/utility/QueryUtility.js +6 -4
- package/project/.sdk/tm/js/src/utility/ReqformUtility.js +32 -0
- package/project/.sdk/tm/js/src/utility/RequestUtility.js +48 -0
- package/project/.sdk/tm/js/src/utility/ResbasicUtility.js +27 -0
- package/project/.sdk/tm/js/src/utility/ResbodyUtility.js +15 -0
- package/project/.sdk/tm/js/src/utility/ResformUtility.js +34 -0
- package/project/.sdk/tm/js/src/utility/ResheadersUtility.js +19 -0
- package/project/{generate → .sdk}/tm/js/src/utility/ResponseUtility.js +11 -10
- package/project/.sdk/tm/js/src/utility/ResultUtility.js +28 -0
- package/project/{generate → .sdk}/tm/js/src/utility/SpecUtility.js +6 -12
- package/project/.sdk/tm/js/src/utility/StructUtility.js +1203 -0
- package/project/.sdk/tm/js/src/utility/Utility.js +74 -0
- package/project/.sdk/tm/js/test/runner.js +171 -0
- package/project/.sdk/tm/js/test/utility/Custom.test.js +85 -0
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +187 -0
- package/project/.sdk/tm/js/test/utility/StructUtility.test.js +367 -0
- package/project/.sdk/tm/py/LICENSE +22 -0
- package/project/.sdk/tm/ts/LICENSE +22 -0
- package/project/.sdk/tm/ts/src/README.md +1 -0
- package/project/.sdk/tm/ts/src/feature/README.md +1 -0
- package/project/.sdk/tm/ts/src/tsconfig.json +15 -0
- package/project/.sdk/tm/ts/src/utility/README.md +3 -0
- package/project/.sdk/tm/ts/test/README.md +2 -0
- package/project/.sdk/tm/ts/test/README.md~ +2 -0
- package/project/.sdk/tm/ts/test/tsconfig.json +13 -0
- package/src/action/feature.ts +4 -3
- package/src/action/target.ts +12 -6
- package/src/cmp/Entity.ts +3 -1
- package/src/cmp/Main.ts +30 -10
- package/src/sdkgen.ts +15 -5
- package/src/utility.ts +1 -2
- package/project/generate/src/cmp/js/TestAcceptEntity_js.ts +0 -101
- package/project/generate/src/cmp/js/TestAccept_js.ts +0 -60
- package/project/generate/src/cmp/js/TestEntity_js.ts +0 -24
- package/project/generate/src/cmp/js/TestMain_js.ts +0 -120
- package/project/generate/src/cmp/js/fragment/EntityCreateOp.fragment.js +0 -66
- package/project/generate/src/cmp/js/fragment/EntityListOp.fragment.js +0 -72
- package/project/generate/src/cmp/js/fragment/EntityLoadOp.fragment.js +0 -66
- package/project/generate/src/cmp/js/fragment/EntityRemoveOp.fragment.js +0 -66
- package/project/generate/src/cmp/js/fragment/EntityUpdateOp.fragment.js +0 -66
- package/project/generate/tm/js/src/utility/AuthUtility.js +0 -16
- package/project/generate/tm/js/src/utility/BodyUtility.js +0 -27
- package/project/generate/tm/js/src/utility/EmptyUtility.js +0 -8
- package/project/generate/tm/js/src/utility/ErrorUtility.js +0 -15
- package/project/generate/tm/js/src/utility/EscreUtility.js +0 -8
- package/project/generate/tm/js/src/utility/EscurlUtility.js +0 -8
- package/project/generate/tm/js/src/utility/FetchUtility.js +0 -33
- package/project/generate/tm/js/src/utility/FullurlUtility.js +0 -41
- package/project/generate/tm/js/src/utility/InwardUtility.js +0 -23
- package/project/generate/tm/js/src/utility/JoinurlUtility.js +0 -12
- package/project/generate/tm/js/src/utility/OperatorUtility.js +0 -36
- package/project/generate/tm/js/src/utility/OptionsUtility.js +0 -22
- package/project/generate/tm/js/src/utility/OutwardUtility.js +0 -23
- package/project/generate/tm/js/src/utility/ResbasicUtility.js +0 -17
- package/project/generate/tm/js/src/utility/ResbodyUtility.js +0 -10
- package/project/generate/tm/js/src/utility/ResheadersUtility.js +0 -11
- package/project/generate/tm/js/src/utility/Utility.js +0 -55
- /package/project/{generate → .sdk}/model/feature/limit.jsonic +0 -0
- /package/project/{generate → .sdk}/model/feature/page.jsonic +0 -0
- /package/project/{generate → .sdk}/model/feature/telemetry.jsonic +0 -0
- /package/project/{generate → .sdk}/model/target/go.jsonic +0 -0
- /package/project/{generate → .sdk}/src/cmp/js/MainEntity_js.ts +0 -0
- /package/project/{generate → .sdk}/src/cmp/js/Quick_js.ts +0 -0
- /package/project/{generate → .sdk}/src/cmp/js/ReadmeInstall_js.ts +0 -0
- /package/project/{generate → .sdk}/src/cmp/js/ReadmeQuick_js.ts +0 -0
- /package/project/{generate → .sdk}/src/cmp/js/Test_js.ts +0 -0
- /package/project/{generate → .sdk}/tm/go/LICENSE +0 -0
- /package/project/{generate → .sdk}/tm/js/LICENSE +0 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class EntityOperation { // REMOVED
|
|
2
|
+
|
|
3
|
+
async load(match) {
|
|
4
|
+
const entity = this
|
|
5
|
+
const client = this.#client
|
|
6
|
+
const utility = this.#utility
|
|
7
|
+
const { operator, spec, request, response, result, error, struct, done } = utility
|
|
8
|
+
|
|
9
|
+
const op = {
|
|
10
|
+
entity: 'Name',
|
|
11
|
+
name: 'load',
|
|
12
|
+
path: 'PATH',
|
|
13
|
+
params: ['PARAM-LIST'],
|
|
14
|
+
alias: {'ALIAS':'MAP'},
|
|
15
|
+
match,
|
|
16
|
+
data: this.#data,
|
|
17
|
+
state: {},
|
|
18
|
+
reqform: 'REQFORM',
|
|
19
|
+
resform: 'RESFORM',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let ctx = { client, entity, op, utility}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// #PreOperation-Hook
|
|
26
|
+
|
|
27
|
+
await operator(ctx)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// #PreSpec-Hook
|
|
31
|
+
|
|
32
|
+
this.#match = op.match
|
|
33
|
+
|
|
34
|
+
await spec(ctx)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// #PreRequest-Hook
|
|
38
|
+
|
|
39
|
+
await request(ctx)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// #PreResponse-Hook
|
|
43
|
+
|
|
44
|
+
await response(ctx)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// #PreResult-Hook
|
|
48
|
+
|
|
49
|
+
await result(ctx)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// #PostOperation-Hook
|
|
53
|
+
|
|
54
|
+
if(null != ctx.result.resdata) {
|
|
55
|
+
this.#data = ctx.result.resdata
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return done(ctx)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} // REMOVED
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class EntityOperation { // REMOVED
|
|
2
|
+
|
|
3
|
+
async remove(match) {
|
|
4
|
+
let entity = this
|
|
5
|
+
let client = this.#client
|
|
6
|
+
const utility = this.#utility
|
|
7
|
+
const { operator, spec, request, response, result, error, struct, done } = utility
|
|
8
|
+
|
|
9
|
+
let op = {
|
|
10
|
+
entity: 'Name',
|
|
11
|
+
name: 'remove',
|
|
12
|
+
path: 'PATH',
|
|
13
|
+
params: ['PARAM-LIST'],
|
|
14
|
+
alias: {'ALIAS':'MAP'},
|
|
15
|
+
match,
|
|
16
|
+
data: this.#data,
|
|
17
|
+
state: {},
|
|
18
|
+
reqform: 'REQFORM',
|
|
19
|
+
resform: 'RESFORM',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let ctx = {client, entity, op, utility}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// #PreOperation-Hook
|
|
26
|
+
|
|
27
|
+
await operator(ctx)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// #PreSpec-Hook
|
|
31
|
+
|
|
32
|
+
this.#data = op.data
|
|
33
|
+
|
|
34
|
+
await spec(ctx)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// #PreRequest-Hook
|
|
38
|
+
|
|
39
|
+
await request(ctx)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// #PreResponse-Hook
|
|
43
|
+
|
|
44
|
+
await response(ctx)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// #PreResult-Hook
|
|
48
|
+
|
|
49
|
+
await result(ctx)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// #PostOperation-Hook
|
|
53
|
+
|
|
54
|
+
if(null != ctx.result.resdata) {
|
|
55
|
+
this.#data = ctx.result.resdata
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return done(ctx)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} // REMOVED
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class EntityOperation { // REMOVED
|
|
2
|
+
|
|
3
|
+
async update(data) {
|
|
4
|
+
let entity = this
|
|
5
|
+
let client = this.#client
|
|
6
|
+
const utility = this.#utility
|
|
7
|
+
const { operator, spec, request, response, result, error, struct, done } = utility
|
|
8
|
+
|
|
9
|
+
let op = {
|
|
10
|
+
entity: 'Name',
|
|
11
|
+
name: 'update',
|
|
12
|
+
path: 'PATH',
|
|
13
|
+
params: ['PARAM-LIST'],
|
|
14
|
+
alias: {'ALIAS':'MAP'},
|
|
15
|
+
match: this.#match,
|
|
16
|
+
data: null == data ? this.#data : data,
|
|
17
|
+
state: {},
|
|
18
|
+
reqform: 'REQFORM',
|
|
19
|
+
resform: 'RESFORM',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let ctx = {client, entity, op, utility}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// #PreOperation-Hook
|
|
26
|
+
|
|
27
|
+
await operator(ctx)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// #PreSpec-Hook
|
|
31
|
+
|
|
32
|
+
this.#data = op.data
|
|
33
|
+
|
|
34
|
+
await spec(ctx)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// #PreRequest-Hook
|
|
38
|
+
|
|
39
|
+
await request(ctx)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// #PreResponse-Hook
|
|
43
|
+
|
|
44
|
+
await response(ctx)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// #PreResult-Hook
|
|
48
|
+
|
|
49
|
+
await result(ctx)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// #PostOperation-Hook
|
|
53
|
+
|
|
54
|
+
if(null != ctx.result.resdata) {
|
|
55
|
+
this.#data = ctx.result.resdata
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return done(ctx)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} // REMOVED
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
const { Config } = require('./Config')
|
|
3
|
+
const { Utility } = require('./utility/Utility')
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NameSDK {
|
|
7
|
+
#options
|
|
8
|
+
#features
|
|
9
|
+
#utility = Utility
|
|
10
|
+
|
|
11
|
+
constructor(options) {
|
|
12
|
+
|
|
13
|
+
this.#options = this.#utility.options({
|
|
14
|
+
client: this,
|
|
15
|
+
utility: this.#utility,
|
|
16
|
+
config: Config,
|
|
17
|
+
options,
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// #FeatureOptions
|
|
21
|
+
|
|
22
|
+
this.#features = {
|
|
23
|
+
// #BuildFeature
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// #PostConstruct-Hook
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
options() {
|
|
31
|
+
return { ...this.#options }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
features() {
|
|
35
|
+
return { ...this.#features }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
utility() {
|
|
39
|
+
return { ...this.#utility }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
static test(opts) {
|
|
44
|
+
return new NameSDK({
|
|
45
|
+
// #TestOptions
|
|
46
|
+
...(opts || {})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test(opts) {
|
|
51
|
+
return new NameSDK({
|
|
52
|
+
// #TestOptions
|
|
53
|
+
...(opts || this.#options || {})
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// <[SLOT]>
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
const SDK = NameSDK
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
NameSDK,
|
|
66
|
+
SDK,
|
|
67
|
+
}
|
|
@@ -52,6 +52,10 @@ class LogFeature {
|
|
|
52
52
|
this.#loghook('PostConstruct', ctx)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
PostConstructEntity(ctx) {
|
|
56
|
+
this.#loghook('PostConstructEntity', ctx)
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
SetData(ctx) {
|
|
56
60
|
this.#loghook('SetData', ctx)
|
|
57
61
|
}
|
|
@@ -60,8 +64,8 @@ class LogFeature {
|
|
|
60
64
|
this.#loghook('GetData', ctx)
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
this.#loghook('
|
|
67
|
+
GetMatch(ctx) {
|
|
68
|
+
this.#loghook('GetMatch', ctx)
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
|
|
@@ -69,20 +73,20 @@ class LogFeature {
|
|
|
69
73
|
this.#loghook('PreOperation', ctx)
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
this.#loghook('
|
|
76
|
+
PreSpec(ctx) {
|
|
77
|
+
this.#loghook('PreSpec', ctx)
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
|
|
77
|
-
this.#loghook('
|
|
80
|
+
PreRequest(ctx) {
|
|
81
|
+
this.#loghook('PreRequest', ctx)
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
this.#loghook('
|
|
84
|
+
PreResponse(ctx) {
|
|
85
|
+
this.#loghook('PreResponse', ctx)
|
|
82
86
|
}
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
this.#loghook('
|
|
88
|
+
PreResult(ctx) {
|
|
89
|
+
this.#loghook('PreResult', ctx)
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
PostOperation(ctx) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
function auth(ctx) {
|
|
3
|
+
const { client, spec } = ctx
|
|
4
|
+
const { headers } = spec
|
|
5
|
+
|
|
6
|
+
let options = client.options()
|
|
7
|
+
|
|
8
|
+
if(null != options.apikey && '' !== options.apikey) {
|
|
9
|
+
headers['authorization'] = 'Bearer '+options.apikey
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
delete headers['authorization']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return spec
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
auth
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
function body(ctx) {
|
|
4
|
+
const { op, result, utility } = ctx
|
|
5
|
+
const { struct, error } = utility
|
|
6
|
+
const { isfunc, transform } = struct
|
|
7
|
+
|
|
8
|
+
let body = undefined
|
|
9
|
+
|
|
10
|
+
if('req' === op.kind) {
|
|
11
|
+
try {
|
|
12
|
+
const reqform = op.reqform
|
|
13
|
+
body = isfunc(reqform) ? reqform(ctx) : transform(op, op.reqform)
|
|
14
|
+
|
|
15
|
+
if(op.check.nobody && null == body) {
|
|
16
|
+
return error(ctx, new Error('Request body is empty.'))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return error(ctx, err)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return body
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
body
|
|
29
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
function error(ctx, err) {
|
|
3
|
+
|
|
4
|
+
ctx = ctx || {}
|
|
5
|
+
const op = ctx.op || {}
|
|
6
|
+
op.name = op.name || 'unknown operation'
|
|
7
|
+
|
|
8
|
+
const result = ctx.result = ctx.result || {}
|
|
9
|
+
result.ok = false
|
|
10
|
+
|
|
11
|
+
const reserr = result.err
|
|
12
|
+
|
|
13
|
+
err = undefined === err ? reserr : err
|
|
14
|
+
err = err || new Error('unknown error')
|
|
15
|
+
|
|
16
|
+
const errmsg = err.message || 'unknown error'
|
|
17
|
+
const msg = 'StatuspageSDK: '+op.name+': '+errmsg
|
|
18
|
+
err.message = msg
|
|
19
|
+
// result.err = {...err}
|
|
20
|
+
|
|
21
|
+
const spec = ctx.spec || {}
|
|
22
|
+
|
|
23
|
+
err.result = ctx.result
|
|
24
|
+
err.spec = spec
|
|
25
|
+
|
|
26
|
+
// TODO: model option to return instead
|
|
27
|
+
throw err
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
error
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/* Find value of a match parameter, possibly using an alias.
|
|
3
|
+
*
|
|
4
|
+
* The match parameter may have an alias key. For example, the parameter `foo_id` may be
|
|
5
|
+
* aliased to `id` in the entity data.
|
|
6
|
+
*
|
|
7
|
+
* This function returns `undefined` rather than failing.
|
|
8
|
+
*/
|
|
9
|
+
function findparam(ctx, key) {
|
|
10
|
+
let { op, spec } = ctx
|
|
11
|
+
let { match, data, alias } = op
|
|
12
|
+
|
|
13
|
+
let source = ('res' === op.kind ? match : data) || {}
|
|
14
|
+
let val = source[key]
|
|
15
|
+
|
|
16
|
+
if(null == val) {
|
|
17
|
+
alias = alias || {}
|
|
18
|
+
let akey = alias[key]
|
|
19
|
+
val = source[akey]
|
|
20
|
+
|
|
21
|
+
spec = spec || {}
|
|
22
|
+
spec.alias = spec.alias || {}
|
|
23
|
+
spec.alias[akey] = key
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return val
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = {
|
|
30
|
+
findparam
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
function fullurl(ctx) {
|
|
4
|
+
const { op, spec, utility: { struct, findparam } } = ctx
|
|
5
|
+
const { escurl, escre, joinurl } = struct
|
|
6
|
+
|
|
7
|
+
let url = joinurl([spec.base, spec.prefix, spec.path, spec.suffix])
|
|
8
|
+
|
|
9
|
+
const params = spec.params
|
|
10
|
+
for(let key of op.params) {
|
|
11
|
+
if(null == params[key]) {
|
|
12
|
+
params[key] = findparam(ctx, key)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for(let key in params) {
|
|
17
|
+
const val = params[key]
|
|
18
|
+
if(null != val) {
|
|
19
|
+
url = url.replace(RegExp('{'+escre(key)+'}'), escurl(val))
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let qsep = '?'
|
|
24
|
+
for(let key in spec.query) {
|
|
25
|
+
if(null == spec.alias[key]) {
|
|
26
|
+
const val = spec.query[key]
|
|
27
|
+
if(null != val) {
|
|
28
|
+
url += qsep + escurl(key) + '=' + escurl(val)
|
|
29
|
+
qsep = '&'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return url
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
fullurl
|
|
39
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
// TODO: MOVE TO STRUCT
|
|
3
|
+
function joinurl(...s) {
|
|
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
|
+
module.exports = {
|
|
13
|
+
joinurl
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const OPKIND = {
|
|
4
|
+
create: 'req',
|
|
5
|
+
update: 'req',
|
|
6
|
+
remove: 'req',
|
|
7
|
+
load: 'res',
|
|
8
|
+
list: 'res',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// Ensure standard operation definition.
|
|
13
|
+
function operator(ctx) {
|
|
14
|
+
const { op, utility } = ctx
|
|
15
|
+
const { validate } = utility.struct
|
|
16
|
+
|
|
17
|
+
const opspec = {
|
|
18
|
+
|
|
19
|
+
// Required.
|
|
20
|
+
name: '`$STRING`',
|
|
21
|
+
kind: ['`$ONE`','req','res'],
|
|
22
|
+
path: '`$STRING`',
|
|
23
|
+
entity: '`$STRING`',
|
|
24
|
+
reqform: ['`$ONE`','`$STRING`','`$OBJECT`','`$FUNCTION`'],
|
|
25
|
+
resform: ['`$ONE`','`$STRING`','`$OBJECT`','`$FUNCTION`'],
|
|
26
|
+
|
|
27
|
+
// Optional.
|
|
28
|
+
params: ['`$CHILD`', '`$STRING`'],
|
|
29
|
+
alias: {'`$CHILD`': '`$STRING`' },
|
|
30
|
+
match: {},
|
|
31
|
+
data: ['`$ONE`',{}, []],
|
|
32
|
+
state: {},
|
|
33
|
+
check: {},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ctx.op.kind = OPKIND[op.name]
|
|
37
|
+
|
|
38
|
+
ctx.op = validate(ctx.op, opspec)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
operator
|
|
44
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
function options(ctx) {
|
|
3
|
+
const { options, utility } = ctx
|
|
4
|
+
|
|
5
|
+
let opts = { ...(options||{}) }
|
|
6
|
+
|
|
7
|
+
const customUtils = opts.utility || {}
|
|
8
|
+
for(let key of Object.keys(customUtils)) {
|
|
9
|
+
utility[key] = customUtils[key]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { isempty, merge, validate } = utility.struct
|
|
13
|
+
|
|
14
|
+
let config = ctx.config || {}
|
|
15
|
+
let cfgopts = config.options || {}
|
|
16
|
+
|
|
17
|
+
// Standard SDK option values.
|
|
18
|
+
const optspec = {
|
|
19
|
+
apikey: '',
|
|
20
|
+
base: 'http://localhost:8000',
|
|
21
|
+
prefix: '',
|
|
22
|
+
suffix: '',
|
|
23
|
+
entity: {
|
|
24
|
+
'`$CHILD`': {
|
|
25
|
+
'`$OPEN`': true,
|
|
26
|
+
active: false,
|
|
27
|
+
alias: {}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
feature: {
|
|
31
|
+
'`$CHILD`': {
|
|
32
|
+
'`$OPEN`': true,
|
|
33
|
+
active: false,
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
utility: {},
|
|
37
|
+
system: {},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// JavaScript specific option values.
|
|
41
|
+
optspec.system.fetch = optspec.system.fetch || global.fetch
|
|
42
|
+
|
|
43
|
+
opts = merge([{},cfgopts,opts])
|
|
44
|
+
|
|
45
|
+
opts = validate(opts, optspec)
|
|
46
|
+
|
|
47
|
+
return opts
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
options
|
|
54
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
function params(ctx) {
|
|
3
3
|
const { op } = ctx
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let { params, match } = op
|
|
5
|
+
params = params || []
|
|
6
|
+
match = match || {}
|
|
7
|
+
|
|
7
8
|
const out = {}
|
|
8
9
|
for(let key of params) {
|
|
9
|
-
let val =
|
|
10
|
+
let val = match[key]
|
|
10
11
|
if(null!=val) {
|
|
11
12
|
out[key] = val
|
|
12
13
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
function query(ctx) {
|
|
3
3
|
const { op } = ctx
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let { params, match } = op
|
|
5
|
+
params = params || []
|
|
6
|
+
match = match || {}
|
|
7
|
+
|
|
6
8
|
const out = {}
|
|
7
|
-
for(let key of Object.keys(
|
|
8
|
-
let val =
|
|
9
|
+
for(let key of Object.keys(match)) {
|
|
10
|
+
let val = match[key]
|
|
9
11
|
if(null!=val && !params.includes(key)) {
|
|
10
12
|
out[key] = val
|
|
11
13
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/* Convert entity data or match query into a srtucture suitable for use as request data.
|
|
3
|
+
*
|
|
4
|
+
* The operation (op) property `reqform` is used to perform the data preparation.
|
|
5
|
+
*/
|
|
6
|
+
function reqform(ctx) {
|
|
7
|
+
const { op, spec, result, utility } = ctx
|
|
8
|
+
const { struct, error } = utility
|
|
9
|
+
const { isfunc, transform } = struct
|
|
10
|
+
|
|
11
|
+
if(spec) {
|
|
12
|
+
spec.step = 'reqform'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// if (!result.ok) {
|
|
16
|
+
// return undefined
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const reqform = ctx.op.reqform
|
|
21
|
+
const reqdata = isfunc(reqform) ? reqform(ctx) : transform(ctx.op, reqform)
|
|
22
|
+
return reqdata
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
return error(ctx, err)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
reqform
|
|
32
|
+
}
|