@voxgig/sdkgen 4.50.0 → 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.
- package/bin/voxgig-sdkgen +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/feature/cache.aontu +6 -4
- package/project/.sdk/model/target/lua.aontu +6 -0
- package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
- package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
- package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
- package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
- package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
- package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
- package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
- package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
- package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
- package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
- package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
- package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
- package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
- package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
- package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
- package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
- package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
- package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
- package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
- package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
- package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
- package/project/.sdk/tm/c/core/context.c +1 -0
- package/project/.sdk/tm/c/core/sdk.h +7 -4
- package/project/.sdk/tm/c/feature/cache.c +243 -13
- package/project/.sdk/tm/c/feature/secrets.c +27 -38
- package/project/.sdk/tm/c/tests/feature_test.c +104 -0
- package/project/.sdk/tm/c/utility/clean.c +26 -33
- package/project/.sdk/tm/c/utility/make_options.c +9 -8
- package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
- package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
- package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
- package/project/.sdk/tm/clojure/src/sdk/features.clj +81 -10
- package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +33 -0
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
- package/project/.sdk/tm/cpp/Makefile +5 -0
- package/project/.sdk/tm/cpp/core/types.hpp +11 -4
- package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
- package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
- package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
- package/project/.sdk/tm/cpp/test/feature_test.cpp +99 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
- package/project/.sdk/tm/csharp/core/Context.cs +4 -0
- package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
- package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
- package/project/.sdk/tm/csharp/test/FeatureTest.cs +76 -0
- package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
- package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
- package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
- package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
- package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
- package/project/.sdk/tm/elixir/test/feature_test.exs +61 -0
- package/project/.sdk/tm/go/core/context.go +6 -0
- package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
- package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
- package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
- package/project/.sdk/tm/go/test/feature_test.go +61 -0
- package/project/.sdk/tm/go/utility/clean.go +5 -7
- package/project/.sdk/tm/go/utility/fetcher.go +11 -0
- package/project/.sdk/tm/go/utility/make_options.go +5 -7
- package/project/.sdk/tm/java/core/Context.java +9 -0
- package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
- package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
- package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
- package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
- package/project/.sdk/tm/java/utility/Clean.java +6 -10
- package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
- package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
- package/project/.sdk/tm/js/src/Context.js +4 -0
- package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
- package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
- package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
- package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
- package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
- package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
- package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
- package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
- package/project/.sdk/tm/js/test/feature/harness.js +3 -3
- package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
- package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
- package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
- package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
- package/project/.sdk/tm/kotlin/test/FeatureTest.kt +59 -0
- package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
- package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
- package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
- package/project/.sdk/tm/lua/core/context.lua +6 -0
- package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
- package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
- package/project/.sdk/tm/lua/test/feature_test.lua +81 -0
- package/project/.sdk/tm/lua/utility/clean.lua +6 -9
- package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
- package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
- package/project/.sdk/tm/ocaml/sdk_features.ml +106 -8
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
- package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
- package/project/.sdk/tm/ocaml/test/t_feature.ml +35 -1
- package/project/.sdk/tm/perl/core/context.pm +3 -0
- package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
- package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
- package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
- package/project/.sdk/tm/perl/t/feature.t +66 -0
- package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
- package/project/.sdk/tm/perl/utility/clean.pm +6 -8
- package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
- package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
- package/project/.sdk/tm/php/core/Context.php +4 -0
- package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
- package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
- package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
- package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
- package/project/.sdk/tm/php/utility/Clean.php +3 -10
- package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
- package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
- package/project/.sdk/tm/py/pkg/core/context.py +4 -0
- package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
- package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
- package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
- package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
- package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
- package/project/.sdk/tm/py/test/test_feature.py +50 -0
- package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
- package/project/.sdk/tm/rb/core/context.rb +4 -1
- package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
- package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
- package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
- package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
- package/project/.sdk/tm/rb/test/feature_test.rb +74 -0
- package/project/.sdk/tm/rb/utility/clean.rb +6 -7
- package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
- package/project/.sdk/tm/rust/core/context.rs +8 -0
- package/project/.sdk/tm/rust/feature/cache.rs +120 -3
- package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
- package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
- package/project/.sdk/tm/rust/tests/feature_test.rs +100 -0
- package/project/.sdk/tm/rust/utility/clean.rs +35 -43
- package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
- package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
- package/project/.sdk/tm/scala/core/Context.scala +4 -0
- package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
- package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +28 -0
- package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
- package/project/.sdk/tm/scala/utility/Make.scala +3 -1
- package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +55 -0
- package/project/.sdk/tm/ts/src/Context.ts +4 -0
- package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
- package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
- package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
- package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
- package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
- package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
- package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
- package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
- package/project/.sdk/tm/zig/core/context.zig +5 -0
- package/project/.sdk/tm/zig/core/utility.zig +11 -9
- package/project/.sdk/tm/zig/feature/cache.zig +144 -13
- package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
- package/project/.sdk/tm/zig/test/feature_test.zig +65 -0
- package/project/sdkgen-package.json +1 -1
|
@@ -6,20 +6,18 @@ declare(strict_types=1);
|
|
|
6
6
|
require_once __DIR__ . '/BaseFeature.php';
|
|
7
7
|
require_once __DIR__ . '/../utility/Media.php';
|
|
8
8
|
|
|
9
|
-
// Response caching for safe (read) requests
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// successful (2xx) responses to cacheable methods (default: GET) are
|
|
13
|
-
// stored, keyed by method+URL. The cache is bounded (`max` entries, default
|
|
14
|
-
// 256, oldest evicted first) and every hit/miss/bypass is recorded on
|
|
15
|
-
// `client->_cache` for inspection. Snapshots replay through a fresh `json`
|
|
16
|
-
// closure so both the current caller and later hits can read the body
|
|
17
|
-
// repeatedly. Mirrors ts/src/feature/cache/CacheFeature.ts.
|
|
9
|
+
// Response caching for safe (read) requests, per client: see the features
|
|
10
|
+
// reference for the key, the write invalidation and the Cache-Control rules.
|
|
11
|
+
// Mirrors ts/src/feature/cache/CacheFeature.ts.
|
|
18
12
|
class ProjectNameCacheFeature extends ProjectNameBaseFeature
|
|
19
13
|
{
|
|
14
|
+
private const SAFE_METHODS = ['GET', 'HEAD'];
|
|
15
|
+
private const UNSTORED = ['no-store', 'private', 'no-cache'];
|
|
16
|
+
|
|
20
17
|
private mixed $client;
|
|
21
18
|
private ?array $options;
|
|
22
19
|
private array $store;
|
|
20
|
+
private string $secret = '';
|
|
23
21
|
|
|
24
22
|
public function __construct()
|
|
25
23
|
{
|
|
@@ -43,6 +41,7 @@ class ProjectNameCacheFeature extends ProjectNameBaseFeature
|
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
$this->store = [];
|
|
44
|
+
$this->secret = random_bytes(32);
|
|
46
45
|
|
|
47
46
|
$utility = $ctx->utility;
|
|
48
47
|
$inner = $utility->fetcher;
|
|
@@ -58,10 +57,17 @@ class ProjectNameCacheFeature extends ProjectNameBaseFeature
|
|
|
58
57
|
$methods = $this->options['methods'] ?? ['GET'];
|
|
59
58
|
|
|
60
59
|
if (!is_array($methods) || !in_array($method, $methods, true)) {
|
|
61
|
-
|
|
60
|
+
if (in_array($method, self::SAFE_METHODS, true)) {
|
|
61
|
+
return $inner($ctx, $url, $fetchdef);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
return $inner($ctx, $url, $fetchdef);
|
|
65
|
+
} finally {
|
|
66
|
+
$this->_invalidate($url);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
|
|
64
|
-
$key = $method . ' ' . $url;
|
|
70
|
+
$key = $method . ' ' . $url . ' ' . $this->_digest($fetchdef['headers'] ?? null);
|
|
65
71
|
$now = $this->_now();
|
|
66
72
|
$hit = $this->store[$key] ?? null;
|
|
67
73
|
|
|
@@ -80,9 +86,15 @@ class ProjectNameCacheFeature extends ProjectNameBaseFeature
|
|
|
80
86
|
|
|
81
87
|
if ($this->_cacheable($res, $err)) {
|
|
82
88
|
$snapshot = $this->_snapshot($res);
|
|
83
|
-
$ttl =
|
|
89
|
+
$ttl = self::lifetime($snapshot['headers'],
|
|
90
|
+
is_numeric($this->options['ttl'] ?? null) ? (float)$this->options['ttl'] : 5000.0);
|
|
91
|
+
if ($ttl <= 0) {
|
|
92
|
+
$this->_track('bypass');
|
|
93
|
+
return [$this->_replay($snapshot), null];
|
|
94
|
+
}
|
|
95
|
+
unset($this->store[$key]);
|
|
84
96
|
$this->_evict();
|
|
85
|
-
$this->store[$key] = ['expiry' => $now + $ttl, 'snapshot' => $snapshot];
|
|
97
|
+
$this->store[$key] = ['expiry' => $now + $ttl, 'scope' => self::scope($url), 'snapshot' => $snapshot];
|
|
86
98
|
$this->_track('miss');
|
|
87
99
|
return [$this->_replay($snapshot), null];
|
|
88
100
|
}
|
|
@@ -91,6 +103,79 @@ class ProjectNameCacheFeature extends ProjectNameBaseFeature
|
|
|
91
103
|
return [$res, $err];
|
|
92
104
|
}
|
|
93
105
|
|
|
106
|
+
private function _digest(mixed $headers): string
|
|
107
|
+
{
|
|
108
|
+
$pairs = [];
|
|
109
|
+
if (is_array($headers)) {
|
|
110
|
+
foreach ($headers as $name => $val) {
|
|
111
|
+
if ($val !== null) {
|
|
112
|
+
$pairs[] = [strtolower((string)$name), is_scalar($val) ? (string)$val : json_encode($val)];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
usort($pairs, fn($a, $b) => strcmp($a[0], $b[0]) ?: strcmp($a[1], $b[1]));
|
|
117
|
+
$text = '';
|
|
118
|
+
foreach ($pairs as [$name, $val]) {
|
|
119
|
+
$text .= $name . ':' . $val . "\n";
|
|
120
|
+
}
|
|
121
|
+
return hash_hmac('sha256', $text, $this->secret);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private function _invalidate(string $url): void
|
|
125
|
+
{
|
|
126
|
+
$path = self::scope($url);
|
|
127
|
+
$collection = self::parent($path);
|
|
128
|
+
foreach ($this->store as $key => $entry) {
|
|
129
|
+
if (self::under($entry['scope'], $path) || $entry['scope'] === $collection) {
|
|
130
|
+
unset($this->store[$key]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// The configured ttl capped by the response's Cache-Control; zero when
|
|
136
|
+
// the response may not be stored.
|
|
137
|
+
private static function lifetime(array $headers, float $ttl): float
|
|
138
|
+
{
|
|
139
|
+
$control = '';
|
|
140
|
+
foreach ($headers as $name => $val) {
|
|
141
|
+
if (strtolower((string)$name) === 'cache-control') {
|
|
142
|
+
$control = strtolower((string)$val);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
$life = $ttl;
|
|
146
|
+
foreach (explode(',', $control) as $part) {
|
|
147
|
+
$directive = trim($part);
|
|
148
|
+
if (in_array($directive, self::UNSTORED, true)) {
|
|
149
|
+
return 0.0;
|
|
150
|
+
}
|
|
151
|
+
if (preg_match('/^max-age\s*=\s*"?(\d+)"?$/', $directive, $age)) {
|
|
152
|
+
$life = min($life, (float)$age[1] * 1000.0);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return $life;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private static function scope(string $url): string
|
|
159
|
+
{
|
|
160
|
+
return rtrim(preg_split('/[?#]/', $url, 2)[0], '/');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private static function parent(string $scope): string
|
|
164
|
+
{
|
|
165
|
+
$scheme = strpos($scope, '://');
|
|
166
|
+
$root = $scheme === false ? 0 : strpos($scope, '/', $scheme + 3);
|
|
167
|
+
if ($root === false) {
|
|
168
|
+
return $scope;
|
|
169
|
+
}
|
|
170
|
+
$cut = strrpos($scope, '/');
|
|
171
|
+
return substr($scope, 0, max($cut === false ? 0 : $cut, $root));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private static function under(string $scope, string $prefix): bool
|
|
175
|
+
{
|
|
176
|
+
return $scope === $prefix || str_starts_with($scope, $prefix . '/');
|
|
177
|
+
}
|
|
178
|
+
|
|
94
179
|
private function _cacheable(mixed $res, mixed $err): bool
|
|
95
180
|
{
|
|
96
181
|
// A body the transport could not read as JSON passes through, for the operation to report.
|
|
@@ -313,6 +313,9 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
313
313
|
// gets. A provider ERROR refuses the request with the provider's
|
|
314
314
|
// own message; never an unauthenticated send.
|
|
315
315
|
$err = $this->resolve();
|
|
316
|
+
if ($err instanceof ProjectNameError) {
|
|
317
|
+
return [null, $err];
|
|
318
|
+
}
|
|
316
319
|
if (null !== $err) {
|
|
317
320
|
return [null, $ctx->make_error('secrets_provider', $err->getMessage())];
|
|
318
321
|
}
|
|
@@ -534,17 +537,10 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
534
537
|
$base = is_string($base) ? rtrim($base, '/') : '';
|
|
535
538
|
$url = $base . '/' . ltrim($x['path'], '/');
|
|
536
539
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
// make_options leaves system.fetch unset, so the exchange gets
|
|
542
|
-
// the SDK's own default HTTP path. That static consults neither
|
|
543
|
-
// system.fetch nor the wrapper chain, so there is no recursion,
|
|
544
|
-
// and it already answers the ['status' => .., 'json' => ..]
|
|
545
|
-
// shape read below.
|
|
546
|
-
$fetch = [ProjectNameFetcher::class, 'defaultHttpFetch'];
|
|
547
|
-
}
|
|
540
|
+
// The SDK's own transport, beneath every feature's wrapper: it holds
|
|
541
|
+
// the test feature's block and the GET-only guard.
|
|
542
|
+
$rootctx = $this->rootctx;
|
|
543
|
+
$fetch = static fn (string $at, array $fd): array => ProjectNameFetcher::call($rootctx, $at, $fd);
|
|
548
544
|
|
|
549
545
|
// The body is ENCODED, never concatenated: a refresh token (or a
|
|
550
546
|
// configured request-field name) carrying a quote, backslash or
|
|
@@ -555,16 +551,18 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
555
551
|
'secrets: token exchange request could not be encoded');
|
|
556
552
|
}
|
|
557
553
|
|
|
558
|
-
// Deliberately NOT the
|
|
559
|
-
//
|
|
560
|
-
//
|
|
561
|
-
//
|
|
554
|
+
// Deliberately NOT the wrapped transport: sending the token request
|
|
555
|
+
// back through it would recurse on the first expiry - and would
|
|
556
|
+
// route the exchange through the test mock, which knows nothing
|
|
557
|
+
// about it.
|
|
562
558
|
$fetchdef = [
|
|
563
559
|
'method' => $x['method'],
|
|
564
560
|
'headers' => ['content-type' => 'application/json'],
|
|
565
561
|
'body' => $body,
|
|
566
562
|
// Never followed by the client: a redirect would carry the refresh token on.
|
|
567
563
|
'redirect' => 'manual',
|
|
564
|
+
// Its own bound, in milliseconds: the timeout feature's wrapper is above it.
|
|
565
|
+
'timeout' => 30000,
|
|
568
566
|
];
|
|
569
567
|
|
|
570
568
|
[$res, $err] = $fetch($url, $fetchdef);
|
|
@@ -580,6 +578,11 @@ class ProjectNameSecretsFeature extends ProjectNameBaseFeature
|
|
|
580
578
|
[$res, $err] = $fetch($at, $fetchdef);
|
|
581
579
|
}
|
|
582
580
|
|
|
581
|
+
// The transport's own refusal, the GET-only guard's among them, is
|
|
582
|
+
// the operation's error.
|
|
583
|
+
if ($err instanceof ProjectNameError) {
|
|
584
|
+
throw $err;
|
|
585
|
+
}
|
|
583
586
|
if (null !== $err) {
|
|
584
587
|
throw new \Voxgig\Sekreto\SekretoError(
|
|
585
588
|
'secrets: token exchange failed: ' . self::errtext($err) . ' from ' . $url);
|
|
@@ -169,12 +169,31 @@ class FeatureCorpusTest extends TestCase
|
|
|
169
169
|
return $out;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
private static function invoke($client, array $op, array $ctrl)
|
|
172
|
+
private static function invoke($client, array $op, array $ctrl, array $args = [])
|
|
173
173
|
{
|
|
174
174
|
$acc = $op['accessor'];
|
|
175
175
|
$ent = $client->$acc();
|
|
176
176
|
$fn = $op['op'];
|
|
177
|
-
return $ent->$fn(
|
|
177
|
+
return $ent->$fn($args, $ctrl);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private const ITEM_ARGS = ['id' => 'corpus-item'];
|
|
181
|
+
|
|
182
|
+
/** A write of one entity (#ITEM) that completes when driven with ITEM_ARGS. */
|
|
183
|
+
private static function usableItem(string $accessor): ?array
|
|
184
|
+
{
|
|
185
|
+
foreach (self::candidates(self::buildClient([])) as $cand) {
|
|
186
|
+
if ($cand['accessor'] !== $accessor || !in_array($cand['op'], ['update', 'patch', 'remove'], true)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
self::invoke(self::buildClient([]), $cand, [], self::ITEM_ARGS);
|
|
191
|
+
} catch (\Throwable $e) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
return $cand;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
178
197
|
}
|
|
179
198
|
|
|
180
199
|
/**
|
|
@@ -200,6 +219,51 @@ class FeatureCorpusTest extends TestCase
|
|
|
200
219
|
return $picked;
|
|
201
220
|
}
|
|
202
221
|
|
|
222
|
+
private const READ_OPS = ['list', 'load'];
|
|
223
|
+
private const WRITE_OPS = ['create', 'update', 'patch', 'remove'];
|
|
224
|
+
|
|
225
|
+
/** A read and a write of one entity (#READ, #WRITE), each driven as usableOps drives an op. */
|
|
226
|
+
private static function usablePair(): ?array
|
|
227
|
+
{
|
|
228
|
+
$found = [];
|
|
229
|
+
foreach (self::candidates(self::buildClient([])) as $cand) {
|
|
230
|
+
$role = in_array($cand['op'], self::READ_OPS, true) ? 'read'
|
|
231
|
+
: (in_array($cand['op'], self::WRITE_OPS, true) ? 'write' : null);
|
|
232
|
+
if (null === $role || isset($found[$cand['accessor']][$role])) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
self::invoke(self::buildClient([]), $cand, []);
|
|
237
|
+
} catch (\Throwable $e) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
$found[$cand['accessor']][$role] = $cand;
|
|
241
|
+
if (isset($found[$cand['accessor']]['read'], $found[$cand['accessor']]['write'])) {
|
|
242
|
+
return $found[$cand['accessor']];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** One step: it may wait, may add request headers, and may pass `args` as the first argument. */
|
|
249
|
+
private static function step($client, array $op, array $step, array $ctrl)
|
|
250
|
+
{
|
|
251
|
+
if (isset($step['wait'])) {
|
|
252
|
+
usleep((int)($step['wait'] * 1000));
|
|
253
|
+
}
|
|
254
|
+
$args = is_array($step['args'] ?? null) ? $step['args'] : [];
|
|
255
|
+
if (!isset($step['headers'])) {
|
|
256
|
+
return self::invoke($client, $op, $ctrl, $args);
|
|
257
|
+
}
|
|
258
|
+
$prior = $client->options;
|
|
259
|
+
$client->options['headers'] = array_merge($prior['headers'] ?? [], $step['headers']);
|
|
260
|
+
try {
|
|
261
|
+
return self::invoke($client, $op, $ctrl, $args);
|
|
262
|
+
} finally {
|
|
263
|
+
$client->options = $prior;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
203
267
|
/** Replace #OPn throughout a case, keys included. */
|
|
204
268
|
private static function resolve($node, array $tokens)
|
|
205
269
|
{
|
|
@@ -387,6 +451,21 @@ class FeatureCorpusTest extends TestCase
|
|
|
387
451
|
foreach ($ops as $o) {
|
|
388
452
|
$byKey[$o['key']] = $o;
|
|
389
453
|
}
|
|
454
|
+
$pair = self::usablePair();
|
|
455
|
+
foreach ($pair ?? [] as $o) {
|
|
456
|
+
$byKey[$o['key']] = $o;
|
|
457
|
+
}
|
|
458
|
+
$item = null === $pair ? null : self::usableItem($pair['read']['accessor']);
|
|
459
|
+
if (null !== $item) {
|
|
460
|
+
$byKey[$item['key']] = $item;
|
|
461
|
+
}
|
|
462
|
+
$other = null;
|
|
463
|
+
foreach (null === $pair ? [] : $ops as $o) {
|
|
464
|
+
if ($o['accessor'] !== $pair['read']['accessor']) {
|
|
465
|
+
$other = $o;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
390
469
|
|
|
391
470
|
$ran = 0;
|
|
392
471
|
foreach ($cases as $raw) {
|
|
@@ -397,6 +476,27 @@ class FeatureCorpusTest extends TestCase
|
|
|
397
476
|
continue;
|
|
398
477
|
}
|
|
399
478
|
|
|
479
|
+
$paired = 1 === preg_match('/#(READ|WRITE|ITEM|OTHER)\b/', json_encode($raw));
|
|
480
|
+
if ($paired && null === $pair) {
|
|
481
|
+
fwrite(STDERR, sprintf(
|
|
482
|
+
"skip \"%s\": needs a read and a write of one entity, this SDK offers none\n",
|
|
483
|
+
$raw['name'] ?? ''));
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
$lacking = null;
|
|
488
|
+
foreach (['#ITEM' => $item, '#OTHER' => $other] as $tok => $found) {
|
|
489
|
+
if ($paired && null === $found && 1 === preg_match('/' . $tok . '\b/', json_encode($raw))) {
|
|
490
|
+
$lacking = $tok;
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (null !== $lacking) {
|
|
495
|
+
fwrite(STDERR, sprintf("skip \"%s\": needs %s, which this SDK cannot drive\n",
|
|
496
|
+
$raw['name'] ?? '', $lacking));
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
|
|
400
500
|
$missing = self::missingFeature($raw, $have);
|
|
401
501
|
if (null !== $missing) {
|
|
402
502
|
fwrite(STDERR, sprintf(
|
|
@@ -409,6 +509,16 @@ class FeatureCorpusTest extends TestCase
|
|
|
409
509
|
for ($i = 0; $i < $need; $i++) {
|
|
410
510
|
$tokens['#OP' . ($i + 1)] = $ops[$i]['key'];
|
|
411
511
|
}
|
|
512
|
+
if ($paired) {
|
|
513
|
+
$tokens['#READ'] = $pair['read']['key'];
|
|
514
|
+
$tokens['#WRITE'] = $pair['write']['key'];
|
|
515
|
+
if (null !== $item) {
|
|
516
|
+
$tokens['#ITEM'] = $item['key'];
|
|
517
|
+
}
|
|
518
|
+
if (null !== $other) {
|
|
519
|
+
$tokens['#OTHER'] = $other['key'];
|
|
520
|
+
}
|
|
521
|
+
}
|
|
412
522
|
$kase = self::resolve($raw, $tokens);
|
|
413
523
|
$label = (string)($kase['name'] ?? '');
|
|
414
524
|
$ran++;
|
|
@@ -424,7 +534,7 @@ class FeatureCorpusTest extends TestCase
|
|
|
424
534
|
$wanterr = $step['err'] ?? null;
|
|
425
535
|
|
|
426
536
|
try {
|
|
427
|
-
self::
|
|
537
|
+
self::step($client, $op, $step, $ctrl);
|
|
428
538
|
$this->assertNull($wanterr,
|
|
429
539
|
"$label: {$step['op']} was expected to fail, and did not");
|
|
430
540
|
} catch (\PHPUnit\Framework\AssertionFailedError $e) {
|
|
@@ -763,6 +763,74 @@ class FeatureTest extends TestCase
|
|
|
763
763
|
$this->assertCount(3, $rec->calls);
|
|
764
764
|
}
|
|
765
765
|
|
|
766
|
+
public function test_cache_keys_on_the_request_headers(): void
|
|
767
|
+
{
|
|
768
|
+
$this->needs('cache');
|
|
769
|
+
$rec = new FtRecorder();
|
|
770
|
+
$h = new FtHarness([
|
|
771
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
772
|
+
], $rec->server());
|
|
773
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['x-tenant' => 'tenant-a']]);
|
|
774
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['X-Tenant' => 'tenant-b']]);
|
|
775
|
+
$this->assertCount(2, $rec->calls);
|
|
776
|
+
$h->op(['op' => 'load', 'path' => '/w/1', 'headers' => ['x-tenant' => 'tenant-b']]);
|
|
777
|
+
$this->assertCount(2, $rec->calls);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
public function test_cache_a_write_drops_its_collection(): void
|
|
781
|
+
{
|
|
782
|
+
$this->needs('cache');
|
|
783
|
+
$rec = new FtRecorder();
|
|
784
|
+
$h = new FtHarness([
|
|
785
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
786
|
+
], $rec->server());
|
|
787
|
+
$paths = ['/w/1', '/w', '/w/1/part', '/other/1', '/w/2'];
|
|
788
|
+
foreach ($paths as $p) {
|
|
789
|
+
$h->op(['op' => 'load', 'path' => $p]);
|
|
790
|
+
}
|
|
791
|
+
$h->op(['op' => 'update', 'method' => 'PUT', 'path' => '/w/1']);
|
|
792
|
+
foreach ($paths as $p) {
|
|
793
|
+
$h->op(['op' => 'load', 'path' => $p]);
|
|
794
|
+
}
|
|
795
|
+
$this->assertCount(9, $rec->calls);
|
|
796
|
+
$this->assertSame(2, $h->client->_cache['hit']);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
public function test_cache_control_prevents_storing(): void
|
|
800
|
+
{
|
|
801
|
+
$this->needs('cache');
|
|
802
|
+
foreach (['no-store', 'private', 'No-Cache', 'max-age=60, private'] as $control) {
|
|
803
|
+
$rec = new FtRecorder(function (int $_n) use ($control) {
|
|
804
|
+
return FtHarness::response(200, ['ok' => true], ['Cache-Control' => $control]);
|
|
805
|
+
});
|
|
806
|
+
$h = new FtHarness([
|
|
807
|
+
['name' => 'cache', 'options' => ['ttl' => 10000]],
|
|
808
|
+
], $rec->server());
|
|
809
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
810
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
811
|
+
$this->assertCount(2, $rec->calls, $control);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
public function test_cache_max_age_caps_the_ttl(): void
|
|
816
|
+
{
|
|
817
|
+
$this->needs('cache');
|
|
818
|
+
$clock = new FtClock();
|
|
819
|
+
$rec = new FtRecorder(function (int $_n) {
|
|
820
|
+
return FtHarness::response(200, ['ok' => true], ['cache-control' => 'max-age=1']);
|
|
821
|
+
});
|
|
822
|
+
$h = new FtHarness([
|
|
823
|
+
['name' => 'cache', 'options' => ['ttl' => 10000, 'now' => $clock->now()]],
|
|
824
|
+
], $rec->server());
|
|
825
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
826
|
+
$clock->advance(500);
|
|
827
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
828
|
+
$this->assertCount(1, $rec->calls);
|
|
829
|
+
$clock->advance(600);
|
|
830
|
+
$h->op(['op' => 'load', 'path' => '/w']);
|
|
831
|
+
$this->assertCount(2, $rec->calls);
|
|
832
|
+
}
|
|
833
|
+
|
|
766
834
|
|
|
767
835
|
// --- idempotency ----------------------------------------------------------
|
|
768
836
|
|
|
@@ -172,20 +172,13 @@ class ProjectNameClean
|
|
|
172
172
|
}));
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
// A context without
|
|
175
|
+
// A context without a registry (make_error is reached with a bare one)
|
|
176
176
|
// falls back to the schema defaults, so nothing leaves raw for want of a
|
|
177
177
|
// constructor.
|
|
178
178
|
private static function config_of(?ProjectNameContext $ctx): \stdClass
|
|
179
179
|
{
|
|
180
|
-
$
|
|
181
|
-
|
|
182
|
-
$derived = $ctx->options['__derived__']['clean'] ?? null;
|
|
183
|
-
}
|
|
184
|
-
if ($derived instanceof \stdClass) {
|
|
185
|
-
return $derived;
|
|
186
|
-
}
|
|
187
|
-
if (is_array($derived)) {
|
|
188
|
-
return (object)$derived;
|
|
180
|
+
if (null !== $ctx && $ctx->cleancfg instanceof \stdClass) {
|
|
181
|
+
return $ctx->cleancfg;
|
|
189
182
|
}
|
|
190
183
|
require_once __DIR__ . '/../schema.php';
|
|
191
184
|
return self::config(\Voxgig\Struct\Struct::getprop(ProjectNameSchema::optspec(), 'clean'));
|
|
@@ -166,12 +166,16 @@ class ProjectNameFetcher
|
|
|
166
166
|
$header_lines[] = 'User-Agent: ' . self::DEFAULT_USER_AGENT;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
// A bound in milliseconds, for a caller beneath the timeout feature.
|
|
170
|
+
$bound = $fetchdef['timeout'] ?? null;
|
|
171
|
+
$bound = is_numeric($bound) && 0 < $bound ? (int)$bound : 30000;
|
|
172
|
+
|
|
169
173
|
// Prefer cURL when available — its header capture is reliable across
|
|
170
174
|
// PHP versions, while file_get_contents + custom stream wrappers
|
|
171
175
|
// don't propagate $http_response_header for user-defined wrappers
|
|
172
176
|
// in PHP 8.3+.
|
|
173
177
|
if (function_exists('curl_init')) {
|
|
174
|
-
return self::curlFetch($fullurl, $method_str, $body_str, $header_lines);
|
|
178
|
+
return self::curlFetch($fullurl, $method_str, $body_str, $header_lines, $bound);
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
$opts = [
|
|
@@ -179,6 +183,7 @@ class ProjectNameFetcher
|
|
|
179
183
|
'method' => $method_str,
|
|
180
184
|
'ignore_errors' => true,
|
|
181
185
|
'follow_location' => 0,
|
|
186
|
+
'timeout' => $bound / 1000,
|
|
182
187
|
],
|
|
183
188
|
];
|
|
184
189
|
|
|
@@ -280,13 +285,13 @@ class ProjectNameFetcher
|
|
|
280
285
|
return [$decoded, null];
|
|
281
286
|
}
|
|
282
287
|
|
|
283
|
-
private static function curlFetch(string $fullurl, string $method, $body_str, array $header_lines): array
|
|
288
|
+
private static function curlFetch(string $fullurl, string $method, $body_str, array $header_lines, int $bound): array
|
|
284
289
|
{
|
|
285
290
|
$ch = self::curlHandle($fullurl);
|
|
286
291
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
287
292
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
288
293
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
|
289
|
-
curl_setopt($ch,
|
|
294
|
+
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $bound);
|
|
290
295
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
291
296
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
|
292
297
|
// '' offers every encoding this cURL decodes, and decodes it: a
|
|
@@ -60,9 +60,7 @@ class ProjectNameMakeOptions
|
|
|
60
60
|
$cfgclean = $block($cfgopts['clean'] ?? null);
|
|
61
61
|
$specclean = $block(\Voxgig\Struct\Struct::getprop($optspec, 'clean'));
|
|
62
62
|
$cleancfg = ProjectNameClean::config(array_merge($specclean, $cfgclean, $rawclean));
|
|
63
|
-
$cleanctx = new ProjectNameContext([
|
|
64
|
-
'options' => ['__derived__' => ['clean' => $cleancfg]],
|
|
65
|
-
], null);
|
|
63
|
+
$cleanctx = new ProjectNameContext(['cleancfg' => $cleancfg], null);
|
|
66
64
|
$rawopts = is_object($options) ? get_object_vars($options)
|
|
67
65
|
: (is_array($options) ? $options : []);
|
|
68
66
|
unset($rawopts['clean']);
|
|
@@ -314,10 +312,10 @@ class ProjectNameMakeOptions
|
|
|
314
312
|
unset($merged['clean']);
|
|
315
313
|
ProjectNameClean::add_options($cleanctx, $merged);
|
|
316
314
|
|
|
317
|
-
$opts['__derived__'] = [
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
315
|
+
$opts['__derived__'] = ['featureorder' => $featureorder];
|
|
316
|
+
|
|
317
|
+
// Beside the options, not in them: options_map hands them to callers.
|
|
318
|
+
$ctx->cleancfg = $cleancfg;
|
|
321
319
|
|
|
322
320
|
return $opts;
|
|
323
321
|
}
|
|
@@ -95,6 +95,10 @@ class ProjectNameContext:
|
|
|
95
95
|
else:
|
|
96
96
|
self.options = None
|
|
97
97
|
|
|
98
|
+
# The clean registry, beside the options rather than in them.
|
|
99
|
+
cc = get_ctx_prop(ctxmap, "cleancfg")
|
|
100
|
+
self.cleancfg = cc if cc is not None else getattr(basectx, "cleancfg", None)
|
|
101
|
+
|
|
98
102
|
# Entity
|
|
99
103
|
e = get_ctx_prop(ctxmap, "entity")
|
|
100
104
|
if e is not None:
|