@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
@@ -1,6 +1,7 @@
1
1
 
2
- import { test, describe } from 'node:test'
3
- import { equal, deepEqual } from 'node:assert'
2
+ import { test, describe, before } from 'node:test'
3
+ import { equal, deepStrictEqual, ok } from 'node:assert'
4
+ import assert from 'node:assert'
4
5
 
5
6
  import {
6
7
  makeRunner,
@@ -12,233 +13,449 @@ import {
12
13
  } from './index'
13
14
 
14
15
 
15
-
16
16
  describe('PrimaryUtility', async () => {
17
17
 
18
- const client = SDK.test()
19
- const runner = await makeRunner(TEST_JSON_FILE, client)
18
+ let spec: any
19
+ let runset: any
20
+ let runsetflags: any
21
+ let client: any
22
+ let utility: any
23
+ let struct: any
20
24
 
21
25
 
22
- async function MockFetch(url: string, fetchdef: any) {
23
- return {
24
- status: 200,
25
- statusText: 'OK',
26
+ // Ensure ctx has options derived from client when needed.
27
+ function fixctx(ctx: any) {
28
+ if (ctx && ctx.client && null == ctx.options) {
29
+ ctx.options = ctx.client.options()
26
30
  }
27
31
  }
28
32
 
29
33
 
30
- function MockResponse(resdef: any) {
31
- const mres = {
32
- native: {
33
- status: resdef.native.status,
34
- statusText: resdef.native.reason,
35
- json: async () => resdef.native.body,
36
- headers: {
37
- forEach(callback: any) {
38
- Object.keys(resdef.native.headers).forEach((key) => {
39
- callback(resdef.native.headers[key], key, this)
40
- })
41
- }
42
- }
43
- },
44
- err: resdef.err
34
+ before(async () => {
35
+ const runner = await makeRunner(TEST_JSON_FILE, await SDK.test())
36
+ const run = await runner('primary')
37
+
38
+ spec = run.spec
39
+ runset = run.runset
40
+ runsetflags = run.runsetflags
41
+ client = run.client
42
+ utility = client.utility()
43
+ struct = utility.struct
44
+ })
45
+
46
+
47
+ test('exists', () => {
48
+ const fns = [
49
+ 'clean', 'done', 'makeError', 'featureAdd', 'featureHook', 'featureInit',
50
+ 'fetcher', 'makeFetchDef', 'makeContext', 'makeOptions', 'makeRequest',
51
+ 'makeResponse', 'makeResult', 'makeTarget', 'makeSpec', 'makeUrl',
52
+ 'param', 'prepareAuth', 'prepareBody', 'prepareHeaders', 'prepareMethod',
53
+ 'prepareParams', 'preparePath', 'prepareQuery', 'resultBasic',
54
+ 'resultBody', 'resultHeaders', 'transformRequest', 'transformResponse',
55
+ ]
56
+
57
+ for (const fn of fns) {
58
+ equal('function', typeof utility[fn], fn + ' should be a function')
45
59
  }
46
- return mres
47
- }
60
+ })
48
61
 
49
62
 
50
- const runners = {
51
- auth: await runner('auth'),
52
- body: await runner('body'),
53
- contextify: await runner('contextify'),
54
- done: await runner('done'),
55
- error: await runner('error'),
56
- findparam: await runner('findparam'),
57
- fullurl: await runner('fullurl'),
58
- headers: await runner('headers'),
59
- method: await runner('method'),
60
- operator: await runner('operator'),
61
- options: await runner('options'),
62
- params: await runner('params'),
63
- query: await runner('query'),
64
- reqform: await runner('reqform'),
65
- request: await runner('request', { fetch: MockFetch }),
66
- resbasic: await runner('resbasic'),
67
- resbody: await runner('resbody'),
68
- resform: await runner('resform'),
69
- resheaders: await runner('resheaders'),
70
- response: await runner('response'),
71
- spec: await runner('spec'),
72
- }
63
+ test('context-basic', async () => {
64
+ await runset(spec.makeContext.basic, utility.makeContext)
65
+ })
66
+
67
+
68
+ test('method-basic', async () => {
69
+ await runset(spec.prepareMethod.basic, utility.prepareMethod)
70
+ })
71
+
72
+
73
+ test('headers-basic', async () => {
74
+ await runset(spec.prepareHeaders.basic, utility.prepareHeaders)
75
+ })
76
+
77
+
78
+ test('auth-basic', async () => {
79
+ const sdkopts = spec.prepareAuth?.DEF?.setup?.a || {}
80
+ const authClient = SDK.test({}, sdkopts)
81
+ await runset(spec.prepareAuth.basic, (ctx: any) => {
82
+ ctx.client = authClient
83
+ fixctx(ctx)
84
+ return utility.prepareAuth(ctx)
85
+ })
86
+ })
73
87
 
74
88
 
75
- test('exists', async () => {
76
- equal('function', typeof runners.auth.subject)
77
- equal('function', typeof runners.body.subject)
78
- equal('function', typeof runners.contextify.subject)
79
- equal('function', typeof runners.done.subject)
80
- equal('function', typeof runners.error.subject)
81
- equal('function', typeof runners.findparam.subject)
82
- equal('function', typeof runners.fullurl.subject)
83
- equal('function', typeof runners.method.subject)
84
- equal('function', typeof runners.operator.subject)
85
- equal('function', typeof runners.options.subject)
86
- equal('function', typeof runners.params.subject)
87
- equal('function', typeof runners.query.subject)
88
- equal('function', typeof runners.reqform.subject)
89
- equal('function', typeof runners.request.subject)
90
- equal('function', typeof runners.resbasic.subject)
91
- equal('function', typeof runners.resbody.subject)
92
- equal('function', typeof runners.resform.subject)
93
- equal('function', typeof runners.resheaders.subject)
94
- equal('function', typeof runners.response.subject)
95
- equal('function', typeof runners.spec.subject)
89
+ test('params-basic', async () => {
90
+ await runset(spec.prepareParams.basic, utility.prepareParams)
96
91
  })
97
92
 
98
93
 
99
- // test('auth-basic', async () => {
100
- // const { runset, spec, subject } = runners.auth
101
- // await runset(spec.basic, undefined, (subject: any) => (vin: any) => {
102
- // return subject(vin, vin.spec)
103
- // })
104
- // })
94
+ test('query-basic', async () => {
95
+ await runset(spec.prepareQuery.basic, utility.prepareQuery)
96
+ })
97
+
98
+
99
+ test('body-basic', async () => {
100
+ await runset(spec.prepareBody.basic, (ctx: any) => {
101
+ fixctx(ctx)
102
+ return utility.prepareBody(ctx)
103
+ })
104
+ })
105
+
106
+
107
+ test('findparam-basic', async () => {
108
+ await runset(spec.param.basic, utility.param)
109
+ })
110
+
111
+
112
+ test('fullurl-basic', async () => {
113
+ await runset(spec.makeUrl.basic, utility.makeUrl)
114
+ })
105
115
 
106
116
 
107
- // // NOTE: the name utilbody avoids conflict with resbody when running individual tests.
108
- // test('utilbody-basic', async () => {
109
- // const { runset, spec, subject } = runners.body
110
- // await runset(spec.basic, subject)
111
- // })
117
+ test('operator-basic', async () => {
118
+ await runset(spec.operator.basic, (opmap: any) => ({
119
+ entity: opmap.entity || '_',
120
+ name: opmap.name || '_',
121
+ input: opmap.input || '_',
122
+ targets: opmap.targets || [],
123
+ }))
124
+ })
112
125
 
113
126
 
114
- test('contextify-basic', async () => {
115
- const { runset, spec, subject } = runners.contextify
116
- await runset(spec.basic, subject)
127
+ test('options-basic', async () => {
128
+ await runset(spec.makeOptions.basic, (vin: any) => {
129
+ const ctx = utility.makeContext({ options: vin.options, config: vin.config })
130
+ ctx.client = client
131
+ ctx.utility = utility
132
+ return utility.makeOptions(ctx)
133
+ })
134
+ })
135
+
136
+
137
+ test('spec-basic', async () => {
138
+ const sdkopts = spec.makeSpec?.DEF?.setup?.a || {}
139
+ const specClient = SDK.test({}, sdkopts)
140
+ await runset(spec.makeSpec.basic, (ctx: any) => {
141
+ ctx.client = specClient
142
+ ctx.options = specClient.options()
143
+ return utility.makeSpec(ctx)
144
+ })
145
+ })
146
+
147
+
148
+ test('reqform-basic', async () => {
149
+ await runset(spec.transformRequest.basic, utility.transformRequest)
150
+ })
151
+
152
+
153
+ test('resform-basic', async () => {
154
+ await runset(spec.transformResponse.basic, utility.transformResponse)
155
+ })
156
+
157
+
158
+ test('resbasic-basic', async () => {
159
+ await runset(spec.resultBasic.basic, (ctx: any) => {
160
+ fixctx(ctx)
161
+ return utility.resultBasic(ctx)
162
+ })
163
+ })
164
+
165
+
166
+ test('resheaders-basic', async () => {
167
+ await runset(spec.resultHeaders.basic, (ctx: any) => {
168
+ // Convert plain headers map to forEach-based (browser Response API)
169
+ if (ctx.response?.headers && !ctx.response.headers.forEach) {
170
+ const h = ctx.response.headers
171
+ ctx.response.headers = {
172
+ forEach: (cb: any) => Object.entries(h).forEach(([k, v]) => cb(v, k.toLowerCase()))
173
+ }
174
+ }
175
+ return utility.resultHeaders(ctx)
176
+ })
177
+ })
178
+
179
+
180
+ test('resbody-basic', async () => {
181
+ await runset(spec.resultBody.basic, async (ctx: any) => {
182
+ if (ctx.response && !ctx.response.json) {
183
+ const body = ctx.response.body
184
+ ctx.response.json = async () => body
185
+ }
186
+ return utility.resultBody(ctx)
187
+ })
188
+ })
189
+
190
+
191
+ test('request-basic', async () => {
192
+ const mockFetch = async (url: string, init: any) => ({
193
+ status: 200,
194
+ statusText: 'OK',
195
+ headers: { forEach: (cb: any) => { cb('application/json', 'content-type', {}) } },
196
+ json: async () => ({ id: 'res01' }),
197
+ body: 'present',
198
+ })
199
+ const reqClient = new (SDK as any)({
200
+ system: { fetch: mockFetch }
201
+ })
202
+ const reqUtility = reqClient.utility()
203
+ await runset(spec.makeRequest.basic, async (ctx: any) => {
204
+ ctx.client = reqClient
205
+ ctx.utility = reqUtility
206
+ ctx.options = reqClient.options()
207
+ return reqUtility.makeRequest(ctx)
208
+ })
209
+ })
210
+
211
+
212
+ test('response-basic', async () => {
213
+ await runset(spec.makeResponse.basic, async (ctx: any) => {
214
+ fixctx(ctx)
215
+ // Add json() and forEach to response for proper TS handling
216
+ if (ctx.response && !ctx.response.json) {
217
+ const body = ctx.response.body
218
+ ctx.response.json = async () => body
219
+ }
220
+ if (ctx.response?.headers && !ctx.response.headers.forEach) {
221
+ const h = ctx.response.headers
222
+ ctx.response.headers = {
223
+ forEach: (cb: any) => Object.entries(h).forEach(([k, v]) => cb(v, k.toLowerCase()))
224
+ }
225
+ }
226
+ return utility.makeResponse(ctx)
227
+ })
117
228
  })
118
229
 
119
230
 
120
231
  test('done-basic', async () => {
121
- const { runset, spec, subject } = runners.done
122
- await runset(spec.basic, subject)
232
+ await runset(spec.done.basic, (ctx: any) => {
233
+ fixctx(ctx)
234
+ return utility.done(ctx)
235
+ })
123
236
  })
124
237
 
125
238
 
126
- // test('error-basic', async () => {
127
- // const { runset, spec, subject } = runners.error
128
- // await runset(spec.basic, subject)
129
- // })
239
+ test('error-basic', async () => {
240
+ await runset(spec.makeError.basic, (...args: any[]) => {
241
+ const ctx = args[0]
242
+ fixctx(ctx)
243
+ return utility.makeError(...args)
244
+ })
245
+ })
130
246
 
131
247
 
132
- // test('findparam-basic', async () => {
133
- // const { runset, spec, subject } = runners.findparam
134
- // await runset(spec.basic, subject)
135
- // })
248
+ test('makeTarget-single', () => {
249
+ const ctx = makeCtx()
250
+ const target = {
251
+ parts: ['items', '{id}'],
252
+ args: { params: [] },
253
+ params: [],
254
+ alias: {},
255
+ select: {},
256
+ active: true,
257
+ transform: { req: undefined, res: undefined },
258
+ }
259
+ ctx.op.targets = [target]
136
260
 
261
+ const result = utility.makeTarget(ctx)
262
+ ok(!(result instanceof Error))
263
+ equal(ctx.target, target)
264
+ })
137
265
 
138
- // test('fullurl-basic', async () => {
139
- // const { runset, spec, subject } = runners.fullurl
140
- // await runset(spec.basic, subject)
141
- // })
142
266
 
267
+ test('makeFetchDef', () => {
268
+ const ctx = makeFullCtx()
269
+ ctx.spec = {
270
+ base: 'http://localhost:8080',
271
+ prefix: '/api',
272
+ path: 'items/{id}',
273
+ suffix: '',
274
+ params: { id: 'item01' },
275
+ query: {},
276
+ headers: { 'content-type': 'application/json' },
277
+ method: 'GET',
278
+ step: 'start',
279
+ body: undefined,
280
+ } as any
281
+
282
+ const fetchdef = utility.makeFetchDef(ctx)
283
+ ok(!(fetchdef instanceof Error), 'should not be error')
284
+ equal(fetchdef.method, 'GET')
285
+ ok(fetchdef.url.includes('/api/items/item01'))
286
+ equal(fetchdef.headers['content-type'], 'application/json')
287
+ ok(null == fetchdef.body)
288
+ })
143
289
 
144
- // test('utilheaders-basic', async () => {
145
- // const { runset, spec, subject } = runners.headers
146
- // await runset(spec.basic, subject)
147
- // })
148
290
 
291
+ test('makeFetchDef-with-body', () => {
292
+ const ctx = makeFullCtx()
293
+ ctx.spec = {
294
+ base: 'http://localhost:8080',
295
+ prefix: '',
296
+ path: 'items',
297
+ suffix: '',
298
+ params: {},
299
+ query: {},
300
+ headers: {},
301
+ method: 'POST',
302
+ step: 'start',
303
+ body: { name: 'test' },
304
+ } as any
305
+
306
+ const fetchdef = utility.makeFetchDef(ctx)
307
+ ok(!(fetchdef instanceof Error))
308
+ equal(fetchdef.method, 'POST')
309
+ equal(fetchdef.body, JSON.stringify({ name: 'test' }, null, 2))
310
+ })
149
311
 
150
- test('method-basic', async () => {
151
- const { runset, spec, subject } = runners.method
152
- await runset(spec.basic, subject)
312
+
313
+ test('featureAdd', () => {
314
+ const ctx = makeCtx()
315
+ const startLen = client._features.length
316
+
317
+ const feature = {
318
+ version: '0.0.1',
319
+ name: 'testfeat',
320
+ active: true,
321
+ init: () => { },
322
+ }
323
+
324
+ utility.featureAdd(ctx, feature)
325
+ equal(client._features.length, startLen + 1)
326
+ equal(client._features[client._features.length - 1].name, 'testfeat')
153
327
  })
154
328
 
155
329
 
156
- // test('operator-basic', async () => {
157
- // const { runset, spec, subject } = runners.operator
158
- // await runset(spec.basic, subject)
159
- // })
330
+ test('featureHook', () => {
331
+ const ctx = makeCtx()
160
332
 
333
+ let called = false
334
+ client._features = [{
335
+ name: 'hookfeat',
336
+ TestHook: () => { called = true },
337
+ }]
161
338
 
162
- // test('options-basic', async () => {
163
- // const { runset, spec, subject, client } = runners.options
164
- // await runset(spec.basic, (vin: any) => {
165
- // vin.prep.utility = client.utility()
166
- // return subject(vin.prep)
167
- // })
168
- // })
339
+ utility.featureHook(ctx, 'TestHook')
340
+ equal(called, true)
341
+ })
169
342
 
170
343
 
171
- // test('params-basic', async () => {
172
- // const { runset, spec, subject } = runners.params
173
- // await runset(spec.basic, subject)
174
- // })
344
+ test('featureInit', () => {
345
+ const ctx = makeCtx()
175
346
 
347
+ let initCalled = false
348
+ const feature: any = {
349
+ name: 'initfeat',
350
+ active: true,
351
+ init: () => { initCalled = true },
352
+ }
176
353
 
177
- // test('query-basic', async () => {
178
- // const { runset, spec, subject } = runners.query
179
- // await runset(spec.basic, subject)
180
- // })
354
+ ctx.options.feature.initfeat = { active: true }
355
+
356
+ utility.featureInit(ctx, feature)
357
+ equal(initCalled, true)
358
+ })
181
359
 
182
360
 
183
- // test('reqform-basic', async () => {
184
- // const { runset, spec, subject } = runners.reqform
185
- // await runset(spec.basic, subject)
186
- // })
361
+ test('featureInit-inactive', () => {
362
+ const ctx = makeCtx()
187
363
 
364
+ let initCalled = false
365
+ const feature: any = {
366
+ name: 'nofeat',
367
+ active: false,
368
+ init: () => { initCalled = true },
369
+ }
188
370
 
189
- // test('request-basic', async () => {
190
- // const { runset, spec, subject } = runners.request
191
- // await runset(spec.basic, subject)
192
- // })
371
+ ctx.options.feature.nofeat = { active: false }
372
+
373
+ utility.featureInit(ctx, feature)
374
+ equal(initCalled, false)
375
+ })
193
376
 
194
377
 
195
- // test('resbasic-basic', async () => {
196
- // const { runset, spec, subject } = runners.resbasic
197
- // await runset(spec.basic, (ctx: any) => {
198
- // ctx.response = MockResponse(ctx.response)
199
- // return subject(ctx)
200
- // })
201
- // })
378
+ test('fetcher-live', async () => {
379
+ const calls: any[] = []
380
+ const liveClient = new (SDK as any)({
381
+ system: {
382
+ fetch: async (url: string, init: any) => {
383
+ calls.push({ url, init })
384
+ return { status: 200, statusText: 'OK' }
385
+ }
386
+ }
387
+ })
388
+ const liveUtility = liveClient.utility()
389
+ const ctx = liveUtility.makeContext({ opname: 'load' }, liveClient._rootctx)
390
+ ctx.client = liveClient
391
+
392
+ const fetchdef = { method: 'GET', headers: {} }
393
+ const response = await liveUtility.fetcher(ctx, 'http://example.com/test', fetchdef)
394
+ ok(!(response instanceof Error))
395
+ equal(calls.length, 1)
396
+ equal(calls[0].url, 'http://example.com/test')
397
+ })
202
398
 
203
399
 
204
- // test('resbody-basic', async () => {
205
- // const { runset, spec, subject } = runners.resbody
206
- // await runset(spec.basic, (ctx: any) => {
207
- // ctx.response = MockResponse(ctx.response)
208
- // return subject(ctx)
209
- // })
210
- // })
400
+ test('fetcher-blocked-test-mode', async () => {
401
+ const blockedClient = new (SDK as any)({
402
+ system: { fetch: async () => ({}) }
403
+ })
404
+ blockedClient._mode = 'test'
211
405
 
406
+ const blockedUtility = blockedClient.utility()
407
+ const ctx = blockedUtility.makeContext({ opname: 'load' }, blockedClient._rootctx)
408
+ ctx.client = blockedClient
409
+ const fetchdef = { method: 'GET', headers: {} }
212
410
 
213
- test('resform-basic', async () => {
214
- const { runset, spec, subject } = runners.resform
215
- await runset(spec.basic, subject)
411
+ const result = await blockedUtility.fetcher(ctx, 'http://example.com/test', fetchdef)
412
+ ok(result instanceof Error)
413
+ ok((result as Error).message.includes('mode'))
216
414
  })
217
415
 
218
416
 
219
- // test('resheaders-basic', async () => {
220
- // const { runset, spec, subject } = runners.resheaders
221
- // await runset(spec.basic, (ctx: any) => {
222
- // ctx.response = MockResponse(ctx.response)
223
- // return subject(ctx)
224
- // })
225
- // })
417
+ test('makeError-no-throw', () => {
418
+ const ctx = makeFullCtx()
419
+ ctx.ctrl.throw = false
420
+ ctx.result = { ok: false, resdata: { id: 'safe01' } } as any
226
421
 
422
+ const out = utility.makeError(ctx, ctx.error('test_code', 'test message'))
423
+ deepStrictEqual(out, { id: 'safe01' })
424
+ })
227
425
 
228
- // test('response-basic', async () => {
229
- // const { runset, spec, subject } = runners.response
230
- // await runset(spec.basic, (ctx: any) => {
231
- // ctx.response = MockResponse(ctx.response)
232
- // return subject(ctx)
233
- // })
234
- // })
235
426
 
427
+ test('clean', () => {
428
+ const ctx = makeFullCtx()
429
+ const val = { key: 'secret123', name: 'test' }
430
+ const cleaned = utility.clean(ctx, val)
431
+ ok(null != cleaned)
432
+ })
236
433
 
237
- // test('spec-basic', async () => {
238
- // const { runset, spec, subject } = runners.spec
239
- // await runset(spec.basic, subject)
240
- // })
241
434
 
242
- })
435
+ // Helper functions for manual tests
436
+ function makeCtx(overrides?: any) {
437
+ return utility.makeContext({
438
+ opname: 'load',
439
+ ...overrides,
440
+ }, client._rootctx)
441
+ }
243
442
 
244
443
 
444
+ function makeFullCtx(overrides?: any) {
445
+ const ctx = makeCtx(overrides)
446
+ ctx.target = {
447
+ parts: ['items', '{id}'],
448
+ args: { params: [{ name: 'id', reqd: true }] },
449
+ params: ['id'],
450
+ alias: {},
451
+ select: {},
452
+ active: true,
453
+ relations: [],
454
+ transform: { req: undefined, res: undefined },
455
+ }
456
+ ctx.match = { id: 'item01' }
457
+ ctx.reqmatch = { id: 'item01' }
458
+ return ctx
459
+ }
460
+
461
+ })