@voxgig/apidef 3.0.2 → 3.1.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/dist/apidef.d.ts +5 -4
- package/dist/apidef.js +12 -21
- package/dist/apidef.js.map +1 -1
- package/dist/builder/entity/info.js +1 -1
- package/dist/builder/entity/info.js.map +1 -1
- package/dist/builder/flow.js +29 -27
- package/dist/builder/flow.js.map +1 -1
- package/dist/desc.d.ts +11 -13
- package/dist/guide/guide.js +1 -1
- package/dist/guide/guide.js.map +1 -1
- package/dist/guide/heuristic01.js +4 -2
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/model.d.ts +42 -7
- package/dist/parse.d.ts +3 -1
- package/dist/parse.js +35 -2
- package/dist/parse.js.map +1 -1
- package/dist/resolver.js +2 -1
- package/dist/resolver.js.map +1 -1
- package/dist/transform/args.d.ts +2 -2
- package/dist/transform/args.js +9 -13
- package/dist/transform/args.js.map +1 -1
- package/dist/transform/clean.d.ts +2 -2
- package/dist/transform/clean.js +2 -1
- package/dist/transform/clean.js.map +1 -1
- package/dist/transform/entity.d.ts +3 -3
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.d.ts +2 -2
- package/dist/transform/field.js +2 -3
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/flow.d.ts +3 -0
- package/dist/transform/flow.js +26 -0
- package/dist/transform/flow.js.map +1 -0
- package/dist/transform/flowstep.d.ts +3 -0
- package/dist/transform/flowstep.js +145 -0
- package/dist/transform/flowstep.js.map +1 -0
- package/dist/transform/operation.d.ts +2 -2
- package/dist/transform/operation.js +15 -8
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform/select.d.ts +2 -2
- package/dist/transform/select.js +28 -7
- package/dist/transform/select.js.map +1 -1
- package/dist/transform/top.d.ts +0 -9
- package/dist/transform/top.js +13 -0
- package/dist/transform/top.js.map +1 -1
- package/dist/transform.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.js.map +1 -1
- package/dist/utility.d.ts +5 -1
- package/dist/utility.js +64 -1
- package/dist/utility.js.map +1 -1
- package/model/apidef.jsonic +8 -7
- package/package.json +7 -7
- package/src/apidef.ts +15 -22
- package/src/builder/entity/info.ts +1 -1
- package/src/builder/flow.ts +16 -9
- package/src/desc.ts +28 -17
- package/src/guide/guide.ts +2 -1
- package/src/guide/heuristic01.ts +5 -3
- package/src/model.ts +51 -6
- package/src/parse.ts +50 -3
- package/src/resolver.ts +3 -1
- package/src/transform/args.ts +11 -15
- package/src/transform/clean.ts +4 -5
- package/src/transform/entity.ts +4 -7
- package/src/transform/field.ts +7 -25
- package/src/transform/flow.ts +59 -0
- package/src/transform/flowstep.ts +242 -0
- package/src/transform/operation.ts +27 -31
- package/src/transform/select.ts +44 -15
- package/src/transform/top.ts +11 -42
- package/src/transform.ts +4 -4
- package/src/types.ts +2 -6
- package/src/utility.ts +87 -1
package/src/resolver.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import Path from 'node:path'
|
|
5
5
|
|
|
6
|
+
import { relativizePath } from './utility'
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
async function resolveElements(
|
|
8
10
|
ctx: any,
|
|
@@ -77,7 +79,7 @@ async function resolveElement(
|
|
|
77
79
|
}
|
|
78
80
|
catch (e: any) {
|
|
79
81
|
const err = new Error('Custom element not found: ' +
|
|
80
|
-
customtpath + ': ' + e.message)
|
|
82
|
+
relativizePath(customtpath) + ': ' + e.message)
|
|
81
83
|
log.error({ what: 'element', element: target + ': ' + en, fail: 'require', err })
|
|
82
84
|
throw err
|
|
83
85
|
}
|
package/src/transform/args.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type {
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
const argsTransform = async function(
|
|
30
|
+
const argsTransform: Transform = async function(
|
|
31
31
|
ctx: any,
|
|
32
32
|
): Promise<TransformResult> {
|
|
33
33
|
const { apimodel, def } = ctx
|
|
@@ -49,6 +49,7 @@ const argsTransform = async function(
|
|
|
49
49
|
|
|
50
50
|
resolveArgs(ment, mop, malt, argdefs)
|
|
51
51
|
})
|
|
52
|
+
|
|
52
53
|
})
|
|
53
54
|
|
|
54
55
|
msg += ment.name + ' '
|
|
@@ -68,11 +69,15 @@ const ARG_KIND: Record<string, ModelArg["kind"]> = {
|
|
|
68
69
|
|
|
69
70
|
function resolveArgs(ment: ModelEntity, mop: ModelOp, malt: ModelAlt, argdefs: ParameterDef[]) {
|
|
70
71
|
each(argdefs, (argdef: ParameterDef) => {
|
|
72
|
+
const orig = depluralize(snakify(argdef.name))
|
|
73
|
+
const kind = ARG_KIND[argdef.in] ?? 'query'
|
|
74
|
+
const name = malt.rename[kind]?.[orig] ?? orig
|
|
71
75
|
const marg: ModelArg = {
|
|
72
|
-
name
|
|
76
|
+
name,
|
|
77
|
+
orig,
|
|
73
78
|
type: validator(argdef.schema?.type),
|
|
74
|
-
kind
|
|
75
|
-
|
|
79
|
+
kind,
|
|
80
|
+
reqd: !!argdef.required
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
if (argdef.nullable) {
|
|
@@ -81,17 +86,8 @@ function resolveArgs(ment: ModelEntity, mop: ModelOp, malt: ModelAlt, argdefs: P
|
|
|
81
86
|
|
|
82
87
|
// insert sorted by name
|
|
83
88
|
let kindargs = (malt.args[marg.kind] = malt.args[marg.kind] ?? [])
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
for (let ka, i = 0; i <= kalen; i++) {
|
|
87
|
-
ka = kindargs[i]
|
|
88
|
-
if (ka && ka.name > marg.name) {
|
|
89
|
-
kindargs = [...kindargs.slice(0, i), marg, ...kindargs.slice(i + 1)]
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
kindargs.push(marg)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
89
|
+
kindargs.push(marg)
|
|
90
|
+
kindargs.sort((a: ModelArg, b: ModelArg) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
|
|
95
91
|
})
|
|
96
92
|
}
|
|
97
93
|
|
package/src/transform/clean.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
import type { TransformResult } from '../transform'
|
|
2
|
+
import type { TransformResult, Transform } from '../transform'
|
|
3
3
|
|
|
4
4
|
import { walk, isempty, isnode, ismap, islist } from '@voxgig/struct'
|
|
5
5
|
|
|
6
|
-
import { formatJSONIC } from '../utility'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
const cleanTransform = async function(
|
|
7
|
+
const cleanTransform: Transform = async function(
|
|
10
8
|
ctx: any,
|
|
11
9
|
): Promise<TransformResult> {
|
|
12
10
|
const { apimodel } = ctx
|
|
13
11
|
|
|
14
12
|
let cur: any[] = []
|
|
15
13
|
|
|
16
|
-
// Remove empty nodes and undefined values
|
|
14
|
+
// Remove empty nodes and undefined values. This avoids spurious content in model.
|
|
15
|
+
// NOTE: including ancestors if thus also empty!
|
|
17
16
|
walk(
|
|
18
17
|
apimodel,
|
|
19
18
|
(k: any, v: any, _p: any, ancestors: any) => {
|
package/src/transform/entity.ts
CHANGED
|
@@ -4,18 +4,16 @@ import { each } from 'jostraca'
|
|
|
4
4
|
|
|
5
5
|
import type { TransformResult, Transform } from '../transform'
|
|
6
6
|
|
|
7
|
-
import { formatJSONIC } from '../utility'
|
|
8
|
-
|
|
9
7
|
import { KIT } from '../types'
|
|
10
8
|
|
|
11
9
|
import type { KitModel } from '../types'
|
|
12
10
|
|
|
13
11
|
import type {
|
|
14
12
|
GuideEntity,
|
|
15
|
-
|
|
13
|
+
GuidePath,
|
|
14
|
+
} from '../types'
|
|
16
15
|
|
|
17
16
|
import type {
|
|
18
|
-
GuidePath,
|
|
19
17
|
PathDesc,
|
|
20
18
|
} from '../desc'
|
|
21
19
|
|
|
@@ -25,8 +23,7 @@ import type {
|
|
|
25
23
|
|
|
26
24
|
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
const entityTransform = async function(
|
|
26
|
+
const entityTransform: Transform = async function(
|
|
30
27
|
ctx: any,
|
|
31
28
|
): Promise<TransformResult> {
|
|
32
29
|
const { apimodel, guide } = ctx
|
|
@@ -85,7 +82,7 @@ function resolvePathList(guideEntity: GuideEntity, def: { paths: Record<string,
|
|
|
85
82
|
paths$.push(pathdesc)
|
|
86
83
|
})
|
|
87
84
|
|
|
88
|
-
|
|
85
|
+
; (guideEntity as any).paths$ = paths$
|
|
89
86
|
|
|
90
87
|
return paths$
|
|
91
88
|
}
|
package/src/transform/field.ts
CHANGED
|
@@ -2,47 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
import { each, getx } from 'jostraca'
|
|
4
4
|
|
|
5
|
-
import { getelem } from '@voxgig/struct'
|
|
6
|
-
|
|
7
5
|
import type { TransformResult, Transform } from '../transform'
|
|
8
6
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { formatJSONIC, validator, canonize } from '../utility'
|
|
7
|
+
import { validator, canonize } from '../utility'
|
|
12
8
|
|
|
13
9
|
import { KIT } from '../types'
|
|
14
10
|
|
|
15
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
KitModel,
|
|
13
|
+
} from '../types'
|
|
16
14
|
|
|
17
15
|
import type {
|
|
18
|
-
PathDef,
|
|
19
|
-
ParameterDef,
|
|
20
|
-
MethodDef,
|
|
21
16
|
SchemaDef,
|
|
22
17
|
} from '../def'
|
|
23
18
|
|
|
24
|
-
import type {
|
|
25
|
-
GuideEntity,
|
|
26
|
-
} from './top'
|
|
27
|
-
|
|
28
|
-
import type {
|
|
29
|
-
GuideOp,
|
|
30
|
-
PathDesc,
|
|
31
|
-
} from '../desc'
|
|
32
|
-
|
|
33
19
|
import type {
|
|
34
20
|
OpName,
|
|
35
|
-
ModelOpMap,
|
|
36
21
|
ModelOp,
|
|
37
22
|
ModelEntity,
|
|
38
23
|
ModelAlt,
|
|
39
|
-
ModelArg,
|
|
40
24
|
ModelField,
|
|
41
25
|
} from '../model'
|
|
42
26
|
|
|
43
27
|
|
|
44
28
|
|
|
45
|
-
const fieldTransform = async function(
|
|
29
|
+
const fieldTransform: Transform = async function(
|
|
46
30
|
ctx: any,
|
|
47
31
|
): Promise<TransformResult> {
|
|
48
32
|
const { apimodel, def } = ctx
|
|
@@ -52,9 +36,7 @@ const fieldTransform = async function(
|
|
|
52
36
|
|
|
53
37
|
const opFieldPrecedence: OpName[] = ['load', 'create', 'update', 'patch', 'list']
|
|
54
38
|
|
|
55
|
-
each(kit.entity, (ment: ModelEntity,
|
|
56
|
-
const fielddefs: SchemaDef[] = []
|
|
57
|
-
|
|
39
|
+
each(kit.entity, (ment: ModelEntity, _entname: string) => {
|
|
58
40
|
const fields = ment.fields
|
|
59
41
|
const seen: any = {}
|
|
60
42
|
|
|
@@ -116,7 +98,7 @@ function resolveOpFields(
|
|
|
116
98
|
|
|
117
99
|
|
|
118
100
|
function findFieldDefs(
|
|
119
|
-
|
|
101
|
+
_ment: ModelEntity,
|
|
120
102
|
mop: ModelOp,
|
|
121
103
|
malt: ModelAlt,
|
|
122
104
|
def: any
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { each } from 'jostraca'
|
|
4
|
+
|
|
5
|
+
import type { TransformResult, Transform } from '../transform'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
nom,
|
|
9
|
+
} from '../utility'
|
|
10
|
+
|
|
11
|
+
import { KIT } from '../types'
|
|
12
|
+
|
|
13
|
+
import type { KitModel } from '../types'
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
GuideEntity,
|
|
17
|
+
} from '../types'
|
|
18
|
+
|
|
19
|
+
import type {
|
|
20
|
+
ModelEntity,
|
|
21
|
+
ModelEntityFlow,
|
|
22
|
+
} from '../model'
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const flowTransform: Transform = async function(
|
|
28
|
+
ctx: any,
|
|
29
|
+
): Promise<TransformResult> {
|
|
30
|
+
const { apimodel, guide } = ctx
|
|
31
|
+
const kit: KitModel = apimodel.main[KIT]
|
|
32
|
+
|
|
33
|
+
let msg = ''
|
|
34
|
+
|
|
35
|
+
each(guide.entity, (guideEntity: GuideEntity, entname: string) => {
|
|
36
|
+
ctx.log.debug({ point: 'guide-flow', note: entname })
|
|
37
|
+
|
|
38
|
+
const modelent: ModelEntity = kit.entity[entname]
|
|
39
|
+
|
|
40
|
+
const basicflow: ModelEntityFlow = {
|
|
41
|
+
name: 'Basic' + nom(modelent, 'Name') + 'Flow',
|
|
42
|
+
entity: entname,
|
|
43
|
+
kind: 'basic',
|
|
44
|
+
step: [],
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
kit.flow[basicflow.name] = basicflow
|
|
48
|
+
|
|
49
|
+
msg += basicflow.name + ' '
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return { ok: true, msg }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
flowTransform,
|
|
59
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { each } from 'jostraca'
|
|
4
|
+
|
|
5
|
+
import type { TransformResult, Transform } from '../transform'
|
|
6
|
+
|
|
7
|
+
import { getelem } from '@voxgig/struct'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
nom,
|
|
11
|
+
} from '../utility'
|
|
12
|
+
|
|
13
|
+
import { KIT } from '../types'
|
|
14
|
+
|
|
15
|
+
import type { KitModel } from '../types'
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
OpName,
|
|
19
|
+
GuideEntity,
|
|
20
|
+
} from '../types'
|
|
21
|
+
|
|
22
|
+
import type {
|
|
23
|
+
ModelEntity,
|
|
24
|
+
ModelEntityFlow,
|
|
25
|
+
ModelEntityFlowStep,
|
|
26
|
+
ModelOp,
|
|
27
|
+
} from '../model'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const flowstepTransform: Transform = async function(
|
|
33
|
+
ctx: any,
|
|
34
|
+
): Promise<TransformResult> {
|
|
35
|
+
const { apimodel, guide } = ctx
|
|
36
|
+
const kit: KitModel = apimodel.main[KIT]
|
|
37
|
+
|
|
38
|
+
let msg = ''
|
|
39
|
+
|
|
40
|
+
each(kit.flow, (flow: ModelEntityFlow, flowname: string) => {
|
|
41
|
+
ctx.log.debug({ point: 'flowstep', note: flowname })
|
|
42
|
+
|
|
43
|
+
const ent: ModelEntity = kit.entity[flow.entity]
|
|
44
|
+
const opmap = ent.op
|
|
45
|
+
|
|
46
|
+
// TODO: spec parameter passed into each step func, used semantically by generator
|
|
47
|
+
// validation: part of spec, semantic name and params, up to generator how to use it
|
|
48
|
+
const ref01 = ent.name + '_ref01'
|
|
49
|
+
|
|
50
|
+
createStep(opmap, flow, ent, { input: { ref: ref01 } })
|
|
51
|
+
|
|
52
|
+
listStep(opmap, flow, ent,
|
|
53
|
+
{ valid: [{ apply: 'ItemExists', def: { ref: ref01 } }] })
|
|
54
|
+
|
|
55
|
+
const mark01 = 'Mark01-' + ref01
|
|
56
|
+
const firsttf = firstTextField(ent)
|
|
57
|
+
updateStep(opmap, flow, ent,
|
|
58
|
+
{
|
|
59
|
+
input: {
|
|
60
|
+
ref: ref01,
|
|
61
|
+
textfield: firsttf?.name,
|
|
62
|
+
suffix: '_up0',
|
|
63
|
+
srcdatavar: ref01 + '_data'
|
|
64
|
+
},
|
|
65
|
+
spec: [{
|
|
66
|
+
apply: 'TextFieldMark',
|
|
67
|
+
def: { mark: mark01 }
|
|
68
|
+
}]
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
loadStep(opmap, flow, ent,
|
|
72
|
+
{
|
|
73
|
+
input: {
|
|
74
|
+
ref: ref01,
|
|
75
|
+
suffix: '_dt0',
|
|
76
|
+
srcdatavar: ref01 + '_data'
|
|
77
|
+
},
|
|
78
|
+
valid: [{
|
|
79
|
+
apply: 'TextFieldMark',
|
|
80
|
+
def: { mark: mark01 }
|
|
81
|
+
}]
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
removeStep(opmap, flow, ent, {
|
|
85
|
+
input: { ref: ref01, suffix: '_rm0' }
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
if (null != opmap.remove) {
|
|
89
|
+
listStep(opmap, flow, ent, {
|
|
90
|
+
input: { suffix: '_rt0' },
|
|
91
|
+
valid: [{ apply: 'ItemNotExists', def: { ref: ref01 } }]
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
msg += flowname + ' '
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return { ok: true, msg }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
type MakeFlowStep =
|
|
103
|
+
(opmap: any, flow: ModelEntityFlow, ent: ModelEntity, args: Record<string, any>) => void
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
function newFlowStep(opname: OpName, args: Record<string, any>): ModelEntityFlowStep {
|
|
108
|
+
return {
|
|
109
|
+
op: opname,
|
|
110
|
+
input: args.input ?? {},
|
|
111
|
+
match: args.match ?? {},
|
|
112
|
+
data: args.data ?? {},
|
|
113
|
+
spec: args.spec ?? [],
|
|
114
|
+
valid: args.valid ?? [],
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const createStep: MakeFlowStep = (
|
|
120
|
+
opmap: any,
|
|
121
|
+
flow: ModelEntityFlow,
|
|
122
|
+
ent: ModelEntity,
|
|
123
|
+
args: Record<string, any>
|
|
124
|
+
) => {
|
|
125
|
+
if (null != opmap.update) {
|
|
126
|
+
// Use last alt as most generic
|
|
127
|
+
const alt = getelem(opmap.update.alts, -1)
|
|
128
|
+
const step = newFlowStep('create', args)
|
|
129
|
+
|
|
130
|
+
flow.step.push(step)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const listStep: MakeFlowStep = (
|
|
136
|
+
opmap: any,
|
|
137
|
+
flow: ModelEntityFlow,
|
|
138
|
+
ent: ModelEntity,
|
|
139
|
+
args: Record<string, any>
|
|
140
|
+
) => {
|
|
141
|
+
if (null != opmap.list) {
|
|
142
|
+
// Use last alt as most generic
|
|
143
|
+
const alt = getelem(opmap.list.alts, -1)
|
|
144
|
+
const step = newFlowStep('list', args)
|
|
145
|
+
|
|
146
|
+
each(alt.args.param, (param: any) => {
|
|
147
|
+
step.match[param.name] = args.input?.[param.name] ?? param.name.replace(/_id/, '') + '01'
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
flow.step.push(step)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
const updateStep: MakeFlowStep = (
|
|
156
|
+
opmap: any,
|
|
157
|
+
flow: ModelEntityFlow,
|
|
158
|
+
ent: ModelEntity,
|
|
159
|
+
args: Record<string, any>
|
|
160
|
+
) => {
|
|
161
|
+
if (null != opmap.update) {
|
|
162
|
+
// Use last alt as most generic
|
|
163
|
+
const alt = getelem(opmap.update.alts, -1)
|
|
164
|
+
const step = newFlowStep('update', args)
|
|
165
|
+
|
|
166
|
+
each(alt.args.param, (param: any) => {
|
|
167
|
+
if ('id' === param.name) {
|
|
168
|
+
step.data.id = args.input?.id ?? ent.name + '01'
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
step.data[param.name] = args.input?.[param.name] ?? param.name.replace(/_id/, '') + '01'
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
flow.step.push(step)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
const loadStep: MakeFlowStep = (
|
|
181
|
+
opmap: any,
|
|
182
|
+
flow: ModelEntityFlow,
|
|
183
|
+
ent: ModelEntity,
|
|
184
|
+
args: Record<string, any>
|
|
185
|
+
) => {
|
|
186
|
+
if (null != opmap.load) {
|
|
187
|
+
// Use last alt as most generic
|
|
188
|
+
const alt = getelem(opmap.update.alts, -1)
|
|
189
|
+
const step = newFlowStep('load', args)
|
|
190
|
+
|
|
191
|
+
each(alt.args.param, (param: any) => {
|
|
192
|
+
if ('id' === param.name) {
|
|
193
|
+
step.match.id = args.input?.id ?? ent.name + '01'
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
step.match[param.name] = args.input?.[param.name] ?? param.name.replace(/_id/, '') + '01'
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
flow.step.push(step)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
const removeStep: MakeFlowStep = (
|
|
206
|
+
opmap: any,
|
|
207
|
+
flow: ModelEntityFlow,
|
|
208
|
+
ent: ModelEntity,
|
|
209
|
+
args: Record<string, any>
|
|
210
|
+
) => {
|
|
211
|
+
if (null != opmap.remove) {
|
|
212
|
+
// Use last alt as most generic
|
|
213
|
+
const alt = getelem(opmap.update.alts, -1)
|
|
214
|
+
const step = newFlowStep('remove', args)
|
|
215
|
+
|
|
216
|
+
each(alt.args.param, (param: any) => {
|
|
217
|
+
if ('id' === param.name) {
|
|
218
|
+
step.match.id = args.input?.id ?? ent.name + '01'
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
step.match[param.name] = args.input?.[param.name] ?? param.name.replace(/_id/, '') + '01'
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
flow.step.push(step)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
function firstTextField(ent: ModelEntity) {
|
|
231
|
+
const fields = each(ent.fields)
|
|
232
|
+
for (let fI = 0; fI < fields.length; fI++) {
|
|
233
|
+
const field = fields[fI]
|
|
234
|
+
if ('`$STRING`' === field.type && 'id' !== field.name) {
|
|
235
|
+
return field
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
flowstepTransform,
|
|
242
|
+
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { each
|
|
4
|
-
|
|
5
|
-
import { getelem, isempty } from '@voxgig/struct'
|
|
3
|
+
import { each } from 'jostraca'
|
|
6
4
|
|
|
7
5
|
import type { TransformResult, Transform } from '../transform'
|
|
8
6
|
|
|
9
|
-
import { fixName } from '../transform'
|
|
10
|
-
|
|
11
|
-
import { formatJSONIC } from '../utility'
|
|
12
|
-
|
|
13
|
-
import { KIT } from '../types'
|
|
14
|
-
|
|
15
|
-
import type { KitModel } from '../types'
|
|
16
7
|
|
|
17
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
KIT,
|
|
18
10
|
GuideEntity,
|
|
19
|
-
|
|
11
|
+
GuidePathOp,
|
|
12
|
+
} from '../types'
|
|
20
13
|
|
|
21
14
|
import type {
|
|
22
|
-
GuideOp,
|
|
23
15
|
PathDesc,
|
|
24
16
|
} from '../desc'
|
|
25
17
|
|
|
@@ -32,7 +24,7 @@ import type {
|
|
|
32
24
|
|
|
33
25
|
|
|
34
26
|
|
|
35
|
-
const operationTransform = async function(
|
|
27
|
+
const operationTransform: Transform = async function(
|
|
36
28
|
ctx: any,
|
|
37
29
|
): Promise<TransformResult> {
|
|
38
30
|
const { apimodel, guide } = ctx
|
|
@@ -40,7 +32,6 @@ const operationTransform = async function(
|
|
|
40
32
|
|
|
41
33
|
let msg = 'operation '
|
|
42
34
|
|
|
43
|
-
|
|
44
35
|
each(guide.entity, (gent: GuideEntity, entname: string) => {
|
|
45
36
|
collectOps(gent)
|
|
46
37
|
|
|
@@ -49,7 +40,7 @@ const operationTransform = async function(
|
|
|
49
40
|
list: undefined,
|
|
50
41
|
create: undefined,
|
|
51
42
|
update: undefined,
|
|
52
|
-
|
|
43
|
+
remove: undefined,
|
|
53
44
|
patch: undefined,
|
|
54
45
|
}
|
|
55
46
|
|
|
@@ -57,7 +48,7 @@ const operationTransform = async function(
|
|
|
57
48
|
resolveList(opm, gent)
|
|
58
49
|
resolveCreate(opm, gent)
|
|
59
50
|
resolveUpdate(opm, gent)
|
|
60
|
-
|
|
51
|
+
resolveRemove(opm, gent)
|
|
61
52
|
resolvePatch(opm, gent)
|
|
62
53
|
|
|
63
54
|
kit.entity[entname].op = opm
|
|
@@ -70,21 +61,21 @@ const operationTransform = async function(
|
|
|
70
61
|
|
|
71
62
|
|
|
72
63
|
function collectOps(gent: GuideEntity) {
|
|
73
|
-
gent.opm$ = gent.opm$ ?? {}
|
|
74
|
-
each(gent.paths$, (pathdesc: PathDesc) => {
|
|
75
|
-
each(pathdesc.op, (gop:
|
|
76
|
-
gent.opm$[opname] = gent.opm$[opname] ?? { paths: [] }
|
|
64
|
+
; (gent as any).opm$ = (gent as any).opm$ ?? {}
|
|
65
|
+
each((gent as any).paths$, (pathdesc: PathDesc) => {
|
|
66
|
+
each(pathdesc.op, (gop: GuidePathOp, opname: OpName) => {
|
|
67
|
+
; (gent as any).opm$[opname] = (gent as any).opm$[opname] ?? { paths: [] }
|
|
77
68
|
|
|
78
69
|
const oppathdesc: PathDesc = {
|
|
79
70
|
orig: pathdesc.orig,
|
|
80
71
|
parts: pathdesc.parts,
|
|
81
72
|
rename: pathdesc.rename,
|
|
82
|
-
method: gop.method,
|
|
83
|
-
op:
|
|
73
|
+
method: gop.method as any,
|
|
74
|
+
op: gop as any,
|
|
84
75
|
def: pathdesc.def,
|
|
85
76
|
}
|
|
86
77
|
|
|
87
|
-
|
|
78
|
+
; (gent as any).opm$[opname].paths.push(oppathdesc)
|
|
88
79
|
})
|
|
89
80
|
})
|
|
90
81
|
}
|
|
@@ -117,8 +108,8 @@ function resolveUpdate(opm: ModelOpMap, gent: GuideEntity): undefined | ModelOp
|
|
|
117
108
|
}
|
|
118
109
|
|
|
119
110
|
|
|
120
|
-
function
|
|
121
|
-
const opdesc = opm.
|
|
111
|
+
function resolveRemove(opm: ModelOpMap, gent: GuideEntity): undefined | ModelOp {
|
|
112
|
+
const opdesc = opm.remove = resolveOp('remove', gent)
|
|
122
113
|
return opdesc
|
|
123
114
|
}
|
|
124
115
|
|
|
@@ -141,23 +132,28 @@ function resolvePatch(opm: ModelOpMap, gent: GuideEntity): undefined | ModelOp {
|
|
|
141
132
|
|
|
142
133
|
function resolveOp(opname: OpName, gent: GuideEntity): undefined | ModelOp {
|
|
143
134
|
let mop: undefined | ModelOp = undefined
|
|
144
|
-
let opdesc = gent.opm$[opname]
|
|
135
|
+
let opdesc = (gent as any).opm$[opname]
|
|
145
136
|
if (opdesc) {
|
|
146
|
-
// console.dir(opdesc, { depth: null })
|
|
147
|
-
|
|
148
137
|
mop = {
|
|
149
138
|
name: opname,
|
|
150
|
-
alts: opdesc.paths.map(p => {
|
|
139
|
+
alts: opdesc.paths.map((p: PathDesc) => {
|
|
151
140
|
const parts = applyRename(p)
|
|
152
141
|
|
|
153
142
|
const malt: ModelAlt = {
|
|
154
143
|
orig: p.orig,
|
|
155
144
|
parts,
|
|
145
|
+
rename: p.rename,
|
|
156
146
|
method: p.method,
|
|
157
147
|
args: {},
|
|
158
|
-
|
|
148
|
+
transform: opdesc.transform ?? {},
|
|
149
|
+
select: {
|
|
150
|
+
exist: []
|
|
151
|
+
}
|
|
159
152
|
}
|
|
160
153
|
|
|
154
|
+
malt.transform.req = malt.transform.req ?? '`reqdata`'
|
|
155
|
+
malt.transform.res = malt.transform.res ?? '`body`'
|
|
156
|
+
|
|
161
157
|
return malt
|
|
162
158
|
})
|
|
163
159
|
}
|