@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,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
- }
@@ -1,103 +0,0 @@
1
-
2
- import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
-
4
-
5
- import { TestEntity } from './TestEntity_py'
6
-
7
-
8
- const TestMain = cmp(function TestMain(props: any) {
9
- const { build } = props
10
- const { model } = props.ctx$
11
-
12
- File({ name: 'Fetch.' + build.extension }, () => {
13
-
14
- Content(`
15
- import json
16
-
17
- def fetch(url, config):
18
- parts = url.split("/")
19
- # print('parts: ', parts)
20
- entname = None
21
- entid = None
22
-
23
- try:
24
- # TODO: PARTS DEPEND ON THE SWAGGERS: add logic
25
- # A utility for url parsing is needed
26
- entname = parts[1]
27
- entid = parts[2]
28
- except IndexError:
29
- pass
30
-
31
- data = config.get("body") or {}
32
- method = config.get("method") or "GET"
33
-
34
- req = {
35
- "url": url,
36
- "parts": parts,
37
- "entname": entname,
38
- "entid": entid,
39
- "method": method,
40
- "data": data,
41
- }
42
-
43
- json_data = None
44
- if "GET" == method:
45
- if None != entid:
46
- json_data = {"id": entid, "title": "T01"}
47
- else:
48
- json_data = {
49
- "name": entname,
50
- "list": [{"id": "n01", "title": "N01"}, {"id": "n02", "title": "N02"}],
51
- }
52
- elif "PUT" == method or "POST" == method:
53
- if None != entid:
54
- json_data = { "id": entid, "title": data.get('title') }
55
- else:
56
- json_data = { "id": "n03", "title": data.get('title') or "T03" }
57
-
58
- return {"req": req, "status": 200, "json": json_data}
59
- `)
60
-
61
- })
62
-
63
- File({ name: 'test_' + model.name + '_sdk.' + build.extension }, () => {
64
-
65
- Content(`
66
- import json
67
-
68
- from dotenv import dotenv_values
69
-
70
- import ${model.name}_sdk
71
-
72
- from ${model.name}_sdk import Config
73
-
74
- from Fetch import fetch
75
-
76
-
77
- def makeClient(config = {}):
78
- client = ${model.name}_sdk.${model.Name}SDK.make(Config(
79
- endpoint=config.get('${model.NAME}_ENDPOINT'),
80
- apikey=config.get('${model.NAME}_APIKEY'),
81
- fetch=fetch
82
- ))
83
- return client
84
-
85
- `)
86
- Content(`
87
- def test_happy():
88
- config = dotenv_values('.env.test.local')
89
- client = makeClient(config)
90
- `)
91
- each(model.main.sdk.entity, (entity: any) => {
92
- TestEntity({ model, build, entity })
93
- })
94
-
95
-
96
- })
97
- })
98
-
99
-
100
- export {
101
- TestMain
102
- }
103
-
@@ -1,28 +0,0 @@
1
- import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
2
-
3
-
4
- import { Quick } from './Quick_py'
5
- import { TestMain } from './TestMain_py'
6
- import { TestAccept } from './TestAccept_py'
7
-
8
-
9
- const Test = cmp(function Test_(props: any) {
10
- const { build } = props
11
-
12
- Folder({ name: 'tests' }, () => {
13
-
14
- Quick({ build })
15
- TestMain({ build })
16
-
17
- Folder({ name: 'accept' }, () => {
18
- TestAccept({ build })
19
- })
20
-
21
- })
22
-
23
- })
24
-
25
-
26
- export {
27
- Test
28
- }
@@ -1,142 +0,0 @@
1
- import {
2
- cmp,
3
- each,
4
- camelify,
5
- File,
6
- Content,
7
- Folder,
8
- snakify,
9
- } from '@voxgig/sdkgen';
10
-
11
-
12
- import { MainEntity } from './MainEntity_rb'
13
-
14
-
15
- const Client = cmp(async function Client(props: any) {
16
- const { build } = props;
17
- const { model } = props.ctx$;
18
-
19
- const entity = model.main.sdk.entity;
20
-
21
- Folder({ name: "lib" }, () => {
22
- Folder({ name: snakify(model.Name) + "_sdk" }, () => {
23
- File({ name: "client.rb" }, () => {
24
- Content(`
25
- # ${model.Name} ${build.Name} SDK
26
-
27
- require 'json'
28
- require 'net/http'
29
- `);
30
-
31
- each(entity, (entity: any) => {
32
- entity.Name = camelify(entity.name);
33
- Content(`
34
- require_relative './${snakify(entity.Name)}'
35
- `);
36
- });
37
-
38
- const validate_options = each(build.options).reduce(
39
- (a: string, opt: any) =>
40
- a +
41
- ("String" === opt.kind
42
- ? ` required('String','${opt.name}', @options)\n`
43
- : ""),
44
- ""
45
- );
46
-
47
- Content(`
48
- module ${model.Name}SDK
49
- class Client
50
- attr_reader :options
51
-
52
- def initialize(opts = {})
53
- @options = ${model.Name}SDK.options.merge(opts)
54
- ${validate_options}
55
- @options[:fetch] ||= ->(url, method, apikey, body = nil) {
56
- default_fetch(url, method, apikey, body)
57
- }
58
- end
59
-
60
- def endpoint(op, ent)
61
- data = ent.data
62
- definition = ent.def
63
- base_url = "#{options[:endpoint]}/#{definition[:name]}"
64
-
65
- if (op == 'load' || op == 'remove') && data[:id] != nil
66
- "#{base_url}/#{data[:id]}"
67
- else
68
- base_url
69
- end
70
- end
71
-
72
- def method(op, ent)
73
- ent.nil? && op == 'save' ? 'create' : op
74
- {
75
- 'create' => 'POST',
76
- 'save' => 'PUT',
77
- 'load' => 'GET',
78
- 'list' => 'GET',
79
- 'remove' => 'DELETE'
80
- }[op]
81
- end
82
-
83
- def body(op, ent)
84
- msg = ent.data.dup
85
- JSON.generate(msg)
86
- end
87
-
88
- `);
89
-
90
- each(entity, (entity: any) => {
91
- MainEntity({ model, build, entity });
92
- });
93
-
94
- Content(`
95
-
96
- private
97
-
98
- def required(type, name, options)
99
- val = options[name.to_sym]
100
- unless val.is_a?(Object.const_get(type))
101
- raise ArgumentError, "${model.Name}SDK: Invalid option: #{name}=#{val}: must be of type #{type}"
102
- end
103
- end
104
-
105
- def default_fetch(url, method, apikey, body = nil)
106
- uri = URI(url)
107
- http = Net::HTTP.new(uri.host, uri.port)
108
- http.use_ssl = (uri.scheme == "https")
109
-
110
- request = build_request(uri, method, apikey, body)
111
-
112
- begin
113
- response = http.request(request)
114
- response
115
- rescue SocketError => e
116
- raise ${model.Name}NetworkError.new("Network unreachable: #{e.message}")
117
- rescue Timeout::Error => e
118
- raise ${model.Name}TimeoutError.new("Request timed out: #{e.message}")
119
- rescue StandardError => e
120
- raise ${model.Name}SDKError.new("Unexpected error: #{e.message}")
121
- end
122
- end
123
-
124
- def build_request(uri, method, apikey, body)
125
- request = Net::HTTP.const_get(method.capitalize).new(uri)
126
- request['Content-Type'] = 'application/json'
127
- request['Authorization'] = "Bearer #{apikey}"
128
- request.body = body if %i[post put].include?(method.downcase.to_sym) && body
129
- request
130
- end
131
- end
132
- end
133
-
134
- `);
135
- });
136
- });
137
- });
138
- });
139
-
140
-
141
- export { Client };
142
-