@voxgig/sdkgen 4.48.0 → 4.49.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/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +9 -1
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/secrets.aontu +3 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
- package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
- package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
- package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
- package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
- package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
- package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
- package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
- package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
- package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
- package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
- package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
- package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
- package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
- package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
- package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
- package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
- package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
- package/project/.sdk/tm/c/feature/cache.c +16 -1
- package/project/.sdk/tm/c/feature/secrets.c +149 -18
- package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
- package/project/.sdk/tm/c/tests/feature_test.c +31 -0
- package/project/.sdk/tm/c/utility/make_spec.c +1 -1
- package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
- package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
- package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
- package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
- package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
- package/project/.sdk/tm/cpp/core/types.hpp +1 -11
- package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
- package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
- package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
- package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
- package/project/.sdk/tm/csharp/core/Control.cs +0 -5
- package/project/.sdk/tm/csharp/core/Point.cs +6 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
- package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
- package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
- package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
- package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
- package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
- package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
- package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
- package/project/.sdk/tm/go/core/target.go +8 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
- package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
- package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
- package/project/.sdk/tm/go/test/feature_test.go +32 -0
- package/project/.sdk/tm/go/utility/media.go +2 -2
- package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
- package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
- package/project/.sdk/tm/java/core/Control.java +0 -5
- package/project/.sdk/tm/java/core/Point.java +7 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
- package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
- package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
- package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
- package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
- package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
- package/project/.sdk/tm/java/utility/Media.java +2 -2
- package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
- package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
- package/project/.sdk/tm/js/src/Point.js +2 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
- package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
- package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
- package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
- package/project/.sdk/tm/js/test/feature.test.js +17 -0
- package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
- package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
- package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
- package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
- package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
- package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
- package/project/.sdk/tm/lua/utility/clean.lua +1 -0
- package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
- package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
- package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
- package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
- package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
- package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
- package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
- package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
- package/project/.sdk/tm/perl/t/feature.t +24 -0
- package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
- package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
- package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
- package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
- package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
- package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
- package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
- package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
- package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
- package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
- package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
- package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
- package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
- package/project/.sdk/tm/py/test/test_feature.py +18 -0
- package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
- package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
- package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
- package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
- package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
- package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
- package/project/.sdk/tm/rust/feature/cache.rs +15 -1
- package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
- package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
- package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
- package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
- package/project/.sdk/tm/scala/core/Control.scala +0 -5
- package/project/.sdk/tm/scala/core/Point.scala +3 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
- package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
- package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
- package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
- package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
- package/project/.sdk/tm/ts/src/Point.ts +3 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
- package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
- package/project/.sdk/tm/zig/core/utility.zig +47 -4
- package/project/.sdk/tm/zig/feature/cache.zig +15 -1
- package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
- package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
- package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
- package/project/sdkgen-package.json +1 -1
- package/src/utility.ts +12 -1
|
@@ -78,6 +78,11 @@ public final class SecretsFeature: BaseFeature {
|
|
|
78
78
|
// the client holds). READ ONLY: this feature never writes to it.
|
|
79
79
|
private var liveopts: VMap = VMap()
|
|
80
80
|
|
|
81
|
+
// What prepareAuth was generated from: the config declares auth only
|
|
82
|
+
// where it places a credential, and Basic only where it composes one.
|
|
83
|
+
private var declared = false
|
|
84
|
+
private var basic = false
|
|
85
|
+
|
|
81
86
|
private var secretname = "apikey"
|
|
82
87
|
private var cache = true
|
|
83
88
|
private var sek: Sekreto?
|
|
@@ -114,8 +119,11 @@ public final class SecretsFeature: BaseFeature {
|
|
|
114
119
|
let response: String
|
|
115
120
|
let statuses: [Int]
|
|
116
121
|
let retries: Int
|
|
122
|
+
let sameOrigin: Bool
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
private static let redirectMax = 5
|
|
126
|
+
|
|
119
127
|
// One shared in-flight resolution: late arrivals wait on `done` and read
|
|
120
128
|
// `err`.
|
|
121
129
|
private final class SecretsCall {
|
|
@@ -171,6 +179,10 @@ public final class SecretsFeature: BaseFeature {
|
|
|
171
179
|
liveopts = ctx.options ?? VMap()
|
|
172
180
|
active = foptBool(options, "active", false)
|
|
173
181
|
|
|
182
|
+
let authdecl = gp(gp(ctx.config, "options"), "auth").asMap
|
|
183
|
+
declared = nil != authdecl
|
|
184
|
+
basic = true == gp(authdecl, "basic").asBool
|
|
185
|
+
|
|
174
186
|
if !active {
|
|
175
187
|
return
|
|
176
188
|
}
|
|
@@ -196,7 +208,8 @@ public final class SecretsFeature: BaseFeature {
|
|
|
196
208
|
request: foptStr(xopts, "request", "refresh_token"),
|
|
197
209
|
response: foptStr(xopts, "response", "access_token"),
|
|
198
210
|
statuses: statuses,
|
|
199
|
-
retries: foptInt(xopts, "retries", 1)
|
|
211
|
+
retries: foptInt(xopts, "retries", 1),
|
|
212
|
+
sameOrigin: "same-origin" == foptStr(xopts, "redirect", "refuse"))
|
|
200
213
|
}
|
|
201
214
|
|
|
202
215
|
// WRAP FIRST, BUILD SECOND. The transport wrapper is the fail-closed
|
|
@@ -355,8 +368,14 @@ public final class SecretsFeature: BaseFeature {
|
|
|
355
368
|
}
|
|
356
369
|
}
|
|
357
370
|
|
|
371
|
+
// prepareAuth's decision: auth the config declares, not suppressed by
|
|
372
|
+
// `auth: null`.
|
|
373
|
+
private func authon() -> Bool {
|
|
374
|
+
return declared && !isNil(gp(liveopts, "auth"))
|
|
375
|
+
}
|
|
376
|
+
|
|
358
377
|
private func resolveonce() throws {
|
|
359
|
-
guard let s = sek else {
|
|
378
|
+
guard let s = sek, authon() else {
|
|
360
379
|
return
|
|
361
380
|
}
|
|
362
381
|
|
|
@@ -439,12 +458,9 @@ public final class SecretsFeature: BaseFeature {
|
|
|
439
458
|
// request left, and it carries the token that just failed.
|
|
440
459
|
private func withrefresh(_ ctx: Context, _ url: String, _ fetchdef: VMap,
|
|
441
460
|
_ inner: FetcherFunc) throws -> Value {
|
|
442
|
-
//
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
// cannot be fixed by buying one - retrying would transmit exactly the
|
|
446
|
-
// credential the caller suppressed.
|
|
447
|
-
if isNil(gp(liveopts, "auth")) {
|
|
461
|
+
// A refusal of an unauthenticated request is not an expired token, and
|
|
462
|
+
// retrying would transmit the credential that auth off withholds.
|
|
463
|
+
if !authon() {
|
|
448
464
|
return try inner(ctx, url, fetchdef)
|
|
449
465
|
}
|
|
450
466
|
|
|
@@ -521,7 +537,7 @@ public final class SecretsFeature: BaseFeature {
|
|
|
521
537
|
// where the rule has to hold. The options map is FROZEN after
|
|
522
538
|
// construction (this feature never writes it), so the raw read is safe
|
|
523
539
|
// on any thread.
|
|
524
|
-
guard let auth = gp(liveopts, "auth").asMap else {
|
|
540
|
+
guard authon(), let auth = gp(liveopts, "auth").asMap else {
|
|
525
541
|
headers.entries.removeValue(forKey: "authorization")
|
|
526
542
|
return
|
|
527
543
|
}
|
|
@@ -530,10 +546,20 @@ public final class SecretsFeature: BaseFeature {
|
|
|
530
546
|
let rawname = gp(auth, "name").asString ?? ""
|
|
531
547
|
let name = "" == rawname ? "authorization" : rawname.lowercased()
|
|
532
548
|
|
|
549
|
+
let value = basic && true == gp(auth, "basic").asBool ? pair(token) : token
|
|
550
|
+
|
|
533
551
|
let prefix = gp(auth, "prefix").asString ?? ""
|
|
534
552
|
// Empty prefix (raw apiKey credential) must not add a leading space -
|
|
535
553
|
// prepareAuth's rule, repeated here because this is the other writer.
|
|
536
|
-
headers.entries[name] = .string("" == prefix ?
|
|
554
|
+
headers.entries[name] = .string("" == prefix ? value : prefix + " " + value)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Under Basic the token is the key half, as apikey is: prepareAuth's pair.
|
|
558
|
+
private func pair(_ token: String) -> String {
|
|
559
|
+
let secret = gp(liveopts, "secret").asString ?? ""
|
|
560
|
+
let pair = Data((token + ":" + secret).utf8).base64EncodedString()
|
|
561
|
+
register(pair)
|
|
562
|
+
return pair
|
|
537
563
|
}
|
|
538
564
|
|
|
539
565
|
// buy an access token with the refresh token. Concurrent callers share the
|
|
@@ -624,7 +650,7 @@ public final class SecretsFeature: BaseFeature {
|
|
|
624
650
|
fetchdef.entries["method"] = .string(x.method)
|
|
625
651
|
fetchdef.entries["headers"] = .map(vm(("content-type", .string("application/json"))))
|
|
626
652
|
fetchdef.entries["body"] = .string(body)
|
|
627
|
-
// Never followed: a redirect would carry the refresh token on.
|
|
653
|
+
// Never followed by the client: a redirect would carry the refresh token on.
|
|
628
654
|
fetchdef.entries["redirect"] = .string("manual")
|
|
629
655
|
|
|
630
656
|
// Deliberately NOT the SDK transport. The transport is what this feature
|
|
@@ -636,11 +662,22 @@ public final class SecretsFeature: BaseFeature {
|
|
|
636
662
|
// rawExchangeFetch twin, unlike go); a supplied system.fetch is honoured
|
|
637
663
|
// so a test can intercept the purchase.
|
|
638
664
|
let sysFetch = gpath(options, "system", "fetch")
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
665
|
+
func fetch(_ at: String) throws -> Value {
|
|
666
|
+
if let fn = sysFetch.asNative as? SystemFetch {
|
|
667
|
+
return fn(at, fetchdef)
|
|
668
|
+
}
|
|
669
|
+
return try defaultHttpFetch(at, fetchdef)
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
var res = try fetch(url)
|
|
673
|
+
|
|
674
|
+
// By option alone, and only while the exchange stays on its own origin.
|
|
675
|
+
var at = url
|
|
676
|
+
var hops = 0
|
|
677
|
+
while x.sameOrigin, hops < SecretsFeature.redirectMax, let next = SecretsFeature.moved(url, at, res) {
|
|
678
|
+
at = next
|
|
679
|
+
res = try fetch(at)
|
|
680
|
+
hops += 1
|
|
644
681
|
}
|
|
645
682
|
|
|
646
683
|
let (status, _) = fresStatus(res)
|
|
@@ -668,6 +705,29 @@ public final class SecretsFeature: BaseFeature {
|
|
|
668
705
|
return token
|
|
669
706
|
}
|
|
670
707
|
|
|
708
|
+
// Where a redirect that keeps method and body points, when that is on the
|
|
709
|
+
// exchange's own origin. Any other would drop the body or leave the origin.
|
|
710
|
+
private static func moved(_ url: String, _ at: String, _ res: Value) -> String? {
|
|
711
|
+
let (status, _) = fresStatus(res)
|
|
712
|
+
let (location, has) = fresHeader(res, "location")
|
|
713
|
+
guard 307 == status || 308 == status, has, "" != location,
|
|
714
|
+
let next = resolveLocation(at, location),
|
|
715
|
+
let own = origin(url), own == origin(next)
|
|
716
|
+
else {
|
|
717
|
+
return nil
|
|
718
|
+
}
|
|
719
|
+
return next
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
private static func origin(_ url: String) -> String? {
|
|
723
|
+
guard let parts = URLComponents(string: url), let scheme = parts.scheme?.lowercased(),
|
|
724
|
+
let host = parts.host?.lowercased()
|
|
725
|
+
else {
|
|
726
|
+
return nil
|
|
727
|
+
}
|
|
728
|
+
return "\(scheme)://\(host):\(parts.port ?? (scheme == "https" ? 443 : 80))"
|
|
729
|
+
}
|
|
730
|
+
|
|
671
731
|
// An SDK Value (a plain map from the options) as the plugin host's own
|
|
672
732
|
// value model, which is what sekreto's `specof` reads. QUALIFIED, because
|
|
673
733
|
// this file sees both libraries' `Value` and the SDK's own wins unqualified.
|
|
@@ -226,7 +226,7 @@ func makeSpecUtil(_ ctx: Context) throws -> Spec {
|
|
|
226
226
|
if "graphql" == gp(ctx.point, "kind").asString {
|
|
227
227
|
// GraphQL addresses one endpoint: no path parts, no query string, and
|
|
228
228
|
// the body carries the operation. prepareBody is skipped deliberately —
|
|
229
|
-
// it only
|
|
229
|
+
// it builds only a REST body, whereas every GraphQL op
|
|
230
230
|
// posts one, including load/list/remove.
|
|
231
231
|
ctx.spec!.body = utility.graphqlBody(ctx)
|
|
232
232
|
ctx.spec!.path = ""
|
|
@@ -148,7 +148,9 @@ func prepareQueryUtil(_ ctx: Context) -> VMap {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
// A header or cookie parameter travels in the headers, which prepareHeaders
|
|
151
|
-
// fills,
|
|
151
|
+
// fills, and a field the point's body declares travels in the body, which
|
|
152
|
+
// prepareBody fills, unless a query parameter shares its name: then both
|
|
153
|
+
// are sent.
|
|
152
154
|
var declared: [Value] = []
|
|
153
155
|
if let dql = gpath(ctx.point, "args", "query").asList {
|
|
154
156
|
for qd in dql.items {
|
|
@@ -164,6 +166,11 @@ func prepareQueryUtil(_ ctx: Context) -> VMap {
|
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
}
|
|
169
|
+
for name in gp(ctx.point, "fields").asList?.items ?? [] {
|
|
170
|
+
if let s = name.asString, !containsStr(declared, s) {
|
|
171
|
+
paramnames.append(name)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
167
174
|
|
|
168
175
|
// A query parameter travels under the name the definition gives it, its
|
|
169
176
|
// orig, which the model may have renamed for the caller.
|
|
@@ -202,9 +209,37 @@ func prepareBodyUtil(_ ctx: Context) -> Value {
|
|
|
202
209
|
if isRawRequest(ctx.point) { return rawBodyOf(ctx.reqdata) }
|
|
203
210
|
return ctx.utility!.transformRequest(ctx)
|
|
204
211
|
}
|
|
212
|
+
if let fields = gp(ctx.point, "fields").asList, !fields.items.isEmpty {
|
|
213
|
+
return .map(matchBody(ctx, fields))
|
|
214
|
+
}
|
|
205
215
|
return .noval
|
|
206
216
|
}
|
|
207
217
|
|
|
218
|
+
// A list, load or remove routed to a method with a body sends the match
|
|
219
|
+
// fields that body declares, never a path parameter, and never a header,
|
|
220
|
+
// cookie or query argument the body does not also declare as a field.
|
|
221
|
+
private func matchBody(_ ctx: Context, _ fields: VList) -> VMap {
|
|
222
|
+
var routed: [Value] = gp(ctx.point, "params").asList?.items ?? []
|
|
223
|
+
for pd in gpath(ctx.point, "args", "params").asList?.items ?? [] {
|
|
224
|
+
routed.append(gp(pd, "name"))
|
|
225
|
+
}
|
|
226
|
+
for kind in ["header", "cookie", "query"] {
|
|
227
|
+
for ad in gpath(ctx.point, "args", kind).asList?.items ?? [] where gp(ad, "field").asBool != true {
|
|
228
|
+
routed.append(gp(ad, "name"))
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let body = VMap()
|
|
233
|
+
for field in fields.items {
|
|
234
|
+
guard let name = field.asString else { continue }
|
|
235
|
+
let val = gp(ctx.reqmatch, name)
|
|
236
|
+
if !isNil(val) && "$action" != name && !containsStr(routed, name) {
|
|
237
|
+
body.entries[name] = val
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return body
|
|
241
|
+
}
|
|
242
|
+
|
|
208
243
|
// prepareAuth IS NOT HERE. It was, and it hardcoded
|
|
209
244
|
//
|
|
210
245
|
// private let headerAuth = "authorization"
|
|
@@ -573,6 +573,27 @@ final class FeatureCacheTest: XCTestCase {
|
|
|
573
573
|
XCTAssertEqual(rec.calls.count, 3)
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
func testBodyOfAnotherTypeThanJsonPassesByUnread() {
|
|
577
|
+
if Fh.skipWithout("cache") { return }
|
|
578
|
+
let rec = FhRecorder()
|
|
579
|
+
var sent: [VMap?] = []
|
|
580
|
+
rec.reply = { _, _ in
|
|
581
|
+
let res = Fh.response(200, .noval, vm(("content-type", .string("audio/wav"))))
|
|
582
|
+
res.asMap?.entries["body"] = .string("RIFF")
|
|
583
|
+
sent.append(res.asMap?.entries["headers"]?.asMap)
|
|
584
|
+
return res
|
|
585
|
+
}
|
|
586
|
+
let f = CacheFeature()
|
|
587
|
+
let h = Fh.make(rec.fetch, (f, nil))
|
|
588
|
+
let a = h.op(FhOpSpec(op: "load", path: "/w/1/audio"))
|
|
589
|
+
let b = h.op(FhOpSpec(op: "load", path: "/w/1/audio"))
|
|
590
|
+
XCTAssertEqual(rec.calls.count, 2, "the body was stored")
|
|
591
|
+
XCTAssertTrue(a.ctx?.response?.headers.asMap === sent[0],
|
|
592
|
+
"the cache handed on a copy it had read")
|
|
593
|
+
XCTAssertTrue(sent.count == 2 && b.ctx?.response?.headers.asMap === sent[1])
|
|
594
|
+
XCTAssertEqual(f.bypass, 2)
|
|
595
|
+
}
|
|
596
|
+
|
|
576
597
|
func testInactiveDoesNotWrap() {
|
|
577
598
|
if Fh.skipWithout("cache") { return }
|
|
578
599
|
let rec = FhRecorder()
|