@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
@@ -1394,7 +1394,17 @@ local function merge(val, maxdepth)
1394
1394
  end
1395
1395
 
1396
1396
  local list = val
1397
+
1398
+ -- Use rawlen or find max integer key to handle nil gaps in arrays.
1397
1399
  local lenlist = #list
1400
+ if lenlist == 0 then
1401
+ -- Check for nil gaps: find the actual max integer key.
1402
+ for k in pairs(list) do
1403
+ if type(k) == S_number and k > lenlist then
1404
+ lenlist = k
1405
+ end
1406
+ end
1407
+ end
1398
1408
 
1399
1409
  if lenlist == 0 then
1400
1410
  return NONE
@@ -25,24 +25,26 @@ class ProjectNameTestFeature extends ProjectNameBaseFeature
25
25
  $this->client = $ctx->client;
26
26
  $this->options = $options;
27
27
 
28
- $entity = \Voxgig\Struct\Struct::getprop($options, 'entity');
29
- if (!is_array($entity)) {
30
- $entity = [];
28
+ $entity_data = \Voxgig\Struct\Struct::getprop($options, 'entity');
29
+ if (!is_array($entity_data)) {
30
+ $entity_data = [];
31
31
  }
32
32
 
33
33
  $this->client->mode = 'test';
34
34
 
35
35
  // Ensure entity ids are correct.
36
- \Voxgig\Struct\Struct::walk($entity, function ($key, $val, $parent, $path) {
36
+ \Voxgig\Struct\Struct::walk($entity_data, function ($key, $val, $parent, $path) {
37
37
  if (count($path) === 2 && is_array($val) && $key !== null) {
38
38
  $val['id'] = $key;
39
39
  }
40
40
  return $val;
41
41
  });
42
42
 
43
- $test_self = $this;
43
+ // Wrap in object so closure mutations persist (PHP arrays are value types).
44
+ $entity = new \stdClass();
45
+ $entity->data = $entity_data;
44
46
 
45
- $test_fetcher = function (ProjectNameContext $fctx, string $_fullurl, array $_fetchdef) use ($entity, $test_self): array {
47
+ $test_fetcher = function (ProjectNameContext $fctx, string $_fullurl, array $_fetchdef) use ($entity): array {
46
48
  $respond = function (int $status, mixed $data, ?array $extra): array {
47
49
  $out = [
48
50
  'status' => $status,
@@ -59,83 +61,90 @@ class ProjectNameTestFeature extends ProjectNameBaseFeature
59
61
  };
60
62
 
61
63
  $op = $fctx->op;
62
- $entmap = \Voxgig\Struct\Struct::getprop($entity, $op->entity);
63
- if (!is_array($entmap)) {
64
- $entmap = [];
65
- }
64
+ $entname = $op->entity;
65
+ $entmap = is_array($entity->data[$entname] ?? null) ? $entity->data[$entname] : [];
66
+
67
+ // Extract id from context: reqmatch for load/remove, reqdata for update/create.
68
+ $get_id = function () use ($fctx) {
69
+ $sources = [$fctx->reqmatch, $fctx->reqdata, $fctx->data];
70
+ foreach ($sources as $src) {
71
+ if (is_array($src) && isset($src['id']) && $src['id'] !== '__UNDEFINED__') {
72
+ return $src['id'];
73
+ }
74
+ }
75
+ return null;
76
+ };
66
77
 
67
78
  if ($op->name === 'load') {
68
- $args = $test_self->build_args($fctx, $op, $fctx->reqmatch);
69
- $found = \Voxgig\Struct\Struct::select($entmap, $args);
70
- $ent = \Voxgig\Struct\Struct::getelem($found, 0);
79
+ $id = $get_id();
80
+ $ent = ($id !== null && isset($entmap[$id])) ? $entmap[$id] : null;
81
+ if (!$ent) {
82
+ // Fallback: search by id field value
83
+ foreach ($entmap as $e) {
84
+ if (is_array($e) && ($e['id'] ?? null) === $id) { $ent = $e; break; }
85
+ }
86
+ }
71
87
  if (!$ent) {
72
88
  return $respond(404, null, ['statusText' => 'Not found']);
73
89
  }
74
- \Voxgig\Struct\Struct::delprop($ent, '$KEY');
75
90
  $out = \Voxgig\Struct\Struct::clone($ent);
91
+ if (is_array($out)) { unset($out['$KEY']); }
76
92
  return $respond(200, $out, null);
77
93
 
78
94
  } elseif ($op->name === 'list') {
79
- $args = $test_self->build_args($fctx, $op, $fctx->reqmatch);
80
- $found = \Voxgig\Struct\Struct::select($entmap, $args);
81
- if (!$found) {
82
- return $respond(404, null, ['statusText' => 'Not found']);
83
- }
84
- if (is_array($found)) {
85
- foreach ($found as $item) {
86
- \Voxgig\Struct\Struct::delprop($item, '$KEY');
95
+ $out = [];
96
+ foreach ($entmap as $e) {
97
+ if (is_array($e)) {
98
+ $copy = $e;
99
+ unset($copy['$KEY']);
100
+ $out[] = $copy;
87
101
  }
88
102
  }
89
- $out = \Voxgig\Struct\Struct::clone($found);
90
103
  return $respond(200, $out, null);
91
104
 
92
105
  } elseif ($op->name === 'update') {
93
- $args = $test_self->build_args($fctx, $op, $fctx->reqdata);
94
- $found = \Voxgig\Struct\Struct::select($entmap, $args);
95
- $ent = \Voxgig\Struct\Struct::getelem($found, 0);
106
+ $id = $get_id();
107
+ $ent = ($id !== null && isset($entmap[$id])) ? $entmap[$id] : null;
108
+ if (!$ent) {
109
+ foreach ($entmap as $e) {
110
+ if (is_array($e) && ($e['id'] ?? null) === $id) { $ent = $e; break; }
111
+ }
112
+ }
96
113
  if (!$ent) {
97
114
  return $respond(404, null, ['statusText' => 'Not found']);
98
115
  }
99
- if (is_array($ent) && $fctx->reqdata) {
116
+ if (is_array($fctx->reqdata)) {
100
117
  foreach ($fctx->reqdata as $k => $v) {
101
118
  $ent[$k] = $v;
102
119
  }
103
120
  }
104
- \Voxgig\Struct\Struct::delprop($ent, '$KEY');
121
+ $entmap[$id] = $ent;
122
+ $entity->data[$entname] = $entmap;
105
123
  $out = \Voxgig\Struct\Struct::clone($ent);
124
+ if (is_array($out)) { unset($out['$KEY']); }
106
125
  return $respond(200, $out, null);
107
126
 
108
127
  } elseif ($op->name === 'remove') {
109
- $args = $test_self->build_args($fctx, $op, $fctx->reqmatch);
110
- $found = \Voxgig\Struct\Struct::select($entmap, $args);
111
- $ent = \Voxgig\Struct\Struct::getelem($found, 0);
112
- if (!$ent) {
113
- return $respond(404, null, ['statusText' => 'Not found']);
114
- }
115
- if (is_array($ent)) {
116
- $id = \Voxgig\Struct\Struct::getprop($ent, 'id');
117
- \Voxgig\Struct\Struct::delprop($entmap, $id);
128
+ $id = $get_id();
129
+ if ($id !== null && isset($entmap[$id])) {
130
+ unset($entmap[$id]);
131
+ $entity->data[$entname] = $entmap;
118
132
  }
119
133
  return $respond(200, null, null);
120
134
 
121
135
  } elseif ($op->name === 'create') {
122
- $test_self->build_args($fctx, $op, $fctx->reqdata);
123
- $id = ($fctx->utility->param)($fctx, 'id');
136
+ $id = $get_id();
124
137
  if ($id === null) {
125
138
  $id = sprintf('%04x%04x%04x%04x', random_int(0, 0xFFFF), random_int(0, 0xFFFF), random_int(0, 0xFFFF), random_int(0, 0xFFFF));
126
139
  }
127
140
 
128
- $ent = \Voxgig\Struct\Struct::clone($fctx->reqdata);
129
- if (is_array($ent)) {
130
- $ent['id'] = $id;
131
- if (is_string($id)) {
132
- $entmap[$id] = $ent;
133
- }
134
- \Voxgig\Struct\Struct::delprop($ent, '$KEY');
135
- $out = \Voxgig\Struct\Struct::clone($ent);
136
- return $respond(200, $out, null);
137
- }
138
- return $respond(200, $ent, null);
141
+ $ent = is_array($fctx->reqdata) ? $fctx->reqdata : [];
142
+ $ent['id'] = $id;
143
+ $entmap[$id] = $ent;
144
+ $entity->data[$entname] = $entmap;
145
+ $out = \Voxgig\Struct\Struct::clone($ent);
146
+ if (is_array($out)) { unset($out['$KEY']); }
147
+ return $respond(200, $out, null);
139
148
 
140
149
  } else {
141
150
  return $respond(404, null, ['statusText' => 'Unknown operation']);
@@ -144,50 +153,4 @@ class ProjectNameTestFeature extends ProjectNameBaseFeature
144
153
 
145
154
  $ctx->utility->fetcher = $test_fetcher;
146
155
  }
147
-
148
- public function build_args(ProjectNameContext $ctx, ProjectNameOperation $op, mixed $args): array
149
- {
150
- $opname = $op->name;
151
- $entname = (is_object($ctx->entity) && method_exists($ctx->entity, 'get_name'))
152
- ? $ctx->entity->get_name()
153
- : '_';
154
- $points = \Voxgig\Struct\Struct::getpath($ctx->config, "entity.{$entname}.op.{$opname}.points");
155
- $point = \Voxgig\Struct\Struct::getelem($points, -1);
156
-
157
- $params_path = \Voxgig\Struct\Struct::getpath($point, 'args.params');
158
- $reqd_params = \Voxgig\Struct\Struct::select($params_path, ['reqd' => true]);
159
- $reqd = \Voxgig\Struct\Struct::transform($reqd_params, ['`$EACH`', '', '`$KEY.name`']);
160
-
161
- $qand = [];
162
- $q = ['`$AND`' => &$qand];
163
-
164
- if ($args) {
165
- $keys = \Voxgig\Struct\Struct::keysof($args);
166
- if ($keys) {
167
- foreach ($keys as $key) {
168
- $is_id = ($key === 'id');
169
- $selected = \Voxgig\Struct\Struct::select($reqd, $key);
170
- $is_reqd = !\Voxgig\Struct\Struct::isempty($selected);
171
-
172
- if ($is_id || $is_reqd) {
173
- $v = ($ctx->utility->param)($ctx, $key);
174
- $ka = $op->alias_map ? \Voxgig\Struct\Struct::getprop($op->alias_map, $key) : null;
175
-
176
- $qor = [[$key => $v]];
177
- if (is_string($ka)) {
178
- $qor[] = [$ka => $v];
179
- }
180
-
181
- $qand[] = ['`$OR`' => $qor];
182
- }
183
- }
184
- }
185
- }
186
-
187
- if ($ctx->ctrl->explain) {
188
- $ctx->ctrl->explain['test'] = ['query' => $q];
189
- }
190
-
191
- return $q;
192
- }
193
156
  }