@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
@@ -6,6 +6,7 @@
6
6
  #ifndef SDK_FEATURE_TEST_HPP
7
7
  #define SDK_FEATURE_TEST_HPP
8
8
 
9
+ #include <algorithm>
9
10
  #include <string>
10
11
  #include <vector>
11
12
 
@@ -147,20 +148,10 @@ private:
147
148
  return out;
148
149
  }
149
150
 
150
- Value resolveMatch(CtxPtr ctx, const Value& explicitMatch) {
151
- if (explicitMatch.is_map() && !explicitMatch.as_map()->empty()) {
152
- return explicitMatch;
153
- }
154
- for (const Value& src : {ctx->match, ctx->data}) {
155
- if (!src.is_map()) continue;
156
- Value v = getp(src, "id", Value(nullptr));
157
- if (!v.is_null() && !(v.is_string() && v.as_string() == "__UNDEFINED__")) {
158
- Value out = vmap();
159
- map_put(out, "id", v);
160
- return out;
161
- }
162
- }
163
- return vmap();
151
+ static bool held(const Value& src, const std::string& key) {
152
+ if (!src.is_map()) return false;
153
+ Value v = getp(src, key, Value(nullptr));
154
+ return !is_nullish(v) && !(v.is_string() && v.as_string() == "__UNDEFINED__");
164
155
  }
165
156
 
166
157
  Value serve(CtxPtr ctx, const Value& entity) {
@@ -169,7 +160,7 @@ private:
169
160
  if (!entmap.is_map()) entmap = vmap();
170
161
 
171
162
  if (op->name == "load") {
172
- Value args = buildArgs(ctx, op, resolveMatch(ctx, ctx->reqmatch));
163
+ Value args = buildArgs(ctx, op, ctx->reqmatch);
173
164
  std::vector<Value> found = Struct::select(entmap, args);
174
165
  Value ent = found.empty() ? Value::undef() : found[0];
175
166
  if (is_nullish(ent)) return respond(ctx, 404, Value(nullptr), extra1("statusText", Value("Not found")));
@@ -187,40 +178,22 @@ private:
187
178
  Value out = Struct::clone(outlist);
188
179
  return respond(ctx, 200, out, Value::undef());
189
180
  } else if (op->name == "update" || op->name == "patch") {
190
- Value updateMatch = vmap();
191
- if (ctx->reqdata.is_map()) {
192
- if (map_contains(ctx->reqdata, "id")) {
193
- map_put(updateMatch, "id", getp(ctx->reqdata, "id"));
194
- }
195
- if (op->alias.is_map()) {
196
- Value aliasIdRaw = getp(op->alias, "id");
197
- if (aliasIdRaw.is_string()) {
198
- std::string aliasId = aliasIdRaw.as_string();
199
- if (map_contains(ctx->reqdata, aliasId)) {
200
- map_put(updateMatch, aliasId, getp(ctx->reqdata, aliasId));
201
- }
202
- }
203
- }
204
- }
205
- if (!updateMatch.is_map() || updateMatch.as_map()->empty()) {
206
- updateMatch = resolveMatch(ctx, vmap());
207
- }
208
- Value args = buildArgs(ctx, op, updateMatch);
181
+ // `$body` travels on the wire alone; the record is the rest.
182
+ Value rec = ctx->reqdata.is_map() ? Struct::clone(ctx->reqdata) : vmap();
183
+ Struct::delprop(rec, Value("$body"));
184
+ Value args = buildArgs(ctx, op, rec);
209
185
  std::vector<Value> found = Struct::select(entmap, args);
210
186
  Value ent = found.empty() ? Value::undef() : found[0];
211
187
  // update miss: 404, never another record
212
188
  if (is_nullish(ent)) return respond(ctx, 404, Value(nullptr), extra1("statusText", Value("Not found")));
213
189
  if (ent.is_map() && ctx->reqdata.is_map()) {
214
- // `$body` travels on the wire alone; the record is the rest.
215
- Value rec = Struct::clone(ctx->reqdata);
216
- Struct::delprop(rec, Value("$body"));
217
190
  Struct::merge(vlist({ent, rec}));
218
191
  }
219
192
  Struct::delprop(ent, Value("$KEY"));
220
193
  Value out = Struct::clone(ent);
221
194
  return respond(ctx, 200, out, Value::undef());
222
195
  } else if (op->name == "remove") {
223
- Value args = buildArgs(ctx, op, resolveMatch(ctx, ctx->reqmatch));
196
+ Value args = buildArgs(ctx, op, ctx->reqmatch);
224
197
  std::vector<Value> found = Struct::select(entmap, args);
225
198
  Value ent = found.empty() ? Value::undef() : found[0];
226
199
  if (ent.is_map()) {
@@ -361,24 +334,61 @@ private:
361
334
  Value qand = vlist();
362
335
  Value q = vmap({{"`$AND`", qand}});
363
336
 
337
+ std::string entityName = ctx->entity == nullptr ? std::string("") : ctx->entity->getName();
338
+ Value idfrom = Struct::getpath(ctx->config, {"entity", entityName, "id", "from"});
339
+
340
+ std::vector<std::string> names;
364
341
  if (args.is_map()) {
365
- for (const auto& key : Struct::keysof(args)) {
366
- bool isId = (key == "id");
367
- std::vector<Value> selected = Struct::select(reqd, Value(key));
368
- Value selv = vlist();
369
- for (auto& s : selected) selv.as_list()->push_back(s);
370
- bool isReqd = !Struct::isempty(selv);
371
-
372
- if (isId || isReqd) {
373
- Value v = ctx->utility->param(ctx, Value(key));
374
- Value ka = getp(op->alias, key);
375
-
376
- Value qor = vlist({vmap({{key, v}})});
377
- if (ka.is_string()) {
378
- qor.as_list()->push_back(vmap({{ka.as_string(), v}}));
342
+ for (const auto& key : Struct::keysof(args)) names.push_back(key);
343
+ }
344
+
345
+ // With no id in the call, the entity's held id (or composite parts) stands in.
346
+ if (!held(args, "id")) {
347
+ Value parts = Struct::getpath(ctx->config, {"entity", entityName, "id", "parts"});
348
+ if (!parts.is_list()) parts = opname == "list" ? vlist() : vlist({Value("id")});
349
+ for (const auto& part : *parts.as_list()) {
350
+ if (!part.is_string()) continue;
351
+ std::string pname = part.as_string();
352
+ if (std::find(names.begin(), names.end(), pname) == names.end() &&
353
+ (held(ctx->match, pname) || held(ctx->data, pname))) {
354
+ names.push_back(pname);
355
+ }
356
+ }
357
+ }
358
+
359
+ for (const auto& key : names) {
360
+ bool isId = (key == "id");
361
+ std::vector<Value> selected = Struct::select(reqd, Value(key));
362
+ Value selv = vlist();
363
+ for (auto& s : selected) selv.as_list()->push_back(s);
364
+ bool isReqd = !Struct::isempty(selv);
365
+
366
+ if (isId || isReqd) {
367
+ Value v = ctx->utility->param(ctx, Value(key));
368
+ Value ka = getp(op->alias, key);
369
+
370
+ Value qor = vlist({vmap({{key, v}})});
371
+ if (ka.is_string()) {
372
+ qor.as_list()->push_back(vmap({{ka.as_string(), v}}));
373
+ }
374
+
375
+ // An alternative, never a replacement: a seed keeping the parameter
376
+ // flat is still found.
377
+ Value kf = getp(idfrom, key);
378
+ if (kf.is_string() && kf.as_string() != key) {
379
+ Value nest = v;
380
+ std::string path = kf.as_string();
381
+ size_t end = path.size();
382
+ while (true) {
383
+ size_t dot = path.rfind('.', end == 0 ? 0 : end - 1);
384
+ size_t start = (dot == std::string::npos || dot >= end) ? 0 : dot + 1;
385
+ nest = vmap({{path.substr(start, end - start), nest}});
386
+ if (start == 0) break;
387
+ end = start - 1;
379
388
  }
380
- qand.as_list()->push_back(vmap({{"`$OR`", qor}}));
389
+ qor.as_list()->push_back(nest);
381
390
  }
391
+ qand.as_list()->push_back(vmap({{"`$OR`", qor}}));
382
392
  }
383
393
  }
384
394
 
@@ -899,6 +899,109 @@ static void paging_bodyCursorAndExplicitCursor() {
899
899
  ASSERT_EQ_VAL(getp(res.result->paging, "hasMore"), Value(true), "expected hasMore");
900
900
  }
901
901
 
902
+ // The documented hasMore loop, one request per page.
903
+ static std::vector<std::string> pagingWalk(std::function<Value(int)> reply, Value& paging,
904
+ Value options = Value::undef()) {
905
+ auto rec = std::make_shared<FhRecorder>();
906
+ rec->reply = [reply](int n, const Value&) { return reply(n); };
907
+ FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
908
+ auto h = fhMake(server, {FF(std::make_shared<PagingFeature>(), options)});
909
+ paging = vmap();
910
+ Value ctrl = fhMap({{"paging", paging}});
911
+ h->op(fhOp("list").setPath("/w").setCtrl(ctrl));
912
+ while (getp(paging, "hasMore").is_bool() && getp(paging, "hasMore").as_bool() && rec->calls.size() < 4) {
913
+ h->op(fhOp("list").setPath("/w").setCtrl(ctrl));
914
+ }
915
+ std::vector<std::string> urls;
916
+ for (size_t i = 0; i < rec->calls.size(); i++) urls.push_back(rec->url((int)i));
917
+ return urls;
918
+ }
919
+
920
+ static void checkWalk(const std::vector<std::string>& urls, const Value& paging,
921
+ const std::vector<std::string>& want, const char* where) {
922
+ sdktest::expect_true(urls == want, where, "requests sent: " + (urls.empty() ? std::string() : urls.back()));
923
+ sdktest::expect_eq_val(getp(paging, "hasMore"), Value(false), where, "expected hasMore false");
924
+ std::printf("ran %s\n", where);
925
+ }
926
+
927
+ static void paging_bodyNextIsSentAsTheCursor() {
928
+ if (!have({"paging"})) return;
929
+ Value paging;
930
+ auto urls = pagingWalk([](int n) {
931
+ Value next = n == 1 ? Value("c3") : n == 2 ? Value("c6") : Value(nullptr);
932
+ return fhResponse(200, fhMap({{"next", next}}), Value::undef());
933
+ }, paging);
934
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/w?cursor=c3",
935
+ "http://api.test/w?cursor=c6"}, __func__);
936
+ }
937
+
938
+ static void paging_bodyNextUrlIsTheNextRequest() {
939
+ if (!have({"paging"})) return;
940
+ Value paging;
941
+ auto urls = pagingWalk([](int n) {
942
+ Value next = n == 1 ? Value("http://api.test/v2/w?cursor=c%2F3&limit=3")
943
+ : n == 2 ? Value("/v2/w?cursor=c6") : Value(nullptr);
944
+ return fhResponse(200, fhMap({{"next", next}}), Value::undef());
945
+ }, paging);
946
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/v2/w?cursor=c%2F3&limit=3",
947
+ "http://api.test/v2/w?cursor=c6"}, __func__);
948
+ }
949
+
950
+ static void paging_linkNextUrlIsTheNextRequest() {
951
+ if (!have({"paging"})) return;
952
+ Value paging;
953
+ auto urls = pagingWalk([](int n) {
954
+ Value headers = n == 1 ? fhMap({{"link", Value("<http://api.test/w?after=b3>; rel=\"next\"")}})
955
+ : n == 2 ? fhMap({{"link", Value("</w?after=b6>; rel=\"next\"")}}) : Value::undef();
956
+ return fhResponse(200, vlist(), headers);
957
+ }, paging);
958
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/w?after=b3",
959
+ "http://api.test/w?after=b6"}, __func__);
960
+ }
961
+
962
+ static void paging_queryOnlyLinkKeepsThePath() {
963
+ if (!have({"paging"})) return;
964
+ Value paging;
965
+ auto urls = pagingWalk([](int n) {
966
+ Value headers = n == 1 ? fhMap({{"link", Value("</v1/items?page=2>; rel=\"next\"")}})
967
+ : n == 2 ? fhMap({{"link", Value("<?page=3>; rel=\"next\"")}}) : Value::undef();
968
+ return fhResponse(200, vlist(), headers);
969
+ }, paging);
970
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/v1/items?page=2",
971
+ "http://api.test/v1/items?page=3"}, __func__);
972
+ }
973
+
974
+ static void paging_pathRelativeLinkResolvesAgainstTheRequest() {
975
+ if (!have({"paging"})) return;
976
+ Value paging;
977
+ auto urls = pagingWalk([](int n) {
978
+ Value headers = n == 1 ? fhMap({{"link", Value("</v1/items?page=2>; rel=\"next\"")}})
979
+ : n == 2 ? fhMap({{"link", Value("<more?page=3>; rel=\"next\"")}}) : Value::undef();
980
+ return fhResponse(200, vlist(), headers);
981
+ }, paging);
982
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/v1/items?page=2",
983
+ "http://api.test/v1/more?page=3"}, __func__);
984
+ }
985
+
986
+ static void paging_foreignLinkEndsTheWalk() {
987
+ if (!have({"paging"})) return;
988
+ Value paging;
989
+ auto urls = pagingWalk([](int) {
990
+ return fhResponse(200, vlist(), fhMap({{"link", Value("<https://elsewhere.test/w?after=b3>; rel=\"next\"")}}));
991
+ }, paging);
992
+ checkWalk(urls, paging, {"http://api.test/w?page=1"}, __func__);
993
+ ASSERT_EQ_VAL(getp(paging, "foreign"), Value("https://elsewhere.test/w?after=b3"), "expected the foreign link");
994
+ }
995
+
996
+ static void paging_cursorModeSendsASlashCursor() {
997
+ if (!have({"paging"})) return;
998
+ Value paging;
999
+ auto urls = pagingWalk([](int n) {
1000
+ return fhResponse(200, fhMap({{"next", n == 1 ? Value("/c3") : Value(nullptr)}}), Value::undef());
1001
+ }, paging, fhMap({{"next", Value("cursor")}}));
1002
+ checkWalk(urls, paging, {"http://api.test/w?page=1", "http://api.test/w?cursor=%2Fc3"}, __func__);
1003
+ }
1004
+
902
1005
  static void paging_nonListNotPaged() {
903
1006
  if (!have({"paging"})) return;
904
1007
  auto rec = std::make_shared<FhRecorder>();
@@ -947,6 +1050,31 @@ static void streaming_batchesWithChunkSize() {
947
1050
  ASSERT_EQ_VAL(batches, expected, "expected chunked batches");
948
1051
  }
949
1052
 
1053
+ static void streaming_failedResultIsNotStreamed() {
1054
+ if (!have({"streaming"})) return;
1055
+ auto rec = std::make_shared<FhRecorder>();
1056
+ rec->reply = [](int, const Value&) { return fhResponse(503, vlist(), Value::undef()); };
1057
+ FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
1058
+ auto f = std::make_shared<StreamingFeature>();
1059
+ auto h = fhMake(server, {FF(f, Value::undef())});
1060
+ FhOpResult res = h->op(fhOp("list").setPath("/w"));
1061
+ ASSERT_FALSE(res.result->streaming || (bool)res.result->stream, "a failed result must keep no stream");
1062
+ ASSERT_EQ(f->opened, 0, "expected no opened streams");
1063
+ std::printf("ran %s\n", __func__);
1064
+ }
1065
+
1066
+ static void streaming_emptyListStreamsNothing() {
1067
+ if (!have({"streaming"})) return;
1068
+ auto rec = std::make_shared<FhRecorder>();
1069
+ rec->reply = [](int, const Value&) { return fhResponse(200, vlist(), Value::undef()); };
1070
+ FetcherFn server = [rec](CtxPtr c, const std::string& u, const Value& fd) { return rec->fetch(c, u, fd); };
1071
+ auto h = fhMake(server, {FF(std::make_shared<StreamingFeature>(), Value::undef())});
1072
+ FhOpResult res = h->op(fhOp("list").setPath("/w"));
1073
+ ASSERT_TRUE((bool)res.result->stream, "an empty list still streams");
1074
+ if (res.result->stream) ASSERT_TRUE(res.result->stream().empty(), "an empty list streams nothing");
1075
+ std::printf("ran %s\n", __func__);
1076
+ }
1077
+
950
1078
  static void streaming_nonListNotStreamed() {
951
1079
  if (!have({"streaming"})) return;
952
1080
  auto h = fhMake(nullptr, {FF(std::make_shared<StreamingFeature>(), Value::undef())});
@@ -1105,10 +1233,19 @@ int main() {
1105
1233
  T_RUN(paging_bodyCursorAndExplicitCursor);
1106
1234
  T_RUN(paging_nonListNotPaged);
1107
1235
  T_RUN(paging_inactiveStampsNothing);
1236
+ T_RUN(paging_bodyNextIsSentAsTheCursor);
1237
+ T_RUN(paging_bodyNextUrlIsTheNextRequest);
1238
+ T_RUN(paging_linkNextUrlIsTheNextRequest);
1239
+ T_RUN(paging_queryOnlyLinkKeepsThePath);
1240
+ T_RUN(paging_pathRelativeLinkResolvesAgainstTheRequest);
1241
+ T_RUN(paging_foreignLinkEndsTheWalk);
1242
+ T_RUN(paging_cursorModeSendsASlashCursor);
1108
1243
 
1109
1244
  T_RUN(streaming_streamsListItems);
1110
1245
  T_RUN(streaming_batchesWithChunkSize);
1111
1246
  T_RUN(streaming_nonListNotStreamed);
1247
+ T_RUN(streaming_failedResultIsNotStreamed);
1248
+ T_RUN(streaming_emptyListStreamsNothing);
1112
1249
  T_RUN(streaming_inactiveIsNoop);
1113
1250
 
1114
1251
  T_RUN(proxy_routesThroughProxy);
@@ -2151,6 +2151,33 @@ inline Value makeOptions(CtxPtr ctx) {
2151
2151
  }
2152
2152
  }
2153
2153
 
2154
+ // The model's options for a feature sit beneath the caller's, key by key: a
2155
+ // key the caller sets replaces the default whole, so a list is never merged.
2156
+ {
2157
+ Value cfgfeature = getp(config, "feature");
2158
+ Value given = mapget(opts, "feature");
2159
+ if (cfgfeature.is_map() && (given.is_map() || is_nullish(given))) {
2160
+ Value out = vmap();
2161
+ if (given.is_map()) {
2162
+ for (const auto& g : *given.as_map()) map_put(out, g.first, g.second);
2163
+ }
2164
+ for (const auto& c : *cfgfeature.as_map()) {
2165
+ Value dflt = getp(c.second, "options");
2166
+ Value fopts = mapget(out, c.first);
2167
+ if (!dflt.is_map() || (is_nullish(fopts) && !is_true(getp(dflt, "active"))) ||
2168
+ (!is_nullish(fopts) && !fopts.is_map())) {
2169
+ continue;
2170
+ }
2171
+ Value merged = Struct::clone(dflt);
2172
+ if (fopts.is_map()) {
2173
+ for (const auto& f : *fopts.as_map()) map_put(merged, f.first, f.second);
2174
+ }
2175
+ map_put(out, c.first, merged);
2176
+ }
2177
+ map_put(opts, "feature", out);
2178
+ }
2179
+ }
2180
+
2154
2181
  // A feature option given as null or no value is absent, as the ts reference
2155
2182
  // validates it. This port's validate refuses such a key of an open map
2156
2183
  // under `$ONE` ("Unexpected keys"), so it is dropped first.
@@ -2230,15 +2257,18 @@ inline Value makeOptions(CtxPtr ctx) {
2230
2257
  map_put(opts, "base", Value(resolveServerBase(baseV.as_string(), opts, config, ctx)));
2231
2258
  }
2232
2259
 
2233
- // Resolve the feature add-order: an explicit list order (above) wins;
2234
- // otherwise order the map test-first, then the remaining names sorted, so
2235
- // the outcome is deterministic and `test` is always the base transport.
2236
- if (featureOrder.empty()) {
2260
+ // Resolve the feature add-order: an explicit list order (above) wins, and
2261
+ // the names it leaves out follow it test-first, then sorted, so the outcome
2262
+ // is deterministic and `test` is the base transport of a map.
2263
+ {
2237
2264
  Value featureMap = Helpers::toMapAny(getp(opts, "feature"));
2238
2265
  if (featureMap.is_map()) {
2239
2266
  std::vector<std::string> names;
2240
2267
  for (const auto& item : Struct::items(featureMap)) {
2241
- names.push_back(as_str(pair_key(item)));
2268
+ std::string n = as_str(pair_key(item));
2269
+ if (std::find(featureOrder.begin(), featureOrder.end(), n) == featureOrder.end()) {
2270
+ names.push_back(n);
2271
+ }
2242
2272
  }
2243
2273
  std::sort(names.begin(), names.end());
2244
2274
  bool hasTest = std::find(names.begin(), names.end(), "test") != names.end();
@@ -111,7 +111,14 @@ public class AuditFeature : BaseFeature
111
111
 
112
112
  if (Opt(_options, "sink") is Action<Dictionary<string, object?>> sink)
113
113
  {
114
- sink(record);
114
+ // A failing sink never changes the operation's outcome.
115
+ try
116
+ {
117
+ sink(record);
118
+ }
119
+ catch (System.Exception)
120
+ {
121
+ }
115
122
  }
116
123
  }
117
124
  }
@@ -16,6 +16,11 @@ public class MetricsBucket
16
16
  public int Err;
17
17
  public long TotalMs;
18
18
  public long MaxMs;
19
+
20
+ public Dictionary<string, object?> Record() => new Dictionary<string, object?>
21
+ {
22
+ ["count"] = Count, ["ok"] = Ok, ["err"] = Err, ["totalMs"] = TotalMs, ["maxMs"] = MaxMs,
23
+ };
19
24
  }
20
25
 
21
26
  public class MetricsFeature : BaseFeature
@@ -95,6 +100,24 @@ public class MetricsFeature : BaseFeature
95
100
 
96
101
  Bump(Total, ok, dur);
97
102
  Bump(op, ok, dur);
103
+
104
+ if (Opt(_options, "sink") is Action<Dictionary<string, object?>> sink)
105
+ {
106
+ var ops = new Dictionary<string, object?>();
107
+ foreach (var entry in Ops)
108
+ {
109
+ ops[entry.Key] = entry.Value.Record();
110
+ }
111
+ var counters = Fclean(ctx, new Dictionary<string, object?> { ["total"] = Total.Record(), ["ops"] = ops });
112
+ // A failing sink never changes the operation's outcome.
113
+ try
114
+ {
115
+ sink(counters);
116
+ }
117
+ catch (System.Exception)
118
+ {
119
+ }
120
+ }
98
121
  }
99
122
 
100
123
  private static void Bump(MetricsBucket bucket, bool ok, long dur)
@@ -73,10 +73,16 @@ public class PagingFeature : BaseFeature
73
73
 
74
74
  object? cursor = null;
75
75
  var hasCursor = paging != null && paging.TryGetValue("cursor", out cursor) && cursor != null;
76
+ object? nextLink = null;
76
77
  if (hasCursor)
77
78
  {
78
79
  spec.Query[cursorParam] = cursor;
79
80
  }
81
+ else if (paging != null && paging.TryGetValue("next", out nextLink) && nextLink is string link &&
82
+ !Foreign(link, spec.Base))
83
+ {
84
+ Follow(spec, (string)nextLink!);
85
+ }
80
86
  else if (!spec.Query.TryGetValue(pageParam, out var existing) || existing == null)
81
87
  {
82
88
  // A record written back by PreResult holds the page just fetched
@@ -231,10 +237,16 @@ public class PagingFeature : BaseFeature
231
237
  // Body-level signals; snake_case forms are read first so camelCase wins.
232
238
  if (body is Dictionary<string, object?> bm)
233
239
  {
234
- if (bm.TryGetValue("next", out var next) && next != null &&
235
- (!paging.TryGetValue("next", out var pn) || pn == null))
240
+ if (bm.TryGetValue("next", out var next) && next != null)
236
241
  {
237
- paging["next"] = next;
242
+ if (!IsLink(next, FoptStr(_options, "next", "auto")))
243
+ {
244
+ paging["cursor"] = next;
245
+ }
246
+ else if (!paging.TryGetValue("next", out var pn) || pn == null)
247
+ {
248
+ paging["next"] = next;
249
+ }
238
250
  }
239
251
  if (bm.TryGetValue("next_cursor", out var snakeCursor) && snakeCursor != null)
240
252
  {
@@ -283,6 +295,18 @@ public class PagingFeature : BaseFeature
283
295
  }
284
296
  }
285
297
 
298
+ // A link to another origin is recorded, never followed, and ends the walk.
299
+ var baseUrl = ctx.Spec?.Base ?? (ctx.Options != null && ctx.Options.TryGetValue("base", out var ob) ? ob as string : null);
300
+ if (paging.TryGetValue("next", out var rl) && rl is string rawNext && ctx.Spec != null)
301
+ {
302
+ paging["next"] = Resolve(rawNext, ctx.Spec.Url);
303
+ }
304
+ if (paging.TryGetValue("next", out var nl) && nl is string nextUrl && Foreign(nextUrl, baseUrl))
305
+ {
306
+ paging["foreign"] = nextUrl;
307
+ paging.Remove("next");
308
+ }
309
+
286
310
  // Cursor presence only INFERS another page. When the server stated
287
311
  // the answer outright - relay's `hasNextPage: false`, or a body
288
312
  // `hasMore` - that wins: a final page normally carries both an end
@@ -296,6 +320,13 @@ public class PagingFeature : BaseFeature
296
320
  paging["hasMore"] = true;
297
321
  }
298
322
 
323
+ if (paging.ContainsKey("foreign") &&
324
+ (!paging.TryGetValue("cursor", out var c3) || c3 == null) &&
325
+ (!paging.TryGetValue("nextPage", out var np3) || np3 == null))
326
+ {
327
+ paging["hasMore"] = false;
328
+ }
329
+
299
330
  result.Paging = paging;
300
331
  Last = paging;
301
332
 
@@ -318,6 +349,102 @@ public class PagingFeature : BaseFeature
318
349
  }
319
350
  }
320
351
 
352
+ private static readonly Regex Origin =
353
+ new(@"^[a-z][a-z0-9+.-]*://[^/?#]*", RegexOptions.IgnoreCase);
354
+
355
+ // Under the `next` option's default, a URL or an absolute path is a link
356
+ // and anything else a cursor; `cursor` and `url` pin the reading.
357
+ internal static bool IsLink(object? next, string mode) =>
358
+ next is string s && (mode == "url" ||
359
+ (mode != "cursor" && (Origin.IsMatch(s) || s.StartsWith("/"))));
360
+
361
+ private static string OriginOf(string? text)
362
+ {
363
+ var m = Origin.Match(text ?? "");
364
+ return m.Success ? m.Value.ToLowerInvariant() : "";
365
+ }
366
+
367
+ internal static bool Foreign(string link, string? baseUrl)
368
+ {
369
+ var origin = OriginOf(link);
370
+ return origin != "" && origin != OriginOf(baseUrl);
371
+ }
372
+
373
+ private static readonly Regex Scheme = new Regex("^[a-z][a-z0-9+.-]*:", RegexOptions.IgnoreCase);
374
+
375
+ // RFC 3986 reference resolution against the URL of the request that
376
+ // returned the link. A link on that URL's origin comes back as its path and
377
+ // query; an absolute link is left as the server wrote it.
378
+ internal static string Resolve(string link, string? url)
379
+ {
380
+ if (string.IsNullOrEmpty(url) || Scheme.IsMatch(link))
381
+ {
382
+ return link;
383
+ }
384
+ var bare = !Origin.IsMatch(url);
385
+ var holder = "http://placeholder.invalid" + (url.StartsWith("/") ? "" : "/");
386
+ if (!System.Uri.TryCreate(bare ? holder + url : url, System.UriKind.Absolute, out var from) ||
387
+ !System.Uri.TryCreate(from, link, out var to))
388
+ {
389
+ return link;
390
+ }
391
+ if (to.GetLeftPart(System.UriPartial.Authority) != from.GetLeftPart(System.UriPartial.Authority))
392
+ {
393
+ return to.GetComponents(System.UriComponents.HttpRequestUrl, System.UriFormat.UriEscaped);
394
+ }
395
+ return to.GetComponents(System.UriComponents.PathAndQuery, System.UriFormat.UriEscaped);
396
+ }
397
+
398
+ // The request goes to the link's path and query, on the SDK's own origin.
399
+ internal static void Follow(Spec spec, string next)
400
+ {
401
+ var rest = Origin.Replace(next, "", 1);
402
+ var hash = rest.IndexOf('#');
403
+ if (hash >= 0)
404
+ {
405
+ rest = rest.Substring(0, hash);
406
+ }
407
+ var mark = rest.IndexOf('?');
408
+ var path = mark < 0 ? rest : rest.Substring(0, mark);
409
+ var rawquery = mark < 0 ? "" : rest.Substring(mark + 1);
410
+
411
+ var query = new Dictionary<string, object?>();
412
+ foreach (var pair in rawquery.Split('&'))
413
+ {
414
+ if (pair.Length == 0)
415
+ {
416
+ continue;
417
+ }
418
+ var eq = pair.IndexOf('=');
419
+ var key = eq < 0 ? pair : pair.Substring(0, eq);
420
+ var val = eq < 0 ? "" : pair.Substring(eq + 1);
421
+ query[Unescape(key)] = Unescape(val);
422
+ }
423
+ foreach (var key in spec.AuthQuery)
424
+ {
425
+ query[key] = spec.Query.TryGetValue(key, out var v) ? v : null;
426
+ }
427
+
428
+ var origin = Origin.Match(spec.Base ?? "");
429
+ spec.Base = origin.Success ? origin.Value : "";
430
+ spec.Prefix = "";
431
+ spec.Path = path;
432
+ spec.Suffix = "";
433
+ spec.Query = query;
434
+ }
435
+
436
+ private static string Unescape(string text)
437
+ {
438
+ try
439
+ {
440
+ return System.Uri.UnescapeDataString(text.Replace('+', ' '));
441
+ }
442
+ catch (System.UriFormatException)
443
+ {
444
+ return text;
445
+ }
446
+ }
447
+
321
448
  private bool IsList(Context ctx)
322
449
  {
323
450
  var opname = ctx.Op?.Name ?? "";
@@ -13,6 +13,7 @@ public class RatelimitFeature : BaseFeature
13
13
  {
14
14
  private ProjectNameSDK? _client;
15
15
  private Dictionary<string, object?>? _options;
16
+ private readonly object _lock = new();
16
17
  private double _tokens;
17
18
  private long _last;
18
19
 
@@ -53,32 +54,38 @@ public class RatelimitFeature : BaseFeature
53
54
  }
54
55
 
55
56
  private void Acquire()
57
+ {
58
+ var waitMs = Reserve();
59
+ if (waitMs > 0)
60
+ {
61
+ FoptSleep(_options)(waitMs);
62
+ }
63
+ }
64
+
65
+ // Refill, then reserve this call's token before any wait, under the lock:
66
+ // a negative count is the calls already queued, so overlapping calls pace
67
+ // in turn.
68
+ private int Reserve()
56
69
  {
57
70
  var rate = FoptNum(_options, "rate", 5);
58
71
  var burst = FoptNum(_options, "burst", rate);
59
72
 
60
- // Refill according to elapsed time.
61
- var now = FoptNow(_options)();
62
- var elapsed = now - _last;
63
- _last = now;
64
- _tokens = Math.Min(burst, _tokens + (elapsed / 1000.0) * rate);
65
-
66
- if (_tokens >= 1)
73
+ lock (_lock)
67
74
  {
68
- _tokens -= 1;
69
- return;
70
- }
75
+ var now = FoptNow(_options)();
76
+ var elapsed = now - _last;
77
+ _last = now;
78
+ _tokens = Math.Min(burst, _tokens + (elapsed / 1000.0) * rate) - 1;
71
79
 
72
- // Not enough tokens: wait for one to accrue, then consume it.
73
- var needed = 1 - _tokens;
74
- var waitMs = (int)Math.Ceiling((needed / rate) * 1000);
75
- Track(waitMs);
76
- if (waitMs > 0)
77
- {
78
- FoptSleep(_options)(waitMs);
80
+ if (_tokens >= 0)
81
+ {
82
+ return 0;
83
+ }
84
+
85
+ var waitMs = (int)Math.Ceiling((-_tokens / rate) * 1000);
86
+ Track(waitMs);
87
+ return waitMs;
79
88
  }
80
- _last = FoptNow(_options)();
81
- _tokens = 0;
82
89
  }
83
90
 
84
91
  private void Track(int waitMs)