@voxgig/sdkgen 0.25.0 → 0.28.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 +6 -6
- package/dist/action/action.js +1 -2
- package/dist/action/action.js.map +1 -1
- package/dist/action/feature.js +4 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +4 -2
- 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/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +2 -1
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/Test.d.ts +2 -0
- package/dist/cmp/Test.js +17 -0
- package/dist/cmp/Test.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +17 -28
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/model/sdkgen.jsonic +9 -9
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +3 -3
- package/project/.sdk/model/feature/test.jsonic +8 -3
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +5 -5
- package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
- package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
- package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
- package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
- package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
- package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
- package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
- package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
- package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
- package/project/.sdk/src/cmp/js/Main_js.ts +3 -3
- package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
- package/project/.sdk/src/cmp/ts/Config_ts.ts +53 -6
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
- package/project/.sdk/src/cmp/ts/Main_ts.ts +23 -13
- package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
- package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +349 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +23 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +51 -32
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +166 -34
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
- package/project/.sdk/tm/go/Makefile +10 -0
- package/project/.sdk/tm/go/core/context.go +267 -0
- package/project/.sdk/tm/go/core/control.go +7 -0
- package/project/.sdk/tm/go/core/error.go +25 -0
- package/project/.sdk/tm/go/core/helpers.go +33 -0
- package/project/.sdk/tm/go/core/operation.go +61 -0
- package/project/.sdk/tm/go/core/response.go +55 -0
- package/project/.sdk/tm/go/core/result.go +73 -0
- package/project/.sdk/tm/go/core/spec.go +97 -0
- package/project/.sdk/tm/go/core/target.go +102 -0
- package/project/.sdk/tm/go/core/types.go +44 -0
- package/project/.sdk/tm/go/core/utility_type.go +54 -0
- package/project/.sdk/tm/go/feature/base_feature.go +40 -0
- package/project/.sdk/tm/go/feature/test_feature.go +196 -0
- package/project/.sdk/tm/go/src/feature/README.md +1 -0
- package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
- package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
- package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
- package/project/.sdk/tm/go/test/exists_test.go +16 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
- package/project/.sdk/tm/go/test/runner_test.go +428 -0
- package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
- package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
- package/project/.sdk/tm/go/utility/clean.go +7 -0
- package/project/.sdk/tm/go/utility/done.go +20 -0
- package/project/.sdk/tm/go/utility/feature_add.go +10 -0
- package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
- package/project/.sdk/tm/go/utility/feature_init.go +30 -0
- package/project/.sdk/tm/go/utility/fetcher.go +102 -0
- package/project/.sdk/tm/go/utility/make_context.go +7 -0
- package/project/.sdk/tm/go/utility/make_error.go +69 -0
- package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
- package/project/.sdk/tm/go/utility/make_options.go +130 -0
- package/project/.sdk/tm/go/utility/make_request.go +59 -0
- package/project/.sdk/tm/go/utility/make_response.go +46 -0
- package/project/.sdk/tm/go/utility/make_result.go +55 -0
- package/project/.sdk/tm/go/utility/make_spec.go +68 -0
- package/project/.sdk/tm/go/utility/make_target.go +95 -0
- package/project/.sdk/tm/go/utility/make_url.go +41 -0
- package/project/.sdk/tm/go/utility/param.go +66 -0
- package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
- package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
- package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
- package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
- package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
- package/project/.sdk/tm/go/utility/register.go +39 -0
- package/project/.sdk/tm/go/utility/result_basic.go +31 -0
- package/project/.sdk/tm/go/utility/result_body.go +17 -0
- package/project/.sdk/tm/go/utility/result_headers.go +22 -0
- package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
- package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
- package/project/.sdk/tm/go/utility/transform_request.go +32 -0
- package/project/.sdk/tm/go/utility/transform_response.go +45 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
- package/project/.sdk/tm/ts/src/Context.ts +144 -0
- package/project/.sdk/tm/ts/src/Control.ts +20 -0
- package/project/.sdk/tm/ts/src/Operation.ts +24 -0
- package/project/.sdk/tm/ts/src/Response.ts +26 -0
- package/project/.sdk/tm/ts/src/Result.ts +30 -0
- package/project/.sdk/tm/ts/src/Spec.ts +40 -0
- package/project/.sdk/tm/ts/src/Target.ts +36 -0
- package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +158 -104
- package/project/.sdk/tm/ts/src/types.ts +18 -78
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +8 -5
- package/project/.sdk/tm/ts/src/utility/FeatureInitUtility.ts +15 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +20 -2
- package/project/.sdk/tm/ts/src/utility/MakeContextUtility.ts +27 -0
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +10 -6
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +32 -7
- package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
- package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeResultUtility.ts +56 -0
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeTargetUtility.ts +76 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +28 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +10 -4
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +32 -0
- package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
- package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +17 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +12 -7
- package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +22 -0
- package/project/.sdk/tm/ts/src/utility/ResultHeadersUtility.ts +26 -0
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +11 -8
- package/project/.sdk/tm/ts/src/utility/Utility.ts +52 -65
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +36 -13
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +385 -168
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
- package/src/action/action.ts +1 -2
- package/src/action/feature.ts +7 -2
- package/src/action/target.ts +7 -7
- package/src/cmp/Entity.ts +7 -1
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +12 -2
- package/src/cmp/ReadmeEntity.ts +6 -1
- package/src/cmp/Test.ts +31 -0
- package/src/sdkgen.ts +19 -34
- package/src/types.ts +10 -1
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +0 -29
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +0 -67
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +0 -46
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +0 -13
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -66
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +0 -19
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -30
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +0 -36
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -61
|
@@ -5,17 +5,19 @@ import { Context } from '../types'
|
|
|
5
5
|
*
|
|
6
6
|
* The operation (op) property `reqform` is used to perform the data preparation.
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
8
|
+
function transformRequest(ctx: Context) {
|
|
9
|
+
const spec = ctx.spec
|
|
10
|
+
const utility = ctx.utility
|
|
11
|
+
const target = ctx.target
|
|
12
|
+
const isfunc = utility.struct.isfunc
|
|
13
|
+
const transform = utility.struct.transform
|
|
12
14
|
|
|
13
15
|
if (spec) {
|
|
14
16
|
spec.step = 'reqform'
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
try {
|
|
18
|
-
const reqform =
|
|
20
|
+
const reqform = target.transform.req
|
|
19
21
|
const reqdata = isfunc(reqform) ? reqform(ctx) : transform({
|
|
20
22
|
reqdata: ctx.reqdata
|
|
21
23
|
}, reqform)
|
|
@@ -23,11 +25,11 @@ function reqform(ctx: Context) {
|
|
|
23
25
|
return reqdata
|
|
24
26
|
}
|
|
25
27
|
catch (err) {
|
|
26
|
-
return
|
|
28
|
+
return utility.makeError(ctx, err)
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
export {
|
|
32
|
-
|
|
34
|
+
transformRequest
|
|
33
35
|
}
|
|
@@ -6,31 +6,34 @@ import { Context } from '../types'
|
|
|
6
6
|
*
|
|
7
7
|
* The operation (op) property `resform` is used to perform the data extraction.
|
|
8
8
|
*/
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
9
|
+
function transformResponse(ctx: Context) {
|
|
10
|
+
const spec = ctx.spec
|
|
11
|
+
const result = ctx.result
|
|
12
|
+
const utility = ctx.utility
|
|
13
|
+
const target = ctx.target
|
|
14
|
+
const isfunc = utility.struct.isfunc
|
|
15
|
+
const transform = utility.struct.transform
|
|
13
16
|
|
|
14
17
|
if (spec) {
|
|
15
18
|
spec.step = 'resform'
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
if (!result.ok) {
|
|
21
|
+
if (null == result || !result.ok) {
|
|
19
22
|
return undefined
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
try {
|
|
23
|
-
const resform =
|
|
26
|
+
const resform = target.transform.res
|
|
24
27
|
const resdata = isfunc(resform) ? resform(ctx) : transform(ctx.result, resform)
|
|
25
28
|
result.resdata = resdata
|
|
26
29
|
return resdata
|
|
27
30
|
}
|
|
28
31
|
catch (err) {
|
|
29
|
-
return
|
|
32
|
+
return utility.makeError(ctx, err)
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
export {
|
|
35
|
-
|
|
38
|
+
transformResponse
|
|
36
39
|
}
|
|
@@ -1,82 +1,69 @@
|
|
|
1
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
2
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { addfeature } from './AddfeatureUtility'
|
|
20
|
-
import { auth } from './AuthUtility'
|
|
21
|
-
import { body } from './BodyUtility'
|
|
22
3
|
import { clean } from './CleanUtility'
|
|
23
|
-
import { contextify } from './ContextUtility'
|
|
24
4
|
import { done } from './DoneUtility'
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
5
|
+
import { makeError } from './MakeErrorUtility'
|
|
6
|
+
import { featureAdd } from './FeatureAddUtility'
|
|
7
|
+
import { featureHook } from './FeatureHookUtility'
|
|
8
|
+
import { featureInit } from './FeatureInitUtility'
|
|
27
9
|
import { fetcher } from './FetcherUtility'
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
10
|
+
import { makeFetchDef } from './MakeFetchDefUtility'
|
|
11
|
+
import { makeContext } from './MakeContextUtility'
|
|
12
|
+
import { makeOptions } from './MakeOptionsUtility'
|
|
13
|
+
import { makeRequest } from './MakeRequestUtility'
|
|
14
|
+
import { makeResponse } from './MakeResponseUtility'
|
|
15
|
+
import { makeResult } from './MakeResultUtility'
|
|
16
|
+
import { makeTarget } from './MakeTargetUtility'
|
|
17
|
+
import { makeSpec } from './MakeSpecUtility'
|
|
18
|
+
import { makeUrl } from './MakeUrlUtility'
|
|
19
|
+
import { param } from './ParamUtility'
|
|
20
|
+
import { prepareAuth } from './PrepareAuthUtility'
|
|
21
|
+
import { prepareBody } from './PrepareBodyUtility'
|
|
22
|
+
import { prepareHeaders } from './PrepareHeadersUtility'
|
|
23
|
+
import { prepareMethod } from './PrepareMethodUtility'
|
|
24
|
+
import { prepareParams } from './PrepareParamsUtility'
|
|
25
|
+
import { preparePath } from './PreparePathUtility'
|
|
26
|
+
import { prepareQuery } from './PrepareQueryUtility'
|
|
27
|
+
import { resultBasic } from './ResultBasicUtility'
|
|
28
|
+
import { resultBody } from './ResultBodyUtility'
|
|
29
|
+
import { resultHeaders } from './ResultHeadersUtility'
|
|
30
|
+
import { transformRequest } from './TransformRequestUtility'
|
|
31
|
+
import { transformResponse } from './TransformResponseUtility'
|
|
46
32
|
|
|
47
33
|
import { StructUtility } from './StructUtility'
|
|
48
34
|
|
|
49
35
|
|
|
50
36
|
class Utility {
|
|
51
37
|
|
|
52
|
-
addfeature = addfeature
|
|
53
|
-
auth = auth
|
|
54
|
-
body = body
|
|
55
38
|
clean = clean
|
|
56
|
-
contextify = contextify
|
|
57
39
|
done = done
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
makeError = makeError
|
|
41
|
+
featureAdd = featureAdd
|
|
42
|
+
featureHook = featureHook
|
|
43
|
+
featureInit = featureInit
|
|
60
44
|
fetcher = fetcher
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
45
|
+
makeFetchDef = makeFetchDef
|
|
46
|
+
makeContext = makeContext
|
|
47
|
+
makeOptions = makeOptions
|
|
48
|
+
makeRequest = makeRequest
|
|
49
|
+
makeResponse = makeResponse
|
|
50
|
+
makeResult = makeResult
|
|
51
|
+
makeTarget = makeTarget
|
|
52
|
+
makeSpec = makeSpec
|
|
53
|
+
makeUrl = makeUrl
|
|
54
|
+
param = param
|
|
55
|
+
prepareAuth = prepareAuth
|
|
56
|
+
prepareBody = prepareBody
|
|
57
|
+
prepareHeaders = prepareHeaders
|
|
58
|
+
prepareMethod = prepareMethod
|
|
59
|
+
prepareParams = prepareParams
|
|
60
|
+
preparePath = preparePath
|
|
61
|
+
prepareQuery = prepareQuery
|
|
62
|
+
resultBasic = resultBasic
|
|
63
|
+
resultBody = resultBody
|
|
64
|
+
resultHeaders = resultHeaders
|
|
65
|
+
transformRequest = transformRequest
|
|
66
|
+
transformResponse = transformResponse
|
|
80
67
|
|
|
81
68
|
struct = new StructUtility()
|
|
82
69
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// VERSION: @voxgig/struct 0.0.
|
|
1
|
+
// VERSION: @voxgig/struct 0.0.10
|
|
2
2
|
// This test utility runs the JSON-specified tests in build/test/test.json.
|
|
3
3
|
// (or .sdk/test/test.json if used in a @voxgig/sdkgen project)
|
|
4
4
|
|
|
5
5
|
import { readFileSync } from 'node:fs'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
|
-
import {
|
|
7
|
+
import { deepStrictEqual, fail, AssertionError } from 'node:assert'
|
|
8
8
|
|
|
9
9
|
const NULLMARK = '__NULL__' // Value is JSON null
|
|
10
10
|
const UNDEFMARK = '__UNDEF__' // Value is not present (thus, undefined).
|
|
@@ -16,6 +16,7 @@ type RunSet = (testspec: any, testsubject: Function) => Promise<any>
|
|
|
16
16
|
type RunSetFlags = (testspec: any, flags: Record<string, boolean>, testsubject: Function)
|
|
17
17
|
=> Promise<any>
|
|
18
18
|
|
|
19
|
+
|
|
19
20
|
type RunPack = {
|
|
20
21
|
spec: Record<string, any>
|
|
21
22
|
runset: RunSet
|
|
@@ -24,6 +25,7 @@ type RunPack = {
|
|
|
24
25
|
client: any
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
|
|
27
29
|
type TestPack = {
|
|
28
30
|
name?: string
|
|
29
31
|
client: any
|
|
@@ -36,9 +38,10 @@ type Flags = Record<string, boolean>
|
|
|
36
38
|
|
|
37
39
|
type Utility = {
|
|
38
40
|
struct: any
|
|
39
|
-
|
|
41
|
+
makeContext: (ctxmap: Record<string, any>, basectx?: any) => any
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
|
|
42
45
|
type Client = {
|
|
43
46
|
utility: () => Utility
|
|
44
47
|
}
|
|
@@ -80,7 +83,7 @@ async function makeRunner(testfile: string, client: Client) {
|
|
|
80
83
|
res = fixJSON(res, flags)
|
|
81
84
|
entry.res = res
|
|
82
85
|
|
|
83
|
-
checkResult(entry, res, structUtils)
|
|
86
|
+
checkResult(entry, args, res, structUtils)
|
|
84
87
|
}
|
|
85
88
|
catch (err: any) {
|
|
86
89
|
if (err instanceof AssertionError) {
|
|
@@ -110,8 +113,7 @@ async function makeRunner(testfile: string, client: Client) {
|
|
|
110
113
|
|
|
111
114
|
function resolveSpec(name: string, testfile: string): Record<string, any> {
|
|
112
115
|
const alltests =
|
|
113
|
-
JSON.parse(readFileSync(join(
|
|
114
|
-
__dirname, testfile), 'utf8'))
|
|
116
|
+
JSON.parse(readFileSync(join(__dirname, testfile), 'utf8'))
|
|
115
117
|
|
|
116
118
|
let spec = alltests.primary?.[name] || alltests[name] || alltests
|
|
117
119
|
return spec
|
|
@@ -163,16 +165,16 @@ function resolveEntry(entry: any, flags: Flags): any {
|
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
|
|
166
|
-
function checkResult(entry: any, res: any, structUtils: Record<string, any>) {
|
|
168
|
+
function checkResult(entry: any, args: any[], res: any, structUtils: Record<string, any>) {
|
|
167
169
|
let matched = false
|
|
168
170
|
|
|
169
171
|
if (entry.err) {
|
|
170
172
|
return fail('Expected error did not occur: ' + entry.err +
|
|
171
|
-
'\n\nENTRY: ' +
|
|
173
|
+
'\n\nENTRY: ' + safeStringify(entry))
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
if (entry.match) {
|
|
175
|
-
const result = { in: entry.in, out: entry.res, ctx: entry.ctx }
|
|
177
|
+
const result = { in: entry.in, args, out: entry.res, ctx: entry.ctx }
|
|
176
178
|
match(
|
|
177
179
|
entry.match,
|
|
178
180
|
result,
|
|
@@ -193,7 +195,7 @@ function checkResult(entry: any, res: any, structUtils: Record<string, any>) {
|
|
|
193
195
|
return
|
|
194
196
|
}
|
|
195
197
|
|
|
196
|
-
|
|
198
|
+
deepStrictEqual(null != res ? JSON.parse(safeStringify(res)) : res, entry.out)
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
|
|
@@ -221,10 +223,10 @@ function handleError(entry: any, err: any, structUtils: Record<string, any>) {
|
|
|
221
223
|
|
|
222
224
|
// Unexpected error (test didn't specify an error expectation)
|
|
223
225
|
else if (err instanceof AssertionError) {
|
|
224
|
-
fail(err.message + '\n\nENTRY: ' +
|
|
226
|
+
fail(err.message + '\n\nENTRY: ' + safeStringify(entry))
|
|
225
227
|
}
|
|
226
228
|
else {
|
|
227
|
-
fail(err.stack + '
|
|
229
|
+
fail(err.stack + '\n\nENTRY: ' + safeStringify(entry))
|
|
228
230
|
}
|
|
229
231
|
}
|
|
230
232
|
|
|
@@ -251,7 +253,7 @@ function resolveArgs(
|
|
|
251
253
|
let first = args[0]
|
|
252
254
|
if (structUtils.ismap(first)) {
|
|
253
255
|
first = structUtils.clone(first)
|
|
254
|
-
first = utility.
|
|
256
|
+
first = utility.makeContext(first)
|
|
255
257
|
args[0] = first
|
|
256
258
|
entry.ctx = first
|
|
257
259
|
|
|
@@ -354,11 +356,27 @@ function matchval(
|
|
|
354
356
|
}
|
|
355
357
|
|
|
356
358
|
|
|
359
|
+
function safeStringify(val: any): string {
|
|
360
|
+
const seen = new WeakSet()
|
|
361
|
+
return JSON.stringify(val, (_k, v) => {
|
|
362
|
+
if ('object' === typeof v && null !== v) {
|
|
363
|
+
if (seen.has(v)) return '[Circular]'
|
|
364
|
+
seen.add(v)
|
|
365
|
+
}
|
|
366
|
+
if (v instanceof Error) {
|
|
367
|
+
return { name: v.name, message: v.message }
|
|
368
|
+
}
|
|
369
|
+
return v
|
|
370
|
+
}, 2)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
357
374
|
function fixJSON(val: any, flags?: Flags): any {
|
|
358
375
|
if (null == val) {
|
|
359
376
|
return flags?.null ? NULLMARK : val
|
|
360
377
|
}
|
|
361
378
|
|
|
379
|
+
const seen = new WeakSet()
|
|
362
380
|
const replacer = (_k: string, v: any) => {
|
|
363
381
|
if (null == v && flags?.null) {
|
|
364
382
|
return NULLMARK
|
|
@@ -372,6 +390,11 @@ function fixJSON(val: any, flags?: Flags): any {
|
|
|
372
390
|
}
|
|
373
391
|
}
|
|
374
392
|
|
|
393
|
+
if ('object' === typeof v && null !== v) {
|
|
394
|
+
if (seen.has(v)) return '[Circular]'
|
|
395
|
+
seen.add(v)
|
|
396
|
+
}
|
|
397
|
+
|
|
375
398
|
return v
|
|
376
399
|
}
|
|
377
400
|
|
|
@@ -4,38 +4,39 @@ import { equal } from 'node:assert'
|
|
|
4
4
|
|
|
5
5
|
import { ProjectNameSDK } from '../..'
|
|
6
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
7
|
|
|
37
8
|
describe('Custom', () => {
|
|
9
|
+
|
|
38
10
|
test('basic', async () => {
|
|
11
|
+
const client = ProjectNameSDK.test({}, {
|
|
12
|
+
apikey: 'APIKEY01',
|
|
13
|
+
|
|
14
|
+
// NOTE: original utility.options must remain in place.
|
|
15
|
+
utility: {
|
|
16
|
+
auth: () => ({ util: 'AUTH' }),
|
|
17
|
+
body: () => ({ util: 'BODY' }),
|
|
18
|
+
contextify: () => ({ util: 'CONTEXTIFY' }),
|
|
19
|
+
done: () => ({ util: 'DONE' }),
|
|
20
|
+
error: () => ({ util: 'ERROR' }),
|
|
21
|
+
findparam: () => ({ util: 'FINDPARAM' }),
|
|
22
|
+
fullurl: () => ({ util: 'FULLURL' }),
|
|
23
|
+
headers: () => ({ util: 'HEADERS' }),
|
|
24
|
+
method: () => ({ util: 'METHOD' }),
|
|
25
|
+
operator: () => ({ util: 'OPERATOR' }),
|
|
26
|
+
params: () => ({ util: 'PARAMS' }),
|
|
27
|
+
query: () => ({ util: 'QUERY' }),
|
|
28
|
+
reqform: () => ({ util: 'REQFORM' }),
|
|
29
|
+
request: () => ({ util: 'REQUEST' }),
|
|
30
|
+
resbasic: () => ({ util: 'RESBASIC' }),
|
|
31
|
+
resbody: () => ({ util: 'RESBODY' }),
|
|
32
|
+
resform: () => ({ util: 'RESFORM' }),
|
|
33
|
+
resheaders: () => ({ util: 'RESHEADERS' }),
|
|
34
|
+
response: () => ({ util: 'RESPONSE' }),
|
|
35
|
+
result: () => ({ util: 'RESULT' }),
|
|
36
|
+
spec: () => ({ util: 'SPEC' }),
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
|
|
39
40
|
const u: any = client.utility()
|
|
40
41
|
|
|
41
42
|
equal(u.auth().util, 'AUTH')
|