@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
@@ -5,6 +5,9 @@ import type { ProjectNameSDK } from '../../ProjectNameSDK'
5
5
  import { BaseFeature } from '../base/BaseFeature'
6
6
 
7
7
 
8
+ const S_NOT_FOUND = 'Not found'
9
+
10
+
8
11
  class TestFeature extends BaseFeature {
9
12
  version = '0.0.1'
10
13
  name = 'test'
@@ -18,137 +21,188 @@ class TestFeature extends BaseFeature {
18
21
  this._client = ctx.client
19
22
  this._options = options
20
23
 
21
- // console.log('TEST FEATURE', this._options)
22
-
23
- const { struct } = ctx.utility
24
- const { walk, size, setprop, stringify } = struct
24
+ const struct = ctx.utility.struct
25
+ const walk = struct.walk
26
+ const size = struct.size
27
+ const setprop = struct.setprop
25
28
 
26
29
  const entity = this._options.entity
27
30
 
28
- // Set entity ids to correct values
29
- walk(entity, (k: any, v: any, parent: any, path: any) => {
31
+ this._client._mode = 'test'
32
+
33
+ // Ensure entity ids are correct.
34
+ walk(entity, (k: any, v: any, _parent: any, path: any) => {
30
35
  if (2 === size(path)) {
31
36
  setprop(v, 'id', k)
32
37
  }
33
38
  return v
34
39
  })
35
40
 
36
- if (entity) {
37
- ctx.utility.fetcher = (ctx: any, _fullurl: string, _fetchdef: any) => {
38
- const { findparam, struct } = ctx.utility
39
- const { getprop, clone, merge, keysof, size, select, delprop } = struct
40
-
41
-
42
- function respond(status: number, data?: any, res?: any) {
43
- const out = merge([
44
- {
45
- status,
46
- statusText: 'OK',
47
- json: async () => data,
48
- },
49
- res || {}
50
- ])
51
-
52
- const headers: any = out.headers || {}
53
- out.headers = {
54
- forEach(callback: any) {
55
- Object.keys(headers).forEach((key) => {
56
- callback(headers[key], key, this)
57
- })
58
- }
41
+ const self = this
42
+
43
+ function testFetcher(ctx: any, _fullurl: string, _fetchdef: any) {
44
+ const struct = ctx.utility.struct
45
+ const param = ctx.utility.param
46
+
47
+ const getprop = struct.getprop
48
+ const clone = struct.clone
49
+ const merge = struct.merge
50
+ const getelem = struct.getelem
51
+ const select = struct.select
52
+ const delprop = struct.delprop
53
+ const getdef = struct.getdef
54
+
55
+ function respond(status: number, data?: any, res?: any) {
56
+ const out = merge([
57
+ {
58
+ status,
59
+ statusText: 'OK',
60
+ json: async () => data,
61
+ body: 'not-used',
62
+ },
63
+ getdef(res, {})
64
+ ])
65
+
66
+ const headers: any = getprop(out, 'headers', {})
67
+
68
+ // JS specific iterator.
69
+ out.headers = {
70
+ forEach(callback: any) {
71
+ Object.keys(headers).forEach((key) => {
72
+ callback(headers[key], key, this)
73
+ })
59
74
  }
60
-
61
- return out
62
75
  }
63
76
 
77
+ return out
78
+ }
64
79
 
65
- const op = ctx.op
66
- const entmap = entity[op.entity]
67
-
68
- const qand: any[] = []
69
- const q = { '`$AND`': qand }
70
-
71
- for (let k of keysof(ctx.reqmatch)) {
72
- const v = findparam(ctx, k)
73
- const ka = getprop(op.alias, k)
74
-
75
- let qor: any = [{ [k]: v }]
76
- if (null != ka) {
77
- qor.push({ [ka]: v })
78
- }
79
80
 
80
- qor = { '`$OR`': qor }
81
+ const op = ctx.op
82
+ const entmap = getprop(entity, op.entity, {})
81
83
 
82
- qand.push(qor)
84
+ if ('load' === op.name) {
85
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
86
+ const found = select(entmap, args)
87
+ const ent = getelem(found, 0)
88
+ if (null == ent) {
89
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
83
90
  }
84
-
85
- if (ctx.ctrl.explain) {
86
- ctx.ctrl.explain.test = { query: q }
91
+ else {
92
+ delprop(ent, '$KEY')
93
+ const out = clone(ent)
94
+ return respond(200, out)
87
95
  }
88
-
89
- if ('load' === op.name) {
90
- const found = select(entmap, q)
91
- const ent = found[0]
92
- if (null == ent) {
93
- return respond(404, undefined, { statusText: 'Not found' })
94
- }
95
- else {
96
- delprop(ent, '$KEY')
97
- return respond(200, clone(ent))
98
- }
96
+ }
97
+ else if ('list' === op.name) {
98
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
99
+ const found = select(entmap, args)
100
+ if (null == found) {
101
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
99
102
  }
100
- else if ('list' === op.name) {
101
- const found = select(entmap, q)
102
- if (null == found) {
103
- return respond(404, undefined, { statusText: 'Not found' })
104
- }
105
- else {
106
- found.map((ent: any) => delprop(ent, '$KEY'))
107
- return respond(200, clone(found))
108
- }
103
+ else {
104
+ found.map((ent: any) => delprop(ent, '$KEY'))
105
+ const out = clone(found)
106
+ return respond(200, out)
109
107
  }
110
- else if ('update' === op.name) {
111
- const found = select(entmap, q)
112
- const ent = found[0]
113
- if (null == ent) {
114
- return respond(404, undefined, { statusText: 'Not found' })
115
- }
116
- else {
117
- merge([ent, (ctx.reqdata || {})])
118
- delprop(ent, '$KEY')
119
- return respond(200, clone(ent))
120
- }
108
+ }
109
+ else if ('update' === op.name) {
110
+ const args = self.buildArgs(ctx, op, ctx.reqdata)
111
+ const found = select(entmap, args)
112
+ const ent = getelem(found, 0)
113
+ if (null == ent) {
114
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
121
115
  }
122
- else if ('remove' === op.name) {
123
- const found = select(entmap, q)
124
- const ent = found[0]
125
- if (null == ent) {
126
- return respond(404, undefined, { statusText: 'Not found' })
127
- }
128
- else {
129
- delprop(entmap, getprop(ent, 'id'))
130
- return respond(200)
131
- }
116
+ else {
117
+ merge([ent, (ctx.reqdata || {})])
118
+ delprop(ent, '$KEY')
119
+ const out = clone(ent)
120
+ return respond(200, out)
132
121
  }
133
- else if ('create' === op.name) {
134
- const id = findparam(ctx, 'id')
135
- if (null != id) {
136
- const ent = clone(ctx.reqdata)
137
- ent.id = id
138
- setprop(entmap, 'id', ent)
139
- delprop(ent, '$KEY')
140
- return respond(200, clone(ent))
141
- }
142
- else {
143
- return respond(400, undefined, { statusText: 'Missing id' })
144
- }
122
+ }
123
+ else if ('remove' === op.name) {
124
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
125
+ const found = select(entmap, args)
126
+ const ent = getelem(found, 0)
127
+ if (null == ent) {
128
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
129
+ }
130
+ else {
131
+ delprop(entmap, getprop(ent, 'id'))
132
+ return respond(200)
133
+ }
134
+ }
135
+ else if ('create' === op.name) {
136
+ const args = self.buildArgs(ctx, op, ctx.reqdata)
137
+ let id = param(ctx, 'id')
138
+ if (null == id) {
139
+ id = ((1e4 * Math.random() | 0).toString(16) +
140
+ (1e4 * Math.random() | 0).toString(16) +
141
+ (1e4 * Math.random() | 0).toString(16) +
142
+ (1e4 * Math.random() | 0).toString(16)).padEnd(16, '0')
145
143
  }
144
+
145
+ const ent = clone(ctx.reqdata)
146
+ setprop(ent, 'id', id)
147
+ setprop(entmap, id, ent)
148
+ delprop(ent, '$KEY')
149
+ const out = clone(ent)
150
+ return respond(200, out)
146
151
  }
147
152
  }
153
+
154
+ ctx.utility.fetcher = testFetcher
148
155
  }
149
- }
150
156
 
151
157
 
158
+ buildArgs(ctx: any, op: any, args: any): any {
159
+ const struct = ctx.utility.struct
160
+ const param = ctx.utility.param
161
+
162
+ const getprop = struct.getprop
163
+ const keysof = struct.keysof
164
+ const getpath = struct.getpath
165
+ const getelem = struct.getelem
166
+ const select = struct.select
167
+ const transform = struct.transform
168
+ const isempty = struct.isempty
169
+
170
+ const opname = getprop(op, 'name')
171
+ const target =
172
+ getelem(getpath(ctx.config, [
173
+ 'entity', getprop(ctx.entity, 'name'), 'op', opname, 'targets']), -1)
174
+
175
+ const reqd = transform(
176
+ select(getpath(target, ['args', 'params']), { reqd: true }),
177
+ ['`$EACH`', '', '`$KEY.name`']
178
+ )
179
+
180
+ const qand: any[] = []
181
+ const q = { '`$AND`': qand }
182
+
183
+ for (let k of keysof(args)) {
184
+ if ('id' === k || !isempty(select(reqd, k))) {
185
+ const v = param(ctx, k)
186
+ const ka = getprop(op.alias, k)
187
+
188
+ let qor: any = [{ [k]: v }]
189
+ if (null != ka) {
190
+ qor.push({ [ka]: v })
191
+ }
192
+
193
+ qor = { '`$OR`': qor }
194
+
195
+ qand.push(qor)
196
+ }
197
+ }
198
+
199
+ if (ctx.ctrl.explain) {
200
+ ctx.ctrl.explain.test = { query: q }
201
+ }
202
+
203
+ return q
204
+ }
205
+ }
152
206
 
153
207
 
154
208
  export {
@@ -1,79 +1,13 @@
1
1
 
2
2
  import { ProjectNameSDK } from './ProjectNameSDK'
3
3
 
4
- import { Utility } from './utility/Utility'
5
-
6
- type Context = {
7
- ctrl: any
8
- client: ProjectNameSDK
9
- op: Operation
10
- spec: Spec
11
- result: Result
12
- utility: Utility
13
- entopts: any
14
- options: any
15
- config: any
16
- response: any
17
- entity: any
18
- data: any
19
- match: any
20
- reqdata: any
21
- reqmatch: any
22
- work: any
23
- }
24
-
25
-
26
- type Operation = {
27
- kind: string
28
- entity: string
29
- name: string
30
- path: string
31
- pathalt: ({ path: string } & Record<string, boolean>)[],
32
- params: string[],
33
- alias: Record<string, string>
34
- state: Record<string, any>
35
- reqform: any
36
- resform: any
37
- validate: {
38
- params: Record<string, any>
39
- }
40
- check: Record<string, any>
41
- }
42
-
43
-
44
- type Spec = {
45
- headers: Record<string, string>
46
- alias: any
47
- base: string
48
- prefix: string
49
- suffix: string
50
- params: Record<string, string>
51
- query: Record<string, string>
52
- step: string
53
- method: string
54
- body: any
55
- path: string
56
- url?: string
57
- }
58
-
59
-
60
- type Result = {
61
- ok: boolean
62
- status: number
63
- statusText: string
64
- headers: Record<string, string>
65
- body?: any
66
- err?: any
67
- resdata?: any
68
- resmatch?: any
69
- }
70
-
71
-
72
- type Control = {
73
- throw?: boolean
74
- err?: any
75
- explain?: any
76
- }
4
+ import { Target } from './Target'
5
+ import { Context } from './Context'
6
+ import { Control } from './Control'
7
+ import { Operation } from './Operation'
8
+ import { Response } from './Response'
9
+ import { Result } from './Result'
10
+ import { Spec } from './Spec'
77
11
 
78
12
 
79
13
  type FeatureOptions = Record<string, any> | {
@@ -94,7 +28,7 @@ interface Feature {
94
28
  GetData: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
95
29
  GetMatch: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
96
30
 
97
- PreOperation: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
31
+ PreTarget: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
98
32
  PreSpec: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
99
33
  PreRequest: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
100
34
  PreResponse: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
@@ -103,12 +37,18 @@ interface Feature {
103
37
  }
104
38
 
105
39
 
106
-
107
- export type {
40
+ export {
41
+ Target,
108
42
  Context,
43
+ Control,
109
44
  Operation,
45
+ Response,
46
+ Result,
110
47
  Spec,
111
- Control,
112
- FeatureOptions,
48
+ }
49
+
50
+
51
+ export type {
113
52
  Feature,
53
+ FeatureOptions,
114
54
  }
@@ -3,45 +3,31 @@ import { Context } from '../types'
3
3
 
4
4
 
5
5
  import {
6
- walk, getpath, escre, getprop, size, pad, slice, setprop, clone
6
+ walk, size, pad, slice, clone
7
7
  } from './StructUtility'
8
8
 
9
9
 
10
10
  // Clean request data by partially hiding sensitive values.
11
11
  function clean(ctx: Context, val: any) {
12
12
  const options = ctx.options
13
- const work = ctx.work
14
-
15
- let cleaners = getprop(work, 'cleaners')
16
-
17
- if (null == cleaners) {
18
- cleaners =
19
- [
20
- { p: 'apikey', s: 4 }
21
- ]
22
- .map((p: any) => (p.v = getpath(options, p.p), p))
23
- .filter(p => null != p.v && 'string' === typeof p.v)
24
- .map(
25
- p => (
26
- p.re = new RegExp(escre(p.v)),
27
- p.v = pad(slice(p.v, 0, p.s), size(p.v), '*'),
28
- p
29
- )
30
- )
31
- }
32
-
33
- setprop(work, 'cleaners', cleaners)
34
13
 
35
- const out = walk(clone(val), (_k: any, v: any) => {
36
- if ('string' === typeof v) {
37
- cleaners.map((p: any) => {
38
- v = v.replace(p.re, p.v)
39
- })
40
- }
41
- return v
42
- })
14
+ const cleankeyre = options.__derived__.clean.keyre
15
+ const hintsize = 4
16
+
17
+ /*
18
+ if (null != cleankeyre) {
19
+ val = walk(clone(val), (key: any, subval: any) => {
20
+ if (cleankeyre.exec(key) && 'string' === typeof subval) {
21
+ const len = size(subval)
22
+ const hint = (hintsize * 4) < len ? slice(subval, 0, hintsize) : ''
23
+ subval = pad(hint, len, '*')
24
+ }
25
+ return subval
26
+ })
27
+ }
28
+ */
43
29
 
44
- return out
30
+ return val
45
31
  }
46
32
 
47
33
 
@@ -4,18 +4,17 @@ import { Context } from '../types'
4
4
 
5
5
  import { clean } from './CleanUtility'
6
6
 
7
- import { delprop } from './StructUtility'
8
-
9
7
 
10
8
  function done(ctx: Context) {
11
- const { error } = ctx.utility
9
+ const error = ctx.utility.makeError
10
+ const delprop = ctx.utility.struct.delprop
12
11
 
13
12
  if (ctx.ctrl.explain) {
14
13
  ctx.ctrl.explain = clean(ctx, ctx.ctrl.explain)
15
14
  delprop(ctx.ctrl.explain.result, 'err')
16
15
  }
17
16
 
18
- if (ctx.result.ok) {
17
+ if (ctx.result && ctx.result.ok) {
19
18
  return ctx.result.resdata
20
19
  }
21
20
 
@@ -2,7 +2,7 @@
2
2
  import { Context, Feature } from '../types'
3
3
 
4
4
 
5
- function addfeature(ctx: Context, f: Feature) {
5
+ function featureAdd(ctx: Context, f: Feature) {
6
6
  const client = ctx.client
7
7
  const struct = ctx.utility.struct
8
8
  const setprop = struct.setprop
@@ -43,5 +43,5 @@ function addfeature(ctx: Context, f: Feature) {
43
43
 
44
44
 
45
45
  export {
46
- addfeature
46
+ featureAdd
47
47
  }
@@ -2,16 +2,19 @@
2
2
  import { Context, Feature } from '../types'
3
3
 
4
4
 
5
- function featurehook(ctx: Context, name: string) {
5
+ function featureHook(ctx: Context, name: string) {
6
6
  const client = ctx.client
7
7
 
8
8
  let resp: Promise<any>[] = []
9
9
  const features: Feature[] = client._features || []
10
10
 
11
11
  for (let f of features) {
12
- let fres = (f as any)[name](ctx)
13
- if (fres instanceof Promise) {
14
- resp.push(fres)
12
+ const fh = (f as any)[name]
13
+ if (null != fh) {
14
+ const fres = fh(ctx)
15
+ if (fres instanceof Promise) {
16
+ resp.push(fres)
17
+ }
15
18
  }
16
19
  }
17
20
 
@@ -22,5 +25,5 @@ function featurehook(ctx: Context, name: string) {
22
25
 
23
26
 
24
27
  export {
25
- featurehook
28
+ featureHook
26
29
  }
@@ -0,0 +1,15 @@
1
+
2
+ import { Context, Feature } from '../types'
3
+
4
+
5
+ function featureInit(ctx: Context, f: Feature) {
6
+ const fopts = ctx.options.feature[f.name] || {}
7
+ if (true === fopts.active) {
8
+ f.init(ctx, fopts)
9
+ }
10
+ }
11
+
12
+
13
+ export {
14
+ featureInit
15
+ }
@@ -1,9 +1,27 @@
1
1
 
2
- import { Context } from '../types'
2
+ import { Context, Response } from '../types'
3
3
 
4
4
  // Make HTTP call using library. Replace this utility for mocking etc.
5
- async function fetcher(ctx: Context, fullurl: string, fetchdef: Record<string, any>) {
5
+ async function fetcher(
6
+ ctx: Context,
7
+ fullurl: string,
8
+ fetchdef: Record<string, any>
9
+ ): Promise<Response | Error> {
10
+
11
+ if ('live' !== ctx.client._mode) {
12
+ return ctx.error('fetch_mode_block', 'Request blocked by mode: "' + ctx.client._mode +
13
+ '" (URL was: "' + fullurl + '")')
14
+ }
15
+
6
16
  const options = ctx.client.options()
17
+
18
+ const getpath = ctx.utility.struct.getpath
19
+
20
+ if (true === getpath(options, 'feature.test.active')) {
21
+ return ctx.error('fetch_test_block', 'Request blocked as test feature is active' +
22
+ ' (URL was: "' + fullurl + '")')
23
+ }
24
+
7
25
  const fetch = options.system.fetch
8
26
 
9
27
  const response = await fetch(fullurl, fetchdef)
@@ -0,0 +1,27 @@
1
+
2
+ import { ProjectNameSDK } from '../ProjectNameSDK'
3
+
4
+ import { Utility } from './Utility'
5
+
6
+ import type {
7
+ Operation,
8
+ Spec,
9
+ Response,
10
+ Result,
11
+ } from '../types'
12
+
13
+ import {
14
+ Context
15
+ } from '../types'
16
+
17
+
18
+ function makeContext(ctxmap: Record<string, any>, basectx?: Context): any {
19
+ const ctx = new Context(ctxmap, basectx)
20
+ return ctx
21
+ }
22
+
23
+
24
+
25
+ export {
26
+ makeContext,
27
+ }
@@ -1,5 +1,5 @@
1
1
 
2
- import { Context } from '../types'
2
+ import { Result, Context } from '../types'
3
3
 
4
4
 
5
5
  import { clean } from './CleanUtility'
@@ -7,21 +7,25 @@ import { clean } from './CleanUtility'
7
7
  import { clone, delprop } from './StructUtility'
8
8
 
9
9
 
10
- function error(ctx: Context, err?: any) {
10
+ function makeError(ctx: Context, err?: any) {
11
11
 
12
12
  ctx = ctx || {}
13
13
  const op = ctx.op || {}
14
14
  op.name = op.name || 'unknown operation'
15
15
 
16
- const result = ctx.result = ctx.result || {}
16
+
17
+ const result = ctx.result || new Result({})
17
18
  result.ok = false
18
19
 
19
20
  const reserr = result.err
20
21
 
21
22
  err = undefined === err ? reserr : err
22
- err = err || new Error('unknown error')
23
+ err = err || ctx.error('unknown', 'unknown error')
23
24
 
24
25
  const errmsg = err.message || 'unknown error'
26
+ // TODO: project name should come from config
27
+ // avoids spurious changes between template and generated utility
28
+ // applies for all utility files
25
29
  const msg = 'ProjectNameSDK: ' + op.name + ': ' + errmsg
26
30
  err.message = clean(ctx, msg)
27
31
 
@@ -46,7 +50,7 @@ function error(ctx: Context, err?: any) {
46
50
 
47
51
  // TODO: model option to return instead
48
52
  if (false === ctx.ctrl.throw) {
49
- return ctx.result.resdata
53
+ return result.resdata
50
54
  }
51
55
  else {
52
56
  throw err
@@ -55,5 +59,5 @@ function error(ctx: Context, err?: any) {
55
59
 
56
60
 
57
61
  export {
58
- error
62
+ makeError
59
63
  }