@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,203 +1,13 @@
1
1
 
2
- import { inspect } from 'node:util'
3
-
4
2
  import { ProjectNameSDK } from './ProjectNameSDK'
5
3
 
6
- import { Utility } from './utility/Utility'
7
- import { getprop, setprop, getpath } from './utility/StructUtility'
8
-
9
-
10
-
11
-
12
- // TODO: convert to classes
13
-
14
-
15
- type Operation = {
16
- entity: string
17
- name: string
18
- select: string
19
- alts: Alt[]
20
- }
21
-
22
-
23
- type Alt = {
24
- args: {
25
- param: any[]
26
- }
27
- rename: {
28
- param: Record<string, string>
29
- }
30
- method: string
31
- orig: string
32
- parts: string[]
33
- select: any
34
- active: boolean
35
- relations: any[]
36
- }
37
-
38
-
39
- type Spec = {
40
- parts: string[]
41
-
42
- headers: Record<string, string>
43
- alias: any
44
- base: string
45
- prefix: string
46
- suffix: string
47
- params: Record<string, string>
48
- query: Record<string, string>
49
- step: string
50
- method: string
51
- body: any
52
- url?: string
53
-
54
- path?: string
55
-
56
- }
57
-
58
-
59
- type Response = {
60
- status: number,
61
- statusText: string,
62
- headers: any,
63
- json: Function,
64
- err?: Error,
65
- body?: any,
66
- }
67
-
68
-
69
- type Result = {
70
- ok: boolean
71
- status: number
72
- statusText: string
73
- headers: Record<string, string>
74
- body?: any
75
- err?: any
76
- resdata?: any
77
- resmatch?: any
78
- }
79
-
80
-
81
- type Control = {
82
- throw?: boolean
83
- err?: any
84
- explain?: any
85
- }
86
-
87
-
88
- // TODO: move to own file
89
- class Context {
90
-
91
- id = 'C' + ('' + Math.random()).substring(2, 10)
92
-
93
- // Store the output of each operation step.
94
- out: Record<string, any> = {}
95
-
96
- // Store for the current operation.
97
- current: WeakMap<String, any> = new WeakMap()
98
-
99
-
100
- ctrl: Record<string, any> = {}
101
- meta: Record<string, any> = {}
102
-
103
- client: ProjectNameSDK
104
- utility: Utility
105
-
106
- op: Operation
107
- alt: any
108
-
109
- config: Record<string, any>
110
- entopts: Record<string, any>
111
- options: Record<string, any>
112
-
113
- opmap: Record<string, Operation>
114
-
115
- response?: Response
116
- result?: Result
117
- spec?: Spec
118
-
119
- data?: any
120
- reqdata?: any
121
- match?: any
122
- reqmatch?: any
123
-
124
- entity?: any
125
-
126
- // Shared persistent store.
127
- shared: WeakMap<String, any>
128
-
129
-
130
- constructor(ctxmap: Record<string, any>, basectx?: Context) {
131
- this.client = getprop(ctxmap, 'client', getprop(basectx, 'client'))
132
- this.utility = getprop(ctxmap, 'utility', getprop(basectx, 'utility'))
133
-
134
- this.ctrl = getprop(ctxmap, 'ctrl', getprop(basectx, 'ctrl', this.ctrl))
135
- this.meta = getprop(ctxmap, 'meta', getprop(basectx, 'meta', this.meta))
136
-
137
- this.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
138
- this.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
139
- this.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
140
-
141
- this.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
142
- this.shared = getprop(ctxmap, 'shared', getprop(basectx, 'shared'))
143
- this.opmap = getprop(ctxmap, 'opmap', getprop(basectx, 'opmap'))
144
-
145
- this.data = getprop(ctxmap, 'data', {})
146
- this.reqdata = getprop(ctxmap, 'reqdata', {})
147
- this.match = getprop(ctxmap, 'match', {})
148
- this.reqmatch = getprop(ctxmap, 'reqmatch', {})
149
-
150
- const opname = getprop(ctxmap, 'opname')
151
- this.op = this.resolveOp(opname)
152
- }
153
-
154
-
155
- resolveOp(opname: string): Operation {
156
- let op: Operation = getprop(this.opmap, opname)
157
-
158
- if (null == op && null != opname) {
159
- const entname = getprop(this.entity, 'name', '')
160
- const opcfg = getpath(this.config, ['entity', entname, 'op', opname])
161
- let select = 'match'
162
-
163
- if ('update' === opname || 'create' === opname) {
164
- select = 'data'
165
- }
166
-
167
- op = {
168
- entity: entname,
169
- name: opname,
170
- select,
171
- alts: getprop(opcfg, 'alts', [])
172
- }
173
-
174
- setprop(this.opmap, opname, op)
175
- }
176
-
177
- return op
178
- }
179
-
180
-
181
- toJSON() {
182
- return {
183
- id: this.id,
184
- op: this.op,
185
- spec: this.spec,
186
- entity: this.entity,
187
- result: this.result,
188
- meta: this.meta,
189
- }
190
- }
191
-
192
- toString() {
193
- return 'Context ' + (this as any).utility?.struct.jsonify(this.toJSON())
194
- }
195
-
196
- [inspect.custom]() {
197
- return this.toString()
198
- }
199
-
200
- }
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'
201
11
 
202
12
 
203
13
  type FeatureOptions = Record<string, any> | {
@@ -218,7 +28,7 @@ interface Feature {
218
28
  GetData: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
219
29
  GetMatch: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
220
30
 
221
- PreOperation: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
31
+ PreTarget: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
222
32
  PreSpec: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
223
33
  PreRequest: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
224
34
  PreResponse: (this: ProjectNameSDK, ctx: Context) => void | Promise<any>
@@ -228,17 +38,17 @@ interface Feature {
228
38
 
229
39
 
230
40
  export {
231
- Context
41
+ Target,
42
+ Context,
43
+ Control,
44
+ Operation,
45
+ Response,
46
+ Result,
47
+ Spec,
232
48
  }
233
49
 
234
50
 
235
51
  export type {
236
- Alt,
237
- Control,
238
52
  Feature,
239
53
  FeatureOptions,
240
- Operation,
241
- Response,
242
- Result,
243
- Spec,
244
54
  }
@@ -4,11 +4,10 @@ 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)
@@ -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,7 +2,7 @@
2
2
  import { Context, Feature } from '../types'
3
3
 
4
4
 
5
- function initfeature(ctx: Context, f: Feature) {
5
+ function featureInit(ctx: Context, f: Feature) {
6
6
  const fopts = ctx.options.feature[f.name] || {}
7
7
  if (true === fopts.active) {
8
8
  f.init(ctx, fopts)
@@ -11,5 +11,5 @@ function initfeature(ctx: Context, f: Feature) {
11
11
 
12
12
 
13
13
  export {
14
- initfeature
14
+ featureInit
15
15
  }
@@ -9,14 +9,16 @@ async function fetcher(
9
9
  ): Promise<Response | Error> {
10
10
 
11
11
  if ('live' !== ctx.client._mode) {
12
- return Error('Request blocked by mode: "' + ctx.client._mode +
12
+ return ctx.error('fetch_mode_block', 'Request blocked by mode: "' + ctx.client._mode +
13
13
  '" (URL was: "' + fullurl + '")')
14
14
  }
15
15
 
16
16
  const options = ctx.client.options()
17
17
 
18
- if (true === ctx.utility.struct.getpath(options, 'feature.test.active')) {
19
- return Error('Request blocked as test feature is active' +
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' +
20
22
  ' (URL was: "' + fullurl + '")')
21
23
  }
22
24
 
@@ -7,20 +7,20 @@ 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
16
 
17
- const result = ctx.result || ({} as Result)
17
+ const result = ctx.result || new Result({})
18
18
  result.ok = false
19
19
 
20
20
  const reserr = result.err
21
21
 
22
22
  err = undefined === err ? reserr : err
23
- err = err || new Error('unknown error')
23
+ err = err || ctx.error('unknown', 'unknown error')
24
24
 
25
25
  const errmsg = err.message || 'unknown error'
26
26
  // TODO: project name should come from config
@@ -59,5 +59,5 @@ function error(ctx: Context, err?: any) {
59
59
 
60
60
 
61
61
  export {
62
- error
62
+ makeError
63
63
  }
@@ -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) {
5
+ function makeOptions(ctx: Context) {
6
6
  const utility = ctx.utility
7
7
  const options = ctx.options
8
8
  const struct = utility.struct
9
+ const items = struct.items
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
- struct.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
 
@@ -79,7 +82,7 @@ function options(ctx: Context) {
79
82
  const keyre = opts.clean.keys
80
83
  .split(/\s*,\s*/)
81
84
  .filter((s: string) => null != s && '' !== s)
82
- .map((key: string) => struct.escre(key)).join('|')
85
+ .map((key: string) => escre(key)).join('|')
83
86
 
84
87
  if ('' != keyre) {
85
88
  opts.__derived__.clean.keyre = keyre
@@ -90,5 +93,5 @@ function options(ctx: Context) {
90
93
 
91
94
 
92
95
  export {
93
- options
96
+ makeOptions
94
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
+ }
@@ -2,14 +2,14 @@
2
2
  import { Result, Context } from '../types'
3
3
 
4
4
 
5
- function result(ctx: Context): Result | Error {
5
+ function makeResult(ctx: Context): Result | Error {
6
6
  // PreResult feature hook has already provided a result.
7
7
  if (ctx.out.result) {
8
8
  return ctx.out.result
9
9
  }
10
10
 
11
11
  const utility = ctx.utility
12
- const resform = utility.resform
12
+ const transformResponse = utility.transformResponse
13
13
 
14
14
  const op = ctx.op
15
15
  const entity = ctx.entity
@@ -18,16 +18,16 @@ function result(ctx: Context): Result | Error {
18
18
  const result = ctx.result
19
19
 
20
20
  if (null == spec) {
21
- return new Error('Expected context spec property to be defined.')
21
+ return ctx.error('result_no_spec', 'Expected context spec property to be defined.')
22
22
  }
23
23
 
24
24
  if (null == result) {
25
- return new Error('Expected context result property to be defined.')
25
+ return ctx.error('result_no_result', 'Expected context result property to be defined.')
26
26
  }
27
27
 
28
28
  spec.step = 'result'
29
29
 
30
- resform(ctx)
30
+ transformResponse(ctx)
31
31
 
32
32
  if ('list' == op.name) {
33
33
  const resdata = result.resdata
@@ -52,5 +52,5 @@ function result(ctx: Context): Result | Error {
52
52
 
53
53
 
54
54
  export {
55
- result
55
+ makeResult
56
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
+ }