@voxgig/sdkgen 0.43.0 → 0.45.0
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-sdkgen +1 -1
- package/dist/cmp/ReadmeEntity.js +9 -153
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +9 -14
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeModel.js +6 -4
- package/dist/cmp/ReadmeModel.js.map +1 -1
- package/dist/cmp/ReadmeOptions.js +9 -61
- package/dist/cmp/ReadmeOptions.js.map +1 -1
- package/dist/cmp/ReadmeRef.js +10 -1328
- package/dist/cmp/ReadmeRef.js.map +1 -1
- package/dist/sdkgen.d.ts +2 -2
- package/dist/sdkgen.js +2 -1
- package/dist/sdkgen.js.map +1 -1
- package/dist/utility.d.ts +2 -1
- package/dist/utility.js +9 -0
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/project/.sdk/src/cmp/go/Config_go.ts +9 -4
- package/project/.sdk/src/cmp/go/Gitignore_go.ts +47 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +3 -0
- package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +138 -0
- package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +6 -3
- package/project/.sdk/src/cmp/go/ReadmeIntro_go.ts +18 -0
- package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +6 -3
- package/project/.sdk/src/cmp/go/ReadmeOptions_go.ts +58 -0
- package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +11 -7
- package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +354 -0
- package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +6 -4
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +18 -8
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +105 -54
- package/project/.sdk/src/cmp/js/Config_js.ts +18 -0
- package/project/.sdk/src/cmp/js/Gitignore_js.ts +35 -0
- package/project/.sdk/src/cmp/js/Main_js.ts +3 -0
- package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +138 -0
- package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +11 -6
- package/project/.sdk/src/cmp/js/ReadmeIntro_js.ts +18 -0
- package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +6 -3
- package/project/.sdk/src/cmp/js/ReadmeOptions_js.ts +58 -0
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +6 -4
- package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +384 -0
- package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +6 -4
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +23 -12
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +107 -74
- package/project/.sdk/src/cmp/js/fragment/Config.fragment.js +1 -5
- package/project/.sdk/src/cmp/lua/Config_lua.ts +9 -4
- package/project/.sdk/src/cmp/lua/Gitignore_lua.ts +39 -0
- package/project/.sdk/src/cmp/lua/Main_lua.ts +3 -0
- package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +138 -0
- package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +6 -3
- package/project/.sdk/src/cmp/lua/ReadmeIntro_lua.ts +18 -0
- package/project/.sdk/src/cmp/lua/ReadmeModel_lua.ts +6 -3
- package/project/.sdk/src/cmp/lua/ReadmeOptions_lua.ts +58 -0
- package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +6 -4
- package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +360 -0
- package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +6 -4
- package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +18 -8
- package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +95 -51
- package/project/.sdk/src/cmp/php/Config_php.ts +10 -8
- package/project/.sdk/src/cmp/php/Gitignore_php.ts +33 -0
- package/project/.sdk/src/cmp/php/Main_php.ts +3 -0
- package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +138 -0
- package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +6 -3
- package/project/.sdk/src/cmp/php/ReadmeIntro_php.ts +18 -0
- package/project/.sdk/src/cmp/php/ReadmeModel_php.ts +6 -3
- package/project/.sdk/src/cmp/php/ReadmeOptions_php.ts +58 -0
- package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +6 -4
- package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +358 -0
- package/project/.sdk/src/cmp/php/ReadmeTopQuick_php.ts +6 -4
- package/project/.sdk/src/cmp/php/TestDirect_php.ts +18 -8
- package/project/.sdk/src/cmp/php/TestEntity_php.ts +101 -54
- package/project/.sdk/src/cmp/py/Config_py.ts +9 -4
- package/project/.sdk/src/cmp/py/Gitignore_py.ts +55 -0
- package/project/.sdk/src/cmp/py/Main_py.ts +3 -0
- package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +138 -0
- package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +6 -3
- package/project/.sdk/src/cmp/py/ReadmeIntro_py.ts +18 -0
- package/project/.sdk/src/cmp/py/ReadmeModel_py.ts +6 -3
- package/project/.sdk/src/cmp/py/ReadmeOptions_py.ts +58 -0
- package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +9 -6
- package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +356 -0
- package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +9 -6
- package/project/.sdk/src/cmp/py/TestDirect_py.ts +18 -8
- package/project/.sdk/src/cmp/py/TestEntity_py.ts +100 -50
- package/project/.sdk/src/cmp/rb/Config_rb.ts +9 -4
- package/project/.sdk/src/cmp/rb/Gitignore_rb.ts +38 -0
- package/project/.sdk/src/cmp/rb/Main_rb.ts +3 -0
- package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +138 -0
- package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +6 -3
- package/project/.sdk/src/cmp/rb/ReadmeIntro_rb.ts +18 -0
- package/project/.sdk/src/cmp/rb/ReadmeModel_rb.ts +6 -3
- package/project/.sdk/src/cmp/rb/ReadmeOptions_rb.ts +58 -0
- package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +6 -4
- package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +361 -0
- package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +6 -4
- package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +18 -8
- package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +95 -51
- package/project/.sdk/src/cmp/ts/Config_ts.ts +18 -0
- package/project/.sdk/src/cmp/ts/Gitignore_ts.ts +37 -0
- package/project/.sdk/src/cmp/ts/Main_ts.ts +3 -0
- package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +138 -0
- package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +11 -6
- package/project/.sdk/src/cmp/ts/ReadmeIntro_ts.ts +18 -0
- package/project/.sdk/src/cmp/ts/ReadmeModel_ts.ts +9 -5
- package/project/.sdk/src/cmp/ts/ReadmeOptions_ts.ts +58 -0
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +6 -4
- package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +384 -0
- package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +6 -4
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +68 -20
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +109 -74
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +1 -5
- package/project/.sdk/tm/go/utility/prepare_auth.go +15 -1
- package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +7 -1
- package/project/.sdk/tm/lua/utility/prepare_auth.lua +9 -1
- package/project/.sdk/tm/php/utility/PrepareAuth.php +11 -1
- package/project/.sdk/tm/py/utility/prepare_auth.py +10 -1
- package/project/.sdk/tm/rb/utility/prepare_auth.rb +8 -1
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +7 -8
- package/project/.sdk/tm/ts/src/utility/PrepareAuthUtility.ts +7 -1
- package/src/cmp/ReadmeEntity.ts +11 -178
- package/src/cmp/ReadmeIntro.ts +11 -25
- package/src/cmp/ReadmeModel.ts +7 -5
- package/src/cmp/ReadmeOptions.ts +12 -74
- package/src/cmp/ReadmeRef.ts +11 -1372
- package/src/sdkgen.ts +2 -1
- package/src/utility.ts +12 -0
- /package/project/.sdk/tm/go/utility/{make_target.go → make_point.go} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, Content } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const ReadmeOptions = cmp(function ReadmeOptions(props: any) {
|
|
6
|
+
const { target } = props
|
|
7
|
+
const { model } = props.ctx$
|
|
8
|
+
|
|
9
|
+
const publishedOptions = each(target.options).filter((option: any) => option.publish)
|
|
10
|
+
if (0 === publishedOptions.length) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Content(`
|
|
15
|
+
|
|
16
|
+
## Options
|
|
17
|
+
|
|
18
|
+
Pass options when creating a client instance:
|
|
19
|
+
|
|
20
|
+
`)
|
|
21
|
+
|
|
22
|
+
Content(`\`\`\`lua
|
|
23
|
+
local client = sdk.new({
|
|
24
|
+
`)
|
|
25
|
+
|
|
26
|
+
publishedOptions.map((option: any) => {
|
|
27
|
+
if ('apikey' === option.name) {
|
|
28
|
+
Content(` ${option.name} = os.getenv("${model.NAME}_APIKEY"),
|
|
29
|
+
`)
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
Content(` -- ${option.name} = ${option.kind === 'string' ? '"..."' : '...'},
|
|
33
|
+
`)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
Content(`})
|
|
38
|
+
\`\`\`
|
|
39
|
+
|
|
40
|
+
`)
|
|
41
|
+
|
|
42
|
+
Content(`| Option | Type | Description |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
`)
|
|
45
|
+
|
|
46
|
+
publishedOptions.map((option: any) => {
|
|
47
|
+
Content(`| \`${option.name}\` | \`${option.kind}\` | ${option.short} |
|
|
48
|
+
`)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
Content(`
|
|
52
|
+
`)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
ReadmeOptions
|
|
58
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { cmp, each, Content } from '@voxgig/sdkgen'
|
|
2
|
+
import { cmp, each, Content, isAuthActive } from '@voxgig/sdkgen'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
KIT,
|
|
@@ -18,14 +18,16 @@ const ReadmeQuick = cmp(function ReadmeQuick(props: any) {
|
|
|
18
18
|
e.active !== false && e.ancestors && e.ancestors.length > 0
|
|
19
19
|
) as any
|
|
20
20
|
|
|
21
|
+
const apikeyArg = isAuthActive(model)
|
|
22
|
+
? `\n apikey = os.getenv("${model.NAME}_APIKEY"),\n`
|
|
23
|
+
: ''
|
|
24
|
+
|
|
21
25
|
Content(`### 1. Create a client
|
|
22
26
|
|
|
23
27
|
\`\`\`lua
|
|
24
28
|
local sdk = require("${model.name}_sdk")
|
|
25
29
|
|
|
26
|
-
local client = sdk.new({
|
|
27
|
-
apikey = os.getenv("${model.NAME}_APIKEY"),
|
|
28
|
-
})
|
|
30
|
+
local client = sdk.new({${apikeyArg}})
|
|
29
31
|
\`\`\`
|
|
30
32
|
|
|
31
33
|
`)
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, Content, File, isAuthActive } from '@voxgig/sdkgen'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
KIT,
|
|
6
|
+
getModelPath,
|
|
7
|
+
} from '@voxgig/apidef'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const OP_SIGNATURES: Record<string, { sig: string, returns: string, desc: string }> = {
|
|
11
|
+
load: {
|
|
12
|
+
sig: 'load(reqmatch, ctrl) -> any, err',
|
|
13
|
+
returns: 'any, err',
|
|
14
|
+
desc: 'Load a single entity matching the given criteria.',
|
|
15
|
+
},
|
|
16
|
+
list: {
|
|
17
|
+
sig: 'list(reqmatch, ctrl) -> any, err',
|
|
18
|
+
returns: 'any, err',
|
|
19
|
+
desc: 'List entities matching the given criteria. Returns an array.',
|
|
20
|
+
},
|
|
21
|
+
create: {
|
|
22
|
+
sig: 'create(reqdata, ctrl) -> any, err',
|
|
23
|
+
returns: 'any, err',
|
|
24
|
+
desc: 'Create a new entity with the given data.',
|
|
25
|
+
},
|
|
26
|
+
update: {
|
|
27
|
+
sig: 'update(reqdata, ctrl) -> any, err',
|
|
28
|
+
returns: 'any, err',
|
|
29
|
+
desc: 'Update an existing entity. The data must include the entity `id`.',
|
|
30
|
+
},
|
|
31
|
+
remove: {
|
|
32
|
+
sig: 'remove(reqmatch, ctrl) -> any, err',
|
|
33
|
+
returns: 'any, err',
|
|
34
|
+
desc: 'Remove the entity matching the given criteria.',
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const ReadmeRef = cmp(function ReadmeRef(props: any) {
|
|
40
|
+
const { target } = props
|
|
41
|
+
const { model } = props.ctx$
|
|
42
|
+
|
|
43
|
+
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
44
|
+
const feature = getModelPath(model, `main.${KIT}.feature`)
|
|
45
|
+
|
|
46
|
+
const publishedEntities = each(entity).filter((e: any) => e.active !== false)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
File({ name: 'REFERENCE.md' }, () => {
|
|
50
|
+
|
|
51
|
+
Content(`# ${model.Name} ${target.title} SDK Reference
|
|
52
|
+
|
|
53
|
+
Complete API reference for the ${model.Name} ${target.title} SDK.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## ${model.Name}SDK
|
|
57
|
+
|
|
58
|
+
### Constructor
|
|
59
|
+
|
|
60
|
+
`)
|
|
61
|
+
|
|
62
|
+
Content(`\`\`\`lua
|
|
63
|
+
local sdk = require("${model.name}_sdk")
|
|
64
|
+
local client = sdk.new(options)
|
|
65
|
+
\`\`\`
|
|
66
|
+
|
|
67
|
+
Create a new SDK client instance.
|
|
68
|
+
|
|
69
|
+
**Parameters:**
|
|
70
|
+
|
|
71
|
+
| Name | Type | Description |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| \`options\` | \`table\` | SDK configuration options. |
|
|
74
|
+
| \`options.apikey\` | \`string\` | API key for authentication. |
|
|
75
|
+
| \`options.base\` | \`string\` | Base URL for API requests. |
|
|
76
|
+
| \`options.prefix\` | \`string\` | URL prefix appended after base. |
|
|
77
|
+
| \`options.suffix\` | \`string\` | URL suffix appended after path. |
|
|
78
|
+
| \`options.headers\` | \`table\` | Custom headers for all requests. |
|
|
79
|
+
| \`options.feature\` | \`table\` | Feature configuration. |
|
|
80
|
+
| \`options.system\` | \`table\` | System overrides (e.g. custom fetch). |
|
|
81
|
+
|
|
82
|
+
`)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Content(`
|
|
86
|
+
### Static Methods
|
|
87
|
+
|
|
88
|
+
`)
|
|
89
|
+
|
|
90
|
+
Content(`#### \`sdk.test(testopts, sdkopts)\`
|
|
91
|
+
|
|
92
|
+
Create a test client with mock features active. Both arguments may be \`nil\`.
|
|
93
|
+
|
|
94
|
+
\`\`\`lua
|
|
95
|
+
local client = sdk.test(nil, nil)
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
`)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
Content(`
|
|
102
|
+
### Instance Methods
|
|
103
|
+
|
|
104
|
+
`)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// Entity factory methods
|
|
108
|
+
publishedEntities.map((ent: any) => {
|
|
109
|
+
Content(`#### \`${ent.Name}(data)\`
|
|
110
|
+
|
|
111
|
+
Create a new \`${ent.Name}\` entity instance. Pass \`nil\` for no initial data.
|
|
112
|
+
|
|
113
|
+
`)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
Content(`#### \`options_map() -> table\`
|
|
118
|
+
|
|
119
|
+
Return a deep copy of the current SDK options.
|
|
120
|
+
|
|
121
|
+
#### \`get_utility() -> Utility\`
|
|
122
|
+
|
|
123
|
+
Return a copy of the SDK utility object.
|
|
124
|
+
|
|
125
|
+
#### \`direct(fetchargs) -> table, err\`
|
|
126
|
+
|
|
127
|
+
Make a direct HTTP request to any API endpoint.
|
|
128
|
+
|
|
129
|
+
**Parameters:**
|
|
130
|
+
|
|
131
|
+
| Name | Type | Description |
|
|
132
|
+
| --- | --- | --- |
|
|
133
|
+
| \`fetchargs.path\` | \`string\` | URL path with optional \`{param}\` placeholders. |
|
|
134
|
+
| \`fetchargs.method\` | \`string\` | HTTP method (default: \`"GET"\`). |
|
|
135
|
+
| \`fetchargs.params\` | \`table\` | Path parameter values for \`{param}\` substitution. |
|
|
136
|
+
| \`fetchargs.query\` | \`table\` | Query string parameters. |
|
|
137
|
+
| \`fetchargs.headers\` | \`table\` | Request headers (merged with defaults). |
|
|
138
|
+
| \`fetchargs.body\` | \`any\` | Request body (tables are JSON-serialized). |
|
|
139
|
+
| \`fetchargs.ctrl\` | \`table\` | Control options (e.g. \`{ explain = true }\`). |
|
|
140
|
+
|
|
141
|
+
**Returns:** \`table, err\`
|
|
142
|
+
|
|
143
|
+
#### \`prepare(fetchargs) -> table, err\`
|
|
144
|
+
|
|
145
|
+
Prepare a fetch definition without sending the request. Accepts the
|
|
146
|
+
same parameters as \`direct()\`.
|
|
147
|
+
|
|
148
|
+
**Returns:** \`table, err\`
|
|
149
|
+
|
|
150
|
+
`)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
// Entity reference sections
|
|
154
|
+
publishedEntities.map((ent: any) => {
|
|
155
|
+
const opnames = Object.keys(ent.op || {})
|
|
156
|
+
const fields = ent.fields || []
|
|
157
|
+
|
|
158
|
+
Content(`
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## ${ent.Name}Entity
|
|
162
|
+
|
|
163
|
+
`)
|
|
164
|
+
|
|
165
|
+
if (ent.short) {
|
|
166
|
+
Content(`${ent.short}
|
|
167
|
+
|
|
168
|
+
`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Content(`\`\`\`lua
|
|
172
|
+
local ${ent.name} = client:${ent.Name}(nil)
|
|
173
|
+
\`\`\`
|
|
174
|
+
|
|
175
|
+
`)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
// Field schema
|
|
179
|
+
if (fields.length > 0) {
|
|
180
|
+
Content(`### Fields
|
|
181
|
+
|
|
182
|
+
| Field | Type | Required | Description |
|
|
183
|
+
| --- | --- | --- | --- |
|
|
184
|
+
`)
|
|
185
|
+
each(fields, (field: any) => {
|
|
186
|
+
const req = field.req ? 'Yes' : 'No'
|
|
187
|
+
const desc = field.short || ''
|
|
188
|
+
Content(`| \`${field.name}\` | \`${field.type || 'any'}\` | ${req} | ${desc} |
|
|
189
|
+
`)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
Content(`
|
|
193
|
+
`)
|
|
194
|
+
|
|
195
|
+
// Field operations breakdown
|
|
196
|
+
const hasFieldOps = fields.some((f: any) => f.op && Object.keys(f.op).length > 0)
|
|
197
|
+
if (hasFieldOps) {
|
|
198
|
+
Content(`### Field Usage by Operation
|
|
199
|
+
|
|
200
|
+
| Field | load | list | create | update | remove |
|
|
201
|
+
| --- | --- | --- | --- | --- | --- |
|
|
202
|
+
`)
|
|
203
|
+
each(fields, (field: any) => {
|
|
204
|
+
const fops = field.op || {}
|
|
205
|
+
const cols = ['load', 'list', 'create', 'update', 'remove'].map((op: string) => {
|
|
206
|
+
if (!opnames.includes(op)) return '-'
|
|
207
|
+
const fop = fops[op]
|
|
208
|
+
if (null == fop) return '-'
|
|
209
|
+
if (fop.active === false) return '-'
|
|
210
|
+
return 'Yes'
|
|
211
|
+
})
|
|
212
|
+
Content(`| \`${field.name}\` | ${cols.join(' | ')} |
|
|
213
|
+
`)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
Content(`
|
|
217
|
+
`)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
// Operation details
|
|
223
|
+
if (opnames.length > 0) {
|
|
224
|
+
Content(`### Operations
|
|
225
|
+
|
|
226
|
+
`)
|
|
227
|
+
|
|
228
|
+
opnames.map((opname: string) => {
|
|
229
|
+
const info = OP_SIGNATURES[opname]
|
|
230
|
+
if (!info) return
|
|
231
|
+
|
|
232
|
+
Content(`#### \`${info.sig}\`
|
|
233
|
+
|
|
234
|
+
${info.desc}
|
|
235
|
+
|
|
236
|
+
`)
|
|
237
|
+
|
|
238
|
+
// Show example
|
|
239
|
+
if ('load' === opname || 'remove' === opname) {
|
|
240
|
+
Content(`\`\`\`lua
|
|
241
|
+
local result, err = client:${ent.Name}(nil):${opname}({ id = "${ent.name}_id" }, nil)
|
|
242
|
+
\`\`\`
|
|
243
|
+
|
|
244
|
+
`)
|
|
245
|
+
}
|
|
246
|
+
else if ('list' === opname) {
|
|
247
|
+
Content(`\`\`\`lua
|
|
248
|
+
local results, err = client:${ent.Name}(nil):list(nil, nil)
|
|
249
|
+
\`\`\`
|
|
250
|
+
|
|
251
|
+
`)
|
|
252
|
+
}
|
|
253
|
+
else if ('create' === opname) {
|
|
254
|
+
Content(`\`\`\`lua
|
|
255
|
+
local result, err = client:${ent.Name}(nil):create({
|
|
256
|
+
`)
|
|
257
|
+
each(fields, (field: any) => {
|
|
258
|
+
if ('id' !== field.name && field.req) {
|
|
259
|
+
Content(` ${field.name} = --[[ ${field.type || 'value'} ]],
|
|
260
|
+
`)
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
Content(`}, nil)
|
|
264
|
+
\`\`\`
|
|
265
|
+
|
|
266
|
+
`)
|
|
267
|
+
}
|
|
268
|
+
else if ('update' === opname) {
|
|
269
|
+
Content(`\`\`\`lua
|
|
270
|
+
local result, err = client:${ent.Name}(nil):update({
|
|
271
|
+
id = "${ent.name}_id",
|
|
272
|
+
-- Fields to update
|
|
273
|
+
}, nil)
|
|
274
|
+
\`\`\`
|
|
275
|
+
|
|
276
|
+
`)
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
// Common methods
|
|
283
|
+
Content(`### Common Methods
|
|
284
|
+
|
|
285
|
+
#### \`data_get() -> table\`
|
|
286
|
+
|
|
287
|
+
Get the entity data. Returns a copy of the current data.
|
|
288
|
+
|
|
289
|
+
#### \`data_set(data)\`
|
|
290
|
+
|
|
291
|
+
Set the entity data.
|
|
292
|
+
|
|
293
|
+
#### \`match_get() -> table\`
|
|
294
|
+
|
|
295
|
+
Get the entity match criteria.
|
|
296
|
+
|
|
297
|
+
#### \`match_set(match)\`
|
|
298
|
+
|
|
299
|
+
Set the entity match criteria.
|
|
300
|
+
|
|
301
|
+
#### \`make() -> Entity\`
|
|
302
|
+
|
|
303
|
+
Create a new \`${ent.Name}Entity\` instance with the same client and
|
|
304
|
+
options.
|
|
305
|
+
|
|
306
|
+
#### \`get_name() -> string\`
|
|
307
|
+
|
|
308
|
+
Return the entity name.
|
|
309
|
+
|
|
310
|
+
`)
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
// Features section
|
|
315
|
+
const activeFeatures = each(feature).filter((f: any) => f.active)
|
|
316
|
+
if (activeFeatures.length > 0) {
|
|
317
|
+
Content(`
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Features
|
|
321
|
+
|
|
322
|
+
| Feature | Version | Description |
|
|
323
|
+
| --- | --- | --- |
|
|
324
|
+
`)
|
|
325
|
+
|
|
326
|
+
activeFeatures.map((f: any) => {
|
|
327
|
+
Content(`| \`${f.name}\` | ${f.version || '0.0.1'} | ${f.title || ''} |
|
|
328
|
+
`)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
Content(`
|
|
332
|
+
|
|
333
|
+
Features are activated via the \`feature\` option:
|
|
334
|
+
|
|
335
|
+
`)
|
|
336
|
+
|
|
337
|
+
Content(`\`\`\`lua
|
|
338
|
+
local client = sdk.new({
|
|
339
|
+
feature = {
|
|
340
|
+
`)
|
|
341
|
+
activeFeatures.map((f: any) => {
|
|
342
|
+
Content(` ${f.name} = { active = true },
|
|
343
|
+
`)
|
|
344
|
+
})
|
|
345
|
+
Content(` },
|
|
346
|
+
})
|
|
347
|
+
\`\`\`
|
|
348
|
+
|
|
349
|
+
`)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
export {
|
|
359
|
+
ReadmeRef
|
|
360
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { cmp, Content } from '@voxgig/sdkgen'
|
|
2
|
+
import { cmp, Content, isAuthActive } from '@voxgig/sdkgen'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
KIT,
|
|
@@ -15,12 +15,14 @@ const ReadmeTopQuick = cmp(function ReadmeTopQuick(props: any) {
|
|
|
15
15
|
|
|
16
16
|
const exampleEntity = Object.values(entity).find((e: any) => e.active !== false) as any
|
|
17
17
|
|
|
18
|
+
const apikeyArg = isAuthActive(model)
|
|
19
|
+
? `\n apikey = os.getenv("${model.NAME}_APIKEY"),\n`
|
|
20
|
+
: ''
|
|
21
|
+
|
|
18
22
|
Content(`\`\`\`lua
|
|
19
23
|
local sdk = require("${model.name}_sdk")
|
|
20
24
|
|
|
21
|
-
local client = sdk.new({
|
|
22
|
-
apikey = os.getenv("${model.NAME}_APIKEY"),
|
|
23
|
-
})
|
|
25
|
+
local client = sdk.new({${apikeyArg}})
|
|
24
26
|
|
|
25
27
|
`)
|
|
26
28
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import {
|
|
3
|
+
Model,
|
|
4
|
+
ModelEntity,
|
|
5
|
+
nom,
|
|
3
6
|
depluralize,
|
|
4
7
|
} from '@voxgig/apidef'
|
|
5
8
|
|
|
@@ -8,6 +11,7 @@ import {
|
|
|
8
11
|
File,
|
|
9
12
|
cmp,
|
|
10
13
|
snakify,
|
|
14
|
+
isAuthActive,
|
|
11
15
|
} from '@voxgig/sdkgen'
|
|
12
16
|
|
|
13
17
|
|
|
@@ -51,12 +55,20 @@ function normalizePathParams(
|
|
|
51
55
|
|
|
52
56
|
const TestDirect = cmp(function TestDirect(props: any) {
|
|
53
57
|
const ctx$ = props.ctx$
|
|
54
|
-
const model = ctx$.model
|
|
58
|
+
const model: Model = ctx$.model
|
|
55
59
|
|
|
56
60
|
const target = props.target
|
|
57
|
-
const entity = props.entity
|
|
61
|
+
const entity: ModelEntity = props.entity
|
|
58
62
|
|
|
59
|
-
const PROJECTNAME = model
|
|
63
|
+
const PROJECTNAME = nom(model, 'Name').toUpperCase().replace(/[^A-Z_]/g, '_')
|
|
64
|
+
|
|
65
|
+
const authActive = isAuthActive(model)
|
|
66
|
+
const apikeyEnvEntry = authActive
|
|
67
|
+
? `\n ["${PROJECTNAME}_APIKEY"] = "NONE",`
|
|
68
|
+
: ''
|
|
69
|
+
const apikeyLiveField = authActive
|
|
70
|
+
? `\n apikey = env["${PROJECTNAME}_APIKEY"],`
|
|
71
|
+
: ''
|
|
60
72
|
|
|
61
73
|
const opnames = Object.keys(entity.op)
|
|
62
74
|
const hasLoad = opnames.includes('load')
|
|
@@ -77,7 +89,7 @@ const TestDirect = cmp(function TestDirect(props: any) {
|
|
|
77
89
|
const listPath = listPoint ? normalizePathParams(listPoint.parts || [], listPoint?.args?.params || [], listPoint?.rename?.param) : ''
|
|
78
90
|
const listParams = listPoint?.args?.params || []
|
|
79
91
|
|
|
80
|
-
const entidEnvVar = `${PROJECTNAME}_TEST_${entity
|
|
92
|
+
const entidEnvVar = `${PROJECTNAME}_TEST_${nom(entity, 'NAME').replace(/[^A-Z_]/g, '_')}_ENTID`
|
|
81
93
|
|
|
82
94
|
File({ name: entity.name + '_direct_test.' + target.ext }, () => {
|
|
83
95
|
|
|
@@ -205,15 +217,13 @@ function ${entity.name}_direct_setup(mockres)
|
|
|
205
217
|
|
|
206
218
|
local env = runner.env_override({
|
|
207
219
|
["${entidEnvVar}"] = {},
|
|
208
|
-
["${PROJECTNAME}_TEST_LIVE"] = "FALSE"
|
|
209
|
-
["${PROJECTNAME}_APIKEY"] = "NONE",
|
|
220
|
+
["${PROJECTNAME}_TEST_LIVE"] = "FALSE",${apikeyEnvEntry}
|
|
210
221
|
})
|
|
211
222
|
|
|
212
223
|
local live = env["${PROJECTNAME}_TEST_LIVE"] == "TRUE"
|
|
213
224
|
|
|
214
225
|
if live then
|
|
215
|
-
local merged_opts = {
|
|
216
|
-
apikey = env["${PROJECTNAME}_APIKEY"],
|
|
226
|
+
local merged_opts = {${apikeyLiveField}
|
|
217
227
|
}
|
|
218
228
|
local client = sdk.new(merged_opts)
|
|
219
229
|
return {
|