@voxgig/sdkgen 4.50.0 → 4.52.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 (400) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ReadmeExplanation.js +5 -2
  3. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  4. package/dist/cmp/ReadmeFeatures.js +20 -6
  5. package/dist/cmp/ReadmeFeatures.js.map +1 -1
  6. package/dist/helpers/optspec.js +2 -2
  7. package/dist/helpers/optspec.js.map +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/model/sdkgen.aontu +1 -1
  10. package/package.json +1 -1
  11. package/project/.sdk/model/feature/audit.aontu +1 -1
  12. package/project/.sdk/model/feature/cache.aontu +7 -5
  13. package/project/.sdk/model/feature/clienttrack.aontu +1 -1
  14. package/project/.sdk/model/feature/cost.aontu +1 -1
  15. package/project/.sdk/model/feature/debug.aontu +1 -1
  16. package/project/.sdk/model/feature/idempotency.aontu +1 -1
  17. package/project/.sdk/model/feature/log.aontu +1 -1
  18. package/project/.sdk/model/feature/metrics.aontu +3 -1
  19. package/project/.sdk/model/feature/netsim.aontu +1 -1
  20. package/project/.sdk/model/feature/paging.aontu +4 -1
  21. package/project/.sdk/model/feature/proxy.aontu +1 -1
  22. package/project/.sdk/model/feature/ratelimit.aontu +3 -3
  23. package/project/.sdk/model/feature/rbac.aontu +1 -1
  24. package/project/.sdk/model/feature/retry.aontu +1 -1
  25. package/project/.sdk/model/feature/secrets.aontu +1 -1
  26. package/project/.sdk/model/feature/streaming.aontu +1 -1
  27. package/project/.sdk/model/feature/telemetry.aontu +2 -2
  28. package/project/.sdk/model/feature/test.aontu +1 -1
  29. package/project/.sdk/model/feature/timeout.aontu +1 -1
  30. package/project/.sdk/model/feature/validate.aontu +1 -1
  31. package/project/.sdk/model/target/lua.aontu +6 -0
  32. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  33. package/project/.sdk/src/cmp/c/TestClean_c.ts +26 -11
  34. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +17 -10
  35. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  36. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +18 -1
  37. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +15 -1
  38. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  39. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +30 -2
  40. package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +31 -12
  41. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +13 -4
  42. package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +51 -15
  43. package/project/.sdk/src/cmp/elixir/fragment/Pipeline.fragment.ex +17 -0
  44. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  45. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +42 -2
  46. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +42 -14
  47. package/project/.sdk/src/cmp/java/TestClean_java.ts +17 -4
  48. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +21 -0
  49. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +13 -8
  50. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  51. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +26 -2
  52. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +8 -0
  53. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +8 -0
  54. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +8 -0
  55. package/project/.sdk/src/cmp/js/fragment/EntityPatchOp.fragment.js +8 -0
  56. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +8 -0
  57. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +8 -0
  58. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +12 -5
  59. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +31 -4
  60. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +19 -0
  61. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +14 -4
  62. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +42 -5
  63. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +44 -10
  64. package/project/.sdk/src/cmp/lua/utility_lua.ts +2 -1
  65. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +20 -5
  66. package/project/.sdk/src/cmp/ocaml/fragment/RunOp.fragment.ml +36 -21
  67. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +13 -4
  68. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +21 -0
  69. package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +31 -12
  70. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  71. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +33 -4
  72. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +13 -6
  73. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  74. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +25 -2
  75. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +26 -12
  76. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +11 -4
  77. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +23 -2
  78. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +27 -11
  79. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +24 -17
  80. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +22 -2
  81. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +45 -11
  82. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +14 -0
  83. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +31 -21
  84. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +9 -0
  85. package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +24 -10
  86. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +13 -8
  87. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  88. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +26 -2
  89. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +8 -0
  90. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +8 -0
  91. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +8 -0
  92. package/project/.sdk/src/cmp/ts/fragment/EntityPatchOp.fragment.ts +8 -0
  93. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +8 -0
  94. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +8 -0
  95. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +12 -5
  96. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +23 -11
  97. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +17 -10
  98. package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +41 -6
  99. package/project/.sdk/tm/c/core/context.c +1 -0
  100. package/project/.sdk/tm/c/core/sdk.h +7 -4
  101. package/project/.sdk/tm/c/feature/cache.c +243 -13
  102. package/project/.sdk/tm/c/feature/metrics.c +7 -0
  103. package/project/.sdk/tm/c/feature/paging.c +231 -2
  104. package/project/.sdk/tm/c/feature/ratelimit.c +5 -9
  105. package/project/.sdk/tm/c/feature/retry.c +51 -4
  106. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  107. package/project/.sdk/tm/c/feature/streaming.c +2 -1
  108. package/project/.sdk/tm/c/feature/telemetry.c +19 -18
  109. package/project/.sdk/tm/c/feature/test.c +78 -54
  110. package/project/.sdk/tm/c/tests/feature_test.c +288 -0
  111. package/project/.sdk/tm/c/tests/primary_utility_test.c +2 -0
  112. package/project/.sdk/tm/c/utility/clean.c +26 -33
  113. package/project/.sdk/tm/c/utility/make_options.c +89 -17
  114. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  115. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  116. package/project/.sdk/tm/clojure/src/sdk/core.clj +50 -22
  117. package/project/.sdk/tm/clojure/src/sdk/features.clj +279 -80
  118. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +103 -1
  119. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  120. package/project/.sdk/tm/cpp/Makefile +5 -0
  121. package/project/.sdk/tm/cpp/core/types.hpp +148 -72
  122. package/project/.sdk/tm/cpp/feature/audit.hpp +12 -8
  123. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  124. package/project/.sdk/tm/cpp/feature/metrics.hpp +19 -0
  125. package/project/.sdk/tm/cpp/feature/paging.hpp +160 -2
  126. package/project/.sdk/tm/cpp/feature/ratelimit.hpp +18 -14
  127. package/project/.sdk/tm/cpp/feature/retry.hpp +46 -5
  128. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  129. package/project/.sdk/tm/cpp/feature/streaming.hpp +2 -1
  130. package/project/.sdk/tm/cpp/feature/telemetry.hpp +17 -10
  131. package/project/.sdk/tm/cpp/feature/test.hpp +63 -53
  132. package/project/.sdk/tm/cpp/test/feature_test.cpp +236 -0
  133. package/project/.sdk/tm/cpp/utility/pipeline.hpp +44 -12
  134. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  135. package/project/.sdk/tm/csharp/feature/AuditFeature.cs +8 -1
  136. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  137. package/project/.sdk/tm/csharp/feature/MetricsFeature.cs +23 -0
  138. package/project/.sdk/tm/csharp/feature/PagingFeature.cs +130 -3
  139. package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +26 -19
  140. package/project/.sdk/tm/csharp/feature/RetryFeature.cs +41 -7
  141. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  142. package/project/.sdk/tm/csharp/feature/StreamingFeature.cs +2 -1
  143. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +11 -9
  144. package/project/.sdk/tm/csharp/feature/TestFeature.cs +55 -67
  145. package/project/.sdk/tm/csharp/test/FeatureTest.cs +238 -0
  146. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  147. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  148. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +94 -24
  149. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  150. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  151. package/project/.sdk/tm/elixir/lib/projectname/feature/metrics.ex +13 -0
  152. package/project/.sdk/tm/elixir/lib/projectname/feature/paging.ex +110 -5
  153. package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +6 -12
  154. package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +33 -9
  155. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  156. package/project/.sdk/tm/elixir/lib/projectname/feature/streaming.ex +2 -1
  157. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +7 -7
  158. package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +52 -48
  159. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +77 -47
  160. package/project/.sdk/tm/elixir/test/feature_test.exs +198 -0
  161. package/project/.sdk/tm/go/core/context.go +6 -0
  162. package/project/.sdk/tm/go/feature/audit_feature.go +1 -3
  163. package/project/.sdk/tm/go/feature/base_feature.go +11 -0
  164. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  165. package/project/.sdk/tm/go/feature/metrics_feature.go +14 -0
  166. package/project/.sdk/tm/go/feature/paging_feature.go +108 -2
  167. package/project/.sdk/tm/go/feature/ratelimit_feature.go +19 -17
  168. package/project/.sdk/tm/go/feature/retry_feature.go +81 -9
  169. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  170. package/project/.sdk/tm/go/feature/streaming_feature.go +2 -1
  171. package/project/.sdk/tm/go/feature/telemetry_feature.go +18 -11
  172. package/project/.sdk/tm/go/feature/test_feature.go +65 -55
  173. package/project/.sdk/tm/go/test/feature_corpus_test.go +357 -28
  174. package/project/.sdk/tm/go/test/feature_test.go +93 -0
  175. package/project/.sdk/tm/go/utility/clean.go +5 -7
  176. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  177. package/project/.sdk/tm/go/utility/make_options.go +116 -13
  178. package/project/.sdk/tm/java/core/Context.java +9 -0
  179. package/project/.sdk/tm/java/core/SdkClient.java +43 -14
  180. package/project/.sdk/tm/java/feature/AuditFeature.java +5 -1
  181. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  182. package/project/.sdk/tm/java/feature/MetricsFeature.java +31 -0
  183. package/project/.sdk/tm/java/feature/PagingFeature.java +156 -2
  184. package/project/.sdk/tm/java/feature/RatelimitFeature.java +15 -13
  185. package/project/.sdk/tm/java/feature/RetryFeature.java +33 -6
  186. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  187. package/project/.sdk/tm/java/feature/StreamingFeature.java +2 -1
  188. package/project/.sdk/tm/java/feature/TelemetryFeature.java +17 -9
  189. package/project/.sdk/tm/java/feature/TestFeature.java +50 -63
  190. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +309 -17
  191. package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
  192. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  193. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  194. package/project/.sdk/tm/java/utility/MakeOptions.java +131 -15
  195. package/project/.sdk/tm/js/src/Context.js +4 -0
  196. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  197. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  198. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +9 -4
  199. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +103 -5
  200. package/project/.sdk/tm/js/src/feature/ratelimit/RatelimitFeature.js +5 -9
  201. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  202. package/project/.sdk/tm/js/src/feature/retry/RetryFeature.js +25 -3
  203. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  204. package/project/.sdk/tm/js/src/feature/streaming/StreamingFeature.js +2 -1
  205. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +11 -6
  206. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +38 -1
  207. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  208. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  209. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +61 -12
  210. package/project/.sdk/tm/js/test/feature/Corpus.test.js +191 -23
  211. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  212. package/project/.sdk/tm/js/test/feature.test.js +14 -1
  213. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  214. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  215. package/project/.sdk/tm/kotlin/core/SdkClient.kt +23 -10
  216. package/project/.sdk/tm/kotlin/feature/AuditFeature.kt +5 -1
  217. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  218. package/project/.sdk/tm/kotlin/feature/MetricsFeature.kt +22 -0
  219. package/project/.sdk/tm/kotlin/feature/PagingFeature.kt +125 -2
  220. package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +16 -13
  221. package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +36 -14
  222. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  223. package/project/.sdk/tm/kotlin/feature/StreamingFeature.kt +4 -0
  224. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +12 -10
  225. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +45 -48
  226. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +173 -0
  227. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  228. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  229. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +86 -15
  230. package/project/.sdk/tm/lua/core/context.lua +6 -0
  231. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  232. package/project/.sdk/tm/lua/feature/debug_feature.lua +2 -3
  233. package/project/.sdk/tm/lua/feature/metrics_feature.lua +5 -0
  234. package/project/.sdk/tm/lua/feature/paging_feature.lua +143 -2
  235. package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +5 -9
  236. package/project/.sdk/tm/lua/feature/retry_feature.lua +43 -5
  237. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  238. package/project/.sdk/tm/lua/feature/streaming_feature.lua +2 -1
  239. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +18 -7
  240. package/project/.sdk/tm/lua/feature/test_feature.lua +60 -62
  241. package/project/.sdk/tm/lua/test/feature_test.lua +181 -3
  242. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  243. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  244. package/project/.sdk/tm/lua/utility/make_options.lua +60 -18
  245. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  246. package/project/.sdk/tm/ocaml/sdk_features.ml +392 -68
  247. package/project/.sdk/tm/ocaml/sdk_runtime.ml +47 -21
  248. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  249. package/project/.sdk/tm/ocaml/test/t_feature.ml +107 -2
  250. package/project/.sdk/tm/perl/core/context.pm +3 -0
  251. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  252. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  253. package/project/.sdk/tm/perl/feature/debug_feature.pm +2 -2
  254. package/project/.sdk/tm/perl/feature/metrics_feature.pm +5 -0
  255. package/project/.sdk/tm/perl/feature/paging_feature.pm +139 -2
  256. package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +5 -11
  257. package/project/.sdk/tm/perl/feature/retry_feature.pm +22 -4
  258. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  259. package/project/.sdk/tm/perl/feature/streaming_feature.pm +2 -0
  260. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +17 -8
  261. package/project/.sdk/tm/perl/feature/test_feature.pm +45 -50
  262. package/project/.sdk/tm/perl/t/feature.t +68 -2
  263. package/project/.sdk/tm/perl/t/feature_corpus.t +204 -25
  264. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  265. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  266. package/project/.sdk/tm/perl/utility/make_options.pm +38 -15
  267. package/project/.sdk/tm/php/core/Context.php +4 -0
  268. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  269. package/project/.sdk/tm/php/feature/MetricsFeature.php +8 -0
  270. package/project/.sdk/tm/php/feature/PagingFeature.php +128 -1
  271. package/project/.sdk/tm/php/feature/RatelimitFeature.php +5 -9
  272. package/project/.sdk/tm/php/feature/RetryFeature.php +27 -3
  273. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  274. package/project/.sdk/tm/php/feature/StreamingFeature.php +2 -1
  275. package/project/.sdk/tm/php/feature/TelemetryFeature.php +10 -7
  276. package/project/.sdk/tm/php/feature/TestFeature.php +55 -47
  277. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +262 -17
  278. package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
  279. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  280. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  281. package/project/.sdk/tm/php/utility/MakeOptions.php +45 -20
  282. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  283. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  284. package/project/.sdk/tm/py/pkg/feature/metrics_feature.py +7 -0
  285. package/project/.sdk/tm/py/pkg/feature/paging_feature.py +86 -1
  286. package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +13 -16
  287. package/project/.sdk/tm/py/pkg/feature/retry_feature.py +31 -6
  288. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  289. package/project/.sdk/tm/py/pkg/feature/streaming_feature.py +2 -1
  290. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +10 -6
  291. package/project/.sdk/tm/py/pkg/feature/test_feature.py +56 -53
  292. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  293. package/project/.sdk/tm/py/pkg/utility/make_options.py +77 -30
  294. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  295. package/project/.sdk/tm/py/test/test_feature.py +61 -1
  296. package/project/.sdk/tm/py/test/test_feature_corpus.py +197 -17
  297. package/project/.sdk/tm/py-data/pkg/fetch.py +6 -3
  298. package/project/.sdk/tm/py-data/test/test_fetch.py +7 -4
  299. package/project/.sdk/tm/rb/core/context.rb +4 -1
  300. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  301. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  302. package/project/.sdk/tm/rb/feature/debug_feature.rb +2 -2
  303. package/project/.sdk/tm/rb/feature/metrics_feature.rb +8 -0
  304. package/project/.sdk/tm/rb/feature/paging_feature.rb +87 -1
  305. package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +12 -16
  306. package/project/.sdk/tm/rb/feature/retry_feature.rb +19 -3
  307. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  308. package/project/.sdk/tm/rb/feature/streaming_feature.rb +2 -1
  309. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +11 -6
  310. package/project/.sdk/tm/rb/feature/test_feature.rb +42 -49
  311. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +191 -25
  312. package/project/.sdk/tm/rb/test/feature_test.rb +75 -1
  313. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  314. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  315. package/project/.sdk/tm/rb/utility/make_options.rb +37 -16
  316. package/project/.sdk/tm/rust/core/context.rs +8 -0
  317. package/project/.sdk/tm/rust/feature/audit.rs +2 -2
  318. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  319. package/project/.sdk/tm/rust/feature/metrics.rs +24 -1
  320. package/project/.sdk/tm/rust/feature/paging.rs +189 -3
  321. package/project/.sdk/tm/rust/feature/ratelimit.rs +5 -10
  322. package/project/.sdk/tm/rust/feature/retry.rs +59 -6
  323. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  324. package/project/.sdk/tm/rust/feature/streaming.rs +3 -2
  325. package/project/.sdk/tm/rust/feature/support.rs +4 -0
  326. package/project/.sdk/tm/rust/feature/telemetry.rs +22 -11
  327. package/project/.sdk/tm/rust/feature/test.rs +63 -57
  328. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  329. package/project/.sdk/tm/rust/tests/feature_test.rs +274 -0
  330. package/project/.sdk/tm/rust/tests/primary_utility_test.rs +1 -0
  331. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  332. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  333. package/project/.sdk/tm/rust/utility/make_options.rs +130 -38
  334. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  335. package/project/.sdk/tm/scala/core/SdkClient.scala +45 -11
  336. package/project/.sdk/tm/scala/feature/AuditFeature.scala +6 -1
  337. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  338. package/project/.sdk/tm/scala/feature/MetricsFeature.scala +31 -1
  339. package/project/.sdk/tm/scala/feature/PagingFeature.scala +122 -2
  340. package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +14 -11
  341. package/project/.sdk/tm/scala/feature/RetryFeature.scala +29 -7
  342. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  343. package/project/.sdk/tm/scala/feature/StreamingFeature.scala +2 -1
  344. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +12 -10
  345. package/project/.sdk/tm/scala/feature/TestFeature.scala +44 -44
  346. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +69 -0
  347. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  348. package/project/.sdk/tm/scala/utility/Make.scala +99 -14
  349. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  350. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  351. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/AuditFeature.swift +3 -2
  352. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  353. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/MetricsFeature.swift +20 -0
  354. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/PagingFeature.swift +102 -2
  355. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +19 -13
  356. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +40 -5
  357. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  358. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/StreamingFeature.swift +2 -1
  359. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +11 -9
  360. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +55 -49
  361. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  362. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +56 -17
  363. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  364. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +166 -0
  365. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  366. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  367. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  368. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +6 -1
  369. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +103 -5
  370. package/project/.sdk/tm/ts/src/feature/ratelimit/RatelimitFeature.ts +5 -9
  371. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  372. package/project/.sdk/tm/ts/src/feature/retry/RetryFeature.ts +25 -3
  373. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  374. package/project/.sdk/tm/ts/src/feature/streaming/StreamingFeature.ts +2 -1
  375. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +11 -6
  376. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +8 -7
  377. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  378. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  379. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +63 -12
  380. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +192 -23
  381. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  382. package/project/.sdk/tm/ts/test/feature.test.ts +14 -1
  383. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  384. package/project/.sdk/tm/zig/core/context.zig +5 -0
  385. package/project/.sdk/tm/zig/core/utility.zig +118 -17
  386. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  387. package/project/.sdk/tm/zig/feature/metrics.zig +19 -0
  388. package/project/.sdk/tm/zig/feature/paging.zig +172 -4
  389. package/project/.sdk/tm/zig/feature/ratelimit.zig +5 -11
  390. package/project/.sdk/tm/zig/feature/retry.zig +41 -3
  391. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  392. package/project/.sdk/tm/zig/feature/streaming.zig +2 -0
  393. package/project/.sdk/tm/zig/feature/telemetry.zig +15 -9
  394. package/project/.sdk/tm/zig/feature/test.zig +56 -40
  395. package/project/.sdk/tm/zig/test/feature_test.zig +174 -0
  396. package/project/.sdk/tm/zig/test/primary_utility_test.zig +2 -0
  397. package/project/sdkgen-package.json +1 -1
  398. package/src/cmp/ReadmeExplanation.ts +5 -2
  399. package/src/cmp/ReadmeFeatures.ts +21 -6
  400. package/src/helpers/optspec.ts +2 -2
@@ -379,6 +379,17 @@ describe('feature', () => {
379
379
  strictEqual(m.total.err, 1)
380
380
  strictEqual(m.ops['widget.load'].count, 2)
381
381
  })
382
+
383
+ test('the sink gets the counters once per operation', async () => {
384
+ const seen = []
385
+ const h = makeClient({ features: [
386
+ { name: 'metrics', options: { sink: (m) => seen.push(m) } },
387
+ ] })
388
+ await h.op({ op: 'load' })
389
+ await h.op({ op: 'list' })
390
+ deepStrictEqual(seen.map((m) => m.total.count), [1, 2])
391
+ strictEqual(seen[1].ops['widget.list'].count, 1)
392
+ })
382
393
  })
383
394
 
384
395
 
@@ -732,7 +743,9 @@ describe('feature', () => {
732
743
  test('default id generation and no exporter', async () => {
733
744
  const h = makeClient({ features: [{ name: 'telemetry' }] })
734
745
  await h.op({ op: 'load' })
735
- ok(/^t/.test(h.client._telemetry.spans[0].traceId))
746
+ const span = h.client._telemetry.spans[0]
747
+ ok(/^[0-9a-f]{32}$/.test(span.traceId) && !/^0+$/.test(span.traceId), span.traceId)
748
+ ok(/^[0-9a-f]{16}$/.test(span.spanId) && !/^0+$/.test(span.spanId), span.spanId)
736
749
  })
737
750
  })
738
751
 
@@ -559,7 +559,7 @@ describe('pipeline:result helpers', () => {
559
559
  const secret = 'PIPELINE-SECRET-a1b2c3d4e5f6'
560
560
  const text = 'x'.repeat(150) + secret + 'y'.repeat(100)
561
561
  const ctx = base({
562
- options: { __derived__: { clean: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 } } },
562
+ cleancfg: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 },
563
563
  spec: { headers: { 'user-agent': 'Probe ' + secret } },
564
564
  response: { body: 'body', json: async () => { throw Object.assign(new SyntaxError('bad json'), { text }) } },
565
565
  result: { status: 200, headers: { 'content-type': 'text/html' } },
@@ -20,6 +20,8 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
20
20
  var config: MutableMap<String, Any?>? = null
21
21
  var entopts: MutableMap<String, Any?>? = null
22
22
  var options: MutableMap<String, Any?>? = null
23
+ // The clean registry, beside the options rather than in them.
24
+ var cleancfg: Any? = null
23
25
  var opmap: MutableMap<String, Operation>? = null
24
26
  var response: Response? = null
25
27
  var result: Result? = null
@@ -116,6 +118,7 @@ class Context(ctxmap: MutableMap<String, Any?>?, basectx: Context?) {
116
118
  if (this.options == null && basectx != null) {
117
119
  this.options = basectx.options
118
120
  }
121
+ this.cleancfg = Helpers.getCtxProp(ctxmap, "cleancfg") ?: basectx?.cleancfg
119
122
 
120
123
  // Entity
121
124
  val e = Helpers.getCtxProp(ctxmap, "entity")
@@ -51,25 +51,38 @@ abstract class SdkClient(sdkopts: MutableMap<String, Any?>?) {
51
51
  // must be added before them to sit at the base of the chain.
52
52
  val featureOpts = Helpers.toMapAny(Struct.getprop(this.options, "feature"))
53
53
  ?: linkedMapOf()
54
+ fun active(fname: String?): Boolean =
55
+ Helpers.toMapAny(Struct.getprop(featureOpts, fname))?.get("active") == true
56
+ val extend = (Struct.getprop(this.options, "extend") as? List<*>)
57
+ ?.filterIsInstance<Feature>() ?: listOf()
58
+ val placed = mutableListOf<Feature>()
54
59
  val featureOrder = Struct.getpath(this.options, listOf("__derived__", "featureorder"))
55
60
  if (featureOrder is List<*>) {
56
61
  for (fnameObj in featureOrder) {
57
62
  val fname = fnameObj as? String
58
- val fopts = Helpers.toMapAny(Struct.getprop(featureOpts, fname))
59
- if (fname != null && fopts != null && fopts["active"] == true) {
60
- val f = Config.makeFeature(fname)
63
+ if (fname == null || !active(fname)) {
64
+ continue
65
+ }
66
+ val f = Config.makeFeature(fname)
67
+ // An active name with no generated class is legal when an
68
+ // extend-supplied instance carries that name (station's adopt
69
+ // path): the instance takes the slot the order gives its name.
70
+ val carried = if (f.name == fname) null else extend.firstOrNull { it.name == fname }
71
+ if (carried != null) {
72
+ placed.add(carried)
73
+ this.util.featureAdd(this.rootctx, carried)
74
+ } else {
61
75
  this.util.featureAdd(this.rootctx, f)
62
76
  }
63
77
  }
64
78
  }
65
79
 
66
- // Add extension features.
67
- val extend = Struct.getprop(this.options, "extend")
68
- if (extend is List<*>) {
69
- for (f in extend) {
70
- if (f is Feature) {
71
- this.util.featureAdd(this.rootctx, f)
72
- }
80
+ // An extend feature is active by its option, else by its own flag.
81
+ for (f in extend) {
82
+ val fa = Helpers.toMapAny(Struct.getprop(featureOpts, f.name))?.get("active")
83
+ val on = if (fa is Boolean) fa else f.active
84
+ if (placed.none { it === f } && on) {
85
+ this.util.featureAdd(this.rootctx, f)
73
86
  }
74
87
  }
75
88
 
@@ -88,7 +88,11 @@ class AuditFeature : BaseFeature("audit", "0.0.1", true) {
88
88
 
89
89
  val sink = this.options?.get("sink")
90
90
  if (sink is Consumer<*>) {
91
- (sink as Consumer<MutableMap<String, Any?>>).accept(record)
91
+ // A failing sink never changes the operation's outcome.
92
+ try {
93
+ (sink as Consumer<MutableMap<String, Any?>>).accept(record)
94
+ } catch (e: Exception) {
95
+ }
92
96
  }
93
97
  }
94
98
 
@@ -1,16 +1,17 @@
1
1
  package KOTLINPACKAGE.feature
2
2
 
3
+ import java.security.SecureRandom
3
4
  import java.util.function.Supplier
5
+ import javax.crypto.Mac
6
+ import javax.crypto.spec.SecretKeySpec
4
7
 
5
8
  import KOTLINPACKAGE.core.Context
6
9
  import KOTLINPACKAGE.core.FetcherFn
7
10
  import KOTLINPACKAGE.core.SdkClient
8
11
  import KOTLINPACKAGE.utility.Media
9
12
 
10
- // Response caching for safe (read) requests. Wraps the active transport and
11
- // serves a fresh cached snapshot instead of hitting the network when the same
12
- // method+URL was fetched within `ttl` ms (default: 5000). Only successful
13
- // (2xx) responses to cacheable methods (default: GET) are stored.
13
+ // Response caching for safe (read) requests, per client: see the features
14
+ // reference for the key, the write invalidation and the Cache-Control rules.
14
15
  @Suppress("UNCHECKED_CAST")
15
16
  class CacheFeature : BaseFeature("cache", "0.0.1", true) {
16
17
 
@@ -18,6 +19,7 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
18
19
  private var options: MutableMap<String, Any?>? = null
19
20
  private var store: MutableMap<String, CacheEntry> = linkedMapOf()
20
21
  private var order: MutableList<String> = mutableListOf()
22
+ private var secret: SecretKeySpec? = null
21
23
 
22
24
  // Activity tracking (mirrors the ts client._cache record).
23
25
  var hit = 0
@@ -26,6 +28,7 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
26
28
 
27
29
  private class CacheEntry {
28
30
  var expiry: Long = 0
31
+ var scope: String = ""
29
32
  lateinit var snapshot: CacheSnapshot
30
33
  }
31
34
 
@@ -47,6 +50,9 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
47
50
 
48
51
  this.store = linkedMapOf()
49
52
  this.order = mutableListOf()
53
+ val key = ByteArray(32)
54
+ SecureRandom().nextBytes(key)
55
+ this.secret = SecretKeySpec(key, "HmacSHA256")
50
56
 
51
57
  val inner: FetcherFn = ctx.utility!!.fetcher
52
58
 
@@ -72,10 +78,17 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
72
78
  }
73
79
  }
74
80
  if (!cacheable) {
75
- return inner(ctx, url, fetchdef)
81
+ if (method in SAFE_METHODS) {
82
+ return inner(ctx, url, fetchdef)
83
+ }
84
+ try {
85
+ return inner(ctx, url, fetchdef)
86
+ } finally {
87
+ invalidate(url)
88
+ }
76
89
  }
77
90
 
78
- val key = "$method $url"
91
+ val key = "$method $url " + digest(fetchdef["headers"])
79
92
  val now = FeatureOptions.foptNow(this.options).getAsLong()
80
93
 
81
94
  val hitEntry = this.store[key]
@@ -100,10 +113,16 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
100
113
 
101
114
  if (storable(res)) {
102
115
  val snapshot = snapshot(res)
103
- val ttl = FeatureOptions.foptInt(this.options, "ttl", 5000)
116
+ val ttl = lifetime(snapshot.headers, FeatureOptions.foptInt(this.options, "ttl", 5000).toLong())
117
+ if (ttl <= 0) {
118
+ this.bypass++
119
+ return replay(snapshot)
120
+ }
121
+ drop(key)
104
122
  evict()
105
123
  val entry = CacheEntry()
106
124
  entry.expiry = now + ttl
125
+ entry.scope = scope(url)
107
126
  entry.snapshot = snapshot
108
127
  this.store[key] = entry
109
128
  this.order.add(key)
@@ -115,6 +134,39 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
115
134
  return res
116
135
  }
117
136
 
137
+ private fun digest(headers: Any?): String {
138
+ val pairs = mutableListOf<Pair<String, String>>()
139
+ if (headers is Map<*, *>) {
140
+ for ((name, value) in headers) {
141
+ if (value != null) {
142
+ pairs.add(Pair(name.toString().lowercase(), value.toString()))
143
+ }
144
+ }
145
+ }
146
+ pairs.sortWith(compareBy<Pair<String, String>> { it.first }.thenBy { it.second })
147
+ val mac = Mac.getInstance("HmacSHA256")
148
+ mac.init(this.secret)
149
+ for ((name, value) in pairs) {
150
+ mac.update("$name:$value\n".toByteArray(Charsets.UTF_8))
151
+ }
152
+ return mac.doFinal().joinToString("") { "%02x".format(it) }
153
+ }
154
+
155
+ private fun invalidate(url: String) {
156
+ val path = scope(url)
157
+ val collection = parent(path)
158
+ val dropped = this.store.filterValues { under(it.scope, path) || it.scope == collection }.keys.toList()
159
+ for (key in dropped) {
160
+ drop(key)
161
+ }
162
+ }
163
+
164
+ private fun drop(key: String) {
165
+ if (this.store.remove(key) != null) {
166
+ this.order.remove(key)
167
+ }
168
+ }
169
+
118
170
  // A body the transport could not read as JSON passes through, for the operation to report.
119
171
  private fun storable(res: Any?): Boolean {
120
172
  val status = FeatureOptions.fresStatus(res)
@@ -177,4 +229,47 @@ class CacheFeature : BaseFeature("cache", "0.0.1", true) {
177
229
  this.store.remove(oldest)
178
230
  }
179
231
  }
232
+
233
+ companion object {
234
+ private val SAFE_METHODS = listOf("GET", "HEAD")
235
+ private val UNSTORED = listOf("no-store", "private", "no-cache")
236
+ private val MAX_AGE = Regex("^max-age\\s*=\\s*\"?(\\d+)\"?$")
237
+
238
+ // The configured ttl capped by the response's Cache-Control; zero when
239
+ // the response may not be stored.
240
+ private fun lifetime(headers: Map<String, Any?>, ttl: Long): Long {
241
+ var control = ""
242
+ for ((name, value) in headers) {
243
+ if (name.lowercase() == "cache-control") {
244
+ control = value.toString().lowercase()
245
+ }
246
+ }
247
+ var life = ttl
248
+ for (part in control.split(",")) {
249
+ val directive = part.trim()
250
+ if (directive in UNSTORED) {
251
+ return 0
252
+ }
253
+ val secs = MAX_AGE.matchEntire(directive)?.groupValues?.get(1)?.toLongOrNull()
254
+ if (secs != null) {
255
+ life = minOf(life, secs * 1000)
256
+ }
257
+ }
258
+ return life
259
+ }
260
+
261
+ private fun scope(url: String): String = url.split(Regex("[?#]"), 2)[0].trimEnd('/')
262
+
263
+ private fun parent(scope: String): String {
264
+ val scheme = scope.indexOf("://")
265
+ val root = if (scheme < 0) 0 else scope.indexOf('/', scheme + 3)
266
+ if (root < 0) {
267
+ return scope
268
+ }
269
+ return scope.substring(0, maxOf(scope.lastIndexOf('/'), root))
270
+ }
271
+
272
+ private fun under(scope: String, prefix: String): Boolean =
273
+ scope == prefix || scope.startsWith("$prefix/")
274
+ }
180
275
  }
@@ -1,6 +1,9 @@
1
1
  package KOTLINPACKAGE.feature
2
2
 
3
+ import java.util.function.Consumer
4
+
3
5
  import KOTLINPACKAGE.core.Context
6
+ import KOTLINPACKAGE.core.Helpers
4
7
  import KOTLINPACKAGE.core.SdkClient
5
8
 
6
9
  // Statistics capture. Records per-operation counters and latency for every
@@ -21,6 +24,9 @@ class MetricsFeature : BaseFeature("metrics", "0.0.1", true) {
21
24
  var err = 0
22
25
  var totalMs = 0L
23
26
  var maxMs = 0L
27
+
28
+ fun record(): MutableMap<String, Any?> =
29
+ linkedMapOf("count" to count, "ok" to ok, "err" to err, "totalMs" to totalMs, "maxMs" to maxMs)
24
30
  }
25
31
 
26
32
  override fun init(ctx: Context, options: MutableMap<String, Any?>) {
@@ -75,6 +81,22 @@ class MetricsFeature : BaseFeature("metrics", "0.0.1", true) {
75
81
 
76
82
  bump(this.total, ok, dur)
77
83
  bump(op, ok, dur)
84
+
85
+ val sink = this.options?.get("sink")
86
+ if (sink is Consumer<*>) {
87
+ val ops = linkedMapOf<String, Any?>()
88
+ for ((k, b) in this.ops) {
89
+ ops[k] = b.record()
90
+ }
91
+ val raw: MutableMap<String, Any?> = linkedMapOf("total" to this.total.record(), "ops" to ops)
92
+ @Suppress("UNCHECKED_CAST")
93
+ val counters = Helpers.toMapAny(ctx.utility?.clean?.invoke(ctx, raw)) ?: raw
94
+ // A failing sink never changes the operation's outcome.
95
+ try {
96
+ (sink as Consumer<MutableMap<String, Any?>>).accept(counters)
97
+ } catch (e: Exception) {
98
+ }
99
+ }
78
100
  }
79
101
 
80
102
  private fun bump(bucket: MetricsBucket, ok: Boolean, dur: Long) {
@@ -51,8 +51,11 @@ class PagingFeature : BaseFeature("paging", "0.0.1", true) {
51
51
  }
52
52
 
53
53
  val cursor = paging["cursor"]
54
+ val next = paging["next"]
54
55
  if (cursor != null) {
55
56
  spec.query[cursorParam] = cursor
57
+ } else if (next is String && !foreign(next, spec.base)) {
58
+ follow(spec, next)
56
59
  } else if (spec.query[pageParam] == null) {
57
60
  // A record written back by preResult holds the page just fetched as
58
61
  // "page" and the one to fetch as "nextPage", so nextPage wins.
@@ -172,8 +175,12 @@ class PagingFeature : BaseFeature("paging", "0.0.1", true) {
172
175
  // Body-level signals; snake_case forms are read first so camelCase wins.
173
176
  if (body is MutableMap<*, *>) {
174
177
  val bm = body as MutableMap<String, Any?>
175
- if (bm["next"] != null && paging["next"] == null) {
176
- paging["next"] = bm["next"]
178
+ if (bm["next"] != null) {
179
+ if (!isLink(bm["next"], FeatureOptions.foptStr(this.options, "next", "auto"))) {
180
+ paging["cursor"] = bm["next"]
181
+ } else if (paging["next"] == null) {
182
+ paging["next"] = bm["next"]
183
+ }
177
184
  }
178
185
  if (bm["next_cursor"] != null) {
179
186
  paging["cursor"] = bm["next_cursor"]
@@ -202,6 +209,19 @@ class PagingFeature : BaseFeature("paging", "0.0.1", true) {
202
209
  }
203
210
  }
204
211
 
212
+ // A link to another origin is recorded, never followed, and ends the walk.
213
+ val base = ctx.spec?.base ?: (ctx.options?.get("base") as? String) ?: ""
214
+ val spec = ctx.spec
215
+ var nextLink = paging["next"]
216
+ if (nextLink is String && spec != null) {
217
+ nextLink = resolve(nextLink, spec.url)
218
+ paging["next"] = nextLink
219
+ }
220
+ if (nextLink is String && foreign(nextLink, base)) {
221
+ paging["foreign"] = nextLink
222
+ paging.remove("next")
223
+ }
224
+
205
225
  // Cursor presence only INFERS another page. When the server stated the
206
226
  // answer outright — relay's `hasNextPage: false`, or a body `hasMore` —
207
227
  // that wins: a final page normally carries both an end cursor and
@@ -213,6 +233,10 @@ class PagingFeature : BaseFeature("paging", "0.0.1", true) {
213
233
  paging["hasMore"] = true
214
234
  }
215
235
 
236
+ if (paging["foreign"] != null && paging["cursor"] == null && paging["nextPage"] == null) {
237
+ paging["hasMore"] = false
238
+ }
239
+
216
240
  result.paging = paging
217
241
  this.last = paging
218
242
 
@@ -262,5 +286,104 @@ class PagingFeature : BaseFeature("paging", "0.0.1", true) {
262
286
  companion object {
263
287
  private val LINK_NEXT_RE: Pattern =
264
288
  Pattern.compile("<([^>]+)>\\s*;\\s*rel=\"?next\"?", Pattern.CASE_INSENSITIVE)
289
+
290
+ private val ORIGIN_RE: Pattern =
291
+ Pattern.compile("^[a-z][a-z0-9+.-]*://[^/?#]*", Pattern.CASE_INSENSITIVE)
292
+
293
+ private fun originOf(text: String): String {
294
+ val m = ORIGIN_RE.matcher(text)
295
+ return if (m.find()) m.group() else ""
296
+ }
297
+
298
+ // Under the `next` option's default, a URL or an absolute path is a link
299
+ // and anything else a cursor; `cursor` and `url` pin the reading.
300
+ fun isLink(next: Any?, mode: String): Boolean =
301
+ next is String && (mode == "url" ||
302
+ (mode != "cursor" && (originOf(next).isNotEmpty() || next.startsWith("/"))))
303
+
304
+ fun foreign(link: String, base: String?): Boolean {
305
+ val origin = originOf(link).lowercase()
306
+ return origin.isNotEmpty() && origin != originOf(base ?: "").lowercase()
307
+ }
308
+
309
+ private val SCHEME_RE: Pattern = Pattern.compile("^[a-z][a-z0-9+.-]*:", Pattern.CASE_INSENSITIVE)
310
+
311
+ // RFC 3986 reference resolution against the URL of the request that
312
+ // returned the link, by hand: java.net.URI resolves a query-only reference
313
+ // by RFC 2396 and drops the last path segment. A link on that URL's origin
314
+ // comes back as its path and query; an absolute link is left as it is.
315
+ fun resolve(link0: String, url: String?): String {
316
+ if (url.isNullOrEmpty() || SCHEME_RE.matcher(link0).find()) return link0
317
+ val link = link0.substringBefore('#')
318
+ val origin = originOf(url)
319
+ if (link.startsWith("//")) {
320
+ return if (origin.isEmpty()) link else origin.substringBefore(':') + ":" + link
321
+ }
322
+ val from = url.substring(origin.length).substringBefore('#')
323
+ val bpath = from.substringBefore('?')
324
+ val rpath = link.substringBefore('?')
325
+ val query: String?
326
+ val path: String
327
+ if (rpath.isEmpty()) {
328
+ path = bpath
329
+ query = if (link.contains('?')) link.substringAfter('?')
330
+ else if (from.contains('?')) from.substringAfter('?') else null
331
+ } else {
332
+ query = if (link.contains('?')) link.substringAfter('?') else null
333
+ val merged = if (rpath.startsWith("/")) rpath
334
+ else bpath.substring(0, bpath.lastIndexOf('/') + 1) + rpath
335
+ path = removeDots(merged)
336
+ }
337
+ val rooted = if (path.startsWith("/")) path else "/$path"
338
+ return if (query == null) rooted else "$rooted?$query"
339
+ }
340
+
341
+ // RFC 3986 section 5.2.4.
342
+ fun removeDots(path: String): String {
343
+ val abs = path.startsWith("/")
344
+ val segs = path.split("/")
345
+ val out = mutableListOf<String>()
346
+ for (i in (if (abs) 1 else 0) until segs.size) {
347
+ val seg = segs[i]
348
+ if (seg == "." || seg == "..") {
349
+ if (seg == ".." && out.isNotEmpty()) out.removeAt(out.size - 1)
350
+ if (i == segs.size - 1) out.add("")
351
+ } else {
352
+ out.add(seg)
353
+ }
354
+ }
355
+ return (if (abs) "/" else "") + out.joinToString("/")
356
+ }
357
+
358
+ // The request goes to the link's path and query, on the SDK's own origin.
359
+ fun follow(spec: KOTLINPACKAGE.core.Spec, next: String) {
360
+ val link = next.substring(originOf(next).length).substringBefore('#')
361
+ val path = link.substringBefore('?')
362
+ val rawquery = if (link.contains('?')) link.substringAfter('?') else ""
363
+
364
+ val query: MutableMap<String, Any?> = linkedMapOf()
365
+ for (pair in rawquery.split('&')) {
366
+ if (pair.isEmpty()) continue
367
+ val key = pair.substringBefore('=')
368
+ val value = if (pair.contains('=')) pair.substringAfter('=') else ""
369
+ query[unescape(key)] = unescape(value)
370
+ }
371
+ for (key in spec.authquery) {
372
+ query[key] = spec.query[key]
373
+ }
374
+
375
+ spec.base = originOf(spec.base)
376
+ spec.prefix = ""
377
+ spec.path = path
378
+ spec.suffix = ""
379
+ spec.query = query
380
+ }
381
+
382
+ private fun unescape(text: String): String =
383
+ try {
384
+ java.net.URLDecoder.decode(text, Charsets.UTF_8)
385
+ } catch (e: IllegalArgumentException) {
386
+ text
387
+ }
265
388
  }
266
389
  }
@@ -45,29 +45,32 @@ class RatelimitFeature : BaseFeature("ratelimit", "0.0.1", true) {
45
45
  }
46
46
 
47
47
  private fun acquire() {
48
+ val wait = reserve()
49
+ if (wait > 0) {
50
+ FeatureOptions.foptSleep(this.options).accept(wait)
51
+ }
52
+ }
53
+
54
+ // Refill, then reserve this call's token before any wait, under the lock:
55
+ // a negative count is the calls already queued, so overlapping calls pace
56
+ // in turn.
57
+ @Synchronized
58
+ private fun reserve(): Int {
48
59
  val rate = FeatureOptions.foptNum(this.options, "rate", 5.0)
49
60
  val burst = FeatureOptions.foptNum(this.options, "burst", rate)
50
61
 
51
- // Refill according to elapsed time.
52
62
  val now = FeatureOptions.foptNow(this.options).getAsLong()
53
63
  val elapsed = now - this.last
54
64
  this.last = now
55
- this.tokens = min(burst, this.tokens + (elapsed / 1000.0) * rate)
65
+ this.tokens = min(burst, this.tokens + (elapsed / 1000.0) * rate) - 1
56
66
 
57
- if (this.tokens >= 1) {
58
- this.tokens -= 1
59
- return
67
+ if (this.tokens >= 0) {
68
+ return 0
60
69
  }
61
70
 
62
- // Not enough tokens: wait for one to accrue, then consume it.
63
- val needed = 1 - this.tokens
64
- val wait = ceil((needed / rate) * 1000).toInt()
71
+ val wait = ceil((-this.tokens / rate) * 1000).toInt()
65
72
  track(wait)
66
- if (wait > 0) {
67
- FeatureOptions.foptSleep(this.options).accept(wait)
68
- }
69
- this.last = FeatureOptions.foptNow(this.options).getAsLong()
70
- this.tokens = 0.0
73
+ return wait
71
74
  }
72
75
 
73
76
  private fun track(wait: Int) {
@@ -76,10 +76,9 @@ class RetryFeature : BaseFeature("retry", "0.0.1", true) {
76
76
  if (status < 0) {
77
77
  return false
78
78
  }
79
- var statuses: List<Any?>? = FeatureOptions.foptList(this.options, "statuses")
80
- if (statuses == null) {
81
- statuses = listOf(408, 425, 429, 500, 502, 503, 504)
82
- }
79
+ // Any list as given, read-only ones included; only absent or null is unset.
80
+ val statuses = this.options?.get("statuses") as? List<*>
81
+ ?: listOf(408, 425, 429, 500, 502, 503, 504)
83
82
  for (s in statuses) {
84
83
  if (s is Number && s.toInt() == status) {
85
84
  return true
@@ -89,7 +88,7 @@ class RetryFeature : BaseFeature("retry", "0.0.1", true) {
89
88
  }
90
89
 
91
90
  private fun backoff(res: Any?, attempt: Int, minDelay: Int, maxDelay: Int, factor: Double): Int {
92
- // Honour a server-provided Retry-After (seconds) when present.
91
+ // A server-provided Retry-After wins over the computed backoff.
93
92
  val ra = retryAfter(res)
94
93
  if (ra >= 0) {
95
94
  return minOf(ra, maxDelay)
@@ -103,16 +102,39 @@ class RetryFeature : BaseFeature("retry", "0.0.1", true) {
103
102
  return minOf(wait, maxDelay)
104
103
  }
105
104
 
106
- private fun retryAfter(res: Any?): Int {
107
- val v = FeatureOptions.fresHeader(res, "retry-after")
108
- if ("" == v) {
109
- return -1
110
- }
111
- val seconds = FeatureOptions.fparseInt(v, -1)
112
- if (seconds < 0) {
113
- return -1
105
+ private fun retryAfter(res: Any?): Int =
106
+ retryAfterMs(FeatureOptions.fresHeader(res, "retry-after"), System.currentTimeMillis())
107
+
108
+ companion object {
109
+ private const val MONTHS = "JanFebMarAprMayJunJulAugSepOctNovDec"
110
+
111
+ private val IMF_FIXDATE = Regex(
112
+ "(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-9]{2}) ([A-Z][a-z]{2}) ([0-9]{4}) " +
113
+ "([0-9]{2}):([0-9]{2}):([0-9]{2}) GMT")
114
+
115
+ // RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else -1.
116
+ fun retryAfterMs(value: String, now: Long): Int {
117
+ val s = value.trim(' ', '\t')
118
+ if (s.isNotEmpty() && s.all { it in '0'..'9' }) {
119
+ return if (s.length > 6) Int.MAX_VALUE else s.toInt() * 1000
120
+ }
121
+ val m = IMF_FIXDATE.matchEntire(s) ?: return -1
122
+ val g = m.groupValues
123
+ val month = MONTHS.indexOf(g[2])
124
+ if (month < 0 || month % 3 != 0) {
125
+ return -1
126
+ }
127
+ val sec = g[6].toInt()
128
+ return try {
129
+ val at = java.time.LocalDateTime.of(g[3].toInt(), month / 3 + 1, g[1].toInt(),
130
+ g[4].toInt(), g[5].toInt(), minOf(sec, 59))
131
+ .toEpochSecond(java.time.ZoneOffset.UTC) * 1000 + (if (sec > 59) 1000 else 0)
132
+ minOf(Int.MAX_VALUE.toLong(), maxOf(0L, at - now)).toInt()
133
+ }
134
+ catch (e: java.time.DateTimeException) {
135
+ -1
136
+ }
114
137
  }
115
- return seconds * 1000
116
138
  }
117
139
 
118
140
  private fun sleep(ms: Int) {