@voxgig/create-sdkgen 0.0.2 → 0.0.5
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 +73 -12
- package/dist/create-sdkgen.d.ts +5 -2
- package/dist/create-sdkgen.js +10 -2
- package/dist/create-sdkgen.js.map +1 -1
- package/dist/standard/ModelSdk.js +21 -14
- package/dist/standard/ModelSdk.js.map +1 -1
- package/dist/standard/Root.js +13 -47
- package/dist/standard/Root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -7
- package/src/create-sdkgen.ts +21 -4
- package/src/standard/ModelSdk.ts +30 -15
- package/src/standard/Root.ts +15 -54
- package/tm/standard/.env.local +2 -0
- package/tm/standard/build/doc.js +23 -0
- package/tm/standard/build/sdk.js +22 -0
- package/tm/standard/def/DEFINITION.md +4 -0
- package/tm/standard/model/.model-config/model-config.jsonic +15 -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/package.json +31 -0
- package/tm/standard/src/DocStaticRoot.ts +32 -0
- package/tm/standard/src/Root.ts +62 -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 +196 -0
- package/tm/standard/src/js/MainEntity_js.ts +22 -0
- package/tm/standard/src/js/Main_js.ts +154 -0
- package/tm/standard/src/js/Quick_js.ts +81 -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
- package/src/standard/Root.ts~ +0 -3
- /package/{src/standard/ModelSdk.ts~ → bin/run-create-sdkgen.js~} +0 -0
|
@@ -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
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
import { Quick } from './Quick_js'
|
|
5
|
+
import { TestMain } from './TestMain_js'
|
|
6
|
+
import { TestAccept } from './TestAccept_js'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const Test = cmp(function Test(props: any) {
|
|
10
|
+
const { build } = props
|
|
11
|
+
|
|
12
|
+
Folder({ name: 'test' }, () => {
|
|
13
|
+
Quick({ build })
|
|
14
|
+
TestMain({ build })
|
|
15
|
+
Folder({ name: 'accept' }, () => {
|
|
16
|
+
TestAccept({ build })
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
Test
|
|
24
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Entity = cmp(function Entity(props: any) {
|
|
6
|
+
const { build, entity } = props
|
|
7
|
+
const { model } = props.ctx$
|
|
8
|
+
|
|
9
|
+
entity.name = entity.Name.toLowerCase()
|
|
10
|
+
|
|
11
|
+
Folder({ name: 'src' }, () => {
|
|
12
|
+
|
|
13
|
+
File({ name: entity.Name + '.' + build.name }, () => {
|
|
14
|
+
|
|
15
|
+
Content(`<?php
|
|
16
|
+
// ${model.Name} ${build.Name} ${entity.Name}
|
|
17
|
+
|
|
18
|
+
class ${entity.Name} {
|
|
19
|
+
private $sdk;
|
|
20
|
+
private $data = [];
|
|
21
|
+
|
|
22
|
+
public function __construct($sdk, $data = []) {
|
|
23
|
+
$this->sdk = $sdk;
|
|
24
|
+
$this->data = $data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private function handleResult($op, $response, $handler) {
|
|
28
|
+
$statusContent = $response['status'];
|
|
29
|
+
|
|
30
|
+
if ($statusContent == 200) {
|
|
31
|
+
$json = $response['json'];
|
|
32
|
+
return $handler($json);
|
|
33
|
+
} else {
|
|
34
|
+
throw new Exception('HTTP-ERROR: ' . $op . ': ${entity.name}: ' . $statusContent);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public function save($data) {
|
|
39
|
+
$op = 'save';
|
|
40
|
+
$this->data = $data;
|
|
41
|
+
|
|
42
|
+
$spec = $this->sdk->fetchSpec($op, $this->data, $this->def);
|
|
43
|
+
$response = $this->sdk->fetch($spec['url'], $spec);
|
|
44
|
+
|
|
45
|
+
return $this->handleResult($op, $response, function($json) {
|
|
46
|
+
$this->data = $json['ent'];
|
|
47
|
+
return $this;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public function load($data) {
|
|
52
|
+
$op = 'load';
|
|
53
|
+
$this->data = $data;
|
|
54
|
+
|
|
55
|
+
$spec = $this->sdk->fetchSpec($op, $this->data, $this->def);
|
|
56
|
+
$response = $this->sdk->fetch($spec['url'], $spec);
|
|
57
|
+
|
|
58
|
+
return $this->handleResult($op, $response, function($json) {
|
|
59
|
+
$this->data = $json;
|
|
60
|
+
return $this;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public function list($data = []) {
|
|
65
|
+
$op = 'list';
|
|
66
|
+
$this->data = $data;
|
|
67
|
+
|
|
68
|
+
$spec = $this->sdk->fetchSpec($op, $this->data, $this->def);
|
|
69
|
+
$response = $this->sdk->fetch($spec['url'], $spec);
|
|
70
|
+
|
|
71
|
+
return $this->handleResult($op, $response, function($json) {
|
|
72
|
+
$this->data = $json;
|
|
73
|
+
return $this;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public function remove($data) {
|
|
78
|
+
$op = 'remove';
|
|
79
|
+
$this->data = $data;
|
|
80
|
+
|
|
81
|
+
$spec = $this->sdk->fetchSpec($op, $this->data, $this->def);
|
|
82
|
+
$response = $this->sdk->fetch($spec['url'], $spec);
|
|
83
|
+
|
|
84
|
+
return $this->handleResult($op, $response, function($json) {
|
|
85
|
+
$this->data = $json;
|
|
86
|
+
return $this;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`)
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
export {
|
|
96
|
+
Entity
|
|
97
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const MainEntity = cmp(function MainEntity(props: any) {
|
|
6
|
+
const { build, entity, model } = props
|
|
7
|
+
|
|
8
|
+
Folder({ name: 'src' }, () => {
|
|
9
|
+
|
|
10
|
+
File({ name: entity.Name + 'Main.' + build.name }, () => {
|
|
11
|
+
|
|
12
|
+
Content(`<?php
|
|
13
|
+
// ${model.Name} ${build.Name} ${entity.Name} Main
|
|
14
|
+
|
|
15
|
+
require_once __DIR__ . '../../sdk/php/src/${model.Name}SDK.php';
|
|
16
|
+
require_once __DIR__ . '../../sdk/php/src/${entity.Name}.php';
|
|
17
|
+
|
|
18
|
+
use ${model.Name}SDK\\${model.Name}SDK;
|
|
19
|
+
use ${model.Name}SDK\\${entity.Name};
|
|
20
|
+
|
|
21
|
+
// Initialize the SDK
|
|
22
|
+
\$options = [
|
|
23
|
+
'apikey' => 'your_api_key',
|
|
24
|
+
'endpoint' => 'https://api.${model.name}.com'
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
\$sdk = new ${model.Name}SDK(\$options);
|
|
28
|
+
|
|
29
|
+
// Example usage
|
|
30
|
+
\$${entity.Name.toLowerCase()} = new ${entity.Name}(\$sdk);
|
|
31
|
+
\$${entity.Name.toLowerCase()}->save(['name' => 'New ${entity.Name}']);
|
|
32
|
+
\$${entity.Name.toLowerCase()}->load(['id' => '123']);
|
|
33
|
+
\$${entity.Name.toLowerCase()}->list();
|
|
34
|
+
\$${entity.Name.toLowerCase()}->remove(['id' => '123']);
|
|
35
|
+
|
|
36
|
+
?>`)
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
MainEntity
|
|
43
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Main = cmp(function Main(props: any) {
|
|
6
|
+
const { build, model } = props
|
|
7
|
+
|
|
8
|
+
Folder({ name: 'src' }, () => {
|
|
9
|
+
|
|
10
|
+
File({ name: 'Main.' + build.name }, () => {
|
|
11
|
+
|
|
12
|
+
Content(`<?php
|
|
13
|
+
// ${model.Name} Main
|
|
14
|
+
|
|
15
|
+
require_once __DIR__ . '../../sdk/php/src/${model.Name}SDK.php';
|
|
16
|
+
require_once __DIR__ . '../../sdk/php/src/Asset.php';
|
|
17
|
+
require_once __DIR__ . '../../sdk/php/src/Geofence.php';
|
|
18
|
+
require_once __DIR__ . '../../sdk/php/src/Room.php';
|
|
19
|
+
|
|
20
|
+
use ${model.Name}SDK\\${model.Name}SDK;
|
|
21
|
+
use ${model.Name}SDK\\Asset;
|
|
22
|
+
use ${model.Name}SDK\\Geofence;
|
|
23
|
+
use ${model.Name}SDK\\Room;
|
|
24
|
+
|
|
25
|
+
// Initialize the SDK
|
|
26
|
+
\$options = [
|
|
27
|
+
'apikey' => 'your_api_key',
|
|
28
|
+
'endpoint' => 'https://api.${model.name}.com'
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
\$sdk = new ${model.Name}SDK(\$options);
|
|
32
|
+
|
|
33
|
+
// Example usage
|
|
34
|
+
\$asset = new Asset(\$sdk);
|
|
35
|
+
\$asset->save(['name' => 'New Asset']);
|
|
36
|
+
|
|
37
|
+
\$geofence = new Geofence(\$sdk);
|
|
38
|
+
\$geofence->save(['name' => 'New Geofence']);
|
|
39
|
+
|
|
40
|
+
\$room = new Room(\$sdk);
|
|
41
|
+
\$room->save(['name' => 'New Room']);
|
|
42
|
+
|
|
43
|
+
?>`)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
Main
|
|
50
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const Quick = cmp(function Quick(props: any) {
|
|
6
|
+
const { build, ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
Folder({ name: 'src' }, () => {
|
|
9
|
+
|
|
10
|
+
File({ name: 'QuickStart.' + build.name }, () => {
|
|
11
|
+
|
|
12
|
+
Content(`<?php
|
|
13
|
+
// ${model.Name} QuickStart
|
|
14
|
+
|
|
15
|
+
require_once __DIR__ . '../../sdk/php/src/${model.Name}SDK.php';
|
|
16
|
+
require_once __DIR__ . '../../sdk/php/src/Asset.php';
|
|
17
|
+
require_once __DIR__ . '../../sdk/php/src/Geofence.php';
|
|
18
|
+
require_once __DIR__ . '../../sdk/php/src/Room.php';
|
|
19
|
+
|
|
20
|
+
use ${model.Name}SDK\\${model.Name}SDK;
|
|
21
|
+
use ${model.Name}SDK\\Asset;
|
|
22
|
+
use ${model.Name}SDK\\Geofence;
|
|
23
|
+
use ${model.Name}SDK\\Room;
|
|
24
|
+
|
|
25
|
+
// Initialize the SDK
|
|
26
|
+
\$options = [
|
|
27
|
+
'apikey' => 'your_api_key',
|
|
28
|
+
'endpoint' => 'https://api.${model.name}.com'
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
\$sdk = new ${model.Name}SDK(\$options);
|
|
32
|
+
|
|
33
|
+
// Quick example usage
|
|
34
|
+
\$asset = new Asset(\$sdk);
|
|
35
|
+
\$asset->save(['name' => 'New Asset']);
|
|
36
|
+
\$asset->load(['id' => '123']);
|
|
37
|
+
\$asset->list();
|
|
38
|
+
\$asset->remove(['id' => '123']);
|
|
39
|
+
|
|
40
|
+
\$geofence = new Geofence(\$sdk);
|
|
41
|
+
\$geofence->save(['name' => 'New Geofence']);
|
|
42
|
+
\$geofence->load(['id' => '456']);
|
|
43
|
+
\$geofence->list();
|
|
44
|
+
\$geofence->remove(['id' => '456']);
|
|
45
|
+
|
|
46
|
+
\$room = new Room(\$sdk);
|
|
47
|
+
\$room->save(['name' => 'New Room']);
|
|
48
|
+
\$room->load(['id' => '789']);
|
|
49
|
+
\$room->list();
|
|
50
|
+
\$room->remove(['id' => '789']);
|
|
51
|
+
|
|
52
|
+
?>`)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
Quick
|
|
59
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { cmp, camelify, Content } from '@voxgig/sdkgen';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestAcceptEntity = cmp(function TestEntity(props: any) {
|
|
6
|
+
const { entity, ctx$: { model } } = props;
|
|
7
|
+
|
|
8
|
+
entity.Name = camelify(entity.name);
|
|
9
|
+
|
|
10
|
+
Content(`
|
|
11
|
+
<?php
|
|
12
|
+
use PHPUnit\\Framework\\TestCase;
|
|
13
|
+
use Dotenv\\Dotenv;
|
|
14
|
+
use ${model.Name}\\Client;
|
|
15
|
+
|
|
16
|
+
class Test${entity.Name}AcceptList extends TestCase {
|
|
17
|
+
|
|
18
|
+
protected function setUp(): void {
|
|
19
|
+
\$dotenv = Dotenv::createImmutable(__DIR__);
|
|
20
|
+
\$dotenv->load();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public function test${entity.Name}AcceptList() {
|
|
24
|
+
\$endpoint = getenv('${model.NAME}_ENDPOINT');
|
|
25
|
+
\$apikey = getenv('${model.NAME}_APIKEY');
|
|
26
|
+
|
|
27
|
+
\$client = new Client([
|
|
28
|
+
'endpoint' => \$endpoint,
|
|
29
|
+
'apikey' => \$apikey
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
\$entities = \$client->${entity.Name}()->list();
|
|
33
|
+
|
|
34
|
+
if (empty(\$entities)) {
|
|
35
|
+
\$this->fail("Error getting ${entity.name} accept list length == 0");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
\$got = \$entities[0]['data'];
|
|
39
|
+
|
|
40
|
+
if (empty(\$got['id'])) {
|
|
41
|
+
\$this->fail("Error getting ${entity.name} accept list - id equal to empty string");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class Test${entity.Name}AcceptLoad extends TestCase {
|
|
47
|
+
|
|
48
|
+
protected function setUp(): void {
|
|
49
|
+
\$dotenv = Dotenv::createImmutable(__DIR__);
|
|
50
|
+
\$dotenv->load();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public function test${entity.Name}AcceptLoad() {
|
|
54
|
+
\$endpoint = getenv('${model.NAME}_ENDPOINT');
|
|
55
|
+
\$apikey = getenv('${model.NAME}_APIKEY');
|
|
56
|
+
|
|
57
|
+
\$client = new Client([
|
|
58
|
+
'endpoint' => \$endpoint,
|
|
59
|
+
'apikey' => \$apikey
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
\$data = [
|
|
63
|
+
'id' => 't01'
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
\$${entity.name} = \$client->${entity.Name}()->load(\$data);
|
|
67
|
+
|
|
68
|
+
\$got = \$${entity.name}['data'];
|
|
69
|
+
|
|
70
|
+
if (empty(\$got['id'])) {
|
|
71
|
+
\$this->fail("Error getting ${entity.name} accept load - id equal to empty string");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
?>
|
|
76
|
+
`);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
TestAcceptEntity
|
|
81
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { TestAcceptEntity } from './TestAcceptEntity_php'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const TestAccept = cmp(function TestMain(props: any) {
|
|
8
|
+
const { build } = props;
|
|
9
|
+
const { model } = props.ctx$;
|
|
10
|
+
|
|
11
|
+
File({ name: model.name + 'sdk_accept_test.' + build.name }, () => {
|
|
12
|
+
Content(`
|
|
13
|
+
<?php
|
|
14
|
+
namespace ${model.name}_test;
|
|
15
|
+
|
|
16
|
+
use PHPUnit\\Framework\\TestCase;
|
|
17
|
+
use Dotenv\\Dotenv;
|
|
18
|
+
use ${model.Name}\\Client;
|
|
19
|
+
`);
|
|
20
|
+
|
|
21
|
+
each(model.main.sdk.entity, (entity: any) => {
|
|
22
|
+
TestAcceptEntity({ model, build, entity });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
Content(`
|
|
26
|
+
?>
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
TestAccept
|
|
33
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const TestEntity = cmp(function TestEntity(props: any) {
|
|
6
|
+
const { build, entity, ctx$: { model } } = props
|
|
7
|
+
|
|
8
|
+
Folder({ name: 'tests' }, () => {
|
|
9
|
+
|
|
10
|
+
File({ name: entity.Name + 'Test.' + build.name }, () => {
|
|
11
|
+
|
|
12
|
+
Content(`<?php
|
|
13
|
+
// ${model.Name} ${build.Name} ${entity.Name} Test
|
|
14
|
+
|
|
15
|
+
use PHPUnit\Framework\TestCase;
|
|
16
|
+
use ${model.Name}SDK\\${model.Name}SDK;
|
|
17
|
+
use ${model.Name}SDK\\${entity.Name};
|
|
18
|
+
|
|
19
|
+
class ${entity.Name}Test extends TestCase {
|
|
20
|
+
|
|
21
|
+
protected \$sdk;
|
|
22
|
+
protected \$${entity.Name.toLowerCase()};
|
|
23
|
+
|
|
24
|
+
protected function setUp(): void {
|
|
25
|
+
\$options = [
|
|
26
|
+
'apikey' => 'your_api_key',
|
|
27
|
+
'endpoint' => 'https://api.${model.name}.com'
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
\$this->sdk = new ${model.Name}SDK(\$options);
|
|
31
|
+
\$this->${entity.Name.toLowerCase()} = new ${entity.Name}(\$this->sdk);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public function testSave${entity.Name}() {
|
|
35
|
+
\$data = ['name' => 'Test ${entity.Name}'];
|
|
36
|
+
\$result = \$this->${entity.Name.toLowerCase()}->save(\$data);
|
|
37
|
+
\$this->assertEquals('Test ${entity.Name}', \$result->data['name']);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public function testLoad${entity.Name}() {
|
|
41
|
+
\$data = ['id' => '123'];
|
|
42
|
+
\$result = \$this->${entity.Name.toLowerCase()}->load(\$data);
|
|
43
|
+
\$this->assertEquals('123', \$result->data['id']);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public function testList${entity.Name}s() {
|
|
47
|
+
\$result = \$this->${entity.Name.toLowerCase()}->list();
|
|
48
|
+
\$this->assertIsArray(\$result->data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public function testRemove${entity.Name}() {
|
|
52
|
+
\$data = ['id' => '123'];
|
|
53
|
+
\$result = \$this->${entity.Name.toLowerCase()}->remove(\$data);
|
|
54
|
+
\$this->assertNull(\$result->data);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
?>`)
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
TestEntity
|
|
64
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { TestEntity } from './TestEntity_php'
|
|
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
|
+
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', ()=>{
|
|
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
|
+
TestEntity({ model, build, entity })
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Content(`
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function makeClient(config) {
|
|
42
|
+
const client = ${model.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
|
+
|