@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
@@ -178,18 +178,10 @@
178
178
  [out nil]))
179
179
  op (core/oget fctx :op)
180
180
  entmap (let [em (vs/getprop entity (core/op-entity op))] (if (vs/ismap em) em (vs/jm)))
181
- resolve-match (fn [explicit]
182
- (if (and (vs/ismap explicit) (pos? (vs/size explicit))) explicit
183
- (loop [srcs [(core/oget fctx :match) (core/oget fctx :data)]]
184
- (if (empty? srcs) (vs/jm)
185
- (let [src (first srcs)
186
- v (when src (vs/getprop src "id"))]
187
- (if (and (some? v) (not= v "__UNDEFINED__")) (vs/jm "id" v)
188
- (recur (rest srcs))))))))
189
181
  opn (core/op-name op)]
190
182
  (cond
191
183
  (= opn "load")
192
- (let [args (test-build-args fctx op (resolve-match (core/oget fctx :reqmatch)))
184
+ (let [args (test-build-args fctx op (core/oget fctx :reqmatch))
193
185
  found (vs/select entmap args)
194
186
  ent (vs/getelem found 0)]
195
187
  (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
@@ -201,28 +193,20 @@
201
193
  (do (when (vs/islist found) (doseq [item (vec found)] (vs/delprop item "$KEY")))
202
194
  (respond 200 (vs/clone found) nil))))
203
195
  (or (= opn "update") (= opn "patch"))
204
- (let [update-match (vs/jm)
205
- reqdata (core/oget fctx :reqdata)]
206
- (when (vs/ismap reqdata)
207
- (when (contains? (into #{} (vs/keysof reqdata)) "id")
208
- (.put ^java.util.Map update-match "id" (vs/getprop reqdata "id")))
209
- (when-let [am (core/op-alias op)]
210
- (let [alias-id (vs/getprop am "id")]
211
- (when (and alias-id (contains? (into #{} (vs/keysof reqdata)) alias-id))
212
- (.put ^java.util.Map update-match alias-id (vs/getprop reqdata alias-id))))))
213
- (let [update-match (if (zero? (vs/size update-match)) (resolve-match (vs/jm)) update-match)
214
- args (test-build-args fctx op update-match)
215
- found (vs/select entmap args)
216
- ent (vs/getelem found 0)]
217
- ;; update miss: 404, never another record
218
- (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
219
- (do (when (and (vs/ismap ent) (vs/ismap reqdata))
220
- ;; `$body` travels on the wire alone; the record is the rest.
221
- (vs/merge (vs/jt ent (doto (vs/clone reqdata) (vs/delprop "$body")))))
222
- (vs/delprop ent "$KEY")
223
- (respond 200 (vs/clone ent) nil)))))
196
+ (let [reqdata (core/oget fctx :reqdata)
197
+ ;; `$body` travels on the wire alone; the record is the rest.
198
+ rec (if (vs/ismap reqdata) (doto (vs/clone reqdata) (vs/delprop "$body")) (vs/jm))
199
+ args (test-build-args fctx op rec)
200
+ found (vs/select entmap args)
201
+ ent (vs/getelem found 0)]
202
+ ;; update miss: 404, never another record
203
+ (if (nil? ent) (respond 404 nil (vs/jm "statusText" "Not found"))
204
+ (do (when (and (vs/ismap ent) (vs/ismap reqdata))
205
+ (vs/merge (vs/jt ent rec)))
206
+ (vs/delprop ent "$KEY")
207
+ (respond 200 (vs/clone ent) nil))))
224
208
  (= opn "remove")
225
- (let [args (test-build-args fctx op (resolve-match (core/oget fctx :reqmatch)))
209
+ (let [args (test-build-args fctx op (core/oget fctx :reqmatch))
226
210
  found (vs/select entmap args)
227
211
  ent (vs/getelem found 0)]
228
212
  (when (vs/ismap ent) (vs/delprop entmap (vs/getprop ent "id")))
@@ -283,18 +267,36 @@
283
267
  ;; (e.g. GET /result?trace_id=), which has no path param at all.
284
268
  reqd-params (reqd-names point "params")
285
269
  reqd-query (reqd-names point "query")
286
- qand (vs/jt)]
287
- (when args
288
- (doseq [key (or (vs/keysof args) [])]
289
- (let [is-id (= key "id")
290
- is-reqd (or (not (vs/isempty (vs/select reqd-params key)))
291
- (not (vs/isempty (vs/select reqd-query key))))]
292
- (when (or is-id is-reqd)
293
- (let [v ((core/uget ctx :param) ctx key)
294
- ka (when (core/op-alias op) (vs/getprop (core/op-alias op) key))
295
- qor (vs/jt (vs/jm key v))]
296
- (when (string? ka) (.add ^java.util.List qor (vs/jm ka v)))
297
- (.add ^java.util.List qand (vs/jm "`$OR`" qor)))))))
270
+ qand (vs/jt)
271
+ ename (core/entity-get-name (core/oget ctx :entity))
272
+ idfrom (vs/getpath (core/oget ctx :config) (str "entity." ename ".id.from"))
273
+ held (fn [src k] (let [v (when src (vs/getprop src k))] (and (some? v) (not= v "__UNDEFINED__"))))
274
+ given (vec (or (when args (vs/keysof args)) []))
275
+ ;; With no id in the call, the entity's held id (or composite parts) stands in.
276
+ names (if (held args "id") given
277
+ (let [declared (vs/getpath (core/oget ctx :config) (str "entity." ename ".id.parts"))
278
+ parts (if (vs/islist declared) (map str (vec declared)) (if (= opname "list") [] ["id"]))]
279
+ (reduce (fn [acc p]
280
+ (if (and (not (some #{p} acc))
281
+ (or (held (core/oget ctx :match) p) (held (core/oget ctx :data) p)))
282
+ (conj acc p) acc))
283
+ given parts)))]
284
+ (doseq [key names]
285
+ (let [is-id (= key "id")
286
+ is-reqd (or (not (vs/isempty (vs/select reqd-params key)))
287
+ (not (vs/isempty (vs/select reqd-query key))))]
288
+ (when (or is-id is-reqd)
289
+ (let [v ((core/uget ctx :param) ctx key)
290
+ ka (when (core/op-alias op) (vs/getprop (core/op-alias op) key))
291
+ kf (when (vs/ismap idfrom) (vs/getprop idfrom key))
292
+ qor (vs/jt (vs/jm key v))]
293
+ (when (string? ka) (.add ^java.util.List qor (vs/jm ka v)))
294
+ ;; An alternative, never a replacement: a seed keeping the parameter
295
+ ;; flat is still found.
296
+ (when (and (string? kf) (not= kf key))
297
+ (.add ^java.util.List qor (reduce (fn [acc seg] (vs/jm seg acc)) v
298
+ (reverse (clojure.string/split kf #"\.")))))
299
+ (.add ^java.util.List qand (vs/jm "`$OR`" qor))))))
298
300
  (let [q (vs/jm "`$AND`" qand)]
299
301
  (when-let [ex (core/oget (core/oget ctx :ctrl) :explain)] (.put ^java.util.Map ex "test" (vs/jm "query" q)))
300
302
  q)))
@@ -348,6 +350,28 @@
348
350
  (boolean (some #(= (long %) (long status)) (vec statuses))))
349
351
  false))))
350
352
 
353
+ (def ^:private imf-fixdate
354
+ #"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-9]{2}) ([A-Z][a-z]{2}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) GMT")
355
+
356
+ (def ^:private months ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"])
357
+
358
+ ;; RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else nil.
359
+ (defn retry-after-value [value now]
360
+ (let [s (str/replace value #"^[ \t]+|[ \t]+$" "")]
361
+ (if (re-matches #"[0-9]+" s)
362
+ (* 1000 (if (> (count s) 12) 999999999999 (Long/parseLong s)))
363
+ (when-let [[_ day mon year hour minute sec] (re-matches imf-fixdate s)]
364
+ (let [mi (.indexOf ^java.util.List months mon)
365
+ [d y hh mm ss] (map #(Long/parseLong %) [day year hour minute sec])]
366
+ (when (and (>= mi 0) (<= 1 d 31) (<= hh 23) (<= mm 59) (<= ss 60))
367
+ (try
368
+ (let [at (+ (* 1000 (.toEpochSecond (java.time.LocalDateTime/of (int y) (int (inc mi)) (int d)
369
+ (int hh) (int mm) (int (min ss 59)))
370
+ java.time.ZoneOffset/UTC))
371
+ (if (> ss 59) 1000 0))]
372
+ (max 0 (- at now)))
373
+ (catch java.time.DateTimeException _ nil))))))))
374
+
351
375
  (defn- retry-after-ms [res]
352
376
  (when (vs/ismap res)
353
377
  (let [headers (vs/getprop res "headers")]
@@ -357,7 +381,7 @@
357
381
  (when (= (str/lower-case (str (vs/getprop item 0))) "retry-after")
358
382
  (reset! v (vs/getprop item 1))))
359
383
  (when (some? @v)
360
- (try (long (* (Double/parseDouble (str @v)) 1000)) (catch Exception _ nil))))))))
384
+ (retry-after-value (str @v) (System/currentTimeMillis))))))))
361
385
 
362
386
  (defn- retry-backoff [fa res attempt min-delay max-delay factor]
363
387
  (let [ra (retry-after-ms res)]
@@ -444,20 +468,22 @@
444
468
  (let [t (track-ensure! fa "_ratelimit" (vs/jm "throttled" 0 "waitMs" 0))]
445
469
  (.put ^java.util.Map t "throttled" (inc (long (mget t "throttled"))))
446
470
  (.put ^java.util.Map t "waitMs" (+ (long (mget t "waitMs")) (long wait-ms)))))
471
+ ;; Refill, then reserve this call's token before any wait, under the
472
+ ;; lock: a negative count is the calls already queued, so overlapping
473
+ ;; calls pace in turn.
447
474
  acquire (fn [_ctx]
448
475
  (let [rate (opt fa "rate" 5)
449
476
  burst (opt fa "burst" rate)
450
- now (now-ms fa)
451
- elapsed (- now (:last @fa))]
452
- (swap! fa assoc :last now)
453
- (swap! fa assoc :tokens (min burst (+ (:tokens @fa) (* (/ elapsed 1000.0) rate))))
454
- (if (>= (:tokens @fa) 1)
455
- (swap! fa update :tokens dec)
456
- (let [needed (- 1 (:tokens @fa))
457
- wait-ms (long (Math/ceil (* (/ needed (double rate)) 1000)))]
458
- (track! wait-ms)
459
- (sleep-ms fa wait-ms)
460
- (swap! fa assoc :last (now-ms fa) :tokens 0)))))]
477
+ wait-ms (locking fa
478
+ (let [now (now-ms fa)
479
+ refilled (+ (:tokens @fa) (* (/ (- now (:last @fa)) 1000.0) rate))
480
+ tokens (- (min burst refilled) 1)]
481
+ (swap! fa assoc :last now :tokens tokens)
482
+ (when (neg? tokens)
483
+ (let [w (long (Math/ceil (* (/ (- tokens) (double rate)) 1000)))]
484
+ (track! w)
485
+ w))))]
486
+ (when wait-ms (sleep-ms fa wait-ms))))]
461
487
  (swap! fa assoc
462
488
  "init" (fn [ctx options]
463
489
  (swap! fa assoc :client (core/oget ctx :client)
@@ -472,6 +498,52 @@
472
498
  ;; cache
473
499
  ;; ---------------------------------------------------------------------------
474
500
 
501
+ (def ^:private cache-unstored #{"no-store" "private" "no-cache"})
502
+
503
+ (defn- cache-header-text [v]
504
+ (cond (nil? v) nil
505
+ (string? v) v
506
+ (and (number? v) (== v (Math/floor (double v)))) (str (long v))
507
+ :else (str v)))
508
+
509
+ (defn- cache-digest [^javax.crypto.spec.SecretKeySpec secret headers]
510
+ (let [pairs (if (instance? java.util.Map headers)
511
+ (sort (keep (fn [[k v]] (when-let [t (cache-header-text v)] [(str/lower-case (str k)) t]))
512
+ (seq ^java.util.Map headers)))
513
+ [])
514
+ mac (doto (javax.crypto.Mac/getInstance "HmacSHA256") (.init secret))]
515
+ (doseq [[k v] pairs]
516
+ (.update mac (.getBytes (str k ":" v "\n") "UTF-8")))
517
+ (apply str (map #(format "%02x" (bit-and (long %) 0xff)) (.doFinal mac)))))
518
+
519
+ ;; The configured ttl capped by the response's Cache-Control; zero when the
520
+ ;; response may not be stored.
521
+ (defn- cache-lifetime [headers ttl]
522
+ (let [control (str/lower-case (or (some (fn [[k v]] (when (= "cache-control" (str/lower-case (str k))) (cache-header-text v)))
523
+ (when (instance? java.util.Map headers) (seq ^java.util.Map headers)))
524
+ ""))
525
+ directives (map str/trim (str/split control #","))]
526
+ (if (some cache-unstored directives)
527
+ 0
528
+ (reduce (fn [life d]
529
+ (if-let [[_ secs] (re-matches #"max-age\s*=\s*\"?(\d+)\"?" d)]
530
+ (long (min life (*' 1000 (bigint secs))))
531
+ life))
532
+ (long ttl) directives))))
533
+
534
+ (defn- cache-scope [url]
535
+ (str/replace (first (str/split (str url) #"[?#]" 2)) #"/+$" ""))
536
+
537
+ (defn- cache-parent [scope]
538
+ (let [scheme (str/index-of scope "://")
539
+ root (if (nil? scheme) 0 (str/index-of scope "/" (+ scheme 3)))]
540
+ (if (nil? root)
541
+ scope
542
+ (subs scope 0 (max root (or (str/last-index-of scope "/") 0))))))
543
+
544
+ (defn- cache-under? [scope prefix]
545
+ (or (= scope prefix) (str/starts-with? scope (str prefix "/"))))
546
+
475
547
  (defn cache-feature []
476
548
  (let [fa (new-feature "cache" false "0.0.1")
477
549
  track! (fn [kind]
@@ -506,12 +578,22 @@
506
578
  (let [oldest (first (keys (:store @fa)))]
507
579
  (if (nil? oldest) (swap! fa assoc :store {})
508
580
  (swap! fa update :store dissoc oldest))))))
581
+ invalidate! (fn [url]
582
+ (let [path (cache-scope url)
583
+ collection (cache-parent path)]
584
+ (swap! fa update :store
585
+ (fn [store]
586
+ (into {} (remove (fn [[_ e]] (let [scope (mget e "scope")]
587
+ (or (cache-under? scope path)
588
+ (= scope collection))))
589
+ store))))))
509
590
  through (fn [ctx url fetchdef inner]
510
591
  (let [method (str/upper-case (str (or (and (vs/ismap fetchdef) (vs/getprop fetchdef "method")) "GET")))
511
592
  methods (or (opt fa "methods") (vs/jt "GET"))]
512
- (if (not (some #(= % method) (vec methods)))
513
- (inner ctx url fetchdef)
514
- (let [key (str method " " url)
593
+ (cond
594
+ (some #(= % method) (vec methods))
595
+ (let [key (str method " " url " "
596
+ (cache-digest (:secret @fa) (when (vs/ismap fetchdef) (vs/getprop fetchdef "headers"))))
515
597
  now (now-ms fa)
516
598
  hit (get (:store @fa) key)]
517
599
  (if (and (some? hit) (> (mget hit "expiry") now))
@@ -524,17 +606,32 @@
524
606
 
525
607
  (and (nil? err) (cacheable? res))
526
608
  (let [snap (snapshot res)
527
- ttl (opt fa "ttl" 5000)]
528
- (evict!)
529
- (swap! fa update :store assoc key (vs/jm "expiry" (+ now ttl) "snapshot" snap))
530
- (track! "miss")
531
- [(replay snap) nil])
609
+ ttl (cache-lifetime (mget snap "headers") (opt fa "ttl" 5000))]
610
+ (if (<= ttl 0)
611
+ (do (track! "bypass") [(replay snap) nil])
612
+ (do
613
+ (swap! fa update :store dissoc key)
614
+ (evict!)
615
+ (swap! fa update :store assoc key
616
+ (vs/jm "expiry" (+ now ttl) "scope" (cache-scope url) "snapshot" snap))
617
+ (track! "miss")
618
+ [(replay snap) nil])))
619
+
620
+ :else (do (track! "bypass") [res err])))))
621
+
622
+ (contains? #{"GET" "HEAD"} method)
623
+ (inner ctx url fetchdef)
532
624
 
533
- :else (do (track! "bypass") [res err]))))))))]
625
+ :else
626
+ (try (inner ctx url fetchdef)
627
+ (finally (invalidate! url))))))]
534
628
  (swap! fa assoc
535
629
  "init" (fn [ctx options]
536
630
  (swap! fa assoc :client (core/oget ctx :client)
537
- :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :store {})
631
+ :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :store {}
632
+ :secret (let [bytes (byte-array 32)]
633
+ (.nextBytes (java.security.SecureRandom.) bytes)
634
+ (javax.crypto.spec.SecretKeySpec. bytes "HmacSHA256")))
538
635
  (when (active? fa)
539
636
  (wrap-fetcher! ctx (fn [fctx url fd inner] (through fctx url fd inner))))))
540
637
  fa))
@@ -597,6 +694,82 @@
597
694
  (or (try (Long/parseLong s) (catch Exception _ nil))
598
695
  (try (Double/parseDouble s) (catch Exception _ nil))))))
599
696
 
697
+ ;; Under the `next` option's default, a URL or an absolute path is a link and
698
+ ;; anything else a cursor; `cursor` and `url` pin the reading.
699
+ (def ^:private paging-origin #"(?i)^[a-z][a-z0-9+.-]*://[^/?#]*")
700
+
701
+ (defn- paging-link? [nxt mode]
702
+ (and (string? nxt)
703
+ (or (= "url" mode)
704
+ (and (not= "cursor" mode)
705
+ (or (some? (re-find paging-origin nxt)) (str/starts-with? nxt "/"))))))
706
+
707
+ (defn- paging-origin-of [text]
708
+ (str/lower-case (or (when (string? text) (re-find paging-origin text)) "")))
709
+
710
+ (defn- paging-foreign? [link base]
711
+ (let [origin (paging-origin-of link)]
712
+ (and (seq origin) (not= origin (paging-origin-of base)))))
713
+
714
+ (defn- paging-unescape [text]
715
+ (try (java.net.URLDecoder/decode ^String text "UTF-8") (catch Exception _ text)))
716
+
717
+ ;; RFC 3986 section 5.2.4.
718
+ (defn- paging-remove-dots [path]
719
+ (let [abs (str/starts-with? path "/")
720
+ segs (vec (.split ^String path "/" -1))
721
+ segs (if abs (subvec segs 1) segs)
722
+ n (count segs)
723
+ out (reduce (fn [out [i seg]]
724
+ (if (contains? #{"." ".."} seg)
725
+ (cond-> (if (and (= ".." seg) (seq out)) (pop out) out)
726
+ (= i (dec n)) (conj ""))
727
+ (conj out seg)))
728
+ [] (map-indexed vector segs))]
729
+ (str (when abs "/") (str/join "/" out))))
730
+
731
+ ;; RFC 3986 reference resolution against the URL of the request that returned
732
+ ;; the link, by hand: java.net.URI resolves a query-only reference by RFC 2396
733
+ ;; and drops the last path segment. A link on that URL's origin comes back as
734
+ ;; its path and query; an absolute link is left as it is.
735
+ (defn- paging-resolve [link url]
736
+ (if (or (not (string? url)) (= "" url) (re-find #"(?i)^[a-z][a-z0-9+.-]*:" link))
737
+ link
738
+ (let [link (first (.split ^String link "#" 2))
739
+ origin (or (re-find paging-origin url) "")]
740
+ (if (str/starts-with? link "//")
741
+ (if (= "" origin) link (str (first (.split ^String origin ":" 2)) ":" link))
742
+ (let [from (first (.split ^String (subs url (count origin)) "#" 2))
743
+ after (fn [^String s] (when-let [k (str/index-of s "?")] (subs s (inc k))))
744
+ bpath (first (.split ^String from "\\?" 2))
745
+ rpath (first (.split ^String link "\\?" 2))
746
+ query (if (= "" rpath) (or (after link) (after from)) (after link))
747
+ path (cond
748
+ (= "" rpath) bpath
749
+ (str/starts-with? rpath "/") (paging-remove-dots rpath)
750
+ :else (paging-remove-dots
751
+ (str (subs bpath 0 (inc (or (str/last-index-of bpath "/") -1))) rpath)))
752
+ rooted (if (str/starts-with? path "/") path (str "/" path))]
753
+ (if (nil? query) rooted (str rooted "?" query)))))))
754
+
755
+ ;; The request goes to the link's path and query, on the SDK's own origin.
756
+ (defn- paging-follow! [spec nxt]
757
+ (let [link (first (str/split (str/replace-first nxt paging-origin "") #"#" 2))
758
+ [path rawquery] (str/split link #"\?" 2)
759
+ q (vs/jm)
760
+ old (core/oget spec :query)]
761
+ (doseq [pair (str/split (or rawquery "") #"&")
762
+ :when (seq pair)]
763
+ (let [[k v] (str/split pair #"=" 2)]
764
+ (.put ^java.util.Map q (paging-unescape k) (paging-unescape (or v "")))))
765
+ (doseq [k (core/oget spec :authquery [])]
766
+ (.put ^java.util.Map q k (mget old k)))
767
+ (core/oset! spec :base (or (re-find paging-origin (str (or (core/oget spec :base) ""))) ""))
768
+ (core/oset! spec :prefix "")
769
+ (core/oset! spec :path (or path ""))
770
+ (core/oset! spec :suffix "")
771
+ (core/oset! spec :query q)))
772
+
600
773
  ;; Relay pagination: the cursor is the `after` variable (or whatever the model
601
774
  ;; named it), and the page size is `first`.
602
775
  (defn- graphql-pre-request [fa spec point paging]
@@ -650,6 +823,9 @@
650
823
  (do
651
824
  (cond
652
825
  (some? (mget paging "cursor")) (.put ^java.util.Map q cursor-param (mget paging "cursor"))
826
+ (and (string? (mget paging "next"))
827
+ (not (paging-foreign? (mget paging "next") (core/oget spec :base))))
828
+ (paging-follow! spec (mget paging "next"))
653
829
  (nil? (mget q page-param))
654
830
  ;; A record written back by PreResult holds the page
655
831
  ;; just fetched as `page` and the one to fetch as
@@ -659,8 +835,9 @@
659
835
  (some? (mget paging "nextPage")) (mget paging "nextPage")
660
836
  (some? (mget paging "page")) (mget paging "page")
661
837
  :else (opt fa "startPage" 1))))
662
- (when (and (some? (opt fa "limit")) (nil? (mget q limit-param)))
663
- (.put ^java.util.Map q limit-param (opt fa "limit"))))))))))
838
+ (let [q (core/oget spec :query)]
839
+ (when (and (some? (opt fa "limit")) (nil? (mget q limit-param)))
840
+ (.put ^java.util.Map q limit-param (opt fa "limit")))))))))))
664
841
  "PreResult"
665
842
  (fn [ctx]
666
843
  (when (and (active? fa) (list? ctx))
@@ -702,7 +879,10 @@
702
879
  (.put ^java.util.Map paging "hasMore" more)
703
880
  (reset! explicit-more true))))))
704
881
  (when (vs/ismap body)
705
- (when (some? (mget body "next")) (when (nil? (mget paging "next")) (.put ^java.util.Map paging "next" (mget body "next"))))
882
+ (when (some? (mget body "next"))
883
+ (if (paging-link? (mget body "next") (opt fa "next" "auto"))
884
+ (when (nil? (mget paging "next")) (.put ^java.util.Map paging "next" (mget body "next")))
885
+ (.put ^java.util.Map paging "cursor" (mget body "next"))))
706
886
  ;; Both spellings, camelCase last so it wins when a
707
887
  ;; body carries the two.
708
888
  (when (some? (mget body "next_cursor")) (.put ^java.util.Map paging "cursor" (mget body "next_cursor")))
@@ -718,6 +898,15 @@
718
898
  (when (or (= hm true) (= hm false))
719
899
  (.put ^java.util.Map paging "hasMore" hm)
720
900
  (reset! explicit-more true)))))
901
+ ;; A link to another origin is recorded, never followed,
902
+ ;; and ends the walk.
903
+ (let [spec (core/oget ctx :spec)
904
+ base (if spec (core/oget spec :base) (mget (core/oget ctx :options) "base"))]
905
+ (when (and spec (string? (mget paging "next")))
906
+ (.put ^java.util.Map paging "next" (paging-resolve (mget paging "next") (core/oget spec :url))))
907
+ (when (and (string? (mget paging "next")) (paging-foreign? (mget paging "next") base))
908
+ (.put ^java.util.Map paging "foreign" (mget paging "next"))
909
+ (.put ^java.util.Map paging "next" nil)))
721
910
  ;; Cursor presence only INFERS another page. When the
722
911
  ;; server stated the answer outright — relay's
723
912
  ;; `hasNextPage: false`, or a body `hasMore` — that
@@ -728,7 +917,10 @@
728
917
  (when-not @explicit-more
729
918
  (.put ^java.util.Map paging "hasMore"
730
919
  (boolean (or (mget paging "hasMore") (some? (mget paging "next"))
731
- (some? (mget paging "cursor")) (some? (mget paging "nextPage")))))))
920
+ (some? (mget paging "cursor")) (some? (mget paging "nextPage"))))))
921
+ (when (and (some? (mget paging "foreign")) (nil? (mget paging "cursor"))
922
+ (nil? (mget paging "nextPage")))
923
+ (.put ^java.util.Map paging "hasMore" false)))
732
924
  (core/oset! result :paging paging)
733
925
  (when-let [ctrl (core/oget ctx :ctrl)]
734
926
  (let [held (core/oget ctrl :paging)]
@@ -947,8 +1139,9 @@
947
1139
  "PreResult"
948
1140
  (fn [ctx]
949
1141
  (when (and (active? fa) (streamable? ctx))
1142
+ ;; A failed result keeps no stream, so the entity's stream raises its error.
950
1143
  (let [result (core/oget ctx :result)]
951
- (when result
1144
+ (when (and result (nil? (core/oget result :err)))
952
1145
  (core/oset! result :streaming true)
953
1146
  (core/oset! result :stream (make-stream result))
954
1147
  (let [t (track-ensure! fa "_streaming" (vs/jm "opened" 0))]
@@ -1017,17 +1210,23 @@
1017
1210
  ;; telemetry
1018
1211
  ;; ---------------------------------------------------------------------------
1019
1212
 
1213
+ ;; W3C trace context: lowercase hex from the platform's random source, never all zeros.
1214
+ (def ^:private secure-random (java.security.SecureRandom.))
1215
+
1216
+ (defn- random-hex [nbytes]
1217
+ (let [buf (byte-array nbytes)]
1218
+ (loop []
1219
+ (.nextBytes ^java.security.SecureRandom secure-random buf)
1220
+ (if (every? zero? buf) (recur)
1221
+ (apply str (map #(format "%02x" (bit-and (long %) 0xff)) buf))))))
1222
+
1020
1223
  (defn telemetry-feature []
1021
1224
  (let [fa (new-feature "telemetry" false "0.0.1")
1022
1225
  telem (fn [] (track-get fa "_telemetry"))
1023
1226
  gen-id2 (fn [kind]
1024
1227
  (let [idgen (opt fa "idgen")]
1025
1228
  (if (fn? idgen) (idgen kind)
1026
- (do (swap! fa update :seq inc)
1027
- (let [n (let [h (Long/toHexString (long (:seq @fa)))]
1028
- (str (apply str (repeat (max 0 (- 4 (count h))) "0")) h))
1029
- padded (apply str n (repeat (max 0 (- 16 (count n))) "0"))]
1030
- (str (if (= kind "trace") "t" "s") (subs padded 0 16)))))))
1229
+ (random-hex (if (= kind "trace") 16 8)))))
1031
1230
  close (fn [ctx ok]
1032
1231
  (let [span (get (:spans @fa) ctx)]
1033
1232
  (when span
@@ -1041,11 +1240,11 @@
1041
1240
  (.add ^java.util.List (mget t "spans") out))
1042
1241
  (let [exporter (opt fa "exporter")]
1043
1242
  (when (fn? exporter) (try (exporter out) (catch Throwable _ nil))))))))]
1044
- (swap! fa assoc :spans {} :seq 0)
1243
+ (swap! fa assoc :spans {})
1045
1244
  (swap! fa assoc
1046
1245
  "init" (fn [ctx options]
1047
1246
  (swap! fa assoc :client (core/oget ctx :client)
1048
- :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :spans {} :seq 0)
1247
+ :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :spans {})
1049
1248
  (when (active? fa)
1050
1249
  (when (nil? (track-get fa "_telemetry"))
1051
1250
  (track-set! fa "_telemetry" (vs/jm "spans" (vs/jt) "active" 0)))))
@@ -1103,7 +1302,9 @@
1103
1302
  (let [b (vs/jm "count" 0 "ok" 0 "err" 0 "totalMs" 0 "maxMs" 0)]
1104
1303
  (.put ^java.util.Map (mget m "ops") key b) b))]
1105
1304
  (bump! (mget m "total") ok dur)
1106
- (bump! opm ok dur))))))]
1305
+ (bump! opm ok dur)
1306
+ (let [sink (opt fa "sink")]
1307
+ (when (fn? sink) (try (sink (core/ucall ctx :clean m)) (catch Throwable _ nil)))))))))]
1107
1308
  (swap! fa assoc :starts {})
1108
1309
  (swap! fa assoc
1109
1310
  "init" (fn [ctx options]
@@ -1156,9 +1357,7 @@
1156
1357
  max (opt fa "max" 100)]
1157
1358
  (.add ^java.util.List buf entry)
1158
1359
  (while (> (.size ^java.util.List buf) max) (.remove ^java.util.List buf 0))
1159
- ;; `onEntry` is the option spec's spelling; the
1160
- ;; older `on_entry` is kept for callers that used it.
1161
- (let [on-entry (or (opt fa "onEntry") (opt fa "on_entry"))]
1360
+ (let [on-entry (opt fa "onEntry")]
1162
1361
  (when (fn? on-entry) (try (on-entry entry) (catch Throwable _ nil)))))))))]
1163
1362
  (swap! fa assoc :entries {})
1164
1363
  (swap! fa assoc