@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,81 +0,0 @@
1
- import { cmp, camelify, Content } from '@voxgig/sdkgen';
2
-
3
-
4
-
5
- const TestAcceptEntity = cmp(function TestEntity(props: any) {
6
- const { entity, ctx$: { model } } = props;
7
-
8
- entity.Name = camelify(entity.name);
9
-
10
- Content(`
11
- <?php
12
- use PHPUnit\\Framework\\TestCase;
13
- use Dotenv\\Dotenv;
14
- use ${model.Name}\\Client;
15
-
16
- class Test${entity.Name}AcceptList extends TestCase {
17
-
18
- protected function setUp(): void {
19
- \$dotenv = Dotenv::createImmutable(__DIR__);
20
- \$dotenv->load();
21
- }
22
-
23
- public function test${entity.Name}AcceptList() {
24
- \$endpoint = getenv('${model.NAME}_ENDPOINT');
25
- \$apikey = getenv('${model.NAME}_APIKEY');
26
-
27
- \$client = new Client([
28
- 'endpoint' => \$endpoint,
29
- 'apikey' => \$apikey
30
- ]);
31
-
32
- \$entities = \$client->${entity.Name}()->list();
33
-
34
- if (empty(\$entities)) {
35
- \$this->fail("Error getting ${entity.name} accept list length == 0");
36
- }
37
-
38
- \$got = \$entities[0]['data'];
39
-
40
- if (empty(\$got['id'])) {
41
- \$this->fail("Error getting ${entity.name} accept list - id equal to empty string");
42
- }
43
- }
44
- }
45
-
46
- class Test${entity.Name}AcceptLoad extends TestCase {
47
-
48
- protected function setUp(): void {
49
- \$dotenv = Dotenv::createImmutable(__DIR__);
50
- \$dotenv->load();
51
- }
52
-
53
- public function test${entity.Name}AcceptLoad() {
54
- \$endpoint = getenv('${model.NAME}_ENDPOINT');
55
- \$apikey = getenv('${model.NAME}_APIKEY');
56
-
57
- \$client = new Client([
58
- 'endpoint' => \$endpoint,
59
- 'apikey' => \$apikey
60
- ]);
61
-
62
- \$data = [
63
- 'id' => 't01'
64
- ];
65
-
66
- \$${entity.name} = \$client->${entity.Name}()->load(\$data);
67
-
68
- \$got = \$${entity.name}['data'];
69
-
70
- if (empty(\$got['id'])) {
71
- \$this->fail("Error getting ${entity.name} accept load - id equal to empty string");
72
- }
73
- }
74
- }
75
- ?>
76
- `);
77
- });
78
-
79
- export {
80
- TestAcceptEntity
81
- };
@@ -1,33 +0,0 @@
1
- import { cmp, each, File, Content } from '@voxgig/sdkgen';
2
-
3
-
4
- import { TestAcceptEntity } from './TestAcceptEntity_php'
5
-
6
-
7
- const TestAccept = cmp(function TestMain(props: any) {
8
- const { build } = props;
9
- const { model } = props.ctx$;
10
-
11
- File({ name: model.name + 'sdk_accept_test.' + build.name }, () => {
12
- Content(`
13
- <?php
14
- namespace ${model.name}_test;
15
-
16
- use PHPUnit\\Framework\\TestCase;
17
- use Dotenv\\Dotenv;
18
- use ${model.Name}\\Client;
19
- `);
20
-
21
- each(model.main.sdk.entity, (entity: any) => {
22
- TestAcceptEntity({ model, build, entity });
23
- });
24
-
25
- Content(`
26
- ?>
27
- `);
28
- });
29
- });
30
-
31
- export {
32
- TestAccept
33
- };
@@ -1,64 +0,0 @@
1
- import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
2
-
3
-
4
-
5
- const TestEntity = cmp(function TestEntity(props: any) {
6
- const { build, entity, ctx$: { model } } = props
7
-
8
- Folder({ name: 'tests' }, () => {
9
-
10
- File({ name: entity.Name + 'Test.' + build.name }, () => {
11
-
12
- Content(`<?php
13
- // ${model.Name} ${build.Name} ${entity.Name} Test
14
-
15
- use PHPUnit\Framework\TestCase;
16
- use ${model.Name}SDK\\${model.Name}SDK;
17
- use ${model.Name}SDK\\${entity.Name};
18
-
19
- class ${entity.Name}Test extends TestCase {
20
-
21
- protected \$sdk;
22
- protected \$${entity.Name.toLowerCase()};
23
-
24
- protected function setUp(): void {
25
- \$options = [
26
- 'apikey' => 'your_api_key',
27
- 'endpoint' => 'https://api.${model.name}.com'
28
- ];
29
-
30
- \$this->sdk = new ${model.Name}SDK(\$options);
31
- \$this->${entity.Name.toLowerCase()} = new ${entity.Name}(\$this->sdk);
32
- }
33
-
34
- public function testSave${entity.Name}() {
35
- \$data = ['name' => 'Test ${entity.Name}'];
36
- \$result = \$this->${entity.Name.toLowerCase()}->save(\$data);
37
- \$this->assertEquals('Test ${entity.Name}', \$result->data['name']);
38
- }
39
-
40
- public function testLoad${entity.Name}() {
41
- \$data = ['id' => '123'];
42
- \$result = \$this->${entity.Name.toLowerCase()}->load(\$data);
43
- \$this->assertEquals('123', \$result->data['id']);
44
- }
45
-
46
- public function testList${entity.Name}s() {
47
- \$result = \$this->${entity.Name.toLowerCase()}->list();
48
- \$this->assertIsArray(\$result->data);
49
- }
50
-
51
- public function testRemove${entity.Name}() {
52
- \$data = ['id' => '123'];
53
- \$result = \$this->${entity.Name.toLowerCase()}->remove(\$data);
54
- \$this->assertNull(\$result->data);
55
- }
56
- }
57
- ?>`)
58
- })
59
- })
60
- })
61
-
62
- export {
63
- TestEntity
64
- }
@@ -1,120 +0,0 @@
1
-
2
- import { cmp, each, File, Content } from '@voxgig/sdkgen'
3
-
4
-
5
- import { TestEntity } from './TestEntity_php'
6
-
7
-
8
- const TestMain = cmp(function TestMain(props: any) {
9
- const { build } = props
10
- const { model } = props.ctx$
11
-
12
-
13
- File({ name: model.name + 'SDK.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', ()=>{
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
- TestEntity({ model, build, entity })
34
- })
35
-
36
-
37
- Content(`
38
- })
39
-
40
-
41
- function makeClient(config) {
42
- const client = ${model.Name}SDK.make({
43
- endpoint: 'https://host/api/v1/rest/project_id/plant/stage',
44
- apikey: 'apikey',
45
- fetch,
46
- ...config
47
- })
48
-
49
- return client
50
- }
51
-
52
- async function fetch(url, config) {
53
- const parts = url.split('/')
54
- const entname = parts[9]
55
- const entid = parts[10]
56
- const data = JSON.parse(config.body||'{}')
57
- const method = config.method || 'GET'
58
-
59
- const req$ = {
60
- url,
61
- parts,
62
- entname,
63
- entid,
64
- method,
65
- data,
66
- }
67
-
68
- console.log('REQ', req$)
69
-
70
- return {
71
- req$,
72
- status: 200,
73
- json: async function() {
74
- if('PUT'=== method||'POST'===method) {
75
- return entid ? {
76
- id: entid,
77
- title: data.title,
78
- } :
79
- {
80
- id: 'n01',
81
- title: data.title || 'T01',
82
- }
83
- }
84
- else if('GET'===method) {
85
- return entid ? {
86
- id: entid,
87
- title: 'T01'
88
- } :
89
- {
90
- name: entname,
91
- list: [
92
- {
93
- id: 'n01',
94
- title: 'N01'
95
- },
96
- {
97
- id: 'n01',
98
- title: 'N01'
99
- },
100
- ]
101
- }
102
- }
103
- else {
104
- return {}
105
- }
106
- }
107
- }
108
- }
109
-
110
-
111
- `)
112
-
113
- })
114
- })
115
-
116
-
117
- export {
118
- TestMain
119
- }
120
-
@@ -1,21 +0,0 @@
1
-
2
- import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
3
-
4
- import { Quick } from './Quick_php'
5
- import { TestMain } from './TestMain_php'
6
-
7
-
8
- const Test = cmp(function Test(props: any) {
9
- const { build } = props
10
-
11
- Folder({ name: 'test' }, () => {
12
-
13
- Quick({ build })
14
- TestMain({ build })
15
- })
16
- })
17
-
18
-
19
- export {
20
- Test
21
- }
@@ -1,98 +0,0 @@
1
-
2
- import { cmp, File, Content, Folder } 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
- // console.log('build.name: ', entity.Name, build.name)
10
-
11
- Folder({ name: 'src/' + model.name + '_sdk' }, () => {
12
-
13
- File({ name: entity.Name + '.' + build.extension }, () => {
14
-
15
- Content(`
16
-
17
- # from pydantic import BaseModel
18
- # from .Model import Data
19
-
20
- # ${model.Name} ${build.Name} ${entity.Name}
21
-
22
- class ${entity.Name}:
23
- def __init__(self, sdk, data = {}):
24
- self.sdk = sdk
25
- self.definition = {
26
- 'name': '${entity.name}'
27
- }
28
- self.id = data.get('id') or ''
29
- self.data = data
30
-
31
- def handle_result(self, op, res, spec, handler):
32
- status = res['status']
33
- if(200 == status):
34
- json = res['json']
35
-
36
- return handler(json)
37
- else:
38
- raise Exception('HTTP-ERROR: ' + op + ' ${entity.name}: ' + str(status))
39
-
40
- def create(self, data):
41
- op = 'create'
42
- self.data = data
43
- # TODO: validate data
44
-
45
- spec = self.sdk.fetchSpec(op, self)
46
- res = self.sdk.options.fetch(spec['url'], spec)
47
-
48
- return self.handle_result(op, res, spec, lambda json: json)
49
-
50
- def save(self, data):
51
- op = 'save'
52
- self.data = data
53
- # TODO: validate data
54
-
55
- spec = self.sdk.fetchSpec(op, self)
56
- res = self.sdk.options.fetch(spec['url'], spec)
57
-
58
- return self.handle_result(op, res, spec, lambda json: json)
59
-
60
- def load(self, data):
61
- op = 'load'
62
- self.data = data
63
- # TODO: validate data
64
-
65
- spec = self.sdk.fetchSpec(op, self)
66
- res = self.sdk.options.fetch(spec['url'], spec)
67
-
68
- return self.handle_result(op, res, spec, lambda json: json)
69
-
70
- def list(self, data = {}):
71
- op = 'list'
72
- self.data = data
73
- # TODO: validate data
74
-
75
- spec = self.sdk.fetchSpec(op, self)
76
- res = self.sdk.options.fetch(spec['url'], spec)
77
-
78
- return self.handle_result(op, res, spec, lambda json: json)
79
-
80
- def remove(self, data):
81
- op = 'remove'
82
- self.data = data
83
- # TODO: validate data
84
-
85
- spec = self.sdk.fetchSpec(op, self)
86
- res = self.sdk.options.fetch(spec['url'], spec)
87
-
88
- return self.handle_result(op, res, spec, lambda json: json)
89
-
90
- `)
91
- })
92
- })
93
- })
94
-
95
-
96
- export {
97
- Entity
98
- }
@@ -1,19 +0,0 @@
1
- import { cmp, each, File, Content } from '@voxgig/sdkgen'
2
-
3
-
4
- const MainEntity = cmp(async function MainEntity(props: any) {
5
- const { entity } = props
6
-
7
- const def = JSON.stringify(entity)
8
-
9
- Content(`
10
- def ${entity.Name}(self):
11
- return ${entity.Name}(self, json.loads('''${def}'''))
12
- `)
13
-
14
- })
15
-
16
-
17
- export {
18
- MainEntity
19
- }
@@ -1,211 +0,0 @@
1
-
2
-
3
- import { cmp, each, camelify, File, Content, Folder, Copy } from '@voxgig/sdkgen'
4
-
5
- import { MainEntity } from './MainEntity_py'
6
- import { Test } from './Test_py'
7
-
8
-
9
- const config_setup_files = [
10
- 'setup.py',
11
- 'pyproject.toml',
12
- 'requirements.txt',
13
- 'setup.cfg',
14
- 'MANIFEST.in',
15
- 'Makefile',
16
- 'pytest.ini'
17
- ]
18
-
19
- const Main = cmp(async function Main(props: any) {
20
- const { build, ctx$: { model } } = props
21
-
22
- const entity = model.main.sdk.entity
23
-
24
-
25
- Test({ build })
26
-
27
- for (let config_file of config_setup_files) {
28
- Copy({ from: 'tm/' + build.name + '/' + config_file, name: config_file })
29
- }
30
-
31
- File({ name: '.env.test.local' }, () => {
32
- Content(`
33
- ${model.Name}_ENDPOINT=example.com
34
- ${model.Name}_ENDPOINT_PRISM=http://127.0.0.1:4010/a/b/c
35
- ${model.Name}_APIKEY=pqapikey
36
- `)
37
-
38
- })
39
-
40
- Folder({ name: 'src/' + model.name + '_sdk' }, () => {
41
-
42
- File({ name: '__init__.py' }, () => {
43
- Content(`from .${model.Name}SDK import *
44
- from .Model import Config
45
- from .Model import Data
46
- from .Model import Query
47
-
48
- `)
49
-
50
- each(entity, (entity: any) => {
51
- entity.Name = camelify(entity.name)
52
- // console.log('entity.Name: ', entity)
53
- Content(`from .${entity.Name} import ${entity.Name}
54
- `)
55
-
56
- })
57
-
58
- Content(`__doc__ = 'An example SDK'
59
- `)
60
-
61
-
62
- })
63
-
64
- File({ name: 'Model.py' }, () => {
65
- Content(`
66
- from typing import Any, Callable
67
-
68
- from pydantic import BaseModel, Field, ConfigDict, ValidationError
69
-
70
-
71
- class Config(BaseModel):
72
- endpoint: str = Field(validate_default=True)
73
- apikey: str = Field(validate_default=True)
74
- fetch: Callable = Field(validate_default=True)
75
-
76
- model_config = ConfigDict(extra='allow')
77
-
78
- class Data(BaseModel):
79
- id: str = Field(default=None, validate_default=False)
80
- model_config = ConfigDict(extra='allow')
81
-
82
- class Query(BaseModel):
83
- id: str = Field(default=None, validate_default=False)
84
- model_config = ConfigDict(extra='allow')
85
-
86
- `)
87
-
88
- })
89
-
90
-
91
- File({ name: model.Name + 'SDK.' + build.extension }, () => {
92
-
93
- /*
94
- const validate_options = each(build.options)
95
- .reduce((a: string, opt: any) =>
96
- a + ('String' === opt.kind ?
97
- ` required(str, '${opt.name}', options)\n` : ''), '')
98
- */
99
-
100
- const imports = `
101
- import json
102
-
103
- `
104
- Content(`${imports}`)
105
-
106
- each(entity, (entity: any) => {
107
- entity.Name = camelify(entity.name)
108
- Content(`from .${entity.Name} import ${entity.Name}
109
- `)
110
- })
111
-
112
-
113
- /*
114
- // Replaced by pydantic
115
- Content(`
116
- def required(type_class, name, options):
117
- val = options[name]
118
- if(type_class != type(val)):
119
- raise Exception('${model.Name}SDK: Invalid option: '+name+'='+val+': must be of type '+ str(type_class))
120
-
121
- `)
122
- */
123
-
124
- Content(`
125
-
126
- from pydantic import BaseModel
127
- # from .Model import Data
128
-
129
- # ${model.Name} ${build.Name} SDK
130
-
131
-
132
- class ${model.Name}SDK:
133
- def __init__(self, options):
134
- self.options = options
135
-
136
-
137
- @staticmethod
138
- def make(options):
139
- return ${model.Name}SDK(options)
140
-
141
- def endpoint(self, op, ent):
142
- data = ent.data
143
- id = None
144
- # print("ent.data: ", type(ent.data) == Data, isinstance(ent.data, Data), isinstance(ent.data, BaseModel))
145
- if dict == type(ent.data):
146
- id = ent.data.get('id')
147
- elif isinstance(ent.data, BaseModel):
148
- id = ent.data.id
149
-
150
- return (
151
- self.options.endpoint
152
- + "/"
153
- + ent.definition.get("name")
154
- + ((id and (op == 'load' or op == 'delete') and "/" + id) or "")
155
- )
156
-
157
- def method(self, op, ent=None):
158
- key = op
159
- if (None == ent or None == ent.id) and "save" == op:
160
- key = "create"
161
-
162
- if "create" == key:
163
- return "POST"
164
- elif "save" == key:
165
- return "PUT"
166
- elif "load" == key or "list" == key:
167
- return "GET"
168
- elif "remove" == key:
169
- return "DELETE"
170
-
171
- def body(self, op, ent):
172
- # msg = {}
173
- # msg.update(ent.data)
174
- # print('body ent.data: ', ent.data)
175
-
176
- if dict == type(ent.data):
177
- # return json.dumps(ent.data)
178
- return ent.data
179
- elif isinstance(ent.data, BaseModel):
180
- return ent.data.model_dump(exclude_none=True)
181
- # return ent.data.model_dump_json(exclude_none=True)
182
-
183
-
184
- def fetchSpec(self, op, ent):
185
- method = self.method(op, ent)
186
- spec = {
187
- "url": self.endpoint(op, ent),
188
- "method": method,
189
- "headers": {
190
- "content-type": "application/json",
191
- "authorization": "Bearer " + self.options.apikey,
192
- },
193
- "body": ("GET" == method and {}) or self.body(op, ent),
194
- }
195
- return spec
196
-
197
- `)
198
-
199
- each(entity, (entity: any) => {
200
- MainEntity({ model, build, entity })
201
- })
202
-
203
-
204
- })
205
- })
206
- })
207
-
208
-
209
- export {
210
- Main
211
- }