@voxgig/sdkgen 4.51.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 (289) 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 +1 -1
  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/src/cmp/c/TestClean_c.ts +12 -11
  32. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +17 -10
  33. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +18 -1
  34. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +2 -1
  35. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +30 -2
  36. package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +31 -12
  37. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +2 -1
  38. package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +51 -15
  39. package/project/.sdk/src/cmp/elixir/fragment/Pipeline.fragment.ex +17 -0
  40. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +42 -2
  41. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +42 -14
  42. package/project/.sdk/src/cmp/java/TestClean_java.ts +9 -4
  43. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +21 -0
  44. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +13 -8
  45. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +26 -2
  46. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +8 -0
  47. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +8 -0
  48. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +8 -0
  49. package/project/.sdk/src/cmp/js/fragment/EntityPatchOp.fragment.js +8 -0
  50. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +8 -0
  51. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +8 -0
  52. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +12 -5
  53. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +9 -4
  54. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +19 -0
  55. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +2 -1
  56. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +42 -5
  57. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +44 -10
  58. package/project/.sdk/src/cmp/lua/utility_lua.ts +2 -1
  59. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +2 -1
  60. package/project/.sdk/src/cmp/ocaml/fragment/RunOp.fragment.ml +36 -21
  61. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +1 -1
  62. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +21 -0
  63. package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +31 -12
  64. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +33 -4
  65. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +13 -6
  66. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +25 -2
  67. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +26 -12
  68. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +1 -1
  69. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +23 -2
  70. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +27 -11
  71. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +14 -17
  72. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +22 -2
  73. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +11 -11
  74. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +14 -0
  75. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +11 -11
  76. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +9 -0
  77. package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +24 -10
  78. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +13 -8
  79. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +26 -2
  80. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +8 -0
  81. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +8 -0
  82. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +8 -0
  83. package/project/.sdk/src/cmp/ts/fragment/EntityPatchOp.fragment.ts +8 -0
  84. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +8 -0
  85. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +8 -0
  86. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +12 -5
  87. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +11 -11
  88. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +17 -10
  89. package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +41 -6
  90. package/project/.sdk/tm/c/feature/metrics.c +7 -0
  91. package/project/.sdk/tm/c/feature/paging.c +231 -2
  92. package/project/.sdk/tm/c/feature/ratelimit.c +5 -9
  93. package/project/.sdk/tm/c/feature/retry.c +51 -4
  94. package/project/.sdk/tm/c/feature/streaming.c +2 -1
  95. package/project/.sdk/tm/c/feature/telemetry.c +19 -18
  96. package/project/.sdk/tm/c/feature/test.c +78 -54
  97. package/project/.sdk/tm/c/tests/feature_test.c +184 -0
  98. package/project/.sdk/tm/c/tests/primary_utility_test.c +2 -0
  99. package/project/.sdk/tm/c/utility/make_options.c +80 -9
  100. package/project/.sdk/tm/clojure/src/sdk/core.clj +31 -11
  101. package/project/.sdk/tm/clojure/src/sdk/features.clj +198 -70
  102. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +70 -1
  103. package/project/.sdk/tm/cpp/core/types.hpp +137 -68
  104. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -1
  105. package/project/.sdk/tm/cpp/feature/metrics.hpp +19 -0
  106. package/project/.sdk/tm/cpp/feature/paging.hpp +160 -2
  107. package/project/.sdk/tm/cpp/feature/ratelimit.hpp +18 -14
  108. package/project/.sdk/tm/cpp/feature/retry.hpp +46 -5
  109. package/project/.sdk/tm/cpp/feature/streaming.hpp +2 -1
  110. package/project/.sdk/tm/cpp/feature/telemetry.hpp +17 -10
  111. package/project/.sdk/tm/cpp/feature/test.hpp +63 -53
  112. package/project/.sdk/tm/cpp/test/feature_test.cpp +137 -0
  113. package/project/.sdk/tm/cpp/utility/pipeline.hpp +35 -5
  114. package/project/.sdk/tm/csharp/feature/AuditFeature.cs +8 -1
  115. package/project/.sdk/tm/csharp/feature/MetricsFeature.cs +23 -0
  116. package/project/.sdk/tm/csharp/feature/PagingFeature.cs +130 -3
  117. package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +26 -19
  118. package/project/.sdk/tm/csharp/feature/RetryFeature.cs +41 -7
  119. package/project/.sdk/tm/csharp/feature/StreamingFeature.cs +2 -1
  120. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +11 -9
  121. package/project/.sdk/tm/csharp/feature/TestFeature.cs +55 -67
  122. package/project/.sdk/tm/csharp/test/FeatureTest.cs +162 -0
  123. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +89 -12
  124. package/project/.sdk/tm/elixir/lib/projectname/feature/metrics.ex +13 -0
  125. package/project/.sdk/tm/elixir/lib/projectname/feature/paging.ex +110 -5
  126. package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +6 -12
  127. package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +33 -9
  128. package/project/.sdk/tm/elixir/lib/projectname/feature/streaming.ex +2 -1
  129. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +7 -7
  130. package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +52 -48
  131. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +59 -35
  132. package/project/.sdk/tm/elixir/test/feature_test.exs +137 -0
  133. package/project/.sdk/tm/go/feature/audit_feature.go +1 -3
  134. package/project/.sdk/tm/go/feature/base_feature.go +11 -0
  135. package/project/.sdk/tm/go/feature/metrics_feature.go +14 -0
  136. package/project/.sdk/tm/go/feature/paging_feature.go +108 -2
  137. package/project/.sdk/tm/go/feature/ratelimit_feature.go +19 -17
  138. package/project/.sdk/tm/go/feature/retry_feature.go +81 -9
  139. package/project/.sdk/tm/go/feature/streaming_feature.go +2 -1
  140. package/project/.sdk/tm/go/feature/telemetry_feature.go +18 -11
  141. package/project/.sdk/tm/go/feature/test_feature.go +65 -55
  142. package/project/.sdk/tm/go/test/feature_corpus_test.go +209 -28
  143. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  144. package/project/.sdk/tm/go/utility/make_options.go +111 -6
  145. package/project/.sdk/tm/java/core/SdkClient.java +43 -14
  146. package/project/.sdk/tm/java/feature/AuditFeature.java +5 -1
  147. package/project/.sdk/tm/java/feature/MetricsFeature.java +31 -0
  148. package/project/.sdk/tm/java/feature/PagingFeature.java +156 -2
  149. package/project/.sdk/tm/java/feature/RatelimitFeature.java +15 -13
  150. package/project/.sdk/tm/java/feature/RetryFeature.java +33 -6
  151. package/project/.sdk/tm/java/feature/StreamingFeature.java +2 -1
  152. package/project/.sdk/tm/java/feature/TelemetryFeature.java +17 -9
  153. package/project/.sdk/tm/java/feature/TestFeature.java +50 -63
  154. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +170 -17
  155. package/project/.sdk/tm/java/utility/MakeOptions.java +128 -14
  156. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +8 -3
  157. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +99 -1
  158. package/project/.sdk/tm/js/src/feature/ratelimit/RatelimitFeature.js +5 -9
  159. package/project/.sdk/tm/js/src/feature/retry/RetryFeature.js +25 -3
  160. package/project/.sdk/tm/js/src/feature/streaming/StreamingFeature.js +2 -1
  161. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +11 -6
  162. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +38 -1
  163. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +55 -6
  164. package/project/.sdk/tm/js/test/feature/Corpus.test.js +95 -25
  165. package/project/.sdk/tm/js/test/feature.test.js +14 -1
  166. package/project/.sdk/tm/kotlin/core/SdkClient.kt +23 -10
  167. package/project/.sdk/tm/kotlin/feature/AuditFeature.kt +5 -1
  168. package/project/.sdk/tm/kotlin/feature/MetricsFeature.kt +22 -0
  169. package/project/.sdk/tm/kotlin/feature/PagingFeature.kt +125 -2
  170. package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +16 -13
  171. package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +36 -14
  172. package/project/.sdk/tm/kotlin/feature/StreamingFeature.kt +4 -0
  173. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +12 -10
  174. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +45 -48
  175. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +114 -0
  176. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +83 -14
  177. package/project/.sdk/tm/lua/feature/debug_feature.lua +2 -3
  178. package/project/.sdk/tm/lua/feature/metrics_feature.lua +5 -0
  179. package/project/.sdk/tm/lua/feature/paging_feature.lua +143 -2
  180. package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +5 -9
  181. package/project/.sdk/tm/lua/feature/retry_feature.lua +43 -5
  182. package/project/.sdk/tm/lua/feature/streaming_feature.lua +2 -1
  183. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +18 -7
  184. package/project/.sdk/tm/lua/feature/test_feature.lua +60 -62
  185. package/project/.sdk/tm/lua/test/feature_test.lua +100 -3
  186. package/project/.sdk/tm/lua/utility/make_options.lua +55 -13
  187. package/project/.sdk/tm/ocaml/sdk_features.ml +286 -60
  188. package/project/.sdk/tm/ocaml/sdk_runtime.ml +34 -11
  189. package/project/.sdk/tm/ocaml/test/t_feature.ml +72 -1
  190. package/project/.sdk/tm/perl/feature/debug_feature.pm +2 -2
  191. package/project/.sdk/tm/perl/feature/metrics_feature.pm +5 -0
  192. package/project/.sdk/tm/perl/feature/paging_feature.pm +139 -2
  193. package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +5 -11
  194. package/project/.sdk/tm/perl/feature/retry_feature.pm +22 -4
  195. package/project/.sdk/tm/perl/feature/streaming_feature.pm +2 -0
  196. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +17 -8
  197. package/project/.sdk/tm/perl/feature/test_feature.pm +45 -50
  198. package/project/.sdk/tm/perl/t/feature.t +2 -2
  199. package/project/.sdk/tm/perl/t/feature_corpus.t +126 -23
  200. package/project/.sdk/tm/perl/utility/make_options.pm +33 -10
  201. package/project/.sdk/tm/php/feature/MetricsFeature.php +8 -0
  202. package/project/.sdk/tm/php/feature/PagingFeature.php +128 -1
  203. package/project/.sdk/tm/php/feature/RatelimitFeature.php +5 -9
  204. package/project/.sdk/tm/php/feature/RetryFeature.php +27 -3
  205. package/project/.sdk/tm/php/feature/StreamingFeature.php +2 -1
  206. package/project/.sdk/tm/php/feature/TelemetryFeature.php +10 -7
  207. package/project/.sdk/tm/php/feature/TestFeature.php +55 -47
  208. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +151 -16
  209. package/project/.sdk/tm/php/utility/MakeOptions.php +40 -13
  210. package/project/.sdk/tm/py/pkg/feature/metrics_feature.py +7 -0
  211. package/project/.sdk/tm/py/pkg/feature/paging_feature.py +86 -1
  212. package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +13 -16
  213. package/project/.sdk/tm/py/pkg/feature/retry_feature.py +31 -6
  214. package/project/.sdk/tm/py/pkg/feature/streaming_feature.py +2 -1
  215. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +10 -6
  216. package/project/.sdk/tm/py/pkg/feature/test_feature.py +56 -53
  217. package/project/.sdk/tm/py/pkg/utility/make_options.py +68 -20
  218. package/project/.sdk/tm/py/test/test_feature.py +11 -1
  219. package/project/.sdk/tm/py/test/test_feature_corpus.py +111 -16
  220. package/project/.sdk/tm/py-data/pkg/fetch.py +6 -3
  221. package/project/.sdk/tm/py-data/test/test_fetch.py +7 -4
  222. package/project/.sdk/tm/rb/feature/debug_feature.rb +2 -2
  223. package/project/.sdk/tm/rb/feature/metrics_feature.rb +8 -0
  224. package/project/.sdk/tm/rb/feature/paging_feature.rb +87 -1
  225. package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +12 -16
  226. package/project/.sdk/tm/rb/feature/retry_feature.rb +19 -3
  227. package/project/.sdk/tm/rb/feature/streaming_feature.rb +2 -1
  228. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +11 -6
  229. package/project/.sdk/tm/rb/feature/test_feature.rb +42 -49
  230. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +108 -24
  231. package/project/.sdk/tm/rb/test/feature_test.rb +1 -1
  232. package/project/.sdk/tm/rb/utility/make_options.rb +32 -11
  233. package/project/.sdk/tm/rust/feature/audit.rs +2 -2
  234. package/project/.sdk/tm/rust/feature/metrics.rs +24 -1
  235. package/project/.sdk/tm/rust/feature/paging.rs +189 -3
  236. package/project/.sdk/tm/rust/feature/ratelimit.rs +5 -10
  237. package/project/.sdk/tm/rust/feature/retry.rs +59 -6
  238. package/project/.sdk/tm/rust/feature/streaming.rs +3 -2
  239. package/project/.sdk/tm/rust/feature/support.rs +4 -0
  240. package/project/.sdk/tm/rust/feature/telemetry.rs +22 -11
  241. package/project/.sdk/tm/rust/feature/test.rs +63 -57
  242. package/project/.sdk/tm/rust/tests/feature_test.rs +174 -0
  243. package/project/.sdk/tm/rust/tests/primary_utility_test.rs +1 -0
  244. package/project/.sdk/tm/rust/utility/make_options.rs +122 -27
  245. package/project/.sdk/tm/scala/core/SdkClient.scala +45 -11
  246. package/project/.sdk/tm/scala/feature/AuditFeature.scala +6 -1
  247. package/project/.sdk/tm/scala/feature/MetricsFeature.scala +31 -1
  248. package/project/.sdk/tm/scala/feature/PagingFeature.scala +122 -2
  249. package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +14 -11
  250. package/project/.sdk/tm/scala/feature/RetryFeature.scala +29 -7
  251. package/project/.sdk/tm/scala/feature/StreamingFeature.scala +2 -1
  252. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +12 -10
  253. package/project/.sdk/tm/scala/feature/TestFeature.scala +44 -44
  254. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +41 -0
  255. package/project/.sdk/tm/scala/utility/Make.scala +96 -13
  256. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/AuditFeature.swift +3 -2
  257. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/MetricsFeature.swift +20 -0
  258. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/PagingFeature.swift +102 -2
  259. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +19 -13
  260. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +40 -5
  261. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/StreamingFeature.swift +2 -1
  262. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +11 -9
  263. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +55 -49
  264. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +51 -13
  265. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +111 -0
  266. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +5 -0
  267. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +99 -1
  268. package/project/.sdk/tm/ts/src/feature/ratelimit/RatelimitFeature.ts +5 -9
  269. package/project/.sdk/tm/ts/src/feature/retry/RetryFeature.ts +25 -3
  270. package/project/.sdk/tm/ts/src/feature/streaming/StreamingFeature.ts +2 -1
  271. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +11 -6
  272. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +8 -7
  273. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +57 -6
  274. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +95 -25
  275. package/project/.sdk/tm/ts/test/feature.test.ts +14 -1
  276. package/project/.sdk/tm/zig/core/utility.zig +107 -8
  277. package/project/.sdk/tm/zig/feature/metrics.zig +19 -0
  278. package/project/.sdk/tm/zig/feature/paging.zig +172 -4
  279. package/project/.sdk/tm/zig/feature/ratelimit.zig +5 -11
  280. package/project/.sdk/tm/zig/feature/retry.zig +41 -3
  281. package/project/.sdk/tm/zig/feature/streaming.zig +2 -0
  282. package/project/.sdk/tm/zig/feature/telemetry.zig +15 -9
  283. package/project/.sdk/tm/zig/feature/test.zig +56 -40
  284. package/project/.sdk/tm/zig/test/feature_test.zig +109 -0
  285. package/project/.sdk/tm/zig/test/primary_utility_test.zig +2 -0
  286. package/project/sdkgen-package.json +1 -1
  287. package/src/cmp/ReadmeExplanation.ts +5 -2
  288. package/src/cmp/ReadmeFeatures.ts +21 -6
  289. package/src/helpers/optspec.ts +2 -2
@@ -1802,6 +1802,25 @@
1802
1802
  :else [[nil feature]])]
1803
1803
  (u-clean-add-sensitive ctx (plain fopts fname)))))
1804
1804
 
1805
+ ;; The model's options for a feature sit beneath the caller's, key by key: a
1806
+ ;; key the caller sets replaces the default whole, so a list is never merged.
1807
+ (defn- feature-defaults! [opts cfgfeature]
1808
+ (let [given (vs/getprop opts "feature")]
1809
+ (when (and (vs/ismap cfgfeature) (or (nil? given) (vs/ismap given)))
1810
+ (let [out (vs/jm)]
1811
+ (when (vs/ismap given)
1812
+ (doseq [k (vs/keysof given)] (.put ^java.util.Map out k (vs/getprop given k))))
1813
+ (doseq [fname (vs/keysof cfgfeature)]
1814
+ (let [dflt (vs/getprop (vs/getprop cfgfeature fname) "options")
1815
+ fopts (vs/getprop out fname)]
1816
+ (when (and (vs/ismap dflt)
1817
+ (if (nil? fopts) (true? (vs/getprop dflt "active")) (vs/ismap fopts)))
1818
+ (let [merged (vs/clone dflt)]
1819
+ (when (vs/ismap fopts)
1820
+ (doseq [k (vs/keysof fopts)] (.put ^java.util.Map merged k (vs/getprop fopts k))))
1821
+ (.put ^java.util.Map out fname merged)))))
1822
+ (.put ^java.util.Map opts "feature" out)))))
1823
+
1805
1824
  (defn u-make-options [ctx]
1806
1825
  (let [options (or (oget ctx :options) (vs/jm))
1807
1826
  custom-utils (vs/getprop options "utility")]
@@ -1857,6 +1876,7 @@
1857
1876
  order)))
1858
1877
  config (or (oget ctx :config) (vs/jm))
1859
1878
  cfgopts (let [c (vs/getprop config "options")] (if (vs/ismap c) c (vs/jm)))
1879
+ _ (feature-defaults! opts0 (vs/getprop config "feature"))
1860
1880
  ;; THE OPTION SPEC IS GENERATED, NOT WRITTEN HERE.
1861
1881
  ;;
1862
1882
  ;; Built from the model: main.kit.optspec for the standard
@@ -1928,18 +1948,18 @@
1928
1948
  (when (not (vs/ismap (vs/getprop opts "system"))) (.put ^java.util.Map opts "system" (vs/jm)))
1929
1949
  (.put ^java.util.Map (vs/getprop opts "system") "fetch" sys-fetch))
1930
1950
  (let [;; Resolve the feature add-order: an explicit array order (above)
1931
- ;; wins; otherwise order the map test-first, then the remaining
1932
- ;; names sorted, so the outcome is deterministic and `test` is
1933
- ;; always the base transport.
1951
+ ;; wins, and the names it leaves out follow it test-first, then
1952
+ ;; sorted, so the outcome is deterministic and `test` is the base
1953
+ ;; transport of a map.
1934
1954
  feature-order
1935
- (if explicit-order
1936
- explicit-order
1937
- (let [fmap (let [f (vs/getprop opts "feature")] (if (vs/ismap f) f (vs/jm)))
1938
- names (vec (sort (map str (or (vs/keysof fmap) []))))
1939
- order (vs/jt)]
1940
- (when (some #(= % "test") names) (.add ^java.util.List order "test"))
1941
- (doseq [n names] (when (not= n "test") (.add ^java.util.List order n)))
1942
- order))
1955
+ (let [fmap (let [f (vs/getprop opts "feature")] (if (vs/ismap f) f (vs/jm)))
1956
+ given (set (or explicit-order []))
1957
+ names (vec (sort (remove given (map str (or (vs/keysof fmap) [])))))
1958
+ order (vs/jt)]
1959
+ (doseq [n (or explicit-order [])] (.add ^java.util.List order n))
1960
+ (when (some #(= % "test") names) (.add ^java.util.List order "test"))
1961
+ (doseq [n names] (when (not= n "test") (.add ^java.util.List order n)))
1962
+ order)
1943
1963
  derived (vs/jm "featureorder" feature-order)]
1944
1964
  (.put ^java.util.Map opts "__derived__" derived)
1945
1965
  ;; Beside the options, not in them: options-map hands them to callers.
@@ -178,18 +178,10 @@
178
178
  [out nil]))
179
179
  op (core/oget fctx :op)
180
180
  entmap (let [em (vs/getprop entity (core/op-entity op))] (if (vs/ismap em) em (vs/jm)))
181
- resolve-match (fn [explicit]
182
- (if (and (vs/ismap explicit) (pos? (vs/size explicit))) explicit
183
- (loop [srcs [(core/oget fctx :match) (core/oget fctx :data)]]
184
- (if (empty? srcs) (vs/jm)
185
- (let [src (first srcs)
186
- v (when src (vs/getprop src "id"))]
187
- (if (and (some? v) (not= v "__UNDEFINED__")) (vs/jm "id" v)
188
- (recur (rest srcs))))))))
189
181
  opn (core/op-name op)]
190
182
  (cond
191
183
  (= opn "load")
192
- (let [args (test-build-args fctx op (resolve-match (core/oget fctx :reqmatch)))
184
+ (let [args (test-build-args fctx op (core/oget fctx :reqmatch))
193
185
  found (vs/select entmap args)
194
186
  ent (vs/getelem found 0)]
195
187
  (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
@@ -201,28 +193,20 @@
201
193
  (do (when (vs/islist found) (doseq [item (vec found)] (vs/delprop item "$KEY")))
202
194
  (respond 200 (vs/clone found) nil))))
203
195
  (or (= opn "update") (= opn "patch"))
204
- (let [update-match (vs/jm)
205
- reqdata (core/oget fctx :reqdata)]
206
- (when (vs/ismap reqdata)
207
- (when (contains? (into #{} (vs/keysof reqdata)) "id")
208
- (.put ^java.util.Map update-match "id" (vs/getprop reqdata "id")))
209
- (when-let [am (core/op-alias op)]
210
- (let [alias-id (vs/getprop am "id")]
211
- (when (and alias-id (contains? (into #{} (vs/keysof reqdata)) alias-id))
212
- (.put ^java.util.Map update-match alias-id (vs/getprop reqdata alias-id))))))
213
- (let [update-match (if (zero? (vs/size update-match)) (resolve-match (vs/jm)) update-match)
214
- args (test-build-args fctx op update-match)
215
- found (vs/select entmap args)
216
- ent (vs/getelem found 0)]
217
- ;; update miss: 404, never another record
218
- (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
219
- (do (when (and (vs/ismap ent) (vs/ismap reqdata))
220
- ;; `$body` travels on the wire alone; the record is the rest.
221
- (vs/merge (vs/jt ent (doto (vs/clone reqdata) (vs/delprop "$body")))))
222
- (vs/delprop ent "$KEY")
223
- (respond 200 (vs/clone ent) nil)))))
196
+ (let [reqdata (core/oget fctx :reqdata)
197
+ ;; `$body` travels on the wire alone; the record is the rest.
198
+ rec (if (vs/ismap reqdata) (doto (vs/clone reqdata) (vs/delprop "$body")) (vs/jm))
199
+ args (test-build-args fctx op rec)
200
+ found (vs/select entmap args)
201
+ ent (vs/getelem found 0)]
202
+ ;; update miss: 404, never another record
203
+ (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
204
+ (do (when (and (vs/ismap ent) (vs/ismap reqdata))
205
+ (vs/merge (vs/jt ent rec)))
206
+ (vs/delprop ent "$KEY")
207
+ (respond 200 (vs/clone ent) nil))))
224
208
  (= opn "remove")
225
- (let [args (test-build-args fctx op (resolve-match (core/oget fctx :reqmatch)))
209
+ (let [args (test-build-args fctx op (core/oget fctx :reqmatch))
226
210
  found (vs/select entmap args)
227
211
  ent (vs/getelem found 0)]
228
212
  (when (vs/ismap ent) (vs/delprop entmap (vs/getprop ent "id")))
@@ -283,18 +267,36 @@
283
267
  ;; (e.g. GET /result?trace_id=), which has no path param at all.
284
268
  reqd-params (reqd-names point "params")
285
269
  reqd-query (reqd-names point "query")
286
- qand (vs/jt)]
287
- (when args
288
- (doseq [key (or (vs/keysof args) [])]
289
- (let [is-id (= key "id")
290
- is-reqd (or (not (vs/isempty (vs/select reqd-params key)))
291
- (not (vs/isempty (vs/select reqd-query key))))]
292
- (when (or is-id is-reqd)
293
- (let [v ((core/uget ctx :param) ctx key)
294
- ka (when (core/op-alias op) (vs/getprop (core/op-alias op) key))
295
- qor (vs/jt (vs/jm key v))]
296
- (when (string? ka) (.add ^java.util.List qor (vs/jm ka v)))
297
- (.add ^java.util.List qand (vs/jm "`$OR`" qor)))))))
270
+ qand (vs/jt)
271
+ ename (core/entity-get-name (core/oget ctx :entity))
272
+ idfrom (vs/getpath (core/oget ctx :config) (str "entity." ename ".id.from"))
273
+ held (fn [src k] (let [v (when src (vs/getprop src k))] (and (some? v) (not= v "__UNDEFINED__"))))
274
+ given (vec (or (when args (vs/keysof args)) []))
275
+ ;; With no id in the call, the entity's held id (or composite parts) stands in.
276
+ names (if (held args "id") given
277
+ (let [declared (vs/getpath (core/oget ctx :config) (str "entity." ename ".id.parts"))
278
+ parts (if (vs/islist declared) (map str (vec declared)) (if (= opname "list") [] ["id"]))]
279
+ (reduce (fn [acc p]
280
+ (if (and (not (some #{p} acc))
281
+ (or (held (core/oget ctx :match) p) (held (core/oget ctx :data) p)))
282
+ (conj acc p) acc))
283
+ given parts)))]
284
+ (doseq [key names]
285
+ (let [is-id (= key "id")
286
+ is-reqd (or (not (vs/isempty (vs/select reqd-params key)))
287
+ (not (vs/isempty (vs/select reqd-query key))))]
288
+ (when (or is-id is-reqd)
289
+ (let [v ((core/uget ctx :param) ctx key)
290
+ ka (when (core/op-alias op) (vs/getprop (core/op-alias op) key))
291
+ kf (when (vs/ismap idfrom) (vs/getprop idfrom key))
292
+ qor (vs/jt (vs/jm key v))]
293
+ (when (string? ka) (.add ^java.util.List qor (vs/jm ka v)))
294
+ ;; An alternative, never a replacement: a seed keeping the parameter
295
+ ;; flat is still found.
296
+ (when (and (string? kf) (not= kf key))
297
+ (.add ^java.util.List qor (reduce (fn [acc seg] (vs/jm seg acc)) v
298
+ (reverse (clojure.string/split kf #"\.")))))
299
+ (.add ^java.util.List qand (vs/jm "`$OR`" qor))))))
298
300
  (let [q (vs/jm "`$AND`" qand)]
299
301
  (when-let [ex (core/oget (core/oget ctx :ctrl) :explain)] (.put ^java.util.Map ex "test" (vs/jm "query" q)))
300
302
  q)))
@@ -348,6 +350,28 @@
348
350
  (boolean (some #(= (long %) (long status)) (vec statuses))))
349
351
  false))))
350
352
 
353
+ (def ^:private imf-fixdate
354
+ #"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-9]{2}) ([A-Z][a-z]{2}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) GMT")
355
+
356
+ (def ^:private months ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"])
357
+
358
+ ;; RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else nil.
359
+ (defn retry-after-value [value now]
360
+ (let [s (str/replace value #"^[ \t]+|[ \t]+$" "")]
361
+ (if (re-matches #"[0-9]+" s)
362
+ (* 1000 (if (> (count s) 12) 999999999999 (Long/parseLong s)))
363
+ (when-let [[_ day mon year hour minute sec] (re-matches imf-fixdate s)]
364
+ (let [mi (.indexOf ^java.util.List months mon)
365
+ [d y hh mm ss] (map #(Long/parseLong %) [day year hour minute sec])]
366
+ (when (and (>= mi 0) (<= 1 d 31) (<= hh 23) (<= mm 59) (<= ss 60))
367
+ (try
368
+ (let [at (+ (* 1000 (.toEpochSecond (java.time.LocalDateTime/of (int y) (int (inc mi)) (int d)
369
+ (int hh) (int mm) (int (min ss 59)))
370
+ java.time.ZoneOffset/UTC))
371
+ (if (> ss 59) 1000 0))]
372
+ (max 0 (- at now)))
373
+ (catch java.time.DateTimeException _ nil))))))))
374
+
351
375
  (defn- retry-after-ms [res]
352
376
  (when (vs/ismap res)
353
377
  (let [headers (vs/getprop res "headers")]
@@ -357,7 +381,7 @@
357
381
  (when (= (str/lower-case (str (vs/getprop item 0))) "retry-after")
358
382
  (reset! v (vs/getprop item 1))))
359
383
  (when (some? @v)
360
- (try (long (* (Double/parseDouble (str @v)) 1000)) (catch Exception _ nil))))))))
384
+ (retry-after-value (str @v) (System/currentTimeMillis))))))))
361
385
 
362
386
  (defn- retry-backoff [fa res attempt min-delay max-delay factor]
363
387
  (let [ra (retry-after-ms res)]
@@ -444,20 +468,22 @@
444
468
  (let [t (track-ensure! fa "_ratelimit" (vs/jm "throttled" 0 "waitMs" 0))]
445
469
  (.put ^java.util.Map t "throttled" (inc (long (mget t "throttled"))))
446
470
  (.put ^java.util.Map t "waitMs" (+ (long (mget t "waitMs")) (long wait-ms)))))
471
+ ;; Refill, then reserve this call's token before any wait, under the
472
+ ;; lock: a negative count is the calls already queued, so overlapping
473
+ ;; calls pace in turn.
447
474
  acquire (fn [_ctx]
448
475
  (let [rate (opt fa "rate" 5)
449
476
  burst (opt fa "burst" rate)
450
- now (now-ms fa)
451
- elapsed (- now (:last @fa))]
452
- (swap! fa assoc :last now)
453
- (swap! fa assoc :tokens (min burst (+ (:tokens @fa) (* (/ elapsed 1000.0) rate))))
454
- (if (>= (:tokens @fa) 1)
455
- (swap! fa update :tokens dec)
456
- (let [needed (- 1 (:tokens @fa))
457
- wait-ms (long (Math/ceil (* (/ needed (double rate)) 1000)))]
458
- (track! wait-ms)
459
- (sleep-ms fa wait-ms)
460
- (swap! fa assoc :last (now-ms fa) :tokens 0)))))]
477
+ wait-ms (locking fa
478
+ (let [now (now-ms fa)
479
+ refilled (+ (:tokens @fa) (* (/ (- now (:last @fa)) 1000.0) rate))
480
+ tokens (- (min burst refilled) 1)]
481
+ (swap! fa assoc :last now :tokens tokens)
482
+ (when (neg? tokens)
483
+ (let [w (long (Math/ceil (* (/ (- tokens) (double rate)) 1000)))]
484
+ (track! w)
485
+ w))))]
486
+ (when wait-ms (sleep-ms fa wait-ms))))]
461
487
  (swap! fa assoc
462
488
  "init" (fn [ctx options]
463
489
  (swap! fa assoc :client (core/oget ctx :client)
@@ -668,6 +694,82 @@
668
694
  (or (try (Long/parseLong s) (catch Exception _ nil))
669
695
  (try (Double/parseDouble s) (catch Exception _ nil))))))
670
696
 
697
+ ;; Under the `next` option's default, a URL or an absolute path is a link and
698
+ ;; anything else a cursor; `cursor` and `url` pin the reading.
699
+ (def ^:private paging-origin #"(?i)^[a-z][a-z0-9+.-]*://[^/?#]*")
700
+
701
+ (defn- paging-link? [nxt mode]
702
+ (and (string? nxt)
703
+ (or (= "url" mode)
704
+ (and (not= "cursor" mode)
705
+ (or (some? (re-find paging-origin nxt)) (str/starts-with? nxt "/"))))))
706
+
707
+ (defn- paging-origin-of [text]
708
+ (str/lower-case (or (when (string? text) (re-find paging-origin text)) "")))
709
+
710
+ (defn- paging-foreign? [link base]
711
+ (let [origin (paging-origin-of link)]
712
+ (and (seq origin) (not= origin (paging-origin-of base)))))
713
+
714
+ (defn- paging-unescape [text]
715
+ (try (java.net.URLDecoder/decode ^String text "UTF-8") (catch Exception _ text)))
716
+
717
+ ;; RFC 3986 section 5.2.4.
718
+ (defn- paging-remove-dots [path]
719
+ (let [abs (str/starts-with? path "/")
720
+ segs (vec (.split ^String path "/" -1))
721
+ segs (if abs (subvec segs 1) segs)
722
+ n (count segs)
723
+ out (reduce (fn [out [i seg]]
724
+ (if (contains? #{"." ".."} seg)
725
+ (cond-> (if (and (= ".." seg) (seq out)) (pop out) out)
726
+ (= i (dec n)) (conj ""))
727
+ (conj out seg)))
728
+ [] (map-indexed vector segs))]
729
+ (str (when abs "/") (str/join "/" out))))
730
+
731
+ ;; RFC 3986 reference resolution against the URL of the request that returned
732
+ ;; the link, by hand: java.net.URI resolves a query-only reference by RFC 2396
733
+ ;; and drops the last path segment. A link on that URL's origin comes back as
734
+ ;; its path and query; an absolute link is left as it is.
735
+ (defn- paging-resolve [link url]
736
+ (if (or (not (string? url)) (= "" url) (re-find #"(?i)^[a-z][a-z0-9+.-]*:" link))
737
+ link
738
+ (let [link (first (.split ^String link "#" 2))
739
+ origin (or (re-find paging-origin url) "")]
740
+ (if (str/starts-with? link "//")
741
+ (if (= "" origin) link (str (first (.split ^String origin ":" 2)) ":" link))
742
+ (let [from (first (.split ^String (subs url (count origin)) "#" 2))
743
+ after (fn [^String s] (when-let [k (str/index-of s "?")] (subs s (inc k))))
744
+ bpath (first (.split ^String from "\\?" 2))
745
+ rpath (first (.split ^String link "\\?" 2))
746
+ query (if (= "" rpath) (or (after link) (after from)) (after link))
747
+ path (cond
748
+ (= "" rpath) bpath
749
+ (str/starts-with? rpath "/") (paging-remove-dots rpath)
750
+ :else (paging-remove-dots
751
+ (str (subs bpath 0 (inc (or (str/last-index-of bpath "/") -1))) rpath)))
752
+ rooted (if (str/starts-with? path "/") path (str "/" path))]
753
+ (if (nil? query) rooted (str rooted "?" query)))))))
754
+
755
+ ;; The request goes to the link's path and query, on the SDK's own origin.
756
+ (defn- paging-follow! [spec nxt]
757
+ (let [link (first (str/split (str/replace-first nxt paging-origin "") #"#" 2))
758
+ [path rawquery] (str/split link #"\?" 2)
759
+ q (vs/jm)
760
+ old (core/oget spec :query)]
761
+ (doseq [pair (str/split (or rawquery "") #"&")
762
+ :when (seq pair)]
763
+ (let [[k v] (str/split pair #"=" 2)]
764
+ (.put ^java.util.Map q (paging-unescape k) (paging-unescape (or v "")))))
765
+ (doseq [k (core/oget spec :authquery [])]
766
+ (.put ^java.util.Map q k (mget old k)))
767
+ (core/oset! spec :base (or (re-find paging-origin (str (or (core/oget spec :base) ""))) ""))
768
+ (core/oset! spec :prefix "")
769
+ (core/oset! spec :path (or path ""))
770
+ (core/oset! spec :suffix "")
771
+ (core/oset! spec :query q)))
772
+
671
773
  ;; Relay pagination: the cursor is the `after` variable (or whatever the model
672
774
  ;; named it), and the page size is `first`.
673
775
  (defn- graphql-pre-request [fa spec point paging]
@@ -721,6 +823,9 @@
721
823
  (do
722
824
  (cond
723
825
  (some? (mget paging "cursor")) (.put ^java.util.Map q cursor-param (mget paging "cursor"))
826
+ (and (string? (mget paging "next"))
827
+ (not (paging-foreign? (mget paging "next") (core/oget spec :base))))
828
+ (paging-follow! spec (mget paging "next"))
724
829
  (nil? (mget q page-param))
725
830
  ;; A record written back by PreResult holds the page
726
831
  ;; just fetched as `page` and the one to fetch as
@@ -730,8 +835,9 @@
730
835
  (some? (mget paging "nextPage")) (mget paging "nextPage")
731
836
  (some? (mget paging "page")) (mget paging "page")
732
837
  :else (opt fa "startPage" 1))))
733
- (when (and (some? (opt fa "limit")) (nil? (mget q limit-param)))
734
- (.put ^java.util.Map q limit-param (opt fa "limit"))))))))))
838
+ (let [q (core/oget spec :query)]
839
+ (when (and (some? (opt fa "limit")) (nil? (mget q limit-param)))
840
+ (.put ^java.util.Map q limit-param (opt fa "limit")))))))))))
735
841
  "PreResult"
736
842
  (fn [ctx]
737
843
  (when (and (active? fa) (list? ctx))
@@ -773,7 +879,10 @@
773
879
  (.put ^java.util.Map paging "hasMore" more)
774
880
  (reset! explicit-more true))))))
775
881
  (when (vs/ismap body)
776
- (when (some? (mget body "next")) (when (nil? (mget paging "next")) (.put ^java.util.Map paging "next" (mget body "next"))))
882
+ (when (some? (mget body "next"))
883
+ (if (paging-link? (mget body "next") (opt fa "next" "auto"))
884
+ (when (nil? (mget paging "next")) (.put ^java.util.Map paging "next" (mget body "next")))
885
+ (.put ^java.util.Map paging "cursor" (mget body "next"))))
777
886
  ;; Both spellings, camelCase last so it wins when a
778
887
  ;; body carries the two.
779
888
  (when (some? (mget body "next_cursor")) (.put ^java.util.Map paging "cursor" (mget body "next_cursor")))
@@ -789,6 +898,15 @@
789
898
  (when (or (= hm true) (= hm false))
790
899
  (.put ^java.util.Map paging "hasMore" hm)
791
900
  (reset! explicit-more true)))))
901
+ ;; A link to another origin is recorded, never followed,
902
+ ;; and ends the walk.
903
+ (let [spec (core/oget ctx :spec)
904
+ base (if spec (core/oget spec :base) (mget (core/oget ctx :options) "base"))]
905
+ (when (and spec (string? (mget paging "next")))
906
+ (.put ^java.util.Map paging "next" (paging-resolve (mget paging "next") (core/oget spec :url))))
907
+ (when (and (string? (mget paging "next")) (paging-foreign? (mget paging "next") base))
908
+ (.put ^java.util.Map paging "foreign" (mget paging "next"))
909
+ (.put ^java.util.Map paging "next" nil)))
792
910
  ;; Cursor presence only INFERS another page. When the
793
911
  ;; server stated the answer outright — relay's
794
912
  ;; `hasNextPage: false`, or a body `hasMore` — that
@@ -799,7 +917,10 @@
799
917
  (when-not @explicit-more
800
918
  (.put ^java.util.Map paging "hasMore"
801
919
  (boolean (or (mget paging "hasMore") (some? (mget paging "next"))
802
- (some? (mget paging "cursor")) (some? (mget paging "nextPage")))))))
920
+ (some? (mget paging "cursor")) (some? (mget paging "nextPage"))))))
921
+ (when (and (some? (mget paging "foreign")) (nil? (mget paging "cursor"))
922
+ (nil? (mget paging "nextPage")))
923
+ (.put ^java.util.Map paging "hasMore" false)))
803
924
  (core/oset! result :paging paging)
804
925
  (when-let [ctrl (core/oget ctx :ctrl)]
805
926
  (let [held (core/oget ctrl :paging)]
@@ -1018,8 +1139,9 @@
1018
1139
  "PreResult"
1019
1140
  (fn [ctx]
1020
1141
  (when (and (active? fa) (streamable? ctx))
1142
+ ;; A failed result keeps no stream, so the entity's stream raises its error.
1021
1143
  (let [result (core/oget ctx :result)]
1022
- (when result
1144
+ (when (and result (nil? (core/oget result :err)))
1023
1145
  (core/oset! result :streaming true)
1024
1146
  (core/oset! result :stream (make-stream result))
1025
1147
  (let [t (track-ensure! fa "_streaming" (vs/jm "opened" 0))]
@@ -1088,17 +1210,23 @@
1088
1210
  ;; telemetry
1089
1211
  ;; ---------------------------------------------------------------------------
1090
1212
 
1213
+ ;; W3C trace context: lowercase hex from the platform's random source, never all zeros.
1214
+ (def ^:private secure-random (java.security.SecureRandom.))
1215
+
1216
+ (defn- random-hex [nbytes]
1217
+ (let [buf (byte-array nbytes)]
1218
+ (loop []
1219
+ (.nextBytes ^java.security.SecureRandom secure-random buf)
1220
+ (if (every? zero? buf) (recur)
1221
+ (apply str (map #(format "%02x" (bit-and (long %) 0xff)) buf))))))
1222
+
1091
1223
  (defn telemetry-feature []
1092
1224
  (let [fa (new-feature "telemetry" false "0.0.1")
1093
1225
  telem (fn [] (track-get fa "_telemetry"))
1094
1226
  gen-id2 (fn [kind]
1095
1227
  (let [idgen (opt fa "idgen")]
1096
1228
  (if (fn? idgen) (idgen kind)
1097
- (do (swap! fa update :seq inc)
1098
- (let [n (let [h (Long/toHexString (long (:seq @fa)))]
1099
- (str (apply str (repeat (max 0 (- 4 (count h))) "0")) h))
1100
- padded (apply str n (repeat (max 0 (- 16 (count n))) "0"))]
1101
- (str (if (= kind "trace") "t" "s") (subs padded 0 16)))))))
1229
+ (random-hex (if (= kind "trace") 16 8)))))
1102
1230
  close (fn [ctx ok]
1103
1231
  (let [span (get (:spans @fa) ctx)]
1104
1232
  (when span
@@ -1112,11 +1240,11 @@
1112
1240
  (.add ^java.util.List (mget t "spans") out))
1113
1241
  (let [exporter (opt fa "exporter")]
1114
1242
  (when (fn? exporter) (try (exporter out) (catch Throwable _ nil))))))))]
1115
- (swap! fa assoc :spans {} :seq 0)
1243
+ (swap! fa assoc :spans {})
1116
1244
  (swap! fa assoc
1117
1245
  "init" (fn [ctx options]
1118
1246
  (swap! fa assoc :client (core/oget ctx :client)
1119
- :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :spans {} :seq 0)
1247
+ :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :spans {})
1120
1248
  (when (active? fa)
1121
1249
  (when (nil? (track-get fa "_telemetry"))
1122
1250
  (track-set! fa "_telemetry" (vs/jm "spans" (vs/jt) "active" 0)))))
@@ -1174,7 +1302,9 @@
1174
1302
  (let [b (vs/jm "count" 0 "ok" 0 "err" 0 "totalMs" 0 "maxMs" 0)]
1175
1303
  (.put ^java.util.Map (mget m "ops") key b) b))]
1176
1304
  (bump! (mget m "total") ok dur)
1177
- (bump! opm ok dur))))))]
1305
+ (bump! opm ok dur)
1306
+ (let [sink (opt fa "sink")]
1307
+ (when (fn? sink) (try (sink (core/ucall ctx :clean m)) (catch Throwable _ nil)))))))))]
1178
1308
  (swap! fa assoc :starts {})
1179
1309
  (swap! fa assoc
1180
1310
  "init" (fn [ctx options]
@@ -1227,9 +1357,7 @@
1227
1357
  max (opt fa "max" 100)]
1228
1358
  (.add ^java.util.List buf entry)
1229
1359
  (while (> (.size ^java.util.List buf) max) (.remove ^java.util.List buf 0))
1230
- ;; `onEntry` is the option spec's spelling; the
1231
- ;; older `on_entry` is kept for callers that used it.
1232
- (let [on-entry (or (opt fa "onEntry") (opt fa "on_entry"))]
1360
+ (let [on-entry (opt fa "onEntry")]
1233
1361
  (when (fn? on-entry) (try (on-entry entry) (catch Throwable _ nil)))))))))]
1234
1362
  (swap! fa assoc :entries {})
1235
1363
  (swap! fa assoc
@@ -152,6 +152,17 @@
152
152
  (core/feature-hook ctx "PreUnexpected")
153
153
  {"ok" false "error" err "result" (core/oget ctx :result) "ctx" ctx})))))
154
154
 
155
+ ;; The documented hasMore loop, one request per page.
156
+ (defn- paging-walk [reply & opts]
157
+ (let [[server calls] (recording-server (fn [n _fd] [(reply n) nil]))
158
+ h (make-harness [(apply fspec "paging" opts)] :server server)
159
+ paging (vs/jm)
160
+ ctrl (vs/jm "paging" paging)]
161
+ (h-op h :opname "list" :path "/w" :ctrl ctrl)
162
+ (while (and (= true (mget paging "hasMore")) (< (count @calls) 4))
163
+ (h-op h :opname "list" :path "/w" :ctrl ctrl))
164
+ [(mapv #(str (vs/getprop % "url")) @calls) paging]))
165
+
155
166
  (defn- rstatus [res] (core/oget (get res "result") :status))
156
167
  (defn- rcode [res] (:code (get res "error")))
157
168
 
@@ -498,7 +509,7 @@
498
509
  ;; ---- debug ----
499
510
  (check "debug-redacted-trace-on-entry-max" "debug"
500
511
  (fn [] (let [seen (atom [])
501
- h (make-harness [(fspec "debug" "max" 1 "on_entry" (fn [e] (swap! seen conj e)))])]
512
+ h (make-harness [(fspec "debug" "max" 1 "onEntry" (fn [e] (swap! seen conj e)))])]
502
513
  (h-op h :headers (vs/jm "authorization" "Bearer secret"))
503
514
  (h-op h :opname "list")
504
515
  (let [entries (mget (h-track h "_debug") "entries")]
@@ -616,6 +627,53 @@
616
627
  (t/is-true (boolean (re-find #"[?&]cursor=xyz(&|$)" (str (vs/getprop (nth @calls 0) "url")))) "cursor=xyz")
617
628
  (t/is-eq (mget (core/oget (get res "result") :paging) "cursor") "abc" "cursor abc")
618
629
  (t/is-eq (mget (core/oget (get res "result") :paging) "hasMore") true "hasMore"))))
630
+ (check "paging-body-next-is-sent-as-the-cursor" "paging"
631
+ (fn [] (let [[urls paging] (paging-walk (fn [n] (make-response 200 (vs/jm "next" (get ["c3" "c6"] (dec n))) nil)))]
632
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/w?cursor=c3"
633
+ "http://api.test/w?cursor=c6"] "requests")
634
+ (t/is-eq (mget paging "hasMore") false "hasMore"))))
635
+ (check "paging-body-next-url-is-the-next-request" "paging"
636
+ (fn [] (let [[urls paging] (paging-walk
637
+ (fn [n] (make-response 200 (vs/jm "next" (get ["http://api.test/v2/w?cursor=c%2F3&limit=3"
638
+ "/v2/w?cursor=c6"] (dec n))) nil)))]
639
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/v2/w?cursor=c%2F3&limit=3"
640
+ "http://api.test/v2/w?cursor=c6"] "requests")
641
+ (t/is-eq (mget paging "hasMore") false "hasMore"))))
642
+ (check "paging-link-next-url-is-the-next-request" "paging"
643
+ (fn [] (let [links ["<http://api.test/w?after=b3>; rel=\"next\"" "</w?after=b6>; rel=\"next\""]
644
+ [urls paging] (paging-walk
645
+ (fn [n] (make-response 200 (vs/jt)
646
+ (when-let [l (get links (dec n))] (vs/jm "link" l)))))]
647
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/w?after=b3"
648
+ "http://api.test/w?after=b6"] "requests")
649
+ (t/is-eq (mget paging "hasMore") false "hasMore"))))
650
+ (check "paging-query-only-link-keeps-the-path" "paging"
651
+ (fn [] (let [links ["</v1/items?page=2>; rel=\"next\"" "<?page=3>; rel=\"next\""]
652
+ [urls _] (paging-walk
653
+ (fn [n] (make-response 200 (vs/jt)
654
+ (when-let [l (get links (dec n))] (vs/jm "link" l)))))]
655
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/v1/items?page=2"
656
+ "http://api.test/v1/items?page=3"] "requests"))))
657
+ (check "paging-path-relative-link-resolves-against-the-request" "paging"
658
+ (fn [] (let [links ["</v1/items?page=2>; rel=\"next\"" "<more?page=3>; rel=\"next\""]
659
+ [urls _] (paging-walk
660
+ (fn [n] (make-response 200 (vs/jt)
661
+ (when-let [l (get links (dec n))] (vs/jm "link" l)))))]
662
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/v1/items?page=2"
663
+ "http://api.test/v1/more?page=3"] "requests"))))
664
+ (check "paging-foreign-link-ends-the-walk" "paging"
665
+ (fn [] (let [[urls paging] (paging-walk
666
+ (fn [_n] (make-response 200 (vs/jt)
667
+ (vs/jm "link" "<https://elsewhere.test/w?after=b3>; rel=\"next\""))))]
668
+ (t/is-deep urls ["http://api.test/w?page=1"] "one request")
669
+ (t/is-eq (mget paging "hasMore") false "hasMore")
670
+ (t/is-eq (mget paging "foreign") "https://elsewhere.test/w?after=b3" "foreign"))))
671
+ (check "paging-cursor-mode-sends-a-slash-cursor" "paging"
672
+ (fn [] (let [[urls paging] (paging-walk
673
+ (fn [n] (make-response 200 (vs/jm "next" (get ["/c3"] (dec n))) nil))
674
+ "next" "cursor")]
675
+ (t/is-deep urls ["http://api.test/w?page=1" "http://api.test/w?cursor=%2Fc3"] "requests")
676
+ (t/is-eq (mget paging "hasMore") false "hasMore"))))
619
677
  (check "paging-non-list-not-paged" "paging"
620
678
  (fn [] (let [[server calls] (recording-server nil)
621
679
  h (make-harness [(fspec "paging")] :server server)
@@ -639,6 +697,17 @@
639
697
  h (make-harness [(fspec "streaming" "chunkSize" 2)] :server server)
640
698
  res (h-op h :opname "list" :path "/w")]
641
699
  (t/is-deep (mapv vec ((core/oget (get res "result") :stream))) [[1 2] [3 4] [5]] "batches"))))
700
+ (check "streaming-failed-result-is-not-streamed" "streaming"
701
+ (fn [] (let [[server _calls] (recording-server (fn [_n _fd] [(make-response 503 (vs/jt) nil) nil]))
702
+ h (make-harness [(fspec "streaming")] :server server)
703
+ res (h-op h :opname "list" :path "/w")]
704
+ (t/is-eq (get res "ok") false "failed")
705
+ (t/is-nil (core/oget (get res "result") :stream) "no stream on a failed result"))))
706
+ (check "streaming-empty-list-streams-nothing" "streaming"
707
+ (fn [] (let [[server _calls] (recording-server (fn [_n _fd] [(make-response 200 (vs/jt) nil) nil]))
708
+ h (make-harness [(fspec "streaming")] :server server)
709
+ res (h-op h :opname "list" :path "/w")]
710
+ (t/is-deep (vec ((core/oget (get res "result") :stream))) [] "nothing streamed"))))
642
711
  (check "streaming-non-list-not-streamed" "streaming"
643
712
  (fn [] (let [h (make-harness [(fspec "streaming")])
644
713
  res (h-op h)]