@voxgig/sdkgen 0.16.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 +7 -5
- package/project/.sdk/model/feature/limit.jsonic +12 -0
- package/project/.sdk/model/feature/log.jsonic +32 -0
- package/project/.sdk/model/feature/page.jsonic +9 -0
- package/project/.sdk/model/feature/telemetry.jsonic +10 -0
- package/project/.sdk/model/target/go.jsonic +7 -0
- package/project/.sdk/model/target/js.jsonic +23 -0
- package/project/.sdk/model/target/ts.jsonic +25 -0
- package/project/.sdk/src/cmp/js/Config_js.ts +49 -0
- package/project/.sdk/src/cmp/js/Entity_js.ts +92 -0
- package/project/.sdk/src/cmp/js/MainEntity_js.ts +22 -0
- package/project/.sdk/src/cmp/js/Main_js.ts +88 -0
- package/project/.sdk/src/cmp/js/Package_js.ts +58 -0
- package/project/.sdk/src/cmp/js/Quick_js.ts +82 -0
- package/project/.sdk/src/cmp/js/ReadmeInstall_js.ts +19 -0
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +25 -0
- 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/.sdk/src/cmp/js/Test_js.ts +24 -0
- package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +79 -0
- 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/.sdk/src/cmp/js/fragment/Main.fragment.js +67 -0
- 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/.sdk/tm/go/LICENSE +22 -0
- package/project/.sdk/tm/js/LICENSE +22 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +108 -0
- 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/.sdk/tm/js/src/utility/HeadersUtility.js +13 -0
- package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +14 -0
- package/project/.sdk/tm/js/src/utility/MethodUtility.js +22 -0
- package/project/.sdk/tm/js/src/utility/OperatorUtility.js +44 -0
- package/project/.sdk/tm/js/src/utility/OptionsUtility.js +54 -0
- package/project/.sdk/tm/js/src/utility/ParamsUtility.js +21 -0
- package/project/.sdk/tm/js/src/utility/QueryUtility.js +21 -0
- 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/.sdk/tm/js/src/utility/ResponseUtility.js +37 -0
- package/project/.sdk/tm/js/src/utility/ResultUtility.js +28 -0
- package/project/.sdk/tm/js/src/utility/SpecUtility.js +35 -0
- 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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
|
|
2
|
+
/* Utility functions.
|
|
3
|
+
*
|
|
4
|
+
* Many of these functions expect the operation context as the first argument, and
|
|
5
|
+
* assume the following top level properties of the context:
|
|
6
|
+
* * client: SDK client instance
|
|
7
|
+
* * op: operation definition
|
|
8
|
+
* * utility: map of these utility functions
|
|
9
|
+
* * entity?: SDK entity instance
|
|
10
|
+
* * spec?: request specification
|
|
11
|
+
* * response?: unprocessed response
|
|
12
|
+
* * result?: processed result built from response
|
|
13
|
+
* * config?: SDK builtin configuration
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { auth } = require('./AuthUtility')
|
|
18
|
+
const { body } = require('./BodyUtility')
|
|
19
|
+
const { done } = require('./DoneUtility')
|
|
20
|
+
const { error } = require('./ErrorUtility')
|
|
21
|
+
const { findparam } = require('./FindparamUtility')
|
|
22
|
+
const { fullurl } = require('./FullurlUtility')
|
|
23
|
+
const { headers } = require('./HeadersUtility')
|
|
24
|
+
const { method } = require('./MethodUtility')
|
|
25
|
+
const { operator } = require('./OperatorUtility')
|
|
26
|
+
const { options } = require('./OptionsUtility')
|
|
27
|
+
const { params } = require('./ParamsUtility')
|
|
28
|
+
const { query } = require('./QueryUtility')
|
|
29
|
+
const { reqform } = require('./ReqformUtility')
|
|
30
|
+
const { request } = require('./RequestUtility')
|
|
31
|
+
const { resbasic } = require('./ResbasicUtility')
|
|
32
|
+
const { resbody } = require('./ResbodyUtility')
|
|
33
|
+
const { resform } = require('./ResformUtility')
|
|
34
|
+
const { resheaders } = require('./ResheadersUtility')
|
|
35
|
+
const { response } = require('./ResponseUtility')
|
|
36
|
+
const { result } = require('./ResultUtility')
|
|
37
|
+
const { spec } = require('./SpecUtility')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const struct = require('./StructUtility')
|
|
41
|
+
// const validate = require('./ValidateUtility')
|
|
42
|
+
|
|
43
|
+
const Utility = {
|
|
44
|
+
auth,
|
|
45
|
+
body,
|
|
46
|
+
done,
|
|
47
|
+
error,
|
|
48
|
+
findparam,
|
|
49
|
+
fullurl,
|
|
50
|
+
headers,
|
|
51
|
+
method,
|
|
52
|
+
operator,
|
|
53
|
+
options,
|
|
54
|
+
params,
|
|
55
|
+
query,
|
|
56
|
+
reqform,
|
|
57
|
+
request,
|
|
58
|
+
resbasic,
|
|
59
|
+
resbody,
|
|
60
|
+
resform,
|
|
61
|
+
resheaders,
|
|
62
|
+
response,
|
|
63
|
+
result,
|
|
64
|
+
spec,
|
|
65
|
+
|
|
66
|
+
struct,
|
|
67
|
+
// validate,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
Utility
|
|
73
|
+
}
|
|
74
|
+
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
|
|
2
|
+
const { readFileSync } = require('node:fs')
|
|
3
|
+
const { join } = require('node:path')
|
|
4
|
+
const { equal, deepEqual, fail, AssertionError } = require('node:assert')
|
|
5
|
+
|
|
6
|
+
const { NameSDK: SDK } = require('..')
|
|
7
|
+
|
|
8
|
+
const client = SDK.test()
|
|
9
|
+
const utility = client.utility()
|
|
10
|
+
const { walk, items, clone, isnode, ismap, getpath, stringify, inject } = utility.struct
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async function runner(name, store) {
|
|
14
|
+
|
|
15
|
+
const alltests =
|
|
16
|
+
JSON.parse(readFileSync(join(
|
|
17
|
+
__dirname, '..', '..', '.sdk', 'test', 'test.json'), 'utf8'))
|
|
18
|
+
|
|
19
|
+
// TODO: a more coherent namespace perhaps?
|
|
20
|
+
let spec = alltests.primary[name] || alltests[name]
|
|
21
|
+
|
|
22
|
+
const clients = {}
|
|
23
|
+
if(spec.DEF) {
|
|
24
|
+
for(let cdef of items(spec.DEF.client)) {
|
|
25
|
+
const copts = cdef[1].test.options || {}
|
|
26
|
+
if(ismap(store)) {
|
|
27
|
+
inject(copts, store)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clients[cdef[0]] = await SDK.test(copts)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let subject = utility[name]
|
|
35
|
+
|
|
36
|
+
let runset = async (testspec, testsubject, makesubject) => {
|
|
37
|
+
testsubject = testsubject || subject
|
|
38
|
+
|
|
39
|
+
next_entry:
|
|
40
|
+
for (let entry of testspec.set) {
|
|
41
|
+
try {
|
|
42
|
+
let testclient = client
|
|
43
|
+
|
|
44
|
+
if(entry.client) {
|
|
45
|
+
testclient = clients[entry.client]
|
|
46
|
+
testsubject = client.utility()[name]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if(makesubject) {
|
|
50
|
+
testsubject = makesubject(testsubject)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let args = [clone(entry.in)]
|
|
54
|
+
|
|
55
|
+
if(entry.ctx) {
|
|
56
|
+
args = [entry.ctx]
|
|
57
|
+
}
|
|
58
|
+
else if(entry.args) {
|
|
59
|
+
args = entry.args
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if(entry.ctx || entry.args) {
|
|
63
|
+
let first = args[0]
|
|
64
|
+
if(ismap(first)) {
|
|
65
|
+
entry.ctx = first = args[0] = clone(args[0])
|
|
66
|
+
first.client = testclient
|
|
67
|
+
first.utility = testclient.utility()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let res = await testsubject(...args)
|
|
72
|
+
entry.res = res
|
|
73
|
+
|
|
74
|
+
if(undefined === entry.match || undefined !== entry.out) {
|
|
75
|
+
// NOTE: don't use clone as we want to strip functions
|
|
76
|
+
deepEqual(null != res ? JSON.parse(JSON.stringify(res)) : res, entry.out)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if(entry.match) {
|
|
80
|
+
match(entry.match, {in:entry.in, out:entry.res, ctx:entry.ctx})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
entry.thrown = err
|
|
85
|
+
|
|
86
|
+
const entry_err = entry.err
|
|
87
|
+
|
|
88
|
+
if (null != entry_err) {
|
|
89
|
+
// if (true === entry_err || (err.message.includes(entry_err))) {
|
|
90
|
+
if (true === entry_err || matchval(entry_err, err.message)) {
|
|
91
|
+
|
|
92
|
+
if(entry.match) {
|
|
93
|
+
match(entry.match, {in:entry.in, out:entry.res, ctx:entry.ctx, err})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
continue next_entry
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fail('ERROR MATCH: ['+stringify(entry_err)+'] <=> ['+err.message+']')
|
|
100
|
+
}
|
|
101
|
+
else if(err instanceof AssertionError ) {
|
|
102
|
+
fail(err.message+'\n\nENTRY: '+JSON.stringify(entry,null,2))
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
fail(err.stack+'\\nnENTRY: '+JSON.stringify(entry,null,2))
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
spec,
|
|
114
|
+
runset,
|
|
115
|
+
subject,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
function match(check, base) {
|
|
121
|
+
let nodes = [base]
|
|
122
|
+
|
|
123
|
+
// TODO: walk should be called on entry and exit from a node to
|
|
124
|
+
// avoid needing getpath
|
|
125
|
+
walk(check, (key, val, parent, path)=>{
|
|
126
|
+
if(!isnode(val)) {
|
|
127
|
+
let baseval = getpath(path, base)
|
|
128
|
+
|
|
129
|
+
if(!matchval(val, baseval)) {
|
|
130
|
+
fail('MATCH: '+path.join('.')+': ['+stringify(val)+'] <=> ['+stringify(baseval)+']')
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
function matchval(check, base) {
|
|
138
|
+
check = '__UNDEF__' === check ? undefined : check
|
|
139
|
+
|
|
140
|
+
let pass = check === base
|
|
141
|
+
|
|
142
|
+
if(!pass) {
|
|
143
|
+
|
|
144
|
+
if('string' === typeof check) {
|
|
145
|
+
let basestr = stringify(base)
|
|
146
|
+
|
|
147
|
+
let rem = check.match(/^\/(.+)\/$/)
|
|
148
|
+
if(rem) {
|
|
149
|
+
pass = new RegExp(rem[1]).test(basestr)
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
pass = basestr.toLowerCase().includes(stringify(check).toLowerCase())
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if('function' === typeof check) {
|
|
156
|
+
pass = true
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
return pass
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
runner
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
const { test, describe } = require('node:test')
|
|
3
|
+
const { equal, deepEqual } = require('node:assert')
|
|
4
|
+
|
|
5
|
+
const { StatuspageSDK } = require('../..')
|
|
6
|
+
|
|
7
|
+
const client = StatuspageSDK.test({
|
|
8
|
+
apikey: 'APIKEY01',
|
|
9
|
+
utility: {
|
|
10
|
+
auth: ()=> ({util:'AUTH'}),
|
|
11
|
+
body: () => ({util:'BODY'}),
|
|
12
|
+
empty: () => ({util:'EMPTY'}),
|
|
13
|
+
error: () => ({util:'ERROR'}),
|
|
14
|
+
escre: () => ({util:'ESCRE'}),
|
|
15
|
+
escurl: () => ({util:'ESCURL'}),
|
|
16
|
+
fetch: () => ({util:'FETCH'}),
|
|
17
|
+
findparam: () => ({util:'FINDPARAM'}),
|
|
18
|
+
fullurl: () => ({util:'FULLURL'}),
|
|
19
|
+
headers: () => ({util:'HEADERS'}),
|
|
20
|
+
inward: () => ({util:'INWARD'}),
|
|
21
|
+
joinurl: () => ({util:'JOINURL'}),
|
|
22
|
+
method: () => ({util:'METHOD'}),
|
|
23
|
+
operator: () => ({util:'OPERATOR'}),
|
|
24
|
+
options: () => ({util:'OPTIONS'}),
|
|
25
|
+
outward: () => ({util:'OUTWARD'}),
|
|
26
|
+
params: () => ({util:'PARAMS'}),
|
|
27
|
+
query: () => ({util:'QUERY'}),
|
|
28
|
+
resbasic: () => ({util:'RESBASIC'}),
|
|
29
|
+
resbody: () => ({util:'RESBODY'}),
|
|
30
|
+
resheaders: () => ({util:'RESHEADERS'}),
|
|
31
|
+
response: () => ({util:'RESPONSE'}),
|
|
32
|
+
spec: () => ({util:'SPEC'}),
|
|
33
|
+
|
|
34
|
+
string: {
|
|
35
|
+
stringify: () => ({util:'STRING-STRINGIFY'}),
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
validate: {
|
|
39
|
+
string: () => ({util:'VALIDATE-STRING'}),
|
|
40
|
+
array: () => ({util:'VALIDATE-ARRAY'}),
|
|
41
|
+
object: () => ({util:'VALIDATE-OBJECT'}),
|
|
42
|
+
func: () => ({util:'VALIDATE-FUNC'}),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
describe('Custom', ()=>{
|
|
50
|
+
test('basic', async ()=>{
|
|
51
|
+
const u = client.utility()
|
|
52
|
+
|
|
53
|
+
equal(u.auth().util, 'AUTH')
|
|
54
|
+
equal(u.body().util, 'BODY')
|
|
55
|
+
equal(u.empty().util, 'EMPTY')
|
|
56
|
+
equal(u.error().util, 'ERROR')
|
|
57
|
+
equal(u.escre().util, 'ESCRE')
|
|
58
|
+
equal(u.escurl().util, 'ESCURL')
|
|
59
|
+
equal(u.fetch().util, 'FETCH')
|
|
60
|
+
equal(u.findparam().util, 'FINDPARAM')
|
|
61
|
+
equal(u.fullurl().util, 'FULLURL')
|
|
62
|
+
equal(u.headers().util, 'HEADERS')
|
|
63
|
+
equal(u.inward().util, 'INWARD')
|
|
64
|
+
equal(u.joinurl().util, 'JOINURL')
|
|
65
|
+
equal(u.method().util, 'METHOD')
|
|
66
|
+
equal(u.operator().util, 'OPERATOR')
|
|
67
|
+
equal(u.options().util, 'OPTIONS')
|
|
68
|
+
equal(u.outward().util, 'OUTWARD')
|
|
69
|
+
equal(u.params().util, 'PARAMS')
|
|
70
|
+
equal(u.query().util, 'QUERY')
|
|
71
|
+
equal(u.resbasic().util, 'RESBASIC')
|
|
72
|
+
equal(u.resbody().util, 'RESBODY')
|
|
73
|
+
equal(u.resheaders().util, 'RESHEADERS')
|
|
74
|
+
equal(u.response().util, 'RESPONSE')
|
|
75
|
+
equal(u.spec().util, 'SPEC')
|
|
76
|
+
|
|
77
|
+
equal(u.string.stringify().util, 'STRING-STRINGIFY')
|
|
78
|
+
|
|
79
|
+
equal(u.validate.string().util, 'VALIDATE-STRING')
|
|
80
|
+
equal(u.validate.array().util, 'VALIDATE-ARRAY')
|
|
81
|
+
equal(u.validate.object().util, 'VALIDATE-OBJECT')
|
|
82
|
+
equal(u.validate.func().util, 'VALIDATE-FUNC')
|
|
83
|
+
|
|
84
|
+
})
|
|
85
|
+
})
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
|
|
2
|
+
const { test, describe } = require('node:test')
|
|
3
|
+
const { equal, deepEqual } = require('node:assert')
|
|
4
|
+
|
|
5
|
+
const { runner } = require('../runner')
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('PrimaryUtility', async ()=>{
|
|
9
|
+
|
|
10
|
+
async function MockFetch(url, fetchdef) {
|
|
11
|
+
return {
|
|
12
|
+
status: 200,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const runners = {
|
|
17
|
+
auth: await runner('auth'),
|
|
18
|
+
body: await runner('body'),
|
|
19
|
+
error: await runner('error'),
|
|
20
|
+
findparam: await runner('findparam'),
|
|
21
|
+
fullurl: await runner('fullurl'),
|
|
22
|
+
headers: await runner('headers'),
|
|
23
|
+
method: await runner('method'),
|
|
24
|
+
operator: await runner('operator'),
|
|
25
|
+
options: await runner('options'),
|
|
26
|
+
params: await runner('params'),
|
|
27
|
+
query: await runner('query'),
|
|
28
|
+
reqform: await runner('reqform'),
|
|
29
|
+
request: await runner('request', { fetch: MockFetch }),
|
|
30
|
+
resbasic: await runner('resbasic'),
|
|
31
|
+
resbody: await runner('resbody'),
|
|
32
|
+
resform: await runner('resform'),
|
|
33
|
+
resheaders: await runner('resheaders'),
|
|
34
|
+
response: await runner('response'),
|
|
35
|
+
spec: await runner('spec'),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
test('exists', async ()=>{
|
|
40
|
+
equal('function', typeof runners.auth.subject)
|
|
41
|
+
equal('function', typeof runners.body.subject)
|
|
42
|
+
equal('function', typeof runners.error.subject)
|
|
43
|
+
equal('function', typeof runners.findparam.subject)
|
|
44
|
+
equal('function', typeof runners.fullurl.subject)
|
|
45
|
+
equal('function', typeof runners.method.subject)
|
|
46
|
+
equal('function', typeof runners.operator.subject)
|
|
47
|
+
equal('function', typeof runners.options.subject)
|
|
48
|
+
equal('function', typeof runners.params.subject)
|
|
49
|
+
equal('function', typeof runners.query.subject)
|
|
50
|
+
equal('function', typeof runners.reqform.subject)
|
|
51
|
+
equal('function', typeof runners.request.subject)
|
|
52
|
+
equal('function', typeof runners.resbasic.subject)
|
|
53
|
+
equal('function', typeof runners.resbody.subject)
|
|
54
|
+
equal('function', typeof runners.resform.subject)
|
|
55
|
+
equal('function', typeof runners.resheaders.subject)
|
|
56
|
+
equal('function', typeof runners.response.subject)
|
|
57
|
+
equal('function', typeof runners.spec.subject)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
test('auth-basic', async () => {
|
|
62
|
+
const { runset, spec, subject } = runners.auth
|
|
63
|
+
await runset(spec.basic, undefined, (subject)=>(vin)=>{
|
|
64
|
+
return subject(vin, vin.spec)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
test('body-basic', async () => {
|
|
70
|
+
const { runset, spec, subject } = runners.body
|
|
71
|
+
await runset(spec.basic, subject)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
test('error-basic', async () => {
|
|
76
|
+
const { runset, spec, subject } = runners.error
|
|
77
|
+
await runset(spec.basic, subject)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
test('findparam-basic', async () => {
|
|
82
|
+
const { runset, spec, subject } = runners.findparam
|
|
83
|
+
await runset(spec.basic, subject)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
test('fullurl-basic', async () => {
|
|
88
|
+
const { runset, spec, subject } = runners.fullurl
|
|
89
|
+
await runset(spec.basic, subject)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
test('headers-basic', async () => {
|
|
94
|
+
const { runset, spec, subject } = runners.headers
|
|
95
|
+
await runset(spec.basic, subject)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
test('method-basic', async () => {
|
|
100
|
+
const { runset, spec, subject } = runners.method
|
|
101
|
+
await runset(spec.basic, subject)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
test('operator-basic', async () => {
|
|
106
|
+
const { runset, spec, subject } = runners.operator
|
|
107
|
+
await runset(spec.basic, subject)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
test('options-basic', async () => {
|
|
112
|
+
const { runset, spec, subject } = runners.options
|
|
113
|
+
await runset(spec.basic, subject)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
test('params-basic', async () => {
|
|
118
|
+
const { runset, spec, subject } = runners.params
|
|
119
|
+
await runset(spec.basic, subject)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
test('query-basic', async () => {
|
|
124
|
+
const { runset, spec, subject } = runners.query
|
|
125
|
+
await runset(spec.basic, subject)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
test('reqform-basic', async () => {
|
|
130
|
+
const { runset, spec, subject } = runners.reqform
|
|
131
|
+
await runset(spec.basic, subject)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
test('request-basic', async () => {
|
|
136
|
+
const { runset, spec, subject } = runners.request
|
|
137
|
+
await runset(spec.basic, subject)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
test('resbasic-basic', async () => {
|
|
142
|
+
const { runset, spec, subject } = runners.resbasic
|
|
143
|
+
await runset(spec.basic, subject)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
test('resbody-basic', async () => {
|
|
148
|
+
const { runset, spec, subject } = runners.resbody
|
|
149
|
+
await runset(spec.basic, (ctx, result)=>{
|
|
150
|
+
let resdata = ctx.utility.struct.clone(ctx.response)
|
|
151
|
+
ctx.response.json = async ()=>resdata
|
|
152
|
+
return subject(ctx, result)
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
test('resform-basic', async () => {
|
|
158
|
+
const { runset, spec, subject } = runners.resform
|
|
159
|
+
await runset(spec.basic, subject)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
test('resheaders-basic', async () => {
|
|
164
|
+
const { runset, spec, subject } = runners.resheaders
|
|
165
|
+
await runset(spec.basic, (ctx, result)=>{
|
|
166
|
+
ctx.response.headers.forEach = function (callback) {
|
|
167
|
+
Object.keys(this).forEach((key) => {
|
|
168
|
+
callback(this[key], key, this)
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
return subject(ctx, result)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
test('response-basic', async () => {
|
|
177
|
+
const { runset, spec, subject } = runners.response
|
|
178
|
+
await runset(spec.basic, subject)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
test('spec-basic', async () => {
|
|
183
|
+
const { runset, spec, subject } = runners.spec
|
|
184
|
+
await runset(spec.basic, subject)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
})
|