@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.
Files changed (213) hide show
  1. package/bin/voxgig-sdkgen +6 -6
  2. package/dist/action/action.js +1 -2
  3. package/dist/action/action.js.map +1 -1
  4. package/dist/action/feature.js +4 -2
  5. package/dist/action/feature.js.map +1 -1
  6. package/dist/action/target.js +4 -2
  7. package/dist/action/target.js.map +1 -1
  8. package/dist/cmp/Entity.js +2 -1
  9. package/dist/cmp/Entity.js.map +1 -1
  10. package/dist/cmp/Feature.js +11 -9
  11. package/dist/cmp/Feature.js.map +1 -1
  12. package/dist/cmp/FeatureHook.js +2 -1
  13. package/dist/cmp/FeatureHook.js.map +1 -1
  14. package/dist/cmp/Main.js +6 -2
  15. package/dist/cmp/Main.js.map +1 -1
  16. package/dist/cmp/ReadmeEntity.js +2 -1
  17. package/dist/cmp/ReadmeEntity.js.map +1 -1
  18. package/dist/cmp/Test.d.ts +2 -0
  19. package/dist/cmp/Test.js +17 -0
  20. package/dist/cmp/Test.js.map +1 -0
  21. package/dist/sdkgen.d.ts +2 -1
  22. package/dist/sdkgen.js +17 -28
  23. package/dist/sdkgen.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/dist/types.d.ts +3 -1
  26. package/dist/types.js +4 -0
  27. package/dist/types.js.map +1 -1
  28. package/model/sdkgen.jsonic +9 -9
  29. package/package.json +8 -6
  30. package/project/.sdk/model/feature/log.jsonic +3 -3
  31. package/project/.sdk/model/feature/test.jsonic +8 -3
  32. package/project/.sdk/model/target/go.jsonic +19 -4
  33. package/project/.sdk/model/target/js.jsonic +2 -2
  34. package/project/.sdk/model/target/ts.jsonic +5 -5
  35. package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
  36. package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
  37. package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
  38. package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
  39. package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
  40. package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
  41. package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
  42. package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
  43. package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
  44. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
  45. package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
  46. package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
  47. package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
  48. package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
  49. package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
  50. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
  51. package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
  52. package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
  53. package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
  54. package/project/.sdk/src/cmp/js/Main_js.ts +3 -3
  55. package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
  56. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
  57. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
  58. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
  59. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
  60. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
  61. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
  62. package/project/.sdk/src/cmp/ts/Config_ts.ts +53 -6
  63. package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
  64. package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
  65. package/project/.sdk/src/cmp/ts/Main_ts.ts +23 -13
  66. package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
  67. package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
  68. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
  69. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +349 -2
  70. package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
  71. package/project/.sdk/src/cmp/ts/Test_ts.ts +23 -3
  72. package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
  73. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
  74. package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
  75. package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
  76. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
  77. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
  78. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
  79. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +51 -32
  80. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
  81. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +166 -34
  82. package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
  83. package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
  84. package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
  85. package/project/.sdk/tm/go/Makefile +10 -0
  86. package/project/.sdk/tm/go/core/context.go +267 -0
  87. package/project/.sdk/tm/go/core/control.go +7 -0
  88. package/project/.sdk/tm/go/core/error.go +25 -0
  89. package/project/.sdk/tm/go/core/helpers.go +33 -0
  90. package/project/.sdk/tm/go/core/operation.go +61 -0
  91. package/project/.sdk/tm/go/core/response.go +55 -0
  92. package/project/.sdk/tm/go/core/result.go +73 -0
  93. package/project/.sdk/tm/go/core/spec.go +97 -0
  94. package/project/.sdk/tm/go/core/target.go +102 -0
  95. package/project/.sdk/tm/go/core/types.go +44 -0
  96. package/project/.sdk/tm/go/core/utility_type.go +54 -0
  97. package/project/.sdk/tm/go/feature/base_feature.go +40 -0
  98. package/project/.sdk/tm/go/feature/test_feature.go +196 -0
  99. package/project/.sdk/tm/go/src/feature/README.md +1 -0
  100. package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
  101. package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
  102. package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
  103. package/project/.sdk/tm/go/test/exists_test.go +16 -0
  104. package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
  105. package/project/.sdk/tm/go/test/runner_test.go +428 -0
  106. package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
  107. package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
  108. package/project/.sdk/tm/go/utility/clean.go +7 -0
  109. package/project/.sdk/tm/go/utility/done.go +20 -0
  110. package/project/.sdk/tm/go/utility/feature_add.go +10 -0
  111. package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
  112. package/project/.sdk/tm/go/utility/feature_init.go +30 -0
  113. package/project/.sdk/tm/go/utility/fetcher.go +102 -0
  114. package/project/.sdk/tm/go/utility/make_context.go +7 -0
  115. package/project/.sdk/tm/go/utility/make_error.go +69 -0
  116. package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
  117. package/project/.sdk/tm/go/utility/make_options.go +130 -0
  118. package/project/.sdk/tm/go/utility/make_request.go +59 -0
  119. package/project/.sdk/tm/go/utility/make_response.go +46 -0
  120. package/project/.sdk/tm/go/utility/make_result.go +55 -0
  121. package/project/.sdk/tm/go/utility/make_spec.go +68 -0
  122. package/project/.sdk/tm/go/utility/make_target.go +95 -0
  123. package/project/.sdk/tm/go/utility/make_url.go +41 -0
  124. package/project/.sdk/tm/go/utility/param.go +66 -0
  125. package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
  126. package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
  127. package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
  128. package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
  129. package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
  130. package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
  131. package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
  132. package/project/.sdk/tm/go/utility/register.go +39 -0
  133. package/project/.sdk/tm/go/utility/result_basic.go +31 -0
  134. package/project/.sdk/tm/go/utility/result_body.go +17 -0
  135. package/project/.sdk/tm/go/utility/result_headers.go +22 -0
  136. package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
  137. package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
  138. package/project/.sdk/tm/go/utility/transform_request.go +32 -0
  139. package/project/.sdk/tm/go/utility/transform_response.go +45 -0
  140. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
  141. package/project/.sdk/tm/ts/src/Context.ts +144 -0
  142. package/project/.sdk/tm/ts/src/Control.ts +20 -0
  143. package/project/.sdk/tm/ts/src/Operation.ts +24 -0
  144. package/project/.sdk/tm/ts/src/Response.ts +26 -0
  145. package/project/.sdk/tm/ts/src/Result.ts +30 -0
  146. package/project/.sdk/tm/ts/src/Spec.ts +40 -0
  147. package/project/.sdk/tm/ts/src/Target.ts +36 -0
  148. package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
  149. package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
  150. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +158 -104
  151. package/project/.sdk/tm/ts/src/types.ts +18 -78
  152. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
  153. package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +3 -4
  154. package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
  155. package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +8 -5
  156. package/project/.sdk/tm/ts/src/utility/FeatureInitUtility.ts +15 -0
  157. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +20 -2
  158. package/project/.sdk/tm/ts/src/utility/MakeContextUtility.ts +27 -0
  159. package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +10 -6
  160. package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
  161. package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +32 -7
  162. package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
  163. package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
  164. package/project/.sdk/tm/ts/src/utility/MakeResultUtility.ts +56 -0
  165. package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
  166. package/project/.sdk/tm/ts/src/utility/MakeTargetUtility.ts +76 -0
  167. package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +61 -0
  168. package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +28 -8
  169. package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +10 -4
  170. package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +32 -0
  171. package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
  172. package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
  173. package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
  174. package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +17 -0
  175. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
  176. package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +12 -7
  177. package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +22 -0
  178. package/project/.sdk/tm/ts/src/utility/ResultHeadersUtility.ts +26 -0
  179. package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
  180. package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
  181. package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +11 -8
  182. package/project/.sdk/tm/ts/src/utility/Utility.ts +52 -65
  183. package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
  184. package/project/.sdk/tm/ts/test/runner.ts +36 -13
  185. package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
  186. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +385 -168
  187. package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
  188. package/src/action/action.ts +1 -2
  189. package/src/action/feature.ts +7 -2
  190. package/src/action/target.ts +7 -7
  191. package/src/cmp/Entity.ts +7 -1
  192. package/src/cmp/Feature.ts +11 -9
  193. package/src/cmp/FeatureHook.ts +6 -1
  194. package/src/cmp/Main.ts +12 -2
  195. package/src/cmp/ReadmeEntity.ts +6 -1
  196. package/src/cmp/Test.ts +31 -0
  197. package/src/sdkgen.ts +19 -34
  198. package/src/types.ts +10 -1
  199. package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
  200. package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +0 -29
  201. package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +0 -67
  202. package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +0 -46
  203. package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +0 -13
  204. package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
  205. package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
  206. package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
  207. package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
  208. package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -66
  209. package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +0 -19
  210. package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +0 -23
  211. package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -30
  212. package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +0 -36
  213. 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 reqform(ctx: Context) {
9
- const { spec, utility } = ctx
10
- const { struct, error } = utility
11
- const { isfunc, transform } = struct
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 = ctx.op.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 error(ctx, err)
28
+ return utility.makeError(ctx, err)
27
29
  }
28
30
  }
29
31
 
30
32
 
31
33
  export {
32
- reqform
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 resform(ctx: Context) {
10
- const { spec, result, utility } = ctx
11
- const { struct, error } = utility
12
- const { isfunc, transform } = struct
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 = ctx.op.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 error(ctx, err)
32
+ return utility.makeError(ctx, err)
30
33
  }
31
34
  }
32
35
 
33
36
 
34
37
  export {
35
- resform
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 { error } from './ErrorUtility'
26
- import { featurehook } from './FeaturehookUtility'
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 { 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'
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
- error = error
59
- featurehook = featurehook
40
+ makeError = makeError
41
+ featureAdd = featureAdd
42
+ featureHook = featureHook
43
+ featureInit = featureInit
60
44
  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
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
  }
@@ -10,7 +10,6 @@ describe('exists', async () => {
10
10
 
11
11
  test('test-mode', async () => {
12
12
  const testsdk = await ProjectNameSDK.test()
13
- // console.log('testsdk', testsdk)
14
13
  equal(null !== testsdk, true)
15
14
  })
16
15
 
@@ -1,10 +1,10 @@
1
- // VERSION: @voxgig/struct 0.0.4
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 { deepEqual, fail, AssertionError } from 'node:assert'
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
- contextify: (ctxmap: Record<string, any>) => any
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: ' + JSON.stringify(entry, null, 2))
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
- deepEqual(null != res ? JSON.parse(JSON.stringify(res)) : res, entry.out)
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: ' + JSON.stringify(entry, null, 2))
226
+ fail(err.message + '\n\nENTRY: ' + safeStringify(entry))
225
227
  }
226
228
  else {
227
- fail(err.stack + '\\nnENTRY: ' + JSON.stringify(entry, null, 2))
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.contextify(first)
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')