@voxgig/sdkgen 4.52.0 → 4.53.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 (488) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/check.js +15 -0
  3. package/dist/action/check.js.map +1 -1
  4. package/dist/action/doctor.js +1 -1
  5. package/dist/action/doctor.js.map +1 -1
  6. package/dist/action/resolve.js +13 -3
  7. package/dist/action/resolve.js.map +1 -1
  8. package/dist/cmp/Deploy.js +19 -7
  9. package/dist/cmp/Deploy.js.map +1 -1
  10. package/dist/cmp/License.d.ts +3 -1
  11. package/dist/cmp/License.js +6 -1
  12. package/dist/cmp/License.js.map +1 -1
  13. package/dist/helpers/clientOptions.js +1 -0
  14. package/dist/helpers/clientOptions.js.map +1 -1
  15. package/dist/helpers/definitionPlan.js +2 -2
  16. package/dist/helpers/definitionPlan.js.map +1 -1
  17. package/dist/helpers/doccheck.d.ts +9 -2
  18. package/dist/helpers/doccheck.js +20 -9
  19. package/dist/helpers/doccheck.js.map +1 -1
  20. package/dist/helpers/modelcheck.d.ts +7 -2
  21. package/dist/helpers/modelcheck.js +51 -0
  22. package/dist/helpers/modelcheck.js.map +1 -1
  23. package/dist/helpers/naming.js +1 -1
  24. package/dist/helpers/naming.js.map +1 -1
  25. package/dist/helpers/opShape.js +9 -3
  26. package/dist/helpers/opShape.js.map +1 -1
  27. package/dist/helpers/packageMeta.js +5 -7
  28. package/dist/helpers/packageMeta.js.map +1 -1
  29. package/dist/helpers/targetrun.d.ts +22 -0
  30. package/dist/helpers/targetrun.js +180 -0
  31. package/dist/helpers/targetrun.js.map +1 -0
  32. package/dist/helpers/testPolicy.d.ts +2 -1
  33. package/dist/helpers/testPolicy.js +13 -2
  34. package/dist/helpers/testPolicy.js.map +1 -1
  35. package/dist/sdkgen.d.ts +3 -3
  36. package/dist/sdkgen.js +34 -13
  37. package/dist/sdkgen.js.map +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/dist/utility.d.ts +2 -1
  40. package/dist/utility.js +20 -0
  41. package/dist/utility.js.map +1 -1
  42. package/model/sdkgen.aontu +6 -0
  43. package/package.json +1 -1
  44. package/project/.sdk/model/target/go-mcp.aontu +1 -1
  45. package/project/.sdk/model/target/py-data.aontu +1 -1
  46. package/project/.sdk/model/target/py.aontu +0 -5
  47. package/project/.sdk/model/target/rust.aontu +5 -0
  48. package/project/.sdk/src/cmp/c/Main_c.ts +3 -1
  49. package/project/.sdk/src/cmp/c/PrepareAuth_c.ts +40 -2
  50. package/project/.sdk/src/cmp/c/ReadmeHowto_c.ts +10 -5
  51. package/project/.sdk/src/cmp/clojure/Main_clojure.ts +3 -1
  52. package/project/.sdk/src/cmp/clojure/PrepareAuth_clojure.ts +15 -2
  53. package/project/.sdk/src/cmp/cpp/Main_cpp.ts +3 -1
  54. package/project/.sdk/src/cmp/cpp/PrepareAuth_cpp.ts +12 -2
  55. package/project/.sdk/src/cmp/csharp/Main_csharp.ts +3 -1
  56. package/project/.sdk/src/cmp/csharp/PrepareAuth_csharp.ts +19 -0
  57. package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +4 -3
  58. package/project/.sdk/src/cmp/csharp/fragment/SdkError.fragment.cs +9 -0
  59. package/project/.sdk/src/cmp/elixir/Main_elixir.ts +3 -1
  60. package/project/.sdk/src/cmp/elixir/PrepareAuth_elixir.ts +28 -4
  61. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +1 -1
  62. package/project/.sdk/src/cmp/go/EntityTypes_go.ts +2 -1
  63. package/project/.sdk/src/cmp/go/Main_go.ts +3 -1
  64. package/project/.sdk/src/cmp/go/PrepareAuth_go.ts +17 -1
  65. package/project/.sdk/src/cmp/go/ReadmeExamplesTest_go.ts +11 -6
  66. package/project/.sdk/src/cmp/go/TestDirect_go.ts +4 -6
  67. package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +45 -15
  68. package/project/.sdk/src/cmp/go-mcp/Main_go-mcp.ts +46 -11
  69. package/project/.sdk/src/cmp/go-mcp/fragment/tools.fragment.go +9 -0
  70. package/project/.sdk/src/cmp/java/Main_java.ts +3 -1
  71. package/project/.sdk/src/cmp/java/PrepareAuth_java.ts +17 -1
  72. package/project/.sdk/src/cmp/java/TestClean_java.ts +1 -1
  73. package/project/.sdk/src/cmp/java/TestDirect_java.ts +4 -3
  74. package/project/.sdk/src/cmp/js/Main_js.ts +2 -0
  75. package/project/.sdk/src/cmp/js/PrepareAuth_js.ts +22 -2
  76. package/project/.sdk/src/cmp/js/TestClean_js.ts +4 -2
  77. package/project/.sdk/src/cmp/js/TestDirect_js.ts +4 -7
  78. package/project/.sdk/src/cmp/kotlin/Main_kotlin.ts +3 -1
  79. package/project/.sdk/src/cmp/kotlin/PrepareAuth_kotlin.ts +11 -0
  80. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +1 -1
  81. package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +4 -3
  82. package/project/.sdk/src/cmp/lua/Main_lua.ts +2 -1
  83. package/project/.sdk/src/cmp/lua/PrepareAuth_lua.ts +18 -2
  84. package/project/.sdk/src/cmp/lua/ReadmeExamplesTest_lua.ts +12 -3
  85. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +3 -2
  86. package/project/.sdk/src/cmp/ocaml/Main_ocaml.ts +3 -1
  87. package/project/.sdk/src/cmp/ocaml/PrepareAuth_ocaml.ts +24 -0
  88. package/project/.sdk/src/cmp/perl/Main_perl.ts +2 -1
  89. package/project/.sdk/src/cmp/perl/PrepareAuth_perl.ts +12 -2
  90. package/project/.sdk/src/cmp/perl/ReadmeExamplesTest_perl.ts +8 -2
  91. package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +3 -2
  92. package/project/.sdk/src/cmp/php/Main_php.ts +3 -1
  93. package/project/.sdk/src/cmp/php/PrepareAuth_php.ts +28 -2
  94. package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +1 -1
  95. package/project/.sdk/src/cmp/php/ReadmeExamplesTest_php.ts +12 -3
  96. package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +1 -1
  97. package/project/.sdk/src/cmp/php/TestDirect_php.ts +3 -2
  98. package/project/.sdk/src/cmp/py/Main_py.ts +2 -1
  99. package/project/.sdk/src/cmp/py/Package_py.ts +6 -2
  100. package/project/.sdk/src/cmp/py/PrepareAuth_py.ts +12 -0
  101. package/project/.sdk/src/cmp/py/ReadmeInstall_py.ts +4 -0
  102. package/project/.sdk/src/cmp/py/TestDirect_py.ts +3 -2
  103. package/project/.sdk/src/cmp/py-data/Main_py-data.ts +4 -3
  104. package/project/.sdk/src/cmp/rb/EntityTypes_rb.ts +13 -10
  105. package/project/.sdk/src/cmp/rb/MainEntity_rb.ts +1 -1
  106. package/project/.sdk/src/cmp/rb/Main_rb.ts +2 -1
  107. package/project/.sdk/src/cmp/rb/PrepareAuth_rb.ts +23 -10
  108. package/project/.sdk/src/cmp/rb/ReadmeExamplesTest_rb.ts +14 -8
  109. package/project/.sdk/src/cmp/rb/ReadmeExplanation_rb.ts +5 -0
  110. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +3 -2
  111. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +1 -1
  112. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +276 -274
  113. package/project/.sdk/src/cmp/rb/fragment/EntityCreateOp.fragment.rb +1 -1
  114. package/project/.sdk/src/cmp/rb/fragment/EntityLoadOp.fragment.rb +1 -1
  115. package/project/.sdk/src/cmp/rb/fragment/EntityPatchOp.fragment.rb +1 -1
  116. package/project/.sdk/src/cmp/rb/fragment/EntityRemoveOp.fragment.rb +1 -1
  117. package/project/.sdk/src/cmp/rb/fragment/EntityUpdateOp.fragment.rb +1 -1
  118. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +30 -30
  119. package/project/.sdk/src/cmp/rust/Main_rust.ts +3 -1
  120. package/project/.sdk/src/cmp/rust/PrepareAuth_rust.ts +19 -1
  121. package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +3 -2
  122. package/project/.sdk/src/cmp/rust/fragment/SdkError.fragment.rs +16 -1
  123. package/project/.sdk/src/cmp/scala/Main_scala.ts +3 -0
  124. package/project/.sdk/src/cmp/scala/PrepareAuth_scala.ts +14 -0
  125. package/project/.sdk/src/cmp/swift/Main_swift.ts +3 -1
  126. package/project/.sdk/src/cmp/swift/PrepareAuth_swift.ts +13 -0
  127. package/project/.sdk/src/cmp/ts/Main_ts.ts +2 -0
  128. package/project/.sdk/src/cmp/ts/PrepareAuth_ts.ts +20 -1
  129. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +4 -2
  130. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +4 -7
  131. package/project/.sdk/src/cmp/zig/Main_zig.ts +3 -0
  132. package/project/.sdk/src/cmp/zig/PrepareAuth_zig.ts +23 -0
  133. package/project/.sdk/src/cmp/zig/fragment/Root.fragment.zig +2 -0
  134. package/project/.sdk/tm/c/core/context.c +4 -0
  135. package/project/.sdk/tm/c/core/control.c +19 -0
  136. package/project/.sdk/tm/c/core/result.c +3 -0
  137. package/project/.sdk/tm/c/core/sdk.h +17 -0
  138. package/project/.sdk/tm/c/feature/netsim.c +20 -5
  139. package/project/.sdk/tm/c/feature/ratelimit.c +7 -6
  140. package/project/.sdk/tm/c/feature/retry.c +5 -2
  141. package/project/.sdk/tm/c/feature/support.c +17 -0
  142. package/project/.sdk/tm/c/feature/test.c +16 -4
  143. package/project/.sdk/tm/c/tests/feature_harness.h +1 -0
  144. package/project/.sdk/tm/c/tests/feature_test.c +69 -0
  145. package/project/.sdk/tm/c/utility/clean.c +6 -3
  146. package/project/.sdk/tm/c/utility/http.c +20 -9
  147. package/project/.sdk/tm/c/utility/make_fetch_def.c +3 -0
  148. package/project/.sdk/tm/c/utility/make_point.c +43 -0
  149. package/project/.sdk/tm/c/utility/make_request.c +14 -1
  150. package/project/.sdk/tm/c/utility/make_spec.c +32 -0
  151. package/project/.sdk/tm/c/utility/media.c +31 -0
  152. package/project/.sdk/tm/c/utility/result_body.c +3 -0
  153. package/project/.sdk/tm/c/utility/tls/none.c +2 -2
  154. package/project/.sdk/tm/c/utility/tls/openssl.c +29 -4
  155. package/project/.sdk/tm/c/utility/tls/tls.h +4 -2
  156. package/project/.sdk/tm/clojure/src/sdk/core.clj +163 -20
  157. package/project/.sdk/tm/clojure/src/sdk/features.clj +40 -17
  158. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +32 -0
  159. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -1
  160. package/project/.sdk/tm/cpp/core/types.hpp +34 -0
  161. package/project/.sdk/tm/cpp/feature/netsim.hpp +9 -8
  162. package/project/.sdk/tm/cpp/feature/options.hpp +22 -0
  163. package/project/.sdk/tm/cpp/feature/ratelimit.hpp +3 -8
  164. package/project/.sdk/tm/cpp/feature/retry.hpp +6 -5
  165. package/project/.sdk/tm/cpp/feature/test.hpp +8 -7
  166. package/project/.sdk/tm/cpp/feature/timeout.hpp +19 -1
  167. package/project/.sdk/tm/cpp/test/feature_test.cpp +70 -0
  168. package/project/.sdk/tm/cpp/test/harness.hpp +1 -0
  169. package/project/.sdk/tm/cpp/utility/pipeline.hpp +101 -2
  170. package/project/.sdk/tm/csharp/core/Context.cs +8 -0
  171. package/project/.sdk/tm/csharp/core/Control.cs +6 -0
  172. package/project/.sdk/tm/csharp/core/Result.cs +3 -0
  173. package/project/.sdk/tm/csharp/feature/FeatureOptions.cs +37 -0
  174. package/project/.sdk/tm/csharp/feature/NetsimFeature.cs +8 -9
  175. package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +4 -10
  176. package/project/.sdk/tm/csharp/feature/RetryFeature.cs +5 -6
  177. package/project/.sdk/tm/csharp/feature/TestFeature.cs +7 -8
  178. package/project/.sdk/tm/csharp/feature/TimeoutFeature.cs +8 -2
  179. package/project/.sdk/tm/csharp/test/FeatureHarness.cs +4 -0
  180. package/project/.sdk/tm/csharp/test/FeatureTest.cs +68 -0
  181. package/project/.sdk/tm/csharp/utility/Clean.cs +1 -1
  182. package/project/.sdk/tm/csharp/utility/Fetcher.cs +101 -15
  183. package/project/.sdk/tm/csharp/utility/MakeError.cs +8 -1
  184. package/project/.sdk/tm/csharp/utility/MakeFetchDef.cs +5 -0
  185. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +44 -0
  186. package/project/.sdk/tm/csharp/utility/MakePoint.cs +24 -0
  187. package/project/.sdk/tm/csharp/utility/MakeRequest.cs +11 -1
  188. package/project/.sdk/tm/csharp/utility/MakeSpec.cs +18 -0
  189. package/project/.sdk/tm/csharp/utility/Media.cs +29 -0
  190. package/project/.sdk/tm/csharp/utility/ResultBody.cs +4 -0
  191. package/project/.sdk/tm/elixir/lib/projectname/context.ex +4 -0
  192. package/project/.sdk/tm/elixir/lib/projectname/core.ex +6 -1
  193. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +1 -1
  194. package/project/.sdk/tm/elixir/lib/projectname/feature/netsim.ex +13 -6
  195. package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +5 -6
  196. package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +6 -3
  197. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +7 -1
  198. package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +7 -10
  199. package/project/.sdk/tm/elixir/lib/projectname/feature.ex +36 -0
  200. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +307 -11
  201. package/project/.sdk/tm/elixir/test/feature_test.exs +46 -0
  202. package/project/.sdk/tm/elixir/test/support/feature_harness.ex +2 -0
  203. package/project/.sdk/tm/go/core/context.go +7 -0
  204. package/project/.sdk/tm/go/core/control.go +6 -0
  205. package/project/.sdk/tm/go/core/error.go +6 -0
  206. package/project/.sdk/tm/go/core/result.go +2 -0
  207. package/project/.sdk/tm/go/feature/feature_options.go +39 -0
  208. package/project/.sdk/tm/go/feature/netsim_feature.go +17 -10
  209. package/project/.sdk/tm/go/feature/ratelimit_feature.go +6 -5
  210. package/project/.sdk/tm/go/feature/retry_feature.go +5 -9
  211. package/project/.sdk/tm/go/feature/test_feature.go +14 -9
  212. package/project/.sdk/tm/go/feature/timeout_feature.go +24 -3
  213. package/project/.sdk/tm/go/test/feature_corpus_test.go +41 -3
  214. package/project/.sdk/tm/go/utility/clean.go +6 -2
  215. package/project/.sdk/tm/go/utility/fetcher.go +151 -12
  216. package/project/.sdk/tm/go/utility/make_error.go +8 -0
  217. package/project/.sdk/tm/go/utility/make_fetch_def.go +4 -0
  218. package/project/.sdk/tm/go/utility/make_point.go +40 -4
  219. package/project/.sdk/tm/go/utility/make_request.go +21 -3
  220. package/project/.sdk/tm/go/utility/make_spec.go +24 -0
  221. package/project/.sdk/tm/go/utility/media.go +28 -0
  222. package/project/.sdk/tm/go/utility/register.go +22 -2
  223. package/project/.sdk/tm/go/utility/result_body.go +5 -0
  224. package/project/.sdk/tm/java/core/Context.java +8 -0
  225. package/project/.sdk/tm/java/core/Control.java +9 -0
  226. package/project/.sdk/tm/java/core/Result.java +4 -0
  227. package/project/.sdk/tm/java/feature/FeatureOptions.java +44 -0
  228. package/project/.sdk/tm/java/feature/NetsimFeature.java +8 -9
  229. package/project/.sdk/tm/java/feature/RatelimitFeature.java +3 -8
  230. package/project/.sdk/tm/java/feature/RetryFeature.java +5 -6
  231. package/project/.sdk/tm/java/feature/TestFeature.java +7 -8
  232. package/project/.sdk/tm/java/feature/TimeoutFeature.java +27 -1
  233. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +48 -3
  234. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +1 -1
  235. package/project/.sdk/tm/java/utility/CallerFetchError.java +41 -0
  236. package/project/.sdk/tm/java/utility/Clean.java +2 -1
  237. package/project/.sdk/tm/java/utility/Fetcher.java +145 -7
  238. package/project/.sdk/tm/java/utility/MakeError.java +5 -0
  239. package/project/.sdk/tm/java/utility/MakeFetchDef.java +3 -0
  240. package/project/.sdk/tm/java/utility/MakePoint.java +24 -0
  241. package/project/.sdk/tm/java/utility/MakeRequest.java +9 -1
  242. package/project/.sdk/tm/java/utility/MakeSpec.java +13 -0
  243. package/project/.sdk/tm/java/utility/Media.java +31 -0
  244. package/project/.sdk/tm/java/utility/Register.java +4 -1
  245. package/project/.sdk/tm/java/utility/ResultBody.java +3 -0
  246. package/project/.sdk/tm/js/src/Control.js +1 -0
  247. package/project/.sdk/tm/js/src/Response.js +16 -5
  248. package/project/.sdk/tm/js/src/Result.js +1 -0
  249. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  250. package/project/.sdk/tm/js/src/utility/FetcherUtility.js +156 -4
  251. package/project/.sdk/tm/js/src/utility/MakePointUtility.js +25 -2
  252. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +15 -0
  253. package/project/.sdk/tm/js/src/utility/MediaUtility.js +18 -0
  254. package/project/.sdk/tm/js/src/utility/ResultBodyUtility.js +17 -0
  255. package/project/.sdk/tm/js/test/feature/Corpus.test.js +31 -5
  256. package/project/.sdk/tm/js/test/live-runner.js +14 -4
  257. package/project/.sdk/tm/kotlin/core/Context.kt +5 -0
  258. package/project/.sdk/tm/kotlin/core/Control.kt +7 -0
  259. package/project/.sdk/tm/kotlin/core/Result.kt +3 -0
  260. package/project/.sdk/tm/kotlin/feature/FeatureOptions.kt +39 -0
  261. package/project/.sdk/tm/kotlin/feature/NetsimFeature.kt +8 -9
  262. package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +3 -8
  263. package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +5 -6
  264. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +7 -8
  265. package/project/.sdk/tm/kotlin/feature/TimeoutFeature.kt +25 -1
  266. package/project/.sdk/tm/kotlin/test/FeatureHarness.kt +1 -0
  267. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +58 -0
  268. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +1 -1
  269. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +2 -1
  270. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +117 -8
  271. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +26 -1
  272. package/project/.sdk/tm/kotlin/utility/MakePoint.kt +22 -0
  273. package/project/.sdk/tm/kotlin/utility/MakeReqRes.kt +8 -1
  274. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +11 -0
  275. package/project/.sdk/tm/kotlin/utility/Media.kt +20 -0
  276. package/project/.sdk/tm/kotlin/utility/ResultTransform.kt +1 -0
  277. package/project/.sdk/tm/lua/core/context.lua +6 -0
  278. package/project/.sdk/tm/lua/core/control.lua +9 -0
  279. package/project/.sdk/tm/lua/core/result.lua +2 -0
  280. package/project/.sdk/tm/lua/feature/base_feature.lua +24 -0
  281. package/project/.sdk/tm/lua/feature/netsim_feature.lua +17 -17
  282. package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +8 -16
  283. package/project/.sdk/tm/lua/feature/retry_feature.lua +8 -14
  284. package/project/.sdk/tm/lua/feature/test_feature.lua +14 -15
  285. package/project/.sdk/tm/lua/test/feature_test.lua +47 -0
  286. package/project/.sdk/tm/lua/utility/clean.lua +2 -1
  287. package/project/.sdk/tm/lua/utility/fetcher.lua +8 -3
  288. package/project/.sdk/tm/lua/utility/make_fetch_def.lua +4 -0
  289. package/project/.sdk/tm/lua/utility/make_point.lua +24 -0
  290. package/project/.sdk/tm/lua/utility/make_request.lua +13 -2
  291. package/project/.sdk/tm/lua/utility/make_spec.lua +21 -0
  292. package/project/.sdk/tm/lua/utility/media.lua +33 -0
  293. package/project/.sdk/tm/lua/utility/result_body.lua +3 -0
  294. package/project/.sdk/tm/lua/utility/tls.lua +66 -4
  295. package/project/.sdk/tm/ocaml/sdk_features.ml +35 -18
  296. package/project/.sdk/tm/ocaml/sdk_helpers.ml +3 -0
  297. package/project/.sdk/tm/ocaml/sdk_runtime.ml +66 -5
  298. package/project/.sdk/tm/ocaml/sdk_types.ml +4 -0
  299. package/project/.sdk/tm/ocaml/test/harness.ml +1 -0
  300. package/project/.sdk/tm/ocaml/test/t_feature.ml +28 -0
  301. package/project/.sdk/tm/perl/core/context.pm +3 -0
  302. package/project/.sdk/tm/perl/core/control.pm +4 -0
  303. package/project/.sdk/tm/perl/core/helpers.pm +26 -0
  304. package/project/.sdk/tm/perl/core/result.pm +2 -0
  305. package/project/.sdk/tm/perl/feature/netsim_feature.pm +12 -15
  306. package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +7 -15
  307. package/project/.sdk/tm/perl/feature/retry_feature.pm +5 -12
  308. package/project/.sdk/tm/perl/feature/test_feature.pm +10 -12
  309. package/project/.sdk/tm/perl/feature/timeout_feature.pm +5 -3
  310. package/project/.sdk/tm/perl/t/feature_corpus.t +23 -2
  311. package/project/.sdk/tm/perl/utility/clean.pm +2 -1
  312. package/project/.sdk/tm/perl/utility/fetcher.pm +66 -2
  313. package/project/.sdk/tm/perl/utility/make_fetch_def.pm +1 -0
  314. package/project/.sdk/tm/perl/utility/make_point.pm +20 -0
  315. package/project/.sdk/tm/perl/utility/make_request.pm +10 -2
  316. package/project/.sdk/tm/perl/utility/make_spec.pm +17 -0
  317. package/project/.sdk/tm/perl/utility/media.pm +25 -0
  318. package/project/.sdk/tm/perl/utility/result_body.pm +3 -0
  319. package/project/.sdk/tm/php/core/Context.php +6 -0
  320. package/project/.sdk/tm/php/core/Control.php +12 -0
  321. package/project/.sdk/tm/php/core/Result.php +4 -0
  322. package/project/.sdk/tm/php/feature/BaseFeature.php +31 -0
  323. package/project/.sdk/tm/php/feature/NetsimFeature.php +17 -15
  324. package/project/.sdk/tm/php/feature/RatelimitFeature.php +8 -14
  325. package/project/.sdk/tm/php/feature/RetryFeature.php +6 -12
  326. package/project/.sdk/tm/php/feature/TestFeature.php +14 -14
  327. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +27 -3
  328. package/project/.sdk/tm/php/test/FeatureTest.php +3 -1
  329. package/project/.sdk/tm/php/test/StructUtilityTest.php +5 -0
  330. package/project/.sdk/tm/php/utility/Clean.php +2 -1
  331. package/project/.sdk/tm/php/utility/Fetcher.php +111 -5
  332. package/project/.sdk/tm/php/utility/MakeFetchDef.php +3 -0
  333. package/project/.sdk/tm/php/utility/MakePoint.php +23 -0
  334. package/project/.sdk/tm/php/utility/MakeRequest.php +11 -2
  335. package/project/.sdk/tm/php/utility/MakeSpec.php +21 -0
  336. package/project/.sdk/tm/php/utility/Media.php +28 -0
  337. package/project/.sdk/tm/php/utility/ResultBody.php +3 -0
  338. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  339. package/project/.sdk/tm/py/pkg/core/control.py +9 -0
  340. package/project/.sdk/tm/py/pkg/core/result.py +2 -0
  341. package/project/.sdk/tm/py/pkg/feature/base_feature.py +23 -0
  342. package/project/.sdk/tm/py/pkg/feature/netsim_feature.py +13 -14
  343. package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +8 -12
  344. package/project/.sdk/tm/py/pkg/feature/retry_feature.py +8 -10
  345. package/project/.sdk/tm/py/pkg/feature/test_feature.py +11 -13
  346. package/project/.sdk/tm/py/pkg/utility/clean.py +2 -1
  347. package/project/.sdk/tm/py/pkg/utility/fetcher.py +451 -95
  348. package/project/.sdk/tm/py/pkg/utility/make_fetch_def.py +3 -0
  349. package/project/.sdk/tm/py/pkg/utility/make_point.py +24 -3
  350. package/project/.sdk/tm/py/pkg/utility/make_request.py +11 -2
  351. package/project/.sdk/tm/py/pkg/utility/make_spec.py +16 -0
  352. package/project/.sdk/tm/py/pkg/utility/media.py +25 -0
  353. package/project/.sdk/tm/py/pkg/utility/requests_fetch.py +93 -0
  354. package/project/.sdk/tm/py/pkg/utility/result_body.py +2 -0
  355. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +1 -24
  356. package/project/.sdk/tm/py/test/test_feature_corpus.py +26 -3
  357. package/project/.sdk/tm/py/test/test_primary_utility.py +242 -48
  358. package/project/.sdk/tm/rb/core/context.rb +5 -3
  359. package/project/.sdk/tm/rb/core/control.rb +9 -1
  360. package/project/.sdk/tm/rb/core/operation.rb +5 -5
  361. package/project/.sdk/tm/rb/core/response.rb +7 -7
  362. package/project/.sdk/tm/rb/core/result.rb +11 -9
  363. package/project/.sdk/tm/rb/feature/base_feature.rb +22 -0
  364. package/project/.sdk/tm/rb/feature/cost_feature.rb +1 -1
  365. package/project/.sdk/tm/rb/feature/netsim_feature.rb +7 -13
  366. package/project/.sdk/tm/rb/feature/paging_feature.rb +7 -7
  367. package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +5 -11
  368. package/project/.sdk/tm/rb/feature/retry_feature.rb +5 -10
  369. package/project/.sdk/tm/rb/feature/secrets_feature.rb +4 -4
  370. package/project/.sdk/tm/rb/feature/test_feature.rb +46 -53
  371. package/project/.sdk/tm/rb/feature/validate_feature.rb +2 -2
  372. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +1 -1
  373. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +23 -3
  374. package/project/.sdk/tm/rb/test/feature_test.rb +2 -2
  375. package/project/.sdk/tm/rb/test/omni.rb +7 -7
  376. package/project/.sdk/tm/rb/test/pipeline_test.rb +1 -1
  377. package/project/.sdk/tm/rb/test/runner.rb +1 -1
  378. package/project/.sdk/tm/rb/test/struct_utility_test.rb +120 -120
  379. package/project/.sdk/tm/rb/utility/clean.rb +6 -4
  380. package/project/.sdk/tm/rb/utility/feature_init.rb +2 -2
  381. package/project/.sdk/tm/rb/utility/fetcher.rb +52 -7
  382. package/project/.sdk/tm/rb/utility/graphql.rb +13 -13
  383. package/project/.sdk/tm/rb/utility/make_fetch_def.rb +1 -0
  384. package/project/.sdk/tm/rb/utility/make_options.rb +12 -12
  385. package/project/.sdk/tm/rb/utility/make_point.rb +38 -20
  386. package/project/.sdk/tm/rb/utility/make_request.rb +11 -2
  387. package/project/.sdk/tm/rb/utility/make_spec.rb +23 -6
  388. package/project/.sdk/tm/rb/utility/make_url.rb +6 -6
  389. package/project/.sdk/tm/rb/utility/media.rb +30 -11
  390. package/project/.sdk/tm/rb/utility/param.rb +18 -18
  391. package/project/.sdk/tm/rb/utility/prepare_body.rb +6 -6
  392. package/project/.sdk/tm/rb/utility/prepare_headers.rb +8 -8
  393. package/project/.sdk/tm/rb/utility/prepare_method.rb +1 -1
  394. package/project/.sdk/tm/rb/utility/prepare_params.rb +3 -3
  395. package/project/.sdk/tm/rb/utility/prepare_path.rb +2 -2
  396. package/project/.sdk/tm/rb/utility/prepare_query.rb +12 -12
  397. package/project/.sdk/tm/rb/utility/result_body.rb +1 -0
  398. package/project/.sdk/tm/rb/utility/struct/voxgig_struct.rb +31 -31
  399. package/project/.sdk/tm/rb/utility/transform_request.rb +5 -5
  400. package/project/.sdk/tm/rb/utility/transform_response.rb +3 -3
  401. package/project/.sdk/tm/rust/core/context.rs +6 -0
  402. package/project/.sdk/tm/rust/core/control.rs +11 -0
  403. package/project/.sdk/tm/rust/core/helpers.rs +4 -0
  404. package/project/.sdk/tm/rust/core/result.rs +9 -0
  405. package/project/.sdk/tm/rust/feature/netsim.rs +11 -6
  406. package/project/.sdk/tm/rust/feature/ratelimit.rs +6 -6
  407. package/project/.sdk/tm/rust/feature/retry.rs +3 -3
  408. package/project/.sdk/tm/rust/feature/support.rs +32 -1
  409. package/project/.sdk/tm/rust/feature/test.rs +10 -5
  410. package/project/.sdk/tm/rust/tests/common/mod.rs +6 -0
  411. package/project/.sdk/tm/rust/tests/feature_test.rs +83 -0
  412. package/project/.sdk/tm/rust/utility/fetcher.rs +164 -17
  413. package/project/.sdk/tm/rust/utility/make_error.rs +10 -0
  414. package/project/.sdk/tm/rust/utility/make_fetch_def.rs +7 -0
  415. package/project/.sdk/tm/rust/utility/make_point.rs +37 -0
  416. package/project/.sdk/tm/rust/utility/make_request.rs +13 -1
  417. package/project/.sdk/tm/rust/utility/make_spec.rs +27 -0
  418. package/project/.sdk/tm/rust/utility/media.rs +20 -0
  419. package/project/.sdk/tm/rust/utility/result_body.rs +3 -0
  420. package/project/.sdk/tm/scala/core/Context.scala +2 -0
  421. package/project/.sdk/tm/scala/core/Control.scala +7 -0
  422. package/project/.sdk/tm/scala/core/Result.scala +3 -0
  423. package/project/.sdk/tm/scala/feature/FeatureOptions.scala +30 -0
  424. package/project/.sdk/tm/scala/feature/NetsimFeature.scala +9 -8
  425. package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +6 -6
  426. package/project/.sdk/tm/scala/feature/RetryFeature.scala +6 -5
  427. package/project/.sdk/tm/scala/feature/TestFeature.scala +8 -7
  428. package/project/.sdk/tm/scala/feature/TimeoutFeature.scala +19 -1
  429. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +31 -2
  430. package/project/.sdk/tm/scala/utility/Fetcher.scala +99 -8
  431. package/project/.sdk/tm/scala/utility/Make.scala +67 -3
  432. package/project/.sdk/tm/scala/utility/MakeSpec.scala +14 -0
  433. package/project/.sdk/tm/scala/utility/Media.scala +27 -0
  434. package/project/.sdk/tm/scala/utility/Misc.scala +2 -1
  435. package/project/.sdk/tm/scala/utility/Results.scala +3 -0
  436. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +2 -0
  437. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +7 -0
  438. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Result.swift +3 -0
  439. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/FeatureOptions.swift +32 -0
  440. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/NetsimFeature.swift +8 -9
  441. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +3 -8
  442. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +5 -6
  443. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +8 -7
  444. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TimeoutFeature.swift +21 -1
  445. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +149 -4
  446. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +42 -1
  447. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Media.swift +17 -0
  448. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +2 -1
  449. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +54 -0
  450. package/project/.sdk/tm/ts/src/Control.ts +3 -0
  451. package/project/.sdk/tm/ts/src/Response.ts +17 -5
  452. package/project/.sdk/tm/ts/src/Result.ts +3 -0
  453. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  454. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +156 -4
  455. package/project/.sdk/tm/ts/src/utility/MakePointUtility.ts +24 -2
  456. package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +15 -0
  457. package/project/.sdk/tm/ts/src/utility/MediaUtility.ts +18 -0
  458. package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +17 -0
  459. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +31 -5
  460. package/project/.sdk/tm/ts/test/live-runner.ts +15 -4
  461. package/project/.sdk/tm/zig/core/context.zig +2 -0
  462. package/project/.sdk/tm/zig/core/control.zig +27 -0
  463. package/project/.sdk/tm/zig/core/result.zig +4 -0
  464. package/project/.sdk/tm/zig/core/utility.zig +78 -2
  465. package/project/.sdk/tm/zig/feature/netsim.zig +5 -5
  466. package/project/.sdk/tm/zig/feature/ratelimit.zig +4 -4
  467. package/project/.sdk/tm/zig/feature/retry.zig +4 -4
  468. package/project/.sdk/tm/zig/feature/support.zig +24 -0
  469. package/project/.sdk/tm/zig/feature/test.zig +4 -4
  470. package/project/.sdk/tm/zig/test/feature_test.zig +62 -0
  471. package/project/.sdk/tm/zig/test/fh.zig +1 -0
  472. package/project/sdkgen-package.json +1 -1
  473. package/src/action/check.ts +20 -0
  474. package/src/action/doctor.ts +1 -1
  475. package/src/action/resolve.ts +15 -3
  476. package/src/cmp/Deploy.ts +22 -7
  477. package/src/cmp/License.ts +7 -0
  478. package/src/helpers/clientOptions.ts +1 -0
  479. package/src/helpers/definitionPlan.ts +3 -3
  480. package/src/helpers/doccheck.ts +34 -11
  481. package/src/helpers/modelcheck.ts +67 -0
  482. package/src/helpers/naming.ts +1 -1
  483. package/src/helpers/opShape.ts +12 -3
  484. package/src/helpers/packageMeta.ts +5 -7
  485. package/src/helpers/targetrun.ts +214 -0
  486. package/src/helpers/testPolicy.ts +14 -4
  487. package/src/sdkgen.ts +33 -11
  488. package/src/utility.ts +24 -0
@@ -228,18 +228,18 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
228
228
  val call = this.netcalls
229
229
 
230
230
  if (FeatureOptions.foptBool(net, "offline", false)) {
231
- netSleep(net, pickLatency(net))
231
+ netSleep(ctx, fetchdef, net, pickLatency(net))
232
232
  throw ctx.makeError(
233
233
  "netsim_offline",
234
234
  "Simulated network offline (URL was: \"$url\")",
235
235
  )
236
236
  }
237
237
  if (call <= FeatureOptions.foptInt(net, "errorTimes", 0)) {
238
- netSleep(net, pickLatency(net))
238
+ netSleep(ctx, fetchdef, net, pickLatency(net))
239
239
  throw ctx.makeError("netsim_conn", "Simulated connection error (call $call)")
240
240
  }
241
241
  if (call <= FeatureOptions.foptInt(net, "failTimes", 0)) {
242
- netSleep(net, pickLatency(net))
242
+ netSleep(ctx, fetchdef, net, pickLatency(net))
243
243
  val status = FeatureOptions.foptInt(net, "failStatus", 503)
244
244
  val out = linkedMapOf<String, Any?>()
245
245
  out["status"] = status
@@ -249,7 +249,7 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
249
249
  out["headers"] = linkedMapOf<String, Any?>()
250
250
  out
251
251
  } else {
252
- netSleep(net, pickLatency(net))
252
+ netSleep(ctx, fetchdef, net, pickLatency(net))
253
253
  inner(ctx, url, fetchdef)
254
254
  }
255
255
  }
@@ -273,11 +273,10 @@ class TestFeature : BaseFeature("test", "0.0.1", true) {
273
273
  return if (fixed < 0) 0 else fixed
274
274
  }
275
275
 
276
- private fun netSleep(net: MutableMap<String, Any?>, ms: Int) {
277
- if (ms <= 0) {
278
- return
276
+ private fun netSleep(ctx: Context, fetchdef: MutableMap<String, Any?>, net: MutableMap<String, Any?>, ms: Int) {
277
+ if (FeatureOptions.fwait(net, fetchdef, ms)) {
278
+ throw ctx.makeError("request_aborted", "request aborted")
279
279
  }
280
- FeatureOptions.foptSleep(net).accept(ms)
281
280
  }
282
281
 
283
282
  private fun buildArgs(ctx: Context, op: Operation, args: MutableMap<String, Any?>?): Any? {
@@ -61,7 +61,7 @@ class TimeoutFeature : BaseFeature("timeout", "0.0.1", true) {
61
61
  try {
62
62
  val remaining = maxOf(0L, deadline - (now.asLong - start))
63
63
  val out = try {
64
- fut.get(remaining, TimeUnit.MILLISECONDS)
64
+ await(ctx, fut, remaining, FeatureOptions.fsignal(fetchdef))
65
65
  } catch (e: ExecutionException) {
66
66
  if (deadline < arrived.get() - start) {
67
67
  throw timeout(ctx, deadline)
@@ -80,6 +80,30 @@ class TimeoutFeature : BaseFeature("timeout", "0.0.1", true) {
80
80
  }
81
81
  }
82
82
 
83
+ // The response, or the caller's cancel, whichever comes first.
84
+ private fun await(ctx: Context, fut: CompletableFuture<Any?>, ms: Long,
85
+ signal: java.util.concurrent.Future<*>?): Any? {
86
+ if (signal == null) {
87
+ return fut.get(ms, TimeUnit.MILLISECONDS)
88
+ }
89
+ val end = System.nanoTime() + ms * 1_000_000L
90
+ while (true) {
91
+ if (signal.isDone) {
92
+ fut.cancel(true)
93
+ throw ctx.makeError("request_aborted", "request aborted")
94
+ }
95
+ val left = (end - System.nanoTime()) / 1_000_000L
96
+ if (left <= 0) {
97
+ throw TimeoutException()
98
+ }
99
+ try {
100
+ return fut.get(minOf(left, 10L), TimeUnit.MILLISECONDS)
101
+ } catch (e: TimeoutException) {
102
+ // Neither yet: look at the signal again.
103
+ }
104
+ }
105
+ }
106
+
83
107
  private fun unwrap(e: ExecutionException): Throwable {
84
108
  var cause: Throwable? = e.cause
85
109
  if (cause is CompletionException && cause.cause != null) {
@@ -234,6 +234,7 @@ object FeatureHarness {
234
234
  if (ctx.spec!!.body != null) {
235
235
  fetchdef["body"] = ctx.spec!!.body
236
236
  }
237
+ ctx.ctrl.signal?.let { fetchdef["signal"] = it }
237
238
 
238
239
  var response: Any? = null
239
240
  var fetchErr: RuntimeException? = null
@@ -369,6 +369,64 @@ class FeatureTest {
369
369
  assertEquals(0, f.throttled, "expected no throttling")
370
370
  }
371
371
 
372
+ // --- cancel ----------------------------------------------------------------
373
+
374
+ // A signal done soon after the call starts ends each wait at once, and the
375
+ // call fails as request_aborted.
376
+ private fun cancelling(ms: Long): MutableMap<String, Any?> {
377
+ val signal = java.util.concurrent.CompletableFuture<Any?>()
378
+ java.util.concurrent.CompletableFuture.delayedExecutor(ms, java.util.concurrent.TimeUnit.MILLISECONDS)
379
+ .execute { signal.cancel(true) }
380
+ return fhMap("signal", signal)
381
+ }
382
+
383
+ private fun assertAborted(res: FeatureHarness.FhOpResult, started: Long) {
384
+ assertFalse(res.ok, "a cancelled call succeeded")
385
+ assertEquals("request_aborted", fhErrCode(res.err))
386
+ val took = (System.nanoTime() - started) / 1_000_000L
387
+ assertTrue(took < 5000, "settled after $took ms")
388
+ }
389
+
390
+ @Test
391
+ fun cancel_endsTheRetryBackoff() {
392
+ assumeFeatures("retry")
393
+ val rec = FhRecorder()
394
+ rec.reply = { _, _ -> fhResponse(503, null, null) }
395
+ val h = fhMake(rec::fetch, fhF(RetryFeature(),
396
+ fhMap("retries", 3, "minDelay", 20000, "maxDelay", 20000, "jitter", false)))
397
+ val started = System.nanoTime()
398
+ assertAborted(h.op(fhOp("load").ctrl(cancelling(50))), started)
399
+ assertEquals(1, rec.calls.size, "expected 1 call")
400
+ }
401
+
402
+ @Test
403
+ fun cancel_endsTheNetsimLatency() {
404
+ assumeFeatures("netsim")
405
+ val h = fhMake(null, fhF(NetsimFeature(), fhMap("latency", 20000)))
406
+ val started = System.nanoTime()
407
+ assertAborted(h.op(fhOp("load").ctrl(cancelling(50))), started)
408
+ }
409
+
410
+ @Test
411
+ fun cancel_endsTheRatelimitWait() {
412
+ assumeFeatures("ratelimit")
413
+ val h = fhMake(null, fhF(RatelimitFeature(), fhMap("rate", 0.05, "burst", 1)))
414
+ assertTrue(h.op(fhOp("load")).ok, "the first call has a token")
415
+ val started = System.nanoTime()
416
+ assertAborted(h.op(fhOp("load").ctrl(cancelling(50))), started)
417
+ }
418
+
419
+ @Test
420
+ fun cancel_endsTheTimeoutWait() {
421
+ assumeFeatures("timeout")
422
+ val rec = FhRecorder()
423
+ rec.reply = { _, _ -> Thread.sleep(3000); fhResponse(200, null, null) }
424
+ val h = fhMake(rec::fetch, fhF(TimeoutFeature(), fhMap("ms", 20000)))
425
+ val started = System.nanoTime()
426
+ assertAborted(h.op(fhOp("load").ctrl(cancelling(50))), started)
427
+ assertTrue((System.nanoTime() - started) / 1_000_000L < 2000, "the timeout wait did not end")
428
+ }
429
+
372
430
  // --- cache --------------------------------------------------------------------
373
431
 
374
432
  @Test
@@ -674,7 +674,7 @@ class PrimaryUtilityTest {
674
674
  "-cp", System.getProperty("java.class.path"), PrimaryUtilityTest::class.java.name,
675
675
  )
676
676
  pb.environment()["VOXGIG_GETONLY_GUARD"] = "TRUE"
677
- pb.redirectErrorStream(true)
677
+ pb.redirectError(ProcessBuilder.Redirect.INHERIT)
678
678
  val proc = pb.start()
679
679
  val text = proc.inputStream.readAllBytes().toString(Charsets.UTF_8)
680
680
  assertEquals(0, proc.waitFor(), text)
@@ -313,7 +313,7 @@ private fun binaryBodies(ctx: Context?, cfg: CleanConfig): List<BinaryBody> {
313
313
  val response = ctx?.response
314
314
  val type = Response.headerValue(response?.headers, "content-type")
315
315
  if (response != null && Response.isBinaryResponse(ctx?.point, type)) {
316
- bodies.add(BinaryBody(listOf(response.body).filter(known).filterNotNull(),
316
+ bodies.add(BinaryBody(listOf(response.body, ctx?.result?.text).filter(known).filterNotNull(),
317
317
  type.ifEmpty { null }, false))
318
318
  }
319
319
 
@@ -643,6 +643,7 @@ fun makeError(ctx: Context, errIn: RuntimeException?): Any? {
643
643
  sdkErr.result = clean(ctx, result)
644
644
  sdkErr.spec = clean(ctx, spec)
645
645
  sdkErr.status = result.status
646
+ callerCause(ctx, err)?.let { sdkErr.initCause(it) }
646
647
 
647
648
  ctx.ctrl.err = sdkErr
648
649
 
@@ -11,27 +11,58 @@ import java.net.http.HttpClient
11
11
  import java.net.http.HttpRequest
12
12
  import java.net.http.HttpResponse
13
13
  import java.nio.charset.Charset
14
+ import java.security.GeneralSecurityException
15
+ import java.security.KeyStore
16
+ import java.security.MessageDigest
17
+ import java.security.cert.CertificateException
18
+ import java.security.cert.CertificateFactory
19
+ import java.security.cert.X509Certificate
14
20
  import java.util.concurrent.ConcurrentHashMap
15
21
  import java.util.function.BiFunction
16
22
  import java.util.function.Supplier
17
23
  import java.util.zip.GZIPInputStream
18
24
  import java.util.zip.Inflater
19
25
  import java.util.zip.InflaterInputStream
26
+ import javax.net.ssl.SSLContext
27
+ import javax.net.ssl.TrustManager
28
+ import javax.net.ssl.TrustManagerFactory
29
+ import javax.net.ssl.X509TrustManager
20
30
 
21
31
  import KOTLINPACKAGE.core.Context
22
32
  import KOTLINPACKAGE.core.SdkError
23
33
  import KOTLINPACKAGE.utility.struct.Struct
24
34
 
25
- // Clients keyed by proxy. Each HttpClient owns a connection pool and a
26
- // selector thread, so one per request reused nothing; one per key pools
27
- // across calls. None follows a redirect: followRedirects does.
35
+ // Clients keyed by proxy and TLS trust. Each HttpClient owns a connection
36
+ // pool and a selector thread, so one per request reused nothing; one per key
37
+ // pools across calls. None follows a redirect: followRedirects does.
28
38
  private val clients = ConcurrentHashMap<String, HttpClient>()
29
39
 
30
- private fun clientFor(fetchdef: MutableMap<String, Any?>): HttpClient {
40
+ // The asynchronous send, cancelled once the caller's signal is done.
41
+ private fun sendUntil(client: HttpClient, req: HttpRequest,
42
+ signal: java.util.concurrent.Future<*>): HttpResponse<String> {
43
+ val pending = client.sendAsync(req, decodedText())
44
+ while (true) {
45
+ if (signal.isDone) {
46
+ pending.cancel(true)
47
+ throw java.util.concurrent.CancellationException("request aborted")
48
+ }
49
+ try {
50
+ return pending.get(10, java.util.concurrent.TimeUnit.MILLISECONDS)
51
+ } catch (e: java.util.concurrent.TimeoutException) {
52
+ // Still in flight: look at the signal again.
53
+ } catch (e: java.util.concurrent.ExecutionException) {
54
+ throw e.cause ?: e
55
+ }
56
+ }
57
+ }
58
+
59
+ private fun clientFor(fetchdef: MutableMap<String, Any?>, trust: Pair<String, String>?): HttpClient {
31
60
  val praw = fetchdef["proxy"]
32
61
  val proxy = if (praw is String) praw else ""
62
+ val pin = trust?.first ?: ""
63
+ val ca = trust?.second ?: ""
33
64
 
34
- return clients.computeIfAbsent(proxy) {
65
+ return clients.computeIfAbsent(proxy + "\n" + pin + "\n" + ca) {
35
66
  val clientb = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER)
36
67
  if ("" != proxy) {
37
68
  try {
@@ -42,10 +73,80 @@ private fun clientFor(fetchdef: MutableMap<String, Any?>): HttpClient {
42
73
  // Unparseable proxy target: direct connection, as the go transport.
43
74
  }
44
75
  }
76
+ if (null != trust) {
77
+ clientb.sslContext(tlsContext(pin, ca))
78
+ }
45
79
  clientb.build()
46
80
  }
47
81
  }
48
82
 
83
+ // The tls option: a SHA-256 pin, bare or colon-paired, and a PEM trusted as
84
+ // the authority. Empty is unset; null for neither.
85
+ internal fun tlsTrust(ctx: Context?): Pair<String, String>? {
86
+ if (null == ctx) {
87
+ return null
88
+ }
89
+ val options = ctx.client?.optionsMap() ?: return null
90
+ val fingerprint = (Struct.getpath(options, listOf("tls", "fingerprint")) as? String)?.trim() ?: ""
91
+ val ca = (Struct.getpath(options, listOf("tls", "ca")) as? String)?.trim() ?: ""
92
+ if (fingerprint.isEmpty() && ca.isEmpty()) {
93
+ return null
94
+ }
95
+ val pin = fingerprint.lowercase().removePrefix("sha256:").replace(":", "")
96
+ if (fingerprint.isNotEmpty() && !Regex("[0-9a-f]{64}").matches(pin)) {
97
+ throw ctx.makeError("fetch_tls", "tls.fingerprint is not a SHA-256 fingerprint of 64 hex digits")
98
+ }
99
+ return Pair(if (fingerprint.isEmpty()) "" else pin, ca)
100
+ }
101
+
102
+ // Verification is replaced, never dropped: under a pin the certificate
103
+ // presented must be the pinned one, which stands in for the trust store and
104
+ // is still checked for its dates, and the JDK client checks its name as for
105
+ // any certificate. A ca is the only authority.
106
+ internal fun tlsContext(pin: String, ca: String): SSLContext {
107
+ try {
108
+ var authority: X509TrustManager? = null
109
+ if (ca.isNotEmpty()) {
110
+ val store = KeyStore.getInstance(KeyStore.getDefaultType())
111
+ store.load(null, null)
112
+ CertificateFactory.getInstance("X.509")
113
+ .generateCertificates(ByteArrayInputStream(ca.toByteArray(Charsets.US_ASCII)))
114
+ .forEachIndexed { i, cert -> store.setCertificateEntry("ca" + i, cert) }
115
+ val tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
116
+ tmf.init(store)
117
+ authority = tmf.trustManagers[0] as X509TrustManager
118
+ }
119
+ val chained = authority
120
+ val trust: X509TrustManager = if (pin.isEmpty()) chained!! else object : X509TrustManager {
121
+ override fun checkClientTrusted(chain: Array<X509Certificate>?, auth: String?) {
122
+ throw CertificateException("no client certificate is trusted")
123
+ }
124
+
125
+ override fun checkServerTrusted(chain: Array<X509Certificate>?, auth: String?) {
126
+ if (null == chain || chain.isEmpty()) {
127
+ throw CertificateException("the server presented no certificate")
128
+ }
129
+ chained?.checkServerTrusted(chain, auth)
130
+ val seen = MessageDigest.getInstance("SHA-256").digest(chain[0].encoded)
131
+ .joinToString("") { "%02x".format(it) }
132
+ if (pin != seen) {
133
+ throw CertificateException("the server's certificate is not the one tls.fingerprint names")
134
+ }
135
+ chain[0].checkValidity()
136
+ }
137
+
138
+ override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
139
+ }
140
+ val context = SSLContext.getInstance("TLS")
141
+ context.init(null, arrayOf<TrustManager>(trust), null)
142
+ return context
143
+ } catch (e: GeneralSecurityException) {
144
+ throw RuntimeException("fetch: tls: " + e.message, e)
145
+ } catch (e: IOException) {
146
+ throw RuntimeException("fetch: tls: " + e.message, e)
147
+ }
148
+ }
149
+
49
150
  internal const val GETONLY_ENV = "VOXGIG_GETONLY_GUARD"
50
151
 
51
152
  // A GET-only live run refuses any other method before it is sent. The error
@@ -97,12 +198,13 @@ internal fun followRedirects(
97
198
  // "manual" (set by the station feature's middleware under a hosts
98
199
  // policy) is answered by the 3xx, like any other response.
99
200
  val manual = "manual" == fetchdef["redirect"]
201
+ val trust = tlsTrust(ctx)
100
202
  var url = fullurl
101
203
  var def = fetchdef
102
204
 
103
205
  var hops = 0
104
206
  while (true) {
105
- val res = fetchOnce(url, def)
207
+ val res = fetchOnce(url, def, trust)
106
208
  val location = (res["headers"] as? Map<*, *>)?.get("location")
107
209
  val status = res["status"] as? Int
108
210
  if (manual || location !is String || status == null ||
@@ -183,7 +285,9 @@ fun defaultHttpFetch(fullurl: String, fetchdef: MutableMap<String, Any?>): Mutab
183
285
  followRedirects(null, fullurl, fetchdef)
184
286
 
185
287
  @Suppress("UNCHECKED_CAST")
186
- private fun fetchOnce(fullurl: String, fetchdef: MutableMap<String, Any?>): MutableMap<String, Any?> {
288
+ private fun fetchOnce(
289
+ fullurl: String, fetchdef: MutableMap<String, Any?>, trust: Pair<String, String>?,
290
+ ): MutableMap<String, Any?> {
187
291
  var method = if (fetchdef["method"] is String) fetchdef["method"] as String else ""
188
292
  if ("" == method) {
189
293
  method = "GET"
@@ -236,7 +340,12 @@ private fun fetchOnce(fullurl: String, fetchdef: MutableMap<String, Any?>): Muta
236
340
 
237
341
  val resp: HttpResponse<String>
238
342
  try {
239
- resp = clientFor(fetchdef).send(reqb.build(), decodedText())
343
+ val signal = fetchdef["signal"]
344
+ resp = if (signal is java.util.concurrent.Future<*>) {
345
+ sendUntil(clientFor(fetchdef, trust), reqb.build(), signal)
346
+ } else {
347
+ clientFor(fetchdef, trust).send(reqb.build(), decodedText())
348
+ }
240
349
  } catch (e: Exception) {
241
350
  throw RuntimeException("fetch: " + e.message, e)
242
351
  }
@@ -332,6 +332,31 @@ internal fun overrideUtil(utility: Utility, key: String, value: Any?): Boolean {
332
332
  }
333
333
 
334
334
  field.isAccessible = true
335
- field.set(utility, value)
335
+ @Suppress("UNCHECKED_CAST")
336
+ field.set(utility, if ("fetcher" == key) callerFetcher(value as KOTLINPACKAGE.core.FetcherFn) else value)
336
337
  return true
337
338
  }
339
+
340
+
341
+ // An exception the caller's own fetcher threw, which the SDK error keeps as
342
+ // its cause: the caller wrote that code, so it is not cleaned.
343
+ internal class CallerFetchError(err: RuntimeException) :
344
+ RuntimeException(err.message, err, false, false)
345
+
346
+ internal fun callerFetcher(fn: KOTLINPACKAGE.core.FetcherFn): KOTLINPACKAGE.core.FetcherFn =
347
+ { ctx, fullurl, fetchdef ->
348
+ try {
349
+ fn(ctx, fullurl, fetchdef)
350
+ } catch (err: KOTLINPACKAGE.core.SdkError) {
351
+ throw err
352
+ } catch (err: RuntimeException) {
353
+ throw CallerFetchError(err)
354
+ }
355
+ }
356
+
357
+ // The caller's exception, wherever the chain holds it, kept only when its
358
+ // printed trace holds nothing clean would mask: a cause reaches every log.
359
+ internal fun callerCause(ctx: KOTLINPACKAGE.core.Context, err: Throwable?): Throwable? =
360
+ generateSequence(err) { at -> at.cause?.takeIf { it !== at } }
361
+ .firstOrNull { it is CallerFetchError }?.cause
362
+ ?.takeIf { val text = it.stackTraceToString(); text == clean(ctx, text) }
@@ -159,6 +159,28 @@ fun makePoint(ctx: Context): Map<String, Any?> {
159
159
  // the chosen point's $action and would wave the request through
160
160
  // whenever the fallback lands on the action point itself.
161
161
  val unmatchedAction = Struct.getprop(reqselector, "\$action", null)
162
+ val acting = if (unmatchedAction == null) emptyList() else op.points.filter {
163
+ unmatchedAction == Struct.getprop(Helpers.toMapAny(Struct.getprop(it, "select")), "\$action", null)
164
+ }
165
+ if (acting.isNotEmpty()) {
166
+ val missing = mutableListOf<String>()
167
+ for (cand in acting) {
168
+ val exist = Struct.getprop(Helpers.toMapAny(Struct.getprop(cand, "select")), "exist")
169
+ for (ek in (exist as? List<*>) ?: emptyList<Any?>()) {
170
+ val key = ek.toString()
171
+ if (Struct.getprop(reqselector, key, null) == null &&
172
+ Struct.getprop(selector, key, null) == null && key !in missing) {
173
+ missing.add(key)
174
+ }
175
+ }
176
+ }
177
+ throw ctx.makeError(
178
+ "point_no_match",
179
+ "Operation \"" + op.name + "\" action \"" + Struct.stringify(unmatchedAction) +
180
+ "\" has no endpoint whose required fields are all given (missing: " +
181
+ missing.joinToString(", ") + ").",
182
+ )
183
+ }
162
184
  if (unmatchedAction != null) {
163
185
  throw ctx.makeError(
164
186
  "point_action_invalid",
@@ -41,12 +41,19 @@ fun makeRequest(ctx: Context): Response {
41
41
  var fetched: Any? = null
42
42
  var fetchErr: RuntimeException? = null
43
43
  try {
44
+ if (ctx.ctrl.cancelled) {
45
+ throw ctx.makeError("request_aborted", "request aborted")
46
+ }
44
47
  fetched = utility.fetcher(ctx, if (url is String) url else "", fetchdef)
45
48
  } catch (err: RuntimeException) {
46
49
  fetchErr = err
47
50
  }
48
51
 
49
- if (fetchErr != null) {
52
+ // A request that failed once its signal was done failed because of it,
53
+ // whatever the transport threw for it.
54
+ if (fetchErr != null && ctx.ctrl.cancelled) {
55
+ response.err = ctx.makeError("request_aborted", "request aborted")
56
+ } else if (fetchErr != null) {
50
57
  response.err = fetchErr
51
58
  } else if (fetched == null) {
52
59
  val resmap = linkedMapOf<String, Any?>()
@@ -60,6 +60,16 @@ fun makeSpec(ctx: Context): Spec {
60
60
  spec.query = utility.prepareQuery(ctx)
61
61
  spec.headers = utility.prepareHeaders(ctx)
62
62
 
63
+ // A call's accept names one declared response type, and wins over the client's.
64
+ ctx.ctrl.accept?.let { want ->
65
+ val accept = Media.chosenMedia(point, want)
66
+ ?: throw ctx.makeError("spec_accept_undeclared", "Accept \"" + want +
67
+ "\" is not a response type operation \"" + ctx.op.name + "\" declares (declared: " +
68
+ Media.declaredMedia(point).joinToString(", ").ifEmpty { "none" } + ").")
69
+ spec.headers.keys.removeIf { "accept".equals(it, ignoreCase = true) }
70
+ spec.headers["accept"] = accept
71
+ }
72
+
63
73
  if ("graphql" == Struct.getprop(ctx.point, "kind") as? String) {
64
74
  // GraphQL addresses one endpoint: no path parts, no query string, and
65
75
  // the body carries the operation. prepareBody is skipped deliberately
@@ -193,6 +203,7 @@ fun makeFetchDef(ctx: Context): MutableMap<String, Any?> {
193
203
  fetchdef["url"] = url
194
204
  fetchdef["method"] = spec.method
195
205
  fetchdef["headers"] = spec.headers
206
+ ctx.ctrl.signal?.let { fetchdef["signal"] = it }
196
207
 
197
208
  val body = spec.body
198
209
  if (body != null) {
@@ -17,6 +17,26 @@ object Media {
17
17
  return "application/json" == m || "text/json" == m || m.endsWith("+json")
18
18
  }
19
19
 
20
+ // Every response type a point declares, in model order.
21
+ fun declaredMedia(point: Any?): List<String> {
22
+ val res = Struct.getprop(point, "response", null)
23
+ val types = mutableListOf<String>()
24
+ (Struct.getprop(res, "media", null) as? String)?.takeIf { it.isNotEmpty() }?.let { types.add(it) }
25
+ val alts = Struct.getprop(res, "alternatives", null)
26
+ if (alts is List<*>) {
27
+ for (alt in alts) {
28
+ (Struct.getprop(alt, "media", null) as? String)?.takeIf { it.isNotEmpty() }?.let { types.add(it) }
29
+ }
30
+ }
31
+ return types
32
+ }
33
+
34
+ // The declared type a call names with ctrl.accept, in its declared spelling.
35
+ fun chosenMedia(point: Any?, accept: String): String? {
36
+ val want = accept.trim().lowercase()
37
+ return declaredMedia(point).firstOrNull { want == it.lowercase() }
38
+ }
39
+
20
40
  // The declared JSON type alone, else every declared type in the model's
21
41
  // order; null when no success response declares a body.
22
42
  fun acceptOf(point: Any?): String? {
@@ -37,6 +37,7 @@ fun resultBody(ctx: Context): KOTLINPACKAGE.core.Result {
37
37
  if (response != null && response.jsonFunc != null && response.body != null) {
38
38
  result.body = response.jsonFunc!!.get()
39
39
  }
40
+ (response?.body as? String)?.let { result.text = it }
40
41
  if (response != null && response.unreadable) {
41
42
  result.err = KOTLINPACKAGE.core.Response.unreadableBody(ctx, result.status, result.headers,
42
43
  response.body, ctx.spec?.headers, result.err)
@@ -56,9 +56,15 @@ function Context.new(ctxmap, basectx)
56
56
  if ctrl_raw.actor ~= nil then
57
57
  self.ctrl.actor = ctrl_raw.actor
58
58
  end
59
+ if type(ctrl_raw.accept) == "string" then
60
+ self.ctrl.accept = ctrl_raw.accept
61
+ end
59
62
  if type(ctrl_raw.paging) == "table" then
60
63
  self.ctrl.paging = ctrl_raw.paging
61
64
  end
65
+ if type(ctrl_raw.signal) == "function" then
66
+ self.ctrl.signal = ctrl_raw.signal
67
+ end
62
68
  elseif basectx ~= nil and basectx.ctrl ~= nil
63
69
  and helpers.get_ctx_prop(ctxmap, "opname") == nil then
64
70
  self.ctrl = basectx.ctrl
@@ -13,8 +13,17 @@ function Control.new(opts)
13
13
  -- Per-call feature inputs (audit actor, paging cursor/page).
14
14
  self.actor = opts.actor
15
15
  self.paging = opts.paging
16
+ -- Cancels the request: a function of no arguments, true once cancelled.
17
+ self.signal = opts.signal
18
+ -- One of the point's declared response types, sent as Accept.
19
+ self.accept = opts.accept
16
20
  return self
17
21
  end
18
22
 
19
23
 
24
+ function Control.cancelled(signal)
25
+ return type(signal) == "function" and signal() == true
26
+ end
27
+
28
+
20
29
  return Control
@@ -36,6 +36,8 @@ function Result.new(resmap)
36
36
  end
37
37
 
38
38
  self.body = vs.getprop(resmap, "body")
39
+ -- The body verbatim, where the transport read it as text.
40
+ self.text = vs.getprop(resmap, "text")
39
41
 
40
42
  self.err = nil
41
43
  local e = vs.getprop(resmap, "err")
@@ -17,6 +17,30 @@ function BaseFeature:get_name() return self.name end
17
17
  function BaseFeature:get_active() return self.active end
18
18
 
19
19
  function BaseFeature:init(ctx, options) end
20
+
21
+ -- Waits ms as sleep would, polling the call's signal; true when it cancelled.
22
+ -- With no sleep given the wait spins on the clock, as the features always did.
23
+ function BaseFeature:_wait(ms, sleep, fetchdef)
24
+ local Control = require("core.control")
25
+ local signal = type(fetchdef) == "table" and fetchdef["signal"] or nil
26
+ if Control.cancelled(signal) then
27
+ return true
28
+ end
29
+ if ms == nil or ms <= 0 then
30
+ return false
31
+ end
32
+ if type(sleep) == "function" then
33
+ sleep(ms)
34
+ else
35
+ local target = os.clock() + (ms / 1000)
36
+ while os.clock() < target and not Control.cancelled(signal) do end
37
+ end
38
+ return Control.cancelled(signal)
39
+ end
40
+
41
+ function BaseFeature:_aborted(ctx)
42
+ return ctx:make_error("request_aborted", "request aborted")
43
+ end
20
44
  function BaseFeature:PostConstruct(ctx) end
21
45
  function BaseFeature:PostConstructEntity(ctx) end
22
46
  function BaseFeature:SetData(ctx) end