@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,88 @@
|
|
|
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
|
+
|
|
18
|
+
|
|
19
|
+
import { addfeature } from './AddfeatureUtility'
|
|
20
|
+
import { auth } from './AuthUtility'
|
|
21
|
+
import { body } from './BodyUtility'
|
|
22
|
+
import { clean } from './CleanUtility'
|
|
23
|
+
import { contextify } from './ContextUtility'
|
|
24
|
+
import { done } from './DoneUtility'
|
|
25
|
+
import { error } from './ErrorUtility'
|
|
26
|
+
import { featurehook } from './FeaturehookUtility'
|
|
27
|
+
import { fetcher } from './FetcherUtility'
|
|
28
|
+
import { findparam } from './FindparamUtility'
|
|
29
|
+
import { fullurl } from './FullurlUtility'
|
|
30
|
+
import { headers } from './HeadersUtility'
|
|
31
|
+
import { initfeature } from './InitfeatureUtility'
|
|
32
|
+
import { method } from './MethodUtility'
|
|
33
|
+
import { operator, opify } from './OperatorUtility'
|
|
34
|
+
import { options } from './OptionsUtility'
|
|
35
|
+
import { params } from './ParamsUtility'
|
|
36
|
+
import { query } from './QueryUtility'
|
|
37
|
+
import { reqform } from './ReqformUtility'
|
|
38
|
+
import { request } from './RequestUtility'
|
|
39
|
+
import { resbasic } from './ResbasicUtility'
|
|
40
|
+
import { resbody } from './ResbodyUtility'
|
|
41
|
+
import { resform } from './ResformUtility'
|
|
42
|
+
import { resheaders } from './ResheadersUtility'
|
|
43
|
+
import { response } from './ResponseUtility'
|
|
44
|
+
import { result } from './ResultUtility'
|
|
45
|
+
import { spec } from './SpecUtility'
|
|
46
|
+
|
|
47
|
+
import { StructUtility } from './StructUtility'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Utility {
|
|
51
|
+
|
|
52
|
+
addfeature = addfeature
|
|
53
|
+
auth = auth
|
|
54
|
+
body = body
|
|
55
|
+
clean = clean
|
|
56
|
+
contextify = contextify
|
|
57
|
+
done = done
|
|
58
|
+
error = error
|
|
59
|
+
featurehook = featurehook
|
|
60
|
+
fetcher = fetcher
|
|
61
|
+
findparam = findparam
|
|
62
|
+
fullurl = fullurl
|
|
63
|
+
headers = headers
|
|
64
|
+
initfeature = initfeature
|
|
65
|
+
method = method
|
|
66
|
+
operator = operator
|
|
67
|
+
opify = opify
|
|
68
|
+
options = options
|
|
69
|
+
params = params
|
|
70
|
+
query = query
|
|
71
|
+
reqform = reqform
|
|
72
|
+
request = request
|
|
73
|
+
resbasic = resbasic
|
|
74
|
+
resbody = resbody
|
|
75
|
+
resform = resform
|
|
76
|
+
resheaders = resheaders
|
|
77
|
+
response = response
|
|
78
|
+
result = result
|
|
79
|
+
spec = spec
|
|
80
|
+
|
|
81
|
+
struct = new StructUtility()
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
Utility
|
|
87
|
+
}
|
|
88
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { test, describe } from 'node:test'
|
|
3
|
+
import { equal } from 'node:assert'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { ProjectNameSDK } from '..'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('exists', async () => {
|
|
10
|
+
|
|
11
|
+
test('test-mode', async () => {
|
|
12
|
+
const testsdk = await ProjectNameSDK.test()
|
|
13
|
+
// console.log('testsdk', testsdk)
|
|
14
|
+
equal(null !== testsdk, true)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
})
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
// VERSION: @voxgig/struct 0.0.4
|
|
2
|
+
// This test utility runs the JSON-specified tests in build/test/test.json.
|
|
3
|
+
// (or .sdk/test/test.json if used in a @voxgig/sdkgen project)
|
|
4
|
+
|
|
5
|
+
import { readFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { deepEqual, fail, AssertionError } from 'node:assert'
|
|
8
|
+
|
|
9
|
+
const NULLMARK = '__NULL__' // Value is JSON null
|
|
10
|
+
const UNDEFMARK = '__UNDEF__' // Value is not present (thus, undefined).
|
|
11
|
+
const EXISTSMARK = '__EXISTS__' // Value exists (not undefined).
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
type Subject = (...args: any[]) => any
|
|
15
|
+
type RunSet = (testspec: any, testsubject: Function) => Promise<any>
|
|
16
|
+
type RunSetFlags = (testspec: any, flags: Record<string, boolean>, testsubject: Function)
|
|
17
|
+
=> Promise<any>
|
|
18
|
+
|
|
19
|
+
type RunPack = {
|
|
20
|
+
spec: Record<string, any>
|
|
21
|
+
runset: RunSet
|
|
22
|
+
runsetflags: RunSetFlags
|
|
23
|
+
subject: Subject
|
|
24
|
+
client: any
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type TestPack = {
|
|
28
|
+
name?: string
|
|
29
|
+
client: any
|
|
30
|
+
subject: Subject
|
|
31
|
+
utility: any
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type Flags = Record<string, boolean>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
type Utility = {
|
|
38
|
+
struct: any
|
|
39
|
+
contextify: (ctxmap: Record<string, any>) => any
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type Client = {
|
|
43
|
+
utility: () => Utility
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async function makeRunner(testfile: string, client: Client) {
|
|
48
|
+
|
|
49
|
+
return async function runner(
|
|
50
|
+
name: string,
|
|
51
|
+
store?: any,
|
|
52
|
+
): Promise<RunPack> {
|
|
53
|
+
store = store || {}
|
|
54
|
+
|
|
55
|
+
const utility = client.utility()
|
|
56
|
+
const structUtils = utility.struct
|
|
57
|
+
|
|
58
|
+
let spec = resolveSpec(name, testfile)
|
|
59
|
+
let clients = await resolveClients(client, spec, store, structUtils)
|
|
60
|
+
let subject = resolveSubject(name, utility)
|
|
61
|
+
|
|
62
|
+
let runsetflags: RunSetFlags = async (
|
|
63
|
+
testspec: any,
|
|
64
|
+
flags: Flags,
|
|
65
|
+
testsubject: Function
|
|
66
|
+
) => {
|
|
67
|
+
subject = testsubject || subject
|
|
68
|
+
flags = resolveFlags(flags)
|
|
69
|
+
const testspecmap = fixJSON(testspec, flags)
|
|
70
|
+
|
|
71
|
+
const testset: any[] = testspecmap.set
|
|
72
|
+
for (let entry of testset) {
|
|
73
|
+
try {
|
|
74
|
+
entry = resolveEntry(entry, flags)
|
|
75
|
+
|
|
76
|
+
let testpack = resolveTestPack(name, entry, subject, client, clients)
|
|
77
|
+
let args = resolveArgs(entry, testpack, utility, structUtils)
|
|
78
|
+
|
|
79
|
+
let res = await testpack.subject(...args)
|
|
80
|
+
res = fixJSON(res, flags)
|
|
81
|
+
entry.res = res
|
|
82
|
+
|
|
83
|
+
checkResult(entry, res, structUtils)
|
|
84
|
+
}
|
|
85
|
+
catch (err: any) {
|
|
86
|
+
if (err instanceof AssertionError) {
|
|
87
|
+
throw err
|
|
88
|
+
}
|
|
89
|
+
handleError(entry, err, structUtils)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let runset: RunSet = async (
|
|
95
|
+
testspec: any,
|
|
96
|
+
testsubject: Function
|
|
97
|
+
) => runsetflags(testspec, {}, testsubject)
|
|
98
|
+
|
|
99
|
+
const runpack: RunPack = {
|
|
100
|
+
spec,
|
|
101
|
+
runset,
|
|
102
|
+
runsetflags,
|
|
103
|
+
subject,
|
|
104
|
+
client,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return runpack
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function resolveSpec(name: string, testfile: string): Record<string, any> {
|
|
112
|
+
const alltests =
|
|
113
|
+
JSON.parse(readFileSync(join(
|
|
114
|
+
__dirname, testfile), 'utf8'))
|
|
115
|
+
|
|
116
|
+
let spec = alltests.primary?.[name] || alltests[name] || alltests
|
|
117
|
+
return spec
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
async function resolveClients(
|
|
122
|
+
client: any,
|
|
123
|
+
spec: Record<string, any>,
|
|
124
|
+
store: any,
|
|
125
|
+
structUtils: Record<string, any>
|
|
126
|
+
):
|
|
127
|
+
Promise<Record<string, any>> {
|
|
128
|
+
|
|
129
|
+
const clients: Record<string, any> = {}
|
|
130
|
+
if (spec.DEF && spec.DEF.client) {
|
|
131
|
+
for (let cn in spec.DEF.client) {
|
|
132
|
+
const cdef = spec.DEF.client[cn]
|
|
133
|
+
const copts = cdef.test.options || {}
|
|
134
|
+
if ('object' === typeof store && structUtils?.inject) {
|
|
135
|
+
structUtils.inject(copts, store)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
clients[cn] = await client.tester(copts)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return clients
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
function resolveSubject(name: string, container: any) {
|
|
146
|
+
const subject = container[name] || container.struct[name]
|
|
147
|
+
return subject
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
function resolveFlags(flags?: Flags): Flags {
|
|
152
|
+
if (null == flags) {
|
|
153
|
+
flags = {}
|
|
154
|
+
}
|
|
155
|
+
flags.null = null == flags.null ? true : !!flags.null
|
|
156
|
+
return flags
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
function resolveEntry(entry: any, flags: Flags): any {
|
|
161
|
+
entry.out = null == entry.out && flags.null ? NULLMARK : entry.out
|
|
162
|
+
return entry
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
function checkResult(entry: any, res: any, structUtils: Record<string, any>) {
|
|
167
|
+
let matched = false
|
|
168
|
+
|
|
169
|
+
if (entry.err) {
|
|
170
|
+
return fail('Expected error did not occur: ' + entry.err +
|
|
171
|
+
'\n\nENTRY: ' + JSON.stringify(entry, null, 2))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (entry.match) {
|
|
175
|
+
const result = { in: entry.in, out: entry.res, ctx: entry.ctx }
|
|
176
|
+
match(
|
|
177
|
+
entry.match,
|
|
178
|
+
result,
|
|
179
|
+
structUtils
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
matched = true
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const out = entry.out
|
|
186
|
+
|
|
187
|
+
if (out === res) {
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// NOTE: allow match with no out.
|
|
192
|
+
if (matched && (NULLMARK === out || null == out)) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
deepEqual(null != res ? JSON.parse(JSON.stringify(res)) : res, entry.out)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
// Handle errors from test execution
|
|
201
|
+
function handleError(entry: any, err: any, structUtils: Record<string, any>) {
|
|
202
|
+
entry.thrown = err
|
|
203
|
+
|
|
204
|
+
const entry_err = entry.err
|
|
205
|
+
|
|
206
|
+
if (null != entry_err) {
|
|
207
|
+
if (true === entry_err || matchval(entry_err, err.message, structUtils)) {
|
|
208
|
+
if (entry.match) {
|
|
209
|
+
match(
|
|
210
|
+
entry.match,
|
|
211
|
+
{ in: entry.in, out: entry.res, ctx: entry.ctx, err: fixJSON(err, { null: true }) },
|
|
212
|
+
structUtils
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fail('ERROR MATCH: [' + structUtils.stringify(entry_err) +
|
|
219
|
+
'] <=> [' + err.message + ']')
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Unexpected error (test didn't specify an error expectation)
|
|
223
|
+
else if (err instanceof AssertionError) {
|
|
224
|
+
fail(err.message + '\n\nENTRY: ' + JSON.stringify(entry, null, 2))
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
fail(err.stack + '\\nnENTRY: ' + JSON.stringify(entry, null, 2))
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
function resolveArgs(
|
|
233
|
+
entry: any,
|
|
234
|
+
testpack: TestPack,
|
|
235
|
+
utility: Utility,
|
|
236
|
+
structUtils: Record<string, any>
|
|
237
|
+
): any[] {
|
|
238
|
+
let args: any[] = []
|
|
239
|
+
|
|
240
|
+
if (entry.ctx) {
|
|
241
|
+
args = [entry.ctx]
|
|
242
|
+
}
|
|
243
|
+
else if (entry.args) {
|
|
244
|
+
args = entry.args
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
args = [structUtils.clone(entry.in)]
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (entry.ctx || entry.args) {
|
|
251
|
+
let first = args[0]
|
|
252
|
+
if (structUtils.ismap(first)) {
|
|
253
|
+
first = structUtils.clone(first)
|
|
254
|
+
first = utility.contextify(first)
|
|
255
|
+
args[0] = first
|
|
256
|
+
entry.ctx = first
|
|
257
|
+
|
|
258
|
+
first.client = testpack.client
|
|
259
|
+
first.utility = testpack.utility
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return args
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
function resolveTestPack(
|
|
268
|
+
name: string,
|
|
269
|
+
entry: any,
|
|
270
|
+
subject: Subject,
|
|
271
|
+
client: any,
|
|
272
|
+
clients: Record<string, any>
|
|
273
|
+
) {
|
|
274
|
+
const testpack: TestPack = {
|
|
275
|
+
name,
|
|
276
|
+
client,
|
|
277
|
+
subject,
|
|
278
|
+
utility: client.utility(),
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (entry.client) {
|
|
282
|
+
testpack.client = clients[entry.client]
|
|
283
|
+
testpack.utility = testpack.client.utility()
|
|
284
|
+
testpack.subject = resolveSubject(name, testpack.utility)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return testpack
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
function match(
|
|
292
|
+
check: any,
|
|
293
|
+
basex: any,
|
|
294
|
+
structUtils: Record<string, any>
|
|
295
|
+
) {
|
|
296
|
+
const cbase = structUtils.clone(basex)
|
|
297
|
+
|
|
298
|
+
structUtils.walk(check, (_key: any, val: any, _parent: any, path: any) => {
|
|
299
|
+
if (!structUtils.isnode(val)) {
|
|
300
|
+
let baseval = structUtils.getpath(cbase, path)
|
|
301
|
+
|
|
302
|
+
if (baseval === val) {
|
|
303
|
+
return val
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Explicit undefined expected
|
|
307
|
+
if (UNDEFMARK === val && undefined === baseval) {
|
|
308
|
+
return val
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Explicit defined expected
|
|
312
|
+
if (EXISTSMARK === val && null != baseval) {
|
|
313
|
+
return val
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (!matchval(val, baseval, structUtils)) {
|
|
317
|
+
fail('MATCH: ' + path.join('.') +
|
|
318
|
+
': [' + structUtils.stringify(val) +
|
|
319
|
+
'] <=> [' + structUtils.stringify(baseval) + ']')
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return val
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
function matchval(
|
|
329
|
+
check: any,
|
|
330
|
+
base: any,
|
|
331
|
+
structUtils: Record<string, any>
|
|
332
|
+
) {
|
|
333
|
+
let pass = check === base
|
|
334
|
+
|
|
335
|
+
if (!pass) {
|
|
336
|
+
|
|
337
|
+
if ('string' === typeof check) {
|
|
338
|
+
let basestr = structUtils.stringify(base)
|
|
339
|
+
|
|
340
|
+
let rem = check.match(/^\/(.+)\/$/)
|
|
341
|
+
if (rem) {
|
|
342
|
+
pass = new RegExp(rem[1]).test(basestr)
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
pass = basestr.toLowerCase().includes(structUtils.stringify(check).toLowerCase())
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else if ('function' === typeof check) {
|
|
349
|
+
pass = true
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return pass
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
function fixJSON(val: any, flags?: Flags): any {
|
|
358
|
+
if (null == val) {
|
|
359
|
+
return flags?.null ? NULLMARK : val
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const replacer = (_k: string, v: any) => {
|
|
363
|
+
if (null == v && flags?.null) {
|
|
364
|
+
return NULLMARK
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (v instanceof Error) {
|
|
368
|
+
return {
|
|
369
|
+
...v,
|
|
370
|
+
name: v.name,
|
|
371
|
+
message: v.message,
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return v
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return JSON.parse(JSON.stringify(val, replacer))
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
function nullModifier(
|
|
383
|
+
val: any,
|
|
384
|
+
key: any,
|
|
385
|
+
parent: any
|
|
386
|
+
) {
|
|
387
|
+
if ("__NULL__" === val) {
|
|
388
|
+
parent[key] = null
|
|
389
|
+
}
|
|
390
|
+
else if ('string' === typeof val) {
|
|
391
|
+
parent[key] = val.replaceAll('__NULL__', 'null')
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
export {
|
|
397
|
+
NULLMARK,
|
|
398
|
+
EXISTSMARK,
|
|
399
|
+
nullModifier,
|
|
400
|
+
makeRunner,
|
|
401
|
+
}
|
|
402
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
import { test, describe } from 'node:test'
|
|
3
|
+
import { equal } from 'node:assert'
|
|
4
|
+
|
|
5
|
+
import { ProjectNameSDK } from '../..'
|
|
6
|
+
|
|
7
|
+
const client = ProjectNameSDK.test({}, {
|
|
8
|
+
apikey: 'APIKEY01',
|
|
9
|
+
|
|
10
|
+
// NOTE: original utility.options must remain in place.
|
|
11
|
+
utility: {
|
|
12
|
+
auth: () => ({ util: 'AUTH' }),
|
|
13
|
+
body: () => ({ util: 'BODY' }),
|
|
14
|
+
contextify: () => ({ util: 'CONTEXTIFY' }),
|
|
15
|
+
done: () => ({ util: 'DONE' }),
|
|
16
|
+
error: () => ({ util: 'ERROR' }),
|
|
17
|
+
findparam: () => ({ util: 'FINDPARAM' }),
|
|
18
|
+
fullurl: () => ({ util: 'FULLURL' }),
|
|
19
|
+
headers: () => ({ util: 'HEADERS' }),
|
|
20
|
+
method: () => ({ util: 'METHOD' }),
|
|
21
|
+
operator: () => ({ util: 'OPERATOR' }),
|
|
22
|
+
params: () => ({ util: 'PARAMS' }),
|
|
23
|
+
query: () => ({ util: 'QUERY' }),
|
|
24
|
+
reqform: () => ({ util: 'REQFORM' }),
|
|
25
|
+
request: () => ({ util: 'REQUEST' }),
|
|
26
|
+
resbasic: () => ({ util: 'RESBASIC' }),
|
|
27
|
+
resbody: () => ({ util: 'RESBODY' }),
|
|
28
|
+
resform: () => ({ util: 'RESFORM' }),
|
|
29
|
+
resheaders: () => ({ util: 'RESHEADERS' }),
|
|
30
|
+
response: () => ({ util: 'RESPONSE' }),
|
|
31
|
+
result: () => ({ util: 'RESULT' }),
|
|
32
|
+
spec: () => ({ util: 'SPEC' }),
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
describe('Custom', () => {
|
|
38
|
+
test('basic', async () => {
|
|
39
|
+
const u: any = client.utility()
|
|
40
|
+
|
|
41
|
+
equal(u.auth().util, 'AUTH')
|
|
42
|
+
equal(u.body().util, 'BODY')
|
|
43
|
+
equal(u.contextify().util, 'CONTEXTIFY')
|
|
44
|
+
equal(u.done().util, 'DONE')
|
|
45
|
+
equal(u.error().util, 'ERROR')
|
|
46
|
+
equal(u.findparam().util, 'FINDPARAM')
|
|
47
|
+
equal(u.fullurl().util, 'FULLURL')
|
|
48
|
+
equal(u.headers().util, 'HEADERS')
|
|
49
|
+
equal(u.method().util, 'METHOD')
|
|
50
|
+
equal(u.operator().util, 'OPERATOR')
|
|
51
|
+
equal(u.params().util, 'PARAMS')
|
|
52
|
+
equal(u.query().util, 'QUERY')
|
|
53
|
+
equal(u.reqform().util, 'REQFORM')
|
|
54
|
+
equal(u.resbasic().util, 'RESBASIC')
|
|
55
|
+
equal(u.resbody().util, 'RESBODY')
|
|
56
|
+
equal(u.resform().util, 'RESFORM')
|
|
57
|
+
equal(u.resheaders().util, 'RESHEADERS')
|
|
58
|
+
equal(u.response().util, 'RESPONSE')
|
|
59
|
+
equal(u.result().util, 'RESULT')
|
|
60
|
+
equal(u.spec().util, 'SPEC')
|
|
61
|
+
})
|
|
62
|
+
})
|