@voxgig/sdkgen 4.49.1 → 4.51.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 (218) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/debug.c +1 -0
  30. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  31. package/project/.sdk/tm/c/feature/telemetry.c +1 -0
  32. package/project/.sdk/tm/c/tests/feature_test.c +142 -0
  33. package/project/.sdk/tm/c/utility/clean.c +26 -33
  34. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  35. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  36. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  37. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  38. package/project/.sdk/tm/clojure/src/sdk/features.clj +83 -10
  39. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +47 -0
  40. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  41. package/project/.sdk/tm/cpp/Makefile +5 -0
  42. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  43. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  44. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  45. package/project/.sdk/tm/cpp/feature/debug.hpp +1 -0
  46. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  47. package/project/.sdk/tm/cpp/feature/telemetry.hpp +1 -0
  48. package/project/.sdk/tm/cpp/test/feature_test.cpp +128 -0
  49. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  50. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  51. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  52. package/project/.sdk/tm/csharp/feature/DebugFeature.cs +1 -0
  53. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  54. package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +1 -0
  55. package/project/.sdk/tm/csharp/test/FeatureTest.cs +101 -0
  56. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  57. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  58. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  59. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  60. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  61. package/project/.sdk/tm/elixir/lib/projectname/feature/debug.ex +1 -0
  62. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  63. package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +1 -0
  64. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  65. package/project/.sdk/tm/elixir/test/feature_test.exs +84 -0
  66. package/project/.sdk/tm/go/core/context.go +6 -0
  67. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  68. package/project/.sdk/tm/go/feature/debug_feature.go +3 -2
  69. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  70. package/project/.sdk/tm/go/feature/telemetry_feature.go +5 -4
  71. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  72. package/project/.sdk/tm/go/test/feature_test.go +101 -0
  73. package/project/.sdk/tm/go/utility/clean.go +5 -7
  74. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  75. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  76. package/project/.sdk/tm/java/core/Context.java +9 -0
  77. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  78. package/project/.sdk/tm/java/feature/DebugFeature.java +1 -0
  79. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  80. package/project/.sdk/tm/java/feature/TelemetryFeature.java +1 -0
  81. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  82. package/project/.sdk/tm/java/test/FeatureTest.java +88 -0
  83. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  84. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  85. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  86. package/project/.sdk/tm/js/src/Context.js +4 -0
  87. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  88. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  89. package/project/.sdk/tm/js/src/feature/debug/DebugFeature.js +1 -0
  90. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  91. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  92. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  93. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  94. package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +1 -0
  95. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  96. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  97. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  98. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  99. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  100. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  101. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  102. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  103. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  104. package/project/.sdk/tm/kotlin/feature/DebugFeature.kt +1 -0
  105. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  106. package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +1 -0
  107. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +79 -0
  108. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  109. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  110. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  111. package/project/.sdk/tm/lua/core/context.lua +6 -0
  112. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  113. package/project/.sdk/tm/lua/feature/debug_feature.lua +1 -0
  114. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  115. package/project/.sdk/tm/lua/feature/telemetry_feature.lua +1 -0
  116. package/project/.sdk/tm/lua/test/feature_test.lua +108 -0
  117. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  118. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  119. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  120. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  121. package/project/.sdk/tm/ocaml/sdk_features.ml +108 -8
  122. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  123. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  124. package/project/.sdk/tm/ocaml/test/t_feature.ml +51 -1
  125. package/project/.sdk/tm/perl/core/context.pm +3 -0
  126. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  127. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  128. package/project/.sdk/tm/perl/feature/debug_feature.pm +1 -0
  129. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  130. package/project/.sdk/tm/perl/feature/telemetry_feature.pm +1 -0
  131. package/project/.sdk/tm/perl/t/feature.t +86 -0
  132. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  133. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  134. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  135. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  136. package/project/.sdk/tm/php/core/Context.php +4 -0
  137. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  138. package/project/.sdk/tm/php/feature/DebugFeature.php +1 -0
  139. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  140. package/project/.sdk/tm/php/feature/TelemetryFeature.php +1 -0
  141. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  142. package/project/.sdk/tm/php/test/FeatureTest.php +90 -0
  143. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  144. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  145. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  146. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  147. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  148. package/project/.sdk/tm/py/pkg/feature/debug_feature.py +1 -0
  149. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  150. package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +1 -0
  151. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  152. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  153. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  154. package/project/.sdk/tm/py/test/test_feature.py +73 -0
  155. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  156. package/project/.sdk/tm/rb/core/context.rb +4 -1
  157. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  158. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  159. package/project/.sdk/tm/rb/feature/debug_feature.rb +1 -0
  160. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  161. package/project/.sdk/tm/rb/feature/telemetry_feature.rb +1 -0
  162. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  163. package/project/.sdk/tm/rb/test/feature_test.rb +93 -0
  164. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  165. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  166. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  167. package/project/.sdk/tm/rust/core/context.rs +8 -0
  168. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  169. package/project/.sdk/tm/rust/feature/debug.rs +1 -0
  170. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  171. package/project/.sdk/tm/rust/feature/telemetry.rs +1 -0
  172. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  173. package/project/.sdk/tm/rust/tests/feature_test.rs +141 -0
  174. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  175. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  176. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  177. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  178. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  179. package/project/.sdk/tm/scala/feature/DebugFeature.scala +1 -0
  180. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  181. package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +1 -0
  182. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +52 -1
  183. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  184. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  185. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  186. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  187. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  188. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/DebugFeature.swift +1 -0
  189. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  190. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +1 -0
  191. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  192. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  193. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  194. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +79 -0
  195. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  196. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  197. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  198. package/project/.sdk/tm/ts/src/feature/debug/DebugFeature.ts +1 -0
  199. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  200. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  201. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  202. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  203. package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +1 -0
  204. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  205. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  206. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  207. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  208. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  209. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  210. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  211. package/project/.sdk/tm/zig/core/context.zig +5 -0
  212. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  213. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  214. package/project/.sdk/tm/zig/feature/debug.zig +1 -0
  215. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  216. package/project/.sdk/tm/zig/feature/telemetry.zig +1 -0
  217. package/project/.sdk/tm/zig/test/feature_test.zig +100 -0
  218. package/project/sdkgen-package.json +1 -1
@@ -354,6 +354,8 @@
354
354
  config (let [c (cprop "config")] (if (vs/ismap c) c (bget :config)))
355
355
  entopts (let [e (cprop "entopts")] (if (vs/ismap e) e (bget :entopts)))
356
356
  options (let [o (cprop "options")] (if (vs/ismap o) o (bget :options)))
357
+ ;; The clean registry, beside the options rather than in them.
358
+ cleancfg (or (cprop "cleancfg") (bget :cleancfg))
357
359
  entity (or (cprop "entity") (bget :entity))
358
360
  shared (let [s (cprop "shared")] (if (vs/ismap s) s (bget :shared)))
359
361
  opmap (or (cprop "opmap") (bget :opmap) (atom {}))
@@ -369,7 +371,8 @@
369
371
  ctx (atom {:id (str "C" (+ 10000000 (rand-int 89999999)))
370
372
  :out (atom (vs/jm))
371
373
  :client client :utility utility :ctrl ctrl :meta meta
372
- :config config :entopts entopts :options options :entity entity
374
+ :config config :entopts entopts :options options :cleancfg cleancfg
375
+ :entity entity
373
376
  :shared shared :opmap opmap
374
377
  :data (dmap "data") :reqdata (dmap "reqdata")
375
378
  :match (dmap "match") :reqmatch (dmap "reqmatch")
@@ -491,8 +494,8 @@
491
494
  (let [n (try (long (Math/floor (Double/parseDouble (str v)))) (catch Exception _ nil))]
492
495
  (if (and n (<= 0 n)) n dflt)))
493
496
 
494
- ;; The derived clean block: a java.util.Map so it lives in options.__derived__
495
- ;; and its `values` list can be replaced after make-options - features
497
+ ;; The clean registry: a java.util.Map, held on the context as :cleancfg,
498
+ ;; whose `values` list can be replaced after make-options - features
496
499
  ;; register what they resolve later. Concurrent, so a clean or a request
497
500
  ;; copying the options reads it without the lock and sees the last put.
498
501
  (defn make-clean-config [cleanopts]
@@ -507,12 +510,11 @@
507
510
  (.put "hint" (count-opt (o "hint") 0))
508
511
  (.put "min" (max 1 (count-opt (o "min") 4))))))
509
512
 
510
- ;; A context without options (make-error accepts a bare one) still masks by
511
- ;; the schema defaults.
513
+ ;; A context without a registry (make-error accepts a bare one) still masks
514
+ ;; by the schema defaults.
512
515
  (defn- clean-config [ctx]
513
- (let [options (when (instance? clojure.lang.IDeref ctx) (oget ctx :options))
514
- derived (when (vs/ismap options) (vs/getpath options "__derived__.clean"))]
515
- (if (vs/ismap derived) derived (make-clean-config (vs/getprop @optspec-parsed "clean")))))
516
+ (let [cfg (when (instance? clojure.lang.IDeref ctx) (oget ctx :cleancfg))]
517
+ (if (vs/ismap cfg) cfg (make-clean-config (vs/getprop @optspec-parsed "clean")))))
516
518
 
517
519
  ;; The encoded forms a value travels in.
518
520
  (defn- clean-forms [^String value]
@@ -1875,7 +1877,7 @@
1875
1877
  (when (vs/ismap src)
1876
1878
  (doseq [k (vs/keysof src)] (.put ^java.util.Map out k (vs/getprop src k)))))
1877
1879
  out))
1878
- cleanctx (atom {:options (vs/jm "__derived__" (vs/jm "clean" cleancfg))})
1880
+ cleanctx (atom {:cleancfg cleancfg})
1879
1881
  _ (clean-add-options cleanctx (omit-keys opts0 ["clean"]))
1880
1882
  _ (doseq [raw (concat (splitvalues (vs/getpath cfgopts "clean.values"))
1881
1883
  (splitvalues (vs/getpath opts0 "clean.values")))]
@@ -1938,10 +1940,12 @@
1938
1940
  (when (some #(= % "test") names) (.add ^java.util.List order "test"))
1939
1941
  (doseq [n names] (when (not= n "test") (.add ^java.util.List order n)))
1940
1942
  order))
1941
- derived (vs/jm "clean" cleancfg "featureorder" feature-order)]
1943
+ derived (vs/jm "featureorder" feature-order)]
1942
1944
  (.put ^java.util.Map opts "__derived__" derived)
1945
+ ;; Beside the options, not in them: options-map hands them to callers.
1946
+ (oset! ctx :cleancfg cleancfg)
1943
1947
  ;; Again over the merged result: the config's own defaults can carry one.
1944
- (clean-add-options (atom {:options opts}) (omit-keys opts ["clean" "__derived__"]))
1948
+ (clean-add-options cleanctx (omit-keys opts ["clean" "__derived__"]))
1945
1949
  opts))))
1946
1950
 
1947
1951
  ;; ---------------------------------------------------------------------------
@@ -2013,6 +2017,10 @@
2013
2017
  (let [builder (HttpRequest/newBuilder (URI/create fullurl))
2014
2018
  has-ua (atom false)]
2015
2019
  (.method builder (str/upper-case method-str) (body-publisher fetchdef))
2020
+ ;; A bound in milliseconds, for a caller beneath the timeout feature.
2021
+ (let [bound (vs/getprop fetchdef "timeout")]
2022
+ (when (and (number? bound) (pos? bound))
2023
+ (.timeout builder (java.time.Duration/ofMillis (long bound)))))
2016
2024
  (doseq [item (or (vs/items headers) [])]
2017
2025
  (let [k (vs/getprop item 0) v (vs/getprop item 1)]
2018
2026
  (when (string? v)
@@ -472,6 +472,52 @@
472
472
  ;; cache
473
473
  ;; ---------------------------------------------------------------------------
474
474
 
475
+ (def ^:private cache-unstored #{"no-store" "private" "no-cache"})
476
+
477
+ (defn- cache-header-text [v]
478
+ (cond (nil? v) nil
479
+ (string? v) v
480
+ (and (number? v) (== v (Math/floor (double v)))) (str (long v))
481
+ :else (str v)))
482
+
483
+ (defn- cache-digest [^javax.crypto.spec.SecretKeySpec secret headers]
484
+ (let [pairs (if (instance? java.util.Map headers)
485
+ (sort (keep (fn [[k v]] (when-let [t (cache-header-text v)] [(str/lower-case (str k)) t]))
486
+ (seq ^java.util.Map headers)))
487
+ [])
488
+ mac (doto (javax.crypto.Mac/getInstance "HmacSHA256") (.init secret))]
489
+ (doseq [[k v] pairs]
490
+ (.update mac (.getBytes (str k ":" v "\n") "UTF-8")))
491
+ (apply str (map #(format "%02x" (bit-and (long %) 0xff)) (.doFinal mac)))))
492
+
493
+ ;; The configured ttl capped by the response's Cache-Control; zero when the
494
+ ;; response may not be stored.
495
+ (defn- cache-lifetime [headers ttl]
496
+ (let [control (str/lower-case (or (some (fn [[k v]] (when (= "cache-control" (str/lower-case (str k))) (cache-header-text v)))
497
+ (when (instance? java.util.Map headers) (seq ^java.util.Map headers)))
498
+ ""))
499
+ directives (map str/trim (str/split control #","))]
500
+ (if (some cache-unstored directives)
501
+ 0
502
+ (reduce (fn [life d]
503
+ (if-let [[_ secs] (re-matches #"max-age\s*=\s*\"?(\d+)\"?" d)]
504
+ (long (min life (*' 1000 (bigint secs))))
505
+ life))
506
+ (long ttl) directives))))
507
+
508
+ (defn- cache-scope [url]
509
+ (str/replace (first (str/split (str url) #"[?#]" 2)) #"/+$" ""))
510
+
511
+ (defn- cache-parent [scope]
512
+ (let [scheme (str/index-of scope "://")
513
+ root (if (nil? scheme) 0 (str/index-of scope "/" (+ scheme 3)))]
514
+ (if (nil? root)
515
+ scope
516
+ (subs scope 0 (max root (or (str/last-index-of scope "/") 0))))))
517
+
518
+ (defn- cache-under? [scope prefix]
519
+ (or (= scope prefix) (str/starts-with? scope (str prefix "/"))))
520
+
475
521
  (defn cache-feature []
476
522
  (let [fa (new-feature "cache" false "0.0.1")
477
523
  track! (fn [kind]
@@ -506,12 +552,22 @@
506
552
  (let [oldest (first (keys (:store @fa)))]
507
553
  (if (nil? oldest) (swap! fa assoc :store {})
508
554
  (swap! fa update :store dissoc oldest))))))
555
+ invalidate! (fn [url]
556
+ (let [path (cache-scope url)
557
+ collection (cache-parent path)]
558
+ (swap! fa update :store
559
+ (fn [store]
560
+ (into {} (remove (fn [[_ e]] (let [scope (mget e "scope")]
561
+ (or (cache-under? scope path)
562
+ (= scope collection))))
563
+ store))))))
509
564
  through (fn [ctx url fetchdef inner]
510
565
  (let [method (str/upper-case (str (or (and (vs/ismap fetchdef) (vs/getprop fetchdef "method")) "GET")))
511
566
  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)
567
+ (cond
568
+ (some #(= % method) (vec methods))
569
+ (let [key (str method " " url " "
570
+ (cache-digest (:secret @fa) (when (vs/ismap fetchdef) (vs/getprop fetchdef "headers"))))
515
571
  now (now-ms fa)
516
572
  hit (get (:store @fa) key)]
517
573
  (if (and (some? hit) (> (mget hit "expiry") now))
@@ -524,17 +580,32 @@
524
580
 
525
581
  (and (nil? err) (cacheable? res))
526
582
  (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])
583
+ ttl (cache-lifetime (mget snap "headers") (opt fa "ttl" 5000))]
584
+ (if (<= ttl 0)
585
+ (do (track! "bypass") [(replay snap) nil])
586
+ (do
587
+ (swap! fa update :store dissoc key)
588
+ (evict!)
589
+ (swap! fa update :store assoc key
590
+ (vs/jm "expiry" (+ now ttl) "scope" (cache-scope url) "snapshot" snap))
591
+ (track! "miss")
592
+ [(replay snap) nil])))
593
+
594
+ :else (do (track! "bypass") [res err])))))
595
+
596
+ (contains? #{"GET" "HEAD"} method)
597
+ (inner ctx url fetchdef)
532
598
 
533
- :else (do (track! "bypass") [res err]))))))))]
599
+ :else
600
+ (try (inner ctx url fetchdef)
601
+ (finally (invalidate! url))))))]
534
602
  (swap! fa assoc
535
603
  "init" (fn [ctx options]
536
604
  (swap! fa assoc :client (core/oget ctx :client)
537
- :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :store {})
605
+ :options (if (vs/ismap options) options (vs/jm)) :active (opts-active? options) :store {}
606
+ :secret (let [bytes (byte-array 32)]
607
+ (.nextBytes (java.security.SecureRandom.) bytes)
608
+ (javax.crypto.spec.SecretKeySpec. bytes "HmacSHA256")))
538
609
  (when (active? fa)
539
610
  (wrap-fetcher! ctx (fn [fctx url fd inner] (through fctx url fd inner))))))
540
611
  fa))
@@ -1054,6 +1125,7 @@
1054
1125
  (when (active? fa)
1055
1126
  (let [op (core/oget ctx :op)
1056
1127
  span (vs/jm "traceId" (gen-id2 "trace") "spanId" (gen-id2 "span")
1128
+ "correlationId" (core/oget ctx :id)
1057
1129
  "name" (str (if op (core/op-entity op) "_") "." (if op (core/op-name op) "_"))
1058
1130
  "start" (now-ms fa) "end" nil "durationMs" nil "ok" nil)]
1059
1131
  (swap! fa update :spans assoc ctx span)
@@ -1175,6 +1247,7 @@
1175
1247
  method (when spec (core/oget spec :method))
1176
1248
  headers (when spec (core/oget spec :headers))
1177
1249
  entry (vs/jm "op" (str (if op (core/op-entity op) "_") "." (if op (core/op-name op) "_"))
1250
+ "correlationId" (core/oget ctx :id)
1178
1251
  "method" method "url" url "headers" (redact ctx headers) "start" (now-ms fa)
1179
1252
  "status" nil "ok" nil "durationMs" nil "error" nil)]
1180
1253
  (swap! fa update :entries assoc ctx entry))))
@@ -365,6 +365,39 @@
365
365
  h (make-harness [(fspec "cache" "active" false)] :server server)]
366
366
  (h-op h :path "/x") (h-op h :path "/x")
367
367
  (t/is-eq (count @calls) 2 "two calls"))))
368
+ (check "cache-keys-on-request-headers" "cache"
369
+ (fn [] (let [[server calls] (recording-server nil)
370
+ h (make-harness [(fspec "cache" "ttl" 10000)] :server server)]
371
+ (h-op h :path "/w/1" :headers (vs/jm "x-tenant" "tenant-a"))
372
+ (h-op h :path "/w/1" :headers (vs/jm "X-Tenant" "tenant-b"))
373
+ (t/is-eq (count @calls) 2 "a second tenant was not served the first tenant's entry")
374
+ (h-op h :path "/w/1" :headers (vs/jm "x-tenant" "tenant-b"))
375
+ (t/is-eq (count @calls) 2 "the same headers share an entry"))))
376
+ (check "cache-a-write-drops-its-collection" "cache"
377
+ (fn [] (let [[server calls] (recording-server nil)
378
+ h (make-harness [(fspec "cache" "ttl" 10000)] :server server)
379
+ paths ["/w/1" "/w" "/w/1/part" "/other/1" "/w/2"]]
380
+ (doseq [p paths] (h-op h :path p))
381
+ (h-op h :opname "update" :method "PUT" :path "/w/1")
382
+ (doseq [p paths] (h-op h :path p))
383
+ (t/is-eq (count @calls) 9 "the collection refetched")
384
+ (t/is-eq (mget (h-track h "_cache") "hit") 2 "the other entity stayed cached"))))
385
+ (check "cache-control-prevents-storing" "cache"
386
+ (fn [] (doseq [control ["no-store" "private" "No-Cache" "max-age=60, private"]]
387
+ (let [[server calls] (recording-server
388
+ (fn [_n _fd] [(make-response 200 (vs/jm "ok" true) (vs/jm "Cache-Control" control)) nil]))
389
+ h (make-harness [(fspec "cache" "ttl" 10000)] :server server)]
390
+ (h-op h :path "/w") (h-op h :path "/w")
391
+ (t/is-eq (count @calls) 2 (str control " was not stored"))))))
392
+ (check "cache-max-age-caps-the-ttl" "cache"
393
+ (fn [] (let [c (make-clock)
394
+ [server calls] (recording-server
395
+ (fn [_n _fd] [(make-response 200 (vs/jm "ok" true) (vs/jm "cache-control" "max-age=1")) nil]))
396
+ h (make-harness [(fspec "cache" "ttl" 10000 "now" (clock-now c))] :server server)]
397
+ (h-op h :path "/w") (clock-advance c 500) (h-op h :path "/w")
398
+ (t/is-eq (count @calls) 1 "a hit inside max-age")
399
+ (clock-advance c 600) (h-op h :path "/w")
400
+ (t/is-eq (count @calls) 2 "max-age expired before the ttl"))))
368
401
 
369
402
  ;; ---- idempotency ----
370
403
  (check "idempotency-adds-key-mutating" "idempotency"
@@ -517,6 +550,20 @@
517
550
  (t/is-eq (mget (vs/getelem recs 0) "seq") 2 "seq 2")
518
551
  (t/is-eq (mget (vs/getelem recs 1) "seq") 3 "seq 3")))))
519
552
 
553
+ ;; ---- one call, one id ----
554
+ (check "telemetry-debug-audit-one-call-context-id" "telemetry"
555
+ (fn [] (when (and (feature-present? "debug") (feature-present? "audit"))
556
+ (let [h (make-harness [(fspec "telemetry") (fspec "debug") (fspec "audit")])
557
+ ids (fn [recs] (mapv (fn [rec] (mget rec "correlationId")) recs))]
558
+ (h-op h)
559
+ (h-op h :opname "list")
560
+ (let [calls (ids (mget (h-track h "_audit") "records"))]
561
+ (t/is-eq (count calls) 2 "one audit record per call")
562
+ (t/is-true (every? (fn [id] (and (string? id) (not= "" id))) calls) (pr-str calls))
563
+ (t/is-true (not= (nth calls 0) (nth calls 1)) "a different id per call")
564
+ (t/is-eq (ids (mget (h-track h "_telemetry") "spans")) calls "span ids")
565
+ (t/is-eq (ids (mget (h-track h "_debug") "entries")) calls "debug entry ids"))))))
566
+
520
567
  ;; ---- clienttrack ----
521
568
  (check "clienttrack-stable-id-unique-req" "clienttrack"
522
569
  (fn [] (let [[server calls] (recording-server nil)
@@ -15,6 +15,7 @@
15
15
  (let [utility (core/get-utility sdk)
16
16
  ctx (core/make-context (vs/jm "opname" opname "client" sdk "utility" utility) nil)]
17
17
  (when (nil? (core/oget ctx :options)) (core/oset! ctx :options (core/client-options-map sdk)))
18
+ (core/oset! ctx :cleancfg (core/oget (core/client-root-ctx sdk) :cleancfg))
18
19
  ctx))
19
20
 
20
21
  (defn- set-points! [ctx pts] (swap! (core/oget ctx :op) assoc :points pts))
@@ -10,6 +10,11 @@
10
10
 
11
11
  CXX ?= g++
12
12
  CXXFLAGS ?= -std=c++17 -O0 -g -Wall -Wextra -Wno-unused-parameter -pthread
13
+ ifeq ($(OS),Windows_NT)
14
+ ifneq (,$(findstring g++,$(CXX)))
15
+ CXXFLAGS += -Wa,-mbig-obj
16
+ endif
17
+ endif
13
18
 
14
19
  # ---- gated feature payloads (model/feature/<name>.aontu plugin groups) --------
15
20
  #
@@ -460,6 +460,7 @@ struct CtxSpec {
460
460
 
461
461
  Value config = Value::undef();
462
462
  Value options = Value::undef();
463
+ Value cleancfg = Value::undef();
463
464
  Value shared = Value::undef();
464
465
  Value meta = Value::undef();
465
466
  Value entopts = Value::undef();
@@ -491,6 +492,9 @@ struct CtxOut {
491
492
  ResponsePtr request;
492
493
  ResponsePtr response;
493
494
  ResultPtr result;
495
+ // Per-call feature state that must end with the call (the c port's
496
+ // ctx_out_extra).
497
+ std::map<std::string, Value> extra;
494
498
  };
495
499
 
496
500
  // ---- Context ----------------------------------------------------------
@@ -508,6 +512,8 @@ public:
508
512
  Value config = Value::undef();
509
513
  Value entopts = Value::undef();
510
514
  Value options = Value::undef();
515
+ // The clean registry, beside the options rather than in them.
516
+ Value cleancfg = Value::undef();
511
517
  OpMapPtr opmap;
512
518
  ResponsePtr response;
513
519
  ResultPtr result;
@@ -630,9 +636,9 @@ public:
630
636
 
631
637
  // ---- SdkClient --------------------------------------------------------
632
638
 
633
- // A registration replaces the secret registry (options.__derived__.clean
634
- // .values) while requests copy the options: it holds this lock exclusively,
635
- // and every read of that slot holds it shared.
639
+ // A registration replaces the secret registry's `values` slot while other
640
+ // threads clean: it holds this lock exclusively, and every read of that slot
641
+ // holds it shared.
636
642
  inline std::shared_mutex& cleanRegistryLock() {
637
643
  // winpthreads sets up a static rwlock on its first lock, failing threads
638
644
  // that race it with EINVAL; that first lock runs in this static's
@@ -811,6 +817,8 @@ inline Context::Context(const CtxSpec& cs, const CtxPtr& basectx) {
811
817
  // Options
812
818
  if (cs.options.is_map()) options = cs.options;
813
819
  if (options.is_undef() && basectx) options = basectx->options;
820
+ if (cs.cleancfg.is_map()) cleancfg = cs.cleancfg;
821
+ if (cleancfg.is_undef() && basectx) cleancfg = basectx->cleancfg;
814
822
 
815
823
  // Entity
816
824
  entity = cs.entity;
@@ -978,7 +986,6 @@ inline SdkClient::SdkClient(const Value& options_) {
978
986
  }
979
987
 
980
988
  inline Value SdkClient::optionsMap() {
981
- std::shared_lock<std::shared_mutex> guard(cleanRegistryLock());
982
989
  Value out = Struct::clone(options);
983
990
  return out.is_map() ? out : vmap();
984
991
  }
@@ -4,13 +4,12 @@
4
4
  // on the feature (bounded by `max`, default 1000) and, when a `sink` callback
5
5
  // is supplied, are pushed to it. The actor is the per-call ctrl actor,
6
6
  // falling back to the options `actor`, then "anonymous". Each operation is
7
- // audited exactly once (the per-context seen marker — java ctx.out — is kept
8
- // here keyed by ctx.id). Timestamps use the injectable `now` clock.
7
+ // audited exactly once (the per-context seen marker, java's ctx.out, is kept
8
+ // in ctx->out.extra). Timestamps use the injectable `now` clock.
9
9
 
10
10
  #ifndef SDK_FEATURE_AUDIT_HPP
11
11
  #define SDK_FEATURE_AUDIT_HPP
12
12
 
13
- #include <map>
14
13
  #include <string>
15
14
 
16
15
  #include "../core/types.hpp"
@@ -52,15 +51,15 @@ public:
52
51
  }
53
52
 
54
53
  private:
55
- std::map<std::string, bool> seen;
56
-
57
54
  void emit(CtxPtr ctx, const std::string& outcome) {
58
55
  if (!active) return;
59
56
 
60
57
  // One record per operation (PreDone + a following PreUnexpected on a
61
58
  // failure must not double-log).
62
- if (seen.count(ctx->id) && seen[ctx->id]) return;
63
- seen[ctx->id] = true;
59
+ auto& extra = ctx->out.extra;
60
+ auto at = extra.find("audit_seen");
61
+ if (at != extra.end() && at->second.is_bool() && at->second.as_bool()) return;
62
+ extra["audit_seen"] = Value(true);
64
63
 
65
64
  seq++;
66
65
 
@@ -1,18 +1,21 @@
1
1
  // ProjectName SDK — cache feature (mirrors java feature/CacheFeature.java).
2
- // Response caching for safe (read) requests. Wraps the active transport and
3
- // serves a fresh cached snapshot instead of hitting the network when the
4
- // same method+URL was fetched within `ttl` ms (default: 5000). Only
5
- // successful (2xx) responses to cacheable methods (default: GET) are stored,
6
- // keyed by method+URL, bounded (`max`, default 256, oldest evicted first).
7
- // Bodies are snapshotted so both the current caller and later hits re-read
8
- // the JSON body repeatedly.
2
+ // Response caching for safe (read) requests, per client: see the features
3
+ // reference for the key, the write invalidation and the Cache-Control rules.
4
+ // No HMAC in std: SipHash-2-4 under a random per-client key separates header
5
+ // sets within one store without holding a header value. It is not a
6
+ // cryptographic commitment.
9
7
 
10
8
  #ifndef SDK_FEATURE_CACHE_HPP
11
9
  #define SDK_FEATURE_CACHE_HPP
12
10
 
11
+ #include <algorithm>
13
12
  #include <cctype>
13
+ #include <cstdint>
14
+ #include <cstdio>
14
15
  #include <map>
16
+ #include <random>
15
17
  #include <string>
18
+ #include <utility>
16
19
  #include <vector>
17
20
 
18
21
  #include "../core/types.hpp"
@@ -34,6 +37,46 @@ public:
34
37
 
35
38
  CacheFeature() : BaseFeature("cache", "0.0.1", true) {}
36
39
 
40
+ static uint64_t le64(const uint8_t* p) {
41
+ uint64_t v = 0;
42
+ for (int i = 7; i >= 0; i--) v = (v << 8) | p[i];
43
+ return v;
44
+ }
45
+
46
+ static uint64_t rotl(uint64_t x, int b) { return (x << b) | (x >> (64 - b)); }
47
+
48
+ static void sipround(uint64_t& v0, uint64_t& v1, uint64_t& v2, uint64_t& v3) {
49
+ v0 += v1; v1 = rotl(v1, 13); v1 ^= v0; v0 = rotl(v0, 32);
50
+ v2 += v3; v3 = rotl(v3, 16); v3 ^= v2;
51
+ v0 += v3; v3 = rotl(v3, 21); v3 ^= v0;
52
+ v2 += v1; v1 = rotl(v1, 17); v1 ^= v2; v2 = rotl(v2, 32);
53
+ }
54
+
55
+ static uint64_t siphash24(const uint8_t key[16], const std::string& in) {
56
+ const uint8_t* p = reinterpret_cast<const uint8_t*>(in.data());
57
+ size_t len = in.size();
58
+ uint64_t k0 = le64(key), k1 = le64(key + 8);
59
+ uint64_t v0 = 0x736f6d6570736575ULL ^ k0, v1 = 0x646f72616e646f6dULL ^ k1;
60
+ uint64_t v2 = 0x6c7967656e657261ULL ^ k0, v3 = 0x7465646279746573ULL ^ k1;
61
+ size_t full = len - (len % 8);
62
+ for (size_t i = 0; i < full; i += 8) {
63
+ uint64_t m = le64(p + i);
64
+ v3 ^= m;
65
+ sipround(v0, v1, v2, v3);
66
+ sipround(v0, v1, v2, v3);
67
+ v0 ^= m;
68
+ }
69
+ uint64_t b = static_cast<uint64_t>(len) << 56;
70
+ for (size_t i = 0; i < len % 8; i++) b |= static_cast<uint64_t>(p[full + i]) << (8 * i);
71
+ v3 ^= b;
72
+ sipround(v0, v1, v2, v3);
73
+ sipround(v0, v1, v2, v3);
74
+ v0 ^= b;
75
+ v2 ^= 0xff;
76
+ for (int i = 0; i < 4; i++) sipround(v0, v1, v2, v3);
77
+ return v0 ^ v1 ^ v2 ^ v3;
78
+ }
79
+
37
80
  void init(CtxPtr ctx, const Value& options_) override {
38
81
  client = ctx->client;
39
82
  options = options_;
@@ -42,6 +85,8 @@ public:
42
85
 
43
86
  store.clear();
44
87
  order.clear();
88
+ std::random_device rd;
89
+ for (auto& b : secret) b = static_cast<uint8_t>(rd() & 0xff);
45
90
 
46
91
  auto inner = ctx->utility->fetcher;
47
92
  ctx->utility->fetcher = [this, inner](CtxPtr ctx2, const std::string& url,
@@ -60,11 +105,13 @@ private:
60
105
 
61
106
  struct CacheEntry {
62
107
  long long expiry = 0;
108
+ std::string scope;
63
109
  CacheSnapshot snapshot;
64
110
  };
65
111
 
66
112
  std::map<std::string, CacheEntry> store;
67
113
  std::vector<std::string> order;
114
+ uint8_t secret[16] = {0};
68
115
 
69
116
  static std::string upper(std::string s) {
70
117
  for (auto& c : s) c = static_cast<char>(std::toupper((unsigned char)c));
@@ -91,10 +138,18 @@ private:
91
138
  }
92
139
  }
93
140
  if (!cacheable) {
141
+ if (method == "GET" || method == "HEAD") {
142
+ return inner(ctx, url, fetchdef);
143
+ }
144
+ struct Invalidate {
145
+ CacheFeature* self;
146
+ const std::string& url;
147
+ ~Invalidate() { self->invalidate(url); }
148
+ } after{this, url};
94
149
  return inner(ctx, url, fetchdef);
95
150
  }
96
151
 
97
- std::string key = method + " " + url;
152
+ std::string key = method + " " + url + " " + digest(getp(fetchdef, "headers"));
98
153
  long long now = fopt::foptNow(options)();
99
154
 
100
155
  auto it = store.find(key);
@@ -113,10 +168,16 @@ private:
113
168
 
114
169
  if (storable(res) && json(res)) {
115
170
  CacheSnapshot snap = snapshot(res);
116
- int ttl = fopt::foptInt(options, "ttl", 5000);
171
+ long long ttl = lifetime(snap.headers, fopt::foptInt(options, "ttl", 5000));
172
+ if (ttl <= 0) {
173
+ bypass++;
174
+ return replay(snap);
175
+ }
176
+ drop(key);
117
177
  evict();
118
178
  CacheEntry entry;
119
179
  entry.expiry = now + ttl;
180
+ entry.scope = urlScope(url);
120
181
  entry.snapshot = snap;
121
182
  store[key] = entry;
122
183
  order.push_back(key);
@@ -128,6 +189,124 @@ private:
128
189
  return res;
129
190
  }
130
191
 
192
+ static std::string lower(std::string s) {
193
+ for (auto& c : s) c = static_cast<char>(std::tolower((unsigned char)c));
194
+ return s;
195
+ }
196
+
197
+ static bool headerText(const Value& v, std::string& out) {
198
+ if (v.is_string()) { out = v.as_string(); return true; }
199
+ if (v.is_int()) { out = std::to_string(v.as_int()); return true; }
200
+ if (v.is_double()) {
201
+ double d = v.as_double();
202
+ char buf[64];
203
+ if (d == static_cast<double>(static_cast<long long>(d))) {
204
+ std::snprintf(buf, sizeof(buf), "%lld", static_cast<long long>(d));
205
+ } else {
206
+ std::snprintf(buf, sizeof(buf), "%g", d);
207
+ }
208
+ out = buf;
209
+ return true;
210
+ }
211
+ if (v.is_bool()) { out = v.as_bool() ? "true" : "false"; return true; }
212
+ return false;
213
+ }
214
+
215
+ std::string digest(const Value& headers) {
216
+ std::vector<std::pair<std::string, std::string>> pairs;
217
+ if (headers.is_map()) {
218
+ for (const auto& kv : *headers.as_map()) {
219
+ std::string text;
220
+ if (headerText(kv.second, text)) pairs.emplace_back(lower(kv.first), text);
221
+ }
222
+ }
223
+ std::sort(pairs.begin(), pairs.end());
224
+ std::string text;
225
+ for (const auto& p : pairs) text += p.first + ":" + p.second + "\n";
226
+ char hex[17];
227
+ std::snprintf(hex, sizeof(hex), "%016llx",
228
+ static_cast<unsigned long long>(siphash24(secret, text)));
229
+ return std::string(hex);
230
+ }
231
+
232
+ void invalidate(const std::string& url) {
233
+ std::string path = urlScope(url);
234
+ std::string collection = urlParent(path);
235
+ std::vector<std::string> dropped;
236
+ for (const auto& kv : store) {
237
+ if (under(kv.second.scope, path) || kv.second.scope == collection) dropped.push_back(kv.first);
238
+ }
239
+ for (const auto& key : dropped) drop(key);
240
+ }
241
+
242
+ void drop(const std::string& key) {
243
+ if (store.erase(key) > 0) {
244
+ order.erase(std::remove(order.begin(), order.end(), key), order.end());
245
+ }
246
+ }
247
+
248
+ static std::string trim(const std::string& s) {
249
+ size_t a = 0, b = s.size();
250
+ while (a < b && std::isspace((unsigned char)s[a])) a++;
251
+ while (b > a && std::isspace((unsigned char)s[b - 1])) b--;
252
+ return s.substr(a, b - a);
253
+ }
254
+
255
+ // The configured ttl capped by the response's Cache-Control; zero when the
256
+ // response may not be stored.
257
+ static long long lifetime(const Value& headers, long long ttl) {
258
+ std::string control;
259
+ if (headers.is_map()) {
260
+ for (const auto& kv : *headers.as_map()) {
261
+ std::string text;
262
+ if (lower(kv.first) == "cache-control" && headerText(kv.second, text)) control = lower(text);
263
+ }
264
+ }
265
+ long long life = ttl;
266
+ size_t start = 0;
267
+ while (start <= control.size()) {
268
+ size_t comma = control.find(',', start);
269
+ std::string directive = trim(control.substr(start, comma == std::string::npos ? std::string::npos : comma - start));
270
+ if (directive == "no-store" || directive == "private" || directive == "no-cache") return 0;
271
+ if (directive.rfind("max-age", 0) == 0) {
272
+ std::string value = trim(directive.substr(7));
273
+ if (!value.empty() && value[0] == '=') {
274
+ value = trim(value.substr(1));
275
+ if (value.size() >= 2 && value.front() == '"' && value.back() == '"') value = value.substr(1, value.size() - 2);
276
+ if (!value.empty() && value.size() < 16 &&
277
+ std::all_of(value.begin(), value.end(), [](char c) { return std::isdigit((unsigned char)c); })) {
278
+ life = std::min(life, std::stoll(value) * 1000);
279
+ }
280
+ }
281
+ }
282
+ if (comma == std::string::npos) break;
283
+ start = comma + 1;
284
+ }
285
+ return life;
286
+ }
287
+
288
+ static std::string urlScope(const std::string& url) {
289
+ std::string out = url.substr(0, url.find_first_of("?#"));
290
+ while (!out.empty() && out.back() == '/') out.pop_back();
291
+ return out;
292
+ }
293
+
294
+ static std::string urlParent(const std::string& scope) {
295
+ size_t root = 0;
296
+ size_t scheme = scope.find("://");
297
+ if (scheme != std::string::npos) {
298
+ root = scope.find('/', scheme + 3);
299
+ if (root == std::string::npos) return scope;
300
+ }
301
+ size_t cut = scope.rfind('/');
302
+ if (cut == std::string::npos || cut < root) cut = root;
303
+ return scope.substr(0, cut);
304
+ }
305
+
306
+ static bool under(const std::string& scope, const std::string& prefix) {
307
+ return scope == prefix || scope.rfind(prefix + "/", 0) == 0;
308
+ }
309
+
131
310
  // A body the transport could not read as JSON passes through, for the operation to report.
132
311
  bool storable(const Value& res) {
133
312
  int status = fopt::fresStatus(res);
@@ -49,6 +49,7 @@ public:
49
49
 
50
50
  Value entry = vmap();
51
51
  map_put(entry, "op", Value(entity + "." + opname));
52
+ map_put(entry, "correlationId", Value(ctx->id));
52
53
  map_put(entry, "start", Value((long long) fopt::foptNow(options)()));
53
54
  if (ctx->spec) {
54
55
  map_put(entry, "method", Value(ctx->spec->method));