@voxgig/sdkgen 4.37.0 → 4.39.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 +13 -2
- package/dist/action/copies.d.ts +6 -1
- package/dist/action/copies.js +43 -1
- package/dist/action/copies.js.map +1 -1
- package/dist/action/doctor.d.ts +2 -0
- package/dist/action/doctor.js +25 -6
- package/dist/action/doctor.js.map +1 -1
- package/dist/action/edition.js +3 -0
- package/dist/action/edition.js.map +1 -1
- package/dist/action/feature.js +3 -0
- package/dist/action/feature.js.map +1 -1
- package/dist/action/package.js +15 -0
- package/dist/action/package.js.map +1 -1
- package/dist/action/target.js +3 -0
- package/dist/action/target.js.map +1 -1
- package/dist/helpers/copymerge.d.ts +35 -0
- package/dist/helpers/copymerge.js +508 -0
- package/dist/helpers/copymerge.js.map +1 -0
- 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/types.d.ts +1 -0
- package/dist/utility.js +7 -3
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.aontu +4 -0
- 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/action/copies.ts +54 -0
- package/src/action/doctor.ts +36 -7
- package/src/action/edition.ts +9 -1
- package/src/action/feature.ts +7 -1
- package/src/action/package.ts +28 -1
- package/src/action/target.ts +7 -1
- package/src/helpers/copymerge.ts +707 -0
- 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/types.ts +2 -0
- package/src/utility.ts +10 -4
package/src/helpers/flowGuard.ts
CHANGED
|
@@ -20,8 +20,8 @@ const GENERATED = ['create', 'list', 'load', 'update', 'remove']
|
|
|
20
20
|
|
|
21
21
|
// A generated flow test calls each step's op with its own match and data,
|
|
22
22
|
// the record's id where the op acts on one, and what the entity instance
|
|
23
|
-
// holds. A step whose call reaches no route is
|
|
24
|
-
//
|
|
23
|
+
// holds. A step whose op is absent, or whose call reaches no route, is
|
|
24
|
+
// switched off and marked unreachable for the live harness to resolve.
|
|
25
25
|
function guardFlowSteps(model: any, log?: any): Unreachable[] {
|
|
26
26
|
const kit = model?.main?.[KIT]
|
|
27
27
|
const flows = kit?.flow
|
|
@@ -76,7 +76,7 @@ function guardFlowSteps(model: any, log?: any): Unreachable[] {
|
|
|
76
76
|
]
|
|
77
77
|
|
|
78
78
|
const op = ent.op?.[step.o]
|
|
79
|
-
if (null
|
|
79
|
+
if (null == op || !opReachable(op, given)) {
|
|
80
80
|
step.a = false
|
|
81
81
|
step.unreachable = true
|
|
82
82
|
if ('remove' === step.o && null != step.i?.ref) unremoved.add(step.i.ref)
|
|
@@ -103,7 +103,7 @@ function guardFlowSteps(model: any, log?: any): Unreachable[] {
|
|
|
103
103
|
point: 'flow-step-unreachable',
|
|
104
104
|
steps: out.map((s) => s.flow + '.' + s.step + ':' + s.op),
|
|
105
105
|
note: 'flow step(s) ' + out.map((s) => s.flow + '#' + s.step + ' (' + s.op + ')').join(', ') +
|
|
106
|
-
' switched off: the call they make reaches no route of
|
|
106
|
+
' switched off: the entity has no such operation, the call they make reaches no route of it, ' +
|
|
107
107
|
'or they check a removal such a step was to make. ' +
|
|
108
108
|
'Every route needs an action, or a path parameter the step does not give.',
|
|
109
109
|
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
type LiveDiscovery = {
|
|
3
|
+
// the load path parameter the first listed record fills
|
|
4
|
+
param: string
|
|
5
|
+
// the field of that record it reads
|
|
6
|
+
field: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// What a live direct load lists to find, the same in every target. Only a path
|
|
11
|
+
// parameter the list route does not also take can come from a listed record,
|
|
12
|
+
// `id` first; every other one comes from *_ENTID or its example. A route with no
|
|
13
|
+
// path parameter, or an example for each, loads directly.
|
|
14
|
+
function liveDirectDiscovery(entity: any, loadParams: any[], listPoint: any):
|
|
15
|
+
LiveDiscovery | undefined {
|
|
16
|
+
if (null == listPoint || loadParams.every((p: any) => null != p.ex)) {
|
|
17
|
+
return undefined
|
|
18
|
+
}
|
|
19
|
+
const listed = new Set((listPoint.g?.params || []).map((p: any) => p.n))
|
|
20
|
+
const open = loadParams.filter((p: any) => !listed.has(p.n))
|
|
21
|
+
const param: string | undefined = (open.find((p: any) => 'id' === p.n) ?? open[0])?.n
|
|
22
|
+
if (null == param) {
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
return { param, field: 'id' === param ? (entity?.id?.field || 'id') : param }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export type { LiveDiscovery }
|
|
30
|
+
|
|
31
|
+
export { liveDirectDiscovery }
|
package/src/helpers/opShape.ts
CHANGED
|
@@ -753,6 +753,11 @@ function entityDataIdField(ent: any): string | null {
|
|
|
753
753
|
}
|
|
754
754
|
|
|
755
755
|
|
|
756
|
+
function entityRecordIdField(ent: any): string {
|
|
757
|
+
return entityDataIdField(ent) ?? 'id'
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
|
|
756
761
|
export {
|
|
757
762
|
CANON_OP_ORDER,
|
|
758
763
|
OP_SUFFIX,
|
|
@@ -772,6 +777,7 @@ export {
|
|
|
772
777
|
opRequestShape,
|
|
773
778
|
entityIdField,
|
|
774
779
|
entityDataIdField,
|
|
780
|
+
entityRecordIdField,
|
|
775
781
|
entityOps,
|
|
776
782
|
invalidRequest,
|
|
777
783
|
entityPrimaryOp,
|
package/src/helpers/pointPath.ts
CHANGED
|
@@ -31,6 +31,13 @@ function pointParts(point: any): string[] {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
// The trailing slash a route declares, which its segments do not hold.
|
|
35
|
+
function pointSlash(point: any): string {
|
|
36
|
+
const orig = point?.o ?? point?.orig
|
|
37
|
+
return 'string' === typeof orig && orig.endsWith('/') ? '/' : ''
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
34
41
|
// The path parameters a point's URL needs, including a placeholder inside a
|
|
35
42
|
// literal segment such as `{version}.mod`.
|
|
36
43
|
function pointPlaceholders(point: any): string[] {
|
|
@@ -71,6 +78,7 @@ export type {
|
|
|
71
78
|
export {
|
|
72
79
|
pointSegments,
|
|
73
80
|
pointParts,
|
|
81
|
+
pointSlash,
|
|
74
82
|
pointPlaceholders,
|
|
75
83
|
pointTerminalParam,
|
|
76
84
|
pointPathKey,
|
|
@@ -26,9 +26,15 @@ function liveStrictNote(strict: boolean, prefix: string, indent = ''): string {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
type Scalar = string | number | boolean
|
|
30
|
+
|
|
29
31
|
type LiveFlowNeeds = {
|
|
30
32
|
// idmap keys the steps bind, which only the *_ENTID variable supplies live
|
|
31
33
|
keys: string[]
|
|
34
|
+
// idmap keys a live run takes from an example when *_ENTID gives none
|
|
35
|
+
examples?: [string, Scalar][]
|
|
36
|
+
// idmap key of the id a load reads when no earlier step finds its record
|
|
37
|
+
record?: string
|
|
32
38
|
// match of the list that finds the existing record a create-less load reads
|
|
33
39
|
discover?: Record<string, string>
|
|
34
40
|
// why the flow cannot run against a live API at all
|
|
@@ -36,24 +42,45 @@ type LiveFlowNeeds = {
|
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
|
|
45
|
+
const bindings = (map: any): [string, string][] => Object.entries(map || {})
|
|
46
|
+
.filter(([k, v]: any) => !k.endsWith('$') && 'string' === typeof v && '' !== v) as [string, string][]
|
|
47
|
+
|
|
48
|
+
|
|
39
49
|
// What an entity flow generated from the offline fixtures needs before it
|
|
40
|
-
// can run live
|
|
41
|
-
//
|
|
50
|
+
// can run live: a create gives its record, a list finds it, else *_ENTID or
|
|
51
|
+
// the load's example names it. A bound parameter falls back to its example.
|
|
42
52
|
function liveFlowNeeds(entity: any, flow: any): LiveFlowNeeds {
|
|
43
53
|
const steps: any[] = flowSteps(flow)
|
|
44
54
|
const hasCreate = steps.some((step) => 'create' === step.o)
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
.map(([, v]) => v as string)
|
|
55
|
+
const keyed = null != entity?.id
|
|
56
|
+
const list = steps.find((step) => 'list' === step.o)
|
|
48
57
|
|
|
49
58
|
const keys = new Set<string>()
|
|
59
|
+
const examples = new Map<string, Scalar>()
|
|
60
|
+
const fill = (args: LiveArg[]) => args.filter((arg) => null != arg.key).forEach((arg) =>
|
|
61
|
+
undefined === arg.ex ? keys.add(arg.key!) : examples.has(arg.key!) || examples.set(arg.key!, arg.ex))
|
|
62
|
+
let unrouted = false
|
|
50
63
|
for (const step of steps) {
|
|
51
|
-
if ('create' === step.o
|
|
52
|
-
if ('update' === step.o)
|
|
64
|
+
if ('create' === step.o) bindings(step.m).forEach(([, k]) => keys.add(k))
|
|
65
|
+
if ('update' === step.o) bindings(step.d).forEach(([, k]) => keys.add(k))
|
|
66
|
+
if ('list' === step.o) {
|
|
67
|
+
const args = liveStepArgs(entity, step, flow) || []
|
|
68
|
+
fill(args)
|
|
69
|
+
bindings(step.m).filter(([, k]) => !args.some((arg) => k === arg.key)).forEach(([, k]) => keys.add(k))
|
|
70
|
+
}
|
|
71
|
+
if ('load' === step.o && !liveRecordFound(entity, flow)) {
|
|
72
|
+
const args = liveStepArgs(entity, step, flow)
|
|
73
|
+
unrouted = unrouted || null == args
|
|
74
|
+
fill(args || [])
|
|
75
|
+
}
|
|
53
76
|
}
|
|
54
77
|
|
|
55
78
|
const needs: LiveFlowNeeds = { keys: [...keys] }
|
|
56
|
-
|
|
79
|
+
const seeded = [...examples].filter(([key]) => !keys.has(key))
|
|
80
|
+
if (0 < seeded.length) {
|
|
81
|
+
needs.examples = seeded
|
|
82
|
+
}
|
|
83
|
+
if (hasCreate || !keyed) {
|
|
57
84
|
return needs
|
|
58
85
|
}
|
|
59
86
|
|
|
@@ -61,16 +88,20 @@ function liveFlowNeeds(entity: any, flow: any): LiveFlowNeeds {
|
|
|
61
88
|
needs.blocked = 'the flow updates a ' + entity.name + ' record it did not create'
|
|
62
89
|
}
|
|
63
90
|
else if (steps.some((step) => 'load' === step.o)) {
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
if (null != list) {
|
|
92
|
+
needs.discover = Object.fromEntries(bindings(list.m))
|
|
93
|
+
}
|
|
94
|
+
else if (unrouted) {
|
|
66
95
|
needs.blocked = 'the flow loads a ' + entity.name + ' record it has no list to find'
|
|
67
96
|
}
|
|
68
97
|
else {
|
|
69
|
-
needs.
|
|
70
|
-
.filter(([k, v]: any) => !k.endsWith('$') && 'string' === typeof v && '' !== v)) as any
|
|
98
|
+
needs.record = loadIdKey(entity, steps.find((step) => 'load' === step.o))
|
|
71
99
|
}
|
|
72
100
|
}
|
|
73
101
|
|
|
102
|
+
if (null != needs.blocked) {
|
|
103
|
+
delete needs.examples
|
|
104
|
+
}
|
|
74
105
|
return needs
|
|
75
106
|
}
|
|
76
107
|
|
|
@@ -81,13 +112,13 @@ function liveIdKey(entityName: string, paramName: string): string {
|
|
|
81
112
|
}
|
|
82
113
|
|
|
83
114
|
|
|
84
|
-
function scalar(value: any):
|
|
115
|
+
function scalar(value: any): Scalar | undefined {
|
|
85
116
|
return 'string' === typeof value || 'number' === typeof value || 'boolean' === typeof value ?
|
|
86
117
|
value : undefined
|
|
87
118
|
}
|
|
88
119
|
|
|
89
120
|
|
|
90
|
-
function scalarExample(arg: any):
|
|
121
|
+
function scalarExample(arg: any): Scalar | undefined {
|
|
91
122
|
return scalar(arg?.ex)
|
|
92
123
|
}
|
|
93
124
|
|
|
@@ -114,29 +145,61 @@ function liveQueryExamples(point: any): [string, string | number | boolean][] {
|
|
|
114
145
|
}
|
|
115
146
|
|
|
116
147
|
|
|
117
|
-
const
|
|
118
|
-
|
|
148
|
+
const isAction = (point: any) => null != point.q?.$action
|
|
149
|
+
|
|
150
|
+
// An action route only when the operation has no other.
|
|
151
|
+
function plainPoints(entity: any, opname: string): any[] {
|
|
152
|
+
const points = (entity?.op?.[opname]?.points || []).filter((point: any) => false !== point.a)
|
|
153
|
+
const plain = points.filter((point: any) => !isAction(point))
|
|
154
|
+
return 0 < plain.length ? plain : points
|
|
155
|
+
}
|
|
119
156
|
|
|
120
157
|
|
|
121
|
-
|
|
122
|
-
|
|
158
|
+
// `key`: the idmap key the step binds the argument to, which *_ENTID supplies.
|
|
159
|
+
type LiveArg = { name: string, ex?: Scalar, key?: string, bound?: boolean }
|
|
160
|
+
|
|
161
|
+
function routeArgs(point: any, bound: Map<string, any>, pathBound: boolean): LiveArg[] | undefined {
|
|
123
162
|
const params = pathBound ? [] : point.g?.params || []
|
|
124
163
|
const args = [...params, ...(point.g?.query || []).filter((arg: any) => arg.r)]
|
|
125
|
-
const
|
|
164
|
+
const out: LiveArg[] = []
|
|
126
165
|
for (const arg of args) {
|
|
127
|
-
if (
|
|
166
|
+
if (out.some(({ name }) => name === arg.n)) continue
|
|
128
167
|
const ex = scalarExample(arg)
|
|
129
|
-
|
|
168
|
+
const binding = bound.get(arg.n)
|
|
169
|
+
if (bound.has(arg.n)) {
|
|
170
|
+
out.push({ name: arg.n, ex, bound: true, ...('string' === typeof binding ? { key: binding } : {}) })
|
|
171
|
+
}
|
|
172
|
+
else if (undefined !== ex) out.push({ name: arg.n, ex })
|
|
130
173
|
else if (false !== arg.r) return undefined
|
|
131
174
|
}
|
|
132
|
-
return
|
|
175
|
+
return out
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
function routeExamples(point: any, bound: string[], pathBound: boolean):
|
|
180
|
+
[string, Scalar][] | undefined {
|
|
181
|
+
const args = routeArgs(point, new Map(bound.map((name) => [name, undefined])), pathBound)
|
|
182
|
+
return null == args ? undefined : unboundExamples(args)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
const unboundExamples = (args: LiveArg[]): [string, Scalar][] =>
|
|
187
|
+
args.filter((arg) => !arg.bound).map((arg) => [arg.name, arg.ex!])
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
function firstRouteArgs(points: any[], bound: Map<string, any>, pathBound: boolean): LiveArg[] | undefined {
|
|
191
|
+
for (const point of points) {
|
|
192
|
+
const args = routeArgs(point, bound, pathBound)
|
|
193
|
+
if (null != args) return args
|
|
194
|
+
}
|
|
195
|
+
return undefined
|
|
133
196
|
}
|
|
134
197
|
|
|
135
198
|
|
|
136
199
|
// The live entity harness's route: the first whose required parameters are
|
|
137
200
|
// all bound or exemplified. A load of a known record binds its own path.
|
|
138
201
|
function liveRouteExamples(entity: any, opname: string, bound: string[], pathBound = false):
|
|
139
|
-
[string,
|
|
202
|
+
[string, Scalar][] {
|
|
140
203
|
for (const point of plainPoints(entity, opname)) {
|
|
141
204
|
const fill = routeExamples(point, bound, pathBound)
|
|
142
205
|
if (null != fill) return fill
|
|
@@ -145,13 +208,47 @@ function liveRouteExamples(entity: any, opname: string, bound: string[], pathBou
|
|
|
145
208
|
}
|
|
146
209
|
|
|
147
210
|
|
|
148
|
-
|
|
211
|
+
// A record the flow creates or its list finds; an entity with no id has none.
|
|
212
|
+
function liveRecordFound(entity: any, flow: any): boolean {
|
|
213
|
+
return null != entity?.id &&
|
|
214
|
+
flowSteps(flow).some((step: any) => 'create' === step.o || 'list' === step.o)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// The idmap key a live load of no known record reads its id from.
|
|
219
|
+
function loadIdKey(entity: any, step: any): string {
|
|
220
|
+
const binding = getMatchEntries(step).find(([name]) => 'id' === name)?.[1]
|
|
221
|
+
return 'string' === typeof binding && '' !== binding ? binding : liveIdKey(entity.name, 'id')
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
// The arguments of the route a live list or load takes; undefined when none qualifies.
|
|
226
|
+
function liveStepArgs(entity: any, step: any, flow?: any): LiveArg[] | undefined {
|
|
149
227
|
if ('list' !== step?.o && 'load' !== step?.o) return []
|
|
150
|
-
const bound = getMatchEntries(step)
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
228
|
+
const bound = new Map<string, any>(getMatchEntries(step))
|
|
229
|
+
const keyed = 'load' === step.o && null != entity?.id
|
|
230
|
+
if (keyed && (null == flow || liveRecordFound(entity, flow))) {
|
|
231
|
+
const route = flowLoadRoute(entity, step)
|
|
232
|
+
return null == route ? firstRouteArgs(plainPoints(entity, 'load'), bound, true) :
|
|
233
|
+
routeArgs(route.point, bound, true)
|
|
234
|
+
}
|
|
235
|
+
if (keyed) {
|
|
236
|
+
bound.set('id', loadIdKey(entity, step))
|
|
237
|
+
}
|
|
238
|
+
else if ('load' === step.o) {
|
|
239
|
+
// The match of a load of an entity with no id never carries an id binding.
|
|
240
|
+
bound.delete('id')
|
|
241
|
+
}
|
|
242
|
+
const route = keyed ? flowLoadRoute(entity, step) : undefined
|
|
243
|
+
const points = plainPoints(entity, step.o)
|
|
244
|
+
return firstRouteArgs(null == route ? points :
|
|
245
|
+
[route.point, ...points.filter((point) => point !== route.point)], bound, false)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
// The examples of the arguments a live step leaves unbound, which it always sends.
|
|
250
|
+
function liveStepExamples(entity: any, step: any, flow?: any): [string, Scalar][] {
|
|
251
|
+
return unboundExamples(liveStepArgs(entity, step, flow) || [])
|
|
155
252
|
}
|
|
156
253
|
|
|
157
254
|
|
|
@@ -184,7 +281,7 @@ function flowLoadRoute(entity: any, step: any): FlowLoadRoute | undefined {
|
|
|
184
281
|
[string, string][])
|
|
185
282
|
const order = [...bound.keys()]
|
|
186
283
|
const rank = (arg: FlowRouteArg) => order.includes(arg.name) ? order.indexOf(arg.name) : order.length
|
|
187
|
-
for (const point of plainPoints(entity, 'load')) {
|
|
284
|
+
for (const point of plainPoints(entity, 'load').filter((point) => !isAction(point))) {
|
|
188
285
|
const names = [...new Set<string>((point.g?.params || []).map((arg: any) => arg.n))]
|
|
189
286
|
if (keyed && !names.includes('id')) continue
|
|
190
287
|
const args: FlowRouteArg[] = names.filter((name) => !keyed || 'id' !== name).map((name) => {
|
|
@@ -306,46 +403,83 @@ function liveGetOnlyReason(point: any): string | undefined {
|
|
|
306
403
|
}
|
|
307
404
|
|
|
308
405
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
406
|
+
const hasRoute = (entity: any, opname: string) =>
|
|
407
|
+
(entity?.op?.[opname]?.points || []).some((point: any) => false !== point.a)
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
// What a live run leaves out: a step on an operation the entity has no route
|
|
411
|
+
// for, or no GET route reaches in a GET-only run, and what acts on its record.
|
|
412
|
+
function livePlan(entity: any, flow: any, getOnly: boolean): { plan: LiveGetOnly, writes: number } {
|
|
313
413
|
const steps = liveFlowSteps(flow)
|
|
314
414
|
const reasons = new Map<any, string>()
|
|
415
|
+
let writes = 0
|
|
315
416
|
for (const step of steps) {
|
|
316
417
|
const route = writeRoute(entity, step.o)
|
|
317
|
-
if (
|
|
418
|
+
if (!hasRoute(entity, step.o)) reasons.set(step, entity.name + ' has no ' + step.o + ' operation')
|
|
419
|
+
else if (getOnly && null != route) {
|
|
420
|
+
reasons.set(step, GETONLY + 'needs ' + route)
|
|
421
|
+
writes++
|
|
422
|
+
}
|
|
318
423
|
}
|
|
319
|
-
if (0 === reasons.size) return undefined
|
|
320
424
|
|
|
321
425
|
const id = (step: any) => liveStepId(entity, step, steps.indexOf(step))
|
|
322
426
|
const left = () => steps.filter((step) => !reasons.has(step))
|
|
427
|
+
const after = (sources: any[], why: string) =>
|
|
428
|
+
(sources.some((step) => reasons.get(step)!.startsWith(GETONLY)) ? GETONLY : '') + why
|
|
323
429
|
const create = steps.find((step) => 'create' === step.o && reasons.has(step))
|
|
324
430
|
const sources = steps.filter((step) => ['create', 'list'].includes(step.o) && reasons.has(step))
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
reasons.set(step, 'acts on the record ' + id(create) + ' makes')
|
|
329
|
-
}
|
|
330
|
-
else if ('list' === step.o && (step.v || []).some((v: any) => 'ItemNotExists' === v?.apply)) {
|
|
331
|
-
reasons.set(step, 'checks a removal this run does not make')
|
|
332
|
-
}
|
|
431
|
+
for (const step of null == create ? [] : left()) {
|
|
432
|
+
if (['update', 'remove'].includes(step.o)) {
|
|
433
|
+
reasons.set(step, after([create], 'acts on the record ' + id(create) + ' makes'))
|
|
333
434
|
}
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
435
|
+
else if (null != entity?.id && 'list' === step.o &&
|
|
436
|
+
(step.v || []).some((v: any) => 'ItemNotExists' === v?.apply)) {
|
|
437
|
+
reasons.set(step, after([create], 'checks a removal this run does not make'))
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (null != entity?.id && 0 < sources.length && !left().some((step) => 'list' === step.o)) {
|
|
441
|
+
for (const step of left().filter((step) => 'load' === step.o)) {
|
|
442
|
+
reasons.set(step, after(sources, 'reads a record only ' + sources.map(id).join(', ') + ' gives'))
|
|
338
443
|
}
|
|
339
444
|
}
|
|
340
445
|
|
|
341
446
|
return {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
447
|
+
writes,
|
|
448
|
+
plan: {
|
|
449
|
+
excluded: steps.filter((step) => reasons.has(step))
|
|
450
|
+
.map((step) => ({ id: id(step), reason: reasons.get(step)! })),
|
|
451
|
+
flow: { ...flow, step: left() },
|
|
452
|
+
},
|
|
345
453
|
}
|
|
346
454
|
}
|
|
347
455
|
|
|
348
456
|
|
|
457
|
+
// A GET-only run's plan; undefined when it leaves out no more than any live run.
|
|
458
|
+
function liveGetOnly(entity: any, flow: any): LiveGetOnly | undefined {
|
|
459
|
+
const { plan, writes } = livePlan(entity, flow, true)
|
|
460
|
+
return 0 === writes ? undefined : plan
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
// Any live run's plan, undefined when every step runs; one with none left skips.
|
|
465
|
+
function liveFlowPlan(entity: any, flow: any): LiveGetOnly | undefined {
|
|
466
|
+
const { plan } = livePlan(entity, flow, false)
|
|
467
|
+
return 0 < plan.excluded.length || 0 === flowSteps(plan.flow).length ? plan : undefined
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
type LiveGate = { getOnly: boolean, plan: LiveGetOnly, runs: boolean }
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
// The plans a live flow test settles before its offline flow, GET-only first.
|
|
475
|
+
function liveGates(entity: any, flow: any): LiveGate[] {
|
|
476
|
+
return [liveGetOnly(entity, flow), liveFlowPlan(entity, flow)]
|
|
477
|
+
.map((plan, index) => null == plan ? undefined :
|
|
478
|
+
{ getOnly: 0 === index, plan, runs: 0 < flowSteps(plan.flow).length })
|
|
479
|
+
.filter((gate): gate is LiveGate => null != gate)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
|
|
349
483
|
type LiveKeyExcluded = LiveExcluded & { key: string }
|
|
350
484
|
|
|
351
485
|
|
|
@@ -373,19 +507,23 @@ function liveExcludedLines(plan: { excluded: LiveExcluded[] }): string[] {
|
|
|
373
507
|
}
|
|
374
508
|
|
|
375
509
|
|
|
376
|
-
|
|
510
|
+
const LIVE_NO_STEP = 'the flow has no step to run'
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
// Why a test with no step left to run skips, as the live harness says it.
|
|
377
514
|
function liveExcludedSummary(plan: { excluded: LiveExcluded[] }): string {
|
|
378
|
-
return 'Live coverage incomplete: ' +
|
|
379
|
-
plan.excluded.map(({ id, reason }) => id + ' excluded (' + reason + ')').join('; ')
|
|
515
|
+
return 'Live coverage incomplete: ' + (0 === plan.excluded.length ? LIVE_NO_STEP :
|
|
516
|
+
plan.excluded.map(({ id, reason }) => id + ' excluded (' + reason + ')').join('; '))
|
|
380
517
|
}
|
|
381
518
|
|
|
382
519
|
|
|
383
|
-
export type { LiveFlowNeeds, LiveExcluded, LiveGetOnly, LiveKeyExcluded, FlowRouteArg, FlowLoadRoute }
|
|
520
|
+
export type { LiveFlowNeeds, LiveExcluded, LiveGetOnly, LiveGate, LiveKeyExcluded, FlowRouteArg, FlowLoadRoute }
|
|
384
521
|
|
|
385
522
|
export {
|
|
386
523
|
liveStrict, liveStrictNote, liveFlowNeeds,
|
|
387
524
|
liveIdKey, liveExampleIds, liveQueryExamples, liveRouteExamples, liveStepExamples,
|
|
388
525
|
flowLoadRoute, flowLoadReadsRecord, liveFlowRoutes,
|
|
389
526
|
liveEntity, LIVE_GETONLY_ENV, liveFlowSteps, liveStepId, liveGetOnly, liveGetOnlyReason,
|
|
527
|
+
liveFlowPlan, liveGates,
|
|
390
528
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary,
|
|
391
529
|
}
|
package/src/sdkgen.ts
CHANGED
|
@@ -71,7 +71,7 @@ import type { DepEntry } from './helpers/collectDeps'
|
|
|
71
71
|
import { canonToType, canonToDtype, canonKey, canonScalarKey } from './helpers/canonType'
|
|
72
72
|
import { canonToSpec, entityDataSpec, entityOpSpec, entitySpecs, validateSeeds } from './helpers/canonSpec'
|
|
73
73
|
import { optionSpec, featureOptionSpec, entitySpecMap } from './helpers/optspec'
|
|
74
|
-
import { OP_SUFFIX, opTypeName, opParams, opReachable, opNeedsAction, ownPoint, opActions, entityActions, entityPath, opRequestShape, entityIdField, entityDataIdField, entityOps, invalidRequest, entityPrimaryOp, pickExampleEntity, entityClassName, entityConstructorName, entityTypeCollisions, warnEntityTypeCollisions, ungeneratedOps, warnUngeneratedOps, deriveEntityNames, entityCollection } from './helpers/opShape'
|
|
74
|
+
import { OP_SUFFIX, opTypeName, opParams, opReachable, opNeedsAction, ownPoint, opActions, entityActions, entityPath, opRequestShape, entityIdField, entityDataIdField, entityRecordIdField, entityOps, invalidRequest, entityPrimaryOp, pickExampleEntity, entityClassName, entityConstructorName, entityTypeCollisions, warnEntityTypeCollisions, ungeneratedOps, warnUngeneratedOps, deriveEntityNames, entityCollection } from './helpers/opShape'
|
|
75
75
|
import { isReservedName, safeVarName, exampleVarName, phpEntityAccessor, entityCacheField, isRbCoreConstant, isRbSdkConstant, rbSafeTypeName, isSwiftSdkType, swiftSafeTypeName, isPhpReservedType, isPhpSdkClass, phpSafeTypeName, isTsReservedType, isTsSdkType, tsSafeTypeName, isElixirReservedType, elixirSafeTypeName, elixirTypeNames, elixirTypeName, elixirAccessorNames, elixirAccessor, tsTypeName, rbTypeName, phpTypeName, swiftTypeName, jsProp, jsOptProp, jsKey, jsQuote, luaKey, luaString, prefixLeadingDigit } from './helpers/naming'
|
|
76
76
|
import { serverVariables, hasServerVariables, serverVarEnv } from './helpers/serverVars'
|
|
77
77
|
import { mcpTools, MCP_READ_OPS, MCP_WRITE_OPS } from './helpers/mcpTools'
|
|
@@ -86,13 +86,16 @@ import {
|
|
|
86
86
|
liveIdKey, liveExampleIds, liveQueryExamples, liveRouteExamples, liveStepExamples,
|
|
87
87
|
flowLoadRoute, flowLoadReadsRecord, liveFlowRoutes,
|
|
88
88
|
liveEntity, LIVE_GETONLY_ENV, liveFlowSteps, liveStepId, liveGetOnly, liveGetOnlyReason,
|
|
89
|
+
liveFlowPlan, liveGates,
|
|
89
90
|
liveDirectGetOnly, liveExcludedLines, liveExcludedSummary,
|
|
90
91
|
} from './helpers/testPolicy'
|
|
91
|
-
import type { LiveFlowNeeds, LiveExcluded, LiveGetOnly, LiveKeyExcluded, FlowRouteArg, FlowLoadRoute } from './helpers/testPolicy'
|
|
92
|
-
import { pointSegments, pointParts, pointPlaceholders, pointTerminalParam, pointPathKey }
|
|
92
|
+
import type { LiveFlowNeeds, LiveExcluded, LiveGetOnly, LiveGate, LiveKeyExcluded, FlowRouteArg, FlowLoadRoute } from './helpers/testPolicy'
|
|
93
|
+
import { pointSegments, pointParts, pointSlash, pointPlaceholders, pointTerminalParam, pointPathKey }
|
|
93
94
|
from './helpers/pointPath'
|
|
94
95
|
import { pointIsGraphql, ownPointFirst, primaryPoint, graphqlDirectSkip } from './helpers/graphqlPoint'
|
|
95
96
|
import type { PathSegment } from './helpers/pointPath'
|
|
97
|
+
import { liveDirectDiscovery } from './helpers/liveDiscovery'
|
|
98
|
+
import type { LiveDiscovery } from './helpers/liveDiscovery'
|
|
96
99
|
import {
|
|
97
100
|
featureOf,
|
|
98
101
|
availableFeatures,
|
|
@@ -1002,10 +1005,12 @@ export type {
|
|
|
1002
1005
|
LiveFlowNeeds,
|
|
1003
1006
|
LiveExcluded,
|
|
1004
1007
|
LiveGetOnly,
|
|
1008
|
+
LiveGate,
|
|
1005
1009
|
LiveKeyExcluded,
|
|
1006
1010
|
FlowRouteArg,
|
|
1007
1011
|
FlowLoadRoute,
|
|
1008
1012
|
PathSegment,
|
|
1013
|
+
LiveDiscovery,
|
|
1009
1014
|
FeatureSource,
|
|
1010
1015
|
DoctorReport,
|
|
1011
1016
|
RegisterOptions,
|
|
@@ -1131,6 +1136,7 @@ export {
|
|
|
1131
1136
|
|
|
1132
1137
|
pointSegments,
|
|
1133
1138
|
pointParts,
|
|
1139
|
+
pointSlash,
|
|
1134
1140
|
pointPlaceholders,
|
|
1135
1141
|
pointTerminalParam,
|
|
1136
1142
|
pointPathKey,
|
|
@@ -1138,6 +1144,7 @@ export {
|
|
|
1138
1144
|
ownPointFirst,
|
|
1139
1145
|
primaryPoint,
|
|
1140
1146
|
graphqlDirectSkip,
|
|
1147
|
+
liveDirectDiscovery,
|
|
1141
1148
|
canonToType,
|
|
1142
1149
|
canonToSpec,
|
|
1143
1150
|
entityDataSpec,
|
|
@@ -1164,6 +1171,7 @@ export {
|
|
|
1164
1171
|
opRequestShape,
|
|
1165
1172
|
entityIdField,
|
|
1166
1173
|
entityDataIdField,
|
|
1174
|
+
entityRecordIdField,
|
|
1167
1175
|
entityOps,
|
|
1168
1176
|
entityPrimaryOp,
|
|
1169
1177
|
pickExampleEntity,
|
|
@@ -1227,6 +1235,8 @@ export {
|
|
|
1227
1235
|
liveStepId,
|
|
1228
1236
|
liveGetOnly,
|
|
1229
1237
|
liveGetOnlyReason,
|
|
1238
|
+
liveFlowPlan,
|
|
1239
|
+
liveGates,
|
|
1230
1240
|
liveDirectGetOnly,
|
|
1231
1241
|
liveExcludedLines,
|
|
1232
1242
|
liveExcludedSummary,
|
package/src/types.ts
CHANGED
package/src/utility.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { targetFeatures } from './helpers/applicability'
|
|
|
9
9
|
|
|
10
10
|
import { serverVariables } from './helpers/serverVars'
|
|
11
11
|
import { pointParts } from './helpers/pointPath'
|
|
12
|
-
import { bodyFieldNames } from './helpers/opShape'
|
|
12
|
+
import { bodyFieldNames, entityRecordIdField } from './helpers/opShape'
|
|
13
13
|
import { ownPointFirst, pointGraphql } from './helpers/graphqlPoint'
|
|
14
14
|
import { packageVersion } from './helpers/packageMeta'
|
|
15
15
|
|
|
@@ -287,10 +287,15 @@ const SPEC_FACTS: Record<string, (model: any) => any> = {
|
|
|
287
287
|
const ROUTED_KINDS = ['header', 'cookie', 'query']
|
|
288
288
|
|
|
289
289
|
|
|
290
|
-
|
|
290
|
+
// `alias` names the record field an entity keeps its identity in, where that is
|
|
291
|
+
// not the parameter's own name, so an entity a list returned can address itself.
|
|
292
|
+
function withPointParts(
|
|
293
|
+
op: any, fields: any[] = [], entityName: string = '', ident?: { name: string, field: string },
|
|
294
|
+
): any {
|
|
291
295
|
if (null == op) {
|
|
292
296
|
return op
|
|
293
297
|
}
|
|
298
|
+
const alias = null == ident || ident.name === ident.field ? undefined : { [ident.name]: ident.field }
|
|
294
299
|
|
|
295
300
|
const out: any = {}
|
|
296
301
|
each(op, (o: any, opname: string) => {
|
|
@@ -311,7 +316,7 @@ function withPointParts(op: any, fields: any[] = [], entityName: string = ''): a
|
|
|
311
316
|
active: pt.a, kind: pt.k, method: pt.m, orig: pt.o,
|
|
312
317
|
segments: pt.s, parts: pointParts(pt), rename: pt.r,
|
|
313
318
|
transform: pt.t, args, select: pt.q, live: pt.li, graphql: pointGraphql(pt),
|
|
314
|
-
body: pt.rb, response: pt.rs,
|
|
319
|
+
body: pt.rb, response: pt.rs, alias,
|
|
315
320
|
}
|
|
316
321
|
}),
|
|
317
322
|
}
|
|
@@ -348,7 +353,8 @@ function configDefinition(model: any, targetname?: string): { def: any, json: st
|
|
|
348
353
|
})),
|
|
349
354
|
id: e.id,
|
|
350
355
|
name: e.name,
|
|
351
|
-
op: withPointParts(e.op, each(e.fields || {}), e.name
|
|
356
|
+
op: withPointParts(e.op, each(e.fields || {}), e.name, null == e.id ? undefined :
|
|
357
|
+
{ name: e.id.name || 'id', field: entityRecordIdField(e) }),
|
|
352
358
|
relations: e.relations,
|
|
353
359
|
}, true)
|
|
354
360
|
entityStubs[e.name] = {}
|