@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.
- package/bin/voxgig-create-sdkgen +196 -0
- package/dist/create-sdkgen.d.ts +11 -8
- package/dist/create-sdkgen.js +61 -63
- package/dist/create-sdkgen.js.map +1 -1
- package/dist/standard/ModelSdk.js +8 -61
- package/dist/standard/ModelSdk.js.map +1 -1
- package/dist/standard/Root.js +58 -57
- package/dist/standard/Root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -10
- package/src/create-sdkgen.ts +56 -74
- package/src/standard/ModelSdk.ts +9 -71
- package/src/standard/Root.ts +26 -68
- package/bin/run-create-sdkgen.js +0 -269
- package/bin/run-create-sdkgen.js~ +0 -1
- package/src/standard/ModelSdk.ts~ +0 -1
- package/src/standard/Root.ts~ +0 -3
- package/src/utility.ts +0 -8
- package/tm/standard/.env.local +0 -2
- package/tm/standard/build/sdk.js +0 -25
- package/tm/standard/def/DEFINITION.md +0 -2
- package/tm/standard/model/.model-config/model-config.jsonic +0 -13
- package/tm/standard/model/go.jsonic +0 -6
- package/tm/standard/model/js.jsonic +0 -6
- package/tm/standard/model/php.jsonic +0 -6
- package/tm/standard/model/py.jsonic +0 -7
- package/tm/standard/model/rb.jsonic +0 -6
- package/tm/standard/model/sdk.jsonic.off +0 -60
- package/tm/standard/package.json +0 -30
- package/tm/standard/src/Root.ts +0 -60
- package/tm/standard/src/go/Entity_go.ts +0 -226
- package/tm/standard/src/go/MainEntity_go.ts +0 -26
- package/tm/standard/src/go/Main_go.ts +0 -168
- package/tm/standard/src/go/Quick_go.ts +0 -108
- package/tm/standard/src/go/ReadmeInstall_go.ts +0 -19
- package/tm/standard/src/go/ReadmeQuick_go.ts +0 -45
- package/tm/standard/src/go/TestAcceptEntity_go.ts +0 -219
- package/tm/standard/src/go/TestAccept_go.ts +0 -38
- package/tm/standard/src/go/TestEntity_go.ts +0 -79
- package/tm/standard/src/go/TestMain_go.ts +0 -61
- package/tm/standard/src/go/Test_go.ts +0 -20
- package/tm/standard/src/js/Entity_js.ts +0 -135
- package/tm/standard/src/js/MainEntity_js.ts +0 -22
- package/tm/standard/src/js/Main_js.ts +0 -128
- package/tm/standard/src/js/Quick_js.ts +0 -72
- package/tm/standard/src/js/ReadmeInstall_js.ts +0 -19
- package/tm/standard/src/js/ReadmeQuick_js.ts +0 -27
- package/tm/standard/src/js/TestAcceptEntity_js.ts +0 -101
- package/tm/standard/src/js/TestAccept_js.ts +0 -60
- package/tm/standard/src/js/TestEntity_js.ts +0 -24
- package/tm/standard/src/js/TestMain_js.ts +0 -123
- package/tm/standard/src/js/Test_js.ts +0 -24
- package/tm/standard/src/php/Entity_php.ts +0 -97
- package/tm/standard/src/php/MainEntity_php.ts +0 -43
- package/tm/standard/src/php/Main_php.ts +0 -50
- package/tm/standard/src/php/Quick_php.ts +0 -59
- package/tm/standard/src/php/TestAcceptEntity_php.ts +0 -81
- package/tm/standard/src/php/TestAccept_php.ts +0 -33
- package/tm/standard/src/php/TestEntity_php.ts +0 -64
- package/tm/standard/src/php/TestMain_php.ts +0 -120
- package/tm/standard/src/php/Test_php.ts +0 -21
- package/tm/standard/src/py/Entity_py.ts +0 -98
- package/tm/standard/src/py/MainEntity_py.ts +0 -19
- package/tm/standard/src/py/Main_py.ts +0 -211
- package/tm/standard/src/py/Quick_py.ts +0 -133
- package/tm/standard/src/py/TestAcceptEntity_py.ts +0 -47
- package/tm/standard/src/py/TestAccept_py.ts +0 -77
- package/tm/standard/src/py/TestEntity_py.ts +0 -50
- package/tm/standard/src/py/TestMain_py.ts +0 -103
- package/tm/standard/src/py/Test_py.ts +0 -28
- package/tm/standard/src/rb/Client_rb.ts +0 -142
- package/tm/standard/src/rb/Entity_rb.ts +0 -153
- package/tm/standard/src/rb/Error_rb.ts +0 -56
- package/tm/standard/src/rb/MainEntity_rb.ts +0 -16
- package/tm/standard/src/rb/Main_rb.ts +0 -55
- package/tm/standard/src/rb/Quick_rb.ts +0 -65
- package/tm/standard/src/rb/ReadmeInstall_rb.ts +0 -19
- package/tm/standard/src/rb/ReadmeQuick_rb.ts +0 -30
- package/tm/standard/src/rb/TestAcceptEntity_rb.ts +0 -83
- package/tm/standard/src/rb/TestAccept_rb.ts +0 -45
- package/tm/standard/src/rb/TestEntity_rb.ts +0 -82
- package/tm/standard/src/rb/TestMain_rb.ts +0 -67
- package/tm/standard/src/rb/Test_rb.ts +0 -27
- package/tm/standard/src/tsconfig.json +0 -15
- package/tm/standard/tm/go/.env.example +0 -2
- package/tm/standard/tm/go/LICENSE +0 -22
- package/tm/standard/tm/go/go.mod +0 -5
- package/tm/standard/tm/go/go.sum +0 -2
- package/tm/standard/tm/js/LICENSE +0 -22
- package/tm/standard/tm/js/package.json +0 -17
- package/tm/standard/tm/php/LICENSE +0 -22
- package/tm/standard/tm/py/LICENSE +0 -22
- package/tm/standard/tm/py/MANIFEST.in +0 -4
- package/tm/standard/tm/py/Makefile +0 -14
- package/tm/standard/tm/py/pyproject.toml +0 -4
- package/tm/standard/tm/py/pytest.ini +0 -3
- package/tm/standard/tm/py/requirements.txt +0 -4
- package/tm/standard/tm/py/setup.cfg +0 -2
- package/tm/standard/tm/py/setup.py +0 -82
- package/tm/standard/tm/rb/.rspec +0 -1
- package/tm/standard/tm/rb/Gemfile +0 -21
- package/tm/standard/tm/rb/LICENSE +0 -22
- package/tm/standard/tm/rb/Rakefile +0 -6
- package/tm/standard/tm/rb/spec/spec_helper.rb +0 -22
- package/tm/standard/tm/rb/tm.gemspec +0 -39
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cmp,
|
|
3
|
-
File,
|
|
4
|
-
Content,
|
|
5
|
-
Folder,
|
|
6
|
-
snakify,
|
|
7
|
-
} from '@voxgig/sdkgen';
|
|
8
|
-
|
|
9
|
-
const Entity = cmp(function Entity(props: any) {
|
|
10
|
-
const { build, entity } = props;
|
|
11
|
-
const { model } = props.ctx$;
|
|
12
|
-
|
|
13
|
-
Folder({ name: "lib" }, () => {
|
|
14
|
-
Folder({ name: snakify(model.Name) + "_sdk" }, () => {
|
|
15
|
-
File({ name: snakify(entity.Name) + ".rb" }, () => {
|
|
16
|
-
Content(`
|
|
17
|
-
# ${model.Name} ${build.Name} ${entity.Name}
|
|
18
|
-
|
|
19
|
-
require 'json'
|
|
20
|
-
require 'net/http'
|
|
21
|
-
|
|
22
|
-
class ${entity.Name}
|
|
23
|
-
attr_accessor :sdk, :def, :data
|
|
24
|
-
|
|
25
|
-
def initialize(sdk, data = nil)
|
|
26
|
-
@sdk = sdk
|
|
27
|
-
@def = {
|
|
28
|
-
name: "${entity.name}"
|
|
29
|
-
}
|
|
30
|
-
@data = data
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def handle_result(op, res, spec)
|
|
34
|
-
status = res.code.to_i
|
|
35
|
-
|
|
36
|
-
case status
|
|
37
|
-
when 200
|
|
38
|
-
json = JSON.parse(res.body, symbolize_names: true)
|
|
39
|
-
yield(json)
|
|
40
|
-
when 400
|
|
41
|
-
raise ${model.Name}BadRequestError.new("Bad request", status, res.body)
|
|
42
|
-
when 401
|
|
43
|
-
raise ${model.Name}AuthenticationError.new("Authentication failed", status, res.body)
|
|
44
|
-
when 404
|
|
45
|
-
raise ${model.Name}NotFoundError.new("Resource not found", status, res.body)
|
|
46
|
-
when 429
|
|
47
|
-
raise ${model.Name}RateLimitError.new("Rate limit exceeded", status, res.body)
|
|
48
|
-
when 400..499
|
|
49
|
-
raise ${model.Name}ClientError.new("Client error", status, res.body)
|
|
50
|
-
when 500..599
|
|
51
|
-
raise ${model.Name}ServerError.new("Server error", status, res.body)
|
|
52
|
-
else
|
|
53
|
-
raise ${model.Name}SDKError.new("HTTP-ERROR: #{op}: ${entity.name}: #{status}", status, res.body)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def save(data)
|
|
58
|
-
op = 'save'
|
|
59
|
-
self.data = data
|
|
60
|
-
# TODO: validate data
|
|
61
|
-
|
|
62
|
-
body = sdk.body('save', self)
|
|
63
|
-
method = sdk.method('save', self)
|
|
64
|
-
url = sdk.endpoint('save', self)
|
|
65
|
-
|
|
66
|
-
spec = {}
|
|
67
|
-
res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
|
|
68
|
-
|
|
69
|
-
handle_result(op, res, spec) do |json|
|
|
70
|
-
self.data = json
|
|
71
|
-
self
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def create(data)
|
|
76
|
-
op = 'create'
|
|
77
|
-
self.data = data
|
|
78
|
-
|
|
79
|
-
body = sdk.body('create', self)
|
|
80
|
-
method = sdk.method('create', self)
|
|
81
|
-
url = sdk.endpoint('create', self)
|
|
82
|
-
|
|
83
|
-
spec = {}
|
|
84
|
-
res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
|
|
85
|
-
|
|
86
|
-
handle_result(op, res, spec) do |json|
|
|
87
|
-
self.data = json
|
|
88
|
-
self
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def load(data)
|
|
93
|
-
op = 'load'
|
|
94
|
-
self.data = data
|
|
95
|
-
# TODO: check if data.id is defined
|
|
96
|
-
|
|
97
|
-
body = sdk.body('load', self)
|
|
98
|
-
method = sdk.method('load', self)
|
|
99
|
-
url = sdk.endpoint('load', self)
|
|
100
|
-
|
|
101
|
-
spec = {}
|
|
102
|
-
res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
|
|
103
|
-
|
|
104
|
-
handle_result(op, res, spec) do |json|
|
|
105
|
-
self.data = json
|
|
106
|
-
self
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def list(data = {})
|
|
111
|
-
op = 'list'
|
|
112
|
-
self.data = data
|
|
113
|
-
# TODO: check if data.id is defined
|
|
114
|
-
|
|
115
|
-
body = sdk.body('load', self)
|
|
116
|
-
method = sdk.method('load', self)
|
|
117
|
-
url = sdk.endpoint('load', self)
|
|
118
|
-
|
|
119
|
-
spec = {}
|
|
120
|
-
res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
|
|
121
|
-
|
|
122
|
-
handle_result(op, res, spec) do |json|
|
|
123
|
-
return json[:list].map { |data| sdk.${entity.Name}(data) }
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def remove(data)
|
|
128
|
-
op = 'remove'
|
|
129
|
-
self.data = data
|
|
130
|
-
|
|
131
|
-
body = sdk.body('remove', self)
|
|
132
|
-
method = sdk.method('remove', self)
|
|
133
|
-
url = sdk.endpoint('remove', self)
|
|
134
|
-
|
|
135
|
-
spec = {}
|
|
136
|
-
res = sdk.options[:fetch].call(url, method, sdk.options[:apikey], body)
|
|
137
|
-
|
|
138
|
-
handle_result(op, res, spec) do |json|
|
|
139
|
-
self.data = json
|
|
140
|
-
self
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
`);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
export { Entity };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cmp,
|
|
3
|
-
File,
|
|
4
|
-
Content,
|
|
5
|
-
Folder,
|
|
6
|
-
snakify,
|
|
7
|
-
} from '@voxgig/sdkgen';
|
|
8
|
-
|
|
9
|
-
const Error = cmp(function Error(props: any) {
|
|
10
|
-
const { build, entity } = props;
|
|
11
|
-
const { model } = props.ctx$;
|
|
12
|
-
|
|
13
|
-
Folder({ name: "lib" }, () => {
|
|
14
|
-
Folder({ name: snakify(model.Name) + "_sdk" }, () => {
|
|
15
|
-
File({ name: "errors.rb" }, () => {
|
|
16
|
-
Content(`
|
|
17
|
-
|
|
18
|
-
module ${model.Name}SDK
|
|
19
|
-
class ${model.Name}SDKError < StandardError
|
|
20
|
-
attr_reader :status, :body, :response
|
|
21
|
-
|
|
22
|
-
def initialize(message, status = nil, body = nil, response = nil)
|
|
23
|
-
super(message)
|
|
24
|
-
@status = status
|
|
25
|
-
@body = body
|
|
26
|
-
@response = response
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def to_s
|
|
30
|
-
"#{message} (status: #{status || 'N/A'}, response body: #{body || 'N/A'})"
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Network errors
|
|
35
|
-
class ${model.Name}NetworkError < ${model.Name}SDKError; end
|
|
36
|
-
class ${model.Name}TimeoutError < ${model.Name}SDKError; end
|
|
37
|
-
|
|
38
|
-
# API errors
|
|
39
|
-
class ${model.Name}BadRequestError < ${model.Name}SDKError; end
|
|
40
|
-
class ${model.Name}AuthenticationError < ${model.Name}SDKError; end
|
|
41
|
-
class ${model.Name}NotFoundError < ${model.Name}SDKError; end
|
|
42
|
-
class ${model.Name}RateLimitError < ${model.Name}SDKError; end
|
|
43
|
-
class ${model.Name}ClientError < ${model.Name}SDKError; end
|
|
44
|
-
class ${model.Name}ServerError < ${model.Name}SDKError; end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
`);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
export { Error };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { cmp, Content } from '@voxgig/sdkgen';
|
|
2
|
-
|
|
3
|
-
const MainEntity = cmp(async function MainEntity(props: any) {
|
|
4
|
-
const { entity } = props;
|
|
5
|
-
|
|
6
|
-
const def = JSON.stringify(entity);
|
|
7
|
-
|
|
8
|
-
Content(`
|
|
9
|
-
def ${entity.Name}(data={})
|
|
10
|
-
${entity.Name}.new(self, data)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
`);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export { MainEntity };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cmp,
|
|
3
|
-
File,
|
|
4
|
-
Content,
|
|
5
|
-
Copy,
|
|
6
|
-
Folder,
|
|
7
|
-
snakify,
|
|
8
|
-
} from '@voxgig/sdkgen';
|
|
9
|
-
|
|
10
|
-
import { Test } from "./Test_rb";
|
|
11
|
-
import { Error } from "./Error_rb";
|
|
12
|
-
import { Client } from './Client_rb';
|
|
13
|
-
|
|
14
|
-
const Main = cmp(async function Main(props: any) {
|
|
15
|
-
const { build } = props;
|
|
16
|
-
const { model } = props.ctx$;
|
|
17
|
-
|
|
18
|
-
Copy({ from: "tm/" + build.name + "/Gemfile", name: "Gemfile" });
|
|
19
|
-
Copy({ from: "tm/" + build.name + "/" + 'tm.gemspec', name: snakify(model.Name) + "_sdk.gemspec" });
|
|
20
|
-
Copy({ from: "tm/" + build.name + "/Rakefile", name: "Rakefile" });
|
|
21
|
-
|
|
22
|
-
Test({ build });
|
|
23
|
-
Error({ model, build });
|
|
24
|
-
Client({ model, build });
|
|
25
|
-
|
|
26
|
-
Folder({ name: "lib" }, () => {
|
|
27
|
-
File({ name: snakify(model.Name) + "_sdk.rb" }, () => {
|
|
28
|
-
Content(`
|
|
29
|
-
# ${model.Name} ${build.Name} SDK
|
|
30
|
-
`);
|
|
31
|
-
|
|
32
|
-
Content(`
|
|
33
|
-
|
|
34
|
-
require_relative "${model.name}_sdk/client"
|
|
35
|
-
|
|
36
|
-
module ${model.Name}SDK
|
|
37
|
-
class << self
|
|
38
|
-
attr_accessor :options
|
|
39
|
-
|
|
40
|
-
def options
|
|
41
|
-
@options ||= {}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def configure
|
|
45
|
-
yield self
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
`);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export { Main };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { cmp, File, Content } from '@voxgig/sdkgen';
|
|
2
|
-
|
|
3
|
-
const Quick = cmp(function Quick(props: any) {
|
|
4
|
-
const { build } = props;
|
|
5
|
-
const { model } = props.ctx$;
|
|
6
|
-
|
|
7
|
-
File({ name: "quick.rb" }, () => {
|
|
8
|
-
Content(`
|
|
9
|
-
require 'dotenv'
|
|
10
|
-
Dotenv.load
|
|
11
|
-
require_relative '../lib/${model.name}_sdk'
|
|
12
|
-
|
|
13
|
-
def run
|
|
14
|
-
|
|
15
|
-
client = ${model.Name}SDK::Client.new(
|
|
16
|
-
{
|
|
17
|
-
endpoint: ENV['${model.NAME}_ENDPOINT'],
|
|
18
|
-
apikey: ENV['${model.NAME}_APIKEY'],
|
|
19
|
-
}
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
# Test listing assets
|
|
23
|
-
out = client.Geofence.list()
|
|
24
|
-
puts "Geofence.list: #{out.inspect}\n\n"
|
|
25
|
-
|
|
26
|
-
# Test loading an asset
|
|
27
|
-
out = client.Geofence.load({id: 1})
|
|
28
|
-
puts "Geofence.load: #{out.inspect}\n\n"
|
|
29
|
-
|
|
30
|
-
# Check if endpoint includes localhost
|
|
31
|
-
if ENV['${model.NAME}_ENDPOINT'].include? 'localhost'
|
|
32
|
-
# Test creating an asset
|
|
33
|
-
out = client.Geofence.create({
|
|
34
|
-
id: 'CF49B47C-317B-4387-83C3-4A23715B1C45',
|
|
35
|
-
name: 'Geofence 1',
|
|
36
|
-
desc: 'Geofence 1 description',
|
|
37
|
-
custom: { foo: 'bar' },
|
|
38
|
-
extent_id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'
|
|
39
|
-
})
|
|
40
|
-
puts "Geofence.create: #{out.inspect}\n\n"
|
|
41
|
-
|
|
42
|
-
# Test updating an asset
|
|
43
|
-
out = client.Geofence.save({
|
|
44
|
-
id: 'CF49B47C-317B-4387-83C3-4A23715B1C45',
|
|
45
|
-
name: 'Geofence 1',
|
|
46
|
-
desc: 'Geofence 1 description',
|
|
47
|
-
custom: { foo: 'bar' },
|
|
48
|
-
extent_id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'
|
|
49
|
-
})
|
|
50
|
-
puts "Geofence.save: #{out.inspect}\n\n"
|
|
51
|
-
|
|
52
|
-
# Test deleting an asset
|
|
53
|
-
out = client.Geofence.remove({id: 'CF49B47C-317B-4387-83C3-4A23715B1C45'})
|
|
54
|
-
puts "Geofence.remove: #{out.inspect}\n\n"
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
run
|
|
60
|
-
|
|
61
|
-
`);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
export { Quick };
|
|
@@ -1,19 +0,0 @@
|
|
|
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('```ruby')
|
|
9
|
-
Content(`
|
|
10
|
-
gem install ${build.module.name}
|
|
11
|
-
`)
|
|
12
|
-
Content('```')
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
ReadmeInstall
|
|
19
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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('```ruby')
|
|
9
|
-
Content(`
|
|
10
|
-
require('${build.module.name}')
|
|
11
|
-
|
|
12
|
-
client = ${model.Name}SDK::Client.new(
|
|
13
|
-
{
|
|
14
|
-
endpoint: ENV['${model.NAME}_ENDPOINT'],
|
|
15
|
-
apikey: ENV['${model.NAME}_APIKEY'],
|
|
16
|
-
}
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
# List all buildings
|
|
20
|
-
buildings = client.Building.list()
|
|
21
|
-
puts "Buildings: #{buildings.inspect}"
|
|
22
|
-
`)
|
|
23
|
-
Content('```')
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
ReadmeQuick
|
|
30
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
describe '${entity.name}-load' do
|
|
12
|
-
it 'loads the entity correctly' do
|
|
13
|
-
out = @client.${entity.Name}.load(id: 't01')
|
|
14
|
-
# puts '${entity.name}-load', out
|
|
15
|
-
|
|
16
|
-
expect(out.data).to be_a(Hash)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '${entity.name}-list' do
|
|
21
|
-
it 'lists the entity correctly' do
|
|
22
|
-
out = @client.${entity.Name}.list
|
|
23
|
-
# puts '${entity.name}-list', out
|
|
24
|
-
|
|
25
|
-
expect(out).to be_a(Array)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '${entity.name}-create' do
|
|
30
|
-
it 'creates the entity correctly' do
|
|
31
|
-
out = @client.${entity.Name}.create(${JSON.stringify(generateObjectFromFields(entity.field))})
|
|
32
|
-
# puts '${entity.name}-create', out
|
|
33
|
-
|
|
34
|
-
expect(out.data).to be_a(Hash)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe '${entity.name}-save' do
|
|
39
|
-
it 'saves the entity correctly' do
|
|
40
|
-
out = @client.${entity.Name}.save(${JSON.stringify(generateObjectFromFields(entity.field))})
|
|
41
|
-
# puts '${entity.name}-save', out
|
|
42
|
-
|
|
43
|
-
expect(out.data).to be_a(Hash)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe '${entity.name}-remove' do
|
|
48
|
-
it 'removes the entity correctly' do
|
|
49
|
-
out = @client.${entity.Name}.remove(id: 't01')
|
|
50
|
-
# puts '${entity.name}-remove', out
|
|
51
|
-
|
|
52
|
-
expect(out.data).to be_a(Hash)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
`);
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
function generateObjectFromFields(fields: any) {
|
|
60
|
-
const getRandomString = (length: number): string =>
|
|
61
|
-
Array.from({ length }, () => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'.charAt(Math.floor(Math.random() * 62))).join('');
|
|
62
|
-
|
|
63
|
-
const defaultValues: Record<string, any> = {
|
|
64
|
-
number: Math.floor(Math.random() * 100),
|
|
65
|
-
string: getRandomString(5),
|
|
66
|
-
object: { [getRandomString(3)]: getRandomString(3) },
|
|
67
|
-
boolean: Math.random() > 0.5,
|
|
68
|
-
array: Array.from({ length: 3 }, () => getRandomString(3)),
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const result: Record<string, any> = {}
|
|
72
|
-
|
|
73
|
-
for (const key in fields) {
|
|
74
|
-
result[key] = defaultValues[fields[key].type] ?? null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return result
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export {
|
|
82
|
-
TestAcceptEntity
|
|
83
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, each, File, Content } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { TestAcceptEntity } from "./TestAcceptEntity_rb"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const TestAccept = cmp(function TestMain_js(props: any) {
|
|
9
|
-
const { build } = props
|
|
10
|
-
const { model } = props.ctx$
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
File({ name: model.name + '_sdk_spec.rb' }, () => {
|
|
14
|
-
|
|
15
|
-
Content(`
|
|
16
|
-
RSpec.describe '${model.Name}SDK::Client Acceptance Tests' do
|
|
17
|
-
before(:each) do
|
|
18
|
-
@client = ${model.Name}SDK::Client.new(
|
|
19
|
-
apikey: ENV['${model.NAME}_APIKEY'],
|
|
20
|
-
endpoint: ENV['${model.NAME}_ENDPOINT']
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'happy' do
|
|
25
|
-
out = @client.Geofence.load(id: 'gf01')
|
|
26
|
-
# puts 'Geofence-load', out.inspect
|
|
27
|
-
expect(out.data[:id]).to eq('gf01')
|
|
28
|
-
end
|
|
29
|
-
`)
|
|
30
|
-
|
|
31
|
-
each(model.main.sdk.entity, (entity: any) => {
|
|
32
|
-
TestAcceptEntity({ model, build, entity })
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
Content(`end`)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
TestAccept
|
|
44
|
-
}
|
|
45
|
-
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cmp,
|
|
3
|
-
camelify,
|
|
4
|
-
Content,
|
|
5
|
-
} from '@voxgig/sdkgen';
|
|
6
|
-
|
|
7
|
-
const TestEntity = cmp(function TestEntity(props: any) {
|
|
8
|
-
const { entity, model } = props;
|
|
9
|
-
|
|
10
|
-
entity.Name = camelify(entity.name);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Content(`
|
|
14
|
-
describe '${entity.name}-load' do
|
|
15
|
-
it 'loads the entity with the correct data' do
|
|
16
|
-
stub_request(:get, "http://example.com/${entity.name}/t01")
|
|
17
|
-
.to_return(body: { id: 't01', title: 'T01' }.to_json, headers: { 'Content-Type' => 'application/json' })
|
|
18
|
-
|
|
19
|
-
out = @client.${entity.Name}.load(id: 't01')
|
|
20
|
-
expect(out.data).to eq({ id: 't01', title: 'T01' })
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe '${entity.name}-list' do
|
|
25
|
-
it 'lists the entities with the correct data' do
|
|
26
|
-
stub_request(:get, "http://example.com/${entity.name}")
|
|
27
|
-
.to_return(body: {name: '${entity.name}' ,list:[{ id: 't01', title: 'T01' }, { id: 't02', title: 'T02' }]}.to_json, headers: { 'Content-Type' => 'application/json' })
|
|
28
|
-
|
|
29
|
-
out = @client.${entity.Name}.list
|
|
30
|
-
expect(out).to be_an(Array)
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
`);
|
|
35
|
-
|
|
36
|
-
// const entityTestCases: Record<string,any> = {
|
|
37
|
-
// create: {
|
|
38
|
-
// requestBody: `{ id: 't01', title: 'T01' }`,
|
|
39
|
-
// responseBody: `{ id: 't01', title: 'T01' }`,
|
|
40
|
-
// description: 'creates the entity with the correct data'
|
|
41
|
-
// },
|
|
42
|
-
// save: {
|
|
43
|
-
// requestBody: `{ id: 't01', title: 'T01' }`,
|
|
44
|
-
// responseBody: `{ id: 't01', title: 'T01' }`,
|
|
45
|
-
// description: 'saves the entity with the correct data'
|
|
46
|
-
// },
|
|
47
|
-
// load: {
|
|
48
|
-
// idParam: 't01',
|
|
49
|
-
// requestBody: `{ id: 't01' }`,
|
|
50
|
-
// responseBody: `{ id: 't01', title: 'T01' }`,
|
|
51
|
-
// description: 'loads the entity with the correct data'
|
|
52
|
-
// },
|
|
53
|
-
// list: {
|
|
54
|
-
// responseBody: `{ name: '${entity.name}', list: [{ id: 't01', title: 'T01' }, { id: 't02', title: 'T02' }]}`,
|
|
55
|
-
// description: 'lists the entities with the correct data'
|
|
56
|
-
// },
|
|
57
|
-
// remove: {
|
|
58
|
-
// idParam: 't01',
|
|
59
|
-
// requestBody: `{ id: 't01' }`,
|
|
60
|
-
// description: 'removes the entity with the correct data'
|
|
61
|
-
// },
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
// Object.keys(entity.op).forEach((op: any) => {
|
|
65
|
-
// const testData = entityTestCases[op];
|
|
66
|
-
// Content(`
|
|
67
|
-
|
|
68
|
-
// describe('${entity.name}-${op}') do
|
|
69
|
-
// it '${testData.description}' do
|
|
70
|
-
// stub_request(:${entity.op[op].method}, "http://example.com/${entity.name}${testData.idParam ? `/${testData.idParam}` : ''}")
|
|
71
|
-
// .to_return(body: ${testData.responseBody ? testData.responseBody : `''`}.to_json, headers: { 'Content-Type' => 'application/json' })
|
|
72
|
-
|
|
73
|
-
// out = @client.${entity.Name}().${op}(${testData.requestBody ? testData.requestBody : ``})
|
|
74
|
-
// expect(${op == 'list' ? 'out' : 'out.data'}).to eq(${testData.responseBody ? testData.responseBody : ''})
|
|
75
|
-
// end
|
|
76
|
-
// end
|
|
77
|
-
|
|
78
|
-
// `);
|
|
79
|
-
// })
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export { TestEntity };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cmp,
|
|
3
|
-
each,
|
|
4
|
-
File,
|
|
5
|
-
Content,
|
|
6
|
-
snakify,
|
|
7
|
-
} from '@voxgig/sdkgen';
|
|
8
|
-
|
|
9
|
-
import { TestEntity } from './TestEntity_rb'
|
|
10
|
-
|
|
11
|
-
const TestMain = cmp(function TestMain(props: any) {
|
|
12
|
-
const { build } = props
|
|
13
|
-
const { model } = props.ctx$
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
File({ name: snakify(model.name) + "_sdk_spec.rb" }, () => {
|
|
17
|
-
Content(`
|
|
18
|
-
RSpec.describe '${model.Name}SDK::Client Unit Tests' do
|
|
19
|
-
before(:each) do
|
|
20
|
-
${model.Name}SDK.configure do |config|
|
|
21
|
-
config.options = {
|
|
22
|
-
endpoint: 'http://example.com',
|
|
23
|
-
apikey: 'test_api_key',
|
|
24
|
-
}
|
|
25
|
-
end
|
|
26
|
-
@client = ${model.Name}SDK::Client.new
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '.configure' do
|
|
30
|
-
it 'creates a new client with the given options' do
|
|
31
|
-
expected_options = { apikey: 'test_api_key', endpoint: 'http://example.com' }
|
|
32
|
-
expect(@client).to be_a(${model.Name}SDK::Client)
|
|
33
|
-
expect(@client.options).to include(expected_options)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'merges the options with the default options' do
|
|
37
|
-
expected_options = { apikey: 'another_api_key', endpoint: 'http://example.com' }
|
|
38
|
-
another_client = ${model.Name}SDK::Client.new(apikey: 'another_api_key')
|
|
39
|
-
expect(another_client.options).to include(expected_options)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe '#initialize' do
|
|
44
|
-
it 'sets the options' do
|
|
45
|
-
expected_options = { apikey: 'test_api_key', endpoint: 'http://example.com' }
|
|
46
|
-
expect(@client.options).to include(expected_options)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
`);
|
|
51
|
-
|
|
52
|
-
each(model.main.sdk.entity, (entity: any) => {
|
|
53
|
-
TestEntity({ model, build, entity });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
Content(`
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
`);
|
|
61
|
-
});
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
export {
|
|
65
|
-
TestMain
|
|
66
|
-
}
|
|
67
|
-
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { cmp, File, Content, Folder, Copy } from '@voxgig/sdkgen'
|
|
3
|
-
|
|
4
|
-
import { Quick } from './Quick_rb'
|
|
5
|
-
import { TestMain } from './TestMain_rb'
|
|
6
|
-
import { TestAccept } from './TestAccept_rb'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const Test = cmp(function Test(props: any) {
|
|
10
|
-
const { build } = props
|
|
11
|
-
|
|
12
|
-
Copy({ from: "tm/" + build.name + "/.rspec", name: ".rspec" });
|
|
13
|
-
|
|
14
|
-
Folder({ name: 'spec' }, () => {
|
|
15
|
-
Copy({ from: "tm/" + build.name + "/spec/spec_helper.rb", name: "spec_helper.rb" });
|
|
16
|
-
Quick({ build })
|
|
17
|
-
TestMain({ build })
|
|
18
|
-
Folder({ name: 'integration' }, () => {
|
|
19
|
-
TestAccept({ build })
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
Test
|
|
27
|
-
}
|