@voxgig/create-sdkgen 0.0.3 → 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 +11 -8
- package/dist/create-sdkgen.js +61 -63
- package/dist/create-sdkgen.js.map +1 -1
- package/dist/standard/ModelSdk.js +8 -61
- package/dist/standard/ModelSdk.js.map +1 -1
- package/dist/standard/Root.js +58 -57
- package/dist/standard/Root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -10
- package/src/create-sdkgen.ts +56 -74
- package/src/standard/ModelSdk.ts +9 -71
- package/src/standard/Root.ts +26 -68
- package/bin/run-create-sdkgen.js +0 -269
- package/bin/run-create-sdkgen.js~ +0 -1
- package/src/standard/ModelSdk.ts~ +0 -1
- package/src/standard/Root.ts~ +0 -3
- package/src/utility.ts +0 -8
- package/tm/standard/.env.local +0 -2
- package/tm/standard/build/sdk.js +0 -25
- package/tm/standard/def/DEFINITION.md +0 -2
- package/tm/standard/model/.model-config/model-config.jsonic +0 -13
- 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/model/sdk.jsonic.off +0 -60
- package/tm/standard/package.json +0 -30
- package/tm/standard/src/Root.ts +0 -60
- 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 -135
- package/tm/standard/src/js/MainEntity_js.ts +0 -22
- package/tm/standard/src/js/Main_js.ts +0 -128
- package/tm/standard/src/js/Quick_js.ts +0 -72
- 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,226 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, each, File, Content } 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
|
-
File({ name: entity.name + '.' + build.name }, () => {
|
|
10
|
-
const complexTypeMap: Record<string, string> = {
|
|
11
|
-
"custom": "map[string]any",
|
|
12
|
-
"xval": "float64",
|
|
13
|
-
"yval": "float64",
|
|
14
|
-
"zval": "float64",
|
|
15
|
-
"xlen": "int",
|
|
16
|
-
"ylen": "int",
|
|
17
|
-
"parent_xlen": "int",
|
|
18
|
-
"parent_xval": "float64",
|
|
19
|
-
"parent_xyangle": "float64",
|
|
20
|
-
"parent_ylen": "int",
|
|
21
|
-
"parent_yval": "float64",
|
|
22
|
-
"parent_zval": "float64",
|
|
23
|
-
"polygon": "struct{Points [][]float64}",
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const defaultTypeMap: Record<string, string> = {
|
|
27
|
-
"boolean": "bool",
|
|
28
|
-
"string": "string"
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
Content(`
|
|
32
|
-
// ${model.Name} ${build.Name} ${entity.Name}
|
|
33
|
-
|
|
34
|
-
package ${model.name}sdk
|
|
35
|
-
|
|
36
|
-
import (
|
|
37
|
-
"fmt"
|
|
38
|
-
"encoding/json"
|
|
39
|
-
"io"
|
|
40
|
-
"errors"
|
|
41
|
-
"net/http"
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
type ${entity.Name}Data struct {`)
|
|
45
|
-
each(entity.field, (field: any) => {
|
|
46
|
-
const type = complexTypeMap[field.name] ? complexTypeMap[field.name]
|
|
47
|
-
: defaultTypeMap[field.type]
|
|
48
|
-
Content(`
|
|
49
|
-
${field.Name} ${type} \`json:"${field.name}"\`
|
|
50
|
-
`)
|
|
51
|
-
})
|
|
52
|
-
Content(`
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type ${entity.Name} struct {
|
|
56
|
-
Data ${entity.Name}Data
|
|
57
|
-
def map[string]any
|
|
58
|
-
sdk func () *${model.name}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
func (e *${entity.Name}) reqSetup(op string, data ${entity.Name}Data) (*http.Request, error) {
|
|
62
|
-
e.Data = data
|
|
63
|
-
|
|
64
|
-
endpointConfig := endpointConfig{
|
|
65
|
-
op: op,
|
|
66
|
-
id: e.Data.Id,
|
|
67
|
-
name: e.def["name"].(string),
|
|
68
|
-
apiUrl: e.sdk().options.Endpoint,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fetchConfig := fetchConfig{
|
|
72
|
-
op: op,
|
|
73
|
-
url: endpoint(endpointConfig),
|
|
74
|
-
apikey: e.sdk().options.Apikey,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
spec, err := fetchSpec(fetchConfig, e.Data)
|
|
78
|
-
if err != nil {
|
|
79
|
-
return nil, err
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
req, err := http.NewRequest(spec.method, spec.url, spec.body)
|
|
83
|
-
if err != nil {
|
|
84
|
-
return nil, err
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
req.Header.Set("Content-Type", spec.contentType)
|
|
88
|
-
req.Header.Set("Authorization", spec.authorization)
|
|
89
|
-
|
|
90
|
-
return req, nil
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
func (e *${entity.Name}) handleResult(op string, res *http.Response,
|
|
94
|
-
handler func(${entity.Name}Data) *${entity.Name}) (*${entity.Name}, error) {
|
|
95
|
-
var result ${entity.Name}Data
|
|
96
|
-
status := res.StatusContent
|
|
97
|
-
|
|
98
|
-
if status == 200 {
|
|
99
|
-
resBody, err := io.ReadAll(res.Body)
|
|
100
|
-
if err != nil {
|
|
101
|
-
return nil, err
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if err = json.Unmarshal(resBody, &result); err != nil {
|
|
105
|
-
return nil, err
|
|
106
|
-
}
|
|
107
|
-
return handler(result), nil
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return nil, errors.New(fmt.Sprintf("HTTP-ERROR: %v: ${entity.name}: %v",
|
|
111
|
-
op, status))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
`)
|
|
115
|
-
each(entity.op, (op: any) => {
|
|
116
|
-
if (op.name == "list") {
|
|
117
|
-
Content(`
|
|
118
|
-
func (e *${entity.Name}) ${op.Name}() ([]*${entity.Name}, error) {
|
|
119
|
-
type entity${op.Name} struct {
|
|
120
|
-
${op.Name} []${entity.Name}Data
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
op := "${op.name}"
|
|
124
|
-
var entities []*${entity.Name}
|
|
125
|
-
|
|
126
|
-
endpointConfig := endpointConfig{
|
|
127
|
-
op: op,
|
|
128
|
-
id: e.Data.Id,
|
|
129
|
-
name: e.def["name"].(string),
|
|
130
|
-
apiUrl: e.sdk().options.Endpoint,
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
fetchConfig := fetchConfig{
|
|
134
|
-
op: op,
|
|
135
|
-
url: endpoint(endpointConfig),
|
|
136
|
-
apikey: e.sdk().options.Apikey,
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
spec, err := fetchSpec(fetchConfig, e.Data)
|
|
140
|
-
if err != nil {
|
|
141
|
-
return nil, err
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
req, err := http.NewRequest(spec.method, spec.url, spec.body)
|
|
145
|
-
if err != nil {
|
|
146
|
-
return nil, err
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
req.Header.Set("Content-Type", spec.contentType)
|
|
150
|
-
req.Header.Set("Authorization", spec.authorization)
|
|
151
|
-
|
|
152
|
-
res, err := e.sdk().httpClient.Do(req)
|
|
153
|
-
if err != nil {
|
|
154
|
-
return nil, err
|
|
155
|
-
}
|
|
156
|
-
defer res.Body.Close()
|
|
157
|
-
|
|
158
|
-
status := res.StatusContent
|
|
159
|
-
|
|
160
|
-
if status == 200 {
|
|
161
|
-
resBody, err := io.ReadAll(res.Body)
|
|
162
|
-
if err != nil {
|
|
163
|
-
return nil, err
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
var entity${op.Name} entity${op.Name}
|
|
167
|
-
if err = json.Unmarshal(resBody, &entity${op.Name}); err != nil {
|
|
168
|
-
return nil, err
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
for _, entityData := range entity${op.Name}.${op.Name} {
|
|
172
|
-
entity := e.sdk().${entity.Name}(entityData)
|
|
173
|
-
entities = append(entities, entity)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return entities, nil
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return nil, errors.New(fmt.Sprintf("HTTP-ERROR: %v: ${entity.name}: %v",
|
|
180
|
-
op, status))
|
|
181
|
-
}
|
|
182
|
-
`)
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
Content(`
|
|
186
|
-
func (e *${entity.Name}) ${op.Name}(data ${entity.Name}Data) (*${entity.Name}, error) {
|
|
187
|
-
op := "${op.name}"
|
|
188
|
-
|
|
189
|
-
req, err := e.reqSetup(op, data)
|
|
190
|
-
if err != nil {
|
|
191
|
-
return nil, err
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
res, err := e.sdk().httpClient.Do(req)
|
|
195
|
-
if err != nil {
|
|
196
|
-
return nil, err
|
|
197
|
-
}
|
|
198
|
-
defer res.Body.Close()
|
|
199
|
-
|
|
200
|
-
handler := func(data ${entity.Name}Data) *${entity.Name} {
|
|
201
|
-
e.Data = data
|
|
202
|
-
`)
|
|
203
|
-
if (op.name == "remove") {
|
|
204
|
-
Content(`
|
|
205
|
-
return nil
|
|
206
|
-
}
|
|
207
|
-
return e.handleResult(op, res, handler)
|
|
208
|
-
}
|
|
209
|
-
`)
|
|
210
|
-
return
|
|
211
|
-
}
|
|
212
|
-
Content(`
|
|
213
|
-
return e
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return e.handleResult(op, res, handler)
|
|
217
|
-
}
|
|
218
|
-
`)
|
|
219
|
-
});
|
|
220
|
-
})
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
export {
|
|
225
|
-
Entity
|
|
226
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, Content } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const MainEntity = cmp(async function MainEntity(props: any) {
|
|
6
|
-
const { model, entity } = props
|
|
7
|
-
|
|
8
|
-
Content(`
|
|
9
|
-
func (m *${model.name}) ${entity.Name}(data ...${entity.Name}Data) *${entity.Name} {
|
|
10
|
-
e := new (${entity.Name})
|
|
11
|
-
e.sdk = func () *${model.name} {return m}
|
|
12
|
-
if data != nil {
|
|
13
|
-
e.Data = data[0]
|
|
14
|
-
}
|
|
15
|
-
e.def = map[string]any{
|
|
16
|
-
"name": "${entity.name}",
|
|
17
|
-
}
|
|
18
|
-
return e
|
|
19
|
-
}
|
|
20
|
-
`)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
MainEntity
|
|
26
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, each, camelify, File, Content, Copy } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
import { MainEntity } from './MainEntity_go'
|
|
5
|
-
import { Test } from './Test_go'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Main = cmp(async function Main(props: any) {
|
|
9
|
-
const { build } = props
|
|
10
|
-
const { model } = props.ctx$
|
|
11
|
-
|
|
12
|
-
const entity = model.main.sdk.entity
|
|
13
|
-
const options = build.options
|
|
14
|
-
|
|
15
|
-
Copy({ from: 'tm/' + build.name + '/.env.example', name: '.env.example' })
|
|
16
|
-
Copy({ from: 'tm/' + build.name + '/go.mod', name: 'go.mod' })
|
|
17
|
-
Copy({ from: 'tm/' + build.name + '/go.sum', name: 'go.sum' })
|
|
18
|
-
Test({ build })
|
|
19
|
-
File({ name: model.name + 'sdk.' + build.name }, () => {
|
|
20
|
-
|
|
21
|
-
Content(`
|
|
22
|
-
// ${model.Name} ${build.Name} SDK
|
|
23
|
-
|
|
24
|
-
package ${model.name}sdk
|
|
25
|
-
|
|
26
|
-
import(
|
|
27
|
-
"bytes"
|
|
28
|
-
"encoding/json"
|
|
29
|
-
"fmt"
|
|
30
|
-
"net/http"
|
|
31
|
-
"errors"
|
|
32
|
-
"reflect"
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
type endpointConfig struct {
|
|
36
|
-
op string
|
|
37
|
-
id string
|
|
38
|
-
name string
|
|
39
|
-
apiUrl string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type fetchConfig struct {
|
|
43
|
-
op string
|
|
44
|
-
url string
|
|
45
|
-
apikey string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type spec struct {
|
|
49
|
-
body *bytes.Buffer
|
|
50
|
-
url string
|
|
51
|
-
method string
|
|
52
|
-
contentType string
|
|
53
|
-
authorization string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type Options struct {`)
|
|
57
|
-
each(options, (option: any) => {
|
|
58
|
-
if (option.kind != "Any") {
|
|
59
|
-
Content(`
|
|
60
|
-
${camelify(option.name)} ${option.kind.toLowerCase()}
|
|
61
|
-
`)
|
|
62
|
-
}
|
|
63
|
-
}); Content(`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type ${model.name} struct {
|
|
67
|
-
httpClient http.Client
|
|
68
|
-
options Options
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
func method(op string) string {
|
|
72
|
-
operations := map[string]string {
|
|
73
|
-
"create": "POST",
|
|
74
|
-
"save": "PUT",
|
|
75
|
-
"load": "GET",
|
|
76
|
-
"list": "GET",
|
|
77
|
-
"remove": "DELETE",
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return operations[op]
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
func endpoint(config endpointConfig) string {
|
|
84
|
-
url := fmt.Sprintf("%v/%v", config.apiUrl, config.name)
|
|
85
|
-
|
|
86
|
-
if config.op == "load" || config.op == "remove" {
|
|
87
|
-
url += fmt.Sprintf("/%v", config.id)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return url
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
func body[T any](data T) ([]byte, error) {
|
|
94
|
-
var msg []byte
|
|
95
|
-
msg, err := json.Marshal(data)
|
|
96
|
-
if err != nil {
|
|
97
|
-
return nil, err
|
|
98
|
-
}
|
|
99
|
-
return msg, nil
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
func fetchSpec[T any](config fetchConfig, data T) (spec, error){
|
|
103
|
-
method := method(config.op)
|
|
104
|
-
buffBody := bytes.NewBuffer([]byte{})
|
|
105
|
-
|
|
106
|
-
if method != "GET" && method != "DELETE" {
|
|
107
|
-
parsedBody, err := body(data)
|
|
108
|
-
if err != nil {
|
|
109
|
-
return spec{}, err
|
|
110
|
-
}
|
|
111
|
-
buffBody = bytes.NewBuffer(parsedBody)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
spec := spec{
|
|
115
|
-
url: config.url,
|
|
116
|
-
method: method,
|
|
117
|
-
contentType: "application/json",
|
|
118
|
-
authorization: fmt.Sprintf("Bearer %v", config.apikey),
|
|
119
|
-
body: buffBody,
|
|
120
|
-
}
|
|
121
|
-
return spec, nil
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
`)
|
|
125
|
-
|
|
126
|
-
each(entity, (entity: any) => {
|
|
127
|
-
MainEntity({ model, build, entity })
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
Content(`
|
|
131
|
-
func validateOptions(options Options) error {
|
|
132
|
-
e := reflect.ValueOf(&options).Elem()
|
|
133
|
-
|
|
134
|
-
for i := 0; i < e.NumField(); i++ {
|
|
135
|
-
field := e.Field(i)
|
|
136
|
-
fieldName := e.Type().Field(i).Name
|
|
137
|
-
fieldValue := field.Interface()
|
|
138
|
-
|
|
139
|
-
if field.IsZero() {
|
|
140
|
-
return errors.New(fmt.Sprintf("${model.Name}SDK: Invalid options: opt: %v value: %v",
|
|
141
|
-
fieldName, fieldValue))
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return nil
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
func new${model.Name}SDK(options Options) (*${model.name}, error) {
|
|
148
|
-
sdk := new(${model.name})
|
|
149
|
-
sdk.options = options
|
|
150
|
-
sdk.httpClient = *http.DefaultClient
|
|
151
|
-
return sdk, nil
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
func Make(options Options) (*${model.name}, error) {
|
|
155
|
-
err := validateOptions(options)
|
|
156
|
-
if err != nil {
|
|
157
|
-
return nil, err
|
|
158
|
-
}
|
|
159
|
-
return new${model.Name}SDK(options)
|
|
160
|
-
}
|
|
161
|
-
`)
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
export {
|
|
167
|
-
Main
|
|
168
|
-
}
|
|
@@ -1,108 +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_test.' + build.name }, () => {
|
|
10
|
-
|
|
11
|
-
Content(`
|
|
12
|
-
package ${model.name}sdk
|
|
13
|
-
|
|
14
|
-
import (
|
|
15
|
-
"log"
|
|
16
|
-
"os"
|
|
17
|
-
"strings"
|
|
18
|
-
"testing"
|
|
19
|
-
|
|
20
|
-
"github.com/joho/godotenv"
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
func TestQuick(t *testing.T) {
|
|
24
|
-
err := godotenv.Load()
|
|
25
|
-
if err != nil {
|
|
26
|
-
t.Fatal("Error loading .env file for Quick test")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
endpoint := os.Getenv("${model.NAME}_ENDPOINT")
|
|
30
|
-
apikey := os.Getenv("${model.NAME}_APIKEY")
|
|
31
|
-
|
|
32
|
-
var options Options
|
|
33
|
-
options.Apikey = apikey
|
|
34
|
-
options.Endpoint = endpoint
|
|
35
|
-
client, err := Make(options)
|
|
36
|
-
if err != nil {
|
|
37
|
-
t.Fatalf("Error creating a new client Quick: %q", err)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
data := GeofenceData{
|
|
41
|
-
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
out, err := client.Geofence().Load(data)
|
|
45
|
-
if err != nil {
|
|
46
|
-
t.Fatalf("Error running Quick load method: %q", err)
|
|
47
|
-
}
|
|
48
|
-
log.Print("Geofence.load", out.Data)
|
|
49
|
-
|
|
50
|
-
out2, err := client.Geofence().List()
|
|
51
|
-
if err != nil {
|
|
52
|
-
t.Fatalf("Error running Quick list method: %q", err)
|
|
53
|
-
}
|
|
54
|
-
log.Print("Geofence.list", out2[0].Data, out2[1].Data)
|
|
55
|
-
|
|
56
|
-
if strings.Contains(endpoint, "localhost") {
|
|
57
|
-
//Create Quick Test
|
|
58
|
-
data := GeofenceData{
|
|
59
|
-
Name: "Geofence 1",
|
|
60
|
-
Desc: "Geofence 1 description",
|
|
61
|
-
Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
62
|
-
Custom: map[string]any{
|
|
63
|
-
"foo": "bar",
|
|
64
|
-
},
|
|
65
|
-
}
|
|
66
|
-
out, err := client.Geofence().Create(data)
|
|
67
|
-
if err != nil {
|
|
68
|
-
t.Fatalf("Error running Quick create method: %q", err)
|
|
69
|
-
}
|
|
70
|
-
log.Print("Geofence.create", out.Data)
|
|
71
|
-
|
|
72
|
-
//Save Quick Test
|
|
73
|
-
data = GeofenceData{
|
|
74
|
-
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
75
|
-
Name: "Geofence 1",
|
|
76
|
-
Desc: "Geofence 1 description",
|
|
77
|
-
Extent_id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
78
|
-
Custom: map[string]any{
|
|
79
|
-
"foo": "bar",
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
out, err = client.Geofence().Save(data)
|
|
83
|
-
if err != nil {
|
|
84
|
-
t.Fatalf("Error running Quick save method: %q", err)
|
|
85
|
-
}
|
|
86
|
-
log.Print("Geofence.save", out.Data)
|
|
87
|
-
|
|
88
|
-
//Remove Quick Test
|
|
89
|
-
data = GeofenceData{
|
|
90
|
-
Id: "CF49B47C-317B-4387-83C3-4A23715B1C45",
|
|
91
|
-
}
|
|
92
|
-
out, err = client.Geofence().Remove(data)
|
|
93
|
-
if err != nil {
|
|
94
|
-
t.Fatalf("Error running Quick remove method: %q", err)
|
|
95
|
-
}
|
|
96
|
-
log.Print("Geofence.remove ", out)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
`)
|
|
100
|
-
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export {
|
|
106
|
-
Quick
|
|
107
|
-
}
|
|
108
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
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('```go')
|
|
9
|
-
Content(`
|
|
10
|
-
go get ${build.module.name}
|
|
11
|
-
`)
|
|
12
|
-
Content('```')
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
ReadmeInstall
|
|
19
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
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('```go')
|
|
9
|
-
Content(`
|
|
10
|
-
package main
|
|
11
|
-
|
|
12
|
-
import (
|
|
13
|
-
"log"
|
|
14
|
-
"os"
|
|
15
|
-
|
|
16
|
-
"${build.module.name}"
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
func main() {
|
|
20
|
-
var options ${model.name}sdk.Options
|
|
21
|
-
options.Apikey = os.Getenv("${model.NAME}_APIKEY")
|
|
22
|
-
options.Endpoint = os.Getenv("${model.NAME}_ENDPOINT")
|
|
23
|
-
|
|
24
|
-
client, err := ${model.name}sdk.Make(options)
|
|
25
|
-
if err != nil {
|
|
26
|
-
log.Fatal(err)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
buildings, err := client.Building().List()
|
|
30
|
-
if err != nil {
|
|
31
|
-
log.Println("Error running building list:", err)
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
log.Println("Buildings", buildings)
|
|
36
|
-
}
|
|
37
|
-
`)
|
|
38
|
-
Content('```')
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
ReadmeQuick
|
|
45
|
-
}
|