@voxgig/sdkgen 0.26.1 → 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 (157) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Feature.js +11 -9
  3. package/dist/cmp/Feature.js.map +1 -1
  4. package/dist/cmp/Main.js +6 -2
  5. package/dist/cmp/Main.js.map +1 -1
  6. package/model/sdkgen.jsonic +1 -1
  7. package/package.json +3 -3
  8. package/project/.sdk/model/feature/log.jsonic +1 -1
  9. package/project/.sdk/model/feature/test.jsonic +1 -1
  10. package/project/.sdk/model/target/go.jsonic +19 -4
  11. package/project/.sdk/model/target/ts.jsonic +3 -3
  12. package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
  13. package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
  14. package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
  15. package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
  16. package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
  17. package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
  18. package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
  19. package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
  20. package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
  21. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
  22. package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
  23. package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
  24. package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
  25. package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
  26. package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
  27. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
  28. package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
  29. package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
  30. package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
  31. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
  32. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
  33. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
  34. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
  35. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
  36. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
  37. package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +1 -1
  38. package/project/.sdk/src/cmp/ts/Main_ts.ts +4 -4
  39. package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
  40. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
  41. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +14 -6
  42. package/project/.sdk/src/cmp/ts/Test_ts.ts +2 -0
  43. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
  44. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +12 -12
  45. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +12 -12
  46. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +12 -12
  47. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +13 -13
  48. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +12 -12
  49. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +102 -6
  50. package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
  51. package/project/.sdk/tm/go/Makefile +10 -0
  52. package/project/.sdk/tm/go/core/context.go +267 -0
  53. package/project/.sdk/tm/go/core/control.go +7 -0
  54. package/project/.sdk/tm/go/core/error.go +25 -0
  55. package/project/.sdk/tm/go/core/helpers.go +33 -0
  56. package/project/.sdk/tm/go/core/operation.go +61 -0
  57. package/project/.sdk/tm/go/core/response.go +55 -0
  58. package/project/.sdk/tm/go/core/result.go +73 -0
  59. package/project/.sdk/tm/go/core/spec.go +97 -0
  60. package/project/.sdk/tm/go/core/target.go +102 -0
  61. package/project/.sdk/tm/go/core/types.go +44 -0
  62. package/project/.sdk/tm/go/core/utility_type.go +54 -0
  63. package/project/.sdk/tm/go/feature/base_feature.go +40 -0
  64. package/project/.sdk/tm/go/feature/test_feature.go +196 -0
  65. package/project/.sdk/tm/go/src/feature/README.md +1 -0
  66. package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
  67. package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
  68. package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
  69. package/project/.sdk/tm/go/test/exists_test.go +16 -0
  70. package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
  71. package/project/.sdk/tm/go/test/runner_test.go +428 -0
  72. package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
  73. package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
  74. package/project/.sdk/tm/go/utility/clean.go +7 -0
  75. package/project/.sdk/tm/go/utility/done.go +20 -0
  76. package/project/.sdk/tm/go/utility/feature_add.go +10 -0
  77. package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
  78. package/project/.sdk/tm/go/utility/feature_init.go +30 -0
  79. package/project/.sdk/tm/go/utility/fetcher.go +102 -0
  80. package/project/.sdk/tm/go/utility/make_context.go +7 -0
  81. package/project/.sdk/tm/go/utility/make_error.go +69 -0
  82. package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
  83. package/project/.sdk/tm/go/utility/make_options.go +130 -0
  84. package/project/.sdk/tm/go/utility/make_request.go +59 -0
  85. package/project/.sdk/tm/go/utility/make_response.go +46 -0
  86. package/project/.sdk/tm/go/utility/make_result.go +55 -0
  87. package/project/.sdk/tm/go/utility/make_spec.go +68 -0
  88. package/project/.sdk/tm/go/utility/make_target.go +95 -0
  89. package/project/.sdk/tm/go/utility/make_url.go +41 -0
  90. package/project/.sdk/tm/go/utility/param.go +66 -0
  91. package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
  92. package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
  93. package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
  94. package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
  95. package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
  96. package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
  97. package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
  98. package/project/.sdk/tm/go/utility/register.go +39 -0
  99. package/project/.sdk/tm/go/utility/result_basic.go +31 -0
  100. package/project/.sdk/tm/go/utility/result_body.go +17 -0
  101. package/project/.sdk/tm/go/utility/result_headers.go +22 -0
  102. package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
  103. package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
  104. package/project/.sdk/tm/go/utility/transform_request.go +32 -0
  105. package/project/.sdk/tm/go/utility/transform_response.go +45 -0
  106. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
  107. package/project/.sdk/tm/ts/src/Context.ts +144 -0
  108. package/project/.sdk/tm/ts/src/Control.ts +20 -0
  109. package/project/.sdk/tm/ts/src/Operation.ts +24 -0
  110. package/project/.sdk/tm/ts/src/Response.ts +26 -0
  111. package/project/.sdk/tm/ts/src/Result.ts +30 -0
  112. package/project/.sdk/tm/ts/src/Spec.ts +40 -0
  113. package/project/.sdk/tm/ts/src/Target.ts +36 -0
  114. package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
  115. package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
  116. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +7 -7
  117. package/project/.sdk/tm/ts/src/types.ts +15 -205
  118. package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +2 -3
  119. package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
  120. package/project/.sdk/tm/ts/src/utility/{InitfeatureUtility.ts → FeatureInitUtility.ts} +2 -2
  121. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +5 -3
  122. package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +4 -4
  123. package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
  124. package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +10 -7
  125. package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
  126. package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
  127. package/project/.sdk/tm/ts/src/utility/{ResultUtility.ts → MakeResultUtility.ts} +6 -6
  128. package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
  129. package/project/.sdk/tm/ts/src/utility/{SelectionUtility.ts → MakeTargetUtility.ts} +22 -24
  130. package/project/.sdk/tm/ts/src/utility/{FullurlUtility.ts → MakeUrlUtility.ts} +7 -8
  131. package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +21 -8
  132. package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +4 -4
  133. package/project/.sdk/tm/ts/src/utility/{BodyUtility.ts → PrepareBodyUtility.ts} +7 -7
  134. package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
  135. package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
  136. package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
  137. package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +3 -4
  138. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
  139. package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +11 -6
  140. package/project/.sdk/tm/ts/src/utility/{ResbodyUtility.ts → ResultBodyUtility.ts} +4 -3
  141. package/project/.sdk/tm/ts/src/utility/{ResheadersUtility.ts → ResultHeadersUtility.ts} +4 -3
  142. package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
  143. package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +10 -7
  144. package/project/.sdk/tm/ts/src/utility/Utility.ts +47 -62
  145. package/project/.sdk/tm/ts/test/runner.ts +25 -4
  146. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +386 -175
  147. package/src/cmp/Feature.ts +11 -9
  148. package/src/cmp/Main.ts +8 -2
  149. package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
  150. package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +0 -23
  151. package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
  152. package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
  153. package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -83
  154. package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -61
  155. package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -68
  156. /package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +0 -0
  157. /package/project/.sdk/tm/ts/src/utility/{ContextUtility.ts → MakeContextUtility.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
 
2
2
  import { test, describe, before } from 'node:test'
3
- import { equal } from 'node:assert'
3
+ import { equal, deepStrictEqual, ok } from 'node:assert'
4
+ import assert from 'node:assert'
4
5
 
5
6
  import {
6
7
  makeRunner,
@@ -12,239 +13,449 @@ import {
12
13
  } from './index'
13
14
 
14
15
 
15
-
16
16
  describe('PrimaryUtility', async () => {
17
17
 
18
+ let spec: any
19
+ let runset: any
20
+ let runsetflags: any
18
21
  let client: any
19
- let runner: any
20
- let runners: any
22
+ let utility: any
23
+ let struct: any
24
+
25
+
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()
30
+ }
31
+ }
32
+
21
33
 
22
34
  before(async () => {
23
- client = SDK.test()
24
- runner = await makeRunner(TEST_JSON_FILE, client)
25
-
26
- runners = {
27
- auth: await runner('auth'),
28
- body: await runner('body'),
29
- // makeContext: await runner('makeContext'),
30
- done: await runner('done'),
31
- error: await runner('error'),
32
- findparam: await runner('findparam'),
33
- fullurl: await runner('fullurl'),
34
- headers: await runner('headers'),
35
- method: await runner('method'),
36
- operator: await runner('operator'),
37
- options: await runner('options'),
38
- params: await runner('params'),
39
- query: await runner('query'),
40
- reqform: await runner('reqform'),
41
- request: await runner('request', { fetch: MockFetch }),
42
- resbasic: await runner('resbasic'),
43
- resbody: await runner('resbody'),
44
- resform: await runner('resform'),
45
- resheaders: await runner('resheaders'),
46
- response: await runner('response'),
47
- spec: await runner('spec'),
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')
48
59
  }
60
+ })
61
+
62
+
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
+ })
87
+
88
+
89
+ test('params-basic', async () => {
90
+ await runset(spec.prepareParams.basic, utility.prepareParams)
91
+ })
92
+
93
+
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
+ })
115
+
116
+
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
+ })
125
+
126
+
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
+
49
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
+ })
50
145
  })
51
146
 
52
147
 
53
- async function MockFetch(url: string, fetchdef: any) {
54
- return {
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) => ({
55
193
  status: 200,
56
194
  statusText: 'OK',
57
- }
58
- }
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
+ })
59
210
 
60
211
 
61
- function MockResponse(resdef: any) {
62
- const mres = {
63
- native: {
64
- status: resdef.native.status,
65
- statusText: resdef.native.reason,
66
- json: async () => resdef.native.body,
67
- headers: {
68
- forEach(callback: any) {
69
- Object.keys(resdef.native.headers).forEach((key) => {
70
- callback(resdef.native.headers[key], key, this)
71
- })
72
- }
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()))
73
224
  }
74
- },
75
- err: resdef.err
76
- }
77
- return mres
78
- }
225
+ }
226
+ return utility.makeResponse(ctx)
227
+ })
228
+ })
79
229
 
80
230
 
81
- test('exists', async () => {
82
- equal('function', typeof runners.auth.subject)
83
- equal('function', typeof runners.body.subject)
84
- // equal('function', typeof runners.makeContext.subject)
85
- equal('function', typeof runners.done.subject)
86
- equal('function', typeof runners.error.subject)
87
- equal('function', typeof runners.findparam.subject)
88
- equal('function', typeof runners.fullurl.subject)
89
- equal('function', typeof runners.method.subject)
90
- // equal('function', typeof runners.operator.subject)
91
- equal('function', typeof runners.options.subject)
92
- equal('function', typeof runners.params.subject)
93
- equal('function', typeof runners.query.subject)
94
- equal('function', typeof runners.reqform.subject)
95
- equal('function', typeof runners.request.subject)
96
- equal('function', typeof runners.resbasic.subject)
97
- equal('function', typeof runners.resbody.subject)
98
- equal('function', typeof runners.resform.subject)
99
- equal('function', typeof runners.resheaders.subject)
100
- equal('function', typeof runners.response.subject)
101
- equal('function', typeof runners.spec.subject)
231
+ test('done-basic', async () => {
232
+ await runset(spec.done.basic, (ctx: any) => {
233
+ fixctx(ctx)
234
+ return utility.done(ctx)
235
+ })
102
236
  })
103
237
 
104
238
 
105
- // test('auth-basic', async () => {
106
- // const { runset, spec, subject } = runners.auth
107
- // await runset(spec.basic, undefined, (subject: any) => (vin: any) => {
108
- // return subject(vin, vin.spec)
109
- // })
110
- // })
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
+ })
111
246
 
112
247
 
113
- // // NOTE: the name utilbody avoids conflict with resbody when running individual tests.
114
- // test('utilbody-basic', async () => {
115
- // const { runset, spec, subject } = runners.body
116
- // await runset(spec.basic, subject)
117
- // })
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]
118
260
 
261
+ const result = utility.makeTarget(ctx)
262
+ ok(!(result instanceof Error))
263
+ equal(ctx.target, target)
264
+ })
119
265
 
120
- // test('makeContext-basic', async () => {
121
- // const { runset, spec, subject } = runners.makeContext
122
- // await runset(spec.basic, subject)
123
- // })
124
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
+ })
125
289
 
126
- // test('done-basic', async () => {
127
- // const { runset, spec, subject } = runners.done
128
- // await runset(spec.basic, subject)
129
- // })
130
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
+ })
131
311
 
132
- // test('error-basic', async () => {
133
- // const { runset, spec, subject } = runners.error
134
- // await runset(spec.basic, subject)
135
- // })
136
312
 
313
+ test('featureAdd', () => {
314
+ const ctx = makeCtx()
315
+ const startLen = client._features.length
137
316
 
138
- // test('findparam-basic', async () => {
139
- // const { runset, spec, subject } = runners.findparam
140
- // await runset(spec.basic, subject)
141
- // })
317
+ const feature = {
318
+ version: '0.0.1',
319
+ name: 'testfeat',
320
+ active: true,
321
+ init: () => { },
322
+ }
142
323
 
324
+ utility.featureAdd(ctx, feature)
325
+ equal(client._features.length, startLen + 1)
326
+ equal(client._features[client._features.length - 1].name, 'testfeat')
327
+ })
143
328
 
144
- // test('fullurl-basic', async () => {
145
- // const { runset, spec, subject } = runners.fullurl
146
- // await runset(spec.basic, subject)
147
- // })
148
329
 
330
+ test('featureHook', () => {
331
+ const ctx = makeCtx()
149
332
 
150
- // test('utilheaders-basic', async () => {
151
- // const { runset, spec, subject } = runners.headers
152
- // await runset(spec.basic, subject)
153
- // })
333
+ let called = false
334
+ client._features = [{
335
+ name: 'hookfeat',
336
+ TestHook: () => { called = true },
337
+ }]
154
338
 
339
+ utility.featureHook(ctx, 'TestHook')
340
+ equal(called, true)
341
+ })
155
342
 
156
- // test('method-basic', async () => {
157
- // const { runset, spec, subject } = runners.method
158
- // await runset(spec.basic, subject)
159
- // })
160
343
 
344
+ test('featureInit', () => {
345
+ const ctx = makeCtx()
161
346
 
162
- // test('operator-basic', async () => {
163
- // const { runset, spec, subject } = runners.operator
164
- // await runset(spec.basic, subject)
165
- // })
347
+ let initCalled = false
348
+ const feature: any = {
349
+ name: 'initfeat',
350
+ active: true,
351
+ init: () => { initCalled = true },
352
+ }
166
353
 
354
+ ctx.options.feature.initfeat = { active: true }
167
355
 
168
- // test('options-basic', async () => {
169
- // const { runset, spec, subject, client } = runners.options
170
- // await runset(spec.basic, (vin: any) => {
171
- // vin.prep.utility = client.utility()
172
- // return subject(vin.prep)
173
- // })
174
- // })
356
+ utility.featureInit(ctx, feature)
357
+ equal(initCalled, true)
358
+ })
175
359
 
176
360
 
177
- // test('params-basic', async () => {
178
- // const { runset, spec, subject } = runners.params
179
- // await runset(spec.basic, subject)
180
- // })
361
+ test('featureInit-inactive', () => {
362
+ const ctx = makeCtx()
181
363
 
364
+ let initCalled = false
365
+ const feature: any = {
366
+ name: 'nofeat',
367
+ active: false,
368
+ init: () => { initCalled = true },
369
+ }
182
370
 
183
- // test('query-basic', async () => {
184
- // const { runset, spec, subject } = runners.query
185
- // await runset(spec.basic, subject)
186
- // })
371
+ ctx.options.feature.nofeat = { active: false }
187
372
 
373
+ utility.featureInit(ctx, feature)
374
+ equal(initCalled, false)
375
+ })
188
376
 
189
- // test('reqform-basic', async () => {
190
- // const { runset, spec, subject } = runners.reqform
191
- // await runset(spec.basic, subject)
192
- // })
193
377
 
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
+ })
194
398
 
195
- // test('request-basic', async () => {
196
- // const { runset, spec, subject } = runners.request
197
- // await runset(spec.basic, subject)
198
- // })
199
399
 
400
+ test('fetcher-blocked-test-mode', async () => {
401
+ const blockedClient = new (SDK as any)({
402
+ system: { fetch: async () => ({}) }
403
+ })
404
+ blockedClient._mode = 'test'
200
405
 
201
- // test('resbasic-basic', async () => {
202
- // const { runset, spec, subject } = runners.resbasic
203
- // await runset(spec.basic, (ctx: any) => {
204
- // ctx.response = MockResponse(ctx.response)
205
- // return subject(ctx)
206
- // })
207
- // })
406
+ const blockedUtility = blockedClient.utility()
407
+ const ctx = blockedUtility.makeContext({ opname: 'load' }, blockedClient._rootctx)
408
+ ctx.client = blockedClient
409
+ const fetchdef = { method: 'GET', headers: {} }
208
410
 
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'))
414
+ })
209
415
 
210
- // test('resbody-basic', async () => {
211
- // const { runset, spec, subject } = runners.resbody
212
- // await runset(spec.basic, (ctx: any) => {
213
- // ctx.response = MockResponse(ctx.response)
214
- // return subject(ctx)
215
- // })
216
- // })
217
416
 
417
+ test('makeError-no-throw', () => {
418
+ const ctx = makeFullCtx()
419
+ ctx.ctrl.throw = false
420
+ ctx.result = { ok: false, resdata: { id: 'safe01' } } as any
218
421
 
219
- // test('resform-basic', async () => {
220
- // const { runset, spec, subject } = runners.resform
221
- // await runset(spec.basic, subject)
222
- // })
422
+ const out = utility.makeError(ctx, ctx.error('test_code', 'test message'))
423
+ deepStrictEqual(out, { id: 'safe01' })
424
+ })
223
425
 
224
426
 
225
- // test('resheaders-basic', async () => {
226
- // const { runset, spec, subject } = runners.resheaders
227
- // await runset(spec.basic, (ctx: any) => {
228
- // ctx.response = MockResponse(ctx.response)
229
- // return subject(ctx)
230
- // })
231
- // })
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
+ })
232
433
 
233
434
 
234
- // test('response-basic', async () => {
235
- // const { runset, spec, subject } = runners.response
236
- // await runset(spec.basic, (ctx: any) => {
237
- // ctx.response = MockResponse(ctx.response)
238
- // return subject(ctx)
239
- // })
240
- // })
435
+ // Helper functions for manual tests
436
+ function makeCtx(overrides?: any) {
437
+ return utility.makeContext({
438
+ opname: 'load',
439
+ ...overrides,
440
+ }, client._rootctx)
441
+ }
241
442
 
242
443
 
243
- // test('spec-basic', async () => {
244
- // const { runset, spec, subject } = runners.spec
245
- // await runset(spec.basic, subject)
246
- // })
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
+ }
247
460
 
248
461
  })
249
-
250
-
@@ -5,16 +5,18 @@ const Feature = cmp(function Feature(props: any) {
5
5
  const { target, feature, ctx$ } = props
6
6
  const { log } = ctx$
7
7
 
8
- Folder({ name: 'src/feature/' + feature.name }, () => {
9
- // TODO: Copy should just warn if from not found
10
- Copy({
11
- from: 'tm/' + target.name + '/src/feature/' + feature.name,
12
- replace: {
13
- FEATURE_VERSION: feature.version,
14
- FEATURE_Name: feature.Name,
15
- }
8
+ if (false !== target.srcfeature) {
9
+ Folder({ name: 'src/feature/' + feature.name }, () => {
10
+ // TODO: Copy should just warn if from not found
11
+ Copy({
12
+ from: 'tm/' + target.name + '/src/feature/' + feature.name,
13
+ replace: {
14
+ FEATURE_VERSION: feature.version,
15
+ FEATURE_Name: feature.Name,
16
+ }
17
+ })
16
18
  })
17
- })
19
+ }
18
20
 
19
21
  log.info({
20
22
  point: 'generate-feature', target, feature,