@voxgig/create-sdkgen 0.0.2 → 0.0.3
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/run-create-sdkgen.js~ +1 -0
- package/package.json +3 -1
- package/tm/standard/.env.local +2 -0
- package/tm/standard/build/sdk.js +25 -0
- package/tm/standard/def/DEFINITION.md +2 -0
- package/tm/standard/model/.model-config/model-config.jsonic +13 -0
- package/tm/standard/model/go.jsonic +6 -0
- package/tm/standard/model/js.jsonic +6 -0
- package/tm/standard/model/php.jsonic +6 -0
- package/tm/standard/model/py.jsonic +7 -0
- package/tm/standard/model/rb.jsonic +6 -0
- package/tm/standard/model/sdk.jsonic.off +60 -0
- package/tm/standard/package.json +30 -0
- package/tm/standard/src/Root.ts +60 -0
- package/tm/standard/src/go/Entity_go.ts +226 -0
- package/tm/standard/src/go/MainEntity_go.ts +26 -0
- package/tm/standard/src/go/Main_go.ts +168 -0
- package/tm/standard/src/go/Quick_go.ts +108 -0
- package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
- package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
- package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
- package/tm/standard/src/go/TestAccept_go.ts +38 -0
- package/tm/standard/src/go/TestEntity_go.ts +79 -0
- package/tm/standard/src/go/TestMain_go.ts +61 -0
- package/tm/standard/src/go/Test_go.ts +20 -0
- package/tm/standard/src/js/Entity_js.ts +135 -0
- package/tm/standard/src/js/MainEntity_js.ts +22 -0
- package/tm/standard/src/js/Main_js.ts +128 -0
- package/tm/standard/src/js/Quick_js.ts +72 -0
- package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
- package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
- package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
- package/tm/standard/src/js/TestAccept_js.ts +60 -0
- package/tm/standard/src/js/TestEntity_js.ts +24 -0
- package/tm/standard/src/js/TestMain_js.ts +123 -0
- package/tm/standard/src/js/Test_js.ts +24 -0
- package/tm/standard/src/php/Entity_php.ts +97 -0
- package/tm/standard/src/php/MainEntity_php.ts +43 -0
- package/tm/standard/src/php/Main_php.ts +50 -0
- package/tm/standard/src/php/Quick_php.ts +59 -0
- package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
- package/tm/standard/src/php/TestAccept_php.ts +33 -0
- package/tm/standard/src/php/TestEntity_php.ts +64 -0
- package/tm/standard/src/php/TestMain_php.ts +120 -0
- package/tm/standard/src/php/Test_php.ts +21 -0
- package/tm/standard/src/py/Entity_py.ts +98 -0
- package/tm/standard/src/py/MainEntity_py.ts +19 -0
- package/tm/standard/src/py/Main_py.ts +211 -0
- package/tm/standard/src/py/Quick_py.ts +133 -0
- package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
- package/tm/standard/src/py/TestAccept_py.ts +77 -0
- package/tm/standard/src/py/TestEntity_py.ts +50 -0
- package/tm/standard/src/py/TestMain_py.ts +103 -0
- package/tm/standard/src/py/Test_py.ts +28 -0
- package/tm/standard/src/rb/Client_rb.ts +142 -0
- package/tm/standard/src/rb/Entity_rb.ts +153 -0
- package/tm/standard/src/rb/Error_rb.ts +56 -0
- package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
- package/tm/standard/src/rb/Main_rb.ts +55 -0
- package/tm/standard/src/rb/Quick_rb.ts +65 -0
- package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
- package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
- package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
- package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
- package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
- package/tm/standard/src/rb/TestMain_rb.ts +67 -0
- package/tm/standard/src/rb/Test_rb.ts +27 -0
- package/tm/standard/src/tsconfig.json +15 -0
- package/tm/standard/tm/go/.env.example +2 -0
- package/tm/standard/tm/go/LICENSE +22 -0
- package/tm/standard/tm/go/go.mod +5 -0
- package/tm/standard/tm/go/go.sum +2 -0
- package/tm/standard/tm/js/LICENSE +22 -0
- package/tm/standard/tm/js/package.json +17 -0
- package/tm/standard/tm/php/LICENSE +22 -0
- package/tm/standard/tm/py/LICENSE +22 -0
- package/tm/standard/tm/py/MANIFEST.in +4 -0
- package/tm/standard/tm/py/Makefile +14 -0
- package/tm/standard/tm/py/pyproject.toml +4 -0
- package/tm/standard/tm/py/pytest.ini +3 -0
- package/tm/standard/tm/py/requirements.txt +4 -0
- package/tm/standard/tm/py/setup.cfg +2 -0
- package/tm/standard/tm/py/setup.py +82 -0
- package/tm/standard/tm/rb/.rspec +1 -0
- package/tm/standard/tm/rb/Gemfile +21 -0
- package/tm/standard/tm/rb/LICENSE +22 -0
- package/tm/standard/tm/rb/Rakefile +6 -0
- package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
- package/tm/standard/tm/rb/tm.gemspec +39 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
|
|
2
|
+
// Entity 1
|
|
3
|
+
|
|
4
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const Entity = cmp(function Entity(props: any) {
|
|
8
|
+
const { build, entity } = props
|
|
9
|
+
const { model } = props.ctx$
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Folder({ name: 'src' }, () => {
|
|
13
|
+
|
|
14
|
+
File({ name: entity.Name + '.' + build.name }, () => {
|
|
15
|
+
|
|
16
|
+
Content(`
|
|
17
|
+
// ${model.Name} ${build.Name} ${entity.Name} 1
|
|
18
|
+
|
|
19
|
+
class ${entity.Name} {
|
|
20
|
+
def
|
|
21
|
+
data
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
constructor(sdk,data) {
|
|
25
|
+
this.sdk = ()=>sdk
|
|
26
|
+
this.def = {
|
|
27
|
+
name: '${entity.name}'
|
|
28
|
+
}
|
|
29
|
+
// data is optional
|
|
30
|
+
this.data = data
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async handleResult(op, res, spec, handler) {
|
|
35
|
+
const status = res.status
|
|
36
|
+
|
|
37
|
+
if(200 === status) {
|
|
38
|
+
const json = await res.json()
|
|
39
|
+
// TODO: error
|
|
40
|
+
return handler(json)
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error('HTTP-ERROR: '+op+': ${entity.name}: '+status)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async save(data) {
|
|
49
|
+
const op = 'save'
|
|
50
|
+
this.data = data
|
|
51
|
+
// TODO: validate data
|
|
52
|
+
|
|
53
|
+
const spec = this.sdk().fetchSpec(op,this)
|
|
54
|
+
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
55
|
+
|
|
56
|
+
return this.handleResult(op, res, spec, (json)=>{
|
|
57
|
+
this.data = json
|
|
58
|
+
return this
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async create(data) {
|
|
63
|
+
const op = 'create'
|
|
64
|
+
this.data = data
|
|
65
|
+
// TODO: validate data
|
|
66
|
+
|
|
67
|
+
const spec = this.sdk().fetchSpec(op,this)
|
|
68
|
+
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
69
|
+
|
|
70
|
+
return this.handleResult(op, res, spec, (json)=>{
|
|
71
|
+
this.data = json
|
|
72
|
+
return this
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
async load(data) {
|
|
78
|
+
const op = 'load'
|
|
79
|
+
this.data = data
|
|
80
|
+
// TODO: check data.id defined
|
|
81
|
+
// TODO: separate data and query
|
|
82
|
+
|
|
83
|
+
const spec = this.sdk().fetchSpec(op,this)
|
|
84
|
+
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
85
|
+
|
|
86
|
+
return this.handleResult(op, res, spec, (json)=>{
|
|
87
|
+
this.data = json
|
|
88
|
+
return this
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async remove(data) {
|
|
94
|
+
const op = 'remove'
|
|
95
|
+
this.data = data
|
|
96
|
+
// TODO: check data.id defined
|
|
97
|
+
|
|
98
|
+
const spec = this.sdk().fetchSpec(op,this)
|
|
99
|
+
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
100
|
+
|
|
101
|
+
return this.handleResult(op, res, spec, (json)=>{
|
|
102
|
+
this.data = json
|
|
103
|
+
return null
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
async list(query) {
|
|
109
|
+
const op = 'list'
|
|
110
|
+
// TODO: use query if defined
|
|
111
|
+
|
|
112
|
+
const spec = this.sdk().fetchSpec(op,this)
|
|
113
|
+
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
114
|
+
|
|
115
|
+
return this.handleResult(op, res, spec, (json)=>{
|
|
116
|
+
return json.list.map(data=>this.sdk().${entity.Name}(data))
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
${entity.Name}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
`)
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
export {
|
|
134
|
+
Entity
|
|
135
|
+
}
|
|
@@ -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}(self,data)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
`)
|
|
16
|
+
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
MainEntity
|
|
22
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { cmp, each, camelify, File, Content, Copy, Folder } from '@voxgig/sdkgen'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import { MainEntity } from './MainEntity_js'
|
|
7
|
+
import { Test } from './Test_js'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const Main = cmp(async function Main(props: any) {
|
|
11
|
+
const { build } = props
|
|
12
|
+
const { model } = props.ctx$
|
|
13
|
+
|
|
14
|
+
const entity = model.main.sdk.entity
|
|
15
|
+
|
|
16
|
+
Copy({ from: 'tm/' + build.name + '/package.json', name: 'package.json' })
|
|
17
|
+
|
|
18
|
+
Test({ build })
|
|
19
|
+
|
|
20
|
+
Folder({ name: 'src' }, () => {
|
|
21
|
+
|
|
22
|
+
File({ name: model.Name + 'SDK.' + build.name }, () => {
|
|
23
|
+
|
|
24
|
+
Content(`
|
|
25
|
+
// ${model.Name} ${build.Name} SDK
|
|
26
|
+
`)
|
|
27
|
+
|
|
28
|
+
each(entity, (entity: any) => {
|
|
29
|
+
entity.Name = camelify(entity.name)
|
|
30
|
+
Content(`
|
|
31
|
+
const { ${entity.Name} } = require('./${entity.Name}')
|
|
32
|
+
`)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const validate_options = each(build.options)
|
|
37
|
+
.reduce((a: string, opt: any) =>
|
|
38
|
+
a + ('String' === opt.kind ?
|
|
39
|
+
` required('string','${opt.name}',options)\n` : ''), '')
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Content(`
|
|
43
|
+
|
|
44
|
+
class ${model.Name}SDK {
|
|
45
|
+
options
|
|
46
|
+
|
|
47
|
+
static make(options) {
|
|
48
|
+
return new ${model.Name}SDK(options)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
constructor(options) {
|
|
53
|
+
this.options = options
|
|
54
|
+
|
|
55
|
+
${validate_options}
|
|
56
|
+
|
|
57
|
+
this.options.fetch = this.options.fetch || fetch
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
endpoint(op,ent) {
|
|
62
|
+
let data = ent.data || {}
|
|
63
|
+
let def = ent.def
|
|
64
|
+
// Make this code depend on openapi spec
|
|
65
|
+
return this.options.endpoint + '/' + def.name + ((op === 'load' || op === 'remove') && data.id ? '/' + data.id : '')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
method(op,ent) {
|
|
69
|
+
let key = (null == ent || null === ent.id) && 'save' === op ? 'create' : op
|
|
70
|
+
return ({
|
|
71
|
+
create: 'POST',
|
|
72
|
+
save: 'PUT',
|
|
73
|
+
load: 'GET',
|
|
74
|
+
list: 'GET',
|
|
75
|
+
remove: 'DELETE',
|
|
76
|
+
})[op]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
body(op,ent) {
|
|
80
|
+
const msg = { ...ent.data }
|
|
81
|
+
return JSON.stringify(msg)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fetchSpec(op,ent) {
|
|
85
|
+
const method = this.method(op, ent)
|
|
86
|
+
const spec = {
|
|
87
|
+
url: this.endpoint(op, ent),
|
|
88
|
+
method,
|
|
89
|
+
headers: {
|
|
90
|
+
'content-type': 'application/json',
|
|
91
|
+
'authorization': 'Bearer '+this.options.apikey
|
|
92
|
+
},
|
|
93
|
+
body: 'GET' === method || 'DELETE' === method ? undefined : this.body(op, ent),
|
|
94
|
+
}
|
|
95
|
+
return spec
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
`)
|
|
99
|
+
|
|
100
|
+
each(entity, (entity: any) => {
|
|
101
|
+
MainEntity({ model, build, entity })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
Content(`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
function required(type,name,options) {
|
|
109
|
+
const val = options[name]
|
|
110
|
+
if(type !== typeof val) {
|
|
111
|
+
throw new Error('${model.Name}SDK: Invalid option: '+name+'='+val+': must be of type '+type)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
${model.Name}SDK
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
`)
|
|
120
|
+
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
Main
|
|
128
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
import { names, getx, cmp, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Quick = cmp(function Quick(props: any) {
|
|
6
|
+
const { build } = props
|
|
7
|
+
const { model, meta: { spec } } = props.ctx$
|
|
8
|
+
|
|
9
|
+
// get quick entity from build config
|
|
10
|
+
|
|
11
|
+
// console.log('CONFIG 2')
|
|
12
|
+
// console.dir(spec.config, { depth: null })
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const ent = getx(spec.config, 'entity *').find((ent: any) => ent.test.quick.active)
|
|
16
|
+
names(ent, ent.key$)
|
|
17
|
+
|
|
18
|
+
console.log('ENT 3', ent)
|
|
19
|
+
|
|
20
|
+
File({ name: 'quick.' + build.name }, () => {
|
|
21
|
+
|
|
22
|
+
Content(`
|
|
23
|
+
// ENT 3
|
|
24
|
+
require('dotenv').config({ path: ['../../.env.local']})
|
|
25
|
+
|
|
26
|
+
const { ${model.Name}SDK } = require('../')
|
|
27
|
+
|
|
28
|
+
run()
|
|
29
|
+
|
|
30
|
+
async function run() {
|
|
31
|
+
const client = ${model.Name}SDK.make({
|
|
32
|
+
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
33
|
+
apikey: process.env.${model.NAME}_APIKEY,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
let out
|
|
37
|
+
|
|
38
|
+
`)
|
|
39
|
+
|
|
40
|
+
if (ent.test.quick.create) {
|
|
41
|
+
Content(`
|
|
42
|
+
out = await client.${ent.Name}().create(${JSON.stringify(ent.test.quick.create)})
|
|
43
|
+
console.log('${ent.Name}.load', out)
|
|
44
|
+
`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (ent.test.quick.load) {
|
|
48
|
+
Content(`
|
|
49
|
+
out = await client.${ent.Name}().load(${JSON.stringify(ent.test.quick.load)})
|
|
50
|
+
console.log('${ent.Name}.load', out)
|
|
51
|
+
`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (ent.test.quick.list) {
|
|
55
|
+
Content(`
|
|
56
|
+
out = await client.${ent.Name}().list(${JSON.stringify(ent.test.quick.list)})
|
|
57
|
+
console.log('${ent.Name}.list', out)
|
|
58
|
+
`)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Content(`
|
|
62
|
+
}
|
|
63
|
+
`)
|
|
64
|
+
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
Quick
|
|
71
|
+
}
|
|
72
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeInstall = cmp(function ReadmeInstall(props: any) {
|
|
6
|
+
const { build } = props
|
|
7
|
+
|
|
8
|
+
Content('```js')
|
|
9
|
+
Content(`
|
|
10
|
+
npm install ${build.module.name}
|
|
11
|
+
`)
|
|
12
|
+
Content('```')
|
|
13
|
+
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ReadmeInstall
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
6
|
+
const { build, ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
Content('```js')
|
|
9
|
+
Content(`
|
|
10
|
+
const { ${model.Name}SDK } = require('${build.module.name}')
|
|
11
|
+
|
|
12
|
+
const client = ${model.Name}SDK.make({
|
|
13
|
+
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
14
|
+
apikey: process.env.${model.NAME}_APIKEY,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
let buildings = await client.Building().list()
|
|
18
|
+
console.log('Buildings', buildings)
|
|
19
|
+
`)
|
|
20
|
+
Content('```')
|
|
21
|
+
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
ReadmeQuick
|
|
27
|
+
}
|
|
@@ -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 { build } = props
|
|
10
|
+
const { model } = props.ctx$
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
File({ name: model.Name + 'SDK.accept.test.' + build.name }, () => {
|
|
14
|
+
|
|
15
|
+
Content(`
|
|
16
|
+
const { test, describe } = require('node:test')
|
|
17
|
+
const { equal, deepEqual } = require('node:assert')
|
|
18
|
+
|
|
19
|
+
const { ${model.Name}SDK } = require('../../')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
describe('${model.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, build, entity })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Content(`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function makeClient(config) {
|
|
42
|
+
const client = ${model.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,123 @@
|
|
|
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 { build } = props
|
|
10
|
+
const { model } = props.ctx$
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
File({ name: model.Name + 'SDK.test.' + build.name }, () => {
|
|
14
|
+
|
|
15
|
+
Content(`
|
|
16
|
+
|
|
17
|
+
// 1
|
|
18
|
+
|
|
19
|
+
const { test, describe } = require('node:test')
|
|
20
|
+
const { equal, deepEqual } = require('node:assert')
|
|
21
|
+
|
|
22
|
+
const { ${model.Name}SDK } = require('../')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
describe('${model.Name}SDK Unit Tests', ()=>{
|
|
26
|
+
test('happy', async ()=>{
|
|
27
|
+
const client = makeClient()
|
|
28
|
+
const out = await client.Geofence().load({id:'gf01'})
|
|
29
|
+
console.log('Geofence-load', out)
|
|
30
|
+
equal(out.data.id,'gf01')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
`)
|
|
34
|
+
|
|
35
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
36
|
+
TestEntity({ model, build, entity })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Content(`
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
function makeClient(config) {
|
|
45
|
+
const client = ${model.Name}SDK.make({
|
|
46
|
+
endpoint: 'https://host/api/v1/rest/project_id/plant/stage',
|
|
47
|
+
apikey: 'apikey',
|
|
48
|
+
fetch,
|
|
49
|
+
...config
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return client
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function fetch(url, config) {
|
|
56
|
+
const parts = url.split('/')
|
|
57
|
+
const entname = parts[9]
|
|
58
|
+
const entid = parts[10]
|
|
59
|
+
const data = JSON.parse(config.body||'{}')
|
|
60
|
+
const method = config.method || 'GET'
|
|
61
|
+
|
|
62
|
+
const req$ = {
|
|
63
|
+
url,
|
|
64
|
+
parts,
|
|
65
|
+
entname,
|
|
66
|
+
entid,
|
|
67
|
+
method,
|
|
68
|
+
data,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log('REQ', req$)
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
req$,
|
|
75
|
+
status: 200,
|
|
76
|
+
json: async function() {
|
|
77
|
+
if('PUT'=== method||'POST'===method) {
|
|
78
|
+
return entid ? {
|
|
79
|
+
id: entid,
|
|
80
|
+
title: data.title,
|
|
81
|
+
} :
|
|
82
|
+
{
|
|
83
|
+
id: 'n01',
|
|
84
|
+
title: data.title || 'T01',
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if('GET'===method) {
|
|
88
|
+
return entid ? {
|
|
89
|
+
id: entid,
|
|
90
|
+
title: 'T01'
|
|
91
|
+
} :
|
|
92
|
+
{
|
|
93
|
+
name: entname,
|
|
94
|
+
list: [
|
|
95
|
+
{
|
|
96
|
+
id: 'n01',
|
|
97
|
+
title: 'N01'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 'n01',
|
|
101
|
+
title: 'N01'
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return {}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
`)
|
|
115
|
+
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
TestMain
|
|
122
|
+
}
|
|
123
|
+
|