@voxgig/sdkgen 4.37.0 → 4.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/voxgig-sdkgen +1 -1
- package/dist/helpers/flowGuard.js +4 -4
- package/dist/helpers/flowGuard.js.map +1 -1
- package/dist/helpers/liveDiscovery.d.ts +7 -0
- package/dist/helpers/liveDiscovery.js +20 -0
- package/dist/helpers/liveDiscovery.js.map +1 -0
- package/dist/helpers/opShape.d.ts +2 -1
- package/dist/helpers/opShape.js +4 -0
- package/dist/helpers/opShape.js.map +1 -1
- package/dist/helpers/pointPath.d.ts +2 -1
- package/dist/helpers/pointPath.js +6 -0
- package/dist/helpers/pointPath.js.map +1 -1
- package/dist/helpers/testPolicy.d.ts +14 -4
- package/dist/helpers/testPolicy.js +152 -54
- package/dist/helpers/testPolicy.js.map +1 -1
- package/dist/sdkgen.d.ts +8 -6
- package/dist/sdkgen.js +11 -5
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.js +7 -3
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/c/TestDirect_c.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestDirect_cpp.ts +3 -2
- package/project/.sdk/src/cmp/cpp/TestEntity_cpp.ts +33 -10
- package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +12 -12
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +73 -28
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +12 -10
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +67 -23
- package/project/.sdk/src/cmp/java/TestDirect_java.ts +12 -11
- package/project/.sdk/src/cmp/java/TestEntity_java.ts +71 -23
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +13 -12
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +41 -17
- package/project/.sdk/src/cmp/kotlin/TestDirect_kotlin.ts +12 -10
- package/project/.sdk/src/cmp/kotlin/TestEntity_kotlin.ts +64 -23
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +9 -5
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +61 -23
- package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +9 -5
- package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +58 -24
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +9 -5
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +61 -23
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +10 -6
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +59 -27
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +9 -5
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +59 -23
- package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +9 -8
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +56 -24
- package/project/.sdk/src/cmp/scala/TestDirect_scala.ts +3 -2
- package/project/.sdk/src/cmp/scala/TestEntity_scala.ts +36 -9
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +15 -32
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +41 -17
- package/project/.sdk/tm/c/tests/transport_test.c +33 -0
- package/project/.sdk/tm/c/utility/fetcher.c +151 -2
- package/project/.sdk/tm/c/utility/make_url.c +8 -6
- package/project/.sdk/tm/clojure/src/sdk/core.clj +17 -10
- package/project/.sdk/tm/clojure/test/sdk/test/pipeline.clj +38 -0
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +5 -4
- package/project/.sdk/tm/csharp/test/PrimaryUtilityTest.cs +69 -0
- package/project/.sdk/tm/csharp/utility/Fetcher.cs +3 -1
- package/project/.sdk/tm/csharp/utility/MakeUrl.cs +5 -4
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +10 -6
- package/project/.sdk/tm/elixir/test/pipeline_test.exs +61 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +60 -0
- package/project/.sdk/tm/go/utility/fetcher.go +15 -4
- package/project/.sdk/tm/go/utility/make_url.go +4 -3
- package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +47 -0
- package/project/.sdk/tm/java/utility/MakeUrl.java +5 -4
- package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +5 -3
- package/project/.sdk/tm/js/test/live-runner.js +4 -3
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +40 -0
- package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +41 -0
- package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +4 -3
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +61 -0
- package/project/.sdk/tm/lua/utility/fetcher.lua +54 -6
- package/project/.sdk/tm/lua/utility/make_url.lua +5 -4
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +5 -5
- package/project/.sdk/tm/perl/t/primary_utility.t +54 -0
- package/project/.sdk/tm/perl/utility/fetcher.pm +65 -11
- package/project/.sdk/tm/perl/utility/make_url.pm +4 -3
- package/project/.sdk/tm/php/test/PipelineTest.php +52 -0
- package/project/.sdk/tm/php/utility/Fetcher.php +81 -15
- package/project/.sdk/tm/php/utility/MakeUrl.php +5 -3
- package/project/.sdk/tm/py/pkg/utility/fetcher.py +1 -0
- package/project/.sdk/tm/py/pkg/utility/make_url.py +5 -4
- package/project/.sdk/tm/py/test/test_primary_utility.py +52 -0
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +46 -0
- package/project/.sdk/tm/rb/utility/fetcher.rb +41 -5
- package/project/.sdk/tm/rb/utility/make_url.rb +5 -3
- package/project/.sdk/tm/rust/tests/primary_utility_test.rs +65 -0
- package/project/.sdk/tm/rust/utility/make_url.rs +7 -6
- package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +47 -1
- package/project/.sdk/tm/scala/utility/Make.scala +8 -6
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Fetcher.swift +59 -15
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +4 -4
- package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/PrimaryUtilityTest.swift +72 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +5 -3
- package/project/.sdk/tm/ts/test/live-runner.ts +4 -3
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +40 -0
- package/project/.sdk/tm/zig/core/utility.zig +5 -5
- package/project/sdkgen-package.json +1 -1
- package/src/helpers/flowGuard.ts +4 -4
- package/src/helpers/liveDiscovery.ts +31 -0
- package/src/helpers/opShape.ts +6 -0
- package/src/helpers/pointPath.ts +8 -0
- package/src/helpers/testPolicy.ts +193 -55
- package/src/sdkgen.ts +13 -3
- package/src/utility.ts +10 -4
|
@@ -35,19 +35,20 @@ import {
|
|
|
35
35
|
isAuthActive,
|
|
36
36
|
serverVarEnv,
|
|
37
37
|
serverVariables,
|
|
38
|
-
entityDataIdField, envName, envToken,
|
|
38
|
+
entityDataIdField, entityRecordIdField, envName, envToken,
|
|
39
39
|
jsKey,
|
|
40
40
|
jsProp,
|
|
41
41
|
hasLiveScenarios,
|
|
42
42
|
liveStrict,
|
|
43
43
|
liveStrictNote,
|
|
44
44
|
liveEntity,
|
|
45
|
-
|
|
45
|
+
liveGates,
|
|
46
46
|
liveFlowRoutes,
|
|
47
47
|
flowLoadRoute,
|
|
48
48
|
flowLoadReadsRecord,
|
|
49
49
|
LIVE_GETONLY_ENV,
|
|
50
50
|
} from '@voxgig/sdkgen'
|
|
51
|
+
import type { LiveGate } from '@voxgig/sdkgen'
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
import {
|
|
@@ -57,11 +58,16 @@ import {
|
|
|
57
58
|
|
|
58
59
|
// See TestEntity_ts.ts for the GenCtx/OpGen contract — this file mirrors
|
|
59
60
|
// it exactly, the only difference being the language string emitted.
|
|
60
|
-
// The steps a
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
// The steps a live run leaves out, for the live harness: a GET-only run's
|
|
62
|
+
// when the guard is set, else those any live run leaves out.
|
|
63
|
+
function excludedArg(entity: any, flow: any): string {
|
|
64
|
+
const gates = liveGates(entity, flow)
|
|
65
|
+
const getOnly = gates.find((gate) => gate.getOnly)
|
|
66
|
+
const any = gates.find((gate) => !gate.getOnly)
|
|
67
|
+
const map = (gate?: LiveGate) => JSON.stringify(
|
|
68
|
+
Object.fromEntries((gate?.plan.excluded || []).map(({ id, reason }) => [id, reason])))
|
|
69
|
+
return null != getOnly ? `, 'TRUE' === process.env.${LIVE_GETONLY_ENV} ? ${map(getOnly)} : ${map(any)}` :
|
|
70
|
+
0 < (any?.plan.excluded.length || 0) ? ', ' + map(any) : ''
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
|
|
@@ -159,7 +165,7 @@ function basicSetup(extra) {
|
|
|
159
165
|
|
|
160
166
|
// TODO: need a xlang JSON parse utility in voxgig/struct with better error msgs
|
|
161
167
|
const entityData = JSON.parse(entityDataSource)
|
|
162
|
-
|
|
168
|
+
${fixtureIdentity(entity)}
|
|
163
169
|
options.entity = entityData.existing
|
|
164
170
|
|
|
165
171
|
let client = ${model.Name}SDK.test(options, extra)
|
|
@@ -235,7 +241,7 @@ function basicSetup(extra) {
|
|
|
235
241
|
${hasLiveScenarios(model) ? `if (process.env.${PROJENVNAME}_TEST_LIVE === 'TRUE') { t.skip('Covered by live operation scenarios'); return }` : ''}
|
|
236
242
|
const setup = basicSetup()
|
|
237
243
|
if (setup.live) {
|
|
238
|
-
return runLiveEntity(setup, ${JSON.stringify(liveEntity(ctx$, entity))}, ${JSON.stringify(liveFlowRoutes(entity, basicflow))}, '${nom(entity, 'Name')}', ${JSON.stringify(liveFacts)}, { strict: LIVE_STRICT, t }${
|
|
244
|
+
return runLiveEntity(setup, ${JSON.stringify(liveEntity(ctx$, entity))}, ${JSON.stringify(liveFlowRoutes(entity, basicflow))}, '${nom(entity, 'Name')}', ${JSON.stringify(liveFacts)}, { strict: LIVE_STRICT, t }${excludedArg(entity, basicflow)})
|
|
239
245
|
}
|
|
240
246
|
const client = setup.client
|
|
241
247
|
const struct = setup.struct
|
|
@@ -316,7 +322,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
316
322
|
${datavar} = (await ${entvar}.create(${datavar})).data()
|
|
317
323
|
`)
|
|
318
324
|
if (hasEntIdC) {
|
|
319
|
-
Content(` assert(null != ${datavar}
|
|
325
|
+
Content(` assert(null != ${rid(entity, datavar)})
|
|
320
326
|
`)
|
|
321
327
|
}
|
|
322
328
|
else {
|
|
@@ -365,12 +371,12 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
365
371
|
|
|
366
372
|
if ('ItemExists' === validator.apply && hasRefData && hasDataId) {
|
|
367
373
|
Content(`
|
|
368
|
-
assert(!isempty(select(${listvar}, {
|
|
374
|
+
assert(!isempty(select(${listvar}, { ${jsKey(entityRecordIdField(entity))}: ${rid(entity, validRef + '_data')} })))
|
|
369
375
|
`)
|
|
370
376
|
}
|
|
371
377
|
else if ('ItemNotExists' === validator.apply && hasRefData && hasDataId) {
|
|
372
378
|
Content(`
|
|
373
|
-
assert(isempty(select(${listvar}, {
|
|
379
|
+
assert(isempty(select(${listvar}, { ${jsKey(entityRecordIdField(entity))}: ${rid(entity, validRef + '_data')} })))
|
|
374
380
|
`)
|
|
375
381
|
}
|
|
376
382
|
}
|
|
@@ -402,7 +408,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
402
408
|
Content(` const ${datavar} = {}
|
|
403
409
|
`)
|
|
404
410
|
if (hasEntIdU) {
|
|
405
|
-
Content(` ${datavar}.id = ${srcdatavar}
|
|
411
|
+
Content(` ${datavar}.id = ${rid(entity, srcdatavar)}
|
|
406
412
|
`)
|
|
407
413
|
}
|
|
408
414
|
|
|
@@ -432,7 +438,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
432
438
|
const ${resdatavar} = (await ${entvar}.update(${datavar})).data()
|
|
433
439
|
`)
|
|
434
440
|
if (hasEntIdU) {
|
|
435
|
-
Content(` assert(${resdatavar}
|
|
441
|
+
Content(` assert(${rid(entity, resdatavar)} === ${datavar}.id)
|
|
436
442
|
`)
|
|
437
443
|
}
|
|
438
444
|
else {
|
|
@@ -493,11 +499,11 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
493
499
|
}
|
|
494
500
|
if (hasEntId) {
|
|
495
501
|
Content(` const ${matchvar} = {}
|
|
496
|
-
${matchvar}.id = ${srcdatavar}
|
|
502
|
+
${matchvar}.id = ${rid(entity, srcdatavar)}
|
|
497
503
|
`)
|
|
498
504
|
loadMatch(entity, step, matchvar, srcdatavar)
|
|
499
505
|
Content(` const ${datavar} = (await ${entvar}.load(${matchvar})).data()
|
|
500
|
-
assert(${datavar}
|
|
506
|
+
assert(${rid(entity, datavar)} === ${rid(entity, srcdatavar)})
|
|
501
507
|
`)
|
|
502
508
|
}
|
|
503
509
|
else {
|
|
@@ -537,7 +543,7 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
537
543
|
Content(` const ${matchvar} = {}
|
|
538
544
|
`)
|
|
539
545
|
if (hasEntIdR) {
|
|
540
|
-
Content(` ${matchvar}.id = ${srcdatavar}
|
|
546
|
+
Content(` ${matchvar}.id = ${rid(entity, srcdatavar)}
|
|
541
547
|
`)
|
|
542
548
|
}
|
|
543
549
|
parentMatch(step, matchvar)
|
|
@@ -546,6 +552,24 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
546
552
|
}
|
|
547
553
|
|
|
548
554
|
|
|
555
|
+
// The record field the entity's identity is read from, on a record.
|
|
556
|
+
function rid(entity: any, record: string): string {
|
|
557
|
+
return jsProp(record, entityRecordIdField(entity))
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
562
|
+
// in another field reads the key from there too.
|
|
563
|
+
function fixtureIdentity(entity: any): string {
|
|
564
|
+
const field = entityRecordIdField(entity)
|
|
565
|
+
return 'id' === field ? '' : `
|
|
566
|
+
for (const rec of Object.values((entityData.existing || {})[${JSON.stringify(entity.name)}] || {})) {
|
|
567
|
+
if (null != rec && null != rec.id) ${jsProp('rec', field)} = rec.id
|
|
568
|
+
}
|
|
569
|
+
`
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
|
|
549
573
|
// A child's route names its parents, and an entity no earlier step has
|
|
550
574
|
// filled knows none of them, so the call itself gives each parent id.
|
|
551
575
|
function parentMatch(step: any, matchvar: string) {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
snakify,
|
|
14
14
|
isAuthActive, envName, envToken,
|
|
15
15
|
pointParts,
|
|
16
|
+
pointSlash,
|
|
16
17
|
pointPlaceholders,
|
|
17
18
|
liveStrict,
|
|
18
19
|
liveStrictNote,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
liveQueryExamples,
|
|
23
24
|
liveEntity,
|
|
24
25
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
26
|
+
liveDirectDiscovery,
|
|
25
27
|
} from '@voxgig/sdkgen'
|
|
26
28
|
|
|
27
29
|
|
|
@@ -106,7 +108,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
106
108
|
const listOp = entity.op?.list
|
|
107
109
|
|
|
108
110
|
const loadPoint = loadOp?.points?.[0]
|
|
109
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
111
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
110
112
|
const allLoadParams = loadPoint?.g?.params || []
|
|
111
113
|
const _pathPlaceholders = new Set<string>(pointPlaceholders(loadPoint))
|
|
112
114
|
const _renameMap = (loadPoint?.r?.param || {}) as Record<string, string>
|
|
@@ -121,7 +123,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
121
123
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
122
124
|
|
|
123
125
|
const listPoint = listOp?.points?.[0]
|
|
124
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
126
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
125
127
|
const listParams = listPoint?.g?.params || []
|
|
126
128
|
|
|
127
129
|
const loadLiveQueryLines = liveQueryExamples(loadPoint)
|
|
@@ -297,13 +299,14 @@ ${listLiveQueryLines ? ' if (setup.live) {\n' + listLiveQueryLines + ' }\n
|
|
|
297
299
|
`)
|
|
298
300
|
}
|
|
299
301
|
else if (hasLoad && loadPoint) {
|
|
300
|
-
const
|
|
302
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
303
|
+
const ancestorParams = loadParams.filter((p: any) => p.n !== discovery?.param)
|
|
301
304
|
|
|
302
305
|
const liveKey = (p: any) => p.n === 'id' ? entity.name + '01' : p.n.replace(/_id$/, '') + '01'
|
|
303
306
|
let loadLiveIdKeys: string[] = []
|
|
304
307
|
if (loadParams.length > 0 && !loadAllHaveExamples) {
|
|
305
|
-
loadLiveIdKeys = [...new Set((
|
|
306
|
-
[...listParams, ...
|
|
308
|
+
loadLiveIdKeys = [...new Set((discovery ?
|
|
309
|
+
[...listParams, ...ancestorParams] : loadParams).map(liveKey))]
|
|
307
310
|
}
|
|
308
311
|
const loadSkipBlock = getOnlyKeysBlock(model, entity, 'direct-load-' + entity.name, loadLiveIdKeys) +
|
|
309
312
|
(loadLiveIdKeys.length > 0
|
|
@@ -345,7 +348,7 @@ ${loadSkipBlock} val client = setup.client
|
|
|
345
348
|
|
|
346
349
|
if (loadAllHaveExamples) {
|
|
347
350
|
Content(loadExampleLines + '\n')
|
|
348
|
-
} else if (
|
|
351
|
+
} else if (discovery) {
|
|
349
352
|
Content(` val listParams = linkedMapOf<String, Any?>()
|
|
350
353
|
`)
|
|
351
354
|
for (const p of listParams) {
|
|
@@ -371,14 +374,13 @@ ${loadSkipBlock} val client = setup.client
|
|
|
371
374
|
RunnerSupport.liveEmpty("The account has no ${entity.name} record to load")
|
|
372
375
|
}
|
|
373
376
|
val firstEnt = Helpers.toMapAny(listData[0]) ?: linkedMapOf()
|
|
374
|
-
if (firstEnt["
|
|
377
|
+
if (firstEnt["${discovery.field}"] == null) {
|
|
375
378
|
RunnerSupport.liveMiss(LIVE_STRICT, "Live load blocked: discovery returned no usable identity")
|
|
376
379
|
}
|
|
377
|
-
params["
|
|
380
|
+
params["${discovery.param}"] = firstEnt["${discovery.field}"]
|
|
378
381
|
`)
|
|
379
382
|
for (const p of ancestorParams) {
|
|
380
|
-
|
|
381
|
-
Content(` params["${p.n}"] = setup.idmap["${key}"]
|
|
383
|
+
Content(` params["${p.n}"] = setup.idmap["${liveKey(p)}"]
|
|
382
384
|
`)
|
|
383
385
|
}
|
|
384
386
|
} else if (loadParams.length > 0) {
|
|
@@ -18,9 +18,9 @@ import {
|
|
|
18
18
|
each,
|
|
19
19
|
buildIdNames,
|
|
20
20
|
getMatchEntries,
|
|
21
|
-
isAuthActive, envName, envToken,
|
|
21
|
+
isAuthActive, envName, envToken, entityRecordIdField,
|
|
22
22
|
liveFlowNeeds, liveStrict, liveStrictNote,
|
|
23
|
-
|
|
23
|
+
liveGates, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
24
24
|
liveRouteExamples, liveStepExamples,
|
|
25
25
|
liveEntity,
|
|
26
26
|
} from '@voxgig/sdkgen'
|
|
@@ -53,6 +53,12 @@ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
|
|
|
53
53
|
function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: string,
|
|
54
54
|
strict: boolean, hasSteps: boolean): string {
|
|
55
55
|
let out = ''
|
|
56
|
+
for (const [k, ex] of needs.examples || []) {
|
|
57
|
+
out += ` if (setup.live && (setup.syntheticOnly || setup.idmap?.get(${JSON.stringify(k)}) == null)) {
|
|
58
|
+
setup.idmap?.put(${JSON.stringify(k)}, ${kotlinIdLit(ex)})
|
|
59
|
+
}
|
|
60
|
+
`
|
|
61
|
+
}
|
|
56
62
|
if (0 < needs.keys.length) {
|
|
57
63
|
out += ` if (setup.live) {
|
|
58
64
|
for (liveKey in arrayOf<String>(${needs.keys.map((k: string) => JSON.stringify(k)).join(', ')})) {
|
|
@@ -73,6 +79,14 @@ function liveFlowGate(entity: any, needs: any, entidEnv: string, accessor: strin
|
|
|
73
79
|
return out
|
|
74
80
|
}
|
|
75
81
|
out += ' val client = setup.client\n'
|
|
82
|
+
if (null != needs.record) {
|
|
83
|
+
out += ` if (setup.live) {
|
|
84
|
+
RunnerSupport.liveExisting(setup.data!!, LIVE_STRICT, ${JSON.stringify(entity.name)}) {
|
|
85
|
+
listOf(linkedMapOf<String, Any?>("id" to setup.idmap?.get(${JSON.stringify(needs.record)})))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
}
|
|
76
90
|
if (null != needs.discover) {
|
|
77
91
|
const match = Object.entries(needs.discover)
|
|
78
92
|
.map(([k, v]: any) => `${JSON.stringify(k)} to setup.idmap?.get(${JSON.stringify(v)})`)
|
|
@@ -215,19 +229,18 @@ ${liveStrictNote(strict, '//', ' ')}
|
|
|
215
229
|
`)
|
|
216
230
|
}
|
|
217
231
|
|
|
218
|
-
const getOnly
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
Content(` Assumptions.assumeTrue(false, ${kotlinLit(liveExcludedSummary(getOnly))})
|
|
232
|
+
for (const { getOnly, plan, runs } of liveGates(entity, basicflow)) {
|
|
233
|
+
Content(` if (setup.live${getOnly ? ` && "TRUE" == System.getenv(${kotlinLit(LIVE_GETONLY_ENV)})` : ''}) {
|
|
234
|
+
${liveExcludedLines(plan).map((line) => ' println(' + kotlinLit(line) + ')\n').join('')}`)
|
|
235
|
+
if (!runs) {
|
|
236
|
+
Content(` Assumptions.assumeTrue(false, ${kotlinLit(liveExcludedSummary(plan))})
|
|
224
237
|
return
|
|
225
238
|
}
|
|
226
239
|
|
|
227
240
|
`)
|
|
228
241
|
}
|
|
229
242
|
else {
|
|
230
|
-
flowBody(
|
|
243
|
+
flowBody(plan.flow)
|
|
231
244
|
Content(` return
|
|
232
245
|
}
|
|
233
246
|
|
|
@@ -296,7 +309,7 @@ ${liveExcludedLines(getOnly).map((line) => ' println(' + kotlinLit(line) +
|
|
|
296
309
|
} catch (e: Exception) {
|
|
297
310
|
throw AssertionError("failed to read ${entity.name} test data: " + e.message, e)
|
|
298
311
|
}
|
|
299
|
-
|
|
312
|
+
${fixtureIdentity(entity)}
|
|
300
313
|
val options = linkedMapOf<String, Any?>()
|
|
301
314
|
options["entity"] = entityData["existing"]
|
|
302
315
|
|
|
@@ -410,7 +423,7 @@ const generateCreate: OpGen = (ctx, step, index) => {
|
|
|
410
423
|
assertNotNull(${datavar}, "expected create result to be a map")
|
|
411
424
|
`)
|
|
412
425
|
if (null != ctx.entity.id) {
|
|
413
|
-
Content(` assertNotNull(${datavar}[
|
|
426
|
+
Content(` assertNotNull(${datavar}[${rid(ctx.entity)}], "expected created entity to have an id")
|
|
414
427
|
`)
|
|
415
428
|
}
|
|
416
429
|
}
|
|
@@ -441,7 +454,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
441
454
|
Content(` ${matchvar}["${key}"] = setup.idmap!!["${val}"]
|
|
442
455
|
`)
|
|
443
456
|
}
|
|
444
|
-
Content(liveFill(entity, step, matchvar))
|
|
457
|
+
Content(liveFill(entity, step, matchvar, flow))
|
|
445
458
|
|
|
446
459
|
const allSteps = Object.values(flowSteps(flow)) as any[]
|
|
447
460
|
const listvarUsed = !!step.v?.some((v: any) => {
|
|
@@ -472,7 +485,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
472
485
|
Content(`
|
|
473
486
|
val foundItem = Struct.select(
|
|
474
487
|
RunnerSupport.entityListToData(${listvar}),
|
|
475
|
-
Struct.jm(
|
|
488
|
+
Struct.jm(${rid(entity)}, ${refDataVar}[${rid(entity)}]))
|
|
476
489
|
assertFalse(Struct.isempty(foundItem), "expected to find created entity in list")
|
|
477
490
|
`)
|
|
478
491
|
} else if ('ItemNotExists' === validator.apply && hasRefData) {
|
|
@@ -480,7 +493,7 @@ const generateList: OpGen = (ctx, step, index) => {
|
|
|
480
493
|
Content(`
|
|
481
494
|
val notFoundItem = Struct.select(
|
|
482
495
|
RunnerSupport.entityListToData(${listvar}),
|
|
483
|
-
Struct.jm(
|
|
496
|
+
Struct.jm(${rid(entity)}, ${refDataVar}[${rid(entity)}]))
|
|
484
497
|
assertTrue(Struct.isempty(notFoundItem), "expected removed entity to not be in list")
|
|
485
498
|
`)
|
|
486
499
|
}
|
|
@@ -513,7 +526,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
513
526
|
Content(` val ${datavar}Up = linkedMapOf<String, Any?>()
|
|
514
527
|
`)
|
|
515
528
|
if (hasEntIdU) {
|
|
516
|
-
Content(` ${datavar}Up["id"] = ${srcdatavar}[
|
|
529
|
+
Content(` ${datavar}Up["id"] = ${srcdatavar}[${rid(entity)}]
|
|
517
530
|
`)
|
|
518
531
|
}
|
|
519
532
|
|
|
@@ -545,7 +558,7 @@ const generateUpdate: OpGen = (ctx, step, index) => {
|
|
|
545
558
|
assertNotNull(${resdatavar}, "expected update result to be a map")
|
|
546
559
|
`)
|
|
547
560
|
if (hasEntIdU) {
|
|
548
|
-
Content(` assertEquals(${datavar}Up["id"], ${resdatavar}[
|
|
561
|
+
Content(` assertEquals(${datavar}Up["id"], ${resdatavar}[${rid(entity)}],
|
|
549
562
|
"expected update result id to match")
|
|
550
563
|
`)
|
|
551
564
|
}
|
|
@@ -604,15 +617,15 @@ const generateLoad: OpGen = (ctx, step, index) => {
|
|
|
604
617
|
Content(` val ${matchvar} = linkedMapOf<String, Any?>()
|
|
605
618
|
`)
|
|
606
619
|
if (hasEntId) {
|
|
607
|
-
Content(` ${matchvar}["id"] = ${srcdatavar}[
|
|
608
|
-
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
|
|
620
|
+
Content(` ${matchvar}["id"] = ${srcdatavar}[${rid(entity)}]
|
|
621
|
+
${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
|
|
609
622
|
val ${datavar}LoadResult = Helpers.toMapAny(if (${datavar}Loaded is SdkEntity) ${datavar}Loaded.data() else ${datavar}Loaded) ?: linkedMapOf()
|
|
610
623
|
assertNotNull(${datavar}LoadResult, "expected load result to be a map")
|
|
611
|
-
assertEquals(${srcdatavar}[
|
|
624
|
+
assertEquals(${srcdatavar}[${rid(entity)}], ${datavar}LoadResult[${rid(entity)}],
|
|
612
625
|
"expected load result id to match")
|
|
613
626
|
`)
|
|
614
627
|
} else {
|
|
615
|
-
Content(`${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
|
|
628
|
+
Content(`${loadMatch(entity, step, matchvar, srcdatavar)}${liveFill(entity, step, matchvar, flow)} val ${datavar}Loaded = ${entvar}.load(${matchvar}, null)
|
|
616
629
|
assertNotNull(${datavar}Loaded, "expected load result to be non-null")
|
|
617
630
|
`)
|
|
618
631
|
}
|
|
@@ -637,12 +650,34 @@ const generateRemove: OpGen = (ctx, step, index) => {
|
|
|
637
650
|
`)
|
|
638
651
|
}
|
|
639
652
|
Content(` val ${matchvar} = linkedMapOf<String, Any?>()
|
|
640
|
-
${matchvar}["id"] = ${srcdatavar}[
|
|
653
|
+
${matchvar}["id"] = ${srcdatavar}[${rid(entity)}]
|
|
641
654
|
${parentMatch(step, matchvar)} ${entvar}.remove(${matchvar}, null)
|
|
642
655
|
`)
|
|
643
656
|
}
|
|
644
657
|
|
|
645
658
|
|
|
659
|
+
// The record field the entity's identity is read from, as a Kotlin string.
|
|
660
|
+
function rid(entity: any): string {
|
|
661
|
+
return JSON.stringify(entityRecordIdField(entity))
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
// The fixture keeps each record's key in `id`; an entity keeping its identity
|
|
666
|
+
// in another field reads the key from there too.
|
|
667
|
+
function fixtureIdentity(entity: any): string {
|
|
668
|
+
const field = entityRecordIdField(entity)
|
|
669
|
+
return 'id' === field ? '' : `
|
|
670
|
+
((entityData["existing"] as? Map<*, *>)?.get(${JSON.stringify(entity.name)}) as? Map<*, *>)?.values?.forEach { fixtureRec ->
|
|
671
|
+
@Suppress("UNCHECKED_CAST")
|
|
672
|
+
val fixtureRecMap = fixtureRec as? MutableMap<String, Any?>
|
|
673
|
+
if (fixtureRecMap != null && fixtureRecMap["id"] != null) {
|
|
674
|
+
fixtureRecMap[${JSON.stringify(field)}] = fixtureRecMap["id"]
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
`
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
|
|
646
681
|
// A child's route names its parents, and an entity no earlier step has
|
|
647
682
|
// filled knows none of them, so the call itself gives each parent id. A live
|
|
648
683
|
// ENTID may key a parent by its field name, the fixture by its own name.
|
|
@@ -652,9 +687,15 @@ function kotlinLit(value: any): string {
|
|
|
652
687
|
}
|
|
653
688
|
|
|
654
689
|
|
|
690
|
+
// A whole number as Json.parse decodes one, so an example equals a record's id.
|
|
691
|
+
function kotlinIdLit(value: any): string {
|
|
692
|
+
return Number.isSafeInteger(value) ? value + 'L' : kotlinLit(value)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
|
|
655
696
|
// A live step sends each example its route requires and the step leaves unbound.
|
|
656
|
-
function liveFill(entity: any, step: any, matchvar: string): string {
|
|
657
|
-
const fills = liveStepExamples(entity, step)
|
|
697
|
+
function liveFill(entity: any, step: any, matchvar: string, flow: any): string {
|
|
698
|
+
const fills = liveStepExamples(entity, step, flow)
|
|
658
699
|
return 0 === fills.length ? '' : ` if (setup.live) {
|
|
659
700
|
${fills.map(([k, ex]) => ` ${matchvar}[${JSON.stringify(k)}] = ${kotlinLit(ex)}\n`).join('')} }
|
|
660
701
|
`
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
serverVarEnv,
|
|
16
16
|
serverVariables,
|
|
17
17
|
pointParts,
|
|
18
|
+
pointSlash,
|
|
18
19
|
pointPlaceholders,
|
|
19
20
|
liveStrict,
|
|
20
21
|
liveStrictNote,
|
|
@@ -24,6 +25,7 @@ import {
|
|
|
24
25
|
liveQueryExamples,
|
|
25
26
|
liveEntity,
|
|
26
27
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary, LIVE_GETONLY_ENV,
|
|
28
|
+
liveDirectDiscovery,
|
|
27
29
|
} from '@voxgig/sdkgen'
|
|
28
30
|
|
|
29
31
|
import { formatLuaValue } from './utility_lua'
|
|
@@ -134,7 +136,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
134
136
|
const listOp = entity.op?.list
|
|
135
137
|
|
|
136
138
|
const loadPoint = loadOp?.points?.[0]
|
|
137
|
-
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) : ''
|
|
139
|
+
const loadPath = loadPoint ? normalizePathParams(pointParts(loadPoint), loadPoint?.g?.params || [], loadPoint?.r?.param) + pointSlash(loadPoint) : ''
|
|
138
140
|
const allLoadParams = loadPoint?.g?.params || []
|
|
139
141
|
// Some upstream OpenAPI specs declare a parameter as `in: path` even when
|
|
140
142
|
// that path has no `{name}` placeholder for it. Only path params that
|
|
@@ -154,7 +156,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
154
156
|
_renamedPlaceholders.has(p.n) || _renamedPlaceholders.has(p.or))
|
|
155
157
|
|
|
156
158
|
const listPoint = listOp?.points?.[0]
|
|
157
|
-
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) : ''
|
|
159
|
+
const listPath = listPoint ? normalizePathParams(pointParts(listPoint), listPoint?.g?.params || [], listPoint?.r?.param) + pointSlash(listPoint) : ''
|
|
158
160
|
const listParams = listPoint?.g?.params || []
|
|
159
161
|
|
|
160
162
|
// Required query params with spec-provided examples — needed in live mode.
|
|
@@ -270,8 +272,10 @@ ${listLiveQueryLines ? ' if setup.live then\n' + listLiveQueryLines + ' en
|
|
|
270
272
|
`)
|
|
271
273
|
}
|
|
272
274
|
else if (hasLoad && loadPoint) {
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
+
const discovery = liveDirectDiscovery(entity, loadParams, listPoint)
|
|
276
|
+
const discover = null != discovery
|
|
277
|
+
const idParam = discovery?.param
|
|
278
|
+
const idField = discovery?.field
|
|
275
279
|
const loadLiveIdKeys: string[] = loadAllHaveExamples ? [] :
|
|
276
280
|
discover ? listParams.map(liveKey).concat(loadParams.filter((p: any) => idParam !== p.n).map(liveKey)) :
|
|
277
281
|
loadParams.map(liveKey)
|
|
@@ -308,7 +312,7 @@ ${loadLiveQueryLines ? loadLiveQueryLines + '\n' : ''}`)
|
|
|
308
312
|
runner.live_empty(pending, "The account has no ${entity.name} record to load")
|
|
309
313
|
end
|
|
310
314
|
local first = type(records[1]) == "table" and records[1] or {}
|
|
311
|
-
local found = first["${
|
|
315
|
+
local found = first["${idField}"]
|
|
312
316
|
if found == nil then
|
|
313
317
|
runner.live_miss(pending, LIVE_STRICT, "Live load blocked: discovery returned no usable identity")
|
|
314
318
|
end
|