@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,61 @@
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
+
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,135 @@
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
+ }
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,128 @@
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
+ }
@@ -0,0 +1,72 @@
1
+
2
+ import { names, getx, cmp, File, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const Quick = cmp(function Quick(props: any) {
6
+ const { build } = props
7
+ const { model, meta: { spec } } = props.ctx$
8
+
9
+ // get quick entity from build config
10
+
11
+ // console.log('CONFIG 2')
12
+ // console.dir(spec.config, { depth: null })
13
+
14
+
15
+ const ent = getx(spec.config, 'entity *').find((ent: any) => ent.test.quick.active)
16
+ names(ent, ent.key$)
17
+
18
+ console.log('ENT 3', ent)
19
+
20
+ File({ name: 'quick.' + build.name }, () => {
21
+
22
+ Content(`
23
+ // ENT 3
24
+ require('dotenv').config({ path: ['../../.env.local']})
25
+
26
+ const { ${model.Name}SDK } = require('../')
27
+
28
+ run()
29
+
30
+ async function run() {
31
+ const client = ${model.Name}SDK.make({
32
+ endpoint: process.env.${model.NAME}_ENDPOINT,
33
+ apikey: process.env.${model.NAME}_APIKEY,
34
+ })
35
+
36
+ let out
37
+
38
+ `)
39
+
40
+ if (ent.test.quick.create) {
41
+ Content(`
42
+ out = await client.${ent.Name}().create(${JSON.stringify(ent.test.quick.create)})
43
+ console.log('${ent.Name}.load', out)
44
+ `)
45
+ }
46
+
47
+ if (ent.test.quick.load) {
48
+ Content(`
49
+ out = await client.${ent.Name}().load(${JSON.stringify(ent.test.quick.load)})
50
+ console.log('${ent.Name}.load', out)
51
+ `)
52
+ }
53
+
54
+ if (ent.test.quick.list) {
55
+ Content(`
56
+ out = await client.${ent.Name}().list(${JSON.stringify(ent.test.quick.list)})
57
+ console.log('${ent.Name}.list', out)
58
+ `)
59
+ }
60
+
61
+ Content(`
62
+ }
63
+ `)
64
+
65
+ })
66
+ })
67
+
68
+
69
+ export {
70
+ Quick
71
+ }
72
+
@@ -0,0 +1,19 @@
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('```js')
9
+ Content(`
10
+ npm install ${build.module.name}
11
+ `)
12
+ Content('```')
13
+
14
+ })
15
+
16
+
17
+ export {
18
+ ReadmeInstall
19
+ }
@@ -0,0 +1,27 @@
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('```js')
9
+ Content(`
10
+ const { ${model.Name}SDK } = require('${build.module.name}')
11
+
12
+ const client = ${model.Name}SDK.make({
13
+ endpoint: process.env.${model.NAME}_ENDPOINT,
14
+ apikey: process.env.${model.NAME}_APIKEY,
15
+ })
16
+
17
+ let buildings = await client.Building().list()
18
+ console.log('Buildings', buildings)
19
+ `)
20
+ Content('```')
21
+
22
+ })
23
+
24
+
25
+ export {
26
+ ReadmeQuick
27
+ }
@@ -0,0 +1,101 @@
1
+
2
+ import { cmp, camelify, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const TestAcceptEntity = cmp(function TestEntity(props: any) {
6
+ const { entity } = props
7
+
8
+ entity.Name = camelify(entity.name)
9
+
10
+ Content(`
11
+ test('${entity.name}-load', async ()=>{
12
+ const client = makeClient()
13
+ const out = await client.${entity.Name}().load({id:'t01'})
14
+ //console.log('${entity.name}-load', 'out', out)
15
+
16
+ // equal(out.status, 200, 'Expected status code 200');
17
+
18
+ // Check out.data is an object
19
+ equal(typeof out.data, 'object', 'Expected data to be an object');
20
+
21
+ // Check out.data has id
22
+ equal(typeof out.data.id, 'string', 'Expected data to have an id');
23
+
24
+ })
25
+
26
+ test('${entity.name}-list', async ()=>{
27
+ const client = makeClient()
28
+ const out = await client.${entity.Name}().list()
29
+ //console.log('${entity.name}-list', 'out', out)
30
+
31
+ // Check out is an array
32
+ equal(Array.isArray(out), true, 'Expected an array');
33
+
34
+ // Check out.data is an object
35
+ equal(typeof out[0], 'object', 'Expected data to be an object');
36
+
37
+ // Check out.data has id
38
+ equal(typeof out[0].data.id, 'string', 'Expected data to have an id');
39
+ })
40
+
41
+ test('${entity.name}-create', async ()=>{
42
+ const client = makeClient()
43
+ const out = await client.${entity.Name}().create(${JSON.stringify(generateObjectFromFields(entity.field))})
44
+ //console.log('${entity.name}-create', 'out', out)
45
+
46
+ // Check out is an object
47
+ equal(typeof out, 'object', 'Expected an object');
48
+
49
+ // Check out.data has id
50
+ equal(typeof out.data.id, 'string', 'Expected data to have an id');
51
+ })
52
+
53
+ test('${entity.name}-save', async ()=>{
54
+ const client = makeClient()
55
+ const out = await client.${entity.Name}().save(${JSON.stringify(generateObjectFromFields(entity.field))})
56
+ //console.log('${entity.name}-save', 'out', out)
57
+
58
+ // Check out is an object
59
+ equal(typeof out, 'object', 'Expected an object');
60
+
61
+ // Check out.data has id
62
+ equal(typeof out.data.id, 'string', 'Expected data to have an id');
63
+ })
64
+
65
+ test('${entity.name}-remove', async ()=>{
66
+ const client = makeClient()
67
+ const out = await client.${entity.Name}().remove({id:'t01'})
68
+ //console.log('${entity.name}-remove', 'out', out)
69
+
70
+ // Check out is an object
71
+ equal(typeof out, 'object', 'Expected an object');
72
+ })
73
+
74
+ `);
75
+ })
76
+
77
+ function generateObjectFromFields(fields: any) {
78
+ const getRandomString = (length: number): string =>
79
+ Array.from({ length }, () => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random() * 62))).join('');
80
+
81
+ const defaultValues: Record<string, any> = {
82
+ number: Math.floor(Math.random() * 100),
83
+ string: getRandomString(5),
84
+ object: { [getRandomString(3)]: getRandomString(3) },
85
+ boolean: Math.random() > 0.5,
86
+ array: Array.from({ length: 3 }, () => getRandomString(3)),
87
+ }
88
+
89
+ const result: Record<string, any> = {}
90
+
91
+ for (const key in fields) {
92
+ result[key] = defaultValues[fields[key].type] ?? null;
93
+ }
94
+
95
+ return result
96
+ }
97
+
98
+
99
+ export {
100
+ TestAcceptEntity
101
+ }
@@ -0,0 +1,60 @@
1
+
2
+ import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ import { TestAcceptEntity } from './TestAcceptEntity_js'
6
+
7
+
8
+ const TestAccept = cmp(function TestMain(props: any) {
9
+ const { build } = props
10
+ const { model } = props.ctx$
11
+
12
+
13
+ File({ name: model.Name + 'SDK.accept.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 Acceptance Tests', ()=>{
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
+ TestAcceptEntity({ model, build, entity })
34
+ })
35
+
36
+
37
+ Content(`
38
+ })
39
+
40
+
41
+ function makeClient(config) {
42
+ const client = ${model.Name}SDK.make({
43
+ endpoint: process.env.${model.NAME}_ENDPOINT,
44
+ apikey: process.env.${model.NAME}_APIKEY,
45
+ ...config
46
+ })
47
+
48
+ return client
49
+ }
50
+
51
+ `)
52
+
53
+ })
54
+ })
55
+
56
+
57
+ export {
58
+ TestAccept
59
+ }
60
+
@@ -0,0 +1,24 @@
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
+ test('${entity.name}-load', async ()=>{
12
+ const client = makeClient()
13
+ const out = await client.${entity.Name}().load({id:'t01'})
14
+ console.log('${entity.name}-load', out)
15
+ deepEqual(out.data,{id:'t01',title:'T01'})
16
+ })
17
+
18
+ `)
19
+ })
20
+
21
+
22
+ export {
23
+ TestEntity
24
+ }