@voxgig/sdkgen 4.31.0 → 4.32.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.
Files changed (76) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/package.d.ts +2 -1
  3. package/dist/action/package.js +8 -1
  4. package/dist/action/package.js.map +1 -1
  5. package/dist/helpers/definitionPlan.d.ts +5 -0
  6. package/dist/helpers/definitionPlan.js +44 -7
  7. package/dist/helpers/definitionPlan.js.map +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/package.json +1 -1
  10. package/project/.sdk/tm/c/utility/make_url.c +11 -0
  11. package/project/.sdk/tm/c/utility/prepare_headers.c +53 -3
  12. package/project/.sdk/tm/c/utility/prepare_query.c +4 -1
  13. package/project/.sdk/tm/c/utility/transform_request.c +31 -8
  14. package/project/.sdk/tm/clojure/src/sdk/core.clj +62 -15
  15. package/project/.sdk/tm/cpp/utility/pipeline.hpp +72 -15
  16. package/project/.sdk/tm/csharp/utility/MakeUrl.cs +8 -0
  17. package/project/.sdk/tm/csharp/utility/PrepareHeaders.cs +34 -4
  18. package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +14 -0
  19. package/project/.sdk/tm/csharp/utility/TransformRequest.cs +31 -5
  20. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +86 -24
  21. package/project/.sdk/tm/go/utility/make_url.go +8 -0
  22. package/project/.sdk/tm/go/utility/prepare_headers.go +36 -7
  23. package/project/.sdk/tm/go/utility/prepare_query.go +11 -0
  24. package/project/.sdk/tm/go/utility/transform_request.go +31 -5
  25. package/project/.sdk/tm/java/utility/MakeUrl.java +8 -0
  26. package/project/.sdk/tm/java/utility/PrepareHeaders.java +30 -6
  27. package/project/.sdk/tm/java/utility/PrepareQuery.java +10 -0
  28. package/project/.sdk/tm/java/utility/TransformRequest.java +30 -5
  29. package/project/.sdk/tm/js/src/utility/MakeUrlUtility.js +7 -0
  30. package/project/.sdk/tm/js/src/utility/PrepareHeadersUtility.js +18 -0
  31. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +3 -1
  32. package/project/.sdk/tm/js/src/utility/TransformRequestUtility.js +17 -3
  33. package/project/.sdk/tm/js/test/definition-runner.js +74 -13
  34. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +8 -0
  35. package/project/.sdk/tm/kotlin/utility/Prepare.kt +34 -4
  36. package/project/.sdk/tm/kotlin/utility/ResultTransform.kt +18 -6
  37. package/project/.sdk/tm/lua/utility/make_url.lua +8 -0
  38. package/project/.sdk/tm/lua/utility/prepare_headers.lua +35 -6
  39. package/project/.sdk/tm/lua/utility/prepare_query.lua +10 -0
  40. package/project/.sdk/tm/lua/utility/transform_request.lua +37 -6
  41. package/project/.sdk/tm/ocaml/sdk_runtime.ml +63 -13
  42. package/project/.sdk/tm/perl/utility/make_url.pm +6 -0
  43. package/project/.sdk/tm/perl/utility/prepare_headers.pm +21 -3
  44. package/project/.sdk/tm/perl/utility/prepare_query.pm +8 -0
  45. package/project/.sdk/tm/perl/utility/transform_request.pm +19 -7
  46. package/project/.sdk/tm/php/utility/MakeUrl.php +7 -0
  47. package/project/.sdk/tm/php/utility/PrepareHeaders.php +33 -4
  48. package/project/.sdk/tm/php/utility/PrepareQuery.php +11 -0
  49. package/project/.sdk/tm/php/utility/TransformRequest.php +28 -5
  50. package/project/.sdk/tm/py/pkg/utility/make_url.py +7 -0
  51. package/project/.sdk/tm/py/pkg/utility/prepare_headers.py +27 -6
  52. package/project/.sdk/tm/py/pkg/utility/prepare_query.py +8 -0
  53. package/project/.sdk/tm/py/pkg/utility/transform_request.py +21 -5
  54. package/project/.sdk/tm/rb/utility/make_url.rb +7 -0
  55. package/project/.sdk/tm/rb/utility/prepare_headers.rb +21 -3
  56. package/project/.sdk/tm/rb/utility/prepare_query.rb +8 -0
  57. package/project/.sdk/tm/rb/utility/transform_request.rb +18 -5
  58. package/project/.sdk/tm/rust/utility/make_url.rs +10 -1
  59. package/project/.sdk/tm/rust/utility/prepare_headers.rs +43 -7
  60. package/project/.sdk/tm/rust/utility/prepare_query.rs +18 -1
  61. package/project/.sdk/tm/rust/utility/transform_request.rs +29 -7
  62. package/project/.sdk/tm/scala/utility/Make.scala +9 -0
  63. package/project/.sdk/tm/scala/utility/Prepare.scala +42 -3
  64. package/project/.sdk/tm/scala/utility/Transform.scala +30 -6
  65. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +7 -0
  66. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +28 -2
  67. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/ResultUtil.swift +23 -5
  68. package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +7 -0
  69. package/project/.sdk/tm/ts/src/utility/PrepareHeadersUtility.ts +16 -0
  70. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +3 -1
  71. package/project/.sdk/tm/ts/src/utility/TransformRequestUtility.ts +16 -3
  72. package/project/.sdk/tm/ts/test/definition-runner.ts +75 -13
  73. package/project/.sdk/tm/zig/core/utility.zig +80 -20
  74. package/project/sdkgen-package.json +1 -1
  75. package/src/action/package.ts +10 -1
  76. package/src/helpers/definitionPlan.ts +49 -7
@@ -5,6 +5,7 @@ import { KIT, nom } from '@voxgig/apidef'
5
5
  import { entityCollection } from './opShape'
6
6
  import { pointSegments } from './pointPath'
7
7
  import { pointFacts } from './resolved'
8
+ import { isAuthSuppressed, resolveAuthIn, resolveAuthName } from '../utility'
8
9
 
9
10
 
10
11
  // What a generated definition test checks an operation against: the API
@@ -23,6 +24,7 @@ type DefinitionPoint = {
23
24
  action?: string
24
25
  args: { name: string, wire: string, value: any }[]
25
26
  select: Record<string, any>
27
+ headers: { name: string, wire: string, value: any }[]
26
28
  query: string[]
27
29
  auth: Credential[][] | null
28
30
  status: number
@@ -31,6 +33,10 @@ type DefinitionPoint = {
31
33
  }
32
34
 
33
35
 
36
+ // The operations every target generates a method for. The model may hold
37
+ // others, such as a patch beside an update, which no SDK can be called with.
38
+ const GENERATED_OPS = ['load', 'list', 'create', 'update', 'remove']
39
+
34
40
  const MAX_ITEMS = 3
35
41
  const MAX_DEPTH = 8
36
42
  const MAX_SAMPLE = 32 * 1024
@@ -41,13 +47,19 @@ function definitionPlan(ctx$: any): DefinitionPoint[] {
41
47
  const plan: DefinitionPoint[] = []
42
48
  const unchecked = false === model?.main?.[KIT]?.config?.auth?.active ||
43
49
  false === model?.main?.[KIT]?.info?.auth
50
+ // A generated SDK sends one credential, under the scheme apidef chose for it.
51
+ const own = model?.main?.[KIT]?.info?.security?.scheme
52
+ // The header the SDK puts any key in, as its prepareAuth does, though the
53
+ // definition declares no scheme: LearnWorlds declares it as a parameter.
54
+ const ownHeader = !isAuthSuppressed(model) && 'header' === resolveAuthIn(model) ?
55
+ resolveAuthName(model).toLowerCase() : null
44
56
 
45
57
  for (const entity of Object.values(entityCollection(model)) as any[]) {
46
58
  if (false === entity.active) continue
47
59
 
48
60
  for (const [op, operation] of Object.entries(entity.op || {}) as any[]) {
49
61
  // An inactive operation stays in the model but gets no method.
50
- if (false === operation?.active) continue
62
+ if (false === operation?.active || !GENERATED_OPS.includes(op)) continue
51
63
 
52
64
  const points = (operation?.points || []).filter((p: any) => false !== p.a)
53
65
 
@@ -71,9 +83,21 @@ function definitionPlan(ctx$: any): DefinitionPoint[] {
71
83
  return { name: arg.n, wire, value: scalar(def?.example ?? def?.schema?.example) ?? 'p' + (i + 1) }
72
84
  })
73
85
 
86
+ // A header argument is sent too, and must arrive as a header under
87
+ // the definition's name, never in the query.
88
+ const headers = (point.g?.header || [])
89
+ .filter((arg: any) => false !== arg.a &&
90
+ ![ownHeader, 'content-type'].includes(String(arg.or || arg.n).toLowerCase()))
91
+ .map((arg: any, i: number) => {
92
+ const wire = String(arg.or || arg.n)
93
+ const def = params.find((p: any) => 'header' === p?.in &&
94
+ wire.toLowerCase() === String(p?.name).toLowerCase())
95
+ return { name: arg.n, wire, value: scalar(arg.ex ?? def?.example ?? def?.schema?.example) ?? 'h' + (i + 1) }
96
+ })
97
+
74
98
  const selected: Record<string, any> = {}
75
99
  for (const key of select.exist || []) {
76
- if (args.some((a: any) => a.name === key)) continue
100
+ if (args.some((a: any) => a.name === key) || headers.some((h: any) => h.name === key)) continue
77
101
  const def = params.find((p: any) => key === p?.name)
78
102
  selected[key] = scalar(def?.example ?? def?.schema?.example) ?? 'v1'
79
103
  }
@@ -101,10 +125,11 @@ function definitionPlan(ctx$: any): DefinitionPoint[] {
101
125
  ...(null == select.$action ? {} : { action: select.$action }),
102
126
  args,
103
127
  select: selected,
128
+ headers,
104
129
  query: params.filter((p: any) => 'query' === p?.in).map((p: any) => p.name),
105
- auth: unchecked ? null : credentialSets(facts),
130
+ auth: unchecked ? null : credentialSets(facts, own),
106
131
  status: success?.status ?? 200,
107
- sample: null == media ? null : boundedSample(sampleOf(media)),
132
+ sample: null == media ? null : boundedSample(fitting(sampleOf(media), media.schema)),
108
133
  idField: entity.id?.field || 'id',
109
134
  })
110
135
  }
@@ -168,6 +193,20 @@ function sampleOf(media: any): any {
168
193
  }
169
194
 
170
195
 
196
+ // An example whose top level contradicts its own schema proves nothing, such
197
+ // as GitHub's page of deployment rule apps written as a list of its halves.
198
+ function fitting(sample: any, schema: any): any {
199
+ const type = Array.isArray(schema?.type) ?
200
+ schema.type.find((t: string) => 'null' !== t) : schema?.type
201
+ const object = 'object' === type || (null == type && null != schema?.properties)
202
+ const array = 'array' === type || (null == type && null != schema?.items)
203
+ if (object && (Array.isArray(sample) || null == sample || 'object' !== typeof sample)) {
204
+ return undefined
205
+ }
206
+ return array && !Array.isArray(sample) ? undefined : sample
207
+ }
208
+
209
+
171
210
  // Schema-shaped data where the definition gives no example: every property,
172
211
  // one item per array, the first branch of a union.
173
212
  function synthesize(schema: any, depth: number): any {
@@ -222,15 +261,18 @@ function boundedSample(sample: any): any {
222
261
 
223
262
 
224
263
  // Alternatives of credentials, every one of a set needed together. Empty is a
225
- // public operation; null is one whose schemes no SDK option can express.
226
- function credentialSets(facts: any): Credential[][] | null {
264
+ // public operation; null is one whose schemes no SDK option can express. Only
265
+ // those the SDK's one scheme meets count, so Petstore's OAuth pets are null.
266
+ function credentialSets(facts: any, own?: string): Credential[][] | null {
227
267
  const security = facts.security
228
268
  if (!Array.isArray(security) || 0 === security.length) return []
229
269
  if (security.some((req: any) => null == req || 0 === Object.keys(req).length)) return []
230
270
 
271
+ const reqs = 'string' === typeof own && '' !== own ?
272
+ security.filter((req: any) => Object.keys(req).every((name) => name === own)) : security
231
273
  const schemes = facts.securitySchemes || {}
232
274
  const sets: Credential[][] = []
233
- for (const req of security) {
275
+ for (const req of reqs) {
234
276
  const set = Object.keys(req).map((name) => credentialOf(schemes[name]))
235
277
  if (set.every((c) => null != c)) sets.push(set as Credential[])
236
278
  }