@voxgig/create-sdkgen 0.0.5 → 0.0.6
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-create-sdkgen +196 -0
- package/dist/create-sdkgen.d.ts +8 -8
- package/dist/create-sdkgen.js +60 -70
- package/dist/create-sdkgen.js.map +1 -1
- package/dist/standard/ModelSdk.js +7 -67
- package/dist/standard/ModelSdk.js.map +1 -1
- package/dist/standard/Root.js +54 -19
- package/dist/standard/Root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -10
- package/src/create-sdkgen.ts +50 -85
- package/src/standard/ModelSdk.ts +8 -85
- package/src/standard/Root.ts +22 -25
- package/bin/run-create-sdkgen.js +0 -330
- package/bin/run-create-sdkgen.js~ +0 -1
- package/src/utility.ts +0 -8
- package/tm/standard/.env.local +0 -2
- package/tm/standard/build/doc.js +0 -23
- package/tm/standard/build/sdk.js +0 -22
- package/tm/standard/def/DEFINITION.md +0 -4
- package/tm/standard/model/.model-config/model-config.jsonic +0 -15
- package/tm/standard/model/go.jsonic +0 -6
- package/tm/standard/model/js.jsonic +0 -6
- package/tm/standard/model/php.jsonic +0 -6
- package/tm/standard/model/py.jsonic +0 -7
- package/tm/standard/model/rb.jsonic +0 -6
- package/tm/standard/package.json +0 -31
- package/tm/standard/src/DocStaticRoot.ts +0 -32
- package/tm/standard/src/Root.ts +0 -62
- package/tm/standard/src/go/Entity_go.ts +0 -226
- package/tm/standard/src/go/MainEntity_go.ts +0 -26
- package/tm/standard/src/go/Main_go.ts +0 -168
- package/tm/standard/src/go/Quick_go.ts +0 -108
- package/tm/standard/src/go/ReadmeInstall_go.ts +0 -19
- package/tm/standard/src/go/ReadmeQuick_go.ts +0 -45
- package/tm/standard/src/go/TestAcceptEntity_go.ts +0 -219
- package/tm/standard/src/go/TestAccept_go.ts +0 -38
- package/tm/standard/src/go/TestEntity_go.ts +0 -79
- package/tm/standard/src/go/TestMain_go.ts +0 -61
- package/tm/standard/src/go/Test_go.ts +0 -20
- package/tm/standard/src/js/Entity_js.ts +0 -196
- package/tm/standard/src/js/MainEntity_js.ts +0 -22
- package/tm/standard/src/js/Main_js.ts +0 -154
- package/tm/standard/src/js/Quick_js.ts +0 -81
- package/tm/standard/src/js/ReadmeInstall_js.ts +0 -19
- package/tm/standard/src/js/ReadmeQuick_js.ts +0 -27
- package/tm/standard/src/js/TestAcceptEntity_js.ts +0 -101
- package/tm/standard/src/js/TestAccept_js.ts +0 -60
- package/tm/standard/src/js/TestEntity_js.ts +0 -24
- package/tm/standard/src/js/TestMain_js.ts +0 -123
- package/tm/standard/src/js/Test_js.ts +0 -24
- package/tm/standard/src/php/Entity_php.ts +0 -97
- package/tm/standard/src/php/MainEntity_php.ts +0 -43
- package/tm/standard/src/php/Main_php.ts +0 -50
- package/tm/standard/src/php/Quick_php.ts +0 -59
- package/tm/standard/src/php/TestAcceptEntity_php.ts +0 -81
- package/tm/standard/src/php/TestAccept_php.ts +0 -33
- package/tm/standard/src/php/TestEntity_php.ts +0 -64
- package/tm/standard/src/php/TestMain_php.ts +0 -120
- package/tm/standard/src/php/Test_php.ts +0 -21
- package/tm/standard/src/py/Entity_py.ts +0 -98
- package/tm/standard/src/py/MainEntity_py.ts +0 -19
- package/tm/standard/src/py/Main_py.ts +0 -211
- package/tm/standard/src/py/Quick_py.ts +0 -133
- package/tm/standard/src/py/TestAcceptEntity_py.ts +0 -47
- package/tm/standard/src/py/TestAccept_py.ts +0 -77
- package/tm/standard/src/py/TestEntity_py.ts +0 -50
- package/tm/standard/src/py/TestMain_py.ts +0 -103
- package/tm/standard/src/py/Test_py.ts +0 -28
- package/tm/standard/src/rb/Client_rb.ts +0 -142
- package/tm/standard/src/rb/Entity_rb.ts +0 -153
- package/tm/standard/src/rb/Error_rb.ts +0 -56
- package/tm/standard/src/rb/MainEntity_rb.ts +0 -16
- package/tm/standard/src/rb/Main_rb.ts +0 -55
- package/tm/standard/src/rb/Quick_rb.ts +0 -65
- package/tm/standard/src/rb/ReadmeInstall_rb.ts +0 -19
- package/tm/standard/src/rb/ReadmeQuick_rb.ts +0 -30
- package/tm/standard/src/rb/TestAcceptEntity_rb.ts +0 -83
- package/tm/standard/src/rb/TestAccept_rb.ts +0 -45
- package/tm/standard/src/rb/TestEntity_rb.ts +0 -82
- package/tm/standard/src/rb/TestMain_rb.ts +0 -67
- package/tm/standard/src/rb/Test_rb.ts +0 -27
- package/tm/standard/src/tsconfig.json +0 -15
- package/tm/standard/tm/go/.env.example +0 -2
- package/tm/standard/tm/go/LICENSE +0 -22
- package/tm/standard/tm/go/go.mod +0 -5
- package/tm/standard/tm/go/go.sum +0 -2
- package/tm/standard/tm/js/LICENSE +0 -22
- package/tm/standard/tm/js/package.json +0 -17
- package/tm/standard/tm/php/LICENSE +0 -22
- package/tm/standard/tm/py/LICENSE +0 -22
- package/tm/standard/tm/py/MANIFEST.in +0 -4
- package/tm/standard/tm/py/Makefile +0 -14
- package/tm/standard/tm/py/pyproject.toml +0 -4
- package/tm/standard/tm/py/pytest.ini +0 -3
- package/tm/standard/tm/py/requirements.txt +0 -4
- package/tm/standard/tm/py/setup.cfg +0 -2
- package/tm/standard/tm/py/setup.py +0 -82
- package/tm/standard/tm/rb/.rspec +0 -1
- package/tm/standard/tm/rb/Gemfile +0 -21
- package/tm/standard/tm/rb/LICENSE +0 -22
- package/tm/standard/tm/rb/Rakefile +0 -6
- package/tm/standard/tm/rb/spec/spec_helper.rb +0 -22
- package/tm/standard/tm/rb/tm.gemspec +0 -39
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
import { Quick } from './Quick_php'
|
|
5
|
-
import { TestMain } from './TestMain_php'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Test = cmp(function Test(props: any) {
|
|
9
|
-
const { build } = props
|
|
10
|
-
|
|
11
|
-
Folder({ name: 'test' }, () => {
|
|
12
|
-
|
|
13
|
-
Quick({ build })
|
|
14
|
-
TestMain({ build })
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
Test
|
|
21
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Entity = cmp(function Entity(props: any) {
|
|
6
|
-
const { build, entity } = props
|
|
7
|
-
const { model } = props.ctx$
|
|
8
|
-
|
|
9
|
-
// console.log('build.name: ', entity.Name, build.name)
|
|
10
|
-
|
|
11
|
-
Folder({ name: 'src/' + model.name + '_sdk' }, () => {
|
|
12
|
-
|
|
13
|
-
File({ name: entity.Name + '.' + build.extension }, () => {
|
|
14
|
-
|
|
15
|
-
Content(`
|
|
16
|
-
|
|
17
|
-
# from pydantic import BaseModel
|
|
18
|
-
# from .Model import Data
|
|
19
|
-
|
|
20
|
-
# ${model.Name} ${build.Name} ${entity.Name}
|
|
21
|
-
|
|
22
|
-
class ${entity.Name}:
|
|
23
|
-
def __init__(self, sdk, data = {}):
|
|
24
|
-
self.sdk = sdk
|
|
25
|
-
self.definition = {
|
|
26
|
-
'name': '${entity.name}'
|
|
27
|
-
}
|
|
28
|
-
self.id = data.get('id') or ''
|
|
29
|
-
self.data = data
|
|
30
|
-
|
|
31
|
-
def handle_result(self, op, res, spec, handler):
|
|
32
|
-
status = res['status']
|
|
33
|
-
if(200 == status):
|
|
34
|
-
json = res['json']
|
|
35
|
-
|
|
36
|
-
return handler(json)
|
|
37
|
-
else:
|
|
38
|
-
raise Exception('HTTP-ERROR: ' + op + ' ${entity.name}: ' + str(status))
|
|
39
|
-
|
|
40
|
-
def create(self, data):
|
|
41
|
-
op = 'create'
|
|
42
|
-
self.data = data
|
|
43
|
-
# TODO: validate data
|
|
44
|
-
|
|
45
|
-
spec = self.sdk.fetchSpec(op, self)
|
|
46
|
-
res = self.sdk.options.fetch(spec['url'], spec)
|
|
47
|
-
|
|
48
|
-
return self.handle_result(op, res, spec, lambda json: json)
|
|
49
|
-
|
|
50
|
-
def save(self, data):
|
|
51
|
-
op = 'save'
|
|
52
|
-
self.data = data
|
|
53
|
-
# TODO: validate data
|
|
54
|
-
|
|
55
|
-
spec = self.sdk.fetchSpec(op, self)
|
|
56
|
-
res = self.sdk.options.fetch(spec['url'], spec)
|
|
57
|
-
|
|
58
|
-
return self.handle_result(op, res, spec, lambda json: json)
|
|
59
|
-
|
|
60
|
-
def load(self, data):
|
|
61
|
-
op = 'load'
|
|
62
|
-
self.data = data
|
|
63
|
-
# TODO: validate data
|
|
64
|
-
|
|
65
|
-
spec = self.sdk.fetchSpec(op, self)
|
|
66
|
-
res = self.sdk.options.fetch(spec['url'], spec)
|
|
67
|
-
|
|
68
|
-
return self.handle_result(op, res, spec, lambda json: json)
|
|
69
|
-
|
|
70
|
-
def list(self, data = {}):
|
|
71
|
-
op = 'list'
|
|
72
|
-
self.data = data
|
|
73
|
-
# TODO: validate data
|
|
74
|
-
|
|
75
|
-
spec = self.sdk.fetchSpec(op, self)
|
|
76
|
-
res = self.sdk.options.fetch(spec['url'], spec)
|
|
77
|
-
|
|
78
|
-
return self.handle_result(op, res, spec, lambda json: json)
|
|
79
|
-
|
|
80
|
-
def remove(self, data):
|
|
81
|
-
op = 'remove'
|
|
82
|
-
self.data = data
|
|
83
|
-
# TODO: validate data
|
|
84
|
-
|
|
85
|
-
spec = self.sdk.fetchSpec(op, self)
|
|
86
|
-
res = self.sdk.options.fetch(spec['url'], spec)
|
|
87
|
-
|
|
88
|
-
return self.handle_result(op, res, spec, lambda json: json)
|
|
89
|
-
|
|
90
|
-
`)
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
export {
|
|
97
|
-
Entity
|
|
98
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const MainEntity = cmp(async function MainEntity(props: any) {
|
|
5
|
-
const { entity } = props
|
|
6
|
-
|
|
7
|
-
const def = JSON.stringify(entity)
|
|
8
|
-
|
|
9
|
-
Content(`
|
|
10
|
-
def ${entity.Name}(self):
|
|
11
|
-
return ${entity.Name}(self, json.loads('''${def}'''))
|
|
12
|
-
`)
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
MainEntity
|
|
19
|
-
}
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { cmp, each, camelify, File, Content, Folder, Copy } from '@voxgig/sdkgen'
|
|
4
|
-
|
|
5
|
-
import { MainEntity } from './MainEntity_py'
|
|
6
|
-
import { Test } from './Test_py'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const config_setup_files = [
|
|
10
|
-
'setup.py',
|
|
11
|
-
'pyproject.toml',
|
|
12
|
-
'requirements.txt',
|
|
13
|
-
'setup.cfg',
|
|
14
|
-
'MANIFEST.in',
|
|
15
|
-
'Makefile',
|
|
16
|
-
'pytest.ini'
|
|
17
|
-
]
|
|
18
|
-
|
|
19
|
-
const Main = cmp(async function Main(props: any) {
|
|
20
|
-
const { build, ctx$: { model } } = props
|
|
21
|
-
|
|
22
|
-
const entity = model.main.sdk.entity
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Test({ build })
|
|
26
|
-
|
|
27
|
-
for (let config_file of config_setup_files) {
|
|
28
|
-
Copy({ from: 'tm/' + build.name + '/' + config_file, name: config_file })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
File({ name: '.env.test.local' }, () => {
|
|
32
|
-
Content(`
|
|
33
|
-
${model.Name}_ENDPOINT=example.com
|
|
34
|
-
${model.Name}_ENDPOINT_PRISM=http://127.0.0.1:4010/a/b/c
|
|
35
|
-
${model.Name}_APIKEY=pqapikey
|
|
36
|
-
`)
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
Folder({ name: 'src/' + model.name + '_sdk' }, () => {
|
|
41
|
-
|
|
42
|
-
File({ name: '__init__.py' }, () => {
|
|
43
|
-
Content(`from .${model.Name}SDK import *
|
|
44
|
-
from .Model import Config
|
|
45
|
-
from .Model import Data
|
|
46
|
-
from .Model import Query
|
|
47
|
-
|
|
48
|
-
`)
|
|
49
|
-
|
|
50
|
-
each(entity, (entity: any) => {
|
|
51
|
-
entity.Name = camelify(entity.name)
|
|
52
|
-
// console.log('entity.Name: ', entity)
|
|
53
|
-
Content(`from .${entity.Name} import ${entity.Name}
|
|
54
|
-
`)
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
Content(`__doc__ = 'An example SDK'
|
|
59
|
-
`)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
File({ name: 'Model.py' }, () => {
|
|
65
|
-
Content(`
|
|
66
|
-
from typing import Any, Callable
|
|
67
|
-
|
|
68
|
-
from pydantic import BaseModel, Field, ConfigDict, ValidationError
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class Config(BaseModel):
|
|
72
|
-
endpoint: str = Field(validate_default=True)
|
|
73
|
-
apikey: str = Field(validate_default=True)
|
|
74
|
-
fetch: Callable = Field(validate_default=True)
|
|
75
|
-
|
|
76
|
-
model_config = ConfigDict(extra='allow')
|
|
77
|
-
|
|
78
|
-
class Data(BaseModel):
|
|
79
|
-
id: str = Field(default=None, validate_default=False)
|
|
80
|
-
model_config = ConfigDict(extra='allow')
|
|
81
|
-
|
|
82
|
-
class Query(BaseModel):
|
|
83
|
-
id: str = Field(default=None, validate_default=False)
|
|
84
|
-
model_config = ConfigDict(extra='allow')
|
|
85
|
-
|
|
86
|
-
`)
|
|
87
|
-
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
File({ name: model.Name + 'SDK.' + build.extension }, () => {
|
|
92
|
-
|
|
93
|
-
/*
|
|
94
|
-
const validate_options = each(build.options)
|
|
95
|
-
.reduce((a: string, opt: any) =>
|
|
96
|
-
a + ('String' === opt.kind ?
|
|
97
|
-
` required(str, '${opt.name}', options)\n` : ''), '')
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
const imports = `
|
|
101
|
-
import json
|
|
102
|
-
|
|
103
|
-
`
|
|
104
|
-
Content(`${imports}`)
|
|
105
|
-
|
|
106
|
-
each(entity, (entity: any) => {
|
|
107
|
-
entity.Name = camelify(entity.name)
|
|
108
|
-
Content(`from .${entity.Name} import ${entity.Name}
|
|
109
|
-
`)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
/*
|
|
114
|
-
// Replaced by pydantic
|
|
115
|
-
Content(`
|
|
116
|
-
def required(type_class, name, options):
|
|
117
|
-
val = options[name]
|
|
118
|
-
if(type_class != type(val)):
|
|
119
|
-
raise Exception('${model.Name}SDK: Invalid option: '+name+'='+val+': must be of type '+ str(type_class))
|
|
120
|
-
|
|
121
|
-
`)
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
Content(`
|
|
125
|
-
|
|
126
|
-
from pydantic import BaseModel
|
|
127
|
-
# from .Model import Data
|
|
128
|
-
|
|
129
|
-
# ${model.Name} ${build.Name} SDK
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
class ${model.Name}SDK:
|
|
133
|
-
def __init__(self, options):
|
|
134
|
-
self.options = options
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
@staticmethod
|
|
138
|
-
def make(options):
|
|
139
|
-
return ${model.Name}SDK(options)
|
|
140
|
-
|
|
141
|
-
def endpoint(self, op, ent):
|
|
142
|
-
data = ent.data
|
|
143
|
-
id = None
|
|
144
|
-
# print("ent.data: ", type(ent.data) == Data, isinstance(ent.data, Data), isinstance(ent.data, BaseModel))
|
|
145
|
-
if dict == type(ent.data):
|
|
146
|
-
id = ent.data.get('id')
|
|
147
|
-
elif isinstance(ent.data, BaseModel):
|
|
148
|
-
id = ent.data.id
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
self.options.endpoint
|
|
152
|
-
+ "/"
|
|
153
|
-
+ ent.definition.get("name")
|
|
154
|
-
+ ((id and (op == 'load' or op == 'delete') and "/" + id) or "")
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
def method(self, op, ent=None):
|
|
158
|
-
key = op
|
|
159
|
-
if (None == ent or None == ent.id) and "save" == op:
|
|
160
|
-
key = "create"
|
|
161
|
-
|
|
162
|
-
if "create" == key:
|
|
163
|
-
return "POST"
|
|
164
|
-
elif "save" == key:
|
|
165
|
-
return "PUT"
|
|
166
|
-
elif "load" == key or "list" == key:
|
|
167
|
-
return "GET"
|
|
168
|
-
elif "remove" == key:
|
|
169
|
-
return "DELETE"
|
|
170
|
-
|
|
171
|
-
def body(self, op, ent):
|
|
172
|
-
# msg = {}
|
|
173
|
-
# msg.update(ent.data)
|
|
174
|
-
# print('body ent.data: ', ent.data)
|
|
175
|
-
|
|
176
|
-
if dict == type(ent.data):
|
|
177
|
-
# return json.dumps(ent.data)
|
|
178
|
-
return ent.data
|
|
179
|
-
elif isinstance(ent.data, BaseModel):
|
|
180
|
-
return ent.data.model_dump(exclude_none=True)
|
|
181
|
-
# return ent.data.model_dump_json(exclude_none=True)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def fetchSpec(self, op, ent):
|
|
185
|
-
method = self.method(op, ent)
|
|
186
|
-
spec = {
|
|
187
|
-
"url": self.endpoint(op, ent),
|
|
188
|
-
"method": method,
|
|
189
|
-
"headers": {
|
|
190
|
-
"content-type": "application/json",
|
|
191
|
-
"authorization": "Bearer " + self.options.apikey,
|
|
192
|
-
},
|
|
193
|
-
"body": ("GET" == method and {}) or self.body(op, ent),
|
|
194
|
-
}
|
|
195
|
-
return spec
|
|
196
|
-
|
|
197
|
-
`)
|
|
198
|
-
|
|
199
|
-
each(entity, (entity: any) => {
|
|
200
|
-
MainEntity({ model, build, entity })
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
export {
|
|
210
|
-
Main
|
|
211
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, File, Content } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Quick = cmp(function Quick(props: any) {
|
|
6
|
-
const { build } = props
|
|
7
|
-
const { model } = props.ctx$
|
|
8
|
-
|
|
9
|
-
File({ name: 'quick.' + build.extension }, () => {
|
|
10
|
-
|
|
11
|
-
Content(`
|
|
12
|
-
from pathlib import Path
|
|
13
|
-
import sys
|
|
14
|
-
import json
|
|
15
|
-
|
|
16
|
-
import requests
|
|
17
|
-
from dotenv import dotenv_values
|
|
18
|
-
|
|
19
|
-
path_root = str(Path(__file__).parents[1]) + '/src' + '/${model.name}_sdk'
|
|
20
|
-
print('path_root: ', path_root)
|
|
21
|
-
sys.path.append(path_root)
|
|
22
|
-
|
|
23
|
-
import ${model.name}_sdk
|
|
24
|
-
import ${model.name}_sdk.Model as Model
|
|
25
|
-
from ${model.name}_sdk.Model import Data
|
|
26
|
-
from ${model.name}_sdk.Model import Query
|
|
27
|
-
|
|
28
|
-
# from Fetch import fetch
|
|
29
|
-
|
|
30
|
-
config = dotenv_values("../.env.test.local")
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
print("config: ", config, Model)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
print(${model.name}_sdk.${model.Name}SDK)
|
|
37
|
-
print(dir(${model.name}_sdk))
|
|
38
|
-
|
|
39
|
-
def fetch(url, config):
|
|
40
|
-
|
|
41
|
-
method = config.get('method') or 'GET'
|
|
42
|
-
headers = config.get('headers') or {}
|
|
43
|
-
body = config.get('body') or {}
|
|
44
|
-
|
|
45
|
-
res = None
|
|
46
|
-
|
|
47
|
-
if method == 'GET':
|
|
48
|
-
res = requests.get(url, headers=headers)
|
|
49
|
-
|
|
50
|
-
elif method == 'POST':
|
|
51
|
-
res = requests.post(url, headers=headers, json=body)
|
|
52
|
-
elif method == 'PUT':
|
|
53
|
-
res = requests.put(url, headers=headers, json=body)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if res.status_code >= 200 and res.status_code < 300:
|
|
57
|
-
return { "status": res.status_code, "json": res.json(), "res": res }
|
|
58
|
-
|
|
59
|
-
return { "status": res.status_code }
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if __name__ == "__main__":
|
|
63
|
-
client = ${model.name}_sdk.${model.Name}SDK.make(Model.Config(
|
|
64
|
-
endpoint=config.get('${model.NAME}_ENDPOINT_PRISM'),
|
|
65
|
-
apikey=config.get('${model.NAME}_APIKEY'),
|
|
66
|
-
fetch=fetch
|
|
67
|
-
))
|
|
68
|
-
|
|
69
|
-
# load
|
|
70
|
-
out = client.Geofence().load({"id": "CF49B47C-317B-4387-83C3-4A23715B1C45"})
|
|
71
|
-
print("Geofence.load", out)
|
|
72
|
-
|
|
73
|
-
# or
|
|
74
|
-
out = client.Geofence().load(Query(id="CF49B47C-317B-4387-83C3-4A23715B1C45"))
|
|
75
|
-
print("Geofence.load", out)
|
|
76
|
-
|
|
77
|
-
# list
|
|
78
|
-
out = client.Geofence().list()
|
|
79
|
-
print("Geofence.list: ", out)
|
|
80
|
-
|
|
81
|
-
# create
|
|
82
|
-
out = client.Geofence().create(Data(
|
|
83
|
-
id='CF49B47C-317B-4387-83C3-4A23715B1C45',
|
|
84
|
-
name='Geofence 1',
|
|
85
|
-
desc='Geofence 1 description',
|
|
86
|
-
custom={ 'foo': 'bar' },
|
|
87
|
-
extent_id='CF49B47C-317B-4387-83C3-4A23715B1C45'
|
|
88
|
-
))
|
|
89
|
-
|
|
90
|
-
print('Geofence.create: ', out)
|
|
91
|
-
|
|
92
|
-
# save
|
|
93
|
-
out = client.Geofence().save(Data(
|
|
94
|
-
id='CF49B47C-317B-4387-83C3-4A23715B1C45',
|
|
95
|
-
name='Geofence 1',
|
|
96
|
-
desc='Geofence 1 description',
|
|
97
|
-
custom={ 'foo': 'bar' },
|
|
98
|
-
extent_id='CF49B47C-317B-4387-83C3-4A23715B1C45'
|
|
99
|
-
))
|
|
100
|
-
|
|
101
|
-
print('Geofence.save: ', out)
|
|
102
|
-
|
|
103
|
-
'''
|
|
104
|
-
# create
|
|
105
|
-
out = client.Geofence().create(Data(
|
|
106
|
-
title="T04",
|
|
107
|
-
area=0,
|
|
108
|
-
))
|
|
109
|
-
print("Geofence.create: ", out)
|
|
110
|
-
|
|
111
|
-
# or
|
|
112
|
-
out = client.Geofence().create({
|
|
113
|
-
"title": "T05",
|
|
114
|
-
"area": 0
|
|
115
|
-
})
|
|
116
|
-
print("Geofence.create: ", out)
|
|
117
|
-
'''
|
|
118
|
-
|
|
119
|
-
# remove
|
|
120
|
-
out = client.Geofence().remove({"id": "CF49B47C-317B-4387-83C3-4A23715B1C45"})
|
|
121
|
-
print("Geofence.remove: ", out)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
`)
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
export {
|
|
132
|
-
Quick
|
|
133
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { cmp, camelify, Content } from '@voxgig/sdkgen'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const TestAcceptEntity = cmp(function TestAcceptEntity(props: any) {
|
|
5
|
-
const { entity } = props
|
|
6
|
-
|
|
7
|
-
entity.Name = camelify(entity.name)
|
|
8
|
-
|
|
9
|
-
Content(`
|
|
10
|
-
def test_${entity.name}_load():
|
|
11
|
-
config = dotenv_values('.env.test.local')
|
|
12
|
-
client = makeClient(config)
|
|
13
|
-
out = client.${entity.Name}().load({"id" :'t01'})
|
|
14
|
-
|
|
15
|
-
expectedFormat = {
|
|
16
|
-
'id': str,
|
|
17
|
-
'name': str,
|
|
18
|
-
'desc': str,
|
|
19
|
-
'custom': dict,
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
print('load', out)
|
|
23
|
-
|
|
24
|
-
for key in expectedFormat:
|
|
25
|
-
assert expectedFormat[key] == type(out[key])
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
`);
|
|
29
|
-
|
|
30
|
-
Content(`
|
|
31
|
-
def test_${entity.name}_list():
|
|
32
|
-
config = dotenv_values('.env.test.local')
|
|
33
|
-
client = makeClient(config)
|
|
34
|
-
out = client.${entity.Name}().list()
|
|
35
|
-
|
|
36
|
-
print('list', out)
|
|
37
|
-
assert out['name'] == '${entity.name}' and len(out['list']) > 0
|
|
38
|
-
|
|
39
|
-
`);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
TestAcceptEntity
|
|
47
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { TestAcceptEntity } from './TestAcceptEntity_py'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const TestAccept = cmp(function TestAccept(props: any) {
|
|
8
|
-
const { build } = props
|
|
9
|
-
const { model } = props.ctx$
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
File({ name: 'test_accept_' + model.Name + '.' + build.extension }, () => {
|
|
13
|
-
|
|
14
|
-
Content(`
|
|
15
|
-
from pathlib import Path
|
|
16
|
-
import sys
|
|
17
|
-
path_root = str(Path(__file__).parents[1])
|
|
18
|
-
sys.path.append(path_root)
|
|
19
|
-
|
|
20
|
-
import json
|
|
21
|
-
|
|
22
|
-
import requests
|
|
23
|
-
from dotenv import dotenv_values
|
|
24
|
-
|
|
25
|
-
import ${model.name}_sdk
|
|
26
|
-
|
|
27
|
-
from ${model.name}_sdk import Config
|
|
28
|
-
|
|
29
|
-
# from Fetch import fetch
|
|
30
|
-
|
|
31
|
-
def fetch(url, config):
|
|
32
|
-
|
|
33
|
-
method = config.get('method') or 'GET'
|
|
34
|
-
headers = config.get('headers') or {}
|
|
35
|
-
body = config.get('body') or {}
|
|
36
|
-
|
|
37
|
-
res = None
|
|
38
|
-
|
|
39
|
-
if method == 'GET':
|
|
40
|
-
res = requests.get(url, headers=headers)
|
|
41
|
-
elif method == 'POST':
|
|
42
|
-
res = requests.post(url, headers=headers, json=body)
|
|
43
|
-
elif method == 'PUT':
|
|
44
|
-
res = requests.put(url, headers=headers, json=body)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if res.status_code >= 200 and res.status_code < 300:
|
|
48
|
-
return { "status": res.status_code, "json": res.json(), "res": res }
|
|
49
|
-
|
|
50
|
-
return { "status": res.status_code }
|
|
51
|
-
|
|
52
|
-
def makeClient(config = {}):
|
|
53
|
-
client = ${model.name}_sdk.${model.Name}SDK.make(Config(
|
|
54
|
-
endpoint=config.get('${model.NAME}_ENDPOINT_PRISM'),
|
|
55
|
-
apikey=config.get('${model.NAME}_APIKEY') or 'abc123',
|
|
56
|
-
fetch=fetch
|
|
57
|
-
))
|
|
58
|
-
return client
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def test_happy():
|
|
62
|
-
config = dotenv_values('.env.test.local')
|
|
63
|
-
client = makeClient(config)
|
|
64
|
-
`)
|
|
65
|
-
|
|
66
|
-
each(model.main.sdk.entity, (entity: any) => {
|
|
67
|
-
TestAcceptEntity({ model, build, entity })
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
export {
|
|
75
|
-
TestAccept
|
|
76
|
-
}
|
|
77
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
// console.log(entity.op)
|
|
11
|
-
|
|
12
|
-
// TODO: refactor via loop
|
|
13
|
-
for (let key in entity.op) {
|
|
14
|
-
// console.log(key)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Content(`
|
|
18
|
-
def test_${entity.name}():
|
|
19
|
-
config = dotenv_values('.env.test.local')
|
|
20
|
-
client = makeClient(config)
|
|
21
|
-
|
|
22
|
-
# create
|
|
23
|
-
out = client.${entity.Name}().create({ 'title': 'T03' })
|
|
24
|
-
print('create', out)
|
|
25
|
-
assert out == {'id': 'n03', 'title': 'T03'}
|
|
26
|
-
|
|
27
|
-
# save
|
|
28
|
-
out = client.${entity.Name}().save({ 'id': 'n03', 'title': 'T03_3'})
|
|
29
|
-
print('save', out)
|
|
30
|
-
assert out == { 'id': 'n03', 'title': 'T03_3' }
|
|
31
|
-
|
|
32
|
-
# load
|
|
33
|
-
out = client.${entity.Name}().load({ 'id': 't01' })
|
|
34
|
-
print('load', out)
|
|
35
|
-
assert out == {'id': 't01', 'title': 'T01'}
|
|
36
|
-
|
|
37
|
-
# list
|
|
38
|
-
out = client.${entity.Name}().list()
|
|
39
|
-
assert out['list'] != None and len(out['list']) != 0
|
|
40
|
-
assert out['name'] == "${entity.name}"
|
|
41
|
-
print('list', out)
|
|
42
|
-
# raise Exception('4')
|
|
43
|
-
|
|
44
|
-
`)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export {
|
|
49
|
-
TestEntity
|
|
50
|
-
}
|