@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,46 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
- function fullurl(ctx: Context) {
5
- const utility = ctx.utility
6
- // const findparam = utility.findparam
7
-
8
- const struct = utility.struct
9
- const { escurl, escre, joinurl } = struct
10
-
11
- const { spec, result } = ctx
12
-
13
- let url = joinurl([spec.base, spec.prefix, spec.path, spec.suffix])
14
- let resmatch: Record<string, any> = {}
15
-
16
- const params = spec.params
17
-
18
- for (let key in params) {
19
- const val = params[key]
20
- if (null != val) {
21
- url = url.replace(RegExp('{' + escre(key) + '}'), escurl(val))
22
- resmatch[key] = val
23
- }
24
- }
25
-
26
- let qsep = '?'
27
- for (let key in spec.query) {
28
- if (null == spec.alias[key]) {
29
- const val = spec.query[key]
30
- if (null != val) {
31
- url += qsep + escurl(key) + '=' + escurl(val)
32
- qsep = '&'
33
- resmatch[key] = val
34
- }
35
- }
36
- }
37
-
38
- result.resmatch = resmatch
39
-
40
- return url
41
- }
42
-
43
-
44
- export {
45
- fullurl
46
- }
@@ -1,13 +0,0 @@
1
-
2
- import { Context, Feature } from '../types'
3
-
4
-
5
- function initfeature(ctx: Context, f: Feature) {
6
- const fopts = ctx.options.feature[f.name] || {}
7
- f.init(ctx, fopts)
8
- }
9
-
10
-
11
- export {
12
- initfeature
13
- }
@@ -1,15 +0,0 @@
1
-
2
- // TODO: MOVE TO STRUCT
3
- function joinurl(...s: string[]) {
4
- return s
5
- .filter(s => null != s && '' !== s)
6
- .map((s, i) => 0 === i ? s.replace(/([^\/])\/+/, '$1/').replace(/\/+$/, '') :
7
- s.replace(/([^\/])\/+/, '$1/').replace(/^\/+/, '').replace(/\/+$/, ''))
8
- .filter(s => '' !== s)
9
- .join('/')
10
- }
11
-
12
-
13
- export {
14
- joinurl
15
- }
@@ -1,90 +0,0 @@
1
-
2
- import { Context, Operation } from '../types'
3
-
4
- import { getprop } from './StructUtility'
5
-
6
-
7
- const OPKIND: any = {
8
- create: 'req',
9
- update: 'req',
10
- remove: 'req',
11
- load: 'res',
12
- list: 'res',
13
- }
14
-
15
-
16
- function opify(opmap: Record<string, any>) {
17
-
18
- const validate = getprop(opmap, 'validate', {})
19
-
20
- const op: Operation = {
21
- name: getprop(opmap, 'name', '_'),
22
- kind: getprop(opmap, 'kind', '_'),
23
- path: getprop(opmap, 'path', '_'),
24
- pathalt: getprop(opmap, 'pathalt', []),
25
- entity: getprop(opmap, 'entity', '_'),
26
- reqform: getprop(opmap, 'reqform', '_'),
27
- resform: getprop(opmap, 'resform', '_'),
28
- validate: {
29
- params: getprop(validate, 'params', { '`$OPEN`': true }),
30
- },
31
-
32
- params: getprop(opmap, 'params', []),
33
- alias: getprop(opmap, 'alias', {}),
34
- state: getprop(opmap, 'state', {}),
35
- check: getprop(opmap, 'check', {}),
36
- }
37
-
38
- return op
39
- }
40
-
41
-
42
- // Ensure standard operation definition.
43
- function operator(ctx: Context): Operation {
44
- const { op, utility } = ctx
45
- const { validate } = utility.struct
46
-
47
- const opspec = {
48
-
49
- // Required.
50
- name: '`$STRING`',
51
- kind: ['`$ONE`', 'req', 'res'],
52
- path: '`$STRING`',
53
- entity: '`$STRING`',
54
- reqform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
55
- resform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
56
- validate: {
57
- params: '`$OBJECT`'
58
- },
59
-
60
- // Optional.
61
- pathalt: ['`$CHILD`', {
62
- path: '`$STRING`',
63
- '`$OPEN`': true,
64
- // '`$CHILD`': '`$BOOLEAN`'
65
- }],
66
- params: ['`$CHILD`', '`$STRING`'],
67
- alias: { '`$CHILD`': '`$STRING`' },
68
- state: {},
69
- check: {},
70
- }
71
-
72
- ctx.op.kind = OPKIND[op.name]
73
-
74
- const opv = ctx.op.validate
75
- ctx.op = validate(ctx.op, opspec)
76
-
77
- ctx.op.validate = opv
78
-
79
- if (ctx.ctrl.explain) {
80
- ctx.ctrl.explain.op = ctx.op
81
- }
82
-
83
- return ctx.op
84
- }
85
-
86
-
87
- export {
88
- opify,
89
- operator,
90
- }
@@ -1,37 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- function params(ctx: Context) {
6
- const utility = ctx.utility
7
- const findparam = utility.findparam
8
-
9
- const struct = utility.struct
10
- const { validate } = struct
11
-
12
-
13
- const { op } = ctx
14
-
15
- let { params } = op
16
- let { reqmatch } = ctx
17
-
18
- params = params || []
19
- reqmatch = reqmatch || {}
20
-
21
- let out: any = {}
22
- for (let key of params) {
23
- let val = findparam(ctx, key)
24
- if (null != val) {
25
- out[key] = val
26
- }
27
- }
28
-
29
- // out = validate(out, op.validate.params)
30
-
31
- return out
32
- }
33
-
34
-
35
- export {
36
- params
37
- }
@@ -1,27 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- function query(ctx: Context) {
6
- const { op } = ctx
7
- let { params } = op
8
- let { reqmatch } = ctx
9
-
10
- params = params || []
11
- reqmatch = reqmatch || {}
12
-
13
- const out: any = {}
14
- for (let key of Object.keys(reqmatch)) {
15
- let val = reqmatch[key]
16
- if (null != val && !params.includes(key)) {
17
- out[key] = val
18
- }
19
- }
20
-
21
- return out
22
- }
23
-
24
-
25
- export {
26
- query
27
- }
@@ -1,66 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- async function request(ctx: Context) {
6
- const { spec, utility } = ctx
7
- const { fullurl, fetcher } = utility
8
-
9
- let response: any = {}
10
-
11
- let result = {
12
- ok: false,
13
- status: -1,
14
- statusText: '',
15
- headers: {},
16
- body: undefined,
17
- err: undefined,
18
- }
19
-
20
- ctx.result = result
21
-
22
-
23
- try {
24
- spec.step = 'prepare'
25
-
26
- const url = spec.url = fullurl(ctx)
27
-
28
- const fetchdef: any = {
29
- method: spec.method,
30
- headers: spec.headers,
31
- }
32
-
33
- if (null != spec.body) {
34
- fetchdef.body =
35
- 'object' === typeof spec.body ? JSON.stringify(spec.body) : spec.body
36
- }
37
-
38
- if (ctx.ctrl.explain) {
39
- ctx.ctrl.explain.fetchdef = fetchdef
40
- }
41
-
42
- spec.step = 'prerequest'
43
-
44
- // TODO: see js code, use `native` prop here
45
- response = await fetcher(ctx, url, fetchdef)
46
-
47
- if (null == response) {
48
- response = { err: new Error('response: undefined') }
49
- }
50
- }
51
- catch (err) {
52
- response = response || {}
53
- response.err = err
54
- }
55
-
56
- spec.step = 'postrequest'
57
-
58
- ctx.response = response
59
-
60
- return response
61
- }
62
-
63
-
64
- export {
65
- request
66
- }
@@ -1,19 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- async function resbody(ctx: Context) {
6
- const { response, result } = ctx
7
-
8
- if (response && response.json) {
9
- const json = await response.json()
10
- result.body = json
11
- }
12
-
13
- return result
14
- }
15
-
16
-
17
- export {
18
- resbody
19
- }
@@ -1,23 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- function resheaders(ctx: Context) {
6
- const { response, result } = ctx
7
-
8
- if (response && response.headers && response.headers.forEach) {
9
- const headers: any = {}
10
- response.headers.forEach((v: any, k: any) => headers[k] = v)
11
- result.headers = headers
12
- }
13
- else {
14
- result.headers = {}
15
- }
16
-
17
- return result
18
- }
19
-
20
-
21
- export {
22
- resheaders
23
- }
@@ -1,30 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- async function response(ctx: Context) {
6
- let { result, spec, utility } = ctx
7
-
8
- const { resheaders, resbasic, resbody, resform } = utility
9
-
10
- spec.step = 'response'
11
-
12
- try {
13
- resbasic(ctx)
14
- resheaders(ctx)
15
- await resbody(ctx)
16
- resform(ctx)
17
-
18
- if (null == result.err) {
19
- result.ok = true
20
- }
21
- }
22
- catch (err) {
23
- result.err = err
24
- }
25
- }
26
-
27
-
28
- export {
29
- response
30
- }
@@ -1,36 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- async function result(ctx: Context) {
6
- let { op, spec, utility, entity, result } = ctx
7
-
8
- const { resform } = utility
9
-
10
- spec.step = 'result'
11
-
12
- resform(ctx)
13
-
14
- if ('list' == op.name) {
15
- const resdata = result.resdata
16
- result.resdata = []
17
-
18
- if (null != resdata && 0 < resdata.length) {
19
- for (let entry of resdata) {
20
- const ent = entity.make()
21
- ent.data(entry)
22
- result.resdata.push(ent)
23
- }
24
- }
25
- }
26
-
27
- if (ctx.ctrl.explain) {
28
- ctx.ctrl.explain.result = result
29
- }
30
-
31
- }
32
-
33
-
34
- export {
35
- result
36
- }
@@ -1,61 +0,0 @@
1
-
2
- import { Context } from '../types'
3
-
4
-
5
- // Create request specificaton.
6
- function spec(ctx: Context) {
7
- const { client, op, utility } = ctx
8
- const struct = utility.struct
9
- const size = struct.size
10
- const select = struct.select
11
- const { method, params, query, headers, body, auth } = utility
12
-
13
- let options = client.options()
14
-
15
- ctx.spec = {
16
- base: options.base, // string, URL endpoint base prefix,
17
- prefix: options.prefix,
18
- path: op.path,
19
- suffix: options.suffix,
20
- method: 'get',
21
- params: {},
22
- query: {},
23
- headers: {},
24
- body: undefined,
25
- step: 'start',
26
- alias: {}
27
- }
28
-
29
- ctx.spec.method = method(ctx)
30
- ctx.spec.params = params(ctx)
31
- ctx.spec.query = query(ctx)
32
- ctx.spec.headers = headers(ctx)
33
- ctx.spec.body = body(ctx)
34
-
35
- if (1 < size(op.pathalt)) {
36
- let hasQuery = false
37
- const paramQuery: any = {}
38
- for (let paramName of op.params) {
39
- paramQuery[paramName] = null == ctx.spec.params[paramName] ? false : true
40
- hasQuery = true
41
- }
42
-
43
- if (hasQuery) {
44
- const foundParamAlts = select(op.pathalt, paramQuery)
45
- if (0 < size(foundParamAlts)) {
46
- ctx.spec.path = foundParamAlts[0].path
47
- }
48
- }
49
- }
50
-
51
- if (ctx.ctrl.explain) {
52
- ctx.ctrl.explain.spec = ctx.spec
53
- }
54
-
55
- auth(ctx)
56
- }
57
-
58
-
59
- export {
60
- spec
61
- }