@voxgig/sdkgen 4.39.0 → 4.40.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 (92) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/doctor.js +5 -1
  3. package/dist/action/doctor.js.map +1 -1
  4. package/dist/helpers/copymerge.js +14 -9
  5. package/dist/helpers/copymerge.js.map +1 -1
  6. package/dist/helpers/testPolicy.d.ts +8 -2
  7. package/dist/helpers/testPolicy.js +18 -0
  8. package/dist/helpers/testPolicy.js.map +1 -1
  9. package/dist/sdkgen.d.ts +4 -4
  10. package/dist/sdkgen.js +4 -3
  11. package/dist/sdkgen.js.map +1 -1
  12. package/dist/tsconfig.tsbuildinfo +1 -1
  13. package/package.json +1 -1
  14. package/project/.sdk/model/target/rust.aontu +1 -0
  15. package/project/.sdk/src/cmp/c/fragment/Main.fragment.c +15 -0
  16. package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +2 -0
  17. package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +20 -3
  18. package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +43 -15
  19. package/project/.sdk/src/cmp/csharp/fragment/Main.fragment.cs +17 -0
  20. package/project/.sdk/src/cmp/elixir/fragment/Main.fragment.ex +10 -0
  21. package/project/.sdk/src/cmp/go/TestDirect_go.ts +23 -4
  22. package/project/.sdk/src/cmp/go/TestEntity_go.ts +37 -12
  23. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +14 -0
  24. package/project/.sdk/src/cmp/java/TestDirect_java.ts +18 -3
  25. package/project/.sdk/src/cmp/java/TestEntity_java.ts +39 -14
  26. package/project/.sdk/src/cmp/js/TestDirect_js.ts +7 -1
  27. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +7 -0
  28. package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +18 -3
  29. package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +37 -14
  30. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +13 -3
  31. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +36 -10
  32. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +14 -0
  33. package/project/.sdk/src/cmp/ocaml/TestDirect_ocaml.ts +3 -1
  34. package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -3
  35. package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +22 -8
  36. package/project/.sdk/src/cmp/perl/fragment/Main.fragment.pm +6 -0
  37. package/project/.sdk/src/cmp/php/TestDirect_php.ts +13 -3
  38. package/project/.sdk/src/cmp/php/TestEntity_php.ts +31 -9
  39. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +14 -0
  40. package/project/.sdk/src/cmp/py/TestDirect_py.ts +11 -3
  41. package/project/.sdk/src/cmp/py/TestEntity_py.ts +30 -9
  42. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +6 -0
  43. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -3
  44. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +25 -10
  45. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +7 -0
  46. package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +13 -3
  47. package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +48 -27
  48. package/project/.sdk/src/cmp/rust/fragment/Main.fragment.rs +15 -0
  49. package/project/.sdk/src/cmp/swift/fragment/Main.fragment.swift +7 -0
  50. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +7 -1
  51. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +8 -2
  52. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +7 -0
  53. package/project/.sdk/src/cmp/zig/TestDirect_zig.ts +1 -0
  54. package/project/.sdk/src/cmp/zig/fragment/Main.fragment.zig +16 -0
  55. package/project/.sdk/tm/c/utility/http.c +256 -0
  56. package/project/.sdk/tm/clojure/src/sdk/client.clj +7 -0
  57. package/project/.sdk/tm/clojure/src/sdk/core.clj +24 -1
  58. package/project/.sdk/tm/cpp/core/types.hpp +14 -0
  59. package/project/.sdk/tm/csharp/test/Runner.cs +49 -3
  60. package/project/.sdk/tm/csharp/utility/Fetcher.cs +5 -1
  61. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +54 -19
  62. package/project/.sdk/tm/go/test/testsupport_test.go +44 -3
  63. package/project/.sdk/tm/go/utility/fetcher.go +40 -0
  64. package/project/.sdk/tm/java/core/SdkClient.java +7 -0
  65. package/project/.sdk/tm/java/test/RunnerSupport.java +45 -2
  66. package/project/.sdk/tm/java/utility/Fetcher.java +67 -1
  67. package/project/.sdk/tm/js/src/utility/MakeResultUtility.js +3 -1
  68. package/project/.sdk/tm/js/test/live-entity.js +7 -3
  69. package/project/.sdk/tm/kotlin/core/SdkClient.kt +7 -0
  70. package/project/.sdk/tm/kotlin/test/RunnerSupport.kt +40 -3
  71. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +52 -1
  72. package/project/.sdk/tm/lua/test/runner.lua +49 -2
  73. package/project/.sdk/tm/lua/utility/fetcher.lua +228 -0
  74. package/project/.sdk/tm/ocaml/sdk_features.ml +8 -0
  75. package/project/.sdk/tm/perl/t/runner.pm +18 -3
  76. package/project/.sdk/tm/perl/utility/fetcher.pm +42 -3
  77. package/project/.sdk/tm/php/test/Runner.php +43 -5
  78. package/project/.sdk/tm/php/utility/Fetcher.php +36 -0
  79. package/project/.sdk/tm/php/utility/MakeResult.php +3 -1
  80. package/project/.sdk/tm/py/test/runner.py +32 -3
  81. package/project/.sdk/tm/rb/test/runner.rb +24 -1
  82. package/project/.sdk/tm/rust/tests/common/mod.rs +53 -5
  83. package/project/.sdk/tm/rust/utility/fetcher.rs +43 -3
  84. package/project/.sdk/tm/scala/core/SdkClient.scala +7 -0
  85. package/project/.sdk/tm/scala/utility/Fetcher.scala +48 -1
  86. package/project/.sdk/tm/ts/src/utility/MakeResultUtility.ts +3 -1
  87. package/project/.sdk/tm/ts/test/live-entity.ts +8 -3
  88. package/project/sdkgen-package.json +1 -1
  89. package/src/action/doctor.ts +5 -1
  90. package/src/helpers/copymerge.ts +16 -11
  91. package/src/helpers/testPolicy.ts +23 -2
  92. package/src/sdkgen.ts +4 -2
@@ -190,6 +190,20 @@ class ProjectNameSDK implements \JsonSerializable
190
190
  }
191
191
  }
192
192
 
193
+ // A raw request has no point to declare its response type, so it asks
194
+ // for the JSON it reads: an API that negotiates on Accept otherwise
195
+ // answers in its own default format. A caller's own accept wins.
196
+ $has_accept = false;
197
+ foreach (array_keys($ctx->spec->headers) as $k) {
198
+ if (strtolower((string)$k) === 'accept') {
199
+ $has_accept = true;
200
+ break;
201
+ }
202
+ }
203
+ if (!$has_accept) {
204
+ $ctx->spec->headers['accept'] = 'application/json';
205
+ }
206
+
193
207
  [$_, $err] = ($utility->prepare_auth)($ctx);
194
208
  if ($err) {
195
209
  return ($utility->make_error)($ctx, $err);
@@ -222,7 +222,9 @@ class Test${entity.Name}Direct:
222
222
  if _skip:
223
223
  pytest.skip(_reason or "skipped via sdk-test-control.json")
224
224
  return
225
- ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listLiveIdKeys)}${liveKeysBlock(listLiveIdKeys, entidEnvVar)} client = setup["client"]
225
+ ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listLiveIdKeys)}${liveKeysBlock(listLiveIdKeys, entidEnvVar)} if setup["live"]:
226
+ runner.live_pace()
227
+ client = setup["client"]
226
228
 
227
229
  params = {}
228
230
  query = {}
@@ -276,7 +278,9 @@ ${listLiveQueryLines ? ' if setup["live"]:\n' + listLiveQueryLines : ''}`
276
278
  if _skip:
277
279
  pytest.skip(_reason or "skipped via sdk-test-control.json")
278
280
  return
279
- ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} client = setup["client"]
281
+ ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} if setup["live"]:
282
+ runner.live_pace()
283
+ client = setup["client"]
280
284
 
281
285
  params = {}
282
286
  query = {}
@@ -286,10 +290,14 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
286
290
  Content(loadExampleLines + '\n')
287
291
  }
288
292
  else if (discover) {
293
+ // The list sends the query its route requires, as direct-list does.
294
+ const listQuery = liveQueryExamples(listPoint)
295
+ .map(([name, ex]) => `${JSON.stringify(name)}: ${pyLit(ex)}`).join(', ')
289
296
  Content(` list_result = client.direct({
290
297
  "path": "${listPath}",
291
298
  "method": "GET",
292
- "params": {${listParams.map((p: any) => `"${p.n}": setup["idmap"].get("${liveKey(p)}")`).join(', ')}},
299
+ "params": {${listParams.map((p: any) => `"${p.n}": setup["idmap"].get("${liveKey(p)}")`).join(', ')}},${'' === listQuery ? '' : `
300
+ "query": {${listQuery}},`}
293
301
  })
294
302
  if not _live_ok(list_result):
295
303
  runner.live_miss(LIVE_STRICT, "Live list discovery failed: " + runner.live_describe(list_result))
@@ -32,13 +32,13 @@ import {
32
32
  liveFlowNeeds, liveStrict, liveStrictNote,
33
33
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
34
34
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
35
- liveEntity,
35
+ liveEntity, liveIdentity,
36
36
  } from '@voxgig/sdkgen'
37
37
 
38
38
 
39
39
  // The live prologue of a flow built from offline fixtures: blocked without
40
40
  // the ids it binds, and a create-less load reading the first listed record.
41
- function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
41
+ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string): string {
42
42
  let out = ''
43
43
  if (null != needs.examples) {
44
44
  out += ` if setup["live"]:
@@ -62,9 +62,10 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
62
62
  }
63
63
  out += ' client = setup["client"]\n'
64
64
  if (null != needs.record) {
65
+ const id = `setup["idmap"].get(${JSON.stringify(needs.record)})`
65
66
  out += ` if setup["live"]:
66
67
  runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)},
67
- lambda: [{"id": setup["idmap"].get(${JSON.stringify(needs.record)})}])
68
+ lambda: [{"id": ${id}}], ${JSON.stringify(identity.field)}, ${id})
68
69
  `
69
70
  }
70
71
  if (null != needs.discover) {
@@ -73,8 +74,13 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
73
74
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
74
75
  .map(([k, ex]) => `${JSON.stringify(k)}: ${pyLit(ex)}`)).join(', ')
75
76
  out += ` if setup["live"]:
77
+ _live_id = None if setup.get("synthetic_only") else setup["idmap"].get(${JSON.stringify(identity.key)})
78
+ ${undefined === identity.ex ? '' : ` if _live_id is None:
79
+ _live_id = ${pyLit(identity.ex)}
80
+ `} runner.live_pace()
76
81
  runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)},
77
- lambda: client.${entity.Name}(None).list({${match}}, None))
82
+ lambda: client.${entity.Name}(None).list({${match}}, None),
83
+ ${JSON.stringify(identity.field)}, _live_id)
78
84
  `
79
85
  }
80
86
  return out
@@ -235,7 +241,7 @@ ${strict ? '' : ` @runner.live_observe("${PROJUPPER}_TEST_LIVE", LIVE_STRICT)
235
241
 
236
242
  const flowBody = (flow: any) => {
237
243
  const steps = flowSteps(flow) as any[]
238
- Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), entidEnv) + '\n')
244
+ Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow), entidEnv) + '\n')
239
245
 
240
246
  // Check if the flow has a create step
241
247
  const flowHasCreate = steps.some((s: any) => s.o === 'create')
@@ -262,6 +268,7 @@ ${strict ? '' : ` @runner.live_observe("${PROJUPPER}_TEST_LIVE", LIVE_STRICT)
262
268
  }
263
269
  const opgen: OpGen = GENERATE_OP[step.o]
264
270
  if (opgen) {
271
+ Content(LIVE_PACE)
265
272
  opgen({ ...genCtx, flow }, step, index)
266
273
  Content('\n')
267
274
  }
@@ -558,8 +565,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
558
565
  assert ${resdatavar} is not None
559
566
  `)
560
567
  if (hasEntIdU) {
561
- Content(` assert ${resdatavar}[${rid(entity)}] == ${datavar}_up["id"]
562
- `)
568
+ Content(sameId(entity, `${resdatavar}.get(${rid(entity)})`, `${datavar}_up["id"]`))
563
569
  }
564
570
 
565
571
  if (step.s) {
@@ -620,8 +626,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
620
626
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, None)
621
627
  ${datavar}_load_result = helpers.to_map(runner.entity_data(${datavar}_loaded))
622
628
  assert ${datavar}_load_result is not None
623
- assert ${datavar}_load_result[${rid(entity)}] == ${srcdatavar}[${rid(entity)}]
624
- `)
629
+ ${sameId(entity, `${datavar}_load_result.get(${rid(entity)})`, `${srcdatavar}[${rid(entity)}]`)}`)
625
630
  }
626
631
  else {
627
632
  Content(` ${matchvar} = {}
@@ -668,6 +673,22 @@ function rid(entity: any): string {
668
673
  }
669
674
 
670
675
 
676
+ const LIVE_PACE = ` if setup["live"]:
677
+ runner.live_pace()
678
+ `
679
+
680
+
681
+ // A result's identity matches the one asked for, live only where the
682
+ // record's schema has a field to repeat it in.
683
+ function sameId(entity: any, result: string, expected: string): string {
684
+ const check = `assert runner.live_same_id(${result}, ${expected})`
685
+ return null == entityDataIdField(entity) ? ` if not setup["live"]:
686
+ ${check}
687
+ ` : ` ${check}
688
+ `
689
+ }
690
+
691
+
671
692
  // The fixture keeps each record's key in `id`; an entity keeping its identity
672
693
  // in another field reads the key from there too.
673
694
  function fixtureIdentity(entity: any): string {
@@ -188,6 +188,12 @@ class ProjectNameSDK:
188
188
  for k, v in uh.items():
189
189
  ctx.spec.headers[k] = v
190
190
 
191
+ # A raw request has no point to declare its response type, so it asks
192
+ # for the JSON it reads: an API that negotiates on Accept otherwise
193
+ # answers in its own default format. A caller's own accept wins.
194
+ if not any(str(k).lower() == "accept" for k in ctx.spec.headers):
195
+ ctx.spec.headers["accept"] = "application/json"
196
+
191
197
  _, err = utility.prepare_auth(ctx)
192
198
  if err is not None:
193
199
  raise err
@@ -218,7 +218,8 @@ ${liveStrictNote(liveStrict(model, target.name), '#', ' ')}
218
218
  skip(_reason || "skipped via sdk-test-control.json")
219
219
  return
220
220
  end
221
- ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listParams.map(liveKey))}${liveKeysBlock(listParams.map(liveKey), entidEnvVar)} client = setup[:client]
221
+ ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listParams.map(liveKey))}${liveKeysBlock(listParams.map(liveKey), entidEnvVar)} Runner.live_pace if setup[:live]
222
+ client = setup[:client]
222
223
 
223
224
  params = {}
224
225
  query = {}
@@ -277,7 +278,8 @@ ${listLiveQueryLines ? ' if setup[:live]\n' + listLiveQueryLines + ' end\n
277
278
  skip(_reason || "skipped via sdk-test-control.json")
278
279
  return
279
280
  end
280
- ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} client = setup[:client]
281
+ ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} Runner.live_pace if setup[:live]
282
+ client = setup[:client]
281
283
 
282
284
  params = {}
283
285
  query = {}
@@ -287,10 +289,14 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
287
289
  Content(loadExampleLines + '\n')
288
290
  }
289
291
  else if (discover) {
292
+ // The list sends the query its route requires, as direct-list does.
293
+ const listQuery = liveQueryExamples(listPoint)
294
+ .map(([name, ex]) => `${JSON.stringify(name)} => ${formatRubyValue(ex)}`).join(', ')
290
295
  Content(` list_result = client.direct({
291
296
  "path" => "${listPath}",
292
297
  "method" => "GET",
293
- "params" => {${listParams.map((p: any) => `"${p.n}" => setup[:idmap]["${liveKey(p)}"]`).join(', ')}},
298
+ "params" => {${listParams.map((p: any) => `"${p.n}" => setup[:idmap]["${liveKey(p)}"]`).join(', ')}},${'' === listQuery ? '' : `
299
+ "query" => {${listQuery}},`}
294
300
  })
295
301
  unless live_ok(list_result)
296
302
  Runner.live_miss(LIVE_STRICT, "Live list discovery failed: " + Runner.live_describe(list_result))
@@ -32,7 +32,7 @@ import {
32
32
  liveFlowNeeds, liveStrict, liveStrictNote,
33
33
  liveRouteExamples, liveStepExamples, flowLoadRoute, flowLoadReadsRecord,
34
34
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
35
- liveEntity,
35
+ liveEntity, liveIdentity,
36
36
  } from '@voxgig/sdkgen'
37
37
 
38
38
  import { formatRubyValue } from './utility_rb'
@@ -40,7 +40,7 @@ import { formatRubyValue } from './utility_rb'
40
40
 
41
41
  // The live prologue of a flow built from offline fixtures: blocked without
42
42
  // the ids it binds, and a create-less load reading the first listed record.
43
- function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
43
+ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string): string {
44
44
  let out = ''
45
45
  if (null != needs.examples) {
46
46
  out += ` if setup[:live]
@@ -71,9 +71,10 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
71
71
  }
72
72
  out += ' client = setup[:client]\n'
73
73
  if (null != needs.record) {
74
+ const id = `setup[:idmap][${JSON.stringify(needs.record)}]`
74
75
  out += ` if setup[:live]
75
- Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}) do
76
- [{ "id" => setup[:idmap][${JSON.stringify(needs.record)}] }]
76
+ Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, ${id}) do
77
+ [{ "id" => ${id} }]
77
78
  end
78
79
  end
79
80
  `
@@ -84,7 +85,10 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string): string {
84
85
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
85
86
  .map(([k, ex]) => `${JSON.stringify(k)} => ${formatRubyValue(ex)}`)).join(', ')
86
87
  out += ` if setup[:live]
87
- Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}) do
88
+ _live_id = setup[:synthetic_only] ? nil : setup[:idmap][${JSON.stringify(identity.key)}]
89
+ ${undefined === identity.ex ? '' : ` _live_id = ${formatRubyValue(identity.ex)} if _live_id.nil?
90
+ `} Runner.live_pace
91
+ Runner.live_existing(setup, LIVE_STRICT, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, _live_id) do
88
92
  client.${entity.Name}(nil).list({${match}}, nil)
89
93
  end
90
94
  end
@@ -250,7 +254,7 @@ ${failureTests(model, entity)}${validateListTest(model, entity)}` : ''}${validat
250
254
 
251
255
  const flowBody = (flow: any) => {
252
256
  const steps = flowSteps(flow) as any[]
253
- Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), entidEnv) + '\n')
257
+ Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow), entidEnv) + '\n')
254
258
 
255
259
  // Check if the flow has a create step
256
260
  const flowHasCreate = steps.some((s: any) => s.o === 'create')
@@ -278,6 +282,7 @@ ${failureTests(model, entity)}${validateListTest(model, entity)}` : ''}${validat
278
282
  }
279
283
  const opgen: OpGen = GENERATE_OP[step.o]
280
284
  if (opgen) {
285
+ Content(LIVE_PACE)
281
286
  opgen({ ...genCtx, flow }, step, index)
282
287
  Content('\n')
283
288
  }
@@ -581,8 +586,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
581
586
  assert !${resdatavar}.nil?
582
587
  `)
583
588
  if (hasEntIdU) {
584
- Content(` assert_equal ${resdatavar}[${rid(entity)}], ${datavar}_up["id"]
585
- `)
589
+ Content(sameId(entity, `${resdatavar}[${rid(entity)}]`, `${datavar}_up["id"]`))
586
590
  }
587
591
 
588
592
  if (step.s) {
@@ -644,8 +648,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
644
648
  ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} ${datavar}_loaded = ${entvar}.load(${matchvar}, nil)
645
649
  ${datavar}_load_result = Helpers.to_map(${datavar}_loaded.respond_to?(:data_get) ? ${datavar}_loaded.data_get : ${datavar}_loaded)
646
650
  assert !${datavar}_load_result.nil?
647
- assert_equal ${datavar}_load_result[${rid(entity)}], ${srcdatavar}[${rid(entity)}]
648
- `)
651
+ ${sameId(entity, `${datavar}_load_result[${rid(entity)}]`, `${srcdatavar}[${rid(entity)}]`)}`)
649
652
  }
650
653
  else {
651
654
  Content(` ${matchvar} = {}
@@ -692,6 +695,18 @@ function rid(entity: any): string {
692
695
  }
693
696
 
694
697
 
698
+ const LIVE_PACE = ` Runner.live_pace if setup[:live]
699
+ `
700
+
701
+
702
+ // A result's identity matches the one asked for, live only where the
703
+ // record's schema has a field to repeat it in.
704
+ function sameId(entity: any, result: string, expected: string): string {
705
+ return ` assert Runner.live_same_id(${result}, ${expected})${null == entityDataIdField(entity) ? ' unless setup[:live]' : ''}
706
+ `
707
+ }
708
+
709
+
695
710
  // The fixture keeps each record's key in `id`; an entity keeping its identity
696
711
  // in another field reads the key from there too.
697
712
  function fixtureIdentity(entity: any): string {
@@ -153,6 +153,13 @@ class ProjectNameSDK
153
153
  uh.each { |k, v| ctx.spec.headers[k] = v }
154
154
  end
155
155
 
156
+ # A raw request has no point to declare its response type, so it asks
157
+ # for the JSON it reads: an API that negotiates on Accept otherwise
158
+ # answers in its own default format. A caller's own accept wins.
159
+ unless ctx.spec.headers.keys.any? { |k| k.to_s.downcase == "accept" }
160
+ ctx.spec.headers["accept"] = "application/json"
161
+ end
162
+
156
163
  _, err = utility.prepare_auth.call(ctx)
157
164
  raise err if err
158
165
 
@@ -304,7 +304,10 @@ fn ${evar}_direct_list() {
304
304
  );
305
305
  return;
306
306
  }
307
- ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listLiveParams.map((lp: any) => lp.key))}${liveKeysBlock(listLiveParams.map((lp: any) => lp.key), entidEnvVar)} let client = setup.client.clone();
307
+ ${getOnlyKeysBlock(model, entity, 'direct-list-' + entity.name, listLiveParams.map((lp: any) => lp.key))}${liveKeysBlock(listLiveParams.map((lp: any) => lp.key), entidEnvVar)} if setup.live {
308
+ live_pace();
309
+ }
310
+ let client = setup.client.clone();
308
311
 
309
312
  let params = Value::empty_map();
310
313
  ${liveQueryBlock(listPoint)}`)
@@ -419,7 +422,10 @@ fn ${evar}_direct_load() {
419
422
  );
420
423
  return;
421
424
  }
422
- ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} let client = setup.client.clone();
425
+ ${getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, [...new Set(loadLiveIdKeys)])}${liveKeysBlock([...new Set(loadLiveIdKeys)], entidEnvVar)} if setup.live {
426
+ live_pace();
427
+ }
428
+ let client = setup.client.clone();
423
429
 
424
430
  let params = Value::empty_map();
425
431
  ${liveQueryBlock(loadPoint)} if setup.live {
@@ -431,10 +437,14 @@ ${liveQueryBlock(loadPoint)} if setup.live {
431
437
  }
432
438
  }
433
439
  else if (discover) {
440
+ // The list sends the query its route requires, as direct-list does.
441
+ const listQuery = liveQueryExamples(listPoint)
442
+ .map(([name, ex]) => `(${JSON.stringify(name)}, ${rustJson(ex)})`).join(', ')
434
443
  Content(` let list_result = match client.direct(jo(vec![
435
444
  ("path", Value::str("${listPath}")),
436
445
  ("method", Value::str("GET")),
437
- ("params", jo(vec![${listParams.map((p: any) => `("${p.n}", getp(&setup.idmap, "${liveKey(p)}"))`).join(', ')}])),
446
+ ("params", jo(vec![${listParams.map((p: any) => `("${p.n}", getp(&setup.idmap, "${liveKey(p)}"))`).join(', ')}])),${'' === listQuery ? '' : `
447
+ ("query", jo(vec![${listQuery}])),`}
438
448
  ])) {
439
449
  Ok(list_result) => list_result,
440
450
  Err(err) => {
@@ -18,13 +18,13 @@ import {
18
18
  each,
19
19
  buildIdNames,
20
20
  getMatchEntries,
21
- isAuthActive, envName, envToken, entityRecordIdField,
21
+ isAuthActive, envName, envToken, entityDataIdField, entityRecordIdField,
22
22
  serverVarEnv,
23
23
  serverVariables,
24
24
  liveFlowNeeds, liveStrict, liveStrictNote,
25
25
  liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
26
26
  liveRouteExamples, liveStepExamples,
27
- liveEntity,
27
+ liveEntity, liveIdentity,
28
28
  } from '@voxgig/sdkgen'
29
29
 
30
30
 
@@ -45,7 +45,7 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
45
45
  // The live prologue of a flow built from offline fixtures: blocked without
46
46
  // the ids it binds, a create-less load reading the first listed record, and
47
47
  // a lenient run observing its checks rather than failing on them.
48
- function liveFlowGate(entity: any, needs: any, entidEnv: string, method: string,
48
+ function liveFlowGate(entity: any, needs: any, identity: any, entidEnv: string, method: string,
49
49
  strict: boolean, hasSteps: boolean): string {
50
50
  let out = ''
51
51
  for (const [k, ex] of needs.examples || []) {
@@ -77,9 +77,10 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, method: string,
77
77
  }
78
78
  out += ' let client = setup.client.clone();\n'
79
79
  if (null != needs.record) {
80
- out += ` if setup.live && !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, || {
81
- Ok(ja(vec![jo(vec![("id", getp(&setup.idmap, ${JSON.stringify(needs.record)}))])]))
82
- }) {
80
+ const id = `getp(&setup.idmap, ${JSON.stringify(needs.record)})`
81
+ out += ` if setup.live && !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)},
82
+ ${JSON.stringify(identity.field)}, ${id}, || Ok(ja(vec![jo(vec![("id", ${id})])])))
83
+ {
83
84
  return;
84
85
  }
85
86
  `
@@ -89,13 +90,22 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, method: string,
89
90
  .map(([k, v]: any) => `(${JSON.stringify(k)}, getp(&setup.idmap, ${JSON.stringify(v)}))`)
90
91
  .concat(liveRouteExamples(entity, 'list', Object.keys(needs.discover))
91
92
  .map(([k, ex]) => `(${JSON.stringify(k)}, ${rustLit(ex)})`)).join(', ')
92
- out += ` if setup.live && !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, || {
93
- client
94
- .${method}(Value::Noval)
95
- .list(jo(vec![${match}]), Value::Noval)
96
- .map(|list| ja(list.iter().map(|e| e.data(None)).collect::<Vec<Value>>()))
97
- }) {
98
- return;
93
+ const given = `if setup.synthetic_only { Value::Noval } else { getp(&setup.idmap, ${JSON.stringify(identity.key)}) }`
94
+ out += ` if setup.live {
95
+ ${undefined === identity.ex ? ` let live_id = ${given};
96
+ ` : ` let mut live_id = ${given};
97
+ if live_id.is_noval() || live_id.is_null() {
98
+ live_id = ${rustLit(identity.ex)};
99
+ }
100
+ `} live_pace();
101
+ if !live_existing(&setup.data, LIVE_STRICT, ${JSON.stringify(entity.name)}, ${JSON.stringify(identity.field)}, live_id, || {
102
+ client
103
+ .${method}(Value::Noval)
104
+ .list(jo(vec![${match}]), Value::Noval)
105
+ .map(|list| ja(list.iter().map(|e| e.data(None)).collect::<Vec<Value>>()))
106
+ }) {
107
+ return;
108
+ }
99
109
  }
100
110
  `
101
111
  }
@@ -269,8 +279,8 @@ ${skipBlock}`)
269
279
 
270
280
  const flowBody = (flow: any) => {
271
281
  const steps = flowSteps(flow) as any[]
272
- Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), PROJUPPER + '_TEST_' + ENTUPPER + '_ENTID',
273
- method, strict, steps.length > 0))
282
+ Content(liveFlowGate(entity, liveFlowNeeds(entity, flow), liveIdentity(entity, flow),
283
+ PROJUPPER + '_TEST_' + ENTUPPER + '_ENTID', method, strict, steps.length > 0))
274
284
 
275
285
  // No create step: bootstrap entity data from existing fixture data.
276
286
  const flowHasCreate = steps.some((s: any) => s.o === 'create')
@@ -291,6 +301,7 @@ ${skipBlock}`)
291
301
  each(steps, (step: any, index: any) => {
292
302
  const opgen: OpGen = GENERATE_OP[step.o]
293
303
  if (opgen) {
304
+ Content(LIVE_PACE)
294
305
  opgen({ ...genCtx, flow }, step, index)
295
306
  Content('\n')
296
307
  }
@@ -640,12 +651,8 @@ const generateUpdate: OpGen = (ctx, step, index) => {
640
651
  );
641
652
  `)
642
653
  if (hasEntIdU) {
643
- Content(` assert_eq!(
644
- getp(&${resdatavar}, ${rid(entity)}),
645
- getp(&${datavar}_up, "id"),
646
- "expected update result id to match"
647
- );
648
- `)
654
+ Content(sameId(entity, `getp(&${resdatavar}, ${rid(entity)})`, `getp(&${datavar}_up, "id")`,
655
+ 'expected update result id to match'))
649
656
  }
650
657
 
651
658
  // Assert TextFieldMark.
@@ -717,12 +724,8 @@ ${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchva
717
724
  matches!(${datavar}_load_result, Value::Map(_)),
718
725
  "expected load result to be a map"
719
726
  );
720
- assert_eq!(
721
- getp(&${datavar}_load_result, ${rid(entity)}),
722
- getp(&${srcdatavar}, ${rid(entity)}),
723
- "expected load result id to match"
724
- );
725
- `)
727
+ ${sameId(entity, `getp(&${datavar}_load_result, ${rid(entity)})`, `getp(&${srcdatavar}, ${rid(entity)})`,
728
+ 'expected load result id to match')}`)
726
729
  }
727
730
  else {
728
731
  Content(` let ${matchvar} = Value::empty_map();
@@ -771,6 +774,24 @@ function rid(entity: any): string {
771
774
  }
772
775
 
773
776
 
777
+ const LIVE_PACE = ` if setup.live {
778
+ live_pace();
779
+ }
780
+ `
781
+
782
+
783
+ // A result's identity matches the one asked for, live only where the
784
+ // record's schema has a field to repeat it in.
785
+ function sameId(entity: any, result: string, expected: string, message: string): string {
786
+ const check = `assert!(live_same_id(&${result}, &${expected}), ${JSON.stringify(message)});`
787
+ return null == entityDataIdField(entity) ? ` if !setup.live {
788
+ ${check}
789
+ }
790
+ ` : ` ${check}
791
+ `
792
+ }
793
+
794
+
774
795
  // The fixture keeps each record's key in `id`; an entity keeping its identity
775
796
  // in another field reads the key from there too.
776
797
  function fixtureIdentity(entity: any): string {
@@ -186,6 +186,21 @@ impl ProjectNameSDK {
186
186
  }
187
187
  }
188
188
 
189
+ // A raw request has no point to declare its response type, so it
190
+ // asks for the JSON it reads: an API that negotiates on Accept
191
+ // otherwise answers in its own default format. A caller's own
192
+ // accept wins.
193
+ {
194
+ let spec_headers = spec.borrow().headers.clone();
195
+ let has_accept = match &spec_headers {
196
+ Value::Map(m) => m.borrow().keys().any(|k| k.eq_ignore_ascii_case("accept")),
197
+ _ => false,
198
+ };
199
+ if !has_accept {
200
+ setp(&spec_headers, "accept", Value::str("application/json"));
201
+ }
202
+ }
203
+
189
204
  utility.prepare_auth(&ctx)?;
190
205
 
191
206
  utility.make_fetch_def(&ctx)
@@ -144,6 +144,13 @@ public final class ProjectNameSDK {
144
144
  }
145
145
  }
146
146
 
147
+ // A raw request has no point to declare its response type, so it asks
148
+ // for the JSON it reads: an API that negotiates on Accept otherwise
149
+ // answers in its own default format. A caller's own accept wins.
150
+ if !ctx.spec!.headers.entries.keys.contains(where: { $0.lowercased() == "accept" }) {
151
+ ctx.spec!.headers.entries["accept"] = .string("application/json")
152
+ }
153
+
147
154
  _ = try utility.prepareAuth(ctx)
148
155
 
149
156
  return try utility.makeFetchDef(ctx)
@@ -375,6 +375,12 @@ ${loadParams.map((p: any, i: number) => ` ${jsProp('params', p.n)} = 'direc
375
375
  ` ${lp.name}: setup.idmap['${lp.key}'],`).join('\n')
376
376
  const ancestorParamLines = liveAncestorParams.map((lp: any) =>
377
377
  ` ${jsProp('params', lp.name)} = setup.idmap['${lp.key}']`).join('\n')
378
+ // The list sends the query its route requires, as direct-list does.
379
+ const listQueryLines = liveQueryExamples(listPoint)
380
+ .map(([name, ex]) => `\n ${jsKey(name)}: ${JSON.stringify(ex)},`).join('')
381
+ const listQueryBlock = '' === listQueryLines ? '' : `
382
+ query: {${listQueryLines}
383
+ },`
378
384
 
379
385
  liveParamsBlock = ` if (setup.live) {
380
386
  ${liveQueryPrefix} const listResult: any = await client.direct({
@@ -382,7 +388,7 @@ ${liveQueryPrefix} const listResult: any = await client.direct({
382
388
  method: 'GET',
383
389
  params: {
384
390
  ${listParamLines}
385
- },
391
+ },${listQueryBlock}
386
392
  })
387
393
  if (!listResult.ok || listResult.status < 200 || listResult.status >= 300) {
388
394
  return void liveMiss(t, LIVE_STRICT, 'Live list discovery failed: ' + describeLive(listResult))
@@ -465,7 +465,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
465
465
  const ${resdatavar} = (await ${entvar}.update(${datavar})).data()
466
466
  `)
467
467
  if (hasEntIdU) {
468
- Content(` assert(${rid(entity, resdatavar)} === ${datavar}.id)
468
+ Content(` assert(${rid(entity, untyped(entity, resdatavar))} === ${datavar}.id)
469
469
  `)
470
470
  }
471
471
  else {
@@ -551,7 +551,7 @@ const generateLoad: OpGen = (ctx, step, index) => {
551
551
  }
552
552
  if (hasEntId) {
553
553
  Content(` const ${datavar} = (await ${entvar}.load(${matchvar})).data()
554
- assert(${rid(entity, datavar)} === ${rid(entity, srcdatavar)})
554
+ assert(${rid(entity, untyped(entity, datavar))} === ${rid(entity, srcdatavar)})
555
555
  `)
556
556
  }
557
557
  else {
@@ -605,6 +605,12 @@ function rid(entity: any, record: string): string {
605
605
  }
606
606
 
607
607
 
608
+ // A record type with no identity field has no member to read it from.
609
+ function untyped(entity: any, record: string): string {
610
+ return null == entityDataIdField(entity) ? `(${record} as any)` : record
611
+ }
612
+
613
+
608
614
  // The fixture keeps each record's key in `id`; an entity keeping its identity
609
615
  // in another field reads the key from there too.
610
616
  function fixtureIdentity(entity: any): string {
@@ -162,6 +162,13 @@ class ProjectNameSDK {
162
162
  }
163
163
  }
164
164
 
165
+ // A raw request has no point to declare its response type, so it asks
166
+ // for the JSON it reads: an API that negotiates on Accept otherwise
167
+ // answers in its own default format. A caller's own accept wins.
168
+ if (!Object.keys(spec.headers).some((key) => 'accept' === key.toLowerCase())) {
169
+ spec.headers.accept = 'application/json'
170
+ }
171
+
165
172
  // #SecretsResolve
166
173
 
167
174
  const authResult = prepareAuth(ctx)
@@ -45,6 +45,7 @@ test "${method}_prepare_smoke" {
45
45
  return;
46
46
  };
47
47
  try std.testing.expect(std.mem.eql(u8, h.get_str(fetchdef, "method") orelse "", "GET"));
48
+ try std.testing.expect(std.mem.eql(u8, h.get_str(h.getp(fetchdef, "headers"), "accept") orelse "", "application/json"));
48
49
  }
49
50
  `)
50
51
  })
@@ -210,6 +210,22 @@ pub const ProjectNameSDK = struct {
210
210
  while (it.next()) |kv| h.setp(spec.headers, kv.key_ptr.*, kv.value_ptr.*);
211
211
  }
212
212
 
213
+ // A raw request has no point to declare its response type, so it
214
+ // asks for the JSON it reads: an API that negotiates on Accept
215
+ // otherwise answers in its own default format. A caller's own accept
216
+ // wins.
217
+ if (spec.headers == .object) {
218
+ var has_accept = false;
219
+ var hit = spec.headers.object.iterator();
220
+ while (hit.next()) |kv| {
221
+ if (std.ascii.eqlIgnoreCase(kv.key_ptr.*, "accept")) {
222
+ has_accept = true;
223
+ break;
224
+ }
225
+ }
226
+ if (!has_accept) h.setp(spec.headers, "accept", h.vstr("application/json"));
227
+ }
228
+
213
229
  _ = try self.sdkUtility.prepare_auth(ctx);
214
230
 
215
231
  return self.sdkUtility.make_fetch_def(ctx);