@voxgig/sdkgen 4.51.0 → 4.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/ReadmeExplanation.js +5 -2
- package/dist/cmp/ReadmeExplanation.js.map +1 -1
- package/dist/cmp/ReadmeFeatures.js +20 -6
- package/dist/cmp/ReadmeFeatures.js.map +1 -1
- package/dist/helpers/optspec.js +2 -2
- package/dist/helpers/optspec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/sdkgen.aontu +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/audit.aontu +1 -1
- package/project/.sdk/model/feature/cache.aontu +1 -1
- package/project/.sdk/model/feature/clienttrack.aontu +1 -1
- package/project/.sdk/model/feature/cost.aontu +1 -1
- package/project/.sdk/model/feature/debug.aontu +1 -1
- package/project/.sdk/model/feature/idempotency.aontu +1 -1
- package/project/.sdk/model/feature/log.aontu +1 -1
- package/project/.sdk/model/feature/metrics.aontu +3 -1
- package/project/.sdk/model/feature/netsim.aontu +1 -1
- package/project/.sdk/model/feature/paging.aontu +4 -1
- package/project/.sdk/model/feature/proxy.aontu +1 -1
- package/project/.sdk/model/feature/ratelimit.aontu +3 -3
- package/project/.sdk/model/feature/rbac.aontu +1 -1
- package/project/.sdk/model/feature/retry.aontu +1 -1
- package/project/.sdk/model/feature/secrets.aontu +1 -1
- package/project/.sdk/model/feature/streaming.aontu +1 -1
- package/project/.sdk/model/feature/telemetry.aontu +2 -2
- package/project/.sdk/model/feature/test.aontu +1 -1
- package/project/.sdk/model/feature/timeout.aontu +1 -1
- package/project/.sdk/model/feature/validate.aontu +1 -1
- package/project/.sdk/src/cmp/c/TestClean_c.ts +12 -11
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +17 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +18 -1
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +2 -1
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +30 -2
- package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +31 -12
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +2 -1
- package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +51 -15
- package/project/.sdk/src/cmp/elixir/fragment/Pipeline.fragment.ex +17 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +42 -2
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +42 -14
- package/project/.sdk/src/cmp/java/TestClean_java.ts +9 -4
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +21 -0
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +13 -8
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +26 -2
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityPatchOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +8 -0
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +12 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +9 -4
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +19 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +2 -1
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +42 -5
- package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +44 -10
- package/project/.sdk/src/cmp/lua/utility_lua.ts +2 -1
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +2 -1
- package/project/.sdk/src/cmp/ocaml/fragment/RunOp.fragment.ml +36 -21
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +1 -1
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +21 -0
- package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +31 -12
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +33 -4
- package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +13 -6
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +25 -2
- package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +26 -12
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +1 -1
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +23 -2
- package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +27 -11
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +14 -17
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +22 -2
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +11 -11
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +14 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +11 -11
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +9 -0
- package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +24 -10
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +13 -8
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +26 -2
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityPatchOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +8 -0
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +12 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +11 -11
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +17 -10
- package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +41 -6
- package/project/.sdk/tm/c/feature/metrics.c +7 -0
- package/project/.sdk/tm/c/feature/paging.c +231 -2
- package/project/.sdk/tm/c/feature/ratelimit.c +5 -9
- package/project/.sdk/tm/c/feature/retry.c +51 -4
- package/project/.sdk/tm/c/feature/streaming.c +2 -1
- package/project/.sdk/tm/c/feature/telemetry.c +19 -18
- package/project/.sdk/tm/c/feature/test.c +78 -54
- package/project/.sdk/tm/c/tests/feature_test.c +184 -0
- package/project/.sdk/tm/c/tests/primary_utility_test.c +2 -0
- package/project/.sdk/tm/c/utility/make_options.c +80 -9
- package/project/.sdk/tm/clojure/src/sdk/core.clj +31 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +198 -70
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +70 -1
- package/project/.sdk/tm/cpp/core/types.hpp +137 -68
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -1
- package/project/.sdk/tm/cpp/feature/metrics.hpp +19 -0
- package/project/.sdk/tm/cpp/feature/paging.hpp +160 -2
- package/project/.sdk/tm/cpp/feature/ratelimit.hpp +18 -14
- package/project/.sdk/tm/cpp/feature/retry.hpp +46 -5
- package/project/.sdk/tm/cpp/feature/streaming.hpp +2 -1
- package/project/.sdk/tm/cpp/feature/telemetry.hpp +17 -10
- package/project/.sdk/tm/cpp/feature/test.hpp +63 -53
- package/project/.sdk/tm/cpp/test/feature_test.cpp +137 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +35 -5
- package/project/.sdk/tm/csharp/feature/AuditFeature.cs +8 -1
- package/project/.sdk/tm/csharp/feature/MetricsFeature.cs +23 -0
- package/project/.sdk/tm/csharp/feature/PagingFeature.cs +130 -3
- package/project/.sdk/tm/csharp/feature/RatelimitFeature.cs +26 -19
- package/project/.sdk/tm/csharp/feature/RetryFeature.cs +41 -7
- package/project/.sdk/tm/csharp/feature/StreamingFeature.cs +2 -1
- package/project/.sdk/tm/csharp/feature/TelemetryFeature.cs +11 -9
- package/project/.sdk/tm/csharp/feature/TestFeature.cs +55 -67
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +162 -0
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +89 -12
- package/project/.sdk/tm/elixir/lib/projectname/feature/metrics.ex +13 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/paging.ex +110 -5
- package/project/.sdk/tm/elixir/lib/projectname/feature/ratelimit.ex +6 -12
- package/project/.sdk/tm/elixir/lib/projectname/feature/retry.ex +33 -9
- package/project/.sdk/tm/elixir/lib/projectname/feature/streaming.ex +2 -1
- package/project/.sdk/tm/elixir/lib/projectname/feature/telemetry.ex +7 -7
- package/project/.sdk/tm/elixir/lib/projectname/feature/test.ex +52 -48
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +59 -35
- package/project/.sdk/tm/elixir/test/feature_test.exs +137 -0
- package/project/.sdk/tm/go/feature/audit_feature.go +1 -3
- package/project/.sdk/tm/go/feature/base_feature.go +11 -0
- package/project/.sdk/tm/go/feature/metrics_feature.go +14 -0
- package/project/.sdk/tm/go/feature/paging_feature.go +108 -2
- package/project/.sdk/tm/go/feature/ratelimit_feature.go +19 -17
- package/project/.sdk/tm/go/feature/retry_feature.go +81 -9
- package/project/.sdk/tm/go/feature/streaming_feature.go +2 -1
- package/project/.sdk/tm/go/feature/telemetry_feature.go +18 -11
- package/project/.sdk/tm/go/feature/test_feature.go +65 -55
- package/project/.sdk/tm/go/test/feature_corpus_test.go +209 -28
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/make_options.go +111 -6
- package/project/.sdk/tm/java/core/SdkClient.java +43 -14
- package/project/.sdk/tm/java/feature/AuditFeature.java +5 -1
- package/project/.sdk/tm/java/feature/MetricsFeature.java +31 -0
- package/project/.sdk/tm/java/feature/PagingFeature.java +156 -2
- package/project/.sdk/tm/java/feature/RatelimitFeature.java +15 -13
- package/project/.sdk/tm/java/feature/RetryFeature.java +33 -6
- package/project/.sdk/tm/java/feature/StreamingFeature.java +2 -1
- package/project/.sdk/tm/java/feature/TelemetryFeature.java +17 -9
- package/project/.sdk/tm/java/feature/TestFeature.java +50 -63
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +170 -17
- package/project/.sdk/tm/java/utility/MakeOptions.java +128 -14
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +8 -3
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +99 -1
- package/project/.sdk/tm/js/src/feature/ratelimit/RatelimitFeature.js +5 -9
- package/project/.sdk/tm/js/src/feature/retry/RetryFeature.js +25 -3
- package/project/.sdk/tm/js/src/feature/streaming/StreamingFeature.js +2 -1
- package/project/.sdk/tm/js/src/feature/telemetry/TelemetryFeature.js +11 -6
- package/project/.sdk/tm/js/src/feature/test/TestFeature.js +38 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +55 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +95 -25
- package/project/.sdk/tm/js/test/feature.test.js +14 -1
- package/project/.sdk/tm/kotlin/core/SdkClient.kt +23 -10
- package/project/.sdk/tm/kotlin/feature/AuditFeature.kt +5 -1
- package/project/.sdk/tm/kotlin/feature/MetricsFeature.kt +22 -0
- package/project/.sdk/tm/kotlin/feature/PagingFeature.kt +125 -2
- package/project/.sdk/tm/kotlin/feature/RatelimitFeature.kt +16 -13
- package/project/.sdk/tm/kotlin/feature/RetryFeature.kt +36 -14
- package/project/.sdk/tm/kotlin/feature/StreamingFeature.kt +4 -0
- package/project/.sdk/tm/kotlin/feature/TelemetryFeature.kt +12 -10
- package/project/.sdk/tm/kotlin/feature/TestFeature.kt +45 -48
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +114 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +83 -14
- package/project/.sdk/tm/lua/feature/debug_feature.lua +2 -3
- package/project/.sdk/tm/lua/feature/metrics_feature.lua +5 -0
- package/project/.sdk/tm/lua/feature/paging_feature.lua +143 -2
- package/project/.sdk/tm/lua/feature/ratelimit_feature.lua +5 -9
- package/project/.sdk/tm/lua/feature/retry_feature.lua +43 -5
- package/project/.sdk/tm/lua/feature/streaming_feature.lua +2 -1
- package/project/.sdk/tm/lua/feature/telemetry_feature.lua +18 -7
- package/project/.sdk/tm/lua/feature/test_feature.lua +60 -62
- package/project/.sdk/tm/lua/test/feature_test.lua +100 -3
- package/project/.sdk/tm/lua/utility/make_options.lua +55 -13
- package/project/.sdk/tm/ocaml/sdk_features.ml +286 -60
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +34 -11
- package/project/.sdk/tm/ocaml/test/t_feature.ml +72 -1
- package/project/.sdk/tm/perl/feature/debug_feature.pm +2 -2
- package/project/.sdk/tm/perl/feature/metrics_feature.pm +5 -0
- package/project/.sdk/tm/perl/feature/paging_feature.pm +139 -2
- package/project/.sdk/tm/perl/feature/ratelimit_feature.pm +5 -11
- package/project/.sdk/tm/perl/feature/retry_feature.pm +22 -4
- package/project/.sdk/tm/perl/feature/streaming_feature.pm +2 -0
- package/project/.sdk/tm/perl/feature/telemetry_feature.pm +17 -8
- package/project/.sdk/tm/perl/feature/test_feature.pm +45 -50
- package/project/.sdk/tm/perl/t/feature.t +2 -2
- package/project/.sdk/tm/perl/t/feature_corpus.t +126 -23
- package/project/.sdk/tm/perl/utility/make_options.pm +33 -10
- package/project/.sdk/tm/php/feature/MetricsFeature.php +8 -0
- package/project/.sdk/tm/php/feature/PagingFeature.php +128 -1
- package/project/.sdk/tm/php/feature/RatelimitFeature.php +5 -9
- package/project/.sdk/tm/php/feature/RetryFeature.php +27 -3
- package/project/.sdk/tm/php/feature/StreamingFeature.php +2 -1
- package/project/.sdk/tm/php/feature/TelemetryFeature.php +10 -7
- package/project/.sdk/tm/php/feature/TestFeature.php +55 -47
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +151 -16
- package/project/.sdk/tm/php/utility/MakeOptions.php +40 -13
- package/project/.sdk/tm/py/pkg/feature/metrics_feature.py +7 -0
- package/project/.sdk/tm/py/pkg/feature/paging_feature.py +86 -1
- package/project/.sdk/tm/py/pkg/feature/ratelimit_feature.py +13 -16
- package/project/.sdk/tm/py/pkg/feature/retry_feature.py +31 -6
- package/project/.sdk/tm/py/pkg/feature/streaming_feature.py +2 -1
- package/project/.sdk/tm/py/pkg/feature/telemetry_feature.py +10 -6
- package/project/.sdk/tm/py/pkg/feature/test_feature.py +56 -53
- package/project/.sdk/tm/py/pkg/utility/make_options.py +68 -20
- package/project/.sdk/tm/py/test/test_feature.py +11 -1
- package/project/.sdk/tm/py/test/test_feature_corpus.py +111 -16
- package/project/.sdk/tm/py-data/pkg/fetch.py +6 -3
- package/project/.sdk/tm/py-data/test/test_fetch.py +7 -4
- package/project/.sdk/tm/rb/feature/debug_feature.rb +2 -2
- package/project/.sdk/tm/rb/feature/metrics_feature.rb +8 -0
- package/project/.sdk/tm/rb/feature/paging_feature.rb +87 -1
- package/project/.sdk/tm/rb/feature/ratelimit_feature.rb +12 -16
- package/project/.sdk/tm/rb/feature/retry_feature.rb +19 -3
- package/project/.sdk/tm/rb/feature/streaming_feature.rb +2 -1
- package/project/.sdk/tm/rb/feature/telemetry_feature.rb +11 -6
- package/project/.sdk/tm/rb/feature/test_feature.rb +42 -49
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +108 -24
- package/project/.sdk/tm/rb/test/feature_test.rb +1 -1
- package/project/.sdk/tm/rb/utility/make_options.rb +32 -11
- package/project/.sdk/tm/rust/feature/audit.rs +2 -2
- package/project/.sdk/tm/rust/feature/metrics.rs +24 -1
- package/project/.sdk/tm/rust/feature/paging.rs +189 -3
- package/project/.sdk/tm/rust/feature/ratelimit.rs +5 -10
- package/project/.sdk/tm/rust/feature/retry.rs +59 -6
- package/project/.sdk/tm/rust/feature/streaming.rs +3 -2
- package/project/.sdk/tm/rust/feature/support.rs +4 -0
- package/project/.sdk/tm/rust/feature/telemetry.rs +22 -11
- package/project/.sdk/tm/rust/feature/test.rs +63 -57
- package/project/.sdk/tm/rust/tests/feature_test.rs +174 -0
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +1 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +122 -27
- package/project/.sdk/tm/scala/core/SdkClient.scala +45 -11
- package/project/.sdk/tm/scala/feature/AuditFeature.scala +6 -1
- package/project/.sdk/tm/scala/feature/MetricsFeature.scala +31 -1
- package/project/.sdk/tm/scala/feature/PagingFeature.scala +122 -2
- package/project/.sdk/tm/scala/feature/RatelimitFeature.scala +14 -11
- package/project/.sdk/tm/scala/feature/RetryFeature.scala +29 -7
- package/project/.sdk/tm/scala/feature/StreamingFeature.scala +2 -1
- package/project/.sdk/tm/scala/feature/TelemetryFeature.scala +12 -10
- package/project/.sdk/tm/scala/feature/TestFeature.scala +44 -44
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +41 -0
- package/project/.sdk/tm/scala/utility/Make.scala +96 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/AuditFeature.swift +3 -2
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/MetricsFeature.swift +20 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/PagingFeature.swift +102 -2
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RatelimitFeature.swift +19 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/RetryFeature.swift +40 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/StreamingFeature.swift +2 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TelemetryFeature.swift +11 -9
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/TestFeature.swift +55 -49
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +51 -13
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +111 -0
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +5 -0
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +99 -1
- package/project/.sdk/tm/ts/src/feature/ratelimit/RatelimitFeature.ts +5 -9
- package/project/.sdk/tm/ts/src/feature/retry/RetryFeature.ts +25 -3
- package/project/.sdk/tm/ts/src/feature/streaming/StreamingFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/feature/telemetry/TelemetryFeature.ts +11 -6
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +8 -7
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +57 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +95 -25
- package/project/.sdk/tm/ts/test/feature.test.ts +14 -1
- package/project/.sdk/tm/zig/core/utility.zig +107 -8
- package/project/.sdk/tm/zig/feature/metrics.zig +19 -0
- package/project/.sdk/tm/zig/feature/paging.zig +172 -4
- package/project/.sdk/tm/zig/feature/ratelimit.zig +5 -11
- package/project/.sdk/tm/zig/feature/retry.zig +41 -3
- package/project/.sdk/tm/zig/feature/streaming.zig +2 -0
- package/project/.sdk/tm/zig/feature/telemetry.zig +15 -9
- package/project/.sdk/tm/zig/feature/test.zig +56 -40
- package/project/.sdk/tm/zig/test/feature_test.zig +109 -0
- package/project/.sdk/tm/zig/test/primary_utility_test.zig +2 -0
- package/project/sdkgen-package.json +1 -1
- package/src/cmp/ReadmeExplanation.ts +5 -2
- package/src/cmp/ReadmeFeatures.ts +21 -6
- package/src/helpers/optspec.ts +2 -2
|
@@ -30,25 +30,28 @@ class RatelimitFeature extends BaseFeature("ratelimit", "0.0.1", true) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
private def acquire(): Unit = {
|
|
33
|
+
val wait = reserve()
|
|
34
|
+
if (wait > 0) FeatureOptions.foptSleep(this.options).accept(wait)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Refill, then reserve this call's token before any wait, under the lock:
|
|
38
|
+
// a negative count is the calls already queued, so overlapping calls pace
|
|
39
|
+
// in turn.
|
|
40
|
+
private def reserve(): Int = this.synchronized {
|
|
33
41
|
val rate = FeatureOptions.foptNum(this.options, "rate", 5)
|
|
34
42
|
val burst = FeatureOptions.foptNum(this.options, "burst", rate)
|
|
35
43
|
|
|
36
44
|
val now = FeatureOptions.foptNow(this.options).getAsLong()
|
|
37
45
|
val elapsed = now - this.last
|
|
38
46
|
this.last = now
|
|
39
|
-
this.tokens = Math.min(burst, this.tokens + (elapsed / 1000.0) * rate)
|
|
47
|
+
this.tokens = Math.min(burst, this.tokens + (elapsed / 1000.0) * rate) - 1
|
|
40
48
|
|
|
41
|
-
if (this.tokens >=
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
if (this.tokens >= 0) 0
|
|
50
|
+
else {
|
|
51
|
+
val wait = Math.ceil((-this.tokens / rate) * 1000).toInt
|
|
52
|
+
track(wait)
|
|
53
|
+
wait
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
val needed = 1 - this.tokens
|
|
47
|
-
val wait = Math.ceil((needed / rate) * 1000).toInt
|
|
48
|
-
track(wait)
|
|
49
|
-
if (wait > 0) FeatureOptions.foptSleep(this.options).accept(wait)
|
|
50
|
-
this.last = FeatureOptions.foptNow(this.options).getAsLong()
|
|
51
|
-
this.tokens = 0
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
private def track(wait: Int): Unit = {
|
|
@@ -78,13 +78,8 @@ class RetryFeature extends BaseFeature("retry", "0.0.1", true) {
|
|
|
78
78
|
Math.min(wait, maxDelay)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
private def retryAfter(res: Object): Int =
|
|
82
|
-
|
|
83
|
-
if ("" == v) return -1
|
|
84
|
-
val seconds = FeatureOptions.fparseInt(v, -1)
|
|
85
|
-
if (seconds < 0) return -1
|
|
86
|
-
seconds * 1000
|
|
87
|
-
}
|
|
81
|
+
private def retryAfter(res: Object): Int =
|
|
82
|
+
RetryFeature.retryAfterMs(FeatureOptions.fresHeader(res, "retry-after"), System.currentTimeMillis())
|
|
88
83
|
|
|
89
84
|
private def sleep(ms: Int): Unit = {
|
|
90
85
|
if (ms <= 0) return
|
|
@@ -102,3 +97,30 @@ class RetryFeature extends BaseFeature("retry", "0.0.1", true) {
|
|
|
102
97
|
this.retries.add(entry)
|
|
103
98
|
}
|
|
104
99
|
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
object RetryFeature {
|
|
103
|
+
private val Months = "JanFebMarAprMayJunJulAugSepOctNovDec"
|
|
104
|
+
|
|
105
|
+
private val ImfFixdate =
|
|
106
|
+
"(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-9]{2}) ([A-Z][a-z]{2}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) GMT".r
|
|
107
|
+
|
|
108
|
+
// RFC 9110 Retry-After: delay-seconds or an IMF-fixdate, else -1.
|
|
109
|
+
def retryAfterMs(value: String, now: Long): Int = {
|
|
110
|
+
val s = value.replaceAll("^[ \\t]+|[ \\t]+$", "")
|
|
111
|
+
if (s.nonEmpty && s.forall(c => c >= '0' && c <= '9')) {
|
|
112
|
+
if (s.length > 6) Int.MaxValue else s.toInt * 1000
|
|
113
|
+
}
|
|
114
|
+
else s match {
|
|
115
|
+
case ImfFixdate(day, mon, year, hour, min, sec) if Months.indexOf(mon) % 3 == 0 =>
|
|
116
|
+
try {
|
|
117
|
+
val at = java.time.LocalDateTime.of(year.toInt, Months.indexOf(mon) / 3 + 1, day.toInt,
|
|
118
|
+
hour.toInt, min.toInt, Math.min(sec.toInt, 59))
|
|
119
|
+
.toEpochSecond(java.time.ZoneOffset.UTC) * 1000 + (if (sec.toInt > 59) 1000 else 0)
|
|
120
|
+
Math.min(Int.MaxValue.toLong, Math.max(0L, at - now)).toInt
|
|
121
|
+
}
|
|
122
|
+
catch { case _: java.time.DateTimeException => -1 }
|
|
123
|
+
case _ => -1
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -27,8 +27,9 @@ class StreamingFeature extends BaseFeature("streaming", "0.0.1", true) {
|
|
|
27
27
|
if (!this.active || !streamable(ctx)) {
|
|
28
28
|
return
|
|
29
29
|
}
|
|
30
|
+
// A failed result keeps no stream, so the entity's stream raises its error.
|
|
30
31
|
val result = ctx.result
|
|
31
|
-
if (result == null) {
|
|
32
|
+
if (result == null || result.err != null) {
|
|
32
33
|
return
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -15,7 +15,6 @@ class TelemetryFeature extends BaseFeature("telemetry", "0.0.1", true) {
|
|
|
15
15
|
|
|
16
16
|
private var client: SdkClient = null
|
|
17
17
|
private var options: JMap[String, Object] = null
|
|
18
|
-
private var seq: Int = 0
|
|
19
18
|
|
|
20
19
|
// Activity tracking (mirrors the ts client._telemetry record).
|
|
21
20
|
var spans: JList[JMap[String, Object]] = new ArrayList[JMap[String, Object]]()
|
|
@@ -27,7 +26,6 @@ class TelemetryFeature extends BaseFeature("telemetry", "0.0.1", true) {
|
|
|
27
26
|
this.client = ctx.client
|
|
28
27
|
this.options = options
|
|
29
28
|
this.active = FeatureOptions.foptBool(options, "active", false)
|
|
30
|
-
this.seq = 0
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
override def prePoint(ctx: Context): Unit = {
|
|
@@ -125,13 +123,17 @@ class TelemetryFeature extends BaseFeature("telemetry", "0.0.1", true) {
|
|
|
125
123
|
return f.asInstanceOf[java.util.function.Function[String, String]].apply(kind)
|
|
126
124
|
case _ =>
|
|
127
125
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
126
|
+
TelemetryFeature.randomHex(if ("trace".equals(kind)) 16 else 8)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
object TelemetryFeature {
|
|
131
|
+
private val RANDOM = new java.security.SecureRandom()
|
|
132
|
+
|
|
133
|
+
// W3C trace context: lowercase hex from the platform's random source, never all zeros.
|
|
134
|
+
def randomHex(bytes: Int): String = {
|
|
135
|
+
val buf = new Array[Byte](bytes)
|
|
136
|
+
while ({ RANDOM.nextBytes(buf); buf.forall(_ == 0) }) ()
|
|
137
|
+
buf.map(b => "%02x".format(b & 0xff)).mkString
|
|
136
138
|
}
|
|
137
139
|
}
|
|
@@ -127,23 +127,9 @@ class TestFeature extends BaseFeature("test", "0.0.1", true) {
|
|
|
127
127
|
out
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
private def
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
var i = 0
|
|
134
|
-
while (i < srcs.length) {
|
|
135
|
-
val src = srcs(i)
|
|
136
|
-
if (src != null) {
|
|
137
|
-
val v = Struct.getprop(src, "id", null)
|
|
138
|
-
if (v != null && !("__UNDEFINED__" == v)) {
|
|
139
|
-
val out = new LinkedHashMap[String, Object]()
|
|
140
|
-
out.put("id", v)
|
|
141
|
-
return out
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
i += 1
|
|
145
|
-
}
|
|
146
|
-
new LinkedHashMap[String, Object]()
|
|
130
|
+
private def held(src: JMap[String, Object], key: String): Boolean = {
|
|
131
|
+
val v = if (src == null) null else Struct.getprop(src, key, null)
|
|
132
|
+
v != null && !("__UNDEFINED__" == v)
|
|
147
133
|
}
|
|
148
134
|
|
|
149
135
|
private def serve(ctx: Context, entity: JMap[String, Object]): Object = {
|
|
@@ -152,7 +138,7 @@ class TestFeature extends BaseFeature("test", "0.0.1", true) {
|
|
|
152
138
|
if (entmap == null) entmap = new LinkedHashMap[String, Object]()
|
|
153
139
|
|
|
154
140
|
if ("load" == op.name) {
|
|
155
|
-
val args = buildArgs(ctx, op,
|
|
141
|
+
val args = buildArgs(ctx, op, ctx.reqmatch)
|
|
156
142
|
val found = Struct.select(entmap, args)
|
|
157
143
|
val ent = Struct.getelem(found, java.lang.Integer.valueOf(0), null)
|
|
158
144
|
if (ent == null) return respond(ctx, 404, null, extra("statusText", "Not found"))
|
|
@@ -168,18 +154,7 @@ class TestFeature extends BaseFeature("test", "0.0.1", true) {
|
|
|
168
154
|
val out = Struct.clone(found)
|
|
169
155
|
respond(ctx, 200, out, null)
|
|
170
156
|
} else if ("update" == op.name || "patch" == op.name) {
|
|
171
|
-
|
|
172
|
-
if (ctx.reqdata != null) {
|
|
173
|
-
if (ctx.reqdata.containsKey("id")) updateMatch.put("id", ctx.reqdata.get("id"))
|
|
174
|
-
if (op.alias != null) {
|
|
175
|
-
Struct.getprop(op.alias, "id") match {
|
|
176
|
-
case aliasId: String if ctx.reqdata.containsKey(aliasId) => updateMatch.put(aliasId, ctx.reqdata.get(aliasId))
|
|
177
|
-
case _ =>
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
if (updateMatch.isEmpty) updateMatch = resolveMatch(ctx, new LinkedHashMap[String, Object]()).asInstanceOf[LinkedHashMap[String, Object]]
|
|
182
|
-
val args = buildArgs(ctx, op, updateMatch)
|
|
157
|
+
val args = buildArgs(ctx, op, record(ctx.reqdata))
|
|
183
158
|
val found = Struct.select(entmap, args)
|
|
184
159
|
val ent = Struct.getelem(found, java.lang.Integer.valueOf(0), null)
|
|
185
160
|
// update miss: 404, never another record
|
|
@@ -189,7 +164,7 @@ class TestFeature extends BaseFeature("test", "0.0.1", true) {
|
|
|
189
164
|
val out = Struct.clone(ent)
|
|
190
165
|
respond(ctx, 200, out, null)
|
|
191
166
|
} else if ("remove" == op.name) {
|
|
192
|
-
val args = buildArgs(ctx, op,
|
|
167
|
+
val args = buildArgs(ctx, op, ctx.reqmatch)
|
|
193
168
|
val found = Struct.select(entmap, args)
|
|
194
169
|
val ent = Struct.getelem(found, java.lang.Integer.valueOf(0), null)
|
|
195
170
|
ent match {
|
|
@@ -332,23 +307,48 @@ class TestFeature extends BaseFeature("test", "0.0.1", true) {
|
|
|
332
307
|
val qand = Struct.jt()
|
|
333
308
|
val q = Struct.jm("`$AND`", qand)
|
|
334
309
|
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
while (kit.hasNext) {
|
|
338
|
-
val key = kit.next()
|
|
339
|
-
val isId = "id" == key
|
|
340
|
-
val selected = Struct.select(reqd, key)
|
|
341
|
-
val isReqd = !Struct.isempty(selected)
|
|
310
|
+
val entityName = if (ctx.entity == null) "" else ctx.entity.getName()
|
|
311
|
+
val idfrom = Struct.getpath(ctx.config, java.util.List.of("entity", entityName, "id", "from"))
|
|
342
312
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
val ka = Struct.getprop(op.alias, key)
|
|
313
|
+
val names = new java.util.ArrayList[String]()
|
|
314
|
+
if (args != null) names.addAll(Struct.keysof(args))
|
|
346
315
|
|
|
347
|
-
|
|
348
|
-
|
|
316
|
+
// With no id in the call, the entity's held id (or composite parts) stands in.
|
|
317
|
+
if (args == null || args.get("id") == null) {
|
|
318
|
+
val parts: JList[Object] = Struct.getpath(ctx.config, java.util.List.of("entity", entityName, "id", "parts")) match {
|
|
319
|
+
case l: JList[?] => l.asInstanceOf[JList[Object]]
|
|
320
|
+
case _ => if ("list" == opname) java.util.List.of() else java.util.List.of("id")
|
|
321
|
+
}
|
|
322
|
+
val pit = parts.iterator()
|
|
323
|
+
while (pit.hasNext) {
|
|
324
|
+
val pname = String.valueOf(pit.next())
|
|
325
|
+
if (!names.contains(pname) && (held(ctx.matchData, pname) || held(ctx.data, pname))) names.add(pname)
|
|
326
|
+
}
|
|
327
|
+
}
|
|
349
328
|
|
|
350
|
-
|
|
329
|
+
val kit = names.iterator()
|
|
330
|
+
while (kit.hasNext) {
|
|
331
|
+
val key = kit.next()
|
|
332
|
+
val isId = "id" == key
|
|
333
|
+
val selected = Struct.select(reqd, key)
|
|
334
|
+
val isReqd = !Struct.isempty(selected)
|
|
335
|
+
|
|
336
|
+
if (isId || isReqd) {
|
|
337
|
+
val v = ctx.utility.param(ctx, key)
|
|
338
|
+
val ka = Struct.getprop(op.alias, key)
|
|
339
|
+
|
|
340
|
+
val qor = Struct.jt(Struct.jm(key, v))
|
|
341
|
+
ka match { case s: String => qor.add(Struct.jm(s, v)); case _ => }
|
|
342
|
+
|
|
343
|
+
// An alternative, never a replacement: a seed keeping the parameter
|
|
344
|
+
// flat is still found.
|
|
345
|
+
Struct.getprop(idfrom, key) match {
|
|
346
|
+
case kf: String if kf != key =>
|
|
347
|
+
qor.add(kf.split("\\.").foldRight(v)((seg, acc) => Struct.jm(seg, acc)))
|
|
348
|
+
case _ =>
|
|
351
349
|
}
|
|
350
|
+
|
|
351
|
+
qand.add(Struct.jm("`$OR`", qor))
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
354
|
|
|
@@ -631,6 +631,36 @@ object SdkTestMain {
|
|
|
631
631
|
{ val rec = new FhRecorder()
|
|
632
632
|
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(new PagingFeature(), om("active" -> B(false))))
|
|
633
633
|
h.op(fhOp("list").withPath("/w")); check("paging.inactive", !rec.url(0).contains("page="), "url=" + rec.url(0)) }
|
|
634
|
+
|
|
635
|
+
// The documented hasMore loop, one request per page.
|
|
636
|
+
def walk(name: String, reply: Int => JMap[String, Object], want: Seq[String],
|
|
637
|
+
options: JMap[String, Object] = null): JMap[String, Object] = {
|
|
638
|
+
val rec = new FhRecorder()
|
|
639
|
+
rec.reply = (n, fd) => reply(n.intValue)
|
|
640
|
+
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(new PagingFeature(), options))
|
|
641
|
+
val paging = om()
|
|
642
|
+
val ctrl = om("paging" -> paging)
|
|
643
|
+
h.op(fhOp("list").withPath("/w").withCtrl(ctrl))
|
|
644
|
+
while (B(true) == paging.get("hasMore") && rec.calls.size < 4) h.op(fhOp("list").withPath("/w").withCtrl(ctrl))
|
|
645
|
+
val urls = (0 until rec.calls.size).map(rec.url)
|
|
646
|
+
check(name, urls == want, "urls=" + urls.mkString(" | "))
|
|
647
|
+
eq(name + ".end", B(false), paging.get("hasMore"))
|
|
648
|
+
paging
|
|
649
|
+
}
|
|
650
|
+
walk("paging.bodyNextCursor", n => fhResponse(200, if (n <= 2) om("next" -> Seq("c3", "c6")(n - 1)) else om(), null),
|
|
651
|
+
Seq("http://api.test/w?page=1", "http://api.test/w?cursor=c3", "http://api.test/w?cursor=c6"))
|
|
652
|
+
walk("paging.bodyNextUrl", n => fhResponse(200,
|
|
653
|
+
if (n <= 2) om("next" -> Seq("http://api.test/v2/w?cursor=c%2F3&limit=3", "/v2/w?cursor=c6")(n - 1)) else om(), null),
|
|
654
|
+
Seq("http://api.test/w?page=1", "http://api.test/v2/w?cursor=c%2F3&limit=3", "http://api.test/v2/w?cursor=c6"))
|
|
655
|
+
walk("paging.linkNextUrl", n => fhResponse(200, jl(),
|
|
656
|
+
if (n <= 2) om("link" -> Seq("<http://api.test/w?after=b3>; rel=\"next\"", "</w?after=b6>; rel=\"next\"")(n - 1)) else null),
|
|
657
|
+
Seq("http://api.test/w?page=1", "http://api.test/w?after=b3", "http://api.test/w?after=b6"))
|
|
658
|
+
val foreign = walk("paging.foreignLink", n => fhResponse(200, jl(),
|
|
659
|
+
om("link" -> "<https://elsewhere.test/w?after=b3>; rel=\"next\"")),
|
|
660
|
+
Seq("http://api.test/w?page=1"))
|
|
661
|
+
eq("paging.foreignLink.kept", "https://elsewhere.test/w?after=b3", foreign.get("foreign"))
|
|
662
|
+
walk("paging.cursorMode", n => fhResponse(200, if (n == 1) om("next" -> "/c3") else om(), null),
|
|
663
|
+
Seq("http://api.test/w?page=1", "http://api.test/w?cursor=%2Fc3"), om("next" -> "cursor"))
|
|
634
664
|
}
|
|
635
665
|
|
|
636
666
|
private def testStreaming(): Unit = {
|
|
@@ -653,6 +683,17 @@ object SdkTestMain {
|
|
|
653
683
|
{ val f = new StreamingFeature()
|
|
654
684
|
val h = fhMake(null, fhF(f, om("active" -> B(false))))
|
|
655
685
|
val r = h.op(fhOp("list").withPath("/w")); check("streaming.inactive.nostream", !r.result.streaming, "inactive must not attach"); eqI("streaming.inactive.opened", 0, f.opened) }
|
|
686
|
+
{ val rec = new FhRecorder(); val f = new StreamingFeature()
|
|
687
|
+
rec.reply = (n, fd) => fhResponse(503, jl(), null)
|
|
688
|
+
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(f, null))
|
|
689
|
+
val r = h.op(fhOp("list").withPath("/w"))
|
|
690
|
+
check("streaming.failed.nostream", !r.result.streaming && r.result.stream == null, "a failed result must keep no stream")
|
|
691
|
+
eqI("streaming.failed.opened", 0, f.opened) }
|
|
692
|
+
{ val rec = new FhRecorder()
|
|
693
|
+
rec.reply = (n, fd) => fhResponse(200, jl(), null)
|
|
694
|
+
val h = fhMake((c, u, fd) => rec.fetch(c, u, fd), fhF(new StreamingFeature(), null))
|
|
695
|
+
val r = h.op(fhOp("list").withPath("/w"))
|
|
696
|
+
check("streaming.empty", r.result.stream != null && !r.result.stream.get().hasNext, "an empty list streams nothing") }
|
|
656
697
|
}
|
|
657
698
|
|
|
658
699
|
private def testProxy(): Unit = {
|
|
@@ -375,6 +375,9 @@ object MakeOptions {
|
|
|
375
375
|
case _ =>
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
val fdefaults = featureDefaults(config.get("feature"), opts.get("feature"))
|
|
379
|
+
if (fdefaults != null) opts.put("feature", fdefaults)
|
|
380
|
+
|
|
378
381
|
// THE OPTION SPEC IS GENERATED, NOT WRITTEN HERE.
|
|
379
382
|
//
|
|
380
383
|
// Built from the model: `main.kit.optspec` for the standard options, plus
|
|
@@ -401,19 +404,18 @@ object MakeOptions {
|
|
|
401
404
|
mergeList.add(Struct.clone(cfgopts))
|
|
402
405
|
mergeList.add(opts)
|
|
403
406
|
val merged = Struct.merge(mergeList)
|
|
407
|
+
val callbacks = holdCallbacks(merged, optspec)
|
|
404
408
|
|
|
405
|
-
//
|
|
406
|
-
val vopts = new LinkedHashMap[String, Object]()
|
|
407
|
-
vopts.put("errs", new ArrayList[Object]())
|
|
409
|
+
// A rejection quotes the value it rejected.
|
|
408
410
|
val validated =
|
|
409
|
-
try Struct.validate(merged, optspec
|
|
411
|
+
try Struct.validate(merged, optspec)
|
|
410
412
|
catch {
|
|
411
|
-
// A rejection quotes the value it rejected.
|
|
412
413
|
case err: RuntimeException =>
|
|
413
414
|
val text = if (err.getMessage == null) String.valueOf(err) else err.getMessage
|
|
414
415
|
throw new SdkError("options_invalid", Clean.cleanWith(cleancfg, text).asInstanceOf[String], ctx)
|
|
415
416
|
}
|
|
416
417
|
opts = validated.asInstanceOf[JMap[String, Object]]
|
|
418
|
+
restoreCallbacks(opts, callbacks)
|
|
417
419
|
|
|
418
420
|
// Restore the suppression the optspec default would otherwise erase.
|
|
419
421
|
if (authSuppressed) opts.put("auth", null)
|
|
@@ -457,21 +459,30 @@ object MakeOptions {
|
|
|
457
459
|
case _ =>
|
|
458
460
|
}
|
|
459
461
|
|
|
460
|
-
// Resolve the feature add-order: an explicit list order (above) wins
|
|
461
|
-
//
|
|
462
|
-
//
|
|
463
|
-
|
|
462
|
+
// Resolve the feature add-order: an explicit list order (above) wins, and
|
|
463
|
+
// the names it leaves out follow it test-first, then sorted, so the outcome
|
|
464
|
+
// is deterministic and `test` is the base transport of a map.
|
|
465
|
+
{
|
|
464
466
|
val fmap = Helpers.toMapAny(opts.get("feature"))
|
|
465
467
|
val names = new ArrayList[String]()
|
|
466
|
-
if (fmap != null)
|
|
468
|
+
if (fmap != null) fmap.keySet().forEach(n => if (!featureorder.contains(n)) names.add(n))
|
|
467
469
|
java.util.Collections.sort(names)
|
|
470
|
+
val rest = new ArrayList[Object]()
|
|
468
471
|
if (names.contains("test")) {
|
|
469
|
-
|
|
472
|
+
rest.add("test")
|
|
470
473
|
val nit = names.iterator()
|
|
471
|
-
while (nit.hasNext) { val n = nit.next(); if ("test" != n)
|
|
474
|
+
while (nit.hasNext) { val n = nit.next(); if ("test" != n) rest.add(n) }
|
|
472
475
|
} else {
|
|
473
|
-
|
|
476
|
+
rest.addAll(names)
|
|
477
|
+
}
|
|
478
|
+
// Station's transport wrap sits just outside the base transport, so a
|
|
479
|
+
// map-form activation hoists it to just after test, or first.
|
|
480
|
+
val si = rest.indexOf("station")
|
|
481
|
+
if (0 <= si) {
|
|
482
|
+
rest.remove(si)
|
|
483
|
+
rest.add(rest.indexOf("test") + 1, "station")
|
|
474
484
|
}
|
|
485
|
+
featureorder.addAll(rest)
|
|
475
486
|
}
|
|
476
487
|
|
|
477
488
|
val derived = new LinkedHashMap[String, Object]()
|
|
@@ -487,6 +498,78 @@ object MakeOptions {
|
|
|
487
498
|
opts
|
|
488
499
|
}
|
|
489
500
|
|
|
501
|
+
// This struct port's `$FUNCTION` admits only a java.util.function Function or
|
|
502
|
+
// Supplier, so a callback in a slot the spec types as a function is held out
|
|
503
|
+
// of validation and put back; any other key is still validated.
|
|
504
|
+
private def holdCallbacks(opts: Object, optspec: JMap[String, Object]): java.util.List[Array[Object]] = {
|
|
505
|
+
val held = new ArrayList[Array[Object]]()
|
|
506
|
+
val feature = Helpers.toMapAny(Helpers.toMapAny(opts) match { case null => null; case m => m.get("feature") })
|
|
507
|
+
val fspecs = Helpers.toMapAny(optspec.get("feature"))
|
|
508
|
+
if (feature != null && fspecs != null) feature.forEach((name, fopts) => {
|
|
509
|
+
val fm = Helpers.toMapAny(fopts)
|
|
510
|
+
val fspec = specMap(fspecs.get(name))
|
|
511
|
+
if (fm != null && fspec != null) new ArrayList[String](fm.keySet()).forEach(key => {
|
|
512
|
+
if (isFunctionSpec(fspec.get(key)) && isCallback(fm.get(key)))
|
|
513
|
+
held.add(Array[Object](name, key, fm.remove(key)))
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
held
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
private def specMap(spec: Object): JMap[String, Object] = spec match {
|
|
520
|
+
case alts: java.util.List[_] =>
|
|
521
|
+
val from = if (!alts.isEmpty && "`$NOF`" == alts.get(0)) 2 else 0
|
|
522
|
+
var found: JMap[String, Object] = null
|
|
523
|
+
var i = from
|
|
524
|
+
while (found == null && i < alts.size) {
|
|
525
|
+
found = Helpers.toMapAny(alts.get(i))
|
|
526
|
+
i += 1
|
|
527
|
+
}
|
|
528
|
+
found
|
|
529
|
+
case _ => Helpers.toMapAny(spec)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
private def isFunctionSpec(spec: Object): Boolean =
|
|
533
|
+
"`$FUNCTION`" == spec || (spec match { case l: java.util.List[_] => l.contains("`$FUNCTION`"); case _ => false })
|
|
534
|
+
|
|
535
|
+
private def isCallback(v: Object): Boolean = v match {
|
|
536
|
+
case null => false
|
|
537
|
+
case _: Function0[_] | _: Function1[_, _] | _: Function2[_, _, _] | _: Function3[_, _, _, _] => true
|
|
538
|
+
case _ => v.getClass.getInterfaces.exists(i =>
|
|
539
|
+
i.isAnnotationPresent(classOf[FunctionalInterface]) || i.getName.startsWith("java.util.function."))
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
private def restoreCallbacks(opts: JMap[String, Object], held: java.util.List[Array[Object]]): Unit = {
|
|
543
|
+
val feature = Helpers.toMapAny(opts.get("feature"))
|
|
544
|
+
if (feature != null) held.forEach(h => {
|
|
545
|
+
val fm = Helpers.toMapAny(feature.get(h(0)))
|
|
546
|
+
if (fm != null) fm.put(h(1).asInstanceOf[String], h(2))
|
|
547
|
+
})
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// The model's options for a feature sit beneath the caller's, key by key: a
|
|
551
|
+
// key the caller sets replaces the default whole, so a list is never merged.
|
|
552
|
+
private def featureDefaults(cfgfeature: Object, feature: Object): JMap[String, Object] = {
|
|
553
|
+
if (feature != null && !feature.isInstanceOf[JMap[_, _]]) return null
|
|
554
|
+
val out = new LinkedHashMap[String, Object]()
|
|
555
|
+
if (feature != null) out.putAll(feature.asInstanceOf[JMap[String, Object]])
|
|
556
|
+
val cfg = Helpers.toMapAny(cfgfeature)
|
|
557
|
+
if (cfg != null) cfg.forEach((name, fdef) => {
|
|
558
|
+
val fm = Helpers.toMapAny(fdef)
|
|
559
|
+
val dflt = if (fm == null) null else Helpers.toMapAny(fm.get("options"))
|
|
560
|
+
val supplied = out.get(name)
|
|
561
|
+
val skip = dflt == null ||
|
|
562
|
+
(supplied == null && java.lang.Boolean.TRUE != dflt.get("active")) ||
|
|
563
|
+
(supplied != null && !supplied.isInstanceOf[JMap[_, _]])
|
|
564
|
+
if (!skip) {
|
|
565
|
+
val merged = new LinkedHashMap[String, Object](Helpers.toMapAny(Struct.clone(dflt)))
|
|
566
|
+
if (supplied != null) merged.putAll(supplied.asInstanceOf[JMap[String, Object]])
|
|
567
|
+
out.put(name, merged)
|
|
568
|
+
}
|
|
569
|
+
})
|
|
570
|
+
out
|
|
571
|
+
}
|
|
572
|
+
|
|
490
573
|
// A feature's name is not a field name: a feature called `secrets` does not
|
|
491
574
|
// make every one of its options a secret. Entity blocks (entity settings,
|
|
492
575
|
// seeded records) hold no credential, and nor do rbac's rules, keyed by
|
|
@@ -93,8 +93,9 @@ public final class AuditFeature: BaseFeature {
|
|
|
93
93
|
records.removeFirst()
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
// A sink may throw; its failure never changes the operation's outcome.
|
|
97
|
+
if let sink = gp(options, "sink").asNative as? (VMap) throws -> Void {
|
|
98
|
+
try? sink(record)
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
}
|
|
@@ -14,6 +14,16 @@ public final class MetricsBucket {
|
|
|
14
14
|
public var totalMs: Int64 = 0
|
|
15
15
|
public var maxMs: Int64 = 0
|
|
16
16
|
public init() {}
|
|
17
|
+
|
|
18
|
+
func record() -> VMap {
|
|
19
|
+
let out = VMap()
|
|
20
|
+
out.entries["count"] = .int(Int64(count))
|
|
21
|
+
out.entries["ok"] = .int(Int64(ok))
|
|
22
|
+
out.entries["err"] = .int(Int64(err))
|
|
23
|
+
out.entries["totalMs"] = .int(totalMs)
|
|
24
|
+
out.entries["maxMs"] = .int(maxMs)
|
|
25
|
+
return out
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
public final class MetricsFeature: BaseFeature {
|
|
@@ -86,6 +96,16 @@ public final class MetricsFeature: BaseFeature {
|
|
|
86
96
|
|
|
87
97
|
bump(total, ok, dur)
|
|
88
98
|
bump(op, ok, dur)
|
|
99
|
+
|
|
100
|
+
// A sink may throw; its failure never changes the operation's outcome.
|
|
101
|
+
if let sink = gp(options, "sink").asNative as? (VMap) throws -> Void {
|
|
102
|
+
let opsOut = VMap()
|
|
103
|
+
for (k, b) in ops { opsOut.entries[k] = .map(b.record()) }
|
|
104
|
+
let raw = VMap()
|
|
105
|
+
raw.entries["total"] = .map(total.record())
|
|
106
|
+
raw.entries["ops"] = .map(opsOut)
|
|
107
|
+
try? sink(fclean(ctx, raw))
|
|
108
|
+
}
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
private func bump(_ bucket: MetricsBucket, _ ok: Bool, _ dur: Int64) {
|
|
@@ -65,6 +65,9 @@ public final class PagingFeature: BaseFeature {
|
|
|
65
65
|
|
|
66
66
|
if hasCursor {
|
|
67
67
|
spec.query.entries[cursorParam] = cursor
|
|
68
|
+
} else if let paging = paging, let link = gp(paging, "next").asString,
|
|
69
|
+
!PagingFeature.foreign(link, spec.base) {
|
|
70
|
+
PagingFeature.follow(spec, link)
|
|
68
71
|
} else if isNil(gp(spec.query, pageParam)) {
|
|
69
72
|
var page: Value? = nil
|
|
70
73
|
if let paging = paging {
|
|
@@ -183,8 +186,12 @@ public final class PagingFeature: BaseFeature {
|
|
|
183
186
|
// Body-level signals; snake_case forms are read first so camelCase wins.
|
|
184
187
|
if let bm = body.asMap {
|
|
185
188
|
let next = gp(bm, "next")
|
|
186
|
-
if !isNil(next)
|
|
187
|
-
|
|
189
|
+
if !isNil(next) {
|
|
190
|
+
if !PagingFeature.isLink(next.asString, foptStr(options, "next", "auto")) {
|
|
191
|
+
paging.entries["cursor"] = next
|
|
192
|
+
} else if isNil(gp(paging, "next")) {
|
|
193
|
+
paging.entries["next"] = next
|
|
194
|
+
}
|
|
188
195
|
}
|
|
189
196
|
let snakeCursor = gp(bm, "next_cursor")
|
|
190
197
|
if !isNil(snakeCursor) {
|
|
@@ -216,6 +223,16 @@ public final class PagingFeature: BaseFeature {
|
|
|
216
223
|
}
|
|
217
224
|
}
|
|
218
225
|
|
|
226
|
+
// A link to another origin is recorded, never followed, and ends the walk.
|
|
227
|
+
let base = ctx.spec?.base ?? gp(ctx.options, "base").asString ?? ""
|
|
228
|
+
if let link = gp(paging, "next").asString, let spec = ctx.spec {
|
|
229
|
+
paging.entries["next"] = .string(PagingFeature.resolve(link, spec.url))
|
|
230
|
+
}
|
|
231
|
+
if let link = gp(paging, "next").asString, PagingFeature.foreign(link, base) {
|
|
232
|
+
paging.entries["foreign"] = .string(link)
|
|
233
|
+
_ = paging.entries.removeValue(forKey: "next")
|
|
234
|
+
}
|
|
235
|
+
|
|
219
236
|
// Cursor presence only INFERS another page. When the server stated the
|
|
220
237
|
// answer outright - relay's `hasNextPage: false`, or a body `hasMore` -
|
|
221
238
|
// that wins: a final page normally carries both an end cursor and
|
|
@@ -227,6 +244,10 @@ public final class PagingFeature: BaseFeature {
|
|
|
227
244
|
paging.entries["hasMore"] = .bool(true)
|
|
228
245
|
}
|
|
229
246
|
|
|
247
|
+
if !isNil(gp(paging, "foreign")) && isNil(gp(paging, "cursor")) && isNil(gp(paging, "nextPage")) {
|
|
248
|
+
paging.entries["hasMore"] = .bool(false)
|
|
249
|
+
}
|
|
250
|
+
|
|
230
251
|
result.paging = paging
|
|
231
252
|
last = paging
|
|
232
253
|
|
|
@@ -239,6 +260,85 @@ public final class PagingFeature: BaseFeature {
|
|
|
239
260
|
}
|
|
240
261
|
}
|
|
241
262
|
|
|
263
|
+
private static let origin = try! NSRegularExpression(
|
|
264
|
+
pattern: "^[a-z][a-z0-9+.-]*://[^/?#]*", options: [.caseInsensitive])
|
|
265
|
+
|
|
266
|
+
private static func originOf(_ text: String) -> String {
|
|
267
|
+
let range = NSRange(text.startIndex..., in: text)
|
|
268
|
+
guard let m = origin.firstMatch(in: text, options: [], range: range),
|
|
269
|
+
let r = Range(m.range, in: text) else {
|
|
270
|
+
return ""
|
|
271
|
+
}
|
|
272
|
+
return String(text[r])
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Under the `next` option's default, a URL or an absolute path is a link and
|
|
276
|
+
// anything else a cursor; `cursor` and `url` pin the reading.
|
|
277
|
+
static func isLink(_ next: String?, _ mode: String) -> Bool {
|
|
278
|
+
guard let next = next else { return false }
|
|
279
|
+
return mode == "url" || (mode != "cursor" && (originOf(next) != "" || next.hasPrefix("/")))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
static func foreign(_ link: String, _ base: String) -> Bool {
|
|
283
|
+
let origin = originOf(link).lowercased()
|
|
284
|
+
return origin != "" && origin != originOf(base).lowercased()
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private static let scheme = try! NSRegularExpression(
|
|
288
|
+
pattern: "^[a-z][a-z0-9+.-]*:", options: [.caseInsensitive])
|
|
289
|
+
|
|
290
|
+
// RFC 3986 reference resolution against the URL of the request that
|
|
291
|
+
// returned the link. A link on that URL's origin comes back as its path and
|
|
292
|
+
// query; an absolute link is left as the server wrote it.
|
|
293
|
+
static func resolve(_ link: String, _ url: String) -> String {
|
|
294
|
+
if url.isEmpty || nil != scheme.firstMatch(in: link, options: [], range: NSRange(link.startIndex..., in: link)) {
|
|
295
|
+
return link
|
|
296
|
+
}
|
|
297
|
+
let holder = "http://placeholder.invalid" + (url.hasPrefix("/") ? "" : "/")
|
|
298
|
+
guard let from = URL(string: originOf(url).isEmpty ? holder + url : url),
|
|
299
|
+
let to = URL(string: link, relativeTo: from)?.absoluteURL,
|
|
300
|
+
var parts = URLComponents(url: to, resolvingAgainstBaseURL: false) else {
|
|
301
|
+
return link
|
|
302
|
+
}
|
|
303
|
+
parts.fragment = nil
|
|
304
|
+
if to.scheme != from.scheme || to.host != from.host || to.port != from.port {
|
|
305
|
+
return parts.string ?? link
|
|
306
|
+
}
|
|
307
|
+
return parts.percentEncodedPath + (nil == parts.percentEncodedQuery ? "" : "?" + parts.percentEncodedQuery!)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// The request goes to the link's path and query, on the SDK's own origin.
|
|
311
|
+
static func follow(_ spec: Spec, _ next: String) {
|
|
312
|
+
var rest = String(next.dropFirst(originOf(next).count))
|
|
313
|
+
if let hash = rest.firstIndex(of: "#") {
|
|
314
|
+
rest = String(rest[..<hash])
|
|
315
|
+
}
|
|
316
|
+
let parts = rest.split(separator: "?", maxSplits: 1, omittingEmptySubsequences: false)
|
|
317
|
+
let path = parts.isEmpty ? "" : String(parts[0])
|
|
318
|
+
let rawquery = parts.count > 1 ? String(parts[1]) : ""
|
|
319
|
+
|
|
320
|
+
let query = VMap()
|
|
321
|
+
for pair in rawquery.split(separator: "&") {
|
|
322
|
+
let kv = pair.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
|
|
323
|
+
let key = unescape(String(kv[0]))
|
|
324
|
+
query.entries[key] = .string(unescape(kv.count > 1 ? String(kv[1]) : ""))
|
|
325
|
+
}
|
|
326
|
+
for key in spec.authquery {
|
|
327
|
+
query.entries[key] = gp(spec.query, key)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
spec.base = originOf(spec.base)
|
|
331
|
+
spec.prefix = ""
|
|
332
|
+
spec.path = path
|
|
333
|
+
spec.suffix = ""
|
|
334
|
+
spec.query = query
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private static func unescape(_ text: String) -> String {
|
|
338
|
+
let spaced = text.replacingOccurrences(of: "+", with: " ")
|
|
339
|
+
return spaced.removingPercentEncoding ?? spaced
|
|
340
|
+
}
|
|
341
|
+
|
|
242
342
|
private func isList(_ ctx: Context) -> Bool {
|
|
243
343
|
let opname = ctx.op?.name ?? ""
|
|
244
344
|
let ops = foptStrList(options, "ops") ?? ["list"]
|