@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,36 +1,34 @@
1
1
 
2
- import { Context, Alt } from '../types'
2
+ import { Context, Target } from '../types'
3
3
 
4
- import { getprop } from './StructUtility'
5
4
 
6
-
7
- // Ensure standard operation definition.
8
- // TODO: rename to alt
9
- function selection(ctx: Context): Alt | Error {
10
- if (ctx.out.selected) {
11
- return ctx.alt = ctx.out.selected
5
+ function makeTarget(ctx: Context): Target | Error {
6
+ if (ctx.out.target) {
7
+ return ctx.target = ctx.out.target
12
8
  }
13
9
 
14
- const { op, options } = ctx
10
+ const getprop = ctx.utility.struct.getprop
11
+ const op = ctx.op
12
+ const options = ctx.options
15
13
 
16
14
  if (!options.allow.op.includes(op.name)) {
17
- return Error('Operation "' + op.name +
15
+ ctx.error('target_op_allow', 'Operation "' + op.name +
18
16
  '" not allowed by SDK option allow.op value: "' + options.allow.op + '"')
19
17
  }
20
18
 
21
19
  // Choose the appropriate operation alternate based on the match or data.
22
- if (1 === op.alts.length) {
23
- ctx.alt = op.alts[0]
20
+ if (1 === op.targets.length) {
21
+ ctx.target = op.targets[0]
24
22
  }
25
23
  else {
26
24
  // Operation argument has priority, but also look in current data or match.
27
- const reqselector = getprop(ctx, 'req' + op.select)
28
- const selector = getprop(ctx, op.select)
25
+ const reqselector = getprop(ctx, 'req' + op.input)
26
+ const selector = getprop(ctx, op.input)
29
27
 
30
- let alt
31
- for (let i = 0; i < op.alts.length; i++) {
32
- alt = op.alts[i]
33
- const select = alt.select
28
+ let target
29
+ for (let i = 0; i < op.targets.length; i++) {
30
+ target = op.targets[i]
31
+ const select = target.select
34
32
  let found = true
35
33
 
36
34
  if (selector && select.exist) {
@@ -59,20 +57,20 @@ function selection(ctx: Context): Alt | Error {
59
57
 
60
58
  if (
61
59
  null != reqselector.$action &&
62
- null != alt &&
63
- reqselector.$action !== alt.select.$action
60
+ null != target &&
61
+ reqselector.$action !== target.select.$action
64
62
  ) {
65
- return Error('Operation "' + op.name +
63
+ return ctx.error('target_action_invalid', 'Operation "' + op.name +
66
64
  '" action "' + reqselector.$action + '" is not valid.')
67
65
  }
68
66
 
69
- ctx.alt = alt
67
+ ctx.target = target
70
68
  }
71
69
 
72
- return ctx.alt
70
+ return ctx.target
73
71
  }
74
72
 
75
73
 
76
74
  export {
77
- selection,
75
+ makeTarget,
78
76
  }
@@ -2,7 +2,7 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- function fullurl(ctx: Context): Error | string {
5
+ function makeUrl(ctx: Context): Error | string {
6
6
  const utility = ctx.utility
7
7
  const spec = ctx.spec
8
8
  const result = ctx.result
@@ -11,14 +11,15 @@ function fullurl(ctx: Context): Error | string {
11
11
  const escurl = struct.escurl
12
12
  const escre = struct.escre
13
13
  const join = struct.join
14
+ const items = struct.items
14
15
 
15
16
 
16
17
  if (null == spec) {
17
- return new Error('Expected context spec property to be defined.')
18
+ return ctx.error('url_no_spec', 'Expected context spec property to be defined.')
18
19
  }
19
20
 
20
21
  if (null == result) {
21
- return new Error('Expected context result property to be defined.')
22
+ return ctx.error('url_no_result', 'Expected context result property to be defined.')
22
23
  }
23
24
 
24
25
 
@@ -28,8 +29,7 @@ function fullurl(ctx: Context): Error | string {
28
29
 
29
30
  const params = spec.params
30
31
 
31
- for (let key in params) {
32
- const val = params[key]
32
+ for (let [key, val] of items(params)) {
33
33
  if (null != val) {
34
34
  url = url.replace(RegExp('{' + escre(key) + '}'), escurl(val))
35
35
  resmatch[key] = val
@@ -39,9 +39,8 @@ function fullurl(ctx: Context): Error | string {
39
39
 
40
40
  /* TODO: fix
41
41
  let qsep = '?'
42
- for (let key in spec.query) {
42
+ for (let [key, val] of items(spec.query)) {
43
43
  if (null == spec.alias[key]) {
44
- const val = spec.query[key]
45
44
  if (null != val) {
46
45
  url += qsep + escurl(key) + '=' + escurl(val)
47
46
  qsep = '&'
@@ -58,5 +57,5 @@ function fullurl(ctx: Context): Error | string {
58
57
 
59
58
 
60
59
  export {
61
- fullurl
60
+ makeUrl
62
61
  }
@@ -1,9 +1,6 @@
1
1
 
2
2
  import { Context } from '../types'
3
3
 
4
- import { setprop, 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,14 +8,30 @@ import { setprop, getprop } from './StructUtility'
11
8
  *
12
9
  * This function returns `undefined` rather than failing.
13
10
  */
14
- function findparam(ctx: Context, param: any) {
15
- let { alt, 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
27
+
28
+ const pt = typify(paramdef)
16
29
 
17
30
  // TODO: review this search algorithm
18
31
 
19
- const key = param.name
32
+ const key = 0 < (T_string & pt) ? paramdef : getprop(paramdef, 'name')
20
33
 
21
- let akey = getprop(alt.alias, key)
34
+ let akey = getprop(target.alias, key)
22
35
 
23
36
  let val = getprop(reqmatch, key)
24
37
 
@@ -56,6 +69,6 @@ function findparam(ctx: Context, param: any) {
56
69
 
57
70
 
58
71
  export {
59
- findparam
72
+ param
60
73
  }
61
74
 
@@ -6,10 +6,10 @@ 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): Spec | Error {
12
+ function prepareAuth(ctx: Context): Spec | Error {
13
13
  const utility = ctx.utility
14
14
 
15
15
  const struct = utility.struct
@@ -21,7 +21,7 @@ function auth(ctx: Context): Spec | Error {
21
21
  const spec = ctx.spec
22
22
 
23
23
  if (null == spec) {
24
- return new Error('Expected context spec property to be defined.')
24
+ return ctx.error('auth_no_spec', 'Expected context spec property to be defined.')
25
25
  }
26
26
 
27
27
 
@@ -44,5 +44,5 @@ function auth(ctx: Context): Spec | Error {
44
44
 
45
45
 
46
46
  export {
47
- auth
47
+ prepareAuth
48
48
  }
@@ -1,20 +1,20 @@
1
1
 
2
2
  import { Context } from '../types'
3
3
 
4
- function body(ctx: Context) {
4
+ function prepareBody(ctx: Context) {
5
5
  const op = ctx.op
6
6
 
7
7
  const utility = ctx.utility
8
- const error = utility.error
9
- const reqform = utility.reqform
8
+ const error = utility.makeError
9
+ const transformRequest = utility.transformRequest
10
10
 
11
11
  let body = undefined
12
12
 
13
- if ('data' === op.select) {
13
+ if ('data' === op.input) {
14
14
  try {
15
- body = reqform(ctx)
15
+ body = transformRequest(ctx)
16
16
 
17
- // if (alt.check.nobody && null == body) {
17
+ // if (target.check.nobody && null == body) {
18
18
  // return error(ctx, new Error('Request body is empty.'))
19
19
  // }
20
20
  }
@@ -27,6 +27,6 @@ function body(ctx: Context) {
27
27
  }
28
28
 
29
29
  export {
30
- body
30
+ prepareBody
31
31
  }
32
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
  }
@@ -0,0 +1,37 @@
1
+
2
+ import { Context } from '../types'
3
+
4
+
5
+ function prepareParams(ctx: Context) {
6
+ const utility = ctx.utility
7
+ const findparam = utility.param
8
+
9
+ // const struct = utility.struct
10
+ // const validate = struct.validate
11
+
12
+ const target = ctx.target
13
+
14
+ let params = target.args.params
15
+ // let reqmatch = ctx.reqmatch
16
+
17
+ params = params || []
18
+ // reqmatch = reqmatch || {}
19
+
20
+ let out: any = {}
21
+ for (let pd of params) {
22
+ let val = findparam(ctx, pd)
23
+ if (null != val) {
24
+ out[pd.name] = val
25
+ }
26
+ }
27
+
28
+ // TODO: review
29
+ // out = validate(out, target.validate.params)
30
+
31
+ return out
32
+ }
33
+
34
+
35
+ export {
36
+ prepareParams
37
+ }
@@ -1,13 +1,12 @@
1
1
 
2
2
  import { Context } from '../types'
3
3
 
4
- import { join } from './StructUtility'
5
-
6
4
 
7
5
  function preparePath(ctx: Context) {
8
- const { alt } = ctx
6
+ const join = ctx.utility.struct.join
7
+ const target = ctx.target
9
8
 
10
- const path = join(alt.parts, '/', true)
9
+ const path = join(target.parts, '/', true)
11
10
 
12
11
  return path
13
12
  }
@@ -0,0 +1,30 @@
1
+
2
+ import { Context } from '../types'
3
+
4
+
5
+ function prepareQuery(ctx: Context) {
6
+ const utility = ctx.utility
7
+ const struct = utility.struct
8
+ const items = struct.items
9
+
10
+ const target = ctx.target
11
+ let params = target.params
12
+ let reqmatch = ctx.reqmatch
13
+
14
+ params = params || []
15
+ reqmatch = reqmatch || {}
16
+
17
+ const out: any = {}
18
+ for (let [key, val] of items(reqmatch)) {
19
+ if (null != val && !params.includes(key)) {
20
+ out[key] = val
21
+ }
22
+ }
23
+
24
+ return out
25
+ }
26
+
27
+
28
+ export {
29
+ prepareQuery
30
+ }
@@ -2,12 +2,17 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- function resbasic(ctx: Context) {
6
- const { response, result } = ctx
5
+ function resultBasic(ctx: Context) {
6
+ const utility = ctx.utility
7
+ const struct = utility.struct
8
+ const getprop = struct.getprop
9
+
10
+ const response = ctx.response
11
+ const result = ctx.result
7
12
 
8
13
  if (null != result && null != response) {
9
- result.status = response.status || -1
10
- result.statusText = response.statusText || 'no-status'
14
+ result.status = getprop(response, 'status', -1)
15
+ result.statusText = getprop(response, 'statusText', 'no-status')
11
16
 
12
17
  // TODO: use spec!
13
18
  if (400 <= result.status) {
@@ -17,7 +22,7 @@ function resbasic(ctx: Context) {
17
22
  result.err.message = prevmsg + ': ' + msg
18
23
  }
19
24
  else {
20
- result.err = new Error(msg)
25
+ result.err = ctx.error('request_status', msg)
21
26
  }
22
27
  }
23
28
  else if (response.err) {
@@ -30,5 +35,5 @@ function resbasic(ctx: Context) {
30
35
 
31
36
 
32
37
  export {
33
- resbasic
38
+ resultBasic
34
39
  }
@@ -2,8 +2,9 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- async function resbody(ctx: Context) {
6
- const { response, result } = ctx
5
+ async function resultBody(ctx: Context) {
6
+ const response = ctx.response
7
+ const result = ctx.result
7
8
 
8
9
  if (result) {
9
10
  if (response && response.json && null != response.body) {
@@ -17,5 +18,5 @@ async function resbody(ctx: Context) {
17
18
 
18
19
 
19
20
  export {
20
- resbody
21
+ resultBody
21
22
  }
@@ -2,8 +2,9 @@
2
2
  import { Context } from '../types'
3
3
 
4
4
 
5
- function resheaders(ctx: Context) {
6
- const { response, result } = ctx
5
+ function resultHeaders(ctx: Context) {
6
+ const response = ctx.response
7
+ const result = ctx.result
7
8
 
8
9
  if (result) {
9
10
  if (response && response.headers && response.headers.forEach) {
@@ -21,5 +22,5 @@ function resheaders(ctx: Context) {
21
22
 
22
23
 
23
24
  export {
24
- resheaders
25
+ resultHeaders
25
26
  }
@@ -5,17 +5,19 @@ import { Context } from '../types'
5
5
  *
6
6
  * The operation (op) property `reqform` is used to perform the data preparation.
7
7
  */
8
- function reqform(ctx: Context) {
9
- const { spec, utility, alt } = ctx
10
- const { struct, error } = utility
11
- const { isfunc, transform } = struct
8
+ function transformRequest(ctx: Context) {
9
+ const spec = ctx.spec
10
+ const utility = ctx.utility
11
+ const target = ctx.target
12
+ const isfunc = utility.struct.isfunc
13
+ const transform = utility.struct.transform
12
14
 
13
15
  if (spec) {
14
16
  spec.step = 'reqform'
15
17
  }
16
18
 
17
19
  try {
18
- const reqform = alt.transform.req
20
+ const reqform = target.transform.req
19
21
  const reqdata = isfunc(reqform) ? reqform(ctx) : transform({
20
22
  reqdata: ctx.reqdata
21
23
  }, reqform)
@@ -23,11 +25,11 @@ function reqform(ctx: Context) {
23
25
  return reqdata
24
26
  }
25
27
  catch (err) {
26
- return error(ctx, err)
28
+ return utility.makeError(ctx, err)
27
29
  }
28
30
  }
29
31
 
30
32
 
31
33
  export {
32
- reqform
34
+ transformRequest
33
35
  }
@@ -6,10 +6,13 @@ import { Context } from '../types'
6
6
  *
7
7
  * The operation (op) property `resform` is used to perform the data extraction.
8
8
  */
9
- function resform(ctx: Context) {
10
- const { spec, result, utility, alt } = ctx
11
- const { struct, error } = utility
12
- const { isfunc, transform } = struct
9
+ function transformResponse(ctx: Context) {
10
+ const spec = ctx.spec
11
+ const result = ctx.result
12
+ const utility = ctx.utility
13
+ const target = ctx.target
14
+ const isfunc = utility.struct.isfunc
15
+ const transform = utility.struct.transform
13
16
 
14
17
  if (spec) {
15
18
  spec.step = 'resform'
@@ -20,17 +23,17 @@ function resform(ctx: Context) {
20
23
  }
21
24
 
22
25
  try {
23
- const resform = alt.transform.res
26
+ const resform = target.transform.res
24
27
  const resdata = isfunc(resform) ? resform(ctx) : transform(ctx.result, resform)
25
28
  result.resdata = resdata
26
29
  return resdata
27
30
  }
28
31
  catch (err) {
29
- return error(ctx, err)
32
+ return utility.makeError(ctx, err)
30
33
  }
31
34
  }
32
35
 
33
36
 
34
37
  export {
35
- resform
38
+ transformResponse
36
39
  }