@voxgig/sdkgen 4.50.0 → 4.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (400) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ReadmeExplanation.js +5 -2
  3. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  4. package/dist/cmp/ReadmeFeatures.js +20 -6
  5. package/dist/cmp/ReadmeFeatures.js.map +1 -1
  6. package/dist/helpers/optspec.js +2 -2
  7. package/dist/helpers/optspec.js.map +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/model/sdkgen.aontu +1 -1
  10. package/package.json +1 -1
  11. package/project/.sdk/model/feature/audit.aontu +1 -1
  12. package/project/.sdk/model/feature/cache.aontu +7 -5
  13. package/project/.sdk/model/feature/clienttrack.aontu +1 -1
  14. package/project/.sdk/model/feature/cost.aontu +1 -1
  15. package/project/.sdk/model/feature/debug.aontu +1 -1
  16. package/project/.sdk/model/feature/idempotency.aontu +1 -1
  17. package/project/.sdk/model/feature/log.aontu +1 -1
  18. package/project/.sdk/model/feature/metrics.aontu +3 -1
  19. package/project/.sdk/model/feature/netsim.aontu +1 -1
  20. package/project/.sdk/model/feature/paging.aontu +4 -1
  21. package/project/.sdk/model/feature/proxy.aontu +1 -1
  22. package/project/.sdk/model/feature/ratelimit.aontu +3 -3
  23. package/project/.sdk/model/feature/rbac.aontu +1 -1
  24. package/project/.sdk/model/feature/retry.aontu +1 -1
  25. package/project/.sdk/model/feature/secrets.aontu +1 -1
  26. package/project/.sdk/model/feature/streaming.aontu +1 -1
  27. package/project/.sdk/model/feature/telemetry.aontu +2 -2
  28. package/project/.sdk/model/feature/test.aontu +1 -1
  29. package/project/.sdk/model/feature/timeout.aontu +1 -1
  30. package/project/.sdk/model/feature/validate.aontu +1 -1
  31. package/project/.sdk/model/target/lua.aontu +6 -0
  32. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  33. package/project/.sdk/src/cmp/c/TestClean_c.ts +26 -11
  34. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +17 -10
  35. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  36. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +18 -1
  37. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +15 -1
  38. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  39. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +30 -2
  40. package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +31 -12
  41. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +13 -4
  42. package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +51 -15
  43. package/project/.sdk/src/cmp/elixir/fragment/Pipeline.fragment.ex +17 -0
  44. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  45. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +42 -2
  46. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +42 -14
  47. package/project/.sdk/src/cmp/java/TestClean_java.ts +17 -4
  48. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +21 -0
  49. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +13 -8
  50. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  51. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +26 -2
  52. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +8 -0
  53. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +8 -0
  54. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +8 -0
  55. package/project/.sdk/src/cmp/js/fragment/EntityPatchOp.fragment.js +8 -0
  56. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +8 -0
  57. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +8 -0
  58. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +12 -5
  59. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +31 -4
  60. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +19 -0
  61. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +14 -4
  62. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +42 -5
  63. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +44 -10
  64. package/project/.sdk/src/cmp/lua/utility_lua.ts +2 -1
  65. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +20 -5
  66. package/project/.sdk/src/cmp/ocaml/fragment/RunOp.fragment.ml +36 -21
  67. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +13 -4
  68. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +21 -0
  69. package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +31 -12
  70. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  71. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +33 -4
  72. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +13 -6
  73. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  74. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +25 -2
  75. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +26 -12
  76. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +11 -4
  77. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +23 -2
  78. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +27 -11
  79. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +24 -17
  80. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +22 -2
  81. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +45 -11
  82. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +14 -0
  83. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +31 -21
  84. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +9 -0
  85. package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +24 -10
  86. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +13 -8
  87. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  88. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +26 -2
  89. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +8 -0
  90. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +8 -0
  91. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +8 -0
  92. package/project/.sdk/src/cmp/ts/fragment/EntityPatchOp.fragment.ts +8 -0
  93. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +8 -0
  94. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +8 -0
  95. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +12 -5
  96. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +23 -11
  97. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +17 -10
  98. package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +41 -6
  99. package/project/.sdk/tm/c/core/context.c +1 -0
  100. package/project/.sdk/tm/c/core/sdk.h +7 -4
  101. package/project/.sdk/tm/c/feature/cache.c +243 -13
  102. package/project/.sdk/tm/c/feature/metrics.c +7 -0
  103. package/project/.sdk/tm/c/feature/paging.c +231 -2
  104. package/project/.sdk/tm/c/feature/ratelimit.c +5 -9
  105. package/project/.sdk/tm/c/feature/retry.c +51 -4
  106. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  107. package/project/.sdk/tm/c/feature/streaming.c +2 -1
  108. package/project/.sdk/tm/c/feature/telemetry.c +19 -18
  109. package/project/.sdk/tm/c/feature/test.c +78 -54
  110. package/project/.sdk/tm/c/tests/feature_test.c +288 -0
  111. package/project/.sdk/tm/c/tests/primary_utility_test.c +2 -0
  112. package/project/.sdk/tm/c/utility/clean.c +26 -33
  113. package/project/.sdk/tm/c/utility/make_options.c +89 -17
  114. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  115. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  116. package/project/.sdk/tm/clojure/src/sdk/core.clj +50 -22
  117. package/project/.sdk/tm/clojure/src/sdk/features.clj +279 -80
  118. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +103 -1
  119. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  120. package/project/.sdk/tm/cpp/Makefile +5 -0
  121. package/project/.sdk/tm/cpp/core/types.hpp +148 -72
  122. package/project/.sdk/tm/cpp/feature/audit.hpp +12 -8
  123. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  124. package/project/.sdk/tm/cpp/feature/metrics.hpp +19 -0
  125. package/project/.sdk/tm/cpp/feature/paging.hpp +160 -2
  126. package/project/.sdk/tm/cpp/feature/ratelimit.hpp +18 -14
  127. package/project/.sdk/tm/cpp/feature/retry.hpp +46 -5
  128. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  129. package/project/.sdk/tm/cpp/feature/streaming.hpp +2 -1
  130. package/project/.sdk/tm/cpp/feature/telemetry.hpp +17 -10
  131. package/project/.sdk/tm/cpp/feature/test.hpp +63 -53
  132. package/project/.sdk/tm/cpp/test/feature_test.cpp +236 -0
  133. package/project/.sdk/tm/cpp/utility/pipeline.hpp +44 -12
  134. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  135. package/project/.sdk/tm/csharp/feature/AuditFeature.cs +8 -1
  136. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  137. package/project/.sdk/tm/csharp/feature/MetricsFeature.cs +23 -0
  138. package/project/.sdk/tm/csharp/feature/PagingFeature.cs +130 -3
  139. package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +26 -19
  140. package/project/.sdk/tm/csharp/feature/RetryFeature.cs +41 -7
  141. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  142. package/project/.sdk/tm/csharp/feature/StreamingFeature.cs +2 -1
  143. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +11 -9
  144. package/project/.sdk/tm/csharp/feature/TestFeature.cs +55 -67
  145. package/project/.sdk/tm/csharp/test/FeatureTest.cs +238 -0
  146. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  147. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  148. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +94 -24
  149. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  150. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  151. package/project/.sdk/tm/elixir/lib/projectname/feature/metrics.ex +13 -0
  152. package/project/.sdk/tm/elixir/lib/projectname/feature/paging.ex +110 -5
  153. package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +6 -12
  154. package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +33 -9
  155. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  156. package/project/.sdk/tm/elixir/lib/projectname/feature/streaming.ex +2 -1
  157. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +7 -7
  158. package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +52 -48
  159. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +77 -47
  160. package/project/.sdk/tm/elixir/test/feature_test.exs +198 -0
  161. package/project/.sdk/tm/go/core/context.go +6 -0
  162. package/project/.sdk/tm/go/feature/audit_feature.go +1 -3
  163. package/project/.sdk/tm/go/feature/base_feature.go +11 -0
  164. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  165. package/project/.sdk/tm/go/feature/metrics_feature.go +14 -0
  166. package/project/.sdk/tm/go/feature/paging_feature.go +108 -2
  167. package/project/.sdk/tm/go/feature/ratelimit_feature.go +19 -17
  168. package/project/.sdk/tm/go/feature/retry_feature.go +81 -9
  169. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  170. package/project/.sdk/tm/go/feature/streaming_feature.go +2 -1
  171. package/project/.sdk/tm/go/feature/telemetry_feature.go +18 -11
  172. package/project/.sdk/tm/go/feature/test_feature.go +65 -55
  173. package/project/.sdk/tm/go/test/feature_corpus_test.go +357 -28
  174. package/project/.sdk/tm/go/test/feature_test.go +93 -0
  175. package/project/.sdk/tm/go/utility/clean.go +5 -7
  176. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  177. package/project/.sdk/tm/go/utility/make_options.go +116 -13
  178. package/project/.sdk/tm/java/core/Context.java +9 -0
  179. package/project/.sdk/tm/java/core/SdkClient.java +43 -14
  180. package/project/.sdk/tm/java/feature/AuditFeature.java +5 -1
  181. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  182. package/project/.sdk/tm/java/feature/MetricsFeature.java +31 -0
  183. package/project/.sdk/tm/java/feature/PagingFeature.java +156 -2
  184. package/project/.sdk/tm/java/feature/RatelimitFeature.java +15 -13
  185. package/project/.sdk/tm/java/feature/RetryFeature.java +33 -6
  186. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  187. package/project/.sdk/tm/java/feature/StreamingFeature.java +2 -1
  188. package/project/.sdk/tm/java/feature/TelemetryFeature.java +17 -9
  189. package/project/.sdk/tm/java/feature/TestFeature.java +50 -63
  190. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +309 -17
  191. package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
  192. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  193. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  194. package/project/.sdk/tm/java/utility/MakeOptions.java +131 -15
  195. package/project/.sdk/tm/js/src/Context.js +4 -0
  196. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  197. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  198. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +9 -4
  199. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +103 -5
  200. package/project/.sdk/tm/js/src/feature/ratelimit/RatelimitFeature.js +5 -9
  201. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  202. package/project/.sdk/tm/js/src/feature/retry/RetryFeature.js +25 -3
  203. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  204. package/project/.sdk/tm/js/src/feature/streaming/StreamingFeature.js +2 -1
  205. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +11 -6
  206. package/project/.sdk/tm/js/src/feature/test/TestFeature.js +38 -1
  207. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  208. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  209. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +61 -12
  210. package/project/.sdk/tm/js/test/feature/Corpus.test.js +191 -23
  211. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  212. package/project/.sdk/tm/js/test/feature.test.js +14 -1
  213. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  214. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  215. package/project/.sdk/tm/kotlin/core/SdkClient.kt +23 -10
  216. package/project/.sdk/tm/kotlin/feature/AuditFeature.kt +5 -1
  217. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  218. package/project/.sdk/tm/kotlin/feature/MetricsFeature.kt +22 -0
  219. package/project/.sdk/tm/kotlin/feature/PagingFeature.kt +125 -2
  220. package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +16 -13
  221. package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +36 -14
  222. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  223. package/project/.sdk/tm/kotlin/feature/StreamingFeature.kt +4 -0
  224. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +12 -10
  225. package/project/.sdk/tm/kotlin/feature/TestFeature.kt +45 -48
  226. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +173 -0
  227. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  228. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  229. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +86 -15
  230. package/project/.sdk/tm/lua/core/context.lua +6 -0
  231. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  232. package/project/.sdk/tm/lua/feature/debug_feature.lua +2 -3
  233. package/project/.sdk/tm/lua/feature/metrics_feature.lua +5 -0
  234. package/project/.sdk/tm/lua/feature/paging_feature.lua +143 -2
  235. package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +5 -9
  236. package/project/.sdk/tm/lua/feature/retry_feature.lua +43 -5
  237. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  238. package/project/.sdk/tm/lua/feature/streaming_feature.lua +2 -1
  239. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +18 -7
  240. package/project/.sdk/tm/lua/feature/test_feature.lua +60 -62
  241. package/project/.sdk/tm/lua/test/feature_test.lua +181 -3
  242. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  243. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  244. package/project/.sdk/tm/lua/utility/make_options.lua +60 -18
  245. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  246. package/project/.sdk/tm/ocaml/sdk_features.ml +392 -68
  247. package/project/.sdk/tm/ocaml/sdk_runtime.ml +47 -21
  248. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  249. package/project/.sdk/tm/ocaml/test/t_feature.ml +107 -2
  250. package/project/.sdk/tm/perl/core/context.pm +3 -0
  251. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  252. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  253. package/project/.sdk/tm/perl/feature/debug_feature.pm +2 -2
  254. package/project/.sdk/tm/perl/feature/metrics_feature.pm +5 -0
  255. package/project/.sdk/tm/perl/feature/paging_feature.pm +139 -2
  256. package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +5 -11
  257. package/project/.sdk/tm/perl/feature/retry_feature.pm +22 -4
  258. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  259. package/project/.sdk/tm/perl/feature/streaming_feature.pm +2 -0
  260. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +17 -8
  261. package/project/.sdk/tm/perl/feature/test_feature.pm +45 -50
  262. package/project/.sdk/tm/perl/t/feature.t +68 -2
  263. package/project/.sdk/tm/perl/t/feature_corpus.t +204 -25
  264. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  265. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  266. package/project/.sdk/tm/perl/utility/make_options.pm +38 -15
  267. package/project/.sdk/tm/php/core/Context.php +4 -0
  268. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  269. package/project/.sdk/tm/php/feature/MetricsFeature.php +8 -0
  270. package/project/.sdk/tm/php/feature/PagingFeature.php +128 -1
  271. package/project/.sdk/tm/php/feature/RatelimitFeature.php +5 -9
  272. package/project/.sdk/tm/php/feature/RetryFeature.php +27 -3
  273. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  274. package/project/.sdk/tm/php/feature/StreamingFeature.php +2 -1
  275. package/project/.sdk/tm/php/feature/TelemetryFeature.php +10 -7
  276. package/project/.sdk/tm/php/feature/TestFeature.php +55 -47
  277. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +262 -17
  278. package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
  279. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  280. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  281. package/project/.sdk/tm/php/utility/MakeOptions.php +45 -20
  282. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  283. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  284. package/project/.sdk/tm/py/pkg/feature/metrics_feature.py +7 -0
  285. package/project/.sdk/tm/py/pkg/feature/paging_feature.py +86 -1
  286. package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +13 -16
  287. package/project/.sdk/tm/py/pkg/feature/retry_feature.py +31 -6
  288. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  289. package/project/.sdk/tm/py/pkg/feature/streaming_feature.py +2 -1
  290. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +10 -6
  291. package/project/.sdk/tm/py/pkg/feature/test_feature.py +56 -53
  292. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  293. package/project/.sdk/tm/py/pkg/utility/make_options.py +77 -30
  294. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  295. package/project/.sdk/tm/py/test/test_feature.py +61 -1
  296. package/project/.sdk/tm/py/test/test_feature_corpus.py +197 -17
  297. package/project/.sdk/tm/py-data/pkg/fetch.py +6 -3
  298. package/project/.sdk/tm/py-data/test/test_fetch.py +7 -4
  299. package/project/.sdk/tm/rb/core/context.rb +4 -1
  300. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  301. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  302. package/project/.sdk/tm/rb/feature/debug_feature.rb +2 -2
  303. package/project/.sdk/tm/rb/feature/metrics_feature.rb +8 -0
  304. package/project/.sdk/tm/rb/feature/paging_feature.rb +87 -1
  305. package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +12 -16
  306. package/project/.sdk/tm/rb/feature/retry_feature.rb +19 -3
  307. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  308. package/project/.sdk/tm/rb/feature/streaming_feature.rb +2 -1
  309. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +11 -6
  310. package/project/.sdk/tm/rb/feature/test_feature.rb +42 -49
  311. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +191 -25
  312. package/project/.sdk/tm/rb/test/feature_test.rb +75 -1
  313. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  314. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  315. package/project/.sdk/tm/rb/utility/make_options.rb +37 -16
  316. package/project/.sdk/tm/rust/core/context.rs +8 -0
  317. package/project/.sdk/tm/rust/feature/audit.rs +2 -2
  318. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  319. package/project/.sdk/tm/rust/feature/metrics.rs +24 -1
  320. package/project/.sdk/tm/rust/feature/paging.rs +189 -3
  321. package/project/.sdk/tm/rust/feature/ratelimit.rs +5 -10
  322. package/project/.sdk/tm/rust/feature/retry.rs +59 -6
  323. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  324. package/project/.sdk/tm/rust/feature/streaming.rs +3 -2
  325. package/project/.sdk/tm/rust/feature/support.rs +4 -0
  326. package/project/.sdk/tm/rust/feature/telemetry.rs +22 -11
  327. package/project/.sdk/tm/rust/feature/test.rs +63 -57
  328. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  329. package/project/.sdk/tm/rust/tests/feature_test.rs +274 -0
  330. package/project/.sdk/tm/rust/tests/primary_utility_test.rs +1 -0
  331. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  332. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  333. package/project/.sdk/tm/rust/utility/make_options.rs +130 -38
  334. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  335. package/project/.sdk/tm/scala/core/SdkClient.scala +45 -11
  336. package/project/.sdk/tm/scala/feature/AuditFeature.scala +6 -1
  337. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  338. package/project/.sdk/tm/scala/feature/MetricsFeature.scala +31 -1
  339. package/project/.sdk/tm/scala/feature/PagingFeature.scala +122 -2
  340. package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +14 -11
  341. package/project/.sdk/tm/scala/feature/RetryFeature.scala +29 -7
  342. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  343. package/project/.sdk/tm/scala/feature/StreamingFeature.scala +2 -1
  344. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +12 -10
  345. package/project/.sdk/tm/scala/feature/TestFeature.scala +44 -44
  346. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +69 -0
  347. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  348. package/project/.sdk/tm/scala/utility/Make.scala +99 -14
  349. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  350. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  351. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/AuditFeature.swift +3 -2
  352. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  353. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/MetricsFeature.swift +20 -0
  354. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/PagingFeature.swift +102 -2
  355. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +19 -13
  356. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +40 -5
  357. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  358. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/StreamingFeature.swift +2 -1
  359. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +11 -9
  360. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +55 -49
  361. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  362. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +56 -17
  363. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  364. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +166 -0
  365. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  366. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  367. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  368. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +6 -1
  369. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +103 -5
  370. package/project/.sdk/tm/ts/src/feature/ratelimit/RatelimitFeature.ts +5 -9
  371. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  372. package/project/.sdk/tm/ts/src/feature/retry/RetryFeature.ts +25 -3
  373. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  374. package/project/.sdk/tm/ts/src/feature/streaming/StreamingFeature.ts +2 -1
  375. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +11 -6
  376. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +8 -7
  377. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  378. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  379. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +63 -12
  380. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +192 -23
  381. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  382. package/project/.sdk/tm/ts/test/feature.test.ts +14 -1
  383. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  384. package/project/.sdk/tm/zig/core/context.zig +5 -0
  385. package/project/.sdk/tm/zig/core/utility.zig +118 -17
  386. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  387. package/project/.sdk/tm/zig/feature/metrics.zig +19 -0
  388. package/project/.sdk/tm/zig/feature/paging.zig +172 -4
  389. package/project/.sdk/tm/zig/feature/ratelimit.zig +5 -11
  390. package/project/.sdk/tm/zig/feature/retry.zig +41 -3
  391. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  392. package/project/.sdk/tm/zig/feature/streaming.zig +2 -0
  393. package/project/.sdk/tm/zig/feature/telemetry.zig +15 -9
  394. package/project/.sdk/tm/zig/feature/test.zig +56 -40
  395. package/project/.sdk/tm/zig/test/feature_test.zig +174 -0
  396. package/project/.sdk/tm/zig/test/primary_utility_test.zig +2 -0
  397. package/project/sdkgen-package.json +1 -1
  398. package/src/cmp/ReadmeExplanation.ts +5 -2
  399. package/src/cmp/ReadmeFeatures.ts +21 -6
  400. package/src/helpers/optspec.ts +2 -2
@@ -113,6 +113,50 @@ let log_feature () : feature =
113
113
  (* retry *)
114
114
  (* ------------------------------------------------------------------ *)
115
115
 
116
+ (* RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else None. A date
117
+ needs the wall clock, which the stdlib lacks: with no [now] it is None. *)
118
+ let retry_after_ms value (now : float option) =
119
+ let is_ws c = c = ' ' || c = '\t' in
120
+ let n = String.length value in
121
+ let i = ref 0 and j = ref n in
122
+ while !i < n && is_ws value.[!i] do incr i done;
123
+ while !j > !i && is_ws value.[!j - 1] do decr j done;
124
+ let s = String.sub value !i (!j - !i) in
125
+ let len = String.length s in
126
+ let num a b =
127
+ let r = ref 0. in
128
+ (try for k = a to b - 1 do
129
+ match s.[k] with
130
+ | '0' .. '9' as c -> r := !r *. 10. +. float_of_int (Char.code c - 48)
131
+ | _ -> raise Exit
132
+ done; !r
133
+ with Exit -> -1.) in
134
+ let find hay x =
135
+ let rec go k = if k + 3 > String.length hay then -1
136
+ else if String.sub hay k 3 = x then k else go (k + 1) in go 0 in
137
+ if len > 0 && num 0 len >= 0. then Some (num 0 len *. 1000.)
138
+ else if now = None || len <> 29 || String.sub s 3 2 <> ", " || s.[7] <> ' ' || s.[11] <> ' '
139
+ || s.[16] <> ' ' || s.[19] <> ':' || s.[22] <> ':' || String.sub s 25 4 <> " GMT"
140
+ || not (List.mem (String.sub s 0 3) ["Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"; "Sun"])
141
+ then None
142
+ else
143
+ let mi = find "JanFebMarAprMayJunJulAugSepOctNovDec" (String.sub s 8 3) in
144
+ let day = num 5 7 and year = num 12 16 and hour = num 17 19
145
+ and minute = num 20 22 and sec = num 23 25 in
146
+ if mi < 0 || mi mod 3 <> 0 || day < 1. || day > 31. || year < 0. || hour < 0. || hour > 23.
147
+ || minute < 0. || minute > 59. || sec < 0. || sec > 60. then None
148
+ else begin
149
+ let m = mi / 3 + 1 in
150
+ let y = int_of_float year - (if m <= 2 then 1 else 0) in
151
+ let era = (if y >= 0 then y else y - 399) / 400 in
152
+ let yoe = y - era * 400 in
153
+ let doy = (153 * ((m + 9) mod 12) + 2) / 5 + int_of_float day - 1 in
154
+ let doe = yoe * 365 + yoe / 4 - yoe / 100 + doy in
155
+ let days = float_of_int (era * 146097 + doe - 719468) in
156
+ let at = (((days *. 24. +. hour) *. 60. +. minute) *. 60. +. sec) *. 1000. in
157
+ Some (Float.max 0. (at -. Option.get now))
158
+ end
159
+
116
160
  let retry_feature () : feature =
117
161
  let options = ref (empty_map ()) in
118
162
  let f = { f_name = "retry"; f_version = "0.0.1"; f_active = true; f_options = Noval;
@@ -123,7 +167,7 @@ let retry_feature () : feature =
123
167
  (match getp res_v "headers" with
124
168
  | Map _ as h -> (match header_ci h "retry-after" with
125
169
  | Noval | Null -> None
126
- | v -> (try Some (float_of_string (vstr_of v) *. 1000.) with _ -> None))
170
+ | v -> retry_after_ms (vstr_of v) None)
127
171
  | _ -> None)
128
172
  | _ -> None
129
173
  in
@@ -235,16 +279,14 @@ let ratelimit_feature () : feature =
235
279
  let r = rate () and b = burst () in
236
280
  let now = now_of !options in
237
281
  let elapsed = now -. !last in
282
+ (* Refill, then reserve this call's token before any wait: a negative
283
+ count is the calls already queued, so overlapping calls pace in turn. *)
238
284
  last := now;
239
- tokens := Float.min b (!tokens +. (elapsed /. 1000.) *. r);
240
- if !tokens >= 1. then tokens := !tokens -. 1.
241
- else begin
242
- let needed = 1. -. !tokens in
243
- let wait_ms = Float.of_int (int_of_float (ceil ((needed /. r) *. 1000.))) in
285
+ tokens := Float.min b (!tokens +. (elapsed /. 1000.) *. r) -. 1.;
286
+ if !tokens < 0. then begin
287
+ let wait_ms = Float.of_int (int_of_float (ceil ((-. !tokens /. r) *. 1000.))) in
244
288
  track ctx wait_ms;
245
- sleep_of !options wait_ms;
246
- last := now_of !options;
247
- tokens := 0.
289
+ sleep_of !options wait_ms
248
290
  end in
249
291
  f.f_init <- (fun ctx opts ->
250
292
  options := (match to_map opts with Map _ -> opts | _ -> empty_map ());
@@ -262,9 +304,93 @@ let ratelimit_feature () : feature =
262
304
  (* cache *)
263
305
  (* ------------------------------------------------------------------ *)
264
306
 
307
+ (* No HMAC in the stdlib: HMAC-MD5 over Digest separates header sets within
308
+ one client's store without holding a header value. It is not a
309
+ cryptographic commitment. *)
310
+ let cache_hmac (key : string) (msg : string) : string =
311
+ let key = if String.length key > 64 then Digest.string key else key in
312
+ let key = key ^ String.make (64 - String.length key) '\000' in
313
+ let pad c = String.map (fun ch -> Char.chr (Char.code ch lxor c)) key in
314
+ Digest.to_hex (Digest.string (pad 0x5c ^ Digest.string (pad 0x36 ^ msg)))
315
+
316
+ let cache_secret () : string =
317
+ let from_os =
318
+ try
319
+ let ic = open_in_bin "/dev/urandom" in
320
+ Fun.protect ~finally:(fun () -> close_in_noerr ic) (fun () -> Some (really_input_string ic 32))
321
+ with _ -> None in
322
+ match from_os with
323
+ | Some s -> s
324
+ | None ->
325
+ let st = Random.State.make_self_init () in
326
+ String.init 32 (fun _ -> Char.chr (Random.State.int st 256))
327
+
328
+ let cache_header_text (v : value) : string option =
329
+ match v with Noval | Null -> None | Str s -> Some s | _ -> Some (vstr_of v)
330
+
331
+ let cache_digest (secret : string) (headers : value) : string =
332
+ let pairs = match headers with
333
+ | Map _ ->
334
+ List.filter_map (fun k ->
335
+ Option.map (fun t -> (string_lower k, t)) (cache_header_text (getp headers k))) (keysof headers)
336
+ | _ -> [] in
337
+ let text = String.concat "" (List.map (fun (k, v) -> k ^ ":" ^ v ^ "\n") (List.sort compare pairs)) in
338
+ cache_hmac secret text
339
+
340
+ (* The configured ttl capped by the response's Cache-Control; zero when the
341
+ response may not be stored. *)
342
+ let cache_lifetime (headers : value) (ttl : float) : float =
343
+ let control = match headers with
344
+ | Map _ ->
345
+ List.fold_left (fun acc k ->
346
+ if string_lower k = "cache-control" then
347
+ (match cache_header_text (getp headers k) with Some t -> string_lower t | None -> acc)
348
+ else acc) "" (keysof headers)
349
+ | _ -> "" in
350
+ let directives = List.map String.trim (String.split_on_char ',' control) in
351
+ if List.exists (fun d -> List.mem d ["no-store"; "private"; "no-cache"]) directives then 0.
352
+ else
353
+ List.fold_left (fun life d ->
354
+ let n = String.length d in
355
+ if n > 7 && String.sub d 0 7 = "max-age" then begin
356
+ let rest = String.trim (String.sub d 7 (n - 7)) in
357
+ if String.length rest > 0 && rest.[0] = '=' then begin
358
+ let v = String.trim (String.sub rest 1 (String.length rest - 1)) in
359
+ let lv = String.length v in
360
+ let v = if lv >= 2 && v.[0] = '"' && v.[lv - 1] = '"' then String.sub v 1 (lv - 2) else v in
361
+ let rec digits i = i >= String.length v || (v.[i] >= '0' && v.[i] <= '9' && digits (i + 1)) in
362
+ if v <> "" && digits 0 then
363
+ (match float_of_string_opt v with Some secs -> Float.min life (secs *. 1000.) | None -> life)
364
+ else life
365
+ end else life
366
+ end else life) ttl directives
367
+
368
+ let cache_scope (url : string) : string =
369
+ let n = String.length url in
370
+ let rec cut i = if i >= n then n else (match url.[i] with '?' | '#' -> i | _ -> cut (i + 1)) in
371
+ let rec trim e = if e > 0 && url.[e - 1] = '/' then trim (e - 1) else e in
372
+ String.sub url 0 (trim (cut 0))
373
+
374
+ let cache_parent (scope : string) : string =
375
+ let n = String.length scope in
376
+ let rec find_scheme i = if i + 3 > n then None else if String.sub scope i 3 = "://" then Some i else find_scheme (i + 1) in
377
+ let root = match find_scheme 0 with
378
+ | None -> Some 0
379
+ | Some at -> String.index_from_opt scope (at + 3) '/' in
380
+ match root with
381
+ | None -> scope
382
+ | Some root ->
383
+ let cut = match String.rindex_opt scope '/' with Some c -> c | None -> 0 in
384
+ String.sub scope 0 (max cut root)
385
+
386
+ let cache_under (scope : string) (prefix : string) : bool =
387
+ let lp = String.length prefix in
388
+ scope = prefix || (String.length scope > lp && String.sub scope 0 lp = prefix && scope.[lp] = '/')
389
+
265
390
  let cache_feature () : feature =
266
391
  let options = ref (empty_map ()) in
267
392
  let store = ref [] in
393
+ let secret = ref "" in
268
394
  let f = { f_name = "cache"; f_version = "0.0.1"; f_active = true; f_options = Noval;
269
395
  f_init = (fun _ _ -> ()); f_hook = (fun _ _ -> ()) } in
270
396
  let track ctx kind =
@@ -293,12 +419,20 @@ let cache_feature () : feature =
293
419
  let evict () =
294
420
  let mx = opt_int !options "max" ~default:256 in
295
421
  while List.length !store >= mx do (match !store with _ :: tl -> store := tl | [] -> ()) done in
422
+ let invalidate url =
423
+ let path = cache_scope url in
424
+ let collection = cache_parent path in
425
+ store := List.filter (fun (_, e) ->
426
+ let scope = vstr_of (getp e "scope") in
427
+ not (cache_under scope path || scope = collection)) !store in
296
428
  let through ctx url fetchdef inner =
297
429
  let meth = match getp fetchdef "method" with Str s -> string_upper s | _ -> "GET" in
298
430
  let methods = List.map string_upper (opt_str_list !options "methods" ~default:["GET"]) in
299
- if not (List.mem meth methods) then inner ctx url fetchdef
300
- else begin
301
- let key = meth ^ " " ^ url in
431
+ if not (List.mem meth methods) then begin
432
+ if meth = "GET" || meth = "HEAD" then inner ctx url fetchdef
433
+ else Fun.protect ~finally:(fun () -> invalidate url) (fun () -> inner ctx url fetchdef)
434
+ end else begin
435
+ let key = meth ^ " " ^ url ^ " " ^ cache_digest !secret (getp fetchdef "headers") in
302
436
  let now = now_of !options in
303
437
  match List.assoc_opt key !store with
304
438
  | Some hit when (match getp hit "expiry" with Num e -> e > now | _ -> false) ->
@@ -309,11 +443,16 @@ let cache_feature () : feature =
309
443
  if err = None && cacheable res && not (json res) then (track ctx "bypass"; (res, err))
310
444
  else if err = None && cacheable res then begin
311
445
  let snap = snapshot res in
312
- let ttl = opt_num !options "ttl" ~default:5000. in
313
- evict ();
314
- store := (List.remove_assoc key !store) @ [(key, jo [("expiry", Num (now +. ttl)); ("snapshot", snap)])];
315
- track ctx "miss";
316
- (replay snap, None)
446
+ let ttl = cache_lifetime (getp snap "headers") (opt_num !options "ttl" ~default:5000.) in
447
+ if ttl <= 0. then (track ctx "bypass"; (replay snap, None))
448
+ else begin
449
+ store := List.remove_assoc key !store;
450
+ evict ();
451
+ store := !store @ [(key, jo [("expiry", Num (now +. ttl)); ("scope", Str (cache_scope url));
452
+ ("snapshot", snap)])];
453
+ track ctx "miss";
454
+ (replay snap, None)
455
+ end
317
456
  end else (track ctx "bypass"; (res, err))
318
457
  end in
319
458
  f.f_init <- (fun ctx opts ->
@@ -321,6 +460,7 @@ let cache_feature () : feature =
321
460
  f.f_active <- opt_active opts;
322
461
  if f.f_active then begin
323
462
  store := [];
463
+ secret := cache_secret ();
324
464
  let u = cu ctx in
325
465
  let inner = u.u_fetcher in
326
466
  u.u_fetcher <- (fun fctx url fd -> through fctx url fd inner)
@@ -605,7 +745,10 @@ let metrics_feature () : feature =
605
745
  let ops = getp m "ops" in
606
746
  let opb = match getp ops key with Map _ as b -> b
607
747
  | _ -> let b = jo [("count", Num 0.); ("ok", Num 0.); ("err", Num 0.); ("totalMs", Num 0.); ("maxMs", Num 0.)] in setp ops key b; b in
608
- bump (getp m "total") ok dur; bump opb ok dur
748
+ bump (getp m "total") ok dur; bump opb ok dur;
749
+ (match getp !options "sink" with
750
+ | Func _ as fn -> (try ignore (call_vfn fn ((cu ctx).u_clean ctx m)) with _ -> ())
751
+ | _ -> ())
609
752
  | _ -> () in
610
753
  f.f_init <- (fun ctx opts ->
611
754
  options := (match to_map opts with Map _ -> opts | _ -> empty_map ());
@@ -625,9 +768,29 @@ let metrics_feature () : feature =
625
768
  (* telemetry *)
626
769
  (* ------------------------------------------------------------------ *)
627
770
 
771
+ (* W3C trace context: lowercase hex from the platform's random source, never all
772
+ zeros. Where /dev/urandom cannot be read, Random stands in. *)
773
+ let telemetry_random_hex nbytes =
774
+ let read () =
775
+ try
776
+ let ic = open_in_bin "/dev/urandom" in
777
+ let s = (try really_input_string ic nbytes with e -> close_in ic; raise e) in
778
+ close_in ic; s
779
+ with _ -> String.init nbytes (fun _ -> Char.chr (Random.int 256)) in
780
+ let rec go () =
781
+ let s = read () in
782
+ let zero = ref true in
783
+ String.iter (fun c -> if c <> '\000' then zero := false) s;
784
+ if !zero then go ()
785
+ else begin
786
+ let b = Buffer.create (2 * nbytes) in
787
+ String.iter (fun c -> Buffer.add_string b (Printf.sprintf "%02x" (Char.code c))) s;
788
+ Buffer.contents b
789
+ end in
790
+ go ()
791
+
628
792
  let telemetry_feature () : feature =
629
793
  let options = ref (empty_map ()) in
630
- let seq = ref 0 in
631
794
  let f = { f_name = "telemetry"; f_version = "0.0.1"; f_active = true; f_options = Noval;
632
795
  f_init = (fun _ _ -> ()); f_hook = (fun _ _ -> ()) } in
633
796
  let telemetry ctx = track_bucket (cc ctx) "telemetry"
@@ -635,11 +798,7 @@ let telemetry_feature () : feature =
635
798
  let gen_id kind =
636
799
  match getp !options "idgen" with
637
800
  | Func _ as fn -> vstr_of (call_vfn fn (Str kind))
638
- | _ ->
639
- incr seq;
640
- let n = Printf.sprintf "%04x" !seq in
641
- let padded = n ^ String.make (max 0 (16 - String.length n)) '0' in
642
- (if kind = "trace" then "t" else "s") ^ padded in
801
+ | _ -> telemetry_random_hex (if kind = "trace" then 16 else 8) in
643
802
  let close ctx ok =
644
803
  match scratch_get ctx "telemetry_span" with
645
804
  | Some (Map _ as span) ->
@@ -657,7 +816,6 @@ let telemetry_feature () : feature =
657
816
  f.f_init <- (fun ctx opts ->
658
817
  options := (match to_map opts with Map _ -> opts | _ -> empty_map ());
659
818
  f.f_active <- opt_active opts;
660
- seq := 0;
661
819
  ignore (telemetry ctx));
662
820
  f.f_hook <- (fun name ctx ->
663
821
  if f.f_active then match name with
@@ -1115,6 +1273,143 @@ let graphql_pre_request (options : value) (spec : spec) (point : value)
1115
1273
  then setp variables first_var lim)
1116
1274
  | _ -> ()
1117
1275
 
1276
+ (* The length of a URL's scheme and authority, or zero when it has none. *)
1277
+ let paging_origin_len (s : string) : int =
1278
+ let n = String.length s in
1279
+ let is_alpha c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') in
1280
+ let is_scheme c = is_alpha c || (c >= '0' && c <= '9') || c = '+' || c = '.' || c = '-' in
1281
+ if n = 0 || not (is_alpha s.[0]) then 0
1282
+ else begin
1283
+ let i = ref 1 in
1284
+ while !i < n && is_scheme s.[!i] do incr i done;
1285
+ if !i + 3 <= n && String.sub s !i 3 = "://" then begin
1286
+ let j = ref (!i + 3) in
1287
+ while !j < n && s.[!j] <> '/' && s.[!j] <> '?' && s.[!j] <> '#' do incr j done;
1288
+ !j
1289
+ end else 0
1290
+ end
1291
+
1292
+ (* Under the `next` option's default, a URL or an absolute path is a link and
1293
+ * anything else a cursor; `cursor` and `url` pin the reading. *)
1294
+ let paging_is_link (v : value) (mode : string) : bool = match v with
1295
+ | Str s ->
1296
+ mode = "url" ||
1297
+ (mode <> "cursor" && (paging_origin_len s > 0 || (String.length s > 0 && s.[0] = '/')))
1298
+ | _ -> false
1299
+
1300
+ let paging_origin_of (s : string) : string =
1301
+ String.lowercase_ascii (String.sub s 0 (paging_origin_len s))
1302
+
1303
+ let paging_foreign (link : string) (base : string) : bool =
1304
+ let origin = paging_origin_of link in
1305
+ origin <> "" && origin <> paging_origin_of base
1306
+
1307
+ let paging_unescape (s : string) : string =
1308
+ let n = String.length s in
1309
+ let b = Buffer.create n in
1310
+ let hex c = match c with
1311
+ | '0'..'9' -> Some (Char.code c - 48)
1312
+ | 'a'..'f' -> Some (Char.code c - 87)
1313
+ | 'A'..'F' -> Some (Char.code c - 55)
1314
+ | _ -> None in
1315
+ let i = ref 0 in
1316
+ while !i < n do
1317
+ (match s.[!i] with
1318
+ | '+' -> Buffer.add_char b ' '
1319
+ | '%' when !i + 2 < n ->
1320
+ (match hex s.[!i + 1], hex s.[!i + 2] with
1321
+ | Some h, Some l -> Buffer.add_char b (Char.chr (h * 16 + l)); i := !i + 2
1322
+ | _ -> Buffer.add_char b '%')
1323
+ | c -> Buffer.add_char b c);
1324
+ incr i
1325
+ done;
1326
+ Buffer.contents b
1327
+
1328
+ let paging_has_scheme (s : string) : bool =
1329
+ let n = String.length s in
1330
+ let is_alpha c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') in
1331
+ let is_scheme c = is_alpha c || (c >= '0' && c <= '9') || c = '+' || c = '.' || c = '-' in
1332
+ if n = 0 || not (is_alpha s.[0]) then false
1333
+ else begin
1334
+ let i = ref 1 in
1335
+ while !i < n && is_scheme s.[!i] do incr i done;
1336
+ !i < n && s.[!i] = ':'
1337
+ end
1338
+
1339
+ let paging_cut (s : string) (c : char) : string * string option =
1340
+ match String.index_opt s c with
1341
+ | Some k -> (String.sub s 0 k, Some (String.sub s (k + 1) (String.length s - k - 1)))
1342
+ | None -> (s, None)
1343
+
1344
+ (* RFC 3986 section 5.2.4. *)
1345
+ let paging_remove_dots (path : string) : string =
1346
+ let abs = String.length path > 0 && path.[0] = '/' in
1347
+ let segs = String.split_on_char '/' path in
1348
+ let segs = if abs then List.tl segs else segs in
1349
+ let n = List.length segs in
1350
+ let step (i, acc) seg =
1351
+ let acc =
1352
+ if seg = "." || seg = ".." then begin
1353
+ let acc = if seg = ".." then (match acc with _ :: tl -> tl | [] -> []) else acc in
1354
+ if i = n - 1 then "" :: acc else acc
1355
+ end else seg :: acc in
1356
+ (i + 1, acc) in
1357
+ let out = List.rev (snd (List.fold_left step (0, []) segs)) in
1358
+ (if abs then "/" else "") ^ String.concat "/" out
1359
+
1360
+ (* RFC 3986 reference resolution against the URL of the request that returned
1361
+ * the link, by hand: the standard library has no resolver. A link on that
1362
+ * URL's origin comes back as its path and query; an absolute link is left as
1363
+ * it is. *)
1364
+ let paging_resolve (link : string) (url : string) : string =
1365
+ if url = "" || paging_has_scheme link then link
1366
+ else begin
1367
+ let link = fst (paging_cut link '#') in
1368
+ let on = paging_origin_len url in
1369
+ if String.length link >= 2 && String.sub link 0 2 = "//" then
1370
+ (if on = 0 then link else fst (paging_cut url ':') ^ ":" ^ link)
1371
+ else begin
1372
+ let from = fst (paging_cut (String.sub url on (String.length url - on)) '#') in
1373
+ let (bpath, bquery) = paging_cut from '?' in
1374
+ let (rpath, rquery) = paging_cut link '?' in
1375
+ let (path, query) =
1376
+ if rpath = "" then (bpath, (match rquery with Some _ -> rquery | None -> bquery))
1377
+ else if rpath.[0] = '/' then (paging_remove_dots rpath, rquery)
1378
+ else begin
1379
+ let dir = match String.rindex_opt bpath '/' with
1380
+ | Some k -> String.sub bpath 0 (k + 1)
1381
+ | None -> "" in
1382
+ (paging_remove_dots (dir ^ rpath), rquery)
1383
+ end in
1384
+ let path = if String.length path > 0 && path.[0] = '/' then path else "/" ^ path in
1385
+ match query with Some q -> path ^ "?" ^ q | None -> path
1386
+ end
1387
+ end
1388
+
1389
+ (* The request goes to the link's path and query, on the SDK's own origin. *)
1390
+ let paging_follow (spec : spec) (next : string) : unit =
1391
+ let skip = paging_origin_len next in
1392
+ let rest = String.sub next skip (String.length next - skip) in
1393
+ let rest = match String.index_opt rest '#' with Some i -> String.sub rest 0 i | None -> rest in
1394
+ let path, rawquery = match String.index_opt rest '?' with
1395
+ | Some i -> String.sub rest 0 i, String.sub rest (i + 1) (String.length rest - i - 1)
1396
+ | None -> rest, "" in
1397
+ let query = empty_map () in
1398
+ List.iter (fun pair ->
1399
+ if pair <> "" then
1400
+ match String.index_opt pair '=' with
1401
+ | Some i ->
1402
+ setp query (paging_unescape (String.sub pair 0 i))
1403
+ (Str (paging_unescape (String.sub pair (i + 1) (String.length pair - i - 1))))
1404
+ | None -> setp query (paging_unescape pair) (Str ""))
1405
+ (String.split_on_char '&' rawquery);
1406
+ List.iter (fun k -> setp query k (getp spec.sp_query k)) spec.sp_authquery;
1407
+ spec.sp_base <- String.sub spec.sp_base 0 (paging_origin_len spec.sp_base);
1408
+ spec.sp_prefix <- "";
1409
+ spec.sp_path <- path;
1410
+ spec.sp_suffix <- "";
1411
+ spec.sp_query <- query
1412
+
1118
1413
  let paging_feature () : feature =
1119
1414
  let options = ref (empty_map ()) in
1120
1415
  let f = { f_name = "paging"; f_version = "0.0.1"; f_active = true; f_options = Noval;
@@ -1156,6 +1451,10 @@ let paging_feature () : feature =
1156
1451
  graphql_pre_request !options spec ctx.c_point paging
1157
1452
  else begin
1158
1453
  (match getp paging "cursor" with
1454
+ | Noval | Null when (match getp paging "next" with
1455
+ | Str l -> not (paging_foreign l spec.sp_base)
1456
+ | _ -> false) ->
1457
+ paging_follow spec (vstr_of (getp paging "next"))
1159
1458
  | Noval | Null ->
1160
1459
  (match getp q page_param with
1161
1460
  | Noval ->
@@ -1173,7 +1472,10 @@ let paging_feature () : feature =
1173
1472
  | c -> setp q cursor_param c);
1174
1473
  (match getp !options "limit" with
1175
1474
  | Noval | Null -> ()
1176
- | lim -> (match getp q limit_param with Noval -> setp q limit_param lim | _ -> ()))
1475
+ | lim ->
1476
+ (match getp spec.sp_query limit_param with
1477
+ | Noval -> setp spec.sp_query limit_param lim
1478
+ | _ -> ()))
1177
1479
  end)
1178
1480
  | "PreResult" ->
1179
1481
  (match ctx.c_result with
@@ -1219,7 +1521,12 @@ let paging_feature () : feature =
1219
1521
  | _ -> ());
1220
1522
  (match body with
1221
1523
  | Map _ ->
1222
- (match getp body "next" with Noval | Null -> () | n -> if is_nullish (getp paging "next") then setp paging "next" n);
1524
+ (match getp body "next" with
1525
+ | Noval | Null -> ()
1526
+ | n ->
1527
+ if not (paging_is_link n (opt_str !options "next" ~default:"auto")) then
1528
+ setp paging "cursor" n
1529
+ else if is_nullish (getp paging "next") then setp paging "next" n);
1223
1530
  (* Both spellings, camelCase last so it wins when a body
1224
1531
  * carries the two. *)
1225
1532
  (match getp body "next_cursor" with Noval | Null -> () | c -> setp paging "cursor" c);
@@ -1235,6 +1542,18 @@ let paging_feature () : feature =
1235
1542
  | Bool b -> setp paging "hasMore" (Bool b); explicit_more := true
1236
1543
  | _ -> ()) ["has_more"; "hasMore"]
1237
1544
  | _ -> ());
1545
+ (* A link to another origin is recorded, never followed, and
1546
+ * ends the walk. *)
1547
+ let base = match ctx.c_spec with
1548
+ | Some sp -> sp.sp_base
1549
+ | None -> get_str_d ctx.c_options "base" "" in
1550
+ (match ctx.c_spec, getp paging "next" with
1551
+ | Some sp, Str l -> setp paging "next" (Str (paging_resolve l sp.sp_url))
1552
+ | _ -> ());
1553
+ (match getp paging "next" with
1554
+ | Str l when paging_foreign l base ->
1555
+ setp paging "foreign" (Str l); setp paging "next" Noval
1556
+ | _ -> ());
1238
1557
  (* Cursor presence only INFERS another page. When the server
1239
1558
  * stated the answer outright — relay's `hasNextPage: false`, or
1240
1559
  * a body `hasMore` — that wins: a final page normally carries
@@ -1248,6 +1567,9 @@ let paging_feature () : feature =
1248
1567
  || not (is_nullish (getp paging "nextPage")) in
1249
1568
  setp paging "hasMore" (Bool hm)
1250
1569
  end;
1570
+ if not (is_nullish (getp paging "foreign")) && is_nullish (getp paging "cursor")
1571
+ && is_nullish (getp paging "nextPage") then
1572
+ setp paging "hasMore" (Bool false);
1251
1573
  result.rt_paging <- paging;
1252
1574
  (* The record reached the caller through ctrl in every other typed
1253
1575
  * port and through nothing here, so a caller who asked for paging
@@ -1257,7 +1579,7 @@ let paging_feature () : feature =
1257
1579
  (* The caller holds this map: refill it in place. Every key of
1258
1580
  * the record is written, so no key of an earlier page lives on. *)
1259
1581
  List.iter (fun k -> setp held k (getp paging k))
1260
- ["page"; "totalCount"; "nextPage"; "next"; "cursor"; "hasMore"]
1582
+ ["page"; "totalCount"; "nextPage"; "next"; "cursor"; "foreign"; "hasMore"]
1261
1583
  | _ -> ctx.c_ctrl.ctrl_paging <- paging);
1262
1584
  track_set (cc ctx) "paging" (jo [("last", paging)]))
1263
1585
  | _ -> ());
@@ -1290,8 +1612,10 @@ let streaming_feature () : feature =
1290
1612
  f.f_active <- opt_active opts);
1291
1613
  f.f_hook <- (fun name ctx ->
1292
1614
  if name = "PreResult" && f.f_active && streamable ctx then
1615
+ (* A failed result keeps no stream, so the entity's stream raises its error. *)
1293
1616
  match ctx.c_result with
1294
1617
  | None -> ()
1618
+ | Some { rt_err = Some _; _ } -> ()
1295
1619
  | Some result ->
1296
1620
  result.rt_streaming <- true;
1297
1621
  result.rt_stream <- Some (fun () -> iterate result);
@@ -1562,39 +1886,49 @@ let test_feature () : feature =
1562
1886
  let reqd_params = reqd_names point "params" in
1563
1887
  let reqd_query = reqd_names point "query" in
1564
1888
  let qand = ref [] in
1565
- (match args with
1566
- | Map _ ->
1567
- List.iter (fun key ->
1568
- let is_id = key = "id" in
1569
- let is_reqd = not (isempty (select reqd_params (Str key)))
1570
- || not (isempty (select reqd_query (Str key))) in
1571
- if is_id || is_reqd then begin
1572
- let v = (cu ctx).u_param ctx (Str key) in
1573
- let ka = (match op.op_alias with Map _ -> (match getp op.op_alias key with Str s -> Some s | _ -> None) | _ -> None) in
1574
- let qor = ref [jo [(key, v)]] in
1575
- (match ka with Some k -> qor := !qor @ [jo [(k, v)]] | None -> ());
1576
- qand := !qand @ [jo [("`$OR`", ja !qor)]]
1577
- end) (keysof args)
1578
- | _ -> ());
1889
+ let idfrom = getpath_s ctx.c_config ("entity." ^ entname ^ ".id.from") in
1890
+ let held src key = match src with
1891
+ | Map _ -> (match getp src key with Noval | Null | Str "__UNDEFINED__" -> false | _ -> true)
1892
+ | _ -> false in
1893
+ let given = match args with Map _ -> keysof args | _ -> [] in
1894
+ (* With no id in the call, the entity's held id (or composite parts) stands in. *)
1895
+ let names =
1896
+ if held args "id" then given
1897
+ else begin
1898
+ let parts = match getpath_s ctx.c_config ("entity." ^ entname ^ ".id.parts") with
1899
+ | List r -> List.filter_map (function Str s -> Some s | _ -> None) !r
1900
+ | _ -> if opname = "list" then [] else ["id"] in
1901
+ List.fold_left (fun acc p ->
1902
+ if not (List.mem p acc) && (held ctx.c_match p || held ctx.c_data p) then acc @ [p] else acc)
1903
+ given parts
1904
+ end in
1905
+ List.iter (fun key ->
1906
+ let is_id = key = "id" in
1907
+ let is_reqd = not (isempty (select reqd_params (Str key)))
1908
+ || not (isempty (select reqd_query (Str key))) in
1909
+ if is_id || is_reqd then begin
1910
+ let v = (cu ctx).u_param ctx (Str key) in
1911
+ let ka = (match op.op_alias with Map _ -> (match getp op.op_alias key with Str s -> Some s | _ -> None) | _ -> None) in
1912
+ let qor = ref [jo [(key, v)]] in
1913
+ (match ka with Some k -> qor := !qor @ [jo [(k, v)]] | None -> ());
1914
+ (* An alternative, never a replacement: a seed keeping the parameter
1915
+ flat is still found. *)
1916
+ (match (match idfrom with Map _ -> getp idfrom key | _ -> Noval) with
1917
+ | Str kf when kf <> key ->
1918
+ qor := !qor @ [List.fold_right (fun seg acc -> jo [(seg, acc)]) (String.split_on_char '.' kf) v]
1919
+ | _ -> ());
1920
+ qand := !qand @ [jo [("`$OR`", ja !qor)]]
1921
+ end) names;
1579
1922
  let q = jo [("`$AND`", ja !qand)] in
1580
1923
  (match ctx.c_ctrl.ctrl_explain with Map _ -> setp ctx.c_ctrl.ctrl_explain "test" (jo [("query", q)]) | _ -> ());
1581
1924
  q in
1582
1925
  let make_mock entity =
1583
- let resolve_match fctx explicit =
1584
- if (match explicit with Map _ -> size explicit > 0 | _ -> false) then explicit
1585
- else begin
1586
- let try_src src = match src with
1587
- | Map _ -> (match getp src "id" with Noval -> None | Str "__UNDEFINED__" -> None | v -> Some v)
1588
- | _ -> None in
1589
- match try_src fctx.c_match with Some v -> jo [("id", v)]
1590
- | None -> (match try_src fctx.c_data with Some v -> jo [("id", v)] | None -> empty_map ())
1591
- end in
1592
1926
  fun fctx _url _fetchdef ->
1593
1927
  let op = fctx.c_op in
1594
1928
  let entmap = match getp entity op.op_entity with Map _ as m -> m | _ -> empty_map () in
1595
1929
  (match op.op_name with
1596
1930
  | "load" ->
1597
- let args = build_args fctx op (resolve_match fctx fctx.c_reqmatch) in
1931
+ let args = build_args fctx op fctx.c_reqmatch in
1598
1932
  let ent = getelem (select entmap args) (Num 0.0) in
1599
1933
  if is_nullish ent then respond fctx 404 Noval (Some (jo [("statusText", Str "Not found")]))
1600
1934
  else (ignore (delprop ent (Str "$KEY")); respond fctx 200 (clone ent) None)
@@ -1607,32 +1941,22 @@ let test_feature () : feature =
1607
1941
  respond fctx 200 (clone found) None
1608
1942
  end
1609
1943
  | "update" | "patch" ->
1610
- let update_match = empty_map () in
1611
- (match fctx.c_reqdata with
1612
- | Map _ ->
1613
- (match getp fctx.c_reqdata "id" with Noval -> () | v -> setp update_match "id" v);
1614
- (match getp op.op_alias "id" with
1615
- | Str alias_id -> (match getp fctx.c_reqdata alias_id with Noval -> () | v -> setp update_match alias_id v)
1616
- | _ -> ())
1617
- | _ -> ());
1618
- let update_match = if size update_match > 0 then update_match else resolve_match fctx (empty_map ()) in
1619
- let args = build_args fctx op update_match in
1944
+ (* `$body` travels on the wire alone; the record is the rest. *)
1945
+ let rest = (match fctx.c_reqdata with Map _ -> clone fctx.c_reqdata | _ -> empty_map ()) in
1946
+ ignore (delprop rest (Str "$body"));
1947
+ let args = build_args fctx op rest in
1620
1948
  let ent = getelem (select entmap args) (Num 0.0) in
1621
1949
  (* update miss: 404, never another record *)
1622
1950
  if is_nullish ent then respond fctx 404 Noval (Some (jo [("statusText", Str "Not found")]))
1623
1951
  else begin
1624
- (* `$body` travels on the wire alone; the record is the rest. *)
1625
1952
  (match ent, fctx.c_reqdata with
1626
- | Map _, Map _ ->
1627
- let rest = clone fctx.c_reqdata in
1628
- ignore (delprop rest (Str "$body"));
1629
- ignore (merge (ja [ent; rest]))
1953
+ | Map _, Map _ -> ignore (merge (ja [ent; rest]))
1630
1954
  | _ -> ());
1631
1955
  ignore (delprop ent (Str "$KEY"));
1632
1956
  respond fctx 200 (clone ent) None
1633
1957
  end
1634
1958
  | "remove" ->
1635
- let args = build_args fctx op (resolve_match fctx fctx.c_reqmatch) in
1959
+ let args = build_args fctx op fctx.c_reqmatch in
1636
1960
  let ent = getelem (select entmap args) (Num 0.0) in
1637
1961
  (match ent with Map _ -> ignore (delprop entmap (getp ent "id")) | _ -> ());
1638
1962
  respond fctx 200 Noval None