@voxgig/sdkgen 0.44.0 → 1.0.1

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 (160) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/ReadmeEntity.js +9 -153
  3. package/dist/cmp/ReadmeEntity.js.map +1 -1
  4. package/dist/cmp/ReadmeIntro.js +9 -14
  5. package/dist/cmp/ReadmeIntro.js.map +1 -1
  6. package/dist/cmp/ReadmeModel.js +6 -4
  7. package/dist/cmp/ReadmeModel.js.map +1 -1
  8. package/dist/cmp/ReadmeOptions.js +9 -61
  9. package/dist/cmp/ReadmeOptions.js.map +1 -1
  10. package/dist/cmp/ReadmeRef.js +10 -1328
  11. package/dist/cmp/ReadmeRef.js.map +1 -1
  12. package/dist/sdkgen.d.ts +2 -2
  13. package/dist/sdkgen.js +2 -1
  14. package/dist/sdkgen.js.map +1 -1
  15. package/dist/utility.d.ts +2 -1
  16. package/dist/utility.js +9 -0
  17. package/dist/utility.js.map +1 -1
  18. package/package.json +3 -3
  19. package/project/.sdk/src/cmp/go/Config_go.ts +9 -4
  20. package/project/.sdk/src/cmp/go/Entity_go.ts +2 -2
  21. package/project/.sdk/src/cmp/go/Main_go.ts +8 -4
  22. package/project/.sdk/src/cmp/go/Package_go.ts +2 -2
  23. package/project/.sdk/src/cmp/go/ReadmeEntity_go.ts +138 -0
  24. package/project/.sdk/src/cmp/go/ReadmeExplanation_go.ts +2 -2
  25. package/project/.sdk/src/cmp/go/ReadmeHowto_go.ts +8 -5
  26. package/project/.sdk/src/cmp/go/ReadmeInstall_go.ts +2 -2
  27. package/project/.sdk/src/cmp/go/ReadmeIntro_go.ts +18 -0
  28. package/project/.sdk/src/cmp/go/ReadmeModel_go.ts +8 -5
  29. package/project/.sdk/src/cmp/go/ReadmeOptions_go.ts +58 -0
  30. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +13 -9
  31. package/project/.sdk/src/cmp/go/ReadmeRef_go.ts +354 -0
  32. package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +8 -6
  33. package/project/.sdk/src/cmp/go/ReadmeTopTest_go.ts +2 -2
  34. package/project/.sdk/src/cmp/go/TestDirect_go.ts +222 -41
  35. package/project/.sdk/src/cmp/go/TestEntity_go.ts +142 -60
  36. package/project/.sdk/src/cmp/go/Test_go.ts +2 -2
  37. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +21 -4
  38. package/project/.sdk/src/cmp/js/Config_js.ts +18 -0
  39. package/project/.sdk/src/cmp/js/ReadmeEntity_js.ts +138 -0
  40. package/project/.sdk/src/cmp/js/ReadmeHowto_js.ts +11 -6
  41. package/project/.sdk/src/cmp/js/ReadmeIntro_js.ts +18 -0
  42. package/project/.sdk/src/cmp/js/ReadmeModel_js.ts +6 -3
  43. package/project/.sdk/src/cmp/js/ReadmeOptions_js.ts +58 -0
  44. package/project/.sdk/src/cmp/js/ReadmeQuick_js.ts +6 -4
  45. package/project/.sdk/src/cmp/js/ReadmeRef_js.ts +384 -0
  46. package/project/.sdk/src/cmp/js/ReadmeTopQuick_js.ts +6 -4
  47. package/project/.sdk/src/cmp/js/TestDirect_js.ts +23 -12
  48. package/project/.sdk/src/cmp/js/TestEntity_js.ts +107 -74
  49. package/project/.sdk/src/cmp/js/fragment/Config.fragment.js +1 -5
  50. package/project/.sdk/src/cmp/lua/Config_lua.ts +9 -4
  51. package/project/.sdk/src/cmp/lua/Package_lua.ts +9 -2
  52. package/project/.sdk/src/cmp/lua/ReadmeEntity_lua.ts +138 -0
  53. package/project/.sdk/src/cmp/lua/ReadmeHowto_lua.ts +6 -3
  54. package/project/.sdk/src/cmp/lua/ReadmeIntro_lua.ts +18 -0
  55. package/project/.sdk/src/cmp/lua/ReadmeModel_lua.ts +6 -3
  56. package/project/.sdk/src/cmp/lua/ReadmeOptions_lua.ts +58 -0
  57. package/project/.sdk/src/cmp/lua/ReadmeQuick_lua.ts +6 -4
  58. package/project/.sdk/src/cmp/lua/ReadmeRef_lua.ts +360 -0
  59. package/project/.sdk/src/cmp/lua/ReadmeTopQuick_lua.ts +6 -4
  60. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +172 -29
  61. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +120 -52
  62. package/project/.sdk/src/cmp/lua/fragment/Main.fragment.lua +20 -4
  63. package/project/.sdk/src/cmp/php/Config_php.ts +10 -8
  64. package/project/.sdk/src/cmp/php/Package_php.ts +7 -1
  65. package/project/.sdk/src/cmp/php/ReadmeEntity_php.ts +138 -0
  66. package/project/.sdk/src/cmp/php/ReadmeHowto_php.ts +6 -3
  67. package/project/.sdk/src/cmp/php/ReadmeIntro_php.ts +18 -0
  68. package/project/.sdk/src/cmp/php/ReadmeModel_php.ts +6 -3
  69. package/project/.sdk/src/cmp/php/ReadmeOptions_php.ts +58 -0
  70. package/project/.sdk/src/cmp/php/ReadmeQuick_php.ts +6 -4
  71. package/project/.sdk/src/cmp/php/ReadmeRef_php.ts +358 -0
  72. package/project/.sdk/src/cmp/php/ReadmeTopQuick_php.ts +6 -4
  73. package/project/.sdk/src/cmp/php/TestDirect_php.ts +171 -28
  74. package/project/.sdk/src/cmp/php/TestEntity_php.ts +126 -55
  75. package/project/.sdk/src/cmp/php/fragment/Main.fragment.php +17 -3
  76. package/project/.sdk/src/cmp/py/Config_py.ts +9 -4
  77. package/project/.sdk/src/cmp/py/Package_py.ts +8 -1
  78. package/project/.sdk/src/cmp/py/ReadmeEntity_py.ts +138 -0
  79. package/project/.sdk/src/cmp/py/ReadmeHowto_py.ts +6 -3
  80. package/project/.sdk/src/cmp/py/ReadmeIntro_py.ts +18 -0
  81. package/project/.sdk/src/cmp/py/ReadmeModel_py.ts +6 -3
  82. package/project/.sdk/src/cmp/py/ReadmeOptions_py.ts +58 -0
  83. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +9 -6
  84. package/project/.sdk/src/cmp/py/ReadmeRef_py.ts +356 -0
  85. package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +9 -6
  86. package/project/.sdk/src/cmp/py/TestDirect_py.ts +164 -27
  87. package/project/.sdk/src/cmp/py/TestEntity_py.ts +125 -51
  88. package/project/.sdk/src/cmp/py/fragment/Main.fragment.py +19 -4
  89. package/project/.sdk/src/cmp/rb/Config_rb.ts +9 -4
  90. package/project/.sdk/src/cmp/rb/Package_rb.ts +9 -2
  91. package/project/.sdk/src/cmp/rb/ReadmeEntity_rb.ts +138 -0
  92. package/project/.sdk/src/cmp/rb/ReadmeHowto_rb.ts +6 -3
  93. package/project/.sdk/src/cmp/rb/ReadmeIntro_rb.ts +18 -0
  94. package/project/.sdk/src/cmp/rb/ReadmeModel_rb.ts +6 -3
  95. package/project/.sdk/src/cmp/rb/ReadmeOptions_rb.ts +58 -0
  96. package/project/.sdk/src/cmp/rb/ReadmeQuick_rb.ts +6 -4
  97. package/project/.sdk/src/cmp/rb/ReadmeRef_rb.ts +361 -0
  98. package/project/.sdk/src/cmp/rb/ReadmeTopQuick_rb.ts +6 -4
  99. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +172 -29
  100. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +120 -52
  101. package/project/.sdk/src/cmp/rb/fragment/Main.fragment.rb +19 -3
  102. package/project/.sdk/src/cmp/ts/Config_ts.ts +18 -0
  103. package/project/.sdk/src/cmp/ts/Package_ts.ts +1 -1
  104. package/project/.sdk/src/cmp/ts/ReadmeEntity_ts.ts +138 -0
  105. package/project/.sdk/src/cmp/ts/ReadmeHowto_ts.ts +11 -6
  106. package/project/.sdk/src/cmp/ts/ReadmeIntro_ts.ts +18 -0
  107. package/project/.sdk/src/cmp/ts/ReadmeModel_ts.ts +9 -5
  108. package/project/.sdk/src/cmp/ts/ReadmeOptions_ts.ts +58 -0
  109. package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +6 -4
  110. package/project/.sdk/src/cmp/ts/ReadmeRef_ts.ts +384 -0
  111. package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +6 -4
  112. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +213 -42
  113. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +168 -75
  114. package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +1 -5
  115. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +8 -1
  116. package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +8 -2
  117. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +21 -1
  118. package/project/.sdk/tm/go/feature/test_feature.go +51 -3
  119. package/project/.sdk/tm/go/test/runner_test.go +106 -6
  120. package/project/.sdk/tm/go/test/sdk-test-control.json +19 -0
  121. package/project/.sdk/tm/go/utility/fetcher.go +10 -0
  122. package/project/.sdk/tm/go/utility/make_url.go +12 -0
  123. package/project/.sdk/tm/go/utility/prepare_auth.go +15 -1
  124. package/project/.sdk/tm/js/src/utility/PrepareAuthUtility.js +7 -1
  125. package/project/.sdk/tm/lua/feature/test_feature.lua +41 -3
  126. package/project/.sdk/tm/lua/test/runner.lua +74 -0
  127. package/project/.sdk/tm/lua/test/sdk-test-control.json +19 -0
  128. package/project/.sdk/tm/lua/utility/fetcher.lua +13 -0
  129. package/project/.sdk/tm/lua/utility/make_url.lua +16 -0
  130. package/project/.sdk/tm/lua/utility/prepare_auth.lua +9 -1
  131. package/project/.sdk/tm/php/feature/TestFeature.php +185 -43
  132. package/project/.sdk/tm/php/test/Runner.php +62 -0
  133. package/project/.sdk/tm/php/test/sdk-test-control.json +19 -0
  134. package/project/.sdk/tm/php/utility/Fetcher.php +132 -9
  135. package/project/.sdk/tm/php/utility/MakeUrl.php +16 -0
  136. package/project/.sdk/tm/php/utility/PrepareAuth.php +11 -1
  137. package/project/.sdk/tm/py/feature/test_feature.py +35 -3
  138. package/project/.sdk/tm/py/test/runner.py +60 -0
  139. package/project/.sdk/tm/py/test/sdk-test-control.json +19 -0
  140. package/project/.sdk/tm/py/utility/fetcher.py +13 -0
  141. package/project/.sdk/tm/py/utility/make_url.py +13 -0
  142. package/project/.sdk/tm/py/utility/prepare_auth.py +10 -1
  143. package/project/.sdk/tm/rb/feature/test_feature.rb +36 -3
  144. package/project/.sdk/tm/rb/test/runner.rb +46 -0
  145. package/project/.sdk/tm/rb/test/sdk-test-control.json +19 -0
  146. package/project/.sdk/tm/rb/utility/fetcher.rb +49 -28
  147. package/project/.sdk/tm/rb/utility/make_url.rb +16 -0
  148. package/project/.sdk/tm/rb/utility/prepare_auth.rb +8 -1
  149. package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +7 -8
  150. package/project/.sdk/tm/ts/src/utility/PrepareAuthUtility.ts +7 -1
  151. package/project/.sdk/tm/ts/test/sdk-test-control.json +19 -0
  152. package/project/.sdk/tm/ts/test/utility.ts +120 -2
  153. package/src/cmp/ReadmeEntity.ts +11 -178
  154. package/src/cmp/ReadmeIntro.ts +11 -25
  155. package/src/cmp/ReadmeModel.ts +7 -5
  156. package/src/cmp/ReadmeOptions.ts +12 -74
  157. package/src/cmp/ReadmeRef.ts +11 -1372
  158. package/src/sdkgen.ts +2 -1
  159. package/src/utility.ts +12 -0
  160. /package/project/.sdk/tm/go/utility/{make_target.go → make_point.go} +0 -0
@@ -29,6 +29,7 @@ import {
29
29
  Slot,
30
30
  cmp,
31
31
  each,
32
+ isAuthActive,
32
33
  } from '@voxgig/sdkgen'
33
34
 
34
35
 
@@ -37,19 +38,36 @@ import {
37
38
  } from './utility_js'
38
39
 
39
40
 
40
- type OpGen = (model: any, entity: any, flow: any, step: any, index: { key$: number, val$: any }) => void
41
+ // See TestEntity_ts.ts for the GenCtx/OpGen contract this file mirrors
42
+ // it exactly, the only difference being the language string emitted.
43
+ type GenCtx = {
44
+ model: Model
45
+ entity: ModelEntity
46
+ flow: ModelEntityFlow
47
+ PROJUPPER: string
48
+ }
49
+
50
+ type OpGen = (ctx: GenCtx, step: ModelEntityFlowStep, index: number) => void
41
51
 
42
52
 
43
53
  const TestEntity = cmp(function TestEntity(props: any) {
44
54
  const ctx$ = props.ctx$
45
- const model = ctx$.model
55
+ const model: Model = ctx$.model
46
56
  const stdrep = ctx$.stdrep
47
57
 
48
58
  const target = props.target
49
- const entity = props.entity
59
+ const entity: ModelEntity = props.entity
50
60
 
51
61
  const PROJENVNAME = nom(model.const, 'NAME').replace(/[^A-Z_]/g, '_')
52
62
  const ENTENVNAME = nom(entity, 'NAME').replace(/[^A-Z_]/g, '_')
63
+ const authActive = isAuthActive(model)
64
+ const apikeyEnvEntry = authActive
65
+ ? `\n '${PROJENVNAME}_APIKEY': 'NONE',`
66
+ : ''
67
+ const apikeyLiveField = authActive
68
+ ? `
69
+ apikey: env.${PROJENVNAME}_APIKEY,`
70
+ : ''
53
71
 
54
72
  // TODO: should be a utility function
55
73
  const ff = projectPath('src/cmp/js/fragment/')
@@ -67,7 +85,7 @@ const TestEntity = cmp(function TestEntity(props: any) {
67
85
  }
68
86
  }, () => {
69
87
 
70
- const basicflow = getModelPath(model, `main.${KIT}.flow.Basic${entity.Name}Flow`)
88
+ const basicflow = getModelPath(model, `main.${KIT}.flow.Basic${nom(entity, 'Name')}Flow`)
71
89
 
72
90
  const dobasic = basicflow && true === basicflow.active
73
91
 
@@ -123,16 +141,14 @@ function basicSetup(extra) {
123
141
  const env = envOverride({
124
142
  '${PROJENVNAME}_TEST_${ENTENVNAME}_ENTID': idmap,
125
143
  '${PROJENVNAME}_TEST_LIVE': 'FALSE',
126
- '${PROJENVNAME}_TEST_EXPLAIN': 'FALSE',
127
- '${PROJENVNAME}_APIKEY': 'NONE',
144
+ '${PROJENVNAME}_TEST_EXPLAIN': 'FALSE',${apikeyEnvEntry}
128
145
  })
129
146
 
130
147
  idmap = env['${PROJENVNAME}_TEST_${ENTENVNAME}_ENTID']
131
148
 
132
149
  if ('TRUE' === env.${PROJENVNAME}_TEST_LIVE) {
133
150
  client = new ${model.Name}SDK(merge([
134
- {
135
- apikey: env.${PROJENVNAME}_APIKEY,
151
+ {${apikeyLiveField}
136
152
  },
137
153
  extra
138
154
  ]))
@@ -179,10 +195,15 @@ function basicSetup(extra) {
179
195
  `)
180
196
  }
181
197
 
182
- each(basicflow.step, (step: any, index: any) => {
183
- const opgen: OpGen = GENERATE_OP[step.op]
184
- opgen(model, entity, basicflow, step, index)
185
- Content('\n')
198
+ const genCtx: GenCtx = {
199
+ model, entity, flow: basicflow, PROJUPPER: PROJENVNAME,
200
+ }
201
+ each(basicflow.step, (step: ModelEntityFlowStep, index: number) => {
202
+ const opgen = GENERATE_OP[step.op]
203
+ if (null != opgen) {
204
+ opgen(genCtx, step, index)
205
+ Content('\n')
206
+ }
186
207
  })
187
208
  })
188
209
  })
@@ -191,25 +212,20 @@ function basicSetup(extra) {
191
212
  })
192
213
 
193
214
 
194
- const generateCreate: OpGen = (
195
- model: Model,
196
- entity: ModelEntity,
197
- flow: ModelEntityFlow,
198
- step: ModelEntityFlowStep,
199
- index: any
200
- ) => {
215
+ const generateCreate: OpGen = (ctx, step, index) => {
216
+ const { entity, flow } = ctx
201
217
  const ref = step.input.ref ?? entity.name + '_ref01'
202
218
  const entvar = step.input.entvar ?? ref + '_ent'
203
219
  const datavar = step.input.datavar ?? (ref + '_data' + (step.input.suffix ?? ''))
204
220
 
205
- const priorSteps = Object.values(flow.step).slice(0, Number(index))
206
- const needsEnt = !priorSteps.some((s: any) =>
221
+ const priorSteps = flow.step.slice(0, Number(index))
222
+ const needsEnt = !priorSteps.some(s =>
207
223
  ['create', 'list', 'load', 'update', 'remove'].includes(s.op))
208
224
 
209
- const hasDatvar = priorSteps.some((s: any) => {
225
+ const hasDatvar = priorSteps.some(s => {
210
226
  if ('create' === s.op) {
211
- const priorRef = s.input?.ref ?? entity.name + '_ref01'
212
- const priorDatvar = s.input?.datavar ?? (priorRef + '_data' + (s.input?.suffix ?? ''))
227
+ const priorRef = s.input.ref ?? entity.name + '_ref01'
228
+ const priorDatvar = s.input.datavar ?? (priorRef + '_data' + (s.input.suffix ?? ''))
213
229
  return priorDatvar === datavar
214
230
  }
215
231
  return false
@@ -235,27 +251,31 @@ const generateCreate: OpGen = (
235
251
  `)
236
252
  })
237
253
 
254
+ const hasEntIdC = null != entity.id
255
+
238
256
  Content(`
239
257
  ${datavar} = await ${entvar}.create(${datavar})
240
- assert(null != ${datavar}.id)
241
258
  `)
259
+ if (hasEntIdC) {
260
+ Content(` assert(null != ${datavar}.id)
261
+ `)
262
+ }
263
+ else {
264
+ Content(` assert(null != ${datavar})
265
+ `)
266
+ }
242
267
  }
243
268
 
244
269
 
245
- const generateList: OpGen = (
246
- model: Model,
247
- entity: ModelEntity,
248
- flow: ModelEntityFlow,
249
- step: ModelEntityFlowStep,
250
- index: any
251
- ) => {
270
+ const generateList: OpGen = (ctx, step, index) => {
271
+ const { entity, flow } = ctx
252
272
  const ref = step.input.ref ?? entity.name + '_ref01'
253
273
  const entvar = step.input.entvar ?? ref + '_ent'
254
274
  const matchvar = step.input.matchvar ?? (ref + '_match' + (step.input.suffix ?? ''))
255
275
  const listvar = step.input.listvar ?? (ref + '_list' + (step.input.suffix ?? ''))
256
276
 
257
- const priorSteps = Object.values(flow.step).slice(0, Number(index))
258
- const needsEnt = !priorSteps.some((s: any) =>
277
+ const priorSteps = flow.step.slice(0, Number(index))
278
+ const needsEnt = !priorSteps.some(s =>
259
279
  ['create', 'list', 'load', 'update', 'remove'].includes(s.op))
260
280
 
261
281
  Content(`
@@ -276,12 +296,12 @@ const generateList: OpGen = (
276
296
  Content(`
277
297
  const ${listvar} = await ${entvar}.list(${matchvar})
278
298
  `)
279
- const allSteps = Object.values(flow.step)
299
+ const allSteps = flow.step
280
300
  for (let vI = 0; vI < step.valid.length; vI++) {
281
301
  const validator = step.valid[vI]
282
302
  const validRef = validator.def?.ref
283
- const hasRefData = validRef && allSteps.some((s: any) => 'create' === s.op &&
284
- ((s.input?.ref ?? entity.name + '_ref01') === validRef))
303
+ const hasRefData = validRef && allSteps.some(s => 'create' === s.op &&
304
+ ((s.input.ref ?? entity.name + '_ref01') === validRef))
285
305
 
286
306
  if ('ItemExists' === validator.apply && hasRefData) {
287
307
  Content(`
@@ -297,13 +317,8 @@ const generateList: OpGen = (
297
317
  }
298
318
 
299
319
 
300
- const generateUpdate: OpGen = (
301
- model: Model,
302
- entity: ModelEntity,
303
- flow: ModelEntityFlow,
304
- step: ModelEntityFlowStep,
305
- index: any
306
- ) => {
320
+ const generateUpdate: OpGen = (ctx, step, index) => {
321
+ const { entity, flow } = ctx
307
322
  const ref = step.input.ref ?? entity.name + '_ref01'
308
323
  const entvar = step.input.entvar ?? ref + '_ent'
309
324
  const datavar = step.input.datavar ?? (ref + '_data' + (step.input.suffix ?? ''))
@@ -311,10 +326,12 @@ const generateUpdate: OpGen = (
311
326
  const markdefvar = step.input.markdefvar ?? (ref + '_markdef' + (step.input.suffix ?? ''))
312
327
  const srcdatavar = step.input.srcdatavar ?? (ref + '_data' + (step.input.suffix ?? ''))
313
328
 
314
- const priorSteps = Object.values(flow.step).slice(0, Number(index))
315
- const needsEnt = !priorSteps.some((s: any) =>
329
+ const priorSteps = flow.step.slice(0, Number(index))
330
+ const needsEnt = !priorSteps.some(s =>
316
331
  ['create', 'list', 'load', 'update', 'remove'].includes(s.op))
317
332
 
333
+ const hasEntIdU = null != entity.id
334
+
318
335
  Content(`
319
336
  // UPDATE
320
337
  `)
@@ -323,8 +340,11 @@ const generateUpdate: OpGen = (
323
340
  `)
324
341
  }
325
342
  Content(` const ${datavar} = {}
326
- ${datavar}.id = ${srcdatavar}.id
327
343
  `)
344
+ if (hasEntIdU) {
345
+ Content(` ${datavar}.id = ${srcdatavar}.id
346
+ `)
347
+ }
328
348
 
329
349
  each(step.data, (mi: any) => {
330
350
  if ('id' !== mi.key$) {
@@ -348,8 +368,15 @@ const generateUpdate: OpGen = (
348
368
 
349
369
  Content(`
350
370
  const ${resdatavar} = await ${entvar}.update(${datavar})
351
- assert(${resdatavar}.id === ${datavar}.id)
352
371
  `)
372
+ if (hasEntIdU) {
373
+ Content(` assert(${resdatavar}.id === ${datavar}.id)
374
+ `)
375
+ }
376
+ else {
377
+ Content(` assert(null != ${resdatavar})
378
+ `)
379
+ }
353
380
 
354
381
  for (let sI = 0; sI < step.spec.length; sI++) {
355
382
  const spec = step.spec[sI]
@@ -363,37 +390,34 @@ const generateUpdate: OpGen = (
363
390
  }
364
391
 
365
392
 
366
- const generateLoad: OpGen = (
367
- model: Model,
368
- entity: ModelEntity,
369
- flow: ModelEntityFlow,
370
- step: ModelEntityFlowStep,
371
- index: any
372
- ) => {
393
+ const generateLoad: OpGen = (ctx, step, index) => {
394
+ const { entity, flow } = ctx
373
395
  const ref = step.input.ref ?? entity.name + '_ref01'
374
396
  const entvar = step.input.entvar ?? ref + '_ent'
375
397
  const matchvar = step.input.matchvar ?? (ref + '_match' + (step.input.suffix ?? ''))
376
398
  const datavar = step.input.datavar ?? (ref + '_data' + (step.input.suffix ?? ''))
377
399
  const srcdatavar = step.input.srcdatavar ?? (ref + '_data' + (step.input.suffix ?? ''))
378
400
 
379
- const priorSteps = Object.values(flow.step).slice(0, Number(index))
380
- const hasEntVar = priorSteps.some((s: any) =>
401
+ const priorSteps = flow.step.slice(0, Number(index))
402
+ const hasEntVar = priorSteps.some(s =>
381
403
  ['create', 'list', 'load', 'update', 'remove'].includes(s.op))
382
404
 
383
405
  // Check if srcdatavar was declared by a prior create step or by the
384
406
  // preamble bootstrap (which runs when the flow has no create step)
385
- const flowHasCreate = Object.values(flow.step).some((s: any) => s.op === 'create')
407
+ const flowHasCreate = flow.step.some(s => s.op === 'create')
386
408
  const preambleRef = entity.name + '_ref01'
387
409
  const hasSrcData = (!flowHasCreate && srcdatavar === preambleRef + '_data') ||
388
- priorSteps.some((s: any) => {
410
+ priorSteps.some(s => {
389
411
  if ('create' === s.op) {
390
- const priorRef = s.input?.ref ?? entity.name + '_ref01'
391
- const priorDatvar = s.input?.datavar ?? (priorRef + '_data' + (s.input?.suffix ?? ''))
412
+ const priorRef = s.input.ref ?? entity.name + '_ref01'
413
+ const priorDatvar = s.input.datavar ?? (priorRef + '_data' + (s.input.suffix ?? ''))
392
414
  return priorDatvar === srcdatavar
393
415
  }
394
416
  return false
395
417
  })
396
418
 
419
+ const hasEntId = null != entity.id
420
+
397
421
  Content(`
398
422
  // LOAD
399
423
  `)
@@ -401,34 +425,39 @@ const generateLoad: OpGen = (
401
425
  Content(` const ${entvar} = client.${nom(entity, 'Name')}()
402
426
  `)
403
427
  }
404
- if (!hasSrcData) {
428
+ if (!hasSrcData && hasEntId) {
405
429
  Content(` const ${srcdatavar} = Object.values(setup.data.existing.${entity.name})[0]
406
430
  `)
407
431
  }
408
- Content(` const ${matchvar} = {}
432
+ if (hasEntId) {
433
+ Content(` const ${matchvar} = {}
409
434
  ${matchvar}.id = ${srcdatavar}.id
410
435
  const ${datavar} = await ${entvar}.load(${matchvar})
411
436
  assert(${datavar}.id === ${srcdatavar}.id)
412
437
  `)
438
+ }
439
+ else {
440
+ Content(` const ${matchvar} = {}
441
+ const ${datavar} = await ${entvar}.load(${matchvar})
442
+ assert(null != ${datavar})
443
+ `)
444
+ }
413
445
  }
414
446
 
415
447
 
416
- const generateRemove: OpGen = (
417
- model: Model,
418
- entity: ModelEntity,
419
- flow: ModelEntityFlow,
420
- step: ModelEntityFlowStep,
421
- index: any
422
- ) => {
448
+ const generateRemove: OpGen = (ctx, step, index) => {
449
+ const { entity, flow } = ctx
423
450
  const ref = step.input.ref ?? entity.name + '_ref01'
424
451
  const entvar = step.input.entvar ?? ref + '_ent'
425
452
  const matchvar = step.input.matchvar ?? (ref + '_match' + (step.input.suffix ?? ''))
426
453
  const srcdatavar = step.input.srcdatavar ?? (ref + '_data')
427
454
 
428
- const priorSteps = Object.values(flow.step).slice(0, Number(index))
429
- const needsEnt = !priorSteps.some((s: any) =>
455
+ const priorSteps = flow.step.slice(0, Number(index))
456
+ const needsEnt = !priorSteps.some(s =>
430
457
  ['create', 'list', 'load', 'update', 'remove'].includes(s.op))
431
458
 
459
+ const hasEntIdR = null != entity.id
460
+
432
461
  Content(`
433
462
  // REMOVE
434
463
  `)
@@ -437,8 +466,12 @@ const generateRemove: OpGen = (
437
466
  `)
438
467
  }
439
468
  Content(` const ${matchvar} = {}
440
- ${matchvar}.id = ${srcdatavar}.id
441
- await ${entvar}.remove(${matchvar})
469
+ `)
470
+ if (hasEntIdR) {
471
+ Content(` ${matchvar}.id = ${srcdatavar}.id
472
+ `)
473
+ }
474
+ Content(` await ${entvar}.remove(${matchvar})
442
475
  `)
443
476
  }
444
477
 
@@ -31,11 +31,7 @@ class Config {
31
31
  options = {
32
32
  base: '$$main.kit.info.servers.0.url$$',
33
33
 
34
- auth: {
35
- prefix: '$$main.kit.config.auth.prefix$$',
36
- },
37
-
38
- headers: 'HEADERS',
34
+ 'AUTHBLOCK'headers: 'HEADERS',
39
35
 
40
36
  entity: {
41
37
  // #EntityConfigs
@@ -9,6 +9,7 @@ import {
9
9
  Line,
10
10
  cmp,
11
11
  each,
12
+ isAuthActive,
12
13
  } from '@voxgig/sdkgen'
13
14
 
14
15
 
@@ -37,12 +38,19 @@ const Config = cmp(async function Config(props: any) {
37
38
 
38
39
  const headers = getModelPath(model, `main.${KIT}.config.headers`) || {}
39
40
 
41
+ const authActive = isAuthActive(model)
40
42
  let authPrefix = ''
41
43
  try { authPrefix = getModelPath(model, `main.${KIT}.config.auth.prefix`) } catch (_e) { }
42
44
 
43
45
  let baseUrl = ''
44
46
  try { baseUrl = getModelPath(model, `main.${KIT}.info.servers.0.url`) } catch (_e) { }
45
47
 
48
+ const authBlock = authActive
49
+ ? ` auth = {
50
+ prefix = "${authPrefix}",
51
+ },\n`
52
+ : ''
53
+
46
54
  File({ name: 'config.' + target.ext }, () => {
47
55
 
48
56
  Content(`-- ProjectName SDK configuration
@@ -64,10 +72,7 @@ local function make_config()
64
72
  Content(` },
65
73
  options = {
66
74
  base = "${baseUrl}",
67
- auth = {
68
- prefix = "${authPrefix}",
69
- },
70
- headers = ${formatLuaTable(headers, 3)},
75
+ ${authBlock} headers = ${formatLuaTable(headers, 3)},
71
76
  entity = {
72
77
  `)
73
78
 
@@ -18,11 +18,18 @@ const Package = cmp(async function Package(props: any) {
18
18
 
19
19
  const model: Model = ctx$.model
20
20
 
21
+ // Rock name is namespaced to model.origin (e.g. "voxgig-sdk"). LuaRocks has
22
+ // no real namespaces, so the parts are hyphen-joined. The Lua module name
23
+ // (`${model.name}_sdk`) used by `require` is unchanged.
24
+ const ns = model.origin || 'voxgig-sdk'
25
+ const pkgBase = ns.endsWith('-sdk') ? model.name : `${model.name}-sdk`
26
+ const rockName = `${ns}-${pkgBase}`
27
+
21
28
  File({ name: model.name + '.rockspec' }, () => {
22
- Content(`package = "${model.name}-sdk"
29
+ Content(`package = "${rockName}"
23
30
  version = "0.0-1"
24
31
  source = {
25
- url = "git://github.com/voxgig/${model.name}-sdk.git"
32
+ url = "git://github.com/${ns}/${model.name}-sdk.git"
26
33
  }
27
34
  description = {
28
35
  summary = "${model.const.Name} SDK for Lua",
@@ -0,0 +1,138 @@
1
+
2
+ import { cmp, each, Content } from '@voxgig/sdkgen'
3
+
4
+ import {
5
+ KIT,
6
+ getModelPath,
7
+ } from '@voxgig/apidef'
8
+
9
+
10
+ // Operation method spelling differs between Go and other languages — Go
11
+ // uses PascalCase methods with explicit ctrl arg, others use lowercase
12
+ // methods with optional ctrl. The op descriptions are language-agnostic.
13
+ const OP_DESC: Record<string, { method: string, desc: string }> = {
14
+ load: { method: 'load(match)', desc: 'Load a single entity by match criteria.' },
15
+ list: { method: 'list(match)', desc: 'List entities matching the criteria.' },
16
+ create: { method: 'create(data)', desc: 'Create a new entity with the given data.' },
17
+ update: { method: 'update(data)', desc: 'Update an existing entity.' },
18
+ remove: { method: 'remove(match)', desc: 'Remove the matching entity.' },
19
+ }
20
+
21
+
22
+ const ReadmeEntity = cmp(function ReadmeEntity(props: any) {
23
+ const { target } = props
24
+ const { model } = props.ctx$
25
+
26
+ const entity = getModelPath(model, `main.${KIT}.entity`)
27
+
28
+ const publishedEntities = each(entity)
29
+ .filter((entity: any) => entity.active !== false)
30
+
31
+ if (0 === publishedEntities.length) {
32
+ return
33
+ }
34
+
35
+ Content(`
36
+
37
+ ## Entities
38
+
39
+ `)
40
+
41
+ publishedEntities.map((entity: any) => {
42
+ const opnames = Object.keys(entity.op || {})
43
+ const fields = entity.fields || []
44
+
45
+ Content(`
46
+ ### ${entity.Name}
47
+
48
+ `)
49
+
50
+ if (entity.short) {
51
+ Content(`${entity.short}
52
+
53
+ `)
54
+ }
55
+
56
+ Content(`Create an instance: \`const ${entity.name} = client.${entity.Name}()\`
57
+
58
+ `)
59
+
60
+ if (opnames.length > 0) {
61
+ Content(`#### Operations
62
+
63
+ | Method | Description |
64
+ | --- | --- |
65
+ `)
66
+ opnames.map((opname: string) => {
67
+ const info = OP_DESC[opname]
68
+ if (info) {
69
+ Content(`| \`${info.method}\` | ${info.desc} |
70
+ `)
71
+ }
72
+ })
73
+
74
+ Content(`
75
+ `)
76
+ }
77
+
78
+ if (fields.length > 0) {
79
+ Content(`#### Fields
80
+
81
+ | Field | Type | Description |
82
+ | --- | --- | --- |
83
+ `)
84
+
85
+ each(fields, (field: any) => {
86
+ const desc = field.short || ''
87
+ Content(`| \`${field.name}\` | \`${field.type || 'any'}\` | ${desc} |
88
+ `)
89
+ })
90
+
91
+ Content(`
92
+ `)
93
+ }
94
+
95
+ if (opnames.includes('load')) {
96
+ Content(`#### Example: Load
97
+
98
+ \`\`\`ts
99
+ const ${entity.name} = await client.${entity.Name}().load({ id: '${entity.name}_id' })
100
+ \`\`\`
101
+
102
+ `)
103
+ }
104
+
105
+ if (opnames.includes('list')) {
106
+ Content(`#### Example: List
107
+
108
+ \`\`\`ts
109
+ const ${entity.name}s = await client.${entity.Name}().list()
110
+ \`\`\`
111
+
112
+ `)
113
+ }
114
+
115
+ if (opnames.includes('create')) {
116
+ Content(`#### Example: Create
117
+
118
+ \`\`\`ts
119
+ const ${entity.name} = await client.${entity.Name}().create({
120
+ `)
121
+ each(fields, (field: any) => {
122
+ if ('id' !== field.name && field.req) {
123
+ Content(` ${field.name}: /* ${field.type || 'value'} */,
124
+ `)
125
+ }
126
+ })
127
+ Content(`})
128
+ \`\`\`
129
+
130
+ `)
131
+ }
132
+ })
133
+ })
134
+
135
+
136
+ export {
137
+ ReadmeEntity
138
+ }
@@ -1,10 +1,14 @@
1
1
 
2
- import { cmp, Content } from '@voxgig/sdkgen'
2
+ import { cmp, Content, isAuthActive } from '@voxgig/sdkgen'
3
3
 
4
4
 
5
5
  const ReadmeHowto = cmp(function ReadmeHowto(props: any) {
6
6
  const { target, ctx$: { model } } = props
7
7
 
8
+ const apikeyEnvLine = isAuthActive(model)
9
+ ? `\n${model.NAME}_APIKEY=<your-key>`
10
+ : ''
11
+
8
12
  Content(`### Make a direct HTTP request
9
13
 
10
14
  For endpoints not covered by entity methods:
@@ -80,8 +84,7 @@ local client = sdk.new({
80
84
  Create a \`.env.local\` file at the project root:
81
85
 
82
86
  \`\`\`
83
- ${model.NAME}_TEST_LIVE=TRUE
84
- ${model.NAME}_APIKEY=<your-key>
87
+ ${model.NAME}_TEST_LIVE=TRUE${apikeyEnvLine}
85
88
  \`\`\`
86
89
 
87
90
  Then run:
@@ -0,0 +1,18 @@
1
+
2
+ import { cmp, Content } from '@voxgig/sdkgen'
3
+
4
+
5
+ const ReadmeIntro = cmp(function ReadmeIntro(props: any) {
6
+ const { target, ctx$: { model } } = props
7
+
8
+ Content(`# ${model.Name} ${target.title} SDK
9
+
10
+ The ${target.title} SDK for the ${model.Name} API. Provides an entity-oriented interface using Lua conventions.
11
+
12
+ `)
13
+ })
14
+
15
+
16
+ export {
17
+ ReadmeIntro
18
+ }
@@ -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,
@@ -13,6 +13,10 @@ const ReadmeModel = cmp(function ReadmeModel(props: any) {
13
13
  const entity = getModelPath(model, `main.${KIT}.entity`)
14
14
  const entityList = each(entity).filter((e: any) => e.active !== false)
15
15
 
16
+ const apikeyOptionRow = isAuthActive(model)
17
+ ? '| `apikey` | `string` | API key for authentication. |\n'
18
+ : ''
19
+
16
20
  Content(`### ${model.const.Name}SDK
17
21
 
18
22
  \`\`\`lua
@@ -24,8 +28,7 @@ Creates a new SDK client.
24
28
 
25
29
  | Option | Type | Description |
26
30
  | --- | --- | --- |
27
- | \`apikey\` | \`string\` | API key for authentication. |
28
- | \`base\` | \`string\` | Base URL of the API server. |
31
+ ${apikeyOptionRow}| \`base\` | \`string\` | Base URL of the API server. |
29
32
  | \`prefix\` | \`string\` | URL path prefix prepended to all requests. |
30
33
  | \`suffix\` | \`string\` | URL path suffix appended to all requests. |
31
34
  | \`feature\` | \`table\` | Feature activation flags. |