@voxgig/sdkgen 0.32.2 → 0.33.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/Readme.js +10 -0
- package/dist/cmp/Readme.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +91 -8
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/ReadmeIntro.js +24 -2
- package/dist/cmp/ReadmeIntro.js.map +1 -1
- package/dist/cmp/ReadmeModel.js +93 -16
- package/dist/cmp/ReadmeModel.js.map +1 -1
- package/dist/cmp/ReadmeOptions.js +30 -5
- package/dist/cmp/ReadmeOptions.js.map +1 -1
- package/dist/cmp/ReadmeRef.d.ts +2 -0
- package/dist/cmp/ReadmeRef.js +334 -0
- package/dist/cmp/ReadmeRef.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +3 -1
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +2 -2
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +3 -3
- package/project/.sdk/src/cmp/js/Config_js.ts +62 -23
- package/project/.sdk/src/cmp/js/EntityOperation_js.ts +49 -0
- package/project/.sdk/src/cmp/js/Entity_js.ts +21 -50
- package/project/.sdk/src/cmp/js/MainEntity_js.ts +1 -1
- package/project/.sdk/src/cmp/js/Main_js.ts +53 -44
- package/project/.sdk/src/cmp/js/Package_js.ts +39 -12
- package/project/.sdk/src/cmp/js/Quick_js.ts +6 -10
- package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +101 -5
- package/project/.sdk/src/cmp/js/SdkError_js.ts +42 -0
- package/project/.sdk/src/cmp/js/TestDirect_js.ts +288 -0
- package/project/.sdk/src/cmp/js/TestEntity_js.ts +352 -2
- package/project/.sdk/src/cmp/js/TestMain_js.ts +0 -3
- package/project/.sdk/src/cmp/js/Test_js.ts +20 -8
- package/project/.sdk/src/cmp/js/fragment/Config.fragment.js +55 -0
- package/project/.sdk/src/cmp/js/fragment/Direct.test.fragment.js +30 -0
- package/project/.sdk/src/cmp/js/fragment/Entity.fragment.js +119 -28
- package/project/.sdk/src/cmp/js/fragment/Entity.test.fragment.js +39 -0
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +89 -45
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +92 -41
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +95 -45
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +95 -43
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +95 -43
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +150 -65
- package/project/.sdk/src/cmp/js/fragment/SdkError.fragment.js +22 -0
- package/project/.sdk/src/cmp/js/utility_js.ts +64 -0
- package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +102 -5
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +2 -2
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +11 -8
- package/src/cmp/Readme.ts +12 -0
- package/src/cmp/ReadmeEntity.ts +105 -9
- package/src/cmp/ReadmeIntro.ts +30 -2
- package/src/cmp/ReadmeModel.ts +101 -18
- package/src/cmp/ReadmeOptions.ts +35 -6
- package/src/cmp/ReadmeRef.ts +369 -0
- package/src/sdkgen.ts +2 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
|
|
2
|
+
import { cmp, each, Content, File } from 'jostraca'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
KIT,
|
|
6
|
+
getModelPath
|
|
7
|
+
} from '../types'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const OP_SIGNATURES: Record<string, { sig: string, returns: string, desc: string }> = {
|
|
11
|
+
load: {
|
|
12
|
+
sig: 'load(match: object, ctrl?: object)',
|
|
13
|
+
returns: 'Promise<object>',
|
|
14
|
+
desc: 'Load a single entity matching the given criteria.',
|
|
15
|
+
},
|
|
16
|
+
list: {
|
|
17
|
+
sig: 'list(match: object, ctrl?: object)',
|
|
18
|
+
returns: 'Promise<object[]>',
|
|
19
|
+
desc: 'List entities matching the given criteria. Returns an array.',
|
|
20
|
+
},
|
|
21
|
+
create: {
|
|
22
|
+
sig: 'create(data: object, ctrl?: object)',
|
|
23
|
+
returns: 'Promise<object>',
|
|
24
|
+
desc: 'Create a new entity with the given data.',
|
|
25
|
+
},
|
|
26
|
+
update: {
|
|
27
|
+
sig: 'update(data: object, ctrl?: object)',
|
|
28
|
+
returns: 'Promise<object>',
|
|
29
|
+
desc: 'Update an existing entity. The data must include the entity `id`.',
|
|
30
|
+
},
|
|
31
|
+
remove: {
|
|
32
|
+
sig: 'remove(match: object, ctrl?: object)',
|
|
33
|
+
returns: 'Promise<void>',
|
|
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.publish)
|
|
47
|
+
|
|
48
|
+
File({ name: 'REFERENCE.md' }, () => {
|
|
49
|
+
|
|
50
|
+
Content(`# ${model.Name} ${target.title} SDK Reference
|
|
51
|
+
|
|
52
|
+
Complete API reference for the ${model.Name} ${target.title} SDK.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## ${model.Name}SDK
|
|
56
|
+
|
|
57
|
+
### Constructor
|
|
58
|
+
|
|
59
|
+
\`\`\`ts
|
|
60
|
+
new ${model.Name}SDK(options?: object)
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
Create a new SDK client instance.
|
|
64
|
+
|
|
65
|
+
**Parameters:**
|
|
66
|
+
|
|
67
|
+
| Name | Type | Description |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| \`options\` | \`object\` | SDK configuration options. |
|
|
70
|
+
| \`options.apikey\` | \`string\` | API key for authentication. |
|
|
71
|
+
| \`options.base\` | \`string\` | Base URL for API requests. |
|
|
72
|
+
| \`options.prefix\` | \`string\` | URL prefix appended after base. |
|
|
73
|
+
| \`options.suffix\` | \`string\` | URL suffix appended after path. |
|
|
74
|
+
| \`options.headers\` | \`object\` | Custom headers for all requests. |
|
|
75
|
+
| \`options.feature\` | \`object\` | Feature configuration. |
|
|
76
|
+
| \`options.system\` | \`object\` | System overrides (e.g. custom fetch). |
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Static Methods
|
|
80
|
+
|
|
81
|
+
#### \`${model.Name}SDK.test(testopts?, sdkopts?)\`
|
|
82
|
+
|
|
83
|
+
Create a test client with mock features active.
|
|
84
|
+
|
|
85
|
+
\`\`\`ts
|
|
86
|
+
const client = ${model.Name}SDK.test()
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
**Parameters:**
|
|
90
|
+
|
|
91
|
+
| Name | Type | Description |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| \`testopts\` | \`object\` | Test feature options. |
|
|
94
|
+
| \`sdkopts\` | \`object\` | Additional SDK options merged with test defaults. |
|
|
95
|
+
|
|
96
|
+
**Returns:** \`${model.Name}SDK\` instance in test mode.
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
### Instance Methods
|
|
100
|
+
|
|
101
|
+
`)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// Entity factory methods
|
|
105
|
+
publishedEntities.map((ent: any) => {
|
|
106
|
+
Content(`#### \`${ent.Name}(data?: object)\`
|
|
107
|
+
|
|
108
|
+
Create a new \`${ent.Name}\` entity instance.
|
|
109
|
+
|
|
110
|
+
**Parameters:**
|
|
111
|
+
|
|
112
|
+
| Name | Type | Description |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| \`data\` | \`object\` | Initial entity data. |
|
|
115
|
+
|
|
116
|
+
**Returns:** \`${ent.Name}Entity\` instance.
|
|
117
|
+
|
|
118
|
+
`)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
Content(`#### \`options()\`
|
|
123
|
+
|
|
124
|
+
Return a deep copy of the current SDK options.
|
|
125
|
+
|
|
126
|
+
**Returns:** \`object\`
|
|
127
|
+
|
|
128
|
+
#### \`utility()\`
|
|
129
|
+
|
|
130
|
+
Return a copy of the SDK utility object.
|
|
131
|
+
|
|
132
|
+
**Returns:** \`object\`
|
|
133
|
+
|
|
134
|
+
#### \`direct(fetchargs?: object)\`
|
|
135
|
+
|
|
136
|
+
Make a direct HTTP request to any API endpoint.
|
|
137
|
+
|
|
138
|
+
**Parameters:**
|
|
139
|
+
|
|
140
|
+
| Name | Type | Description |
|
|
141
|
+
| --- | --- | --- |
|
|
142
|
+
| \`fetchargs.path\` | \`string\` | URL path with optional \`{param}\` placeholders. |
|
|
143
|
+
| \`fetchargs.method\` | \`string\` | HTTP method (default: \`GET\`). |
|
|
144
|
+
| \`fetchargs.params\` | \`object\` | Path parameter values for \`{param}\` substitution. |
|
|
145
|
+
| \`fetchargs.query\` | \`object\` | Query string parameters. |
|
|
146
|
+
| \`fetchargs.headers\` | \`object\` | Request headers (merged with defaults). |
|
|
147
|
+
| \`fetchargs.body\` | \`any\` | Request body (objects are JSON-serialized). |
|
|
148
|
+
| \`fetchargs.ctrl\` | \`object\` | Control options (e.g. \`{ explain: true }\`). |
|
|
149
|
+
|
|
150
|
+
**Returns:** \`Promise<{ ok, status, headers, data } | Error>\`
|
|
151
|
+
|
|
152
|
+
#### \`prepare(fetchargs?: object)\`
|
|
153
|
+
|
|
154
|
+
Prepare a fetch definition without sending the request. Accepts the
|
|
155
|
+
same parameters as \`direct()\`.
|
|
156
|
+
|
|
157
|
+
**Returns:** \`Promise<{ url, method, headers, body } | Error>\`
|
|
158
|
+
|
|
159
|
+
#### \`tester(testopts?, sdkopts?)\`
|
|
160
|
+
|
|
161
|
+
Alias for \`${model.Name}SDK.test()\`.
|
|
162
|
+
|
|
163
|
+
**Returns:** \`${model.Name}SDK\` instance in test mode.
|
|
164
|
+
|
|
165
|
+
`)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
// Entity reference sections
|
|
169
|
+
publishedEntities.map((ent: any) => {
|
|
170
|
+
const opnames = Object.keys(ent.op || {})
|
|
171
|
+
const fields = ent.field || []
|
|
172
|
+
|
|
173
|
+
Content(`
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## ${ent.Name}Entity
|
|
177
|
+
|
|
178
|
+
`)
|
|
179
|
+
|
|
180
|
+
if (ent.short) {
|
|
181
|
+
Content(`${ent.short}
|
|
182
|
+
|
|
183
|
+
`)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
Content(`\`\`\`ts
|
|
187
|
+
const ${ent.name} = client.${ent.Name}()
|
|
188
|
+
\`\`\`
|
|
189
|
+
|
|
190
|
+
`)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
// Field schema
|
|
194
|
+
if (fields.length > 0) {
|
|
195
|
+
Content(`### Fields
|
|
196
|
+
|
|
197
|
+
| Field | Type | Required | Description |
|
|
198
|
+
| --- | --- | --- | --- |
|
|
199
|
+
`)
|
|
200
|
+
each(fields, (field: any) => {
|
|
201
|
+
const req = field.req ? 'Yes' : 'No'
|
|
202
|
+
const desc = field.short || ''
|
|
203
|
+
Content(`| \`${field.name}\` | \`${field.type || 'any'}\` | ${req} | ${desc} |
|
|
204
|
+
`)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
Content(`
|
|
208
|
+
`)
|
|
209
|
+
|
|
210
|
+
// Field operations breakdown
|
|
211
|
+
const hasFieldOps = fields.some((f: any) => f.op && Object.keys(f.op).length > 0)
|
|
212
|
+
if (hasFieldOps) {
|
|
213
|
+
Content(`### Field Usage by Operation
|
|
214
|
+
|
|
215
|
+
| Field | load | list | create | update | remove |
|
|
216
|
+
| --- | --- | --- | --- | --- | --- |
|
|
217
|
+
`)
|
|
218
|
+
each(fields, (field: any) => {
|
|
219
|
+
const fops = field.op || {}
|
|
220
|
+
const cols = ['load', 'list', 'create', 'update', 'remove'].map((op: string) => {
|
|
221
|
+
if (!opnames.includes(op)) return '-'
|
|
222
|
+
const fop = fops[op]
|
|
223
|
+
if (null == fop) return '-'
|
|
224
|
+
if (fop.active === false) return '-'
|
|
225
|
+
return 'Yes'
|
|
226
|
+
})
|
|
227
|
+
Content(`| \`${field.name}\` | ${cols.join(' | ')} |
|
|
228
|
+
`)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
Content(`
|
|
232
|
+
`)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
// Operation details
|
|
238
|
+
if (opnames.length > 0) {
|
|
239
|
+
Content(`### Operations
|
|
240
|
+
|
|
241
|
+
`)
|
|
242
|
+
|
|
243
|
+
opnames.map((opname: string) => {
|
|
244
|
+
const info = OP_SIGNATURES[opname]
|
|
245
|
+
if (!info) return
|
|
246
|
+
|
|
247
|
+
Content(`#### \`${info.sig}\`
|
|
248
|
+
|
|
249
|
+
${info.desc}
|
|
250
|
+
|
|
251
|
+
`)
|
|
252
|
+
|
|
253
|
+
// Show example
|
|
254
|
+
if ('load' === opname || 'remove' === opname) {
|
|
255
|
+
Content(`\`\`\`ts
|
|
256
|
+
const result = await client.${ent.Name}().${opname}({ id: '${ent.name}_id' })
|
|
257
|
+
\`\`\`
|
|
258
|
+
|
|
259
|
+
`)
|
|
260
|
+
}
|
|
261
|
+
else if ('list' === opname) {
|
|
262
|
+
Content(`\`\`\`ts
|
|
263
|
+
const results = await client.${ent.Name}().${opname}()
|
|
264
|
+
\`\`\`
|
|
265
|
+
|
|
266
|
+
`)
|
|
267
|
+
}
|
|
268
|
+
else if ('create' === opname) {
|
|
269
|
+
Content(`\`\`\`ts
|
|
270
|
+
const result = await client.${ent.Name}().create({
|
|
271
|
+
`)
|
|
272
|
+
each(fields, (field: any) => {
|
|
273
|
+
if ('id' !== field.name && field.req) {
|
|
274
|
+
Content(` ${field.name}: /* ${field.type || 'value'} */,
|
|
275
|
+
`)
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
Content(`})
|
|
279
|
+
\`\`\`
|
|
280
|
+
|
|
281
|
+
`)
|
|
282
|
+
}
|
|
283
|
+
else if ('update' === opname) {
|
|
284
|
+
Content(`\`\`\`ts
|
|
285
|
+
const result = await client.${ent.Name}().update({
|
|
286
|
+
id: '${ent.name}_id',
|
|
287
|
+
// Fields to update
|
|
288
|
+
})
|
|
289
|
+
\`\`\`
|
|
290
|
+
|
|
291
|
+
`)
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
// Common methods
|
|
298
|
+
Content(`### Common Methods
|
|
299
|
+
|
|
300
|
+
#### \`data(data?: object)\`
|
|
301
|
+
|
|
302
|
+
Get or set the entity data. When called with data, sets the entity's
|
|
303
|
+
internal data and returns the current data. When called without
|
|
304
|
+
arguments, returns a copy of the current data.
|
|
305
|
+
|
|
306
|
+
#### \`match(match?: object)\`
|
|
307
|
+
|
|
308
|
+
Get or set the entity match criteria. Works the same as \`data()\`.
|
|
309
|
+
|
|
310
|
+
#### \`make()\`
|
|
311
|
+
|
|
312
|
+
Create a new \`${ent.Name}Entity\` instance with the same client and
|
|
313
|
+
options.
|
|
314
|
+
|
|
315
|
+
#### \`client()\`
|
|
316
|
+
|
|
317
|
+
Return the parent \`${model.Name}SDK\` instance.
|
|
318
|
+
|
|
319
|
+
#### \`entopts()\`
|
|
320
|
+
|
|
321
|
+
Return a copy of the entity options.
|
|
322
|
+
|
|
323
|
+
`)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
// Features section
|
|
328
|
+
const activeFeatures = each(feature).filter((f: any) => f.active)
|
|
329
|
+
if (activeFeatures.length > 0) {
|
|
330
|
+
Content(`
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## Features
|
|
334
|
+
|
|
335
|
+
| Feature | Version | Description |
|
|
336
|
+
| --- | --- | --- |
|
|
337
|
+
`)
|
|
338
|
+
|
|
339
|
+
activeFeatures.map((f: any) => {
|
|
340
|
+
Content(`| \`${f.name}\` | ${f.version || '0.0.1'} | ${f.title || ''} |
|
|
341
|
+
`)
|
|
342
|
+
})
|
|
343
|
+
|
|
344
|
+
Content(`
|
|
345
|
+
|
|
346
|
+
Features are activated via the \`feature\` option:
|
|
347
|
+
|
|
348
|
+
\`\`\`ts
|
|
349
|
+
const client = new ${model.Name}SDK({
|
|
350
|
+
feature: {
|
|
351
|
+
`)
|
|
352
|
+
activeFeatures.map((f: any) => {
|
|
353
|
+
Content(` ${f.name}: { active: true },
|
|
354
|
+
`)
|
|
355
|
+
})
|
|
356
|
+
Content(` }
|
|
357
|
+
})
|
|
358
|
+
\`\`\`
|
|
359
|
+
|
|
360
|
+
`)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
export {
|
|
368
|
+
ReadmeRef
|
|
369
|
+
}
|
package/src/sdkgen.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { Test } from './cmp/Test'
|
|
|
29
29
|
import { ReadmeInstall } from './cmp/ReadmeInstall'
|
|
30
30
|
import { ReadmeOptions } from './cmp/ReadmeOptions'
|
|
31
31
|
import { ReadmeEntity } from './cmp/ReadmeEntity'
|
|
32
|
+
import { ReadmeRef } from './cmp/ReadmeRef'
|
|
32
33
|
import { FeatureHook } from './cmp/FeatureHook'
|
|
33
34
|
|
|
34
35
|
|
|
@@ -358,6 +359,7 @@ export {
|
|
|
358
359
|
ReadmeInstall,
|
|
359
360
|
ReadmeOptions,
|
|
360
361
|
ReadmeEntity,
|
|
362
|
+
ReadmeRef,
|
|
361
363
|
FeatureHook,
|
|
362
364
|
|
|
363
365
|
Jostraca,
|