@voxgig/apidef 2.4.1 → 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 +7 -2
- package/dist/apidef.js +190 -114
- package/dist/apidef.js.map +1 -1
- package/dist/builder/entity/entity.d.ts +3 -0
- package/dist/builder/entity/{apiEntity.js → entity.js} +12 -9
- package/dist/builder/entity/entity.js.map +1 -0
- package/dist/builder/entity/info.d.ts +3 -0
- package/dist/builder/entity/info.js +22 -0
- package/dist/builder/entity/info.js.map +1 -0
- package/dist/builder/entity.js +7 -21
- package/dist/builder/entity.js.map +1 -1
- package/dist/builder/flow/flowHeuristic01.js +21 -11
- package/dist/builder/flow/flowHeuristic01.js.map +1 -1
- package/dist/builder/flow.d.ts +2 -1
- package/dist/builder/flow.js +39 -12
- package/dist/builder/flow.js.map +1 -1
- package/dist/def.d.ts +62 -0
- package/dist/def.js +4 -0
- package/dist/def.js.map +1 -0
- package/dist/desc.d.ts +87 -0
- package/dist/desc.js +4 -0
- package/dist/desc.js.map +1 -0
- package/dist/guide/guide.d.ts +2 -1
- package/dist/guide/guide.js +161 -30
- package/dist/guide/guide.js.map +1 -1
- package/dist/guide/heuristic01.d.ts +2 -1
- package/dist/guide/heuristic01.js +1122 -234
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/model.d.ts +90 -0
- package/dist/model.js +4 -0
- package/dist/model.js.map +1 -0
- package/dist/parse.d.ts +4 -3
- package/dist/parse.js +40 -46
- 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 +3 -0
- package/dist/transform/args.js +54 -0
- package/dist/transform/args.js.map +1 -0
- package/dist/transform/clean.d.ts +2 -2
- package/dist/transform/clean.js +28 -3
- package/dist/transform/clean.js.map +1 -1
- package/dist/transform/entity.d.ts +9 -1
- package/dist/transform/entity.js +57 -41
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.d.ts +1 -1
- package/dist/transform/field.js +89 -65
- 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 +3 -3
- package/dist/transform/operation.js +101 -296
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform/select.d.ts +3 -0
- package/dist/transform/select.js +65 -0
- package/dist/transform/select.js.map +1 -0
- package/dist/transform/top.js +24 -2
- package/dist/transform/top.js.map +1 -1
- package/dist/transform.d.ts +1 -1
- package/dist/transform.js +4 -0
- package/dist/transform.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +115 -14
- package/dist/types.js +4 -2
- package/dist/types.js.map +1 -1
- package/dist/utility.d.ts +34 -2
- package/dist/utility.js +444 -6
- package/dist/utility.js.map +1 -1
- package/model/apidef.jsonic +76 -1
- package/model/guide.jsonic +14 -44
- package/package.json +19 -16
- package/src/apidef.ts +258 -122
- package/src/builder/entity/{apiEntity.ts → entity.ts} +18 -11
- package/src/builder/entity/info.ts +53 -0
- package/src/builder/entity.ts +9 -35
- package/src/builder/flow/flowHeuristic01.ts +46 -12
- package/src/builder/flow.ts +54 -13
- package/src/def.ts +91 -0
- package/src/desc.ts +154 -0
- package/src/guide/guide.ts +208 -134
- package/src/guide/heuristic01.ts +1653 -272
- package/src/model.ts +143 -0
- package/src/parse.ts +50 -59
- package/src/resolver.ts +3 -1
- package/src/schematron.ts.off +317 -0
- package/src/transform/args.ts +98 -0
- package/src/transform/clean.ts +45 -11
- package/src/transform/entity.ts +96 -50
- package/src/transform/field.ts +136 -75
- package/src/transform/flow.ts +59 -0
- package/src/transform/flowstep.ts +242 -0
- package/src/transform/operation.ts +119 -419
- package/src/transform/select.ts +119 -0
- package/src/transform/top.ts +46 -4
- package/src/transform.ts +8 -4
- package/src/types.ts +181 -5
- package/src/utility.ts +567 -9
- package/dist/builder/entity/apiEntity.d.ts +0 -3
- package/dist/builder/entity/apiEntity.js.map +0 -1
- package/dist/builder/entity/def.d.ts +0 -3
- package/dist/builder/entity/def.js +0 -19
- package/dist/builder/entity/def.js.map +0 -1
- package/src/builder/entity/def.ts +0 -44
- package/src/guide.ts.off +0 -136
|
@@ -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
|
+
}
|