@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.
Files changed (105) hide show
  1. package/bin/voxgig-create-sdkgen +196 -0
  2. package/dist/create-sdkgen.d.ts +11 -8
  3. package/dist/create-sdkgen.js +61 -63
  4. package/dist/create-sdkgen.js.map +1 -1
  5. package/dist/standard/ModelSdk.js +8 -61
  6. package/dist/standard/ModelSdk.js.map +1 -1
  7. package/dist/standard/Root.js +58 -57
  8. package/dist/standard/Root.js.map +1 -1
  9. package/dist/tsconfig.tsbuildinfo +1 -1
  10. package/package.json +13 -10
  11. package/src/create-sdkgen.ts +56 -74
  12. package/src/standard/ModelSdk.ts +9 -71
  13. package/src/standard/Root.ts +26 -68
  14. package/bin/run-create-sdkgen.js +0 -269
  15. package/bin/run-create-sdkgen.js~ +0 -1
  16. package/src/standard/ModelSdk.ts~ +0 -1
  17. package/src/standard/Root.ts~ +0 -3
  18. package/src/utility.ts +0 -8
  19. package/tm/standard/.env.local +0 -2
  20. package/tm/standard/build/sdk.js +0 -25
  21. package/tm/standard/def/DEFINITION.md +0 -2
  22. package/tm/standard/model/.model-config/model-config.jsonic +0 -13
  23. package/tm/standard/model/go.jsonic +0 -6
  24. package/tm/standard/model/js.jsonic +0 -6
  25. package/tm/standard/model/php.jsonic +0 -6
  26. package/tm/standard/model/py.jsonic +0 -7
  27. package/tm/standard/model/rb.jsonic +0 -6
  28. package/tm/standard/model/sdk.jsonic.off +0 -60
  29. package/tm/standard/package.json +0 -30
  30. package/tm/standard/src/Root.ts +0 -60
  31. package/tm/standard/src/go/Entity_go.ts +0 -226
  32. package/tm/standard/src/go/MainEntity_go.ts +0 -26
  33. package/tm/standard/src/go/Main_go.ts +0 -168
  34. package/tm/standard/src/go/Quick_go.ts +0 -108
  35. package/tm/standard/src/go/ReadmeInstall_go.ts +0 -19
  36. package/tm/standard/src/go/ReadmeQuick_go.ts +0 -45
  37. package/tm/standard/src/go/TestAcceptEntity_go.ts +0 -219
  38. package/tm/standard/src/go/TestAccept_go.ts +0 -38
  39. package/tm/standard/src/go/TestEntity_go.ts +0 -79
  40. package/tm/standard/src/go/TestMain_go.ts +0 -61
  41. package/tm/standard/src/go/Test_go.ts +0 -20
  42. package/tm/standard/src/js/Entity_js.ts +0 -135
  43. package/tm/standard/src/js/MainEntity_js.ts +0 -22
  44. package/tm/standard/src/js/Main_js.ts +0 -128
  45. package/tm/standard/src/js/Quick_js.ts +0 -72
  46. package/tm/standard/src/js/ReadmeInstall_js.ts +0 -19
  47. package/tm/standard/src/js/ReadmeQuick_js.ts +0 -27
  48. package/tm/standard/src/js/TestAcceptEntity_js.ts +0 -101
  49. package/tm/standard/src/js/TestAccept_js.ts +0 -60
  50. package/tm/standard/src/js/TestEntity_js.ts +0 -24
  51. package/tm/standard/src/js/TestMain_js.ts +0 -123
  52. package/tm/standard/src/js/Test_js.ts +0 -24
  53. package/tm/standard/src/php/Entity_php.ts +0 -97
  54. package/tm/standard/src/php/MainEntity_php.ts +0 -43
  55. package/tm/standard/src/php/Main_php.ts +0 -50
  56. package/tm/standard/src/php/Quick_php.ts +0 -59
  57. package/tm/standard/src/php/TestAcceptEntity_php.ts +0 -81
  58. package/tm/standard/src/php/TestAccept_php.ts +0 -33
  59. package/tm/standard/src/php/TestEntity_php.ts +0 -64
  60. package/tm/standard/src/php/TestMain_php.ts +0 -120
  61. package/tm/standard/src/php/Test_php.ts +0 -21
  62. package/tm/standard/src/py/Entity_py.ts +0 -98
  63. package/tm/standard/src/py/MainEntity_py.ts +0 -19
  64. package/tm/standard/src/py/Main_py.ts +0 -211
  65. package/tm/standard/src/py/Quick_py.ts +0 -133
  66. package/tm/standard/src/py/TestAcceptEntity_py.ts +0 -47
  67. package/tm/standard/src/py/TestAccept_py.ts +0 -77
  68. package/tm/standard/src/py/TestEntity_py.ts +0 -50
  69. package/tm/standard/src/py/TestMain_py.ts +0 -103
  70. package/tm/standard/src/py/Test_py.ts +0 -28
  71. package/tm/standard/src/rb/Client_rb.ts +0 -142
  72. package/tm/standard/src/rb/Entity_rb.ts +0 -153
  73. package/tm/standard/src/rb/Error_rb.ts +0 -56
  74. package/tm/standard/src/rb/MainEntity_rb.ts +0 -16
  75. package/tm/standard/src/rb/Main_rb.ts +0 -55
  76. package/tm/standard/src/rb/Quick_rb.ts +0 -65
  77. package/tm/standard/src/rb/ReadmeInstall_rb.ts +0 -19
  78. package/tm/standard/src/rb/ReadmeQuick_rb.ts +0 -30
  79. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +0 -83
  80. package/tm/standard/src/rb/TestAccept_rb.ts +0 -45
  81. package/tm/standard/src/rb/TestEntity_rb.ts +0 -82
  82. package/tm/standard/src/rb/TestMain_rb.ts +0 -67
  83. package/tm/standard/src/rb/Test_rb.ts +0 -27
  84. package/tm/standard/src/tsconfig.json +0 -15
  85. package/tm/standard/tm/go/.env.example +0 -2
  86. package/tm/standard/tm/go/LICENSE +0 -22
  87. package/tm/standard/tm/go/go.mod +0 -5
  88. package/tm/standard/tm/go/go.sum +0 -2
  89. package/tm/standard/tm/js/LICENSE +0 -22
  90. package/tm/standard/tm/js/package.json +0 -17
  91. package/tm/standard/tm/php/LICENSE +0 -22
  92. package/tm/standard/tm/py/LICENSE +0 -22
  93. package/tm/standard/tm/py/MANIFEST.in +0 -4
  94. package/tm/standard/tm/py/Makefile +0 -14
  95. package/tm/standard/tm/py/pyproject.toml +0 -4
  96. package/tm/standard/tm/py/pytest.ini +0 -3
  97. package/tm/standard/tm/py/requirements.txt +0 -4
  98. package/tm/standard/tm/py/setup.cfg +0 -2
  99. package/tm/standard/tm/py/setup.py +0 -82
  100. package/tm/standard/tm/rb/.rspec +0 -1
  101. package/tm/standard/tm/rb/Gemfile +0 -21
  102. package/tm/standard/tm/rb/LICENSE +0 -22
  103. package/tm/standard/tm/rb/Rakefile +0 -6
  104. package/tm/standard/tm/rb/spec/spec_helper.rb +0 -22
  105. package/tm/standard/tm/rb/tm.gemspec +0 -39
@@ -1,219 +0,0 @@
1
-
2
- import { cmp, each, camelify, Content } from '@voxgig/sdkgen'
3
-
4
-
5
- const TestAcceptEntity = cmp(function TestAcceptEntity(props: any) {
6
- const { model, entity } = props
7
-
8
- entity.Name = camelify(entity.name)
9
-
10
- const valueMap: Record<string, any> = {
11
- "custom": "map[string]any{\"test\": \"test\"}",
12
- "xval": "rand.Float64()",
13
- "yval": "rand.Float64()",
14
- "zval": "rand.Float64()",
15
- "xlen": "rand.Int()",
16
- "ylen": "rand.Int()",
17
- "parent_xlen": "rand.Int()",
18
- "parent_xval": "rand.Float64()",
19
- "parent_xyangle": "rand.Float64()",
20
- "parent_ylen": "rand.Int()",
21
- "parent_yval": "rand.Float64()",
22
- "parent_zval": "rand.Float64()",
23
- "polygon": "struct{Points [][]float64}{[][]float64{{ 1.34},{12.33}}}",
24
- "has_parent": true,
25
- "primary": true,
26
- }
27
-
28
- Content(`
29
- func Test${entity.Name}AcceptList(t *testing.T) {
30
- err := godotenv.Load()
31
- if err != nil {
32
- t.Fatal("Error loading .env file for Test${entity.Name}AcceptList")
33
- }
34
- endpoint := os.Getenv("${model.NAME}_ENDPOINT")
35
- apikey := os.Getenv("${model.NAME}_APIKEY")
36
-
37
- var options ${model.name}sdk.Options
38
- options.Apikey = apikey
39
- options.Endpoint = endpoint
40
- client, err := ${model.name}sdk.Make(options)
41
- if err != nil {
42
- t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
43
- }
44
-
45
- entities, err := client.${entity.Name}().List()
46
- if err != nil {
47
- t.Fatalf("Error running ${entity.name} list method: %v", err)
48
- }
49
-
50
- if len(entities) == 0 {
51
- t.Fatalf("Error getting ${entity.name} accept list length == 0 and got %v",
52
- len(entities))
53
- }
54
-
55
- got := entities[0].Data
56
-
57
- if got.Id == "" {
58
- t.Fatal("Error getting ${entity.name} accept list - id equal to empty string")
59
- }
60
- }
61
-
62
-
63
- func Test${entity.Name}AcceptLoad(t *testing.T) {
64
- err := godotenv.Load()
65
- if err != nil {
66
- t.Fatal("Error loading .env file for Test${entity.Name}AcceptLoad")
67
- }
68
- endpoint := os.Getenv("${model.NAME}_ENDPOINT")
69
- apikey := os.Getenv("${model.NAME}_APIKEY")
70
-
71
- var options ${model.name}sdk.Options
72
- options.Apikey = apikey
73
- options.Endpoint = endpoint
74
- client, err := ${model.name}sdk.Make(options)
75
- if err != nil {
76
- t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
77
- }
78
-
79
- data := ${model.name}sdk.${entity.Name}Data{
80
- Id: "t01",
81
- }
82
-
83
- client${entity.Name}, err := client.${entity.Name}().Load(data)
84
- if err != nil {
85
- t.Fatalf("Error running ${entity.name} load method: %v", err)
86
- }
87
-
88
- got := client${entity.Name}.Data
89
-
90
- if got.Id == "" {
91
- t.Fatal("Error getting ${entity.name} accept load - id equal to empty string")
92
- }
93
- }
94
-
95
- func Test${entity.Name}AcceptCreate(t *testing.T) {
96
- err := godotenv.Load()
97
- if err != nil {
98
- t.Fatal("Error loading .env file for Test${entity.Name}AcceptCreate")
99
- }
100
- endpoint := os.Getenv("${model.NAME}_ENDPOINT")
101
- apikey := os.Getenv("${model.NAME}_APIKEY")
102
-
103
- var options ${model.name}sdk.Options
104
- options.Apikey = apikey
105
- options.Endpoint = endpoint
106
- client, err := ${model.name}sdk.Make(options)
107
- if err != nil {
108
- t.Fatalf("Error creating a new client ${entity.name} create: %q", err)
109
- }
110
-
111
- data := ${model.name}sdk.${entity.Name}Data{
112
- `)
113
- each(entity.field, (field: any) => {
114
- const value = valueMap[field.name] ? valueMap[field.name] : field.type
115
-
116
- if (value == "string") {
117
- Content(`
118
- ${field.Name}: "test",
119
- `)
120
- return
121
- }
122
- Content(`
123
- ${field.Name}: ${value},
124
- `)
125
- })
126
- Content(`
127
- }
128
-
129
- client${entity.Name}, err := client.${entity.Name}().Create(data)
130
- if err != nil {
131
- t.Fatalf("Error running ${entity.name} create method: %v", err)
132
- }
133
-
134
- got := client${entity.Name}.Data
135
-
136
- if got.Id == "" {
137
- t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
138
- }
139
- }
140
-
141
-
142
- func Test${entity.Name}AcceptSave(t *testing.T) {
143
- err := godotenv.Load()
144
- if err != nil {
145
- t.Fatal("Error loading .env file for Test${entity.Name}AcceptSave")
146
- }
147
- endpoint := os.Getenv("${model.NAME}_ENDPOINT")
148
- apikey := os.Getenv("${model.NAME}_APIKEY")
149
-
150
- var options ${model.name}sdk.Options
151
- options.Apikey = apikey
152
- options.Endpoint = endpoint
153
- client, err := ${model.name}sdk.Make(options)
154
- if err != nil {
155
- t.Fatalf("Error creating a new client ${entity.name} save: %q", err)
156
- }
157
-
158
- data := ${model.name}sdk.${entity.Name}Data{
159
- `)
160
- each(entity.field, (field: any) => {
161
- const value = valueMap[field.name] ? valueMap[field.name] : field.type
162
-
163
- if (value == "string") {
164
- Content(`
165
- ${field.Name}: "test",
166
- `)
167
- return
168
- }
169
- Content(`
170
- ${field.Name}: ${value},
171
- `)
172
- })
173
- Content(`
174
- }
175
-
176
- client${entity.Name}, err := client.${entity.Name}().Save(data)
177
- if err != nil {
178
- t.Fatalf("Error running ${entity.name} save method: %v", err)
179
- }
180
-
181
- got := client${entity.Name}.Data
182
-
183
- if got.Id == "" {
184
- t.Fatal("Error getting ${entity.name} accept create - id equal to empty string")
185
- }
186
- }
187
-
188
- func Test${entity.Name}AcceptRemove(t *testing.T) {
189
- err := godotenv.Load()
190
- if err != nil {
191
- t.Fatal("Error loading .env file for Test${entity.Name}AcceptRemove")
192
- }
193
- endpoint := os.Getenv("${model.NAME}_ENDPOINT")
194
- apikey := os.Getenv("${model.NAME}_APIKEY")
195
-
196
- var options ${model.name}sdk.Options
197
- options.Apikey = apikey
198
- options.Endpoint = endpoint
199
- client, err := ${model.name}sdk.Make(options)
200
- if err != nil {
201
- t.Fatalf("Error creating a new client ${entity.name} remove: %q", err)
202
- }
203
-
204
- data := ${model.name}sdk.${entity.Name}Data{
205
- Id: "t01",
206
- }
207
-
208
- _, err = client.${entity.Name}().Remove(data)
209
- if err != nil {
210
- t.Fatalf("Error running ${entity.name} remove method: %v", err)
211
- }
212
- }
213
- `);
214
- })
215
-
216
-
217
- export {
218
- TestAcceptEntity
219
- }
@@ -1,38 +0,0 @@
1
-
2
- import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
-
4
- import { TestAcceptEntity } from './TestAcceptEntity_go'
5
-
6
-
7
- const TestAccept = cmp(function TestAccept(props: any) {
8
- const { build } = props
9
- const { model } = props.ctx$
10
-
11
-
12
- File({ name: model.name + 'sdk_accept_test.' + build.name }, () => {
13
-
14
- Content(`
15
- package ${model.name}sdk_test
16
-
17
- import (
18
- "math/rand"
19
- "testing"
20
- "os"
21
-
22
- "github.com/joho/godotenv"
23
- "github.com/${model.name}/${model.name}-sdk"
24
- )
25
- `)
26
-
27
- each(model.main.sdk.entity, (entity: any) => {
28
- TestAcceptEntity({ model, build, entity })
29
- })
30
-
31
- })
32
- })
33
-
34
-
35
- export {
36
- TestAccept
37
- }
38
-
@@ -1,79 +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
- Content(`
11
- func Test${entity.Name}List(t *testing.T) {
12
- endpoint := "http://test.com"
13
- apikey := "apikey"
14
- want := ${entity.Name}Data{
15
- Id: "${entity.name}t01",
16
- Name: "${entity.Name}T01",
17
- }
18
-
19
- var options Options
20
- options.Apikey = apikey
21
- options.Endpoint = endpoint
22
- client, err := Make(options)
23
- if err != nil {
24
- t.Fatalf("Error creating a new client ${entity.name} list: %q", err)
25
- }
26
-
27
- respData := strings.NewReader(\`{"list":[{"id":"${entity.name}t01"},
28
- {"id":"${entity.name}t02"}]}\`)
29
- httpClientMock := createHttpClientMock(respData)
30
- client.httpClient = *httpClientMock
31
-
32
- entities, err := client.${entity.Name}().List()
33
- if err != nil {
34
- t.Fatalf("Error running ${entity.name} list method: %q", err)
35
- }
36
-
37
- got := entities[0].Data
38
- if got.Id != want.Id {
39
- t.Fatalf("Error getting ${entity.name} list want %v and got %v", want, got)
40
- }
41
- }
42
-
43
- func Test${entity.Name}Load(t *testing.T) {
44
- endpoint := "http://test.com"
45
- apikey := "apikey"
46
- want := ${entity.Name}Data{
47
- Id: "${entity.name}t01",
48
- }
49
-
50
- var options Options
51
- options.Apikey = apikey
52
- options.Endpoint = endpoint
53
- client, err := Make(options)
54
- if err != nil {
55
- t.Fatalf("Error creating a new client ${entity.name} load: %q", err)
56
- }
57
-
58
- respData := strings.NewReader(fmt.Sprintf(\`{"id":"${entity.name}t01"}\`))
59
- httpClientMock := createHttpClientMock(respData)
60
- client.httpClient = *httpClientMock
61
-
62
- data := want
63
- client${entity.Name}, err := client.${entity.Name}().Load(data)
64
- if err != nil {
65
- t.Fatalf("Error running ${entity.name} load method: %q", err)
66
- }
67
-
68
- got := client${entity.Name}.Data
69
- if got.Id != want.Id {
70
- t.Fatalf("Error getting ${entity.name} load want %v and got %v", want.Id, got.Id)
71
- }
72
- }
73
- `)
74
- })
75
-
76
-
77
- export {
78
- TestEntity
79
- }
@@ -1,61 +0,0 @@
1
-
2
- import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
-
4
-
5
- import { TestEntity } from './TestEntity_go'
6
-
7
-
8
- const TestMain = cmp(function TestMain(props: any) {
9
- const { build } = props
10
- const { model } = props.ctx$
11
-
12
- File({ name: model.name + 'sdk_test.' + build.name }, () => {
13
-
14
- Content(`
15
- package ${model.name}sdk
16
-
17
- import (
18
- "fmt"
19
- "testing"
20
- "net/http"
21
- "io"
22
- "strings"
23
- )
24
-
25
- // Mock HTTP Client Transport type.
26
- // For more info, please see: https://pkg.go.dev/net/http#Client
27
- // And: https://pkg.go.dev/net/http#RoundTripper
28
- type fakeService func(*http.Request) (*http.Response, error)
29
-
30
- func (s fakeService) RoundTrip(req *http.Request) (*http.Response, error) {
31
- return s(req)
32
- }
33
-
34
- func createHttpClientMock(respData *strings.Reader) *http.Client {
35
- return &http.Client{
36
- Transport: fakeService(func(*http.Request) (*http.Response, error) {
37
- return &http.Response{
38
- StatusContent: http.StatusOK,
39
- Header: http.Header{
40
- "Content-Type": []string{"application/json"},
41
- },
42
- Body: io.NopCloser(respData),
43
- }, nil
44
- }),
45
- }}
46
- `)
47
-
48
- each(model.main.sdk.entity, (entity: any) => {
49
- TestEntity({ model, build, entity })
50
- })
51
- Content(`
52
- `)
53
-
54
- })
55
- })
56
-
57
-
58
- export {
59
- TestMain
60
- }
61
-
@@ -1,20 +0,0 @@
1
-
2
- import { cmp } from '@voxgig/sdkgen'
3
-
4
- import { Quick } from './Quick_go'
5
- import { TestMain } from './TestMain_go'
6
- import { TestAccept } from './TestAccept_go'
7
-
8
-
9
- const Test = cmp(function Test(props: any) {
10
- const { build } = props
11
-
12
- Quick({ build })
13
- TestMain({ build })
14
- TestAccept({ build })
15
- })
16
-
17
-
18
- export {
19
- Test
20
- }
@@ -1,135 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -1,128 +0,0 @@
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
- }