@voxgig/sdkgen 0.15.0 → 0.17.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 +135 -0
- package/dist/action/feature.d.ts +2 -0
- package/dist/action/feature.js +76 -0
- package/dist/action/feature.js.map +1 -0
- package/dist/action/lang.d.ts +2 -0
- package/dist/action/lang.js +68 -0
- package/dist/action/lang.js.map +1 -0
- package/dist/action/target.d.ts +2 -0
- package/dist/action/target.js +82 -0
- package/dist/action/target.js.map +1 -0
- package/dist/cmp/Entity.js +3 -3
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +10 -3
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.d.ts +2 -0
- package/dist/cmp/FeatureHook.js +17 -0
- package/dist/cmp/FeatureHook.js.map +1 -0
- package/dist/cmp/Hook.d.ts +2 -0
- package/dist/cmp/Hook.js +10 -0
- package/dist/cmp/Hook.js.map +1 -0
- package/dist/cmp/Main.js +12 -5
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/Readme.js +8 -8
- package/dist/cmp/Readme.js.map +1 -1
- package/dist/cmp/ReadmeInstall.js +3 -3
- package/dist/cmp/ReadmeInstall.js.map +1 -1
- package/dist/cmp/ReadmeOptions.js +2 -2
- package/dist/cmp/ReadmeOptions.js.map +1 -1
- package/dist/cmp/ReadmeQuick.js +3 -3
- package/dist/cmp/ReadmeQuick.js.map +1 -1
- package/dist/sdkgen.d.ts +15 -4
- package/dist/sdkgen.js +106 -35
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +4 -1
- package/dist/utility.js +11 -2
- package/dist/utility.js.map +1 -1
- package/model/sdkgen.jsonic +58 -6
- package/package.json +12 -12
- package/project/generate/model/feature/limit.jsonic +12 -0
- package/project/generate/model/feature/log.jsonic +28 -0
- package/project/generate/model/feature/page.jsonic +9 -0
- package/project/generate/model/feature/telemetry.jsonic +10 -0
- package/project/generate/model/target/go.jsonic +7 -0
- package/project/generate/model/target/js.jsonic +24 -0
- package/project/generate/src/cmp/js/Config_js.ts +34 -0
- package/project/generate/src/cmp/js/Entity_js.ts +91 -0
- package/project/generate/src/cmp/js/MainEntity_js.ts +22 -0
- package/project/generate/src/cmp/js/Main_js.ts +82 -0
- package/project/generate/src/cmp/js/Package_js.ts +57 -0
- package/project/generate/src/cmp/js/Quick_js.ts +82 -0
- package/project/generate/src/cmp/js/ReadmeInstall_js.ts +19 -0
- package/project/generate/src/cmp/js/ReadmeQuick_js.ts +25 -0
- package/project/generate/src/cmp/js/TestAcceptEntity_js.ts +101 -0
- package/project/generate/src/cmp/js/TestAccept_js.ts +60 -0
- package/project/generate/src/cmp/js/TestEntity_js.ts +24 -0
- package/project/generate/src/cmp/js/TestMain_js.ts +120 -0
- package/project/generate/src/cmp/js/Test_js.ts +24 -0
- package/project/generate/src/cmp/js/fragment/Entity.fragment.js +71 -0
- package/project/generate/src/cmp/js/fragment/EntityCreateOp.fragment.js +66 -0
- package/project/generate/src/cmp/js/fragment/EntityListOp.fragment.js +72 -0
- package/project/generate/src/cmp/js/fragment/EntityLoadOp.fragment.js +66 -0
- package/project/generate/src/cmp/js/fragment/EntityRemoveOp.fragment.js +66 -0
- package/project/generate/src/cmp/js/fragment/EntityUpdateOp.fragment.js +66 -0
- package/project/generate/src/cmp/js/fragment/Main.fragment.js +44 -0
- package/project/generate/tm/go/LICENSE +22 -0
- package/project/generate/tm/js/LICENSE +22 -0
- package/project/generate/tm/js/src/feature/log/LogFeature.js +104 -0
- package/project/generate/tm/js/src/utility/AuthUtility.js +16 -0
- package/project/generate/tm/js/src/utility/BodyUtility.js +27 -0
- package/project/generate/tm/js/src/utility/EmptyUtility.js +8 -0
- package/project/generate/tm/js/src/utility/ErrorUtility.js +15 -0
- package/project/generate/tm/js/src/utility/EscreUtility.js +8 -0
- package/project/generate/tm/js/src/utility/EscurlUtility.js +8 -0
- package/project/generate/tm/js/src/utility/FetchUtility.js +33 -0
- package/project/generate/tm/js/src/utility/FullurlUtility.js +41 -0
- package/project/generate/tm/js/src/utility/HeadersUtility.js +12 -0
- package/project/generate/tm/js/src/utility/InwardUtility.js +23 -0
- package/project/generate/tm/js/src/utility/JoinurlUtility.js +12 -0
- package/project/generate/tm/js/src/utility/MethodUtility.js +21 -0
- package/project/generate/tm/js/src/utility/OperatorUtility.js +36 -0
- package/project/generate/tm/js/src/utility/OptionsUtility.js +22 -0
- package/project/generate/tm/js/src/utility/OutwardUtility.js +23 -0
- package/project/generate/tm/js/src/utility/ParamsUtility.js +20 -0
- package/project/generate/tm/js/src/utility/QueryUtility.js +19 -0
- package/project/generate/tm/js/src/utility/ResbasicUtility.js +17 -0
- package/project/generate/tm/js/src/utility/ResbodyUtility.js +10 -0
- package/project/generate/tm/js/src/utility/ResheadersUtility.js +11 -0
- package/project/generate/tm/js/src/utility/ResponseUtility.js +36 -0
- package/project/generate/tm/js/src/utility/SpecUtility.js +41 -0
- package/project/generate/tm/js/src/utility/Utility.js +55 -0
- package/src/action/feature.ts +120 -0
- package/src/action/target.ts +127 -0
- package/src/cmp/Entity.ts +6 -4
- package/src/cmp/Feature.ts +11 -4
- package/src/cmp/FeatureHook.ts +23 -0
- package/src/cmp/Main.ts +14 -6
- package/src/cmp/Readme.ts +8 -8
- package/src/cmp/ReadmeInstall.ts +3 -3
- package/src/cmp/ReadmeOptions.ts +2 -2
- package/src/cmp/ReadmeQuick.ts +3 -3
- package/src/sdkgen.ts +116 -34
- package/src/utility.ts +11 -1
- package/src/prepare-openapi.ts +0 -59
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
cmp, each, camelify,
|
|
6
|
+
File, Content, Folder, Fragment, Line, FeatureHook,
|
|
7
|
+
} from '@voxgig/sdkgen'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const Operation = cmp(function Operation(props: any) {
|
|
12
|
+
// console.log('OP', props)
|
|
13
|
+
|
|
14
|
+
const { ff, opname, indent, entity } = props
|
|
15
|
+
|
|
16
|
+
const entop = entity.op[opname]
|
|
17
|
+
const path = entop.path
|
|
18
|
+
// console.log('ENTOP', entop)
|
|
19
|
+
|
|
20
|
+
// TODO: move up to to common Entity
|
|
21
|
+
const params = JSON.stringify(path
|
|
22
|
+
.match(/\{[^}]+\}/g)
|
|
23
|
+
.map((p: string) => p.substring(1, p.length - 1))
|
|
24
|
+
.filter((p: string) => null != p && '' !== p))
|
|
25
|
+
|
|
26
|
+
const hasp = '' != entop.place
|
|
27
|
+
|
|
28
|
+
Fragment({
|
|
29
|
+
from: ff + '/Entity' + camelify(opname) + 'Op.fragment.js',
|
|
30
|
+
indent,
|
|
31
|
+
replace: {
|
|
32
|
+
Name: entity.Name,
|
|
33
|
+
PATH: entop.path,
|
|
34
|
+
"['PARAM']": params,
|
|
35
|
+
"'INWARD'":
|
|
36
|
+
entop.inward ||
|
|
37
|
+
'ctx.result.body' + ('' === entop.place ? '' : '.' + entop.place),
|
|
38
|
+
"'OUTWARD'":
|
|
39
|
+
entop.outward ||
|
|
40
|
+
(hasp ? '({' + entop.place + ': ' : '') + 'ctx.op.data' + (hasp ? '})' : ''),
|
|
41
|
+
|
|
42
|
+
'class EntityOperation { // REMOVED': '',
|
|
43
|
+
'} // REMOVED': '',
|
|
44
|
+
|
|
45
|
+
'#Feature-Hook': ({ name, indent }: any) =>
|
|
46
|
+
FeatureHook({ name }, (f: any) =>
|
|
47
|
+
Line({ indent },
|
|
48
|
+
`${f.await ? 'await ' : ''}this.#features.${f.name}.${name}(ctx)`)),
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const Entity = cmp(function Entity(props: any) {
|
|
56
|
+
const { target, entity } = props
|
|
57
|
+
// const { model } = props.ctx$
|
|
58
|
+
|
|
59
|
+
const ff = Path.normalize(__dirname + '/../../../src/cmp/js/fragment')
|
|
60
|
+
|
|
61
|
+
Folder({ name: 'src/entity' }, () => {
|
|
62
|
+
|
|
63
|
+
File({ name: entity.Name + 'Entity.' + target.name }, () => {
|
|
64
|
+
|
|
65
|
+
const opnames = Object.keys(entity.op)
|
|
66
|
+
|
|
67
|
+
const opfrags =
|
|
68
|
+
(['load', 'list', 'create', 'update', 'remove']
|
|
69
|
+
.reduce((a: any, opname: string) =>
|
|
70
|
+
(a['#' + camelify(opname) + 'Op'] =
|
|
71
|
+
!opnames.includes(opname) ? '' : ({ indent }: any) => {
|
|
72
|
+
Operation({ ff, opname, indent, entity })
|
|
73
|
+
}, a), {}))
|
|
74
|
+
|
|
75
|
+
Fragment({
|
|
76
|
+
from: ff + '/Entity.fragment.js',
|
|
77
|
+
replace: {
|
|
78
|
+
Name: entity.Name,
|
|
79
|
+
|
|
80
|
+
...opfrags,
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
Entity
|
|
91
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const MainEntity = cmp(async function MainEntity(props: any) {
|
|
7
|
+
const { entity } = props
|
|
8
|
+
|
|
9
|
+
Content(`
|
|
10
|
+
${entity.Name}(data) {
|
|
11
|
+
const self = this
|
|
12
|
+
return new ${entity.Name}Entity(self,data)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
`)
|
|
16
|
+
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
MainEntity
|
|
22
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
cmp, each, names,
|
|
6
|
+
List, File, Content, Copy, Folder, Fragment, Line, FeatureHook,
|
|
7
|
+
} from '@voxgig/sdkgen'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import { Package } from './Package_js'
|
|
11
|
+
import { Config } from './Config_js'
|
|
12
|
+
import { MainEntity } from './MainEntity_js'
|
|
13
|
+
import { Test } from './Test_js'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const Main = cmp(async function Main(props: any) {
|
|
17
|
+
const { target } = props
|
|
18
|
+
const { model } = props.ctx$
|
|
19
|
+
|
|
20
|
+
const { entity } = model.main.api
|
|
21
|
+
const { feature } = model.main.sdk
|
|
22
|
+
const { utility } = model.main.sdk
|
|
23
|
+
|
|
24
|
+
Package({ target })
|
|
25
|
+
|
|
26
|
+
Test({ target })
|
|
27
|
+
|
|
28
|
+
Folder({ name: 'src' }, () => {
|
|
29
|
+
|
|
30
|
+
File({ name: model.const.Name + 'SDK.' + target.name }, () => {
|
|
31
|
+
|
|
32
|
+
Line(`// ${model.const.Name} ${target.Name} SDK\n`)
|
|
33
|
+
|
|
34
|
+
List({ item: feature }, ({ item }: any) =>
|
|
35
|
+
Line(`const { ${item.Name + 'Feature'} } = ` +
|
|
36
|
+
`require('./feature/${item.name}/${item.Name}Feature')`))
|
|
37
|
+
|
|
38
|
+
List({ item: entity }, ({ item }: any) =>
|
|
39
|
+
Line(`const { ${item.Name}Entity } = require('./entity/${item.Name}Entity')`))
|
|
40
|
+
|
|
41
|
+
each(utility, (u: any) =>
|
|
42
|
+
Line(`const { ${u.name} } = require('./utility/${u.Name}Utility')`))
|
|
43
|
+
Line('')
|
|
44
|
+
|
|
45
|
+
Fragment({
|
|
46
|
+
from: Path.normalize(__dirname + '/../../../src/cmp/js/fragment/Main.fragment.js'),
|
|
47
|
+
replace: {
|
|
48
|
+
Name: model.const.Name,
|
|
49
|
+
|
|
50
|
+
'#BuildFeature': ({ indent }: any) =>
|
|
51
|
+
List({ item: feature, line: false }, ({ item }: any) =>
|
|
52
|
+
Line({ indent }, `${item.name}: ` +
|
|
53
|
+
`new ${item.Name}Feature(this, this.#options.feature.${item.name}, ` +
|
|
54
|
+
`${JSON.stringify(item.config || {})}), `)),
|
|
55
|
+
|
|
56
|
+
'#CustomUtility': ({ indent }: any) =>
|
|
57
|
+
each(utility, (u: any) =>
|
|
58
|
+
Line({ indent }, `this.#utility.${u.name} = ${u.name}`)),
|
|
59
|
+
|
|
60
|
+
'#Feature-Hook': ({ name, indent }: any) =>
|
|
61
|
+
FeatureHook({ name }, (f: any) =>
|
|
62
|
+
Line({ indent },
|
|
63
|
+
`${f.await ? 'await ' : ''}this.#features.${f.name}.${name}({ client: this })`)),
|
|
64
|
+
}
|
|
65
|
+
}, () => {
|
|
66
|
+
|
|
67
|
+
each(entity, (entity: any) => {
|
|
68
|
+
MainEntity({ model, target, entity })
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
Config({ target })
|
|
75
|
+
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
Main
|
|
82
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
cmp, omap, each, cmap,
|
|
4
|
+
File, Content,
|
|
5
|
+
} from '@voxgig/sdkgen'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const Package = cmp(async function Package(props: any) {
|
|
10
|
+
const { target, ctx$: { model } } = props
|
|
11
|
+
const { main: { sdk: { feature } } } = model
|
|
12
|
+
|
|
13
|
+
const only = (kind: string, deps: any) =>
|
|
14
|
+
omap(deps, ([k, v]: any) => [v.active && kind === v.kind ? k : undefined, v.version])
|
|
15
|
+
|
|
16
|
+
// merge target and feature deps, by kind
|
|
17
|
+
const deps =
|
|
18
|
+
each(feature, (feature: any) =>
|
|
19
|
+
omap(feature.deps[target.name], ([k, v]: any) =>
|
|
20
|
+
[v.active ? k : undefined, v]))
|
|
21
|
+
// TODO: sort by version; rules for version choice?
|
|
22
|
+
.reduce((a: any, deps: any) => (each(deps, (dep: any) =>
|
|
23
|
+
a[dep.kind][dep.key$] = dep.version), a),
|
|
24
|
+
{
|
|
25
|
+
prod: only('prod', target.deps),
|
|
26
|
+
peer: only('peer', target.deps),
|
|
27
|
+
dev: only('dev', target.deps),
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// TODO: complete SDK meta data in model and use here
|
|
31
|
+
const pkg = {
|
|
32
|
+
name: `${model.const.name}-sdk`,
|
|
33
|
+
version: `0.0.1`,
|
|
34
|
+
description: 'DESCRIPTION',
|
|
35
|
+
main: `src/${model.const.Name}SDK.js`,
|
|
36
|
+
scripts: {
|
|
37
|
+
'test': 'node --test test/*.test.js',
|
|
38
|
+
'test-accept': 'node --test test/accept/*.test.js',
|
|
39
|
+
'test-all': 'npm run test && npm run test-accept'
|
|
40
|
+
},
|
|
41
|
+
author: `${model.const.Name}`,
|
|
42
|
+
license: 'MIT',
|
|
43
|
+
dependencies: deps.prod,
|
|
44
|
+
peerDependencies: deps.peer,
|
|
45
|
+
devDependencies: deps.dev,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
File({ name: 'package.json' }, () => {
|
|
50
|
+
Content(JSON.stringify(pkg, null, 2))
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
Package
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
|
|
2
|
+
import { names, getx, each, cmp, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Quick = cmp(function Quick(props: any) {
|
|
6
|
+
const { target } = props
|
|
7
|
+
const { model, meta: { spec } } = props.ctx$
|
|
8
|
+
|
|
9
|
+
// get quick entity from target config
|
|
10
|
+
|
|
11
|
+
let ent: any
|
|
12
|
+
let entmap = getx(spec.config.guideModel, 'guide entity?test:quick:active=true')
|
|
13
|
+
|
|
14
|
+
if (entmap) {
|
|
15
|
+
ent = Object.values(entmap)[0]
|
|
16
|
+
ent.name = Object.keys(entmap)[0]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
ent = ent || { name: 'Entity' }
|
|
20
|
+
names(ent, ent.name)// , ent.key$ || 'name')
|
|
21
|
+
|
|
22
|
+
// TODO: selected features should be active by default!
|
|
23
|
+
|
|
24
|
+
const featureOptions = each(model.main.sdk.feature)
|
|
25
|
+
.filter((f: any) => f.active)
|
|
26
|
+
.reduce((a: any, f: any) => a + `\n ${f.name}: { active: true },`, '')
|
|
27
|
+
|
|
28
|
+
// console.log('QUICK', ent, featureOptions)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
File({ name: 'quick.' + target.name }, () => {
|
|
32
|
+
|
|
33
|
+
Content(`
|
|
34
|
+
// ENT 3
|
|
35
|
+
require('dotenv').config({ path: ['../../.env.local']})
|
|
36
|
+
|
|
37
|
+
const { ${model.const.Name}SDK } = require('../')
|
|
38
|
+
|
|
39
|
+
run()
|
|
40
|
+
|
|
41
|
+
async function run() {
|
|
42
|
+
const client = new ${model.const.Name}SDK({
|
|
43
|
+
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
44
|
+
apikey: process.env.${model.NAME}_APIKEY,
|
|
45
|
+
${featureOptions}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
`)
|
|
49
|
+
|
|
50
|
+
if (ent.test?.quick.create) {
|
|
51
|
+
Content(`
|
|
52
|
+
out = await client.${ent.Name}().create(${JSON.stringify(ent.test?.quick.create)})
|
|
53
|
+
console.log('${ent.Name}.load', out)
|
|
54
|
+
`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (ent.test?.quick.load) {
|
|
58
|
+
Content(`
|
|
59
|
+
out = await client.${ent.Name}().load(${JSON.stringify(ent.test?.quick.load)})
|
|
60
|
+
console.log('${ent.Name}.load', out)
|
|
61
|
+
`)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (ent.test?.quick.list) {
|
|
65
|
+
Content(`
|
|
66
|
+
out = await client.${ent.Name}().list(${JSON.stringify(ent.test?.quick.list)})
|
|
67
|
+
console.log('${ent.Name}.list', out)
|
|
68
|
+
`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Content(`
|
|
72
|
+
}
|
|
73
|
+
`)
|
|
74
|
+
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
Quick
|
|
81
|
+
}
|
|
82
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
|
|
6
|
+
const { target } = props
|
|
7
|
+
|
|
8
|
+
Content('```js')
|
|
9
|
+
Content(`
|
|
10
|
+
npm install ${target.module.name}
|
|
11
|
+
`)
|
|
12
|
+
Content('```')
|
|
13
|
+
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ReadmeInstall
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
6
|
+
const { target, ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
Content('```js')
|
|
9
|
+
Content(`
|
|
10
|
+
const { ${model.const.Name}SDK } = require('${target.module.name}')
|
|
11
|
+
|
|
12
|
+
const client = ${model.const.Name}SDK.make({
|
|
13
|
+
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
14
|
+
apikey: process.env.${model.NAME}_APIKEY,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
`)
|
|
18
|
+
Content('```')
|
|
19
|
+
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
ReadmeQuick
|
|
25
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, camelify, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestAcceptEntity = cmp(function TestEntity(props: any) {
|
|
6
|
+
const { entity } = props
|
|
7
|
+
|
|
8
|
+
entity.Name = camelify(entity.name)
|
|
9
|
+
|
|
10
|
+
Content(`
|
|
11
|
+
test('${entity.name}-load', async ()=>{
|
|
12
|
+
const client = makeClient()
|
|
13
|
+
const out = await client.${entity.Name}().load({id:'t01'})
|
|
14
|
+
//console.log('${entity.name}-load', 'out', out)
|
|
15
|
+
|
|
16
|
+
// equal(out.status, 200, 'Expected status code 200');
|
|
17
|
+
|
|
18
|
+
// Check out.data is an object
|
|
19
|
+
equal(typeof out.data, 'object', 'Expected data to be an object');
|
|
20
|
+
|
|
21
|
+
// Check out.data has id
|
|
22
|
+
equal(typeof out.data.id, 'string', 'Expected data to have an id');
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('${entity.name}-list', async ()=>{
|
|
27
|
+
const client = makeClient()
|
|
28
|
+
const out = await client.${entity.Name}().list()
|
|
29
|
+
//console.log('${entity.name}-list', 'out', out)
|
|
30
|
+
|
|
31
|
+
// Check out is an array
|
|
32
|
+
equal(Array.isArray(out), true, 'Expected an array');
|
|
33
|
+
|
|
34
|
+
// Check out.data is an object
|
|
35
|
+
equal(typeof out[0], 'object', 'Expected data to be an object');
|
|
36
|
+
|
|
37
|
+
// Check out.data has id
|
|
38
|
+
equal(typeof out[0].data.id, 'string', 'Expected data to have an id');
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('${entity.name}-create', async ()=>{
|
|
42
|
+
const client = makeClient()
|
|
43
|
+
const out = await client.${entity.Name}().create(${JSON.stringify(generateObjectFromFields(entity.field))})
|
|
44
|
+
//console.log('${entity.name}-create', 'out', out)
|
|
45
|
+
|
|
46
|
+
// Check out is an object
|
|
47
|
+
equal(typeof out, 'object', 'Expected an object');
|
|
48
|
+
|
|
49
|
+
// Check out.data has id
|
|
50
|
+
equal(typeof out.data.id, 'string', 'Expected data to have an id');
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('${entity.name}-save', async ()=>{
|
|
54
|
+
const client = makeClient()
|
|
55
|
+
const out = await client.${entity.Name}().save(${JSON.stringify(generateObjectFromFields(entity.field))})
|
|
56
|
+
//console.log('${entity.name}-save', 'out', out)
|
|
57
|
+
|
|
58
|
+
// Check out is an object
|
|
59
|
+
equal(typeof out, 'object', 'Expected an object');
|
|
60
|
+
|
|
61
|
+
// Check out.data has id
|
|
62
|
+
equal(typeof out.data.id, 'string', 'Expected data to have an id');
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('${entity.name}-remove', async ()=>{
|
|
66
|
+
const client = makeClient()
|
|
67
|
+
const out = await client.${entity.Name}().remove({id:'t01'})
|
|
68
|
+
//console.log('${entity.name}-remove', 'out', out)
|
|
69
|
+
|
|
70
|
+
// Check out is an object
|
|
71
|
+
equal(typeof out, 'object', 'Expected an object');
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
`);
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
function generateObjectFromFields(fields: any) {
|
|
78
|
+
const getRandomString = (length: number): string =>
|
|
79
|
+
Array.from({ length }, () => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random() * 62))).join('');
|
|
80
|
+
|
|
81
|
+
const defaultValues: Record<string, any> = {
|
|
82
|
+
number: Math.floor(Math.random() * 100),
|
|
83
|
+
string: getRandomString(5),
|
|
84
|
+
object: { [getRandomString(3)]: getRandomString(3) },
|
|
85
|
+
boolean: Math.random() > 0.5,
|
|
86
|
+
array: Array.from({ length: 3 }, () => getRandomString(3)),
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const result: Record<string, any> = {}
|
|
90
|
+
|
|
91
|
+
for (const key in fields) {
|
|
92
|
+
result[key] = defaultValues[fields[key].type] ?? null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
TestAcceptEntity
|
|
101
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { TestAcceptEntity } from './TestAcceptEntity_js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const TestAccept = cmp(function TestMain(props: any) {
|
|
9
|
+
const { target } = props
|
|
10
|
+
const { model } = props.ctx$
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
File({ name: model.const.Name + 'SDK.accept.test.' + target.name }, () => {
|
|
14
|
+
|
|
15
|
+
Content(`
|
|
16
|
+
const { test, describe } = require('node:test')
|
|
17
|
+
const { equal, deepEqual } = require('node:assert')
|
|
18
|
+
|
|
19
|
+
const { ${model.const.Name}SDK } = require('../../')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
describe('${model.const.Name}SDK Acceptance Tests', ()=>{
|
|
23
|
+
test('happy', async ()=>{
|
|
24
|
+
const client = makeClient()
|
|
25
|
+
const out = await client.Geofence().load({id:'gf01'})
|
|
26
|
+
console.log('Geofence.load', out)
|
|
27
|
+
equal(out.data.id,'gf01')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
`)
|
|
31
|
+
|
|
32
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
33
|
+
TestAcceptEntity({ model, target, entity })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Content(`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function makeClient(config) {
|
|
42
|
+
const client = ${model.const.Name}SDK.make({
|
|
43
|
+
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
44
|
+
apikey: process.env.${model.NAME}_APIKEY,
|
|
45
|
+
...config
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return client
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
`)
|
|
52
|
+
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
TestAccept
|
|
59
|
+
}
|
|
60
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, camelify, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestEntity = cmp(function TestEntity(props: any) {
|
|
6
|
+
const { entity } = props
|
|
7
|
+
|
|
8
|
+
entity.Name = camelify(entity.name)
|
|
9
|
+
|
|
10
|
+
Content(`
|
|
11
|
+
test('${entity.name}-load', async ()=>{
|
|
12
|
+
const client = makeClient()
|
|
13
|
+
const out = await client.${entity.Name}().load({id:'t01'})
|
|
14
|
+
console.log('${entity.name}-load', out)
|
|
15
|
+
deepEqual(out.data,{id:'t01',title:'T01'})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
`)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
TestEntity
|
|
24
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { TestEntity } from './TestEntity_js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const TestMain = cmp(function TestMain(props: any) {
|
|
9
|
+
const { target } = props
|
|
10
|
+
const { model } = props.ctx$
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
File({ name: model.const.Name + 'SDK.test.' + target.name }, () => {
|
|
14
|
+
|
|
15
|
+
Content(`
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const { test, describe } = require('node:test')
|
|
19
|
+
const { equal, deepEqual } = require('node:assert')
|
|
20
|
+
|
|
21
|
+
const { ${model.const.Name}SDK } = require('../')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
describe('${model.const.Name}SDK Unit Tests', ()=>{
|
|
25
|
+
test('make', async ()=>{
|
|
26
|
+
const client = makeClient()
|
|
27
|
+
equal(null == client, false)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
`)
|
|
31
|
+
|
|
32
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
33
|
+
TestEntity({ model, target, entity })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Content(`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function makeClient(config) {
|
|
42
|
+
const client = ${model.const.Name}SDK.make({
|
|
43
|
+
endpoint: 'https://host/api/v1/rest/project_id/plant/stage',
|
|
44
|
+
apikey: 'apikey',
|
|
45
|
+
fetch,
|
|
46
|
+
...config
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return client
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function fetch(url, config) {
|
|
53
|
+
const parts = url.split('/')
|
|
54
|
+
const entname = parts[9]
|
|
55
|
+
const entid = parts[10]
|
|
56
|
+
const data = JSON.parse(config.body||'{}')
|
|
57
|
+
const method = config.method || 'GET'
|
|
58
|
+
|
|
59
|
+
const req$ = {
|
|
60
|
+
url,
|
|
61
|
+
parts,
|
|
62
|
+
entname,
|
|
63
|
+
entid,
|
|
64
|
+
method,
|
|
65
|
+
data,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log('REQ', req$)
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
req$,
|
|
72
|
+
status: 200,
|
|
73
|
+
json: async function() {
|
|
74
|
+
if('PUT'=== method||'POST'===method) {
|
|
75
|
+
return entid ? {
|
|
76
|
+
id: entid,
|
|
77
|
+
title: data.title,
|
|
78
|
+
} :
|
|
79
|
+
{
|
|
80
|
+
id: 'n01',
|
|
81
|
+
title: data.title || 'T01',
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if('GET'===method) {
|
|
85
|
+
return entid ? {
|
|
86
|
+
id: entid,
|
|
87
|
+
title: 'T01'
|
|
88
|
+
} :
|
|
89
|
+
{
|
|
90
|
+
name: entname,
|
|
91
|
+
list: [
|
|
92
|
+
{
|
|
93
|
+
id: 'n01',
|
|
94
|
+
title: 'N01'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: 'n01',
|
|
98
|
+
title: 'N01'
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
`)
|
|
112
|
+
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
TestMain
|
|
119
|
+
}
|
|
120
|
+
|