@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
@@ -41,7 +41,7 @@ class ProjectNameTestRunner
41
41
  return $val !== false ? $val : null;
42
42
  }
43
43
 
44
- public static function env_override(array &$m): array
44
+ public static function env_override(array $m): array
45
45
  {
46
46
  $live = self::getenv('PROJECTNAME_TEST_LIVE');
47
47
  $override = self::getenv('PROJECTNAME_TEST_OVERRIDE');
@@ -87,3 +87,26 @@ class ProjectNameTestRunner
87
87
  return $out;
88
88
  }
89
89
  }
90
+
91
+ // Aliases for test convenience.
92
+ class_alias('ProjectNameTestRunner', 'Runner');
93
+ class_alias('ProjectNameHelpers', 'Helpers');
94
+ class_alias('Voxgig\Struct\Struct', 'Vs');
95
+
96
+ // Filter array of maps by matching key-value criteria.
97
+ function sdk_select(array $list, array $criteria): array
98
+ {
99
+ $out = [];
100
+ foreach ($list as $item) {
101
+ if (!is_array($item)) continue;
102
+ $match = true;
103
+ foreach ($criteria as $k => $v) {
104
+ if (!isset($item[$k]) || $item[$k] !== $v) {
105
+ $match = false;
106
+ break;
107
+ }
108
+ }
109
+ if ($match) $out[] = $item;
110
+ }
111
+ return $out;
112
+ }
@@ -0,0 +1,275 @@
1
+ <?php
2
+
3
+ namespace Voxgig\Struct;
4
+
5
+ use Exception;
6
+
7
+ // Vendored from voxgig/struct/php
8
+ require_once __DIR__ . '/../utility/struct/Struct.php';
9
+
10
+ class Runner {
11
+
12
+ private const NULLMARK = "__NULL__";
13
+ private const UNDEFMARK = "__UNDEF__";
14
+
15
+ public static function makeRunner(string $testfile, $client): callable {
16
+ return function (string $name, $store = null) use ($testfile, $client) {
17
+ $store = $store ?? [];
18
+ $utility = $client->utility();
19
+ $structUtils = $utility->struct;
20
+ $spec = self::resolveSpec($name, $testfile);
21
+ $clients = self::resolveClients($client, $spec, $store, $structUtils);
22
+ $subject = self::resolveSubject($name, $utility);
23
+
24
+ $runsetflags = function ($testspec, array $flags = [], $testsubject = null) use ($name, $client, $structUtils, &$subject, $clients) {
25
+ $subject = $testsubject ?? $subject;
26
+ $flags = self::resolveFlags($flags);
27
+ $testspecmap = self::fixJSON($testspec, $flags);
28
+ if (!isset($testspecmap['set']) || !is_array($testspecmap['set'])) {
29
+ throw new Exception("Test specification 'set' is missing or not an array");
30
+ }
31
+ $testset = $testspecmap['set'];
32
+ foreach ($testset as &$entry) {
33
+ try {
34
+ $entry = self::resolveEntry($entry, $flags);
35
+ $testpack = self::resolveTestPack($name, $entry, $subject, $client, $clients);
36
+ $args = self::resolveArgs($entry, $testpack, $structUtils);
37
+ $res = call_user_func_array($testpack['subject'], $args);
38
+ $res = self::fixJSON($res, $flags);
39
+ $entry['res'] = $res;
40
+ self::checkResult($entry, $res, $structUtils);
41
+ } catch (Exception $err) {
42
+ self::handleError($entry, $err, $structUtils);
43
+ }
44
+ }
45
+ };
46
+
47
+ $runset = function ($testspec, $testsubject = null) use ($runsetflags) {
48
+ $runsetflags($testspec, [], $testsubject);
49
+ };
50
+
51
+ return [
52
+ 'spec' => $spec,
53
+ 'runset' => $runset,
54
+ 'runsetflags' => $runsetflags,
55
+ 'subject' => $subject,
56
+ 'client' => $client,
57
+ ];
58
+ };
59
+ }
60
+
61
+ private static function resolveSpec(string $name, string $testfile): array {
62
+ // If $testfile is an absolute path, use it as-is; otherwise, build a path relative to __DIR__
63
+ if (preg_match('/^(\/|[A-Za-z]:[\/\\\\])/', $testfile)) {
64
+ $path = $testfile;
65
+ } else {
66
+ $path = rtrim(__DIR__, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $testfile;
67
+ }
68
+ $json = file_get_contents($path);
69
+ if ($json === false) {
70
+ throw new Exception("Unable to read test file at $path");
71
+ }
72
+ $alltests = json_decode($json, true);
73
+ if (isset($alltests['primary'][$name])) {
74
+ return $alltests['primary'][$name];
75
+ } elseif (isset($alltests[$name])) {
76
+ return $alltests[$name];
77
+ } else {
78
+ return $alltests;
79
+ }
80
+ }
81
+
82
+ private static function resolveClients($client, array $spec, $store, $structUtils): array {
83
+ $clients = [];
84
+ if (isset($spec['DEF']) && isset($spec['DEF']['client'])) {
85
+ foreach ($spec['DEF']['client'] as $cn => $cdef) {
86
+ $copts = $cdef['test']['options'] ?? [];
87
+ if (is_array($store) && method_exists($structUtils, 'inject')) {
88
+ $structUtils->inject($copts, $store);
89
+ }
90
+ $clients[$cn] = $client->test($copts);
91
+ }
92
+ }
93
+ return $clients;
94
+ }
95
+
96
+ private static function resolveSubject(string $name, $container, $subject = null) {
97
+ return $subject ?? ($container->$name ?? null);
98
+ }
99
+
100
+ private static function resolveFlags($flags = null): array {
101
+ if ($flags === null) {
102
+ $flags = [];
103
+ }
104
+ $flags['null'] = $flags['null'] ?? true;
105
+ $flags['null'] = (bool)$flags['null'];
106
+ return $flags;
107
+ }
108
+
109
+ private static function resolveEntry($entry, array $flags) {
110
+ if (!isset($entry['out']) && $flags['null']) {
111
+ $entry['out'] = self::NULLMARK;
112
+ }
113
+ return $entry;
114
+ }
115
+
116
+ private static function checkResult(array $entry, $res, $structUtils) {
117
+ $matched = false;
118
+ if (isset($entry['match'])) {
119
+ $result = [
120
+ 'in' => $entry['in'] ?? null,
121
+ 'out' => $entry['res'] ?? null,
122
+ 'ctx' => $entry['ctx'] ?? null,
123
+ ];
124
+ self::match($entry['match'], $result, $structUtils);
125
+ $matched = true;
126
+ }
127
+ if (isset($entry['out']) && $entry['out'] === $res) {
128
+ return;
129
+ }
130
+ if ($matched && ($entry['out'] === self::NULLMARK || $entry['out'] === null)) {
131
+ return;
132
+ }
133
+ if (json_encode($res) !== json_encode($entry['out'])) {
134
+ throw new \AssertionError('Deep equality failed: expected ' .
135
+ $structUtils->stringify($entry['out']) . ' but got ' .
136
+ $structUtils->stringify($res));
137
+ }
138
+ }
139
+
140
+ private static function handleError(&$entry, \Exception $err, $structUtils) {
141
+ $entry['thrown'] = $err->getMessage();
142
+ if (isset($entry['err'])) {
143
+ if ($entry['err'] === true || self::matchval($entry['err'], $err->getMessage(), $structUtils)) {
144
+ if (isset($entry['match'])) {
145
+ self::match(
146
+ $entry['match'],
147
+ [
148
+ 'in' => $entry['in'] ?? null,
149
+ 'out' => $entry['res'] ?? null,
150
+ 'ctx' => $entry['ctx'] ?? null,
151
+ 'err' => $err->getMessage(),
152
+ ],
153
+ $structUtils
154
+ );
155
+ }
156
+ return;
157
+ }
158
+ throw new \AssertionError('ERROR MATCH: [' . $structUtils->stringify($entry['err']) .
159
+ '] <=> [' . $err->getMessage() . ']');
160
+ } elseif ($err instanceof \AssertionError) {
161
+ throw new \AssertionError($err->getMessage() .
162
+ "\n\nENTRY: " . json_encode($entry, JSON_PRETTY_PRINT));
163
+ } else {
164
+ throw new Exception($err->getTraceAsString() .
165
+ "\n\nENTRY: " . json_encode($entry, JSON_PRETTY_PRINT));
166
+ }
167
+ }
168
+
169
+ private static function resolveArgs($entry, array $testpack, $structUtils): array {
170
+ $args = [];
171
+ if (isset($entry['in'])) {
172
+ $args[] = $structUtils->clone($entry['in']);
173
+ }
174
+ if (isset($entry['ctx'])) {
175
+ $args = [$entry['ctx']];
176
+ } elseif (isset($entry['args'])) {
177
+ $args = $entry['args'];
178
+ }
179
+ if ((isset($entry['ctx']) || isset($entry['args'])) && isset($args[0]) && is_array($args[0])) {
180
+ $first = $structUtils->clone($args[0]);
181
+ $first['client'] = $testpack['client'];
182
+ $first['utility'] = $testpack['utility'];
183
+ $args[0] = $first;
184
+ $entry['ctx'] = $first;
185
+ }
186
+ return $args;
187
+ }
188
+
189
+ private static function resolveTestPack(string $name, $entry, $subject, $client, array $clients): array {
190
+ $testpack = [
191
+ 'client' => $client,
192
+ 'subject' => $subject,
193
+ 'utility' => $client->utility(),
194
+ ];
195
+ if (isset($entry['client'])) {
196
+ $testpack['client'] = $clients[$entry['client']] ?? $client;
197
+ $testpack['utility'] = $testpack['client']->utility();
198
+ $testpack['subject'] = self::resolveSubject($name, $testpack['utility']);
199
+ }
200
+ return $testpack;
201
+ }
202
+
203
+ private static function match($check, $base, $structUtils): void {
204
+ $structUtils->walk($check, function ($key, $val, $parent, $path) use ($base, $structUtils) {
205
+ if (!is_array($val) && !is_object($val)) {
206
+ $baseval = $structUtils->getpath($base, $path);
207
+ if ($baseval === $val) {
208
+ return;
209
+ }
210
+ if ($val === self::UNDEFMARK && $baseval === null) {
211
+ return;
212
+ }
213
+ if (!self::matchval($val, $baseval, $structUtils)) {
214
+ throw new \AssertionError(
215
+ 'MATCH: ' . implode('.', $path) .
216
+ ': [' . $structUtils->stringify($val) .
217
+ '] <=> [' . $structUtils->stringify($baseval) . ']'
218
+ );
219
+ }
220
+ }
221
+ });
222
+ }
223
+
224
+ private static function matchval($check, $base, $structUtils): bool {
225
+ $pass = ($check === $base);
226
+ if (!$pass) {
227
+ if (is_string($check)) {
228
+ $basestr = $structUtils->stringify($base);
229
+ if (preg_match('/^\/(.+)\/$/', $check, $matches)) {
230
+ $pass = preg_match('/' . $matches[1] . '/', $basestr) === 1;
231
+ } else {
232
+ $pass = stripos($basestr, $structUtils->stringify($check)) !== false;
233
+ }
234
+ } elseif (is_callable($check)) {
235
+ $pass = true;
236
+ }
237
+ }
238
+ return $pass;
239
+ }
240
+
241
+ private static function fixJSON($val, array $flags) {
242
+ if ($val === null) {
243
+ return $flags['null'] ? self::NULLMARK : $val;
244
+ }
245
+ $replacer = function ($v) use ($flags, &$replacer) {
246
+ if ($v === null && $flags['null']) {
247
+ return self::NULLMARK;
248
+ }
249
+ if ($v instanceof \Exception) {
250
+ return array_merge(get_object_vars($v), [
251
+ 'name' => get_class($v),
252
+ 'message' => $v->getMessage(),
253
+ ]);
254
+ }
255
+ if (is_array($v)) {
256
+ return array_map($replacer, $v);
257
+ }
258
+ if (is_object($v)) {
259
+ $arr = get_object_vars($v);
260
+ return array_map($replacer, $arr);
261
+ }
262
+ return $v;
263
+ };
264
+ $fixed = $replacer($val);
265
+ return json_decode(json_encode($fixed), true);
266
+ }
267
+
268
+ public static function nullModifier($val, $key, array &$parent) {
269
+ if ($val === self::NULLMARK) {
270
+ $parent[$key] = null;
271
+ } elseif (is_string($val)) {
272
+ $parent[$key] = str_replace('__NULL__', 'null', $val);
273
+ }
274
+ }
275
+ }