@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
@@ -0,0 +1,46 @@
1
+
2
+ import { Context, Result } from '../types'
3
+
4
+
5
+ function makeFetchDef(ctx: Context): any | Error {
6
+ const spec = ctx.spec
7
+ const utility = ctx.utility
8
+ const makeUrl = utility.makeUrl
9
+ const struct = utility.struct
10
+ const jsonify = struct.jsonify
11
+
12
+ if (null == spec) {
13
+ return ctx.error('fetchdef_no_spec', 'Expected context spec property to be defined.')
14
+ }
15
+
16
+ if (null == ctx.result) {
17
+ ctx.result = new Result({})
18
+ }
19
+
20
+ spec.step = 'prepare'
21
+
22
+ const url = makeUrl(ctx)
23
+ if (url instanceof Error) {
24
+ return url
25
+ }
26
+
27
+ spec.url = url
28
+
29
+ const fetchdef: any = {
30
+ url,
31
+ method: spec.method,
32
+ headers: spec.headers,
33
+ }
34
+
35
+ if (null != spec.body) {
36
+ fetchdef.body =
37
+ 'object' === typeof spec.body ? jsonify(spec.body) : spec.body
38
+ }
39
+
40
+ return fetchdef
41
+ }
42
+
43
+
44
+ export {
45
+ makeFetchDef
46
+ }
@@ -2,20 +2,23 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- function options(ctx: Context) {
6
- const { options, utility } = ctx
5
+ function makeOptions(ctx: Context) {
6
+ const utility = ctx.utility
7
+ const options = ctx.options
7
8
  const struct = utility.struct
9
+ const items = struct.items
8
10
  const setprop = struct.setprop
11
+ const merge = struct.merge
12
+ const validate = struct.validate
13
+ const escre = struct.escre
9
14
 
10
15
  let opts = { ...(options || {}) }
11
16
 
12
17
  const customUtils = opts.utility || {}
13
- for (let key of Object.keys(customUtils)) {
14
- setprop(utility, key, customUtils[key])
18
+ for (let [key, val] of items(customUtils)) {
19
+ setprop(utility, key, val)
15
20
  }
16
21
 
17
- const { merge, validate } = utility.struct
18
-
19
22
  let config = ctx.config || {}
20
23
  let cfgopts = config.options || {}
21
24
 
@@ -31,6 +34,10 @@ function options(ctx: Context) {
31
34
  headers: {
32
35
  '`$CHILD`': '`$STRING`'
33
36
  },
37
+ allow: {
38
+ method: 'GET,PUT,POST,PATCH,DELETE,OPTIONS',
39
+ op: 'create,update,load,list,remove,command,direct'
40
+ },
34
41
  entity: {
35
42
  '`$CHILD`': {
36
43
  '`$OPEN`': true,
@@ -53,6 +60,9 @@ function options(ctx: Context) {
53
60
  entity: {
54
61
  '`$OPEN`': true,
55
62
  }
63
+ },
64
+ clean: {
65
+ keys: 'key,token,id'
56
66
  }
57
67
  }
58
68
 
@@ -63,10 +73,25 @@ function options(ctx: Context) {
63
73
 
64
74
  opts = validate(opts, optspec)
65
75
 
76
+ opts.__derived__ = {
77
+ clean: {
78
+ keyre: undefined
79
+ }
80
+ }
81
+
82
+ const keyre = opts.clean.keys
83
+ .split(/\s*,\s*/)
84
+ .filter((s: string) => null != s && '' !== s)
85
+ .map((key: string) => escre(key)).join('|')
86
+
87
+ if ('' != keyre) {
88
+ opts.__derived__.clean.keyre = keyre
89
+ }
90
+
66
91
  return opts
67
92
  }
68
93
 
69
94
 
70
95
  export {
71
- options
96
+ makeOptions
72
97
  }
@@ -0,0 +1,66 @@
1
+
2
+ import { Context, Response, Result } from '../types'
3
+
4
+
5
+ async function makeRequest(ctx: Context): Promise<Response | Error> {
6
+ // PreRequest feature hook has already provided a result.
7
+ if (ctx.out.request) {
8
+ return ctx.out.request
9
+ }
10
+
11
+ const spec = ctx.spec
12
+ const utility = ctx.utility
13
+ const fetcher = utility.fetcher
14
+ const makeFetchDef = utility.makeFetchDef
15
+
16
+ let response = new Response({})
17
+
18
+ let result = new Result({})
19
+
20
+ ctx.result = result
21
+
22
+ if (null == spec) {
23
+ return ctx.error('request_no_spec', 'Expected context spec property to be defined.')
24
+ }
25
+
26
+
27
+ try {
28
+ const fetchdef = makeFetchDef(ctx)
29
+ if (fetchdef instanceof Error) {
30
+ throw fetchdef
31
+ }
32
+
33
+ if (ctx.ctrl.explain) {
34
+ ctx.ctrl.explain.fetchdef = fetchdef
35
+ }
36
+
37
+ spec.step = 'prerequest'
38
+
39
+ // TODO: see js code, use `native` prop here
40
+ const fetched = await fetcher(ctx, fetchdef.url, fetchdef)
41
+
42
+ if (null == fetched) {
43
+ response = new Response({ err: ctx.error('request_no_response', 'response: undefined') })
44
+ }
45
+ else if (fetched instanceof Error) {
46
+ response = new Response({ err: fetched })
47
+ }
48
+ else {
49
+ response = new Response(fetched)
50
+ }
51
+ }
52
+ catch (err) {
53
+ response.err = err as Error
54
+ }
55
+
56
+ spec.step = 'postrequest'
57
+
58
+ ctx.response = response
59
+
60
+ return response
61
+ }
62
+
63
+
64
+ export {
65
+ makeRequest
66
+ }
@@ -0,0 +1,61 @@
1
+
2
+ import { Context, Response } from '../types'
3
+
4
+
5
+ async function makeResponse(ctx: Context): Promise<Response | Error> {
6
+ // PreResponse feature hook has already provided a result.
7
+ if (ctx.out.response) {
8
+ return ctx.out.response
9
+ }
10
+
11
+ const utility = ctx.utility
12
+ const resultBasic = utility.resultBasic
13
+ const resultHeaders = utility.resultHeaders
14
+ const resultBody = utility.resultBody
15
+ const transformResponse = utility.transformResponse
16
+
17
+ const spec = ctx.spec
18
+ const result = ctx.result
19
+ const response = ctx.response
20
+
21
+
22
+ if (null == spec) {
23
+ return ctx.error('response_no_spec', 'Expected context spec property to be defined.')
24
+ }
25
+
26
+ if (null == response) {
27
+ return ctx.error('response_no_response', 'Expected context response property to be defined.')
28
+ }
29
+
30
+ if (null == result) {
31
+ return ctx.error('response_no_result', 'Expected context result property to be defined.')
32
+ }
33
+
34
+
35
+ spec.step = 'response'
36
+
37
+ try {
38
+ resultBasic(ctx)
39
+ resultHeaders(ctx)
40
+ await resultBody(ctx)
41
+ transformResponse(ctx)
42
+
43
+ if (null == result.err) {
44
+ result.ok = true
45
+ }
46
+ }
47
+ catch (err) {
48
+ result.err = err
49
+ }
50
+
51
+ if (ctx.ctrl.explain) {
52
+ ctx.ctrl.explain.result = result
53
+ }
54
+
55
+ return response
56
+ }
57
+
58
+
59
+ export {
60
+ makeResponse
61
+ }
@@ -0,0 +1,56 @@
1
+
2
+ import { Result, Context } from '../types'
3
+
4
+
5
+ function makeResult(ctx: Context): Result | Error {
6
+ // PreResult feature hook has already provided a result.
7
+ if (ctx.out.result) {
8
+ return ctx.out.result
9
+ }
10
+
11
+ const utility = ctx.utility
12
+ const transformResponse = utility.transformResponse
13
+
14
+ const op = ctx.op
15
+ const entity = ctx.entity
16
+
17
+ const spec = ctx.spec
18
+ const result = ctx.result
19
+
20
+ if (null == spec) {
21
+ return ctx.error('result_no_spec', 'Expected context spec property to be defined.')
22
+ }
23
+
24
+ if (null == result) {
25
+ return ctx.error('result_no_result', 'Expected context result property to be defined.')
26
+ }
27
+
28
+ spec.step = 'result'
29
+
30
+ transformResponse(ctx)
31
+
32
+ if ('list' == op.name) {
33
+ const resdata = result.resdata
34
+ result.resdata = []
35
+
36
+ if (null != resdata && 0 < resdata.length) {
37
+ for (let entry of resdata) {
38
+ const ent = entity.make()
39
+ ent.data(entry)
40
+ result.resdata.push(ent)
41
+ }
42
+ }
43
+ }
44
+
45
+ if (ctx.ctrl.explain) {
46
+ ctx.ctrl.explain.result = result
47
+ }
48
+
49
+ // NOTE: returns processesd result.
50
+ return result
51
+ }
52
+
53
+
54
+ export {
55
+ makeResult
56
+ }
@@ -0,0 +1,61 @@
1
+
2
+ import { Context, Spec } from '../types'
3
+
4
+
5
+ // Create request specificaton.
6
+ function makeSpec(ctx: Context): Spec | Error {
7
+ if (ctx.out.spec) {
8
+ return ctx.spec = ctx.out.spec
9
+ }
10
+
11
+ const target = ctx.target
12
+ const options = ctx.options
13
+ const utility = ctx.utility
14
+
15
+ const prepareMethod = utility.prepareMethod
16
+ const prepareParams = utility.prepareParams
17
+ const prepareQuery = utility.prepareQuery
18
+ const prepareHeaders = utility.prepareHeaders
19
+ const prepareBody = utility.prepareBody
20
+ const preparePath = utility.preparePath
21
+ const prepareAuth = utility.prepareAuth
22
+
23
+ ctx.spec = new Spec({
24
+ base: options.base, // string, URL endpoint base prefix,
25
+ prefix: options.prefix,
26
+ parts: target.parts,
27
+ suffix: options.suffix,
28
+ step: 'start',
29
+ })
30
+
31
+ ctx.spec.method = prepareMethod(ctx)
32
+
33
+ // TODO: Add string utils to StructUtility
34
+ if (!options.allow.method.includes(ctx.spec.method)) {
35
+ return ctx.error('spec_method_allow', 'Method "' + ctx.spec.method +
36
+ '" not allowed by SDK option allow.method value: "' + options.allow.method + '"')
37
+ }
38
+
39
+ ctx.spec.params = prepareParams(ctx)
40
+ ctx.spec.query = prepareQuery(ctx)
41
+ ctx.spec.headers = prepareHeaders(ctx)
42
+ ctx.spec.body = prepareBody(ctx)
43
+ ctx.spec.path = preparePath(ctx)
44
+
45
+ if (ctx.ctrl.explain) {
46
+ ctx.ctrl.explain.spec = ctx.spec
47
+ }
48
+
49
+ const spec = prepareAuth(ctx)
50
+
51
+ if (!(spec instanceof Error)) {
52
+ ctx.spec = spec
53
+ }
54
+
55
+ return spec
56
+ }
57
+
58
+
59
+ export {
60
+ makeSpec
61
+ }
@@ -0,0 +1,76 @@
1
+
2
+ import { Context, Target } from '../types'
3
+
4
+
5
+ function makeTarget(ctx: Context): Target | Error {
6
+ if (ctx.out.target) {
7
+ return ctx.target = ctx.out.target
8
+ }
9
+
10
+ const getprop = ctx.utility.struct.getprop
11
+ const op = ctx.op
12
+ const options = ctx.options
13
+
14
+ if (!options.allow.op.includes(op.name)) {
15
+ ctx.error('target_op_allow', 'Operation "' + op.name +
16
+ '" not allowed by SDK option allow.op value: "' + options.allow.op + '"')
17
+ }
18
+
19
+ // Choose the appropriate operation alternate based on the match or data.
20
+ if (1 === op.targets.length) {
21
+ ctx.target = op.targets[0]
22
+ }
23
+ else {
24
+ // Operation argument has priority, but also look in current data or match.
25
+ const reqselector = getprop(ctx, 'req' + op.input)
26
+ const selector = getprop(ctx, op.input)
27
+
28
+ let target
29
+ for (let i = 0; i < op.targets.length; i++) {
30
+ target = op.targets[i]
31
+ const select = target.select
32
+ let found = true
33
+
34
+ if (selector && select.exist) {
35
+ for (let j = 0; j < select.exist.length; j++) {
36
+ const existkey = select.exist[j]
37
+
38
+ if (
39
+ undefined === getprop(reqselector, existkey)
40
+ && undefined === getprop(selector, existkey)
41
+ ) {
42
+ found = false
43
+ break
44
+ }
45
+ }
46
+ }
47
+
48
+ // Action is only in operation argument.
49
+ if (found && reqselector.$action !== select.$action) {
50
+ found = false
51
+ }
52
+
53
+ if (found) {
54
+ break
55
+ }
56
+ }
57
+
58
+ if (
59
+ null != reqselector.$action &&
60
+ null != target &&
61
+ reqselector.$action !== target.select.$action
62
+ ) {
63
+ return ctx.error('target_action_invalid', 'Operation "' + op.name +
64
+ '" action "' + reqselector.$action + '" is not valid.')
65
+ }
66
+
67
+ ctx.target = target
68
+ }
69
+
70
+ return ctx.target
71
+ }
72
+
73
+
74
+ export {
75
+ makeTarget,
76
+ }
@@ -0,0 +1,61 @@
1
+
2
+ import { Context } from '../types'
3
+
4
+
5
+ function makeUrl(ctx: Context): Error | string {
6
+ const utility = ctx.utility
7
+ const spec = ctx.spec
8
+ const result = ctx.result
9
+
10
+ const struct = utility.struct
11
+ const escurl = struct.escurl
12
+ const escre = struct.escre
13
+ const join = struct.join
14
+ const items = struct.items
15
+
16
+
17
+ if (null == spec) {
18
+ return ctx.error('url_no_spec', 'Expected context spec property to be defined.')
19
+ }
20
+
21
+ if (null == result) {
22
+ return ctx.error('url_no_result', 'Expected context result property to be defined.')
23
+ }
24
+
25
+
26
+ // TODO: use parts to avoid regexp?
27
+ let url = join([spec.base, spec.prefix, spec.path, spec.suffix], '/', true)
28
+ let resmatch: Record<string, any> = {}
29
+
30
+ const params = spec.params
31
+
32
+ for (let [key, val] of items(params)) {
33
+ if (null != val) {
34
+ url = url.replace(RegExp('{' + escre(key) + '}'), escurl(val))
35
+ resmatch[key] = val
36
+ }
37
+ }
38
+
39
+
40
+ /* TODO: fix
41
+ let qsep = '?'
42
+ for (let [key, val] of items(spec.query)) {
43
+ if (null == spec.alias[key]) {
44
+ if (null != val) {
45
+ url += qsep + escurl(key) + '=' + escurl(val)
46
+ qsep = '&'
47
+ resmatch[key] = val
48
+ }
49
+ }
50
+ }
51
+ */
52
+
53
+ result.resmatch = resmatch
54
+
55
+ return url
56
+ }
57
+
58
+
59
+ export {
60
+ makeUrl
61
+ }
@@ -1,9 +1,6 @@
1
1
 
2
2
  import { Context } from '../types'
3
3
 
4
- import { getprop } from './StructUtility'
5
-
6
-
7
4
  /* Find value of a match parameter, possibly using an alias.
8
5
  *
9
6
  * The match parameter may have an alias key. For example, the parameter `foo_id` may be
@@ -11,10 +8,30 @@ import { getprop } from './StructUtility'
11
8
  *
12
9
  * This function returns `undefined` rather than failing.
13
10
  */
14
- function findparam(ctx: Context, key: string) {
15
- let { op, spec, match, reqmatch, data, reqdata } = ctx
11
+ function param(ctx: Context, paramdef: any) {
12
+ const target = ctx.target
13
+ const spec = ctx.spec
14
+ const match = ctx.match
15
+ const reqmatch = ctx.reqmatch
16
+ const data = ctx.data
17
+ const reqdata = ctx.reqdata
18
+
19
+ const utility = ctx.utility
20
+ const struct = utility.struct
21
+
22
+ const getprop = struct.getprop
23
+ const setprop = struct.setprop
24
+
25
+ const typify = struct.typify
26
+ const T_string = struct.T_string
16
27
 
17
- let akey = op.alias[key]
28
+ const pt = typify(paramdef)
29
+
30
+ // TODO: review this search algorithm
31
+
32
+ const key = 0 < (T_string & pt) ? paramdef : getprop(paramdef, 'name')
33
+
34
+ let akey = getprop(target.alias, key)
18
35
 
19
36
  let val = getprop(reqmatch, key)
20
37
 
@@ -23,7 +40,10 @@ function findparam(ctx: Context, key: string) {
23
40
  }
24
41
 
25
42
  if (null == val && null != akey) {
26
- spec.alias[akey] = key
43
+
44
+ if (null != spec) {
45
+ setprop(spec.alias, akey, key)
46
+ }
27
47
 
28
48
  val = getprop(reqmatch, akey)
29
49
  }
@@ -49,6 +69,6 @@ function findparam(ctx: Context, key: string) {
49
69
 
50
70
 
51
71
  export {
52
- findparam
72
+ param
53
73
  }
54
74
 
@@ -1,15 +1,15 @@
1
1
 
2
- import { Context } from '../types'
2
+ import { Context, Spec } from '../types'
3
3
 
4
4
 
5
5
  const HEADER_auth = 'authorization'
6
6
 
7
7
  const OPTION_apikey = 'apikey'
8
8
 
9
- const NOTFOUND = ''
9
+ const NOTFOUND = '__NOTFOUND__'
10
10
 
11
11
 
12
- function auth(ctx: Context) {
12
+ function prepareAuth(ctx: Context): Spec | Error {
13
13
  const utility = ctx.utility
14
14
 
15
15
  const struct = utility.struct
@@ -20,6 +20,12 @@ function auth(ctx: Context) {
20
20
  const client = ctx.client
21
21
  const spec = ctx.spec
22
22
 
23
+ if (null == spec) {
24
+ return ctx.error('auth_no_spec', 'Expected context spec property to be defined.')
25
+ }
26
+
27
+
28
+
23
29
  const headers = spec.headers
24
30
 
25
31
  const options = client.options()
@@ -38,5 +44,5 @@ function auth(ctx: Context) {
38
44
 
39
45
 
40
46
  export {
41
- auth
47
+ prepareAuth
42
48
  }
@@ -0,0 +1,32 @@
1
+
2
+ import { Context } from '../types'
3
+
4
+ function prepareBody(ctx: Context) {
5
+ const op = ctx.op
6
+
7
+ const utility = ctx.utility
8
+ const error = utility.makeError
9
+ const transformRequest = utility.transformRequest
10
+
11
+ let body = undefined
12
+
13
+ if ('data' === op.input) {
14
+ try {
15
+ body = transformRequest(ctx)
16
+
17
+ // if (target.check.nobody && null == body) {
18
+ // return error(ctx, new Error('Request body is empty.'))
19
+ // }
20
+ }
21
+ catch (err) {
22
+ return error(ctx, err)
23
+ }
24
+ }
25
+
26
+ return body
27
+ }
28
+
29
+ export {
30
+ prepareBody
31
+ }
32
+
@@ -2,12 +2,10 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- import { getprop } from './StructUtility'
6
-
7
-
8
- function headers(ctx: Context) {
9
- const utility = ctx.utility
10
- const clone = utility.struct.clone
5
+ function prepareHeaders(ctx: Context) {
6
+ const struct = ctx.utility.struct
7
+ const clone = struct.clone
8
+ const getprop = struct.getprop
11
9
 
12
10
  const client = ctx.client
13
11
 
@@ -20,5 +18,5 @@ function headers(ctx: Context) {
20
18
 
21
19
 
22
20
  export {
23
- headers
21
+ prepareHeaders
24
22
  }
@@ -1,25 +1,25 @@
1
1
 
2
2
  import { Context } from '../types'
3
3
 
4
- function method(ctx: Context) {
5
- const { op } = ctx
4
+ function prepareMethod(ctx: Context) {
5
+ const op = ctx.op
6
6
  const opname = op.name
7
7
 
8
8
  let key = opname
9
9
 
10
- // TODO: options
11
- const mmap: any = {
10
+ const methodMap: any = {
12
11
  create: 'POST',
13
12
  update: 'PUT',
14
13
  load: 'GET',
15
14
  list: 'GET',
16
15
  remove: 'DELETE',
16
+ patch: 'PATCH',
17
17
  }
18
18
 
19
- return mmap[key]
19
+ return methodMap[key]
20
20
  }
21
21
 
22
22
 
23
23
  export {
24
- method
24
+ prepareMethod
25
25
  }