@voxgig/sdkgen 0.24.0 → 0.26.1
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 +6 -6
- package/dist/action/action.js +1 -2
- package/dist/action/action.js.map +1 -1
- package/dist/action/feature.js +4 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +4 -2
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/Entity.js +2 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +2 -1
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/Test.d.ts +2 -0
- package/dist/cmp/Test.js +17 -0
- package/dist/cmp/Test.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +17 -28
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/model/sdkgen.jsonic +8 -8
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +2 -2
- package/project/.sdk/model/feature/test.jsonic +7 -2
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +2 -2
- package/project/.sdk/src/cmp/js/Main_js.ts +3 -3
- package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
- package/project/.sdk/src/cmp/ts/Config_ts.ts +53 -6
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
- package/project/.sdk/src/cmp/ts/Main_ts.ts +22 -12
- package/project/.sdk/src/cmp/ts/Package_ts.ts +32 -12
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +341 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +21 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +50 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +70 -34
- package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +158 -104
- package/project/.sdk/tm/ts/src/types.ts +164 -34
- package/project/.sdk/tm/ts/src/utility/AuthUtility.ts +8 -2
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +9 -6
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +14 -54
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ErrorUtility.ts +7 -3
- package/project/.sdk/tm/ts/src/utility/FeaturehookUtility.ts +8 -5
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +18 -2
- package/project/.sdk/tm/ts/src/utility/FindparamUtility.ts +12 -5
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +21 -5
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +3 -1
- package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +23 -0
- package/project/.sdk/tm/ts/src/utility/OptionsUtility.ts +25 -3
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +10 -10
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +18 -0
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/ReqformUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +20 -3
- package/project/.sdk/tm/ts/src/utility/ResbasicUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +5 -3
- package/project/.sdk/tm/ts/src/utility/ResformUtility.ts +3 -3
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +9 -7
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +35 -4
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +24 -4
- package/project/.sdk/tm/ts/src/utility/SelectionUtility.ts +78 -0
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +34 -27
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1117 -509
- package/project/.sdk/tm/ts/src/utility/Utility.ts +10 -8
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +12 -10
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +53 -47
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
- package/src/action/action.ts +1 -2
- package/src/action/feature.ts +7 -2
- package/src/action/target.ts +7 -7
- package/src/cmp/Entity.ts +7 -1
- package/src/cmp/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +4 -0
- package/src/cmp/ReadmeEntity.ts +6 -1
- package/src/cmp/Test.ts +31 -0
- package/src/sdkgen.ts +19 -34
- package/src/types.ts +10 -1
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
package/src/action/action.ts
CHANGED
|
@@ -34,8 +34,7 @@ function loadContent(actx: ActionContext, which: string | string[]) {
|
|
|
34
34
|
const content: any = {}
|
|
35
35
|
|
|
36
36
|
const fs = actx.fs()
|
|
37
|
-
const
|
|
38
|
-
const modelfolder = Path.dirname(tree.url)
|
|
37
|
+
const modelfolder = Path.dirname(actx.url)
|
|
39
38
|
|
|
40
39
|
which.map((w: string) => {
|
|
41
40
|
const indexfile = Path.join(modelfolder, w, w + '-index.jsonic')
|
package/src/action/feature.ts
CHANGED
|
@@ -13,6 +13,10 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import { showChanges } from '@voxgig/util'
|
|
15
15
|
|
|
16
|
+
import {
|
|
17
|
+
KIT
|
|
18
|
+
} from '../types'
|
|
19
|
+
|
|
16
20
|
import type {
|
|
17
21
|
ActionContext,
|
|
18
22
|
ActionResult,
|
|
@@ -68,7 +72,8 @@ async function feature_add(features: string[], actx: ActionContext): Promise<Act
|
|
|
68
72
|
log: actx.log.child({ cmp: 'jostraca' }),
|
|
69
73
|
meta: {
|
|
70
74
|
// model: actx.model,
|
|
71
|
-
tree: actx.tree,
|
|
75
|
+
// tree: actx.tree,
|
|
76
|
+
url: actx.url,
|
|
72
77
|
content: loadContent(actx, 'feature')
|
|
73
78
|
},
|
|
74
79
|
model: actx.model
|
|
@@ -98,7 +103,7 @@ const FeatureRoot = cmp(function FeatureRoot(props: any) {
|
|
|
98
103
|
const { ctx$, features } = props
|
|
99
104
|
const { model, log } = ctx$
|
|
100
105
|
|
|
101
|
-
const target = model.main.
|
|
106
|
+
const target = model.main[KIT].target
|
|
102
107
|
|
|
103
108
|
Project({}, () => {
|
|
104
109
|
each(features, (n) => {
|
package/src/action/target.ts
CHANGED
|
@@ -14,6 +14,10 @@ import { showChanges } from '@voxgig/util'
|
|
|
14
14
|
|
|
15
15
|
import { getelem } from '@voxgig/struct'
|
|
16
16
|
|
|
17
|
+
import {
|
|
18
|
+
KIT
|
|
19
|
+
} from '../types'
|
|
20
|
+
|
|
17
21
|
import type {
|
|
18
22
|
ActionContext,
|
|
19
23
|
ActionResult,
|
|
@@ -36,11 +40,6 @@ const CMD_MAP: any = {
|
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
|
|
39
|
-
type Target = {
|
|
40
|
-
origin: string
|
|
41
|
-
name: string
|
|
42
|
-
}
|
|
43
|
-
|
|
44
43
|
|
|
45
44
|
async function action_target(args: string[], actx: ActionContext): Promise<ActionResult> {
|
|
46
45
|
const cmdname = args[1]
|
|
@@ -75,7 +74,8 @@ async function target_add(targets: string[], actx: ActionContext): Promise<Actio
|
|
|
75
74
|
log: actx.log.child({ cmp: 'jostraca' }),
|
|
76
75
|
meta: {
|
|
77
76
|
// model: actx.model,
|
|
78
|
-
tree: actx.tree,
|
|
77
|
+
// tree: actx.tree,
|
|
78
|
+
url: actx.url,
|
|
79
79
|
content: loadContent(actx, 'target')
|
|
80
80
|
},
|
|
81
81
|
model: actx.model,
|
|
@@ -91,7 +91,7 @@ async function target_add(targets: string[], actx: ActionContext): Promise<Actio
|
|
|
91
91
|
|
|
92
92
|
showChanges(opts.log, 'target-result', jres)
|
|
93
93
|
|
|
94
|
-
const features = Object.keys(actx.model.main.
|
|
94
|
+
const features = Object.keys(actx.model.main[KIT].feature)
|
|
95
95
|
await feature_add(features, actx)
|
|
96
96
|
|
|
97
97
|
opts.log.info({
|
package/src/cmp/Entity.ts
CHANGED
|
@@ -6,11 +6,17 @@ import {
|
|
|
6
6
|
import { requirePath } from '../utility'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
import {
|
|
10
|
+
KIT,
|
|
11
|
+
getModelPath
|
|
12
|
+
} from '../types'
|
|
13
|
+
|
|
14
|
+
|
|
9
15
|
const Entity = cmp(function Entity(props: any) {
|
|
10
16
|
const { target, entity, ctx$ } = props
|
|
11
17
|
const { log } = ctx$
|
|
12
18
|
|
|
13
|
-
const entitySDK = ctx$.model
|
|
19
|
+
const entitySDK = getModelPath(ctx$.model, `main.${KIT}.entity.${entity.name}`)
|
|
14
20
|
|
|
15
21
|
const Entity_sdk = requirePath(ctx$, `./cmp/${target.name}/Entity_${target.name}`)
|
|
16
22
|
Entity_sdk['Entity']({ target, entity, entitySDK })
|
package/src/cmp/FeatureHook.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
import { each, cmp, names, Content } from 'jostraca'
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
KIT,
|
|
6
|
+
getModelPath
|
|
7
|
+
} from '../types'
|
|
8
|
+
|
|
4
9
|
|
|
5
10
|
const FeatureHook = cmp(function FeatureHook(props: any, children: any) {
|
|
6
11
|
const { ctx$: { model } } = props
|
|
7
12
|
|
|
8
|
-
const
|
|
13
|
+
const feature = getModelPath(model, `main.${KIT}.feature`)
|
|
9
14
|
|
|
10
15
|
const hook: any = {}
|
|
11
16
|
names(hook, props.name)
|
package/src/cmp/Main.ts
CHANGED
package/src/cmp/ReadmeEntity.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
import { cmp, each, Content } from 'jostraca'
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
KIT,
|
|
6
|
+
getModelPath
|
|
7
|
+
} from '../types'
|
|
8
|
+
|
|
4
9
|
|
|
5
10
|
const ReadmeEntity = cmp(function ReadmeEntity(props: any) {
|
|
6
11
|
const { ctx$: { model } } = props
|
|
7
12
|
|
|
8
|
-
const
|
|
13
|
+
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
9
14
|
|
|
10
15
|
Content(`
|
|
11
16
|
|
package/src/cmp/Test.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
cmp,
|
|
4
|
+
} from 'jostraca'
|
|
5
|
+
|
|
6
|
+
import { requirePath } from '../utility'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
KIT,
|
|
11
|
+
getModelPath
|
|
12
|
+
} from '../types'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const Test = cmp(function Test(props: any) {
|
|
16
|
+
const { target, ctx$ } = props
|
|
17
|
+
const { model, stdrep, log } = ctx$
|
|
18
|
+
|
|
19
|
+
const Test_sdk = requirePath(ctx$, `./cmp/${target.name}/Test_${target.name}`)
|
|
20
|
+
Test_sdk['Test']({ model, target, stdrep })
|
|
21
|
+
|
|
22
|
+
log.info({
|
|
23
|
+
point: 'generate-test', target,
|
|
24
|
+
note: 'target:' + target.name
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
Test
|
|
31
|
+
}
|
package/src/sdkgen.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Copyright (c) 2024 Richard Rodger, MIT License */
|
|
1
|
+
/* Copyright (c) 2024-2025 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
3
|
import Fs from 'node:fs'
|
|
4
4
|
import Path from 'node:path'
|
|
@@ -7,7 +7,7 @@ import { prettyPino, Pino } from '@voxgig/util'
|
|
|
7
7
|
|
|
8
8
|
import { Jsonic } from 'jsonic'
|
|
9
9
|
import * as JostracaModule from 'jostraca'
|
|
10
|
-
import { Aontu
|
|
10
|
+
import { Aontu } from 'aontu'
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
showChanges,
|
|
@@ -25,6 +25,7 @@ import { Main } from './cmp/Main'
|
|
|
25
25
|
import { Entity } from './cmp/Entity'
|
|
26
26
|
import { Feature } from './cmp/Feature'
|
|
27
27
|
import { Readme } from './cmp/Readme'
|
|
28
|
+
import { Test } from './cmp/Test'
|
|
28
29
|
import { ReadmeInstall } from './cmp/ReadmeInstall'
|
|
29
30
|
import { ReadmeOptions } from './cmp/ReadmeOptions'
|
|
30
31
|
import { ReadmeEntity } from './cmp/ReadmeEntity'
|
|
@@ -82,6 +83,9 @@ const ACTION_MAP: any = {
|
|
|
82
83
|
const dlog = getdlog('sdkgen', __filename)
|
|
83
84
|
|
|
84
85
|
|
|
86
|
+
const aontu = new Aontu()
|
|
87
|
+
|
|
88
|
+
|
|
85
89
|
function SdkGen(opts: SdkGenOptions) {
|
|
86
90
|
const fs = opts.fs || Fs
|
|
87
91
|
const folder = opts.folder || '../'
|
|
@@ -150,29 +154,29 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
150
154
|
const pargs = args.map(arg => Jsonic(arg))
|
|
151
155
|
|
|
152
156
|
const actname = args[0]
|
|
153
|
-
const
|
|
157
|
+
const actionFunc = ACTION_MAP[actname]
|
|
154
158
|
|
|
155
|
-
if (null ==
|
|
159
|
+
if (null == actionFunc) {
|
|
156
160
|
throw new SdkGenError('Unknown action: ' + actname)
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
const ctx = resolveActionContext()
|
|
160
164
|
|
|
161
|
-
await
|
|
165
|
+
await actionFunc(pargs, ctx)
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
|
|
165
169
|
function resolveActionContext(): ActionContext {
|
|
166
170
|
|
|
167
171
|
// TODO: use AsyncLocalStorage to avoid reloading model
|
|
168
|
-
const { model,
|
|
172
|
+
const { model, url } = resolveModel()
|
|
169
173
|
|
|
170
174
|
const ctx: ActionContext = {
|
|
171
175
|
fs: () => fs,
|
|
172
176
|
log,
|
|
173
177
|
folder: '.', // The `generate` folder,
|
|
174
178
|
model,
|
|
175
|
-
|
|
179
|
+
url,
|
|
176
180
|
jostraca,
|
|
177
181
|
opts,
|
|
178
182
|
}
|
|
@@ -183,14 +187,14 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
183
187
|
|
|
184
188
|
function resolveModel() {
|
|
185
189
|
const path = './model/sdk.jsonic'
|
|
186
|
-
const
|
|
190
|
+
const errs: any[] = []
|
|
191
|
+
const aopts = { path, errs }
|
|
187
192
|
const src = fs.readFileSync(path, 'utf8')
|
|
188
193
|
|
|
189
|
-
const
|
|
190
|
-
const hasErr = tree.err && 0 < tree.err.length
|
|
194
|
+
const model = aontu.generate(src, aopts)
|
|
191
195
|
|
|
192
|
-
if (
|
|
193
|
-
for (let serr of
|
|
196
|
+
if (0 < errs.length) {
|
|
197
|
+
for (let serr of errs) {
|
|
194
198
|
let err: any = new SdkGenError('Model Error: ' + serr.msg)
|
|
195
199
|
err.cause$ = [serr]
|
|
196
200
|
|
|
@@ -198,31 +202,11 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
198
202
|
err.uxmsg$ = true
|
|
199
203
|
}
|
|
200
204
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
err.rooterrs$ = tree.err
|
|
205
|
+
err.rooterrs$ = errs
|
|
205
206
|
throw err
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
let genctx = new Context({ root: tree })
|
|
210
|
-
const model = tree.gen(genctx)
|
|
211
|
-
|
|
212
|
-
// TODO: collect all errors
|
|
213
|
-
if (genctx.err && 0 < genctx.err.length) {
|
|
214
|
-
const err: any = new SdkGenError('Model Error:\n' +
|
|
215
|
-
(genctx.err.map((pe: any) => pe.msg)).join('\n'))
|
|
216
|
-
// log.error({ fail: 'build', what: 'guide', file: path, err })
|
|
217
|
-
err.errs = () => genctx.err
|
|
218
|
-
throw err
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// TODO: FIX: This is a hack to set the correct src file
|
|
222
|
-
// aontu bug: url is empty
|
|
223
|
-
tree.url = path
|
|
224
|
-
|
|
225
|
-
|
|
226
210
|
model.const = { name: model.name }
|
|
227
211
|
|
|
228
212
|
names(model.const, model.name)
|
|
@@ -231,7 +215,7 @@ function SdkGen(opts: SdkGenOptions) {
|
|
|
231
215
|
|
|
232
216
|
return {
|
|
233
217
|
model,
|
|
234
|
-
|
|
218
|
+
url: path,
|
|
235
219
|
}
|
|
236
220
|
}
|
|
237
221
|
|
|
@@ -369,6 +353,7 @@ export {
|
|
|
369
353
|
Main,
|
|
370
354
|
Entity,
|
|
371
355
|
Feature,
|
|
356
|
+
Test,
|
|
372
357
|
Readme,
|
|
373
358
|
ReadmeInstall,
|
|
374
359
|
ReadmeOptions,
|
package/src/types.ts
CHANGED
|
@@ -6,6 +6,11 @@ import type {
|
|
|
6
6
|
} from 'jostraca'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
import {
|
|
10
|
+
KIT,
|
|
11
|
+
getModelPath,
|
|
12
|
+
} from '@voxgig/apidef'
|
|
13
|
+
|
|
9
14
|
type FsUtil = typeof Fs
|
|
10
15
|
|
|
11
16
|
|
|
@@ -14,7 +19,7 @@ type ActionContext = {
|
|
|
14
19
|
log: any,
|
|
15
20
|
folder: string,
|
|
16
21
|
model: any,
|
|
17
|
-
|
|
22
|
+
url: string,
|
|
18
23
|
opts: any,
|
|
19
24
|
jostraca: any
|
|
20
25
|
}
|
|
@@ -25,6 +30,10 @@ type ActionResult = {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
|
|
33
|
+
export {
|
|
34
|
+
KIT,
|
|
35
|
+
getModelPath,
|
|
36
|
+
}
|
|
28
37
|
|
|
29
38
|
export type {
|
|
30
39
|
ActionContext,
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
cmp,
|
|
4
|
-
File, Content, Folder, Fragment, Slot
|
|
5
|
-
} from '@voxgig/sdkgen'
|
|
6
|
-
|
|
7
|
-
import { jsonify } from '@voxgig/struct'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const EntityTest = cmp(function EntityTest(props: any) {
|
|
13
|
-
const ctx$ = props.ctx$
|
|
14
|
-
const { model } = props.ctx$
|
|
15
|
-
const { target, entity, entrep, ff } = props
|
|
16
|
-
|
|
17
|
-
Folder({ name: 'test/entity' }, () => {
|
|
18
|
-
|
|
19
|
-
File({ name: entity.Name + 'Entity.test.' + target.name }, () => {
|
|
20
|
-
|
|
21
|
-
Fragment({
|
|
22
|
-
from: ff + 'Entity.test.fragment.ts',
|
|
23
|
-
replace: {
|
|
24
|
-
...entrep
|
|
25
|
-
}
|
|
26
|
-
}, () => {
|
|
27
|
-
|
|
28
|
-
// TODO: should be EntityFlow
|
|
29
|
-
const basicflow = model?.main?.sdk?.flow?.['Basic' + entity.Name + 'Flow']
|
|
30
|
-
|
|
31
|
-
const dobasic = basicflow && true === basicflow.active
|
|
32
|
-
|
|
33
|
-
if (!dobasic) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let indent = 2
|
|
38
|
-
|
|
39
|
-
Slot({ name: 'basicSetup' }, () => {
|
|
40
|
-
Content(`
|
|
41
|
-
function basicSetup(extra?: any) {
|
|
42
|
-
extra = extra || {}
|
|
43
|
-
|
|
44
|
-
const options = ${jsonify(basicflow.test, { offset: indent - 2 })}
|
|
45
|
-
|
|
46
|
-
const setup: any = {
|
|
47
|
-
dm: {
|
|
48
|
-
p: envOverride(${jsonify(basicflow.param, { offset: 2 + indent })}),
|
|
49
|
-
s: {},
|
|
50
|
-
},
|
|
51
|
-
options,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { merge } = utility.struct
|
|
55
|
-
|
|
56
|
-
let client = ${model.Name}SDK.test(options, extra)
|
|
57
|
-
if ('TRUE' === setup.dm.p.${model.NAME}_TEST_LIVE) {
|
|
58
|
-
client = new ${model.Name}SDK(merge([
|
|
59
|
-
{
|
|
60
|
-
apikey: process.env.${model.Name}_APIKEY,
|
|
61
|
-
},
|
|
62
|
-
extra])
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setup.client = client
|
|
67
|
-
setup.struct = client.utility().struct
|
|
68
|
-
setup.explain = 'TRUE' === setup.dm.p.${model.Name}_TEST_EXPLAIN
|
|
69
|
-
|
|
70
|
-
return setup
|
|
71
|
-
}
|
|
72
|
-
`)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
indent = 6
|
|
77
|
-
Slot({ name: 'basic' }, () => {
|
|
78
|
-
Content(`
|
|
79
|
-
const setup = basicSetup()
|
|
80
|
-
const { dm, options, client, struct, explain } = setup
|
|
81
|
-
const { validate, transform } = struct
|
|
82
|
-
let ctrl: any = {}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
`)
|
|
86
|
-
|
|
87
|
-
ctx$.util.makeFlow(basicflow, {
|
|
88
|
-
indent: indent,
|
|
89
|
-
model,
|
|
90
|
-
}, {
|
|
91
|
-
FlowStep:
|
|
92
|
-
'\n// Step: $$__stepdef.name$$ - $$__stepdef.action$$ $$__stepdef.entity$$\n',
|
|
93
|
-
|
|
94
|
-
GetEntity: [
|
|
95
|
-
'const $$__stepdef.name$$ = makeStepData(dm, \'$$__stepdef.name$$\')\n',
|
|
96
|
-
(stepdef: any, pctx: any) => pctx.data.step[stepdef.name] = stepdef,
|
|
97
|
-
[
|
|
98
|
-
'__stepdef._ref',
|
|
99
|
-
'$$__stepdef.name$$.entity = $$__stepdef._ref$$.entity\n',
|
|
100
|
-
'$$__stepdef.name$$.entity = client.$$__stepdef.Entity$$()\n',
|
|
101
|
-
],
|
|
102
|
-
],
|
|
103
|
-
|
|
104
|
-
EntityMatch: [
|
|
105
|
-
(stepdef: any) => stepdef.match_JSON = jsonify(stepdef.match),
|
|
106
|
-
[
|
|
107
|
-
'__stepdef.match',
|
|
108
|
-
'$$__stepdef.name$$.match = makeMatch(dm, transform, $$__stepdef.match_JSON$$)\n'
|
|
109
|
-
]
|
|
110
|
-
],
|
|
111
|
-
|
|
112
|
-
EntityData: [
|
|
113
|
-
(stepdef: any) => stepdef.reqdata_JSON = jsonify(stepdef.reqdata),
|
|
114
|
-
[
|
|
115
|
-
'__stepdef.reqdata',
|
|
116
|
-
'$$__stepdef.name$$.reqdata = ' +
|
|
117
|
-
'makeReqdata(dm, transform, $$__stepdef.reqdata_JSON$$)\n'
|
|
118
|
-
]
|
|
119
|
-
],
|
|
120
|
-
|
|
121
|
-
EntityAction: [
|
|
122
|
-
// 'ctrl = explain ? { explain: {} } : undefined\n',
|
|
123
|
-
[
|
|
124
|
-
{ __stepdef: { action: { '`$OR`': ['update', 'create', 'remove'] } } },
|
|
125
|
-
'$$__stepdef.name$$.resdata =\n' +
|
|
126
|
-
' await $$__stepdef.name$$.entity.$$__stepdef.action$$(' +
|
|
127
|
-
'$$__stepdef.name$$.reqdata, ctrl = makeCtrl(explain))\n'
|
|
128
|
-
],
|
|
129
|
-
[
|
|
130
|
-
{ __stepdef: { action: 'load' } },
|
|
131
|
-
'$$__stepdef.name$$.resdata =\n' +
|
|
132
|
-
' await $$__stepdef.name$$.entity.load($$__stepdef.name$$.match, ctrl = makeCtrl(explain))\n'
|
|
133
|
-
],
|
|
134
|
-
[
|
|
135
|
-
{ __stepdef: { action: 'list' } },
|
|
136
|
-
'$$__stepdef.name$$.reslist =\n' +
|
|
137
|
-
' await $$__stepdef.name$$.entity.list($$__stepdef.name$$.match, ctrl = makeCtrl(explain))\n'
|
|
138
|
-
],
|
|
139
|
-
],
|
|
140
|
-
|
|
141
|
-
ExplainAction:
|
|
142
|
-
'if( explain ) { console.log(\'$$__stepdef.name$$: \', ctrl.explain) }\n',
|
|
143
|
-
|
|
144
|
-
ValidateAction: [
|
|
145
|
-
(stepdef: any) => {
|
|
146
|
-
stepdef.valid_JSON = jsonify(stepdef.valid)
|
|
147
|
-
stepdef.reslist_DATA =
|
|
148
|
-
null == stepdef.reslist ? [] : stepdef.reslist.map((ent: any) => ent.data())
|
|
149
|
-
},
|
|
150
|
-
[
|
|
151
|
-
{ __stepdef: { action: { '`$OR`': ['load', 'update', 'create', 'remove'] } } },
|
|
152
|
-
'makeValid(dm, validate, $$__stepdef.name$$.resdata, ' +
|
|
153
|
-
'$$__stepdef.valid_JSON$$)\n'
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
{ __stepdef: { action: 'list' } },
|
|
157
|
-
'makeValid(dm, validate, $$__stepdef.name$$.reslist_DATA, ' +
|
|
158
|
-
'$$__stepdef.valid_JSON$)\n'
|
|
159
|
-
],
|
|
160
|
-
]
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
Content(`
|
|
164
|
-
}
|
|
165
|
-
catch(err: any) {
|
|
166
|
-
console.dir(dm, {depth: null})
|
|
167
|
-
if( explain ) { console.dir(ctrl.explain, {depth: null}) }
|
|
168
|
-
throw err
|
|
169
|
-
}
|
|
170
|
-
`)
|
|
171
|
-
})
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
})
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
export {
|
|
179
|
-
EntityTest
|
|
180
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Context, Operation } from '../types'
|
|
3
|
-
|
|
4
|
-
import { getprop } from './StructUtility'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const OPKIND: any = {
|
|
8
|
-
create: 'req',
|
|
9
|
-
update: 'req',
|
|
10
|
-
remove: 'req',
|
|
11
|
-
load: 'res',
|
|
12
|
-
list: 'res',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function opify(opmap: Record<string, any>) {
|
|
17
|
-
|
|
18
|
-
const validate = getprop(opmap, 'validate', {})
|
|
19
|
-
|
|
20
|
-
const op: Operation = {
|
|
21
|
-
name: getprop(opmap, 'name', '_'),
|
|
22
|
-
kind: getprop(opmap, 'kind', '_'),
|
|
23
|
-
path: getprop(opmap, 'path', '_'),
|
|
24
|
-
pathalt: getprop(opmap, 'pathalt', []),
|
|
25
|
-
entity: getprop(opmap, 'entity', '_'),
|
|
26
|
-
reqform: getprop(opmap, 'reqform', '_'),
|
|
27
|
-
resform: getprop(opmap, 'resform', '_'),
|
|
28
|
-
validate: {
|
|
29
|
-
params: getprop(validate, 'params', { '`$OPEN`': true }),
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
params: getprop(opmap, 'params', []),
|
|
33
|
-
alias: getprop(opmap, 'alias', {}),
|
|
34
|
-
state: getprop(opmap, 'state', {}),
|
|
35
|
-
check: getprop(opmap, 'check', {}),
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return op
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Ensure standard operation definition.
|
|
43
|
-
function operator(ctx: Context): Operation {
|
|
44
|
-
const { op, utility } = ctx
|
|
45
|
-
const { validate } = utility.struct
|
|
46
|
-
|
|
47
|
-
const opspec = {
|
|
48
|
-
|
|
49
|
-
// Required.
|
|
50
|
-
name: '`$STRING`',
|
|
51
|
-
kind: ['`$ONE`', 'req', 'res'],
|
|
52
|
-
path: '`$STRING`',
|
|
53
|
-
entity: '`$STRING`',
|
|
54
|
-
reqform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
|
|
55
|
-
resform: ['`$ONE`', '`$STRING`', '`$OBJECT`', '`$ARRAY`', '`$FUNCTION`'],
|
|
56
|
-
validate: {
|
|
57
|
-
params: '`$OBJECT`'
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
// Optional.
|
|
61
|
-
pathalt: ['`$CHILD`', {
|
|
62
|
-
path: '`$STRING`',
|
|
63
|
-
'`$OPEN`': true,
|
|
64
|
-
// '`$CHILD`': '`$BOOLEAN`'
|
|
65
|
-
}],
|
|
66
|
-
params: ['`$CHILD`', '`$STRING`'],
|
|
67
|
-
alias: { '`$CHILD`': '`$STRING`' },
|
|
68
|
-
state: {},
|
|
69
|
-
check: {},
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
ctx.op.kind = OPKIND[op.name]
|
|
73
|
-
|
|
74
|
-
const opv = ctx.op.validate
|
|
75
|
-
ctx.op = validate(ctx.op, opspec)
|
|
76
|
-
|
|
77
|
-
ctx.op.validate = opv
|
|
78
|
-
|
|
79
|
-
if (ctx.ctrl.explain) {
|
|
80
|
-
ctx.ctrl.explain.op = ctx.op
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return ctx.op
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export {
|
|
88
|
-
opify,
|
|
89
|
-
operator,
|
|
90
|
-
}
|