@voxgig/sdkgen 0.36.0 → 0.37.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 (135) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Main.js +0 -12
  3. package/dist/cmp/Main.js.map +1 -1
  4. package/package.json +1 -1
  5. package/project/.sdk/src/cmp/go/Config_go.ts +6 -2
  6. package/project/.sdk/src/cmp/js/EntityBase_js.ts +34 -0
  7. package/project/.sdk/src/cmp/js/Main_js.ts +10 -0
  8. package/project/.sdk/src/cmp/js/ReadmeExplanation_js.ts +33 -0
  9. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +123 -0
  10. package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +152 -0
  11. package/project/.sdk/src/cmp/js/ReadmeTopHowto_js.ts +25 -0
  12. package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +65 -0
  13. package/project/.sdk/src/cmp/js/ReadmeTopTest_js.ts +36 -0
  14. package/project/.sdk/src/cmp/js/TestDirect_js.ts +53 -5
  15. package/project/.sdk/src/cmp/js/TestEntity_js.ts +114 -20
  16. package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +7 -139
  17. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +149 -0
  18. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -10
  19. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -10
  20. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +7 -11
  21. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +7 -11
  22. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +7 -11
  23. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +2 -0
  24. package/project/.sdk/src/cmp/js/fragment/SdkError.fragment.js +0 -2
  25. package/project/.sdk/src/cmp/lua/Config_lua.ts +6 -2
  26. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +3 -1
  27. package/project/.sdk/src/cmp/php/Config_php.ts +6 -2
  28. package/project/.sdk/src/cmp/php/TestDirect_php.ts +2 -2
  29. package/project/.sdk/src/cmp/php/TestEntity_php.ts +10 -15
  30. package/project/.sdk/src/cmp/py/Config_py.ts +6 -2
  31. package/project/.sdk/src/cmp/py/TestEntity_py.ts +3 -1
  32. package/project/.sdk/src/cmp/rb/Config_rb.ts +6 -2
  33. package/project/.sdk/src/cmp/ts/Main_ts.ts +7 -0
  34. package/project/.sdk/tm/go/feature/log_feature.go +1 -1
  35. package/project/.sdk/tm/go/test/runner_test.go +16 -2
  36. package/project/.sdk/tm/js/src/Context.js +142 -0
  37. package/project/.sdk/tm/js/src/Control.js +16 -0
  38. package/project/.sdk/tm/js/src/Operation.js +19 -0
  39. package/project/.sdk/tm/js/src/Point.js +24 -0
  40. package/project/.sdk/tm/js/src/README.md +1 -0
  41. package/project/.sdk/tm/js/src/Response.js +19 -0
  42. package/project/.sdk/tm/js/src/Result.js +21 -0
  43. package/project/.sdk/tm/js/src/Spec.js +26 -0
  44. package/project/.sdk/tm/js/src/feature/README.md +1 -0
  45. package/project/.sdk/tm/js/src/feature/base/BaseFeature.js +45 -0
  46. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +46 -47
  47. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +207 -0
  48. package/project/.sdk/tm/js/src/types.js +22 -0
  49. package/project/.sdk/tm/js/src/utility/CleanUtility.js +31 -0
  50. package/project/.sdk/tm/js/src/utility/DoneUtility.js +11 -4
  51. package/project/.sdk/tm/js/src/utility/FeatureAddUtility.js +42 -0
  52. package/project/.sdk/tm/js/src/utility/FeatureHookUtility.js +25 -0
  53. package/project/.sdk/tm/js/src/utility/FeatureInitUtility.js +11 -0
  54. package/project/.sdk/tm/js/src/utility/FetcherUtility.js +28 -0
  55. package/project/.sdk/tm/js/src/utility/MakeContextUtility.js +11 -0
  56. package/project/.sdk/tm/js/src/utility/MakeErrorUtility.js +55 -0
  57. package/project/.sdk/tm/js/src/utility/MakeFetchDefUtility.js +44 -0
  58. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +93 -0
  59. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +77 -0
  60. package/project/.sdk/tm/js/src/utility/MakeRequestUtility.js +63 -0
  61. package/project/.sdk/tm/js/src/utility/MakeResponseUtility.js +55 -0
  62. package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +54 -0
  63. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +58 -0
  64. package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +40 -0
  65. package/project/.sdk/tm/js/src/utility/ParamUtility.js +61 -0
  66. package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +41 -0
  67. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +25 -0
  68. package/project/.sdk/tm/js/src/utility/PrepareHeadersUtility.js +18 -0
  69. package/project/.sdk/tm/js/src/utility/{MethodUtility.js → PrepareMethodUtility.js} +7 -7
  70. package/project/.sdk/tm/js/src/utility/PrepareParamsUtility.js +25 -0
  71. package/project/.sdk/tm/js/src/utility/PreparePathUtility.js +13 -0
  72. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +26 -0
  73. package/project/.sdk/tm/js/src/utility/README.md +1 -0
  74. package/project/.sdk/tm/js/src/utility/ResultBasicUtility.js +34 -0
  75. package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +18 -0
  76. package/project/.sdk/tm/js/src/utility/ResultHeadersUtility.js +22 -0
  77. package/project/.sdk/tm/js/src/utility/StructUtility.js +2219 -1078
  78. package/project/.sdk/tm/js/src/utility/TransformRequestUtility.js +28 -0
  79. package/project/.sdk/tm/js/src/utility/TransformResponseUtility.js +31 -0
  80. package/project/.sdk/tm/js/src/utility/Utility.js +61 -61
  81. package/project/.sdk/tm/js/test/README.md +1 -0
  82. package/project/.sdk/tm/js/test/exists.test.js +16 -0
  83. package/project/.sdk/tm/js/test/runner.js +323 -107
  84. package/project/.sdk/tm/js/test/utility/Custom.test.js +41 -63
  85. package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +390 -116
  86. package/project/.sdk/tm/js/test/utility/StructUtility.test.js +728 -175
  87. package/project/.sdk/tm/js/test/utility/index.js +9 -0
  88. package/project/.sdk/tm/js/test/utility.js +72 -0
  89. package/project/.sdk/tm/lua/test/primary_utility_test.lua +1213 -0
  90. package/project/.sdk/tm/lua/test/runner.lua +2 -2
  91. package/project/.sdk/tm/lua/test/struct_runner.lua +602 -0
  92. package/project/.sdk/tm/lua/test/struct_utility_test.lua +959 -0
  93. package/project/.sdk/tm/lua/utility/struct/struct.lua +10 -0
  94. package/project/.sdk/tm/php/feature/TestFeature.php +59 -96
  95. package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +1309 -0
  96. package/project/.sdk/tm/php/test/Runner.php +24 -1
  97. package/project/.sdk/tm/php/test/StructRunner.php +275 -0
  98. package/project/.sdk/tm/php/test/StructUtilityTest.php +1336 -0
  99. package/project/.sdk/tm/php/utility/Fetcher.php +6 -2
  100. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -1
  101. package/project/.sdk/tm/php/utility/MakeResult.php +3 -0
  102. package/project/.sdk/tm/php/utility/Param.php +9 -7
  103. package/project/.sdk/tm/php/utility/struct/Struct.php +312 -208
  104. package/project/.sdk/tm/py/test/runner.py +13 -0
  105. package/project/.sdk/tm/py/test/struct_runner.py +411 -0
  106. package/project/.sdk/tm/py/test/test_primary_utility.py +1101 -0
  107. package/project/.sdk/tm/py/test/test_struct_utility.py +751 -0
  108. package/project/.sdk/tm/rb/test/primary_utility_test.rb +1083 -0
  109. package/project/.sdk/tm/rb/test/runner.rb +5 -0
  110. package/project/.sdk/tm/rb/test/struct_runner.rb +309 -0
  111. package/project/.sdk/tm/rb/test/struct_utility_test.rb +670 -0
  112. package/src/cmp/Main.ts +1 -16
  113. package/project/.sdk/src/cmp/js/Quick_js.ts +0 -78
  114. package/project/.sdk/src/cmp/js/TestAcceptEntity_js.ts +0 -13
  115. package/project/.sdk/src/cmp/js/TestAccept_js.ts +0 -18
  116. package/project/.sdk/tm/js/src/utility/AuthUtility.js +0 -21
  117. package/project/.sdk/tm/js/src/utility/BodyUtility.js +0 -29
  118. package/project/.sdk/tm/js/src/utility/ErrorUtility.js +0 -33
  119. package/project/.sdk/tm/js/src/utility/FindparamUtility.js +0 -31
  120. package/project/.sdk/tm/js/src/utility/FullurlUtility.js +0 -39
  121. package/project/.sdk/tm/js/src/utility/HeadersUtility.js +0 -13
  122. package/project/.sdk/tm/js/src/utility/JoinurlUtility.js +0 -14
  123. package/project/.sdk/tm/js/src/utility/OperatorUtility.js +0 -44
  124. package/project/.sdk/tm/js/src/utility/OptionsUtility.js +0 -54
  125. package/project/.sdk/tm/js/src/utility/ParamsUtility.js +0 -21
  126. package/project/.sdk/tm/js/src/utility/QueryUtility.js +0 -21
  127. package/project/.sdk/tm/js/src/utility/ReqformUtility.js +0 -32
  128. package/project/.sdk/tm/js/src/utility/RequestUtility.js +0 -48
  129. package/project/.sdk/tm/js/src/utility/ResbasicUtility.js +0 -27
  130. package/project/.sdk/tm/js/src/utility/ResbodyUtility.js +0 -15
  131. package/project/.sdk/tm/js/src/utility/ResformUtility.js +0 -34
  132. package/project/.sdk/tm/js/src/utility/ResheadersUtility.js +0 -19
  133. package/project/.sdk/tm/js/src/utility/ResponseUtility.js +0 -37
  134. package/project/.sdk/tm/js/src/utility/ResultUtility.js +0 -28
  135. package/project/.sdk/tm/js/src/utility/SpecUtility.js +0 -35
@@ -0,0 +1,21 @@
1
+
2
+ const { getprop } = require('./utility/StructUtility')
3
+
4
+
5
+ class Result {
6
+ constructor(resmap) {
7
+ this.ok = getprop(resmap, 'ok', false)
8
+ this.status = getprop(resmap, 'status', -1)
9
+ this.statusText = getprop(resmap, 'statusText', '')
10
+ this.headers = getprop(resmap, 'headers', {})
11
+ this.body = getprop(resmap, 'body')
12
+ this.err = getprop(resmap, 'err')
13
+ this.resdata = getprop(resmap, 'resdata')
14
+ this.resmatch = getprop(resmap, 'resmatch')
15
+ }
16
+ }
17
+
18
+
19
+ module.exports = {
20
+ Result,
21
+ }
@@ -0,0 +1,26 @@
1
+
2
+ const { getprop } = require('./utility/StructUtility')
3
+
4
+
5
+ class Spec {
6
+ constructor(specmap) {
7
+ this.parts = getprop(specmap, 'parts', [])
8
+ this.headers = getprop(specmap, 'headers', {})
9
+ this.alias = getprop(specmap, 'alias', {})
10
+ this.base = getprop(specmap, 'base', '')
11
+ this.prefix = getprop(specmap, 'prefix', '')
12
+ this.suffix = getprop(specmap, 'suffix', '')
13
+ this.params = getprop(specmap, 'params', {})
14
+ this.query = getprop(specmap, 'query', {})
15
+ this.step = getprop(specmap, 'step', '')
16
+ this.method = getprop(specmap, 'method', 'GET')
17
+ this.body = getprop(specmap, 'body')
18
+ this.url = getprop(specmap, 'url')
19
+ this.path = getprop(specmap, 'path')
20
+ }
21
+ }
22
+
23
+
24
+ module.exports = {
25
+ Spec,
26
+ }
@@ -0,0 +1 @@
1
+ # Feature
@@ -0,0 +1,45 @@
1
+
2
+
3
+ class BaseFeature {
4
+ version = '0.0.1'
5
+ name = 'base'
6
+ active = true
7
+
8
+
9
+ init(_ctx, _options) { }
10
+
11
+
12
+ PostConstruct(_ctx) { }
13
+
14
+ PostConstructEntity(_ctx) { }
15
+
16
+
17
+ SetData(_ctx) { }
18
+
19
+ GetData(_ctx) { }
20
+
21
+ SetMatch(_ctx) { }
22
+
23
+ GetMatch(_ctx) { }
24
+
25
+
26
+ PrePoint(_ctx) { }
27
+
28
+ PreSpec(_ctx) { }
29
+
30
+ PreRequest(_ctx) { }
31
+
32
+ PreResponse(_ctx) { }
33
+
34
+ PreResult(_ctx) { }
35
+
36
+ PreDone(_ctx) { }
37
+
38
+ PreUnexpected(_ctx) { }
39
+
40
+ }
41
+
42
+
43
+ module.exports = {
44
+ BaseFeature
45
+ }
@@ -1,98 +1,97 @@
1
1
 
2
2
 
3
+ const { BaseFeature } = require('../base/BaseFeature')
4
+
5
+
3
6
  const Pino = require('pino')
4
7
  const PinoPretty = require('pino-pretty')
5
8
 
6
9
 
7
- class LogFeature {
8
- version = 'FEATURE_VERSION'
9
-
10
- #client // SDK client instance
11
- #options // SDK client feature options
12
- #config // Feature config from model
13
- #logger // Pino-style interface
14
-
15
- constructor(client, options, config) {
16
- // TOOD: make this a default for all features
17
- options = options || {}
18
- options.active = false !== options.active
19
10
 
20
- this.#client = client
21
- this.#options = options
22
- this.#config = config
11
+ class LogFeature extends BaseFeature {
12
+ version = '0.0.1'
13
+ name = 'log'
14
+ active = true
15
+
16
+ _client
17
+ _options
18
+ _logger
19
+
23
20
 
24
- if(options.active) {
25
- let logger = options.logger
21
+ init(ctx, options) {
22
+ this._client = ctx.client
23
+ this._options = options
24
+ this.active = options.active
26
25
 
27
- if(null ==logger) {
26
+ if (this.active) {
27
+ let logger = this._options.logger
28
+
29
+ if (null == logger) {
28
30
  let pretty = PinoPretty({
29
31
  sync: true,
30
32
  ignore: 'ctx',
31
33
  })
32
34
 
33
- let name = options.name || 'FEATURE_Name'
34
- let level = options.level || 'info'
35
-
36
- logger = Pino({ name, level }, pretty)
35
+ let level = this._options.level || 'info'
36
+
37
+ logger = Pino({ name: 'log', level }, pretty)
38
+
39
+ this._logger = logger
37
40
  }
38
- this.#logger = logger
39
41
  }
40
42
  }
41
43
 
42
- options() {
43
- return { ...this.#options }
44
- }
45
-
46
- client() {
47
- return this.#client
48
- }
49
44
 
50
-
51
45
  PostConstruct(ctx) {
52
- this.#loghook('PostConstruct', ctx)
46
+ this._loghook('PostConstruct', ctx)
53
47
  }
54
48
 
55
49
  PostConstructEntity(ctx) {
56
- this.#loghook('PostConstructEntity', ctx)
50
+ this._loghook('PostConstructEntity', ctx)
57
51
  }
58
52
 
59
53
  SetData(ctx) {
60
- this.#loghook('SetData', ctx)
54
+ this._loghook('SetData', ctx)
61
55
  }
62
-
56
+
63
57
  GetData(ctx) {
64
- this.#loghook('GetData', ctx)
58
+ this._loghook('GetData', ctx)
65
59
  }
66
-
60
+
67
61
  GetMatch(ctx) {
68
- this.#loghook('GetMatch', ctx)
62
+ this._loghook('GetMatch', ctx)
69
63
  }
70
64
 
71
65
 
72
66
  PrePoint(ctx) {
73
- this.#loghook('PrePoint', ctx)
67
+ this._loghook('PrePoint', ctx)
74
68
  }
75
69
 
76
70
  PreSpec(ctx) {
77
- this.#loghook('PreSpec', ctx)
71
+ this._loghook('PreSpec', ctx)
78
72
  }
79
73
 
80
74
  PreRequest(ctx) {
81
- this.#loghook('PreRequest', ctx)
75
+ this._loghook('PreRequest', ctx)
82
76
  }
83
77
 
84
78
  PreResponse(ctx) {
85
- this.#loghook('PreResponse', ctx)
79
+ this._loghook('PreResponse', ctx)
86
80
  }
87
81
 
88
82
  PreResult(ctx) {
89
- this.#loghook('PreResult', ctx)
83
+ this._loghook('PreResult', ctx)
90
84
  }
91
-
92
- #loghook(hook, ctx, level) {
85
+
86
+ _loghook(hook, ctx, level) {
93
87
  level = level || 'info'
94
- if(this.#logger) {
95
- this.#logger[level]({hook,op:ctx.op,spec:ctx.spec,ctx})
88
+ if (this._logger) {
89
+ this._logger[level]({
90
+ hook,
91
+ op: ctx.op,
92
+ spec: ctx.spec,
93
+ ctx
94
+ })
96
95
  }
97
96
  }
98
97
  }
@@ -0,0 +1,207 @@
1
+
2
+ const { BaseFeature } = require('../base/BaseFeature')
3
+
4
+
5
+ const S_NOT_FOUND = 'Not found'
6
+
7
+
8
+ class TestFeature extends BaseFeature {
9
+ version = '0.0.1'
10
+ name = 'test'
11
+ active = true
12
+
13
+ _client
14
+ _options
15
+
16
+
17
+ init(ctx, options) {
18
+ this._client = ctx.client
19
+ this._options = options
20
+
21
+ const struct = ctx.utility.struct
22
+ const walk = struct.walk
23
+ const size = struct.size
24
+ const setprop = struct.setprop
25
+
26
+ const entity = this._options.entity
27
+
28
+ this._client._mode = 'test'
29
+
30
+ // Ensure entity ids are correct.
31
+ walk(entity, (k, v, _parent, path) => {
32
+ if (2 === size(path)) {
33
+ setprop(v, 'id', k)
34
+ }
35
+ return v
36
+ })
37
+
38
+ const self = this
39
+
40
+ function testFetcher(ctx, _fullurl, _fetchdef) {
41
+ const struct = ctx.utility.struct
42
+ const param = ctx.utility.param
43
+
44
+ const getprop = struct.getprop
45
+ const clone = struct.clone
46
+ const merge = struct.merge
47
+ const getelem = struct.getelem
48
+ const select = struct.select
49
+ const delprop = struct.delprop
50
+ const getdef = struct.getdef
51
+
52
+ function respond(status, data, res) {
53
+ const out = merge([
54
+ {
55
+ status,
56
+ statusText: 'OK',
57
+ json: async () => data,
58
+ body: 'not-used',
59
+ },
60
+ getdef(res, {})
61
+ ])
62
+
63
+ const headers = getprop(out, 'headers', {})
64
+
65
+ // JS specific iterator.
66
+ out.headers = {
67
+ forEach(callback) {
68
+ Object.keys(headers).forEach((key) => {
69
+ callback(headers[key], key, this)
70
+ })
71
+ }
72
+ }
73
+
74
+ return out
75
+ }
76
+
77
+
78
+ const op = ctx.op
79
+ const entmap = getprop(entity, op.entity, {})
80
+
81
+ if ('load' === op.name) {
82
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
83
+ const found = select(entmap, args)
84
+ const ent = getelem(found, 0)
85
+ if (null == ent) {
86
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
87
+ }
88
+ else {
89
+ delprop(ent, '$KEY')
90
+ const out = clone(ent)
91
+ return respond(200, out)
92
+ }
93
+ }
94
+ else if ('list' === op.name) {
95
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
96
+ const found = select(entmap, args)
97
+ if (null == found) {
98
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
99
+ }
100
+ else {
101
+ found.map((ent) => delprop(ent, '$KEY'))
102
+ const out = clone(found)
103
+ return respond(200, out)
104
+ }
105
+ }
106
+ else if ('update' === op.name) {
107
+ const args = self.buildArgs(ctx, op, ctx.reqdata)
108
+ const found = select(entmap, args)
109
+ const ent = getelem(found, 0)
110
+ if (null == ent) {
111
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
112
+ }
113
+ else {
114
+ merge([ent, (ctx.reqdata || {})])
115
+ delprop(ent, '$KEY')
116
+ const out = clone(ent)
117
+ return respond(200, out)
118
+ }
119
+ }
120
+ else if ('remove' === op.name) {
121
+ const args = self.buildArgs(ctx, op, ctx.reqmatch)
122
+ const found = select(entmap, args)
123
+ const ent = getelem(found, 0)
124
+ if (null == ent) {
125
+ return respond(404, undefined, { statusText: S_NOT_FOUND })
126
+ }
127
+ else {
128
+ delprop(entmap, getprop(ent, 'id'))
129
+ return respond(200)
130
+ }
131
+ }
132
+ else if ('create' === op.name) {
133
+ const args = self.buildArgs(ctx, op, ctx.reqdata)
134
+ let id = param(ctx, 'id')
135
+ if (null == id) {
136
+ id = ((1e4 * Math.random() | 0).toString(16) +
137
+ (1e4 * Math.random() | 0).toString(16) +
138
+ (1e4 * Math.random() | 0).toString(16) +
139
+ (1e4 * Math.random() | 0).toString(16)).padEnd(16, '0')
140
+ }
141
+
142
+ const ent = clone(ctx.reqdata)
143
+ setprop(ent, 'id', id)
144
+ setprop(entmap, id, ent)
145
+ delprop(ent, '$KEY')
146
+ const out = clone(ent)
147
+ return respond(200, out)
148
+ }
149
+ }
150
+
151
+ ctx.utility.fetcher = testFetcher
152
+ }
153
+
154
+
155
+ buildArgs(ctx, op, args) {
156
+ const struct = ctx.utility.struct
157
+ const param = ctx.utility.param
158
+
159
+ const getprop = struct.getprop
160
+ const keysof = struct.keysof
161
+ const getpath = struct.getpath
162
+ const getelem = struct.getelem
163
+ const select = struct.select
164
+ const transform = struct.transform
165
+ const isempty = struct.isempty
166
+
167
+ const opname = getprop(op, 'name')
168
+ const point =
169
+ getelem(getpath(ctx.config, [
170
+ 'entity', getprop(ctx.entity, 'name'), 'op', opname, 'points']), -1)
171
+
172
+ const reqd = transform(
173
+ select(getpath(point, ['args', 'params']), { reqd: true }),
174
+ ['`$EACH`', '', '`$KEY.name`']
175
+ )
176
+
177
+ const qand = []
178
+ const q = { '`$AND`': qand }
179
+
180
+ for (let k of keysof(args)) {
181
+ if ('id' === k || !isempty(select(reqd, k))) {
182
+ const v = param(ctx, k)
183
+ const ka = getprop(op.alias, k)
184
+
185
+ let qor = [{ [k]: v }]
186
+ if (null != ka) {
187
+ qor.push({ [ka]: v })
188
+ }
189
+
190
+ qor = { '`$OR`': qor }
191
+
192
+ qand.push(qor)
193
+ }
194
+ }
195
+
196
+ if (ctx.ctrl.explain) {
197
+ ctx.ctrl.explain.test = { query: q }
198
+ }
199
+
200
+ return q
201
+ }
202
+ }
203
+
204
+
205
+ module.exports = {
206
+ TestFeature
207
+ }
@@ -0,0 +1,22 @@
1
+
2
+ const { ProjectNameEntityBase } = require('./ProjectNameEntityBase')
3
+
4
+ const { Point } = require('./Point')
5
+ const { Context } = require('./Context')
6
+ const { Control } = require('./Control')
7
+ const { Operation } = require('./Operation')
8
+ const { Response } = require('./Response')
9
+ const { Result } = require('./Result')
10
+ const { Spec } = require('./Spec')
11
+
12
+
13
+ module.exports = {
14
+ Point,
15
+ Context,
16
+ Control,
17
+ Operation,
18
+ Response,
19
+ Result,
20
+ Spec,
21
+ ProjectNameEntityBase,
22
+ }
@@ -0,0 +1,31 @@
1
+
2
+ const {
3
+ walk, size, pad, slice, clone
4
+ } = require('./StructUtility')
5
+
6
+ // Clean request data by partially hiding sensitive values.
7
+ function clean(ctx, val) {
8
+ const options = ctx.options
9
+
10
+ const cleankeyre = options?.__derived__?.clean?.keyre
11
+ const hintsize = 4
12
+
13
+ /*
14
+ if (null != cleankeyre) {
15
+ val = walk(clone(val), (key, subval) => {
16
+ if (cleankeyre.exec(key) && 'string' === typeof subval) {
17
+ const len = size(subval)
18
+ const hint = (hintsize * 4) < len ? slice(subval, 0, hintsize) : ''
19
+ subval = pad(hint, len, '*')
20
+ }
21
+ return subval
22
+ })
23
+ }
24
+ */
25
+
26
+ return val
27
+ }
28
+
29
+ module.exports = {
30
+ clean
31
+ }
@@ -1,15 +1,22 @@
1
1
 
2
+ const { clean } = require('./CleanUtility')
3
+
2
4
  function done(ctx) {
3
- const { error } = ctx.utility
4
-
5
- if(ctx.result.ok) {
5
+ const error = ctx.utility.makeError
6
+ const delprop = ctx.utility.struct.delprop
7
+
8
+ if (ctx.ctrl.explain) {
9
+ ctx.ctrl.explain = clean(ctx, ctx.ctrl.explain)
10
+ delprop(ctx.ctrl.explain.result, 'err')
11
+ }
12
+
13
+ if (ctx.result && ctx.result.ok) {
6
14
  return ctx.result.resdata
7
15
  }
8
16
 
9
17
  return error(ctx)
10
18
  }
11
19
 
12
-
13
20
  module.exports = {
14
21
  done
15
22
  }
@@ -0,0 +1,42 @@
1
+
2
+ function featureAdd(ctx, f) {
3
+ const client = ctx.client
4
+ const struct = ctx.utility.struct
5
+ const setprop = struct.setprop
6
+ const getprop = struct.getprop
7
+
8
+ const fopts = getprop(f, '_options', {})
9
+ let added = false
10
+ const features = client._features
11
+
12
+ if (fopts.__before__ || fopts.__after__ || fopts.__replace__) {
13
+
14
+ for (let i = 0; i < features.length; i++) {
15
+ let ef = client._features[i]
16
+ if (fopts.__before__ === ef.name) {
17
+ client._features = [...features.slice(0, i), f, ...features.slice(i)]
18
+ added = true
19
+ break
20
+ }
21
+ else if (fopts.__after__ === ef.name) {
22
+ client._features = [...features.slice(0, ++i), f, ...features.slice(i)]
23
+ added = true
24
+ break
25
+ }
26
+ else if (fopts.__replace__ === ef.name) {
27
+ client._features = setprop(features, i, f)
28
+ added = true
29
+ break
30
+ }
31
+ }
32
+ }
33
+
34
+ if (!added) {
35
+ client._features = setprop(features, features.length, f)
36
+ }
37
+
38
+ }
39
+
40
+ module.exports = {
41
+ featureAdd
42
+ }
@@ -0,0 +1,25 @@
1
+
2
+ function featureHook(ctx, name) {
3
+ const client = ctx.client
4
+
5
+ let resp = []
6
+ const features = client._features || []
7
+
8
+ for (let f of features) {
9
+ const fh = f[name]
10
+ if (null != fh) {
11
+ const fres = fh(ctx)
12
+ if (fres instanceof Promise) {
13
+ resp.push(fres)
14
+ }
15
+ }
16
+ }
17
+
18
+ if (0 < resp.length) {
19
+ return Promise.all(resp)
20
+ }
21
+ }
22
+
23
+ module.exports = {
24
+ featureHook
25
+ }
@@ -0,0 +1,11 @@
1
+
2
+ function featureInit(ctx, f) {
3
+ const fopts = ctx.options.feature[f.name] || {}
4
+ if (true === fopts.active) {
5
+ f.init(ctx, fopts)
6
+ }
7
+ }
8
+
9
+ module.exports = {
10
+ featureInit
11
+ }
@@ -0,0 +1,28 @@
1
+
2
+ // Make HTTP call using library. Replace this utility for mocking etc.
3
+ async function fetcher(ctx, fullurl, fetchdef) {
4
+
5
+ if ('live' !== ctx.client._mode) {
6
+ return ctx.error('fetch_mode_block', 'Request blocked by mode: "' + ctx.client._mode +
7
+ '" (URL was: "' + fullurl + '")')
8
+ }
9
+
10
+ const options = ctx.client.options()
11
+
12
+ const getpath = ctx.utility.struct.getpath
13
+
14
+ if (true === getpath(options, 'feature.test.active')) {
15
+ return ctx.error('fetch_test_block', 'Request blocked as test feature is active' +
16
+ ' (URL was: "' + fullurl + '")')
17
+ }
18
+
19
+ const fetch = options.system.fetch
20
+
21
+ const response = await fetch(fullurl, fetchdef)
22
+
23
+ return response
24
+ }
25
+
26
+ module.exports = {
27
+ fetcher
28
+ }
@@ -0,0 +1,11 @@
1
+
2
+ const { Context } = require('../Context')
3
+
4
+ function makeContext(ctxmap, basectx) {
5
+ const ctx = new Context(ctxmap, basectx)
6
+ return ctx
7
+ }
8
+
9
+ module.exports = {
10
+ makeContext,
11
+ }