@voxgig/create-sdkgen 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +2 -0
  2. package/bin/run-create-sdkgen.js +265 -1
  3. package/bin/run-create-sdkgen.js~ +1 -0
  4. package/dist/create-sdkgen.d.ts +2 -0
  5. package/dist/create-sdkgen.js +51 -2
  6. package/dist/create-sdkgen.js.map +1 -1
  7. package/dist/standard/ModelSdk.d.ts +2 -0
  8. package/dist/standard/ModelSdk.js +71 -0
  9. package/dist/standard/ModelSdk.js.map +1 -0
  10. package/dist/standard/Root.d.ts +2 -0
  11. package/dist/standard/Root.js +76 -0
  12. package/dist/standard/Root.js.map +1 -0
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/package.json +9 -6
  15. package/src/create-sdkgen.ts +71 -3
  16. package/src/standard/ModelSdk.ts +92 -0
  17. package/src/standard/ModelSdk.ts~ +1 -0
  18. package/src/standard/Root.ts +107 -0
  19. package/src/standard/Root.ts~ +3 -0
  20. package/tm/standard/.env.local +2 -0
  21. package/tm/standard/build/sdk.js +25 -0
  22. package/tm/standard/def/DEFINITION.md +2 -0
  23. package/tm/standard/model/.model-config/model-config.jsonic +13 -0
  24. package/tm/standard/model/go.jsonic +6 -0
  25. package/tm/standard/model/js.jsonic +6 -0
  26. package/tm/standard/model/php.jsonic +6 -0
  27. package/tm/standard/model/py.jsonic +7 -0
  28. package/tm/standard/model/rb.jsonic +6 -0
  29. package/tm/standard/model/sdk.jsonic.off +60 -0
  30. package/tm/standard/package.json +30 -0
  31. package/tm/standard/src/Root.ts +60 -0
  32. package/tm/standard/src/go/Entity_go.ts +226 -0
  33. package/tm/standard/src/go/MainEntity_go.ts +26 -0
  34. package/tm/standard/src/go/Main_go.ts +168 -0
  35. package/tm/standard/src/go/Quick_go.ts +108 -0
  36. package/tm/standard/src/go/ReadmeInstall_go.ts +19 -0
  37. package/tm/standard/src/go/ReadmeQuick_go.ts +45 -0
  38. package/tm/standard/src/go/TestAcceptEntity_go.ts +219 -0
  39. package/tm/standard/src/go/TestAccept_go.ts +38 -0
  40. package/tm/standard/src/go/TestEntity_go.ts +79 -0
  41. package/tm/standard/src/go/TestMain_go.ts +61 -0
  42. package/tm/standard/src/go/Test_go.ts +20 -0
  43. package/tm/standard/src/js/Entity_js.ts +135 -0
  44. package/tm/standard/src/js/MainEntity_js.ts +22 -0
  45. package/tm/standard/src/js/Main_js.ts +128 -0
  46. package/tm/standard/src/js/Quick_js.ts +72 -0
  47. package/tm/standard/src/js/ReadmeInstall_js.ts +19 -0
  48. package/tm/standard/src/js/ReadmeQuick_js.ts +27 -0
  49. package/tm/standard/src/js/TestAcceptEntity_js.ts +101 -0
  50. package/tm/standard/src/js/TestAccept_js.ts +60 -0
  51. package/tm/standard/src/js/TestEntity_js.ts +24 -0
  52. package/tm/standard/src/js/TestMain_js.ts +123 -0
  53. package/tm/standard/src/js/Test_js.ts +24 -0
  54. package/tm/standard/src/php/Entity_php.ts +97 -0
  55. package/tm/standard/src/php/MainEntity_php.ts +43 -0
  56. package/tm/standard/src/php/Main_php.ts +50 -0
  57. package/tm/standard/src/php/Quick_php.ts +59 -0
  58. package/tm/standard/src/php/TestAcceptEntity_php.ts +81 -0
  59. package/tm/standard/src/php/TestAccept_php.ts +33 -0
  60. package/tm/standard/src/php/TestEntity_php.ts +64 -0
  61. package/tm/standard/src/php/TestMain_php.ts +120 -0
  62. package/tm/standard/src/php/Test_php.ts +21 -0
  63. package/tm/standard/src/py/Entity_py.ts +98 -0
  64. package/tm/standard/src/py/MainEntity_py.ts +19 -0
  65. package/tm/standard/src/py/Main_py.ts +211 -0
  66. package/tm/standard/src/py/Quick_py.ts +133 -0
  67. package/tm/standard/src/py/TestAcceptEntity_py.ts +47 -0
  68. package/tm/standard/src/py/TestAccept_py.ts +77 -0
  69. package/tm/standard/src/py/TestEntity_py.ts +50 -0
  70. package/tm/standard/src/py/TestMain_py.ts +103 -0
  71. package/tm/standard/src/py/Test_py.ts +28 -0
  72. package/tm/standard/src/rb/Client_rb.ts +142 -0
  73. package/tm/standard/src/rb/Entity_rb.ts +153 -0
  74. package/tm/standard/src/rb/Error_rb.ts +56 -0
  75. package/tm/standard/src/rb/MainEntity_rb.ts +16 -0
  76. package/tm/standard/src/rb/Main_rb.ts +55 -0
  77. package/tm/standard/src/rb/Quick_rb.ts +65 -0
  78. package/tm/standard/src/rb/ReadmeInstall_rb.ts +19 -0
  79. package/tm/standard/src/rb/ReadmeQuick_rb.ts +30 -0
  80. package/tm/standard/src/rb/TestAcceptEntity_rb.ts +83 -0
  81. package/tm/standard/src/rb/TestAccept_rb.ts +45 -0
  82. package/tm/standard/src/rb/TestEntity_rb.ts +82 -0
  83. package/tm/standard/src/rb/TestMain_rb.ts +67 -0
  84. package/tm/standard/src/rb/Test_rb.ts +27 -0
  85. package/tm/standard/src/tsconfig.json +15 -0
  86. package/tm/standard/tm/go/.env.example +2 -0
  87. package/tm/standard/tm/go/LICENSE +22 -0
  88. package/tm/standard/tm/go/go.mod +5 -0
  89. package/tm/standard/tm/go/go.sum +2 -0
  90. package/tm/standard/tm/js/LICENSE +22 -0
  91. package/tm/standard/tm/js/package.json +17 -0
  92. package/tm/standard/tm/php/LICENSE +22 -0
  93. package/tm/standard/tm/py/LICENSE +22 -0
  94. package/tm/standard/tm/py/MANIFEST.in +4 -0
  95. package/tm/standard/tm/py/Makefile +14 -0
  96. package/tm/standard/tm/py/pyproject.toml +4 -0
  97. package/tm/standard/tm/py/pytest.ini +3 -0
  98. package/tm/standard/tm/py/requirements.txt +4 -0
  99. package/tm/standard/tm/py/setup.cfg +2 -0
  100. package/tm/standard/tm/py/setup.py +82 -0
  101. package/tm/standard/tm/rb/.rspec +1 -0
  102. package/tm/standard/tm/rb/Gemfile +21 -0
  103. package/tm/standard/tm/rb/LICENSE +22 -0
  104. package/tm/standard/tm/rb/Rakefile +6 -0
  105. package/tm/standard/tm/rb/spec/spec_helper.rb +22 -0
  106. package/tm/standard/tm/rb/tm.gemspec +39 -0
@@ -0,0 +1,92 @@
1
+
2
+ import {
3
+ names,
4
+ cmp,
5
+ each,
6
+
7
+ Project,
8
+ Folder,
9
+ Copy,
10
+ File,
11
+ Content,
12
+
13
+ } from 'jostraca'
14
+
15
+
16
+
17
+ const ModelSdk = cmp(function ModelSdk(props: any) {
18
+ const { ctx$, ctx$: { model } } = props
19
+
20
+
21
+ // console.log('ModelSdk 2', model)
22
+
23
+ // TODO: use apidef
24
+ // const def = ctx$.fs.readFileSync(model.def.filepath)
25
+
26
+
27
+ File({ name: 'sdk.jsonic' }, () => {
28
+ Content(`
29
+ name: '${model.name}'
30
+
31
+ @"api.jsonic"
32
+ @"def.jsonic"
33
+
34
+ main: sdk: build: &: { name: .$KEY }
35
+
36
+ main: sdk: build: js: @"js.jsonic"
37
+
38
+ main: sdk: build: rb: @"rb.jsonic"
39
+
40
+ main: sdk: build: py: @"py.jsonic"
41
+
42
+ main: sdk: build: php: @"php.jsonic"
43
+
44
+ main: sdk: build: go: @"go.jsonic"
45
+
46
+
47
+
48
+ main: sdk: test: quick: entity: name: q
49
+
50
+
51
+ main: sdk: entity: $.main.api.entity
52
+
53
+
54
+ main: sdk: entity: &: {
55
+ name: .$KEY
56
+ publish: *true | boolean
57
+ }
58
+
59
+
60
+
61
+ main: sdk: options: &: {
62
+ name: .$KEY
63
+ publish: *true | boolean
64
+ }
65
+
66
+
67
+ main: sdk: options: {
68
+
69
+ endpoint: {
70
+ kind: *String | string
71
+ short: "${model.Name} API URL"
72
+ }
73
+
74
+ apikey: {
75
+ kind: *String | string
76
+ short: "${model.Name} API Key"
77
+ }
78
+
79
+ fetch: {
80
+ kind: *Any | string
81
+ publish: false
82
+ }
83
+ }
84
+ `)
85
+ })
86
+
87
+ })
88
+
89
+
90
+ export {
91
+ ModelSdk
92
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,107 @@
1
+
2
+
3
+ import Path from 'node:path'
4
+
5
+
6
+ import {
7
+ names,
8
+ cmp,
9
+ each,
10
+
11
+ Project,
12
+ Folder,
13
+ Copy,
14
+ File,
15
+ Content,
16
+
17
+ } from 'jostraca'
18
+
19
+
20
+ import { ModelSdk } from './ModelSdk'
21
+
22
+
23
+ const Root = cmp(function Root(props: any) {
24
+ const { model, ctx$ } = props
25
+
26
+ const { folder, meta } = ctx$
27
+ const { spec } = meta
28
+
29
+ console.log('Root 5')
30
+
31
+ // console.log('SPEC', spec)
32
+
33
+ names(model, model.name)
34
+
35
+ // console.log('MODEL')
36
+ // console.dir(model, { depth: null })
37
+
38
+ ctx$.model = model
39
+
40
+ /*
41
+ let createInfo = { exclude: [], last: Number.MAX_SAFE_INTEGER }
42
+
43
+
44
+ try {
45
+ createInfo = JSON.parse(ctx$.fs.readFileSync(
46
+ Path.join(folder, '.voxgig', 'create-sdkgen.json'), 'utf8'))
47
+ }
48
+ catch (err: any) {
49
+ console.log(err)
50
+ // TODO: file not foound ignored, handle others!
51
+ }
52
+
53
+ ctx$.info = createInfo
54
+
55
+ console.log('INFO', ctx$.info)
56
+ */
57
+
58
+ Project({ folder }, () => {
59
+
60
+ // TODO: perhaps remove the need for this, create top level folder in Project
61
+ // would keep paths indo of project folder name
62
+ // Folder({ name: Path.basename(folder) }, () => {
63
+
64
+ // File({ name: 'foo.txt' }, () => {
65
+ // Content('FOO')
66
+ // })
67
+
68
+ // console.log('FOLDER', folder)
69
+ Copy({ from: __dirname + '/../../tm/standard' })
70
+
71
+ const def = model.def.filepath
72
+ if (null != def && '' !== def) {
73
+ Folder({ name: 'def' }, () => {
74
+ Copy({ from: def, name: Path.basename(def) })
75
+ })
76
+ }
77
+
78
+ Folder({ name: '.voxgig' }, () => { })
79
+
80
+ Folder({ name: 'model' }, () => {
81
+ ModelSdk({})
82
+ })
83
+ })
84
+
85
+ /*
86
+ // TODO: need mechanism to ensure this is last
87
+ setTimeout(() => {
88
+ try {
89
+ const info = {
90
+ last: Date.now(),
91
+ exclude: ctx$.info.exclude,
92
+ }
93
+ ctx$.fs.writeFileSync(Path.join(folder, '.voxgig', 'create-sdkgen.json'),
94
+ JSON.stringify(info, null, 2))
95
+ }
96
+ catch (err: any) {
97
+ console.log(err)
98
+ // TODO: file not foound ignored, handle others!
99
+ }
100
+ }, 777)
101
+ */
102
+ })
103
+
104
+
105
+ export {
106
+ Root
107
+ }
@@ -0,0 +1,3 @@
1
+
2
+
3
+
@@ -0,0 +1,2 @@
1
+ $$NAME$$_ENDPOINT=https://api.example.com
2
+ $$NAME$$_APIKEY=apikey
@@ -0,0 +1,25 @@
1
+
2
+ const { SdkGen } = require('@voxgig/sdkgen')
3
+ const { Root } = require('../dist/Root')
4
+
5
+
6
+ try {
7
+ const config = {
8
+ folder: __dirname+'/../sdk',
9
+ def: __dirname+'/../def/$$def.filename$$',
10
+ meta: {
11
+ name: '$$name$$'
12
+ },
13
+ model: {
14
+ folder: __dirname+'/../model',
15
+
16
+ entity: {}
17
+ },
18
+ }
19
+
20
+ module.exports = SdkGen.makeBuild(Root, config)
21
+
22
+ }
23
+ catch(e) {
24
+ console.log('SDK ERROR', e)
25
+ }
@@ -0,0 +1,2 @@
1
+ # API Definition
2
+ API definition (OpenAPI etc) files live here.
@@ -0,0 +1,13 @@
1
+
2
+
3
+ @'@voxgig/model/model/.model-config/model-config.jsonic'
4
+
5
+ sys: model: builders: {
6
+ sdk: load: 'build/sdk.js'
7
+ }
8
+
9
+ sys: model: watch: {
10
+ 'build': {}
11
+ 'dist': {}
12
+ 'tm': {}
13
+ }
@@ -0,0 +1,6 @@
1
+
2
+ title: Go
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: JavaScript
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: PHP
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,7 @@
1
+ title: Python
2
+
3
+ extension: py
4
+
5
+ module: name: '$ModuleName'
6
+
7
+ options: $.main.sdk.options
@@ -0,0 +1,6 @@
1
+
2
+ title: Ruby
3
+
4
+ module: name: '$ModuleName'
5
+
6
+ options: $.main.sdk.options
@@ -0,0 +1,60 @@
1
+
2
+ name: '$$name$$'
3
+
4
+ @"api.jsonic"
5
+ @"def.jsonic"
6
+
7
+ main: sdk: build: &: { name: .$KEY }
8
+
9
+ main: sdk: build: js: @"js.jsonic"
10
+
11
+ main: sdk: build: rb: @"rb.jsonic"
12
+
13
+ main: sdk: build: py: @"py.jsonic"
14
+
15
+ main: sdk: build: php: @"php.jsonic"
16
+
17
+ main: sdk: build: go: @"go.jsonic"
18
+
19
+
20
+
21
+ main: sdk: test: quick: entity: name: $$test.quick.entity.name$$
22
+
23
+
24
+ main: sdk: entity: $.main.api.entity
25
+
26
+
27
+ main: sdk: entity: &: {
28
+ name: .$KEY
29
+ publish: *true | boolean
30
+ }
31
+
32
+
33
+
34
+ main: sdk: options: &: {
35
+ name: .$KEY
36
+ publish: *true | boolean
37
+ }
38
+
39
+
40
+ main: sdk: options: {
41
+
42
+ endpoint: {
43
+ kind: *String | string
44
+ short: "$$Name$$ API URL"
45
+ }
46
+
47
+ apikey: {
48
+ kind: *String | string
49
+ short: "$$Name$$ API Key"
50
+ }
51
+
52
+ fetch: {
53
+ kind: *Any | string
54
+ publish: false
55
+ }
56
+ }
57
+
58
+
59
+
60
+
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "build-$$name$$-sdk",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "QQQindex.js",
6
+ "scripts": {
7
+ "model": "voxgig-model model/sdk.jsonic",
8
+ "watch": "tsc --build src -w",
9
+ "build": "tsc --build src",
10
+ "test": "echo no-test",
11
+ "clean": "rm -rf node_modules yarn.lock package-lock.json",
12
+ "reset": "npm run clean && npm i && npm run build && npm test",
13
+ "mock-server": "prism mock def/$DefinitionFile"
14
+ },
15
+ "author": "",
16
+ "license": "MIT",
17
+ "overrides": {
18
+ "@stoplight/prism-cli": {
19
+ "@stoplight/json": "3.21.0"
20
+ }
21
+ },
22
+ "devDependencies": {
23
+ "@voxgig/model": "^3.2.0",
24
+ "@voxgig/sdkgen": "^0.6.0",
25
+ "@voxgig/util": "^0.0.3",
26
+ "@types/node": "22.5.4",
27
+ "@stoplight/prism-cli": "^5.9.0",
28
+ "typescript": "^5.5.4"
29
+ }
30
+ }
@@ -0,0 +1,60 @@
1
+
2
+ import {
3
+ names,
4
+ cmp,
5
+ each,
6
+
7
+ Project,
8
+ Folder,
9
+
10
+ Main,
11
+ Entity,
12
+ Readme,
13
+
14
+ } from '@voxgig/sdkgen'
15
+
16
+ // import { Readme } from './Readme'
17
+ // import { Main } from './Main'
18
+ // import { Entity } from './Entity'
19
+
20
+
21
+ const Root = cmp(function Root(props: any) {
22
+ const { model, ctx$ } = props
23
+
24
+ names(model, model.name)
25
+
26
+ // console.dir(model, { depth: null })
27
+
28
+ ctx$.model = model
29
+
30
+ const build = model.main.sdk.build
31
+ const entity = model.main.sdk.entity
32
+
33
+ Project({}, () => {
34
+
35
+ each(build, (build: any) => {
36
+ names(build, build.name)
37
+ // console.log('BUILD', build.name)
38
+
39
+ Folder({ name: build.name }, () => {
40
+
41
+ each(entity, (entity: any) => {
42
+ names(entity, entity.name)
43
+ // console.log('ENTITY', entity.name)
44
+
45
+ Entity({ build, entity })
46
+ })
47
+
48
+ Main({ build })
49
+
50
+ Readme({ build })
51
+ })
52
+ })
53
+ })
54
+ })
55
+
56
+
57
+ export {
58
+ Root
59
+ }
60
+
@@ -0,0 +1,226 @@
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
+ }
@@ -0,0 +1,26 @@
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
+ }