@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.
Files changed (180) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/package.json +1 -1
  3. package/project/.sdk/model/feature/cache.aontu +6 -4
  4. package/project/.sdk/model/target/lua.aontu +6 -0
  5. package/project/.sdk/src/cmp/c/Config_c.ts +3 -134
  6. package/project/.sdk/src/cmp/c/TestClean_c.ts +14 -0
  7. package/project/.sdk/src/cmp/clojure/TestClean_clojure.ts +10 -5
  8. package/project/.sdk/src/cmp/cpp/TestClean_cpp.ts +13 -0
  9. package/project/.sdk/src/cmp/csharp/TestClean_csharp.ts +9 -0
  10. package/project/.sdk/src/cmp/elixir/TestClean_elixir.ts +11 -3
  11. package/project/.sdk/src/cmp/go/TestClean_go.ts +39 -3
  12. package/project/.sdk/src/cmp/java/TestClean_java.ts +8 -0
  13. package/project/.sdk/src/cmp/js/TestClean_js.ts +13 -5
  14. package/project/.sdk/src/cmp/kotlin/TestClean_kotlin.ts +22 -0
  15. package/project/.sdk/src/cmp/lua/TestClean_lua.ts +12 -3
  16. package/project/.sdk/src/cmp/ocaml/TestClean_ocaml.ts +18 -4
  17. package/project/.sdk/src/cmp/perl/TestClean_perl.ts +12 -3
  18. package/project/.sdk/src/cmp/php/TestClean_php.ts +10 -3
  19. package/project/.sdk/src/cmp/py/TestClean_py.ts +10 -3
  20. package/project/.sdk/src/cmp/rb/TestClean_rb.ts +10 -3
  21. package/project/.sdk/src/cmp/rust/TestClean_rust.ts +10 -0
  22. package/project/.sdk/src/cmp/scala/TestClean_scala.ts +34 -0
  23. package/project/.sdk/src/cmp/swift/TestClean_swift.ts +20 -10
  24. package/project/.sdk/src/cmp/ts/TestClean_ts.ts +13 -5
  25. package/project/.sdk/src/cmp/zig/TestClean_zig.ts +12 -0
  26. package/project/.sdk/tm/c/core/context.c +1 -0
  27. package/project/.sdk/tm/c/core/sdk.h +7 -4
  28. package/project/.sdk/tm/c/feature/cache.c +243 -13
  29. package/project/.sdk/tm/c/feature/secrets.c +27 -38
  30. package/project/.sdk/tm/c/tests/feature_test.c +104 -0
  31. package/project/.sdk/tm/c/utility/clean.c +26 -33
  32. package/project/.sdk/tm/c/utility/make_options.c +9 -8
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +14 -11
  34. package/project/.sdk/tm/clojure/src/sdk/client.clj +3 -1
  35. package/project/.sdk/tm/clojure/src/sdk/core.clj +19 -11
  36. package/project/.sdk/tm/clojure/src/sdk/features.clj +81 -10
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +33 -0
  38. package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +1 -0
  39. package/project/.sdk/tm/cpp/Makefile +5 -0
  40. package/project/.sdk/tm/cpp/core/types.hpp +11 -4
  41. package/project/.sdk/tm/cpp/feature/audit.hpp +6 -7
  42. package/project/.sdk/tm/cpp/feature/cache.hpp +188 -9
  43. package/project/.sdk/tm/cpp/feature/secrets.hpp +12 -0
  44. package/project/.sdk/tm/cpp/test/feature_test.cpp +99 -0
  45. package/project/.sdk/tm/cpp/utility/pipeline.hpp +9 -7
  46. package/project/.sdk/tm/csharp/core/Context.cs +4 -0
  47. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +126 -12
  48. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +9 -27
  49. package/project/.sdk/tm/csharp/test/FeatureTest.cs +76 -0
  50. package/project/.sdk/tm/csharp/utility/Clean.cs +5 -10
  51. package/project/.sdk/tm/csharp/utility/Fetcher.cs +7 -1
  52. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +5 -12
  53. package/project/.sdk/tm/elixir/lib/projectname/context.ex +2 -0
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +146 -30
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +10 -56
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +18 -12
  57. package/project/.sdk/tm/elixir/test/feature_test.exs +61 -0
  58. package/project/.sdk/tm/go/core/context.go +6 -0
  59. package/project/.sdk/tm/go/feature/cache_feature.go +131 -4
  60. package/project/.sdk/tm/go/feature/secrets_feature.go +17 -71
  61. package/project/.sdk/tm/go/test/feature_corpus_test.go +150 -2
  62. package/project/.sdk/tm/go/test/feature_test.go +61 -0
  63. package/project/.sdk/tm/go/utility/clean.go +5 -7
  64. package/project/.sdk/tm/go/utility/fetcher.go +11 -0
  65. package/project/.sdk/tm/go/utility/make_options.go +5 -7
  66. package/project/.sdk/tm/java/core/Context.java +9 -0
  67. package/project/.sdk/tm/java/feature/CacheFeature.java +123 -17
  68. package/project/.sdk/tm/java/feature/SecretsFeature.java +9 -92
  69. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +141 -2
  70. package/project/.sdk/tm/java/test/FeatureTest.java +60 -0
  71. package/project/.sdk/tm/java/utility/Clean.java +6 -10
  72. package/project/.sdk/tm/java/utility/Fetcher.java +5 -1
  73. package/project/.sdk/tm/java/utility/MakeOptions.java +3 -1
  74. package/project/.sdk/tm/js/src/Context.js +4 -0
  75. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +118 -11
  76. package/project/.sdk/tm/js/src/feature/cost/CostFeature.js +3 -2
  77. package/project/.sdk/tm/js/src/feature/metrics/MetricsFeature.js +1 -1
  78. package/project/.sdk/tm/js/src/feature/paging/PagingFeature.js +4 -4
  79. package/project/.sdk/tm/js/src/feature/rbac/RbacFeature.js +4 -4
  80. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +16 -6
  81. package/project/.sdk/tm/js/src/feature/validate/ValidateFeature.js +2 -1
  82. package/project/.sdk/tm/js/src/utility/CleanUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +6 -6
  84. package/project/.sdk/tm/js/test/feature/Corpus.test.js +100 -2
  85. package/project/.sdk/tm/js/test/feature/harness.js +3 -3
  86. package/project/.sdk/tm/js/test/pipeline.test.js +1 -1
  87. package/project/.sdk/tm/kotlin/core/Context.kt +3 -0
  88. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +102 -7
  89. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +10 -20
  90. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +59 -0
  91. package/project/.sdk/tm/kotlin/utility/CoreUtil.kt +5 -5
  92. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +4 -0
  93. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +3 -1
  94. package/project/.sdk/tm/lua/core/context.lua +6 -0
  95. package/project/.sdk/tm/lua/feature/cache_feature.lua +212 -15
  96. package/project/.sdk/tm/lua/feature/secrets_feature.lua +15 -80
  97. package/project/.sdk/tm/lua/test/feature_test.lua +81 -0
  98. package/project/.sdk/tm/lua/utility/clean.lua +6 -9
  99. package/project/.sdk/tm/lua/utility/fetcher.lua +9 -0
  100. package/project/.sdk/tm/lua/utility/make_options.lua +5 -5
  101. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +21 -6
  102. package/project/.sdk/tm/ocaml/sdk_features.ml +106 -8
  103. package/project/.sdk/tm/ocaml/sdk_runtime.ml +13 -10
  104. package/project/.sdk/tm/ocaml/sdk_types.ml +2 -0
  105. package/project/.sdk/tm/ocaml/test/t_feature.ml +35 -1
  106. package/project/.sdk/tm/perl/core/context.pm +3 -0
  107. package/project/.sdk/tm/perl/feature/audit_feature.pm +4 -7
  108. package/project/.sdk/tm/perl/feature/cache_feature.pm +111 -15
  109. package/project/.sdk/tm/perl/feature/secrets_feature.pm +13 -18
  110. package/project/.sdk/tm/perl/t/feature.t +66 -0
  111. package/project/.sdk/tm/perl/t/feature_corpus.t +80 -4
  112. package/project/.sdk/tm/perl/utility/clean.pm +6 -8
  113. package/project/.sdk/tm/perl/utility/fetcher.pm +4 -0
  114. package/project/.sdk/tm/perl/utility/make_options.pm +5 -5
  115. package/project/.sdk/tm/php/core/Context.php +4 -0
  116. package/project/.sdk/tm/php/feature/CacheFeature.php +98 -13
  117. package/project/.sdk/tm/php/feature/SecretsFeature.php +18 -15
  118. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +113 -3
  119. package/project/.sdk/tm/php/test/FeatureTest.php +68 -0
  120. package/project/.sdk/tm/php/utility/Clean.php +3 -10
  121. package/project/.sdk/tm/php/utility/Fetcher.php +8 -3
  122. package/project/.sdk/tm/php/utility/MakeOptions.php +5 -7
  123. package/project/.sdk/tm/py/pkg/core/context.py +4 -0
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +79 -13
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +15 -66
  126. package/project/.sdk/tm/py/pkg/utility/clean.py +4 -10
  127. package/project/.sdk/tm/py/pkg/utility/make_options.py +8 -9
  128. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +23 -9
  129. package/project/.sdk/tm/py/test/test_feature.py +50 -0
  130. package/project/.sdk/tm/py/test/test_feature_corpus.py +88 -3
  131. package/project/.sdk/tm/rb/core/context.rb +4 -1
  132. package/project/.sdk/tm/rb/feature/audit_feature.rb +6 -5
  133. package/project/.sdk/tm/rb/feature/cache_feature.rb +75 -11
  134. package/project/.sdk/tm/rb/feature/secrets_feature.rb +9 -64
  135. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +85 -3
  136. package/project/.sdk/tm/rb/test/feature_test.rb +74 -0
  137. package/project/.sdk/tm/rb/utility/clean.rb +6 -7
  138. package/project/.sdk/tm/rb/utility/fetcher.rb +6 -0
  139. package/project/.sdk/tm/rb/utility/make_options.rb +5 -5
  140. package/project/.sdk/tm/rust/core/context.rs +8 -0
  141. package/project/.sdk/tm/rust/feature/cache.rs +120 -3
  142. package/project/.sdk/tm/rust/feature/secrets.rs +36 -98
  143. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +3 -3
  144. package/project/.sdk/tm/rust/tests/feature_test.rs +100 -0
  145. package/project/.sdk/tm/rust/utility/clean.rs +35 -43
  146. package/project/.sdk/tm/rust/utility/fetcher.rs +6 -0
  147. package/project/.sdk/tm/rust/utility/make_options.rs +8 -11
  148. package/project/.sdk/tm/scala/core/Context.scala +4 -0
  149. package/project/.sdk/tm/scala/feature/CacheFeature.scala +117 -11
  150. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +11 -24
  151. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +28 -0
  152. package/project/.sdk/tm/scala/utility/Fetcher.scala +5 -0
  153. package/project/.sdk/tm/scala/utility/Make.scala +3 -1
  154. package/project/.sdk/tm/scala/utility/Misc.scala +5 -8
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Context.swift +3 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +122 -11
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +9 -13
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +4 -0
  159. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +5 -4
  160. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +4 -5
  161. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +55 -0
  162. package/project/.sdk/tm/ts/src/Context.ts +4 -0
  163. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +115 -4
  164. package/project/.sdk/tm/ts/src/feature/cost/CostFeature.ts +3 -2
  165. package/project/.sdk/tm/ts/src/feature/metrics/MetricsFeature.ts +1 -1
  166. package/project/.sdk/tm/ts/src/feature/paging/PagingFeature.ts +4 -4
  167. package/project/.sdk/tm/ts/src/feature/rbac/RbacFeature.ts +4 -4
  168. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +14 -2
  169. package/project/.sdk/tm/ts/src/feature/validate/ValidateFeature.ts +2 -1
  170. package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +1 -1
  171. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +6 -6
  172. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +101 -2
  173. package/project/.sdk/tm/ts/test/feature/harness.ts +3 -3
  174. package/project/.sdk/tm/ts/test/pipeline.test.ts +1 -1
  175. package/project/.sdk/tm/zig/core/context.zig +5 -0
  176. package/project/.sdk/tm/zig/core/utility.zig +11 -9
  177. package/project/.sdk/tm/zig/feature/cache.zig +144 -13
  178. package/project/.sdk/tm/zig/feature/secrets.zig +6 -1
  179. package/project/.sdk/tm/zig/test/feature_test.zig +65 -0
  180. package/project/sdkgen-package.json +1 -1
@@ -26,7 +26,7 @@ function makeOptions(ctx: Context) {
26
26
  const layer = (b: any) => null != b && 'object' === typeof b && !Array.isArray(b) ? b : {}
27
27
  const cleancfg = makeCleanConfig(merge([{}, (OPTSPEC as any).clean,
28
28
  struct.clone(layer(cfgopts.clean)), layer(opts.clean)]))
29
- const cleanctx: any = { options: { __derived__: { clean: cleancfg } } }
29
+ const cleanctx: any = { cleancfg }
30
30
  cleanAddSensitive(cleanctx, settings(opts))
31
31
  for (const raw of [...splitvalues(cfgopts.clean?.values), ...splitvalues(opts.clean?.values)]) {
32
32
  cleanAdd(cleanctx, raw)
@@ -111,13 +111,13 @@ function makeOptions(ctx: Context) {
111
111
  featureorder = names
112
112
  }
113
113
 
114
- opts.__derived__ = {
115
- clean: cleancfg,
116
- featureorder,
117
- }
114
+ opts.__derived__ = { featureorder }
115
+
116
+ // Beside the options, not in them: options() hands them to callers.
117
+ ctx.cleancfg = cleancfg
118
118
 
119
119
  // Again over the merged result: the config's own defaults can carry one.
120
- cleanAddSensitive({ options: opts } as any, settings(opts))
120
+ cleanAddSensitive(cleanctx, settings(opts))
121
121
 
122
122
  return opts
123
123
  }
@@ -119,6 +119,66 @@ async function usableOps(want: number): Promise<OpRef[]> {
119
119
  }
120
120
 
121
121
 
122
+
123
+ const READ_OPS = ['list', 'load']
124
+ const WRITE_OPS = ['create', 'update', 'patch', 'remove']
125
+
126
+
127
+ // A read and a write of one entity (#READ, #WRITE), each driven as usableOps
128
+ // drives an op; #ITEM is a write of the same entity driven with ITEM_ARGS.
129
+ async function usablePair(): Promise<{ read: OpRef, write: OpRef, item?: OpRef } | undefined> {
130
+ const found: Record<string, { read?: OpRef, write?: OpRef }> = {}
131
+ for (const cand of candidates(makeClient({}))) {
132
+ const role: 'read' | 'write' | '' = READ_OPS.includes(cand.op) ? 'read' : WRITE_OPS.includes(cand.op) ? 'write' : ''
133
+ const seen = found[cand.entity] = found[cand.entity] || {}
134
+ if ('' === role || null != seen[role]) { continue }
135
+ try {
136
+ await makeClient({})[cand.accessor]()[cand.op]({}, {})
137
+ }
138
+ catch (e) { continue }
139
+ seen[role] = cand
140
+ if (null != seen.read && null != seen.write) {
141
+ return { read: seen.read, write: seen.write, item: await usableItem(cand.entity) }
142
+ }
143
+ }
144
+ return undefined
145
+ }
146
+
147
+
148
+ const ITEM_ARGS = { id: 'corpus-item' }
149
+
150
+ async function usableItem(entity: string): Promise<OpRef | undefined> {
151
+ for (const cand of candidates(makeClient({}))) {
152
+ if (entity !== cand.entity || !['update', 'patch', 'remove'].includes(cand.op)) { continue }
153
+ try {
154
+ await makeClient({})[cand.accessor]()[cand.op]({ ...ITEM_ARGS }, {})
155
+ return cand
156
+ }
157
+ catch (e) { continue }
158
+ }
159
+ return undefined
160
+ }
161
+
162
+
163
+ // A step may wait before its call, may add request headers for its call, and
164
+ // may pass `args` as the operation's first argument.
165
+ async function runStep(client: any, ref: OpRef, step: any) {
166
+ if (null != step.wait) {
167
+ await new Promise((resolve) => setTimeout(resolve, step.wait))
168
+ }
169
+ const options = client._rootctx.options
170
+ const prior = options.headers
171
+ if (null != step.headers) {
172
+ options.headers = { ...(prior || {}), ...step.headers }
173
+ }
174
+ try {
175
+ await client[ref.accessor]()[ref.op]({ ...(step.args || {}) }, step.ctrl || {})
176
+ }
177
+ finally {
178
+ options.headers = prior
179
+ }
180
+ }
181
+
122
182
  // Replace #OP1/#OP2 throughout a case, keys included.
123
183
  function resolve(node: any, tokens: Record<string, string>): any {
124
184
  if ('string' === typeof node) {
@@ -132,7 +192,9 @@ function resolve(node: any, tokens: Record<string, string>): any {
132
192
  if (null != node && 'object' === typeof node) {
133
193
  const out: any = {}
134
194
  for (const k of Object.keys(node)) {
135
- out[resolve(k, tokens)] = resolve(node[k], tokens)
195
+ Object.defineProperty(out, resolve(k, tokens), {
196
+ value: resolve(node[k], tokens), enumerable: true, writable: true, configurable: true,
197
+ })
136
198
  }
137
199
  return out
138
200
  }
@@ -140,6 +202,15 @@ function resolve(node: any, tokens: Record<string, string>): any {
140
202
  }
141
203
 
142
204
 
205
+ // No case may write onto the shared prototypes, as a `__proto__` key can.
206
+ function shared(): string {
207
+ return [Object.prototype, Object]
208
+ .map((o) => Object.getOwnPropertyNames(o).sort().join(',')).join(' | ')
209
+ }
210
+
211
+ const PRISTINE = shared()
212
+
213
+
143
214
  // Which #OPn tokens a case uses. A case wanting more operations than this SDK
144
215
  // has is skipped rather than failed.
145
216
  function tokensUsed(kase: any): number {
@@ -177,6 +248,7 @@ describe('FeatureCorpus', () => {
177
248
  let corpus: any
178
249
  let ops: OpRef[] = []
179
250
  let byKey: Record<string, OpRef> = {}
251
+ let pair: { read: OpRef, write: OpRef, item?: OpRef } | undefined
180
252
 
181
253
 
182
254
  before(async () => {
@@ -184,6 +256,10 @@ describe('FeatureCorpus', () => {
184
256
  ops = await usableOps(2)
185
257
  byKey = {}
186
258
  for (const o of ops) { byKey[o.key] = o }
259
+ pair = await usablePair()
260
+ for (const o of pair ? [pair.read, pair.write, pair.item] : []) {
261
+ if (null != o) { byKey[o.key] = o }
262
+ }
187
263
  })
188
264
 
189
265
 
@@ -234,6 +310,21 @@ describe('FeatureCorpus', () => {
234
310
  continue
235
311
  }
236
312
 
313
+ const paired = /#(READ|WRITE|ITEM|OTHER)\b/.test(JSON.stringify(raw))
314
+ if (paired && null == pair) {
315
+ t.diagnostic(`skip "${raw.name}": needs a read and a write of one entity, this SDK offers none`)
316
+ continue
317
+ }
318
+ const other = null == pair ? undefined :
319
+ ops.find((o) => o.entity !== pair!.read.entity)
320
+ const needed: [string, OpRef | undefined][] = [['#ITEM', pair?.item], ['#OTHER', other]]
321
+ const lacking = needed
322
+ .find(([tok, op]) => null == op && new RegExp(tok + '\\b').test(JSON.stringify(raw)))
323
+ if (null != lacking) {
324
+ t.diagnostic(`skip "${raw.name}": needs ${lacking[0]}, which this SDK cannot drive`)
325
+ continue
326
+ }
327
+
237
328
  const missing = missingFeature(probe, raw)
238
329
  if (null != missing) {
239
330
  t.diagnostic(`skip "${raw.name}": needs the ${missing} feature, ` +
@@ -243,6 +334,12 @@ describe('FeatureCorpus', () => {
243
334
 
244
335
  const tokens: Record<string, string> = {}
245
336
  for (let i = 0; i < need; i++) { tokens['#OP' + (i + 1)] = ops[i].key }
337
+ if (paired && null != pair) {
338
+ tokens['#READ'] = pair.read.key
339
+ tokens['#WRITE'] = pair.write.key
340
+ if (null != pair.item) { tokens['#ITEM'] = pair.item.key }
341
+ if (null != other) { tokens['#OTHER'] = other.key }
342
+ }
246
343
 
247
344
  const kase = resolve(raw, tokens)
248
345
  ran++
@@ -256,7 +353,7 @@ describe('FeatureCorpus', () => {
256
353
  ok(null != ref, `${kase.name}: no operation ${step.op}`)
257
354
  let err: any = undefined
258
355
  try {
259
- await client[ref.accessor]()[ref.op]({}, step.ctrl || {})
356
+ await runStep(client, ref, step)
260
357
  }
261
358
  catch (e: any) {
262
359
  err = e
@@ -273,6 +370,8 @@ describe('FeatureCorpus', () => {
273
370
  }
274
371
 
275
372
  subset(client[`_${name}`], kase.out, `${kase.name}: _${name}`)
373
+ deepStrictEqual(shared(), PRISTINE,
374
+ `${kase.name}: the case wrote onto Object or Object.prototype`)
276
375
  }
277
376
  catch (err: any) {
278
377
  const msg = String(err?.message ?? err)
@@ -93,9 +93,8 @@ function makeClient(spec: {
93
93
 
94
94
  // One clean registry per client, as makeOptions gives a real one, so a value
95
95
  // a feature registers with cleanAdd is masked by every clean after it.
96
- const derived = (stdutil as any).makeOptions({
97
- utility, options: { feature: { test: { active: true } } }, config: {},
98
- }).__derived__
96
+ const regctx: any = { utility, options: { feature: { test: { active: true } } }, config: {} }
97
+ const derived = (stdutil as any).makeOptions(regctx).__derived__
99
98
 
100
99
  const client: any = {
101
100
  _mode: spec.mode || 'test',
@@ -121,6 +120,7 @@ function makeClient(spec: {
121
120
  client,
122
121
  utility,
123
122
  options: client._options,
123
+ cleancfg: regctx.cleancfg,
124
124
  out: {},
125
125
  ctrl: over.ctrl || {},
126
126
  meta: {},
@@ -545,7 +545,7 @@ describe('pipeline:result helpers', () => {
545
545
  const secret = 'PIPELINE-SECRET-a1b2c3d4e5f6'
546
546
  const text = 'x'.repeat(150) + secret + 'y'.repeat(100)
547
547
  const ctx = base({
548
- options: { __derived__: { clean: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 } } },
548
+ cleancfg: { active: true, keys: [], values: [], mask: '[redacted]', hint: 0, min: 4 },
549
549
  spec: { headers: { 'user-agent': 'Probe ' + secret } },
550
550
  response: { body: 'body', json: async () => { throw Object.assign(new SyntaxError('bad json'), { text }) } },
551
551
  result: { status: 200, headers: { 'content-type': 'text/html' } },
@@ -39,6 +39,7 @@ pub const CtxSpec = struct {
39
39
  config: ?Value = null,
40
40
  entopts: ?Value = null,
41
41
  options: ?Value = null,
42
+ cleancfg: ?Value = null,
42
43
  entity: ?Entity = null,
43
44
  shared: ?Value = null,
44
45
  opmap: ?*OpMap = null,
@@ -64,6 +65,8 @@ pub const Context = struct {
64
65
  config: Value,
65
66
  entopts: Value,
66
67
  options: Value,
68
+ // The clean registry, beside the options rather than in them.
69
+ cleancfg: Value,
67
70
  opmap: *OpMap,
68
71
  response: ?*Response,
69
72
  result: ?*SdkResult,
@@ -118,6 +121,7 @@ pub const Context = struct {
118
121
  const config: Value = ctxspec.config orelse (if (basectx) |b| b.config else h.vnull());
119
122
  const entopts: Value = ctxspec.entopts orelse (if (basectx) |b| b.entopts else h.vnull());
120
123
  const options: Value = ctxspec.options orelse (if (basectx) |b| b.options else h.vnull());
124
+ const cleancfg: Value = ctxspec.cleancfg orelse (if (basectx) |b| b.cleancfg else h.vnull());
121
125
  const entity: ?Entity = ctxspec.entity orelse (if (basectx) |b| b.entity else null);
122
126
  const shared: Value = ctxspec.shared orelse blk: {
123
127
  if (basectx) |b| {
@@ -163,6 +167,7 @@ pub const Context = struct {
163
167
  .config = config,
164
168
  .entopts = entopts,
165
169
  .options = options,
170
+ .cleancfg = cleancfg,
166
171
  .opmap = opmap,
167
172
  .response = response,
168
173
  .result = result,
@@ -179,9 +179,9 @@ pub const Utility = struct {
179
179
 
180
180
  // Everything that leaves the pipeline passes through clean; inside it data
181
181
  // stays raw, so a hook can still read the header it must add to. The zig
182
- // port of tm/ts/src/utility/CleanUtility.ts. The derived clean block is a
183
- // Value map (`options.__derived__.clean`) whose `values` list is MUTABLE:
184
- // features register secrets after make_options.
182
+ // port of tm/ts/src/utility/CleanUtility.ts. The clean registry is a Value
183
+ // map held on the context beside the options (`ctx.cleancfg`), whose
184
+ // `values` list is MUTABLE: features register secrets after make_options.
185
185
 
186
186
  const CLEAN_MAXDEPTH: usize = 32;
187
187
  const CLEAN_CIRCULAR = "[circular]";
@@ -279,11 +279,11 @@ pub fn clean_splitvalues(values: Value) [][]const u8 {
279
279
  return out.toOwnedSlice(h.A()) catch &.{};
280
280
  }
281
281
 
282
- // A context without options (make_error accepts a bare one) still masks by
283
- // the schema defaults.
282
+ // A context without a registry (make_error accepts a bare one) still masks
283
+ // by the schema defaults.
284
284
  fn clean_config(ctx: *Context) Value {
285
- const derived = h.getpath(&.{ "__derived__", "clean" }, ctx.options);
286
- if (derived == .object and h.getp(derived, "values") == .array) return derived;
285
+ const cfg = ctx.cleancfg;
286
+ if (cfg == .object and h.getp(cfg, "values") == .array) return cfg;
287
287
  return make_clean_config(h.getp(schema.shared_optspec(), "clean"));
288
288
  }
289
289
 
@@ -938,10 +938,12 @@ pub fn make_options_util(ctx: *Context) E!Value {
938
938
  }
939
939
 
940
940
  h.setp(opts, "__derived__", h.jo(&.{
941
- .{ "clean", cleancfg },
942
941
  .{ "featureorder", feature_order },
943
942
  }));
944
943
 
944
+ // Beside the options, not in them: options_map hands them to callers.
945
+ ctx.cleancfg = cleancfg;
946
+
945
947
  // Again over the merged result: the config's own defaults can carry one.
946
948
  clean_add_sensitive_cfg(cleancfg, mo_without(opts, &.{ "clean", "__derived__" }));
947
949
 
@@ -2430,7 +2432,7 @@ pub fn fetcher_util(ctx: *Context, fullurl: []const u8, fetchdef: Value) E!Value
2430
2432
 
2431
2433
  // A GET-only live run refuses any other method before it is sent. The error
2432
2434
  // names the path alone: the query can carry a credential.
2433
- fn getonly_refusal(fullurl: []const u8, fetchdef: Value) ?[]const u8 {
2435
+ pub fn getonly_refusal(fullurl: []const u8, fetchdef: Value) ?[]const u8 {
2434
2436
  const environ = mem.threaded().environ.process_environ;
2435
2437
  const flag = environ.getAlloc(h.A(), "VOXGIG_GETONLY_GUARD") catch return null;
2436
2438
  if (!std.mem.eql(u8, flag, "TRUE")) return null;
@@ -1,12 +1,6 @@
1
- // Response caching for safe (read) requests (mirrors go
2
- // feature/cache_feature.go / rust feature/cache.rs). Wraps the active
3
- // transport and serves a fresh cached snapshot instead of hitting the network
4
- // when the same method+URL was fetched within `ttl` ms (default: 5000). Only
5
- // successful (2xx) responses to cacheable methods (default: GET) are stored,
6
- // keyed by method+URL. The cache is bounded (`max` entries, default 256,
7
- // oldest evicted first) and every hit/miss/bypass is counted. Bodies are
8
- // snapshotted on capture so both the current caller and later hits can
9
- // re-read the JSON body repeatedly.
1
+ // Response caching for safe (read) requests, per client (mirrors go
2
+ // feature/cache_feature.go / rust feature/cache.rs): see the features
3
+ // reference for the key, the write invalidation and the Cache-Control rules.
10
4
 
11
5
  const std = @import("std");
12
6
  const h = @import("../core/helpers.zig");
@@ -19,6 +13,7 @@ const Value = h.Value;
19
13
  const Context = types.Context;
20
14
  const Feature = types.Feature;
21
15
  const Fetcher = types.Fetcher;
16
+ const HmacSha256 = std.crypto.auth.hmac.sha2.HmacSha256;
22
17
 
23
18
  pub const CacheSnapshot = struct {
24
19
  status: i64,
@@ -29,12 +24,14 @@ pub const CacheSnapshot = struct {
29
24
 
30
25
  pub const CacheEntry = struct {
31
26
  expiry: i64,
27
+ scope: []const u8,
32
28
  snapshot: *CacheSnapshot,
33
29
  };
34
30
 
35
31
  pub const CacheTrack = struct {
36
32
  store: std.StringHashMap(CacheEntry),
37
33
  order: std.ArrayList([]const u8),
34
+ secret: [32]u8 = undefined,
38
35
 
39
36
  // Activity tracking (mirrors the ts client._cache record).
40
37
  hit: i64 = 0,
@@ -75,6 +72,8 @@ pub const CacheFeature = struct {
75
72
  self.active = sup.fopt_bool(options, "active", false);
76
73
  if (!self.active) return;
77
74
 
75
+ h.IO().randomSecure(&self.track.secret) catch h.IO().random(&self.track.secret);
76
+
78
77
  const util = ctx.util();
79
78
  const w = h.A().create(WrapCtx) catch unreachable;
80
79
  w.* = .{ .inner = util.fetcher, .options = options, .track = self.track };
@@ -133,9 +132,16 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
133
132
  break;
134
133
  }
135
134
  }
136
- if (!cacheable) return inner.invoke(ctx, url, fetchdef);
135
+ if (!cacheable) {
136
+ if (std.mem.eql(u8, method, "GET") or std.mem.eql(u8, method, "HEAD")) {
137
+ return inner.invoke(ctx, url, fetchdef);
138
+ }
139
+ defer invalidate(track, url);
140
+ return inner.invoke(ctx, url, fetchdef);
141
+ }
137
142
 
138
- const key = std.fmt.allocPrint(h.A(), "{s} {s}", .{ method, url }) catch method;
143
+ const hdigest = digest(&track.secret, h.getp(fetchdef, "headers"));
144
+ const key = std.fmt.allocPrint(h.A(), "{s} {s} {s}", .{ method, url, hdigest }) catch method;
139
145
  const now = sup.fopt_now(options);
140
146
 
141
147
  if (track.store.get(key)) |hit| {
@@ -150,9 +156,14 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
150
156
  if (storable(res) and json(res)) {
151
157
  const snap = h.A().create(CacheSnapshot) catch unreachable;
152
158
  snap.* = snapshot(res);
153
- const ttl = sup.fopt_int(options, "ttl", 5000);
159
+ const ttl = lifetime(snap.headers, sup.fopt_int(options, "ttl", 5000));
160
+ if (ttl <= 0) {
161
+ track.bypass += 1;
162
+ return replay(snap);
163
+ }
164
+ dropEntry(track, key);
154
165
  evict(track, options);
155
- track.store.put(key, .{ .expiry = now + ttl, .snapshot = snap }) catch {};
166
+ track.store.put(key, .{ .expiry = now + ttl, .scope = urlScope(url), .snapshot = snap }) catch {};
156
167
  track.order.append(h.A(), key) catch {};
157
168
  track.miss += 1;
158
169
  return replay(snap);
@@ -165,6 +176,126 @@ fn through(track: *CacheTrack, options: Value, ctx: *Context, url: []const u8, f
165
176
  }
166
177
  }
167
178
 
179
+ fn headerText(v: Value) ?[]const u8 {
180
+ return switch (v) {
181
+ .string => |t| t,
182
+ .integer => |n| std.fmt.allocPrint(h.A(), "{d}", .{n}) catch null,
183
+ .float => |f| if (f == @floor(f) and @abs(f) < 9.0e15)
184
+ std.fmt.allocPrint(h.A(), "{d}", .{@as(i64, @intFromFloat(f))}) catch null
185
+ else
186
+ std.fmt.allocPrint(h.A(), "{d}", .{f}) catch null,
187
+ .bool => |b| if (b) "true" else "false",
188
+ else => null,
189
+ };
190
+ }
191
+
192
+ const HeaderPair = struct { name: []const u8, value: []const u8 };
193
+
194
+ fn pairLess(_: void, a: HeaderPair, b: HeaderPair) bool {
195
+ const order = std.mem.order(u8, a.name, b.name);
196
+ if (order != .eq) return order == .lt;
197
+ return std.mem.lessThan(u8, a.value, b.value);
198
+ }
199
+
200
+ fn digest(secret: *const [32]u8, headers: Value) []const u8 {
201
+ var pairs: std.ArrayList(HeaderPair) = .empty;
202
+ if (headers == .object) {
203
+ var it = headers.object.iterator();
204
+ while (it.next()) |kv| {
205
+ const text = headerText(kv.value_ptr.*) orelse continue;
206
+ pairs.append(h.A(), .{ .name = lowerAlloc(kv.key_ptr.*), .value = text }) catch {};
207
+ }
208
+ }
209
+ std.mem.sort(HeaderPair, pairs.items, {}, pairLess);
210
+ var mac = HmacSha256.init(secret);
211
+ for (pairs.items) |p| {
212
+ mac.update(p.name);
213
+ mac.update(":");
214
+ mac.update(p.value);
215
+ mac.update("\n");
216
+ }
217
+ var out: [HmacSha256.mac_length]u8 = undefined;
218
+ mac.final(&out);
219
+ const hex = std.fmt.bytesToHex(out, .lower);
220
+ return h.A().dupe(u8, &hex) catch "";
221
+ }
222
+
223
+ fn invalidate(track: *CacheTrack, url: []const u8) void {
224
+ const path = urlScope(url);
225
+ const collection = urlParent(path);
226
+ var dropped: std.ArrayList([]const u8) = .empty;
227
+ var it = track.store.iterator();
228
+ while (it.next()) |kv| {
229
+ const scope = kv.value_ptr.scope;
230
+ if (scopeUnder(scope, path) or std.mem.eql(u8, scope, collection)) {
231
+ dropped.append(h.A(), kv.key_ptr.*) catch {};
232
+ }
233
+ }
234
+ for (dropped.items) |key| dropEntry(track, key);
235
+ }
236
+
237
+ fn dropEntry(track: *CacheTrack, key: []const u8) void {
238
+ if (!track.store.remove(key)) return;
239
+ var i: usize = track.order.items.len;
240
+ while (i > 0) {
241
+ i -= 1;
242
+ if (std.mem.eql(u8, track.order.items[i], key)) _ = track.order.orderedRemove(i);
243
+ }
244
+ }
245
+
246
+ // The configured ttl capped by the response's Cache-Control; zero when the
247
+ // response may not be stored.
248
+ fn lifetime(headers: Value, ttl: i64) i64 {
249
+ var control: []const u8 = "";
250
+ if (headers == .object) {
251
+ var it = headers.object.iterator();
252
+ while (it.next()) |kv| {
253
+ if (std.ascii.eqlIgnoreCase(kv.key_ptr.*, "cache-control")) {
254
+ control = lowerAlloc(headerText(kv.value_ptr.*) orelse "");
255
+ }
256
+ }
257
+ }
258
+ var life = ttl;
259
+ var parts = std.mem.splitScalar(u8, control, ',');
260
+ while (parts.next()) |part| {
261
+ const directive = std.mem.trim(u8, part, " \t");
262
+ if (std.mem.eql(u8, directive, "no-store") or std.mem.eql(u8, directive, "private") or
263
+ std.mem.eql(u8, directive, "no-cache")) return 0;
264
+ if (std.mem.startsWith(u8, directive, "max-age")) {
265
+ const rest = std.mem.trim(u8, directive["max-age".len..], " \t");
266
+ if (rest.len == 0 or rest[0] != '=') continue;
267
+ const value = std.mem.trim(u8, std.mem.trim(u8, rest[1..], " \t"), "\"");
268
+ if (value.len == 0) continue;
269
+ var digits = true;
270
+ for (value) |c| digits = digits and std.ascii.isDigit(c);
271
+ if (!digits) continue;
272
+ const secs = std.fmt.parseInt(i64, value, 10) catch continue;
273
+ life = @min(life, secs *| 1000);
274
+ }
275
+ }
276
+ return life;
277
+ }
278
+
279
+ fn urlScope(url: []const u8) []const u8 {
280
+ var end = std.mem.indexOfAny(u8, url, "?#") orelse url.len;
281
+ while (end > 0 and url[end - 1] == '/') end -= 1;
282
+ return url[0..end];
283
+ }
284
+
285
+ fn urlParent(scope: []const u8) []const u8 {
286
+ var root: usize = 0;
287
+ if (std.mem.indexOf(u8, scope, "://")) |scheme| {
288
+ root = std.mem.indexOfScalarPos(u8, scope, scheme + 3, '/') orelse return scope;
289
+ }
290
+ const cut = std.mem.lastIndexOfScalar(u8, scope, '/') orelse 0;
291
+ return scope[0..@max(cut, root)];
292
+ }
293
+
294
+ fn scopeUnder(scope: []const u8, prefix: []const u8) bool {
295
+ if (std.mem.eql(u8, scope, prefix)) return true;
296
+ return scope.len > prefix.len and std.mem.startsWith(u8, scope, prefix) and scope[prefix.len] == '/';
297
+ }
298
+
168
299
  // A body the transport could not read as JSON passes through, for the operation to report.
169
300
  fn storable(res: Value) bool {
170
301
  const status = sup.fres_status(res) orelse return false;
@@ -82,6 +82,7 @@ const h = @import("../core/helpers.zig");
82
82
  const mem = @import("../core/mem.zig");
83
83
  const err = @import("../core/error.zig");
84
84
  const types = @import("../core/types.zig");
85
+ const utility = @import("../core/utility.zig");
85
86
  const sup = @import("support.zig");
86
87
 
87
88
  // NAMED BUILD MODULES, not paths: the vendored trees under feature/secrets/
@@ -857,7 +858,11 @@ fn send(ctx: *Context, sysfetch: Value, url: []const u8, method: []const u8, bod
857
858
  }
858
859
  // No custom transport supplied - the ordinary case (make_options leaves
859
860
  // system.fetch unset, and the SDK's default transport has no HTTP
860
- // client). See raw_exchange_fetch.
861
+ // client). See raw_exchange_fetch. Not the SDK fetcher, as every other
862
+ // target does, for that reason: only its GET-only guard comes first.
863
+ if (utility.getonly_refusal(url, h.jo(&.{.{ "method", h.vstr(method) }}))) |msg| {
864
+ return ctx.fail("fetch_getonly_block", msg);
865
+ }
861
866
  return raw_exchange_fetch(ctx, url, method, body);
862
867
  }
863
868
 
@@ -488,6 +488,71 @@ test "feature cache: inactive does not wrap" {
488
488
  try testing.expect(rec.count() == 2);
489
489
  }
490
490
 
491
+ var cache_control: []const u8 = "";
492
+
493
+ fn replyControl(_: i64, _: *sdk.Context, _: Value) fh.E!Value {
494
+ return fh.fh_response(200, h.jo(&.{.{ "ok", h.vbool(true) }}), h.jo(&.{.{ "Cache-Control", h.vstr(cache_control) }}));
495
+ }
496
+
497
+ test "feature cache: keys on request headers" {
498
+ if (!fh.fh_present(&.{"cache"})) return;
499
+ const rec = fh.Recorder.new(null);
500
+ const f = sdk.CacheFeature.make();
501
+ const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
502
+ _ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "x-tenant", h.vstr("tenant-a") }}) });
503
+ _ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "X-Tenant", h.vstr("tenant-b") }}) });
504
+ try testing.expect(rec.count() == 2);
505
+ _ = hh.op(.{ .op = "load", .path = "/w/1", .headers = h.jo(&.{.{ "x-tenant", h.vstr("tenant-b") }}) });
506
+ try testing.expect(rec.count() == 2);
507
+ }
508
+
509
+ test "feature cache: a write drops its collection" {
510
+ if (!fh.fh_present(&.{"cache"})) return;
511
+ const rec = fh.Recorder.new(null);
512
+ const f = sdk.CacheFeature.make();
513
+ const cf: *sdk.CacheFeature = @ptrCast(@alignCast(f.ptr));
514
+ const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
515
+ const paths = [_][]const u8{ "/w/1", "/w", "/w/1/part", "/other/1", "/w/2" };
516
+ for (paths) |p| _ = hh.op(.{ .op = "load", .path = p });
517
+ _ = hh.op(.{ .op = "update", .method = "PUT", .path = "/w/1" });
518
+ for (paths) |p| _ = hh.op(.{ .op = "load", .path = p });
519
+ try testing.expect(rec.count() == 9);
520
+ try testing.expect(cf.track.hit == 2);
521
+ }
522
+
523
+ test "feature cache: Cache-Control prevents storing" {
524
+ if (!fh.fh_present(&.{"cache"})) return;
525
+ const controls = [_][]const u8{ "no-store", "private", "No-Cache", "max-age=60, private" };
526
+ for (controls) |control| {
527
+ cache_control = control;
528
+ const rec = fh.Recorder.new(replyControl);
529
+ const f = sdk.CacheFeature.make();
530
+ const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{.{ "ttl", h.vnum(10000) }}) }});
531
+ _ = hh.op(.{ .op = "load", .path = "/w" });
532
+ _ = hh.op(.{ .op = "load", .path = "/w" });
533
+ try testing.expect(rec.count() == 2);
534
+ }
535
+ }
536
+
537
+ test "feature cache: max-age caps the ttl" {
538
+ if (!fh.fh_present(&.{"cache"})) return;
539
+ cache_control = "max-age=1";
540
+ const clock = fh.FhClock.new();
541
+ const rec = fh.Recorder.new(replyControl);
542
+ const f = sdk.CacheFeature.make();
543
+ const hh = fh.fh_make(rec.fetcher(), &.{.{ .feat = f, .options = h.jo(&.{
544
+ .{ "ttl", h.vnum(10000) },
545
+ .{ "now", clock.now_fn() },
546
+ }) }});
547
+ _ = hh.op(.{ .op = "load", .path = "/w" });
548
+ clock.advance(500);
549
+ _ = hh.op(.{ .op = "load", .path = "/w" });
550
+ try testing.expect(rec.count() == 1);
551
+ clock.advance(600);
552
+ _ = hh.op(.{ .op = "load", .path = "/w" });
553
+ try testing.expect(rec.count() == 2);
554
+ }
555
+
491
556
  // =====================================================================
492
557
  // idempotency
493
558
  // =====================================================================
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen",
6
- "version": "4.50.0",
6
+ "version": "4.51.0",
7
7
  "provides": {
8
8
  "target": [
9
9
  "c",