@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
@@ -118,6 +118,11 @@ final class MakeOptions {
118
118
  opts.put("feature", fmap);
119
119
  }
120
120
 
121
+ Map<String, Object> fdefaults = featureDefaults(config.get("feature"), opts.get("feature"));
122
+ if (fdefaults != null) {
123
+ opts.put("feature", fdefaults);
124
+ }
125
+
121
126
  // THE OPTION SPEC IS GENERATED, NOT WRITTEN HERE.
122
127
  //
123
128
  // Built from the model: `main.kit.optspec` for the standard options,
@@ -146,12 +151,11 @@ final class MakeOptions {
146
151
  mergeList.add(Struct.clone(cfgopts));
147
152
  mergeList.add(opts);
148
153
  Object merged = Struct.merge(mergeList);
154
+ List<Object[]> callbacks = holdCallbacks(merged, optspec);
149
155
 
150
- Map<String, Object> vopts = new LinkedHashMap<>();
151
- vopts.put("errs", new ArrayList<>());
152
156
  Object validated;
153
157
  try {
154
- validated = Struct.validate(merged, optspec, vopts);
158
+ validated = Struct.validate(merged, optspec);
155
159
  }
156
160
  catch (IllegalArgumentException err) {
157
161
  // The message quotes the offending value; a rewrite is the only way to
@@ -160,6 +164,7 @@ final class MakeOptions {
160
164
  (String) Clean.cleanWith(cleancfg, String.valueOf(err.getMessage())), err.getCause());
161
165
  }
162
166
  opts = (Map<String, Object>) validated;
167
+ restoreCallbacks(opts, callbacks);
163
168
 
164
169
  // Restore the suppression the optspec default would otherwise erase.
165
170
  if (authSuppressed) {
@@ -231,26 +236,31 @@ final class MakeOptions {
231
236
  opts.put("base", resolved.toString());
232
237
  }
233
238
 
234
- // Resolve the feature add-order: an explicit list order (above) wins;
235
- // otherwise order the map test-first, then the remaining names sorted, so
236
- // the outcome is deterministic and `test` is always the base transport.
237
- if (featureorder.isEmpty()) {
239
+ // Resolve the feature add-order: an explicit list order (above) wins, and
240
+ // the names it leaves out follow it test-first, then sorted, so the outcome
241
+ // is deterministic and `test` is the base transport of a map.
242
+ {
238
243
  Map<String, Object> fmap = Helpers.toMapAny(opts.get("feature"));
239
244
  List<String> names = new ArrayList<>();
240
245
  if (fmap != null) {
241
- names.addAll(fmap.keySet());
246
+ for (String n : fmap.keySet()) {
247
+ if (!featureorder.contains(n)) {
248
+ names.add(n);
249
+ }
250
+ }
242
251
  }
243
252
  names.sort(null);
253
+ List<Object> rest = new ArrayList<>();
244
254
  if (names.contains("test")) {
245
- featureorder.add("test");
255
+ rest.add("test");
246
256
  for (String n : names) {
247
257
  if (!"test".equals(n)) {
248
- featureorder.add(n);
258
+ rest.add(n);
249
259
  }
250
260
  }
251
261
  }
252
262
  else {
253
- featureorder.addAll(names);
263
+ rest.addAll(names);
254
264
  }
255
265
  // Station special case, mirroring test's: its transport wrap must
256
266
  // sit immediately outside the base transport (inside every other
@@ -258,24 +268,130 @@ final class MakeOptions {
258
268
  // test - or first, when no test entry exists. Without this the
259
269
  // sorted default would init station last and wrap OUTSIDE the
260
270
  // recording features, turning its wire-truth events into fiction.
261
- int si = featureorder.indexOf("station");
271
+ int si = rest.indexOf("station");
262
272
  if (0 <= si) {
263
- featureorder.remove(si);
264
- featureorder.add(featureorder.indexOf("test") + 1, "station");
273
+ rest.remove(si);
274
+ rest.add(rest.indexOf("test") + 1, "station");
265
275
  }
276
+ featureorder.addAll(rest);
266
277
  }
267
278
 
268
279
  Map<String, Object> derived = new LinkedHashMap<>();
269
- derived.put("clean", cleancfg);
270
280
  derived.put("featureorder", featureorder);
271
281
  opts.put("__derived__", derived);
272
282
 
283
+ // Beside the options, not in them: optionsMap hands them to callers.
284
+ ctx.cleancfg = cleancfg;
285
+
273
286
  // Again over the merged result: the config's own defaults can carry one.
274
287
  Clean.addSensitiveOptions(cleancfg, without(opts, "clean", "__derived__"));
275
288
 
276
289
  return opts;
277
290
  }
278
291
 
292
+ // The model's options for a feature sit beneath the caller's, key by key: a
293
+ // key the caller sets replaces the default whole, so a list is never merged.
294
+ @SuppressWarnings("unchecked")
295
+ private static Map<String, Object> featureDefaults(Object cfgfeature, Object feature) {
296
+ if (feature != null && !(feature instanceof Map)) {
297
+ return null;
298
+ }
299
+ Map<String, Object> out = feature == null
300
+ ? new LinkedHashMap<>() : new LinkedHashMap<>((Map<String, Object>) feature);
301
+ Map<String, Object> cfg = Helpers.toMapAny(cfgfeature);
302
+ if (cfg == null) {
303
+ return out;
304
+ }
305
+ for (Map.Entry<String, Object> e : cfg.entrySet()) {
306
+ Map<String, Object> fdef = Helpers.toMapAny(e.getValue());
307
+ Map<String, Object> dflt = fdef == null ? null : Helpers.toMapAny(fdef.get("options"));
308
+ Object given = out.get(e.getKey());
309
+ if (dflt == null || (given == null && !Boolean.TRUE.equals(dflt.get("active")))
310
+ || (given != null && !(given instanceof Map))) {
311
+ continue;
312
+ }
313
+ Map<String, Object> merged =
314
+ new LinkedHashMap<>(Helpers.toMapAny(Struct.clone(dflt)));
315
+ if (given != null) {
316
+ merged.putAll((Map<String, Object>) given);
317
+ }
318
+ out.put(e.getKey(), merged);
319
+ }
320
+ return out;
321
+ }
322
+
323
+ // This struct port's `$FUNCTION` admits only a java.util.function Function or
324
+ // Supplier, so a callback in a slot the spec types as a function is held out
325
+ // of validation and put back; any other key is still validated.
326
+ private static List<Object[]> holdCallbacks(Object opts, Map<String, Object> optspec) {
327
+ List<Object[]> held = new ArrayList<>();
328
+ Map<String, Object> om = Helpers.toMapAny(opts);
329
+ Map<String, Object> feature = om == null ? null : Helpers.toMapAny(om.get("feature"));
330
+ Map<String, Object> fspecs = Helpers.toMapAny(optspec.get("feature"));
331
+ if (feature == null || fspecs == null) {
332
+ return held;
333
+ }
334
+ for (Map.Entry<String, Object> fe : feature.entrySet()) {
335
+ Map<String, Object> fm = Helpers.toMapAny(fe.getValue());
336
+ Map<String, Object> fspec = specMap(fspecs.get(fe.getKey()));
337
+ if (fm == null || fspec == null) {
338
+ continue;
339
+ }
340
+ for (String key : new ArrayList<>(fm.keySet())) {
341
+ if (isFunctionSpec(fspec.get(key)) && isCallback(fm.get(key))) {
342
+ held.add(new Object[] {fe.getKey(), key, fm.remove(key)});
343
+ }
344
+ }
345
+ }
346
+ return held;
347
+ }
348
+
349
+ private static Map<String, Object> specMap(Object spec) {
350
+ if (spec instanceof List) {
351
+ List<Object> alts = (List<Object>) spec;
352
+ for (int i = "`$NOF`".equals(alts.isEmpty() ? null : alts.get(0)) ? 2 : 0; i < alts.size(); i++) {
353
+ if (alts.get(i) instanceof Map) {
354
+ return (Map<String, Object>) alts.get(i);
355
+ }
356
+ }
357
+ return null;
358
+ }
359
+ return Helpers.toMapAny(spec);
360
+ }
361
+
362
+ private static boolean isFunctionSpec(Object spec) {
363
+ return "`$FUNCTION`".equals(spec)
364
+ || (spec instanceof List && ((List<Object>) spec).contains("`$FUNCTION`"));
365
+ }
366
+
367
+ private static boolean isCallback(Object v) {
368
+ if (v == null) {
369
+ return false;
370
+ }
371
+ for (Class<?> c = v.getClass(); c != null; c = c.getSuperclass()) {
372
+ for (Class<?> i : c.getInterfaces()) {
373
+ if (i.isAnnotationPresent(FunctionalInterface.class)
374
+ || i.getName().startsWith("java.util.function.")) {
375
+ return true;
376
+ }
377
+ }
378
+ }
379
+ return false;
380
+ }
381
+
382
+ private static void restoreCallbacks(Map<String, Object> opts, List<Object[]> held) {
383
+ Map<String, Object> feature = Helpers.toMapAny(opts.get("feature"));
384
+ if (feature == null) {
385
+ return;
386
+ }
387
+ for (Object[] h : held) {
388
+ Map<String, Object> fm = Helpers.toMapAny(feature.get((String) h[0]));
389
+ if (fm != null) {
390
+ fm.put((String) h[1], h[2]);
391
+ }
392
+ }
393
+ }
394
+
279
395
  private static Map<String, Object> without(Map<String, Object> map, String... keys) {
280
396
  Map<String, Object> out = new LinkedHashMap<>(map);
281
397
  for (String key : keys) {
@@ -39,6 +39,9 @@ class Context {
39
39
  entopts
40
40
  options
41
41
 
42
+ // The clean registry, which holds every registered credential in plain form.
43
+ cleancfg
44
+
42
45
  opmap
43
46
 
44
47
  response
@@ -72,6 +75,7 @@ class Context {
72
75
  this.config = getprop(ctxmap, 'config', getprop(basectx, 'config'))
73
76
  this.entopts = getprop(ctxmap, 'entopts', getprop(basectx, 'entopts'))
74
77
  this.options = getprop(ctxmap, 'options', getprop(basectx, 'options'))
78
+ this.cleancfg = getprop(ctxmap, 'cleancfg', getprop(basectx, 'cleancfg'))
75
79
 
76
80
  this.entity = getprop(ctxmap, 'entity', getprop(basectx, 'entity'))
77
81
  this.shared = getprop(ctxmap, 'shared', getprop(basectx, 'shared'))
@@ -5,13 +5,9 @@ const { headerValue, isJsonMedia } = require('../../utility/MediaUtility')
5
5
 
6
6
 
7
7
  // Response caching for safe (read) requests. Wraps the active transport and
8
- // serves a fresh cached snapshot instead of hitting the network when the
9
- // same method+URL was fetched within `ttl` ms. Only successful responses to
10
- // cacheable methods (default: GET) are stored, keyed by method+URL. The
11
- // cache is bounded (`max` entries, oldest evicted) and every hit/miss is
12
- // recorded on `client._cache` for inspection. One-shot response bodies are
13
- // normalised on capture so both the current caller and later hits can read
14
- // the JSON body repeatedly.
8
+ // serves a cached snapshot for a repeat of the same method, URL and headers.
9
+ // The store is per client and bounded; see the features reference for the
10
+ // key, the write invalidation and the Cache-Control rules.
15
11
  class CacheFeature extends BaseFeature {
16
12
  version = '0.0.1'
17
13
  name = 'cache'
@@ -20,6 +16,7 @@ class CacheFeature extends BaseFeature {
20
16
  _client
21
17
  _options = {}
22
18
  _store = new Map()
19
+ _key = undefined
23
20
 
24
21
 
25
22
  init(ctx, options) {
@@ -32,6 +29,7 @@ class CacheFeature extends BaseFeature {
32
29
  }
33
30
 
34
31
  this._store = new Map()
32
+ this._key = cacheKey()
35
33
 
36
34
  const self = this
37
35
  const utility = ctx.utility
@@ -48,10 +46,18 @@ class CacheFeature extends BaseFeature {
48
46
  const methods = this._options.methods || ['GET']
49
47
 
50
48
  if (methods.indexOf(method) < 0) {
51
- return inner(ctx, url, fetchdef)
49
+ if (SAFE_METHODS.indexOf(method) >= 0) {
50
+ return inner(ctx, url, fetchdef)
51
+ }
52
+ try {
53
+ return await inner(ctx, url, fetchdef)
54
+ }
55
+ finally {
56
+ this._invalidate(url)
57
+ }
52
58
  }
53
59
 
54
- const key = method + ' ' + url
60
+ const key = method + ' ' + url + ' ' + await this._digest(fetchdef && fetchdef.headers)
55
61
  const now = this._now()
56
62
  const hit = this._store.get(key)
57
63
 
@@ -78,9 +84,16 @@ class CacheFeature extends BaseFeature {
78
84
  return this._replay(snapshot)
79
85
  }
80
86
 
81
- const ttl = null == this._options.ttl ? 5000 : this._options.ttl
87
+ const ttl = cacheLifetime(snapshot.headers,
88
+ null == this._options.ttl ? 5000 : this._options.ttl)
89
+ if (ttl <= 0) {
90
+ this._track('bypass')
91
+ return this._replay(snapshot)
92
+ }
93
+
94
+ this._store.delete(key)
82
95
  this._evict()
83
- this._store.set(key, { expiry: now + ttl, snapshot })
96
+ this._store.set(key, { expiry: now + ttl, scope: urlScope(url), snapshot })
84
97
  this._track('miss')
85
98
  return this._replay(snapshot)
86
99
  }
@@ -90,6 +103,25 @@ class CacheFeature extends BaseFeature {
90
103
  }
91
104
 
92
105
 
106
+ async _digest(headers) {
107
+ const subtle = globalThis.crypto.subtle
108
+ const mac = await subtle.sign('HMAC', await this._key,
109
+ new TextEncoder().encode(headerText(headers)))
110
+ return Array.from(new Uint8Array(mac), (b) => b.toString(16).padStart(2, '0')).join('')
111
+ }
112
+
113
+
114
+ _invalidate(url) {
115
+ const path = urlScope(url)
116
+ const collection = urlParent(path)
117
+ for (const [key, entry] of this._store) {
118
+ if (scopeUnder(entry.scope, path) || entry.scope === collection) {
119
+ this._store.delete(key)
120
+ }
121
+ }
122
+ }
123
+
124
+
93
125
  _cacheable(res) {
94
126
  if (null == res || res instanceof Error) {
95
127
  return false
@@ -188,6 +220,81 @@ class CacheFeature extends BaseFeature {
188
220
  }
189
221
 
190
222
 
223
+ const SAFE_METHODS = ['GET', 'HEAD']
224
+
225
+ const UNSTORED = ['no-store', 'private', 'no-cache']
226
+
227
+
228
+ // A fresh random secret per client: the key holds a digest of the headers,
229
+ // never a header value.
230
+ function cacheKey() {
231
+ const crypto = globalThis.crypto
232
+ return crypto.subtle.importKey('raw', crypto.getRandomValues(new Uint8Array(32)),
233
+ { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
234
+ }
235
+
236
+
237
+ function headerText(headers) {
238
+ const pairs = []
239
+ for (const name of Object.keys(headers || {})) {
240
+ if (null != headers[name]) {
241
+ pairs.push([name.toLowerCase(), String(headers[name])])
242
+ }
243
+ }
244
+ pairs.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0)
245
+ return pairs.map((p) => p[0] + ':' + p[1] + '\n').join('')
246
+ }
247
+
248
+
249
+ // The configured ttl, capped by the response's Cache-Control; zero when the
250
+ // response may not be stored.
251
+ function cacheLifetime(headers, ttl) {
252
+ let control = ''
253
+ for (const name of Object.keys(headers || {})) {
254
+ if ('cache-control' === name.toLowerCase()) {
255
+ control = String(headers[name])
256
+ }
257
+ }
258
+ let life = ttl
259
+ for (const part of control.toLowerCase().split(',')) {
260
+ const directive = part.trim()
261
+ if (UNSTORED.indexOf(directive) >= 0) {
262
+ return 0
263
+ }
264
+ const age = directive.match(/^max-age\s*=\s*"?(\d+)"?$/)
265
+ if (null != age) {
266
+ life = Math.min(life, Number(age[1]) * 1000)
267
+ }
268
+ }
269
+ return life
270
+ }
271
+
272
+
273
+ function urlScope(url) {
274
+ let scope = String(url).split(/[?#]/)[0]
275
+ while (scope.endsWith('/')) {
276
+ scope = scope.slice(0, -1)
277
+ }
278
+ return scope
279
+ }
280
+
281
+
282
+ function urlParent(scope) {
283
+ const scheme = scope.indexOf('://')
284
+ const root = scheme < 0 ? 0 : scope.indexOf('/', scheme + 3)
285
+ if (root < 0) {
286
+ return scope
287
+ }
288
+ const cut = scope.lastIndexOf('/')
289
+ return scope.slice(0, cut < root ? root : cut)
290
+ }
291
+
292
+
293
+ function scopeUnder(scope, prefix) {
294
+ return scope === prefix || scope.startsWith(prefix + '/')
295
+ }
296
+
297
+
191
298
  module.exports = {
192
299
  CacheFeature
193
300
  }
@@ -51,8 +51,9 @@ class CostFeature extends BaseFeature {
51
51
  client._cost = {
52
52
  currency: this._options.currency || 'USD',
53
53
  total: { calls: 0, attempts: 0, amount: 0, reported: 0, estimated: 0 },
54
- ops: {},
55
- actors: {},
54
+ // Keyed by a caller's string, so no prototype to collide with.
55
+ ops: Object.create(null),
56
+ actors: Object.create(null),
56
57
  budget: { limit, spent: 0, remaining: limit, exceeded: false },
57
58
  last: undefined,
58
59
  }
@@ -6,9 +6,9 @@ const { BaseFeature } = require('../base/BaseFeature')
6
6
  // Statistics capture. Records per-operation counters and latency for every
7
7
  // call: totals plus a breakdown keyed by `<entity>.<op>`. Timing starts at
8
8
  // endpoint resolution (PrePoint) and stops when the call returns (PreDone)
9
- // or throws (PreUnexpected). Aggregates live on `client._metrics` and can be
10
- // read via `client.metrics()` in the generated SDK. The clock is injectable
11
- // (`now`) for deterministic tests.
9
+ // or throws (PreUnexpected). Aggregates live on `client._metrics`; a `sink`
10
+ // callback, when provided, is given a copy of them after each operation. The
11
+ // clock is injectable (`now`) for deterministic tests.
12
12
  class MetricsFeature extends BaseFeature {
13
13
  version = '0.0.1'
14
14
  name = 'metrics'
@@ -29,7 +29,7 @@ class MetricsFeature extends BaseFeature {
29
29
  if (null == client._metrics) {
30
30
  client._metrics = {
31
31
  total: { count: 0, ok: 0, err: 0, totalMs: 0, maxMs: 0 },
32
- ops: {},
32
+ ops: Object.create(null),
33
33
  }
34
34
  }
35
35
  }
@@ -74,6 +74,11 @@ class MetricsFeature extends BaseFeature {
74
74
 
75
75
  this._bump(m.total, ok, dur)
76
76
  this._bump(op, ok, dur)
77
+
78
+ const sink = this._options.sink
79
+ if ('function' === typeof sink) {
80
+ try { sink(ctx.utility.clean(ctx, m)) } catch (_e) { }
81
+ }
77
82
  }
78
83
 
79
84
 
@@ -58,6 +58,9 @@ class PagingFeature extends BaseFeature {
58
58
  if (null != paging.cursor) {
59
59
  spec.query[cursorParam] = paging.cursor
60
60
  }
61
+ else if ('string' === typeof paging.next && !this._foreign(paging.next, spec.base)) {
62
+ this._follow(spec, paging.next)
63
+ }
61
64
  else if (null == spec.query[pageParam]) {
62
65
  // A record written back by PreResult holds the page just fetched as
63
66
  // `page` and the one to fetch as `nextPage`, so nextPage wins.
@@ -93,6 +96,7 @@ class PagingFeature extends BaseFeature {
93
96
  nextPage: this._num(this._header(headers, 'x-next-page')),
94
97
  next: undefined,
95
98
  cursor: undefined,
99
+ foreign: undefined,
96
100
  hasMore: false,
97
101
  }
98
102
 
@@ -130,7 +134,10 @@ class PagingFeature extends BaseFeature {
130
134
 
131
135
  // Body-level signals; snake_case forms are read first so camelCase wins.
132
136
  if (body && 'object' === typeof body) {
133
- if (null != body.next) { paging.next = paging.next || body.next }
137
+ if (null != body.next) {
138
+ if (this._isLink(body.next)) { paging.next = paging.next || body.next }
139
+ else { paging.cursor = body.next }
140
+ }
134
141
  if (null != body.next_cursor) { paging.cursor = body.next_cursor }
135
142
  if (null != body.cursor) { paging.cursor = body.cursor }
136
143
  if (null != body.nextCursor) { paging.cursor = body.nextCursor }
@@ -148,6 +155,16 @@ class PagingFeature extends BaseFeature {
148
155
  }
149
156
  }
150
157
 
158
+ // A link to another origin is recorded, never followed, and ends the walk.
159
+ const base = null == ctx.spec ? ctx.options?.base : ctx.spec.base
160
+ if (null != paging.next) {
161
+ paging.next = this._resolve(paging.next, ctx.spec?.url)
162
+ }
163
+ if (null != paging.next && this._foreign(paging.next, base)) {
164
+ paging.foreign = paging.next
165
+ paging.next = undefined
166
+ }
167
+
151
168
  // Cursor presence only INFERS another page. When the server stated the
152
169
  // answer outright — relay's `hasNextPage: false`, or a body `hasMore` —
153
170
  // that wins: a final page normally carries both an end cursor and
@@ -158,6 +175,10 @@ class PagingFeature extends BaseFeature {
158
175
  null != paging.next || null != paging.cursor || null != paging.nextPage
159
176
  }
160
177
 
178
+ if (null != paging.foreign && null == paging.cursor && null == paging.nextPage) {
179
+ paging.hasMore = false
180
+ }
181
+
161
182
  result.paging = paging
162
183
 
163
184
  // ctx.ctrl is the caller's own object, so the record reaches them.
@@ -189,21 +210,98 @@ class PagingFeature extends BaseFeature {
189
210
 
190
211
  // Only bind variables the operation actually declares, or the server
191
212
  // rejects the document.
192
- const declared = {}
213
+ const declared = new Set()
193
214
  for (const v of ((point.graphql && point.graphql.vars) || [])) {
194
- declared[v.name] = true
215
+ declared.add(v.name)
195
216
  }
196
217
 
197
- if (null != paging.cursor && declared[afterVar]) {
218
+ if (null != paging.cursor && declared.has(afterVar)) {
198
219
  vars[afterVar] = paging.cursor
199
220
  }
200
221
 
201
222
  if (null != this._options.limit && null == vars[firstVar] &&
202
- declared[firstVar]) {
223
+ declared.has(firstVar)) {
203
224
  vars[firstVar] = this._options.limit
204
225
  }
205
226
  }
206
227
 
228
+ // Under the `next` option's default, a URL or an absolute path is a link and
229
+ // anything else a cursor; `cursor` and `url` pin the reading.
230
+ _isLink(next) {
231
+ if ('string' !== typeof next) { return false }
232
+ const mode = this._options.next || 'auto'
233
+ return 'url' === mode ||
234
+ ('cursor' !== mode && ('' !== this._origin(next) || next.startsWith('/')))
235
+ }
236
+
237
+
238
+ _origin(text) {
239
+ const m = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec('string' === typeof text ? text : '')
240
+ return null == m ? '' : m[0].toLowerCase()
241
+ }
242
+
243
+
244
+ _foreign(link, base) {
245
+ const origin = this._origin(link)
246
+ return '' !== origin && origin !== this._origin(base)
247
+ }
248
+
249
+
250
+ // RFC 3986 reference resolution against the URL of the request that
251
+ // returned the link. A link on that URL's origin comes back as its path and
252
+ // query; an absolute link is left as the server wrote it.
253
+ _resolve(link, url) {
254
+ if ('string' !== typeof url || '' === url || /^[a-z][a-z0-9+.-]*:/i.test(link)) {
255
+ return link
256
+ }
257
+ const bare = '' === this._origin(url)
258
+ const holder = 'http://placeholder.invalid'
259
+ try {
260
+ const from = new URL(bare ? holder + (url.startsWith('/') ? '' : '/') + url : url)
261
+ const out = new URL(link, from)
262
+ return out.origin === from.origin ? out.pathname + out.search : out.href
263
+ }
264
+ catch (_e) {
265
+ return link
266
+ }
267
+ }
268
+
269
+
270
+ // The request goes to the link's path and query, on the SDK's own origin.
271
+ _follow(spec, next) {
272
+ const link = /^(?:[a-z][a-z0-9+.-]*:\/\/[^/?#]*)?([^?#]*)(?:\?([^#]*))?/i.exec(next)
273
+ const origin = /^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(String(spec.base || ''))
274
+
275
+ const query = {}
276
+ for (const pair of (link[2] || '').split('&')) {
277
+ if ('' === pair) { continue }
278
+ const at = pair.indexOf('=')
279
+ const key = at < 0 ? pair : pair.slice(0, at)
280
+ const val = at < 0 ? '' : pair.slice(at + 1)
281
+ query[this._unescape(key)] = this._unescape(val)
282
+ }
283
+ for (const key of (spec.authquery || [])) {
284
+ query[key] = spec.query[key]
285
+ }
286
+
287
+ spec.base = null == origin ? '' : origin[0]
288
+ spec.prefix = ''
289
+ spec.path = link[1]
290
+ spec.suffix = ''
291
+ spec.query = query
292
+ }
293
+
294
+
295
+ _unescape(text) {
296
+ try {
297
+ return decodeURIComponent(text.replace(/\+/g, ' '))
298
+ }
299
+ catch (err) {
300
+ return text
301
+ }
302
+ }
303
+
304
+
207
305
  _isList(ctx) {
208
306
  const ops = this._options.ops || ['list']
209
307
  return ops.indexOf(ctx.op && ctx.op.name) >= 0
@@ -48,24 +48,20 @@ class RatelimitFeature extends BaseFeature {
48
48
  const rate = this._options.rate || 5
49
49
  const burst = null == this._options.burst ? rate : this._options.burst
50
50
 
51
- // Refill according to elapsed time.
51
+ // Refill, then reserve this call's token before any wait: a negative
52
+ // count is the calls already queued, so overlapping calls pace in turn.
52
53
  const now = this._now()
53
54
  const elapsed = now - this._last
54
55
  this._last = now
55
- this._tokens = Math.min(burst, this._tokens + (elapsed / 1000) * rate)
56
+ this._tokens = Math.min(burst, this._tokens + (elapsed / 1000) * rate) - 1
56
57
 
57
- if (this._tokens >= 1) {
58
- this._tokens -= 1
58
+ if (this._tokens >= 0) {
59
59
  return
60
60
  }
61
61
 
62
- // Not enough tokens: wait for one to accrue, then consume it.
63
- const needed = 1 - this._tokens
64
- const waitMs = Math.ceil((needed / rate) * 1000)
62
+ const waitMs = Math.ceil((-this._tokens / rate) * 1000)
65
63
  this._track(ctx, waitMs)
66
64
  await this._sleep(waitMs, signal)
67
- this._last = this._now()
68
- this._tokens = 0
69
65
  }
70
66
 
71
67
 
@@ -18,7 +18,7 @@ class RbacFeature extends BaseFeature {
18
18
 
19
19
  _client
20
20
  _options = {}
21
- _granted = {}
21
+ _granted = new Set()
22
22
 
23
23
 
24
24
  init(ctx, options) {
@@ -26,10 +26,10 @@ class RbacFeature extends BaseFeature {
26
26
  this._options = options || {}
27
27
  this.active = options.active
28
28
 
29
- this._granted = {}
29
+ this._granted = new Set()
30
30
  const perms = this._options.permissions || []
31
31
  for (const p of perms) {
32
- this._granted[p] = true
32
+ this._granted.add(p)
33
33
  }
34
34
  }
35
35
 
@@ -48,7 +48,7 @@ class RbacFeature extends BaseFeature {
48
48
  return
49
49
  }
50
50
 
51
- if (this._granted['*'] || this._granted[required]) {
51
+ if (this._granted.has('*') || this._granted.has(required)) {
52
52
  this._track(ctx, required, true)
53
53
  return
54
54
  }