@voxgig/apidef 8.22.1 → 8.24.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 (54) hide show
  1. package/dist/apidef.d.ts +1 -1
  2. package/dist/apidef.js +2 -0
  3. package/dist/apidef.js.map +1 -1
  4. package/dist/builder/entity/entity.d.ts +2 -1
  5. package/dist/builder/entity/entity.js +14 -11
  6. package/dist/builder/entity/entity.js.map +1 -1
  7. package/dist/guide/guide.js +5 -2
  8. package/dist/guide/guide.js.map +1 -1
  9. package/dist/guide/heuristic01.d.ts +11 -1
  10. package/dist/guide/heuristic01.js +457 -100
  11. package/dist/guide/heuristic01.js.map +1 -1
  12. package/dist/model.d.ts +18 -1
  13. package/dist/transform/args.d.ts +4 -1
  14. package/dist/transform/args.js +67 -20
  15. package/dist/transform/args.js.map +1 -1
  16. package/dist/transform/body.d.ts +23 -0
  17. package/dist/transform/body.js +474 -0
  18. package/dist/transform/body.js.map +1 -0
  19. package/dist/transform/entity.d.ts +1 -1
  20. package/dist/transform/entity.js +13 -4
  21. package/dist/transform/entity.js.map +1 -1
  22. package/dist/transform/field.d.ts +3 -1
  23. package/dist/transform/field.js +159 -87
  24. package/dist/transform/field.js.map +1 -1
  25. package/dist/transform/operation.js +77 -24
  26. package/dist/transform/operation.js.map +1 -1
  27. package/dist/transform/select.js +44 -11
  28. package/dist/transform/select.js.map +1 -1
  29. package/dist/transform/top.d.ts +3 -2
  30. package/dist/transform/top.js +127 -11
  31. package/dist/transform/top.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/dist/types.d.ts +6 -0
  34. package/dist/types.js.map +1 -1
  35. package/dist/utility.d.ts +11 -1
  36. package/dist/utility.js +156 -13
  37. package/dist/utility.js.map +1 -1
  38. package/model/apidef.aontu +29 -6
  39. package/model/guide.aontu +8 -0
  40. package/package.json +1 -1
  41. package/src/apidef.ts +5 -0
  42. package/src/builder/entity/entity.ts +17 -15
  43. package/src/guide/guide.ts +5 -3
  44. package/src/guide/heuristic01.ts +587 -104
  45. package/src/model.ts +27 -0
  46. package/src/transform/args.ts +83 -22
  47. package/src/transform/body.ts +638 -0
  48. package/src/transform/entity.ts +20 -4
  49. package/src/transform/field.ts +190 -88
  50. package/src/transform/operation.ts +97 -26
  51. package/src/transform/select.ts +49 -11
  52. package/src/transform/top.ts +154 -15
  53. package/src/types.ts +6 -0
  54. package/src/utility.ts +190 -13
package/model/guide.aontu CHANGED
@@ -33,6 +33,14 @@ guide: entity: &: {
33
33
  active?: boolean
34
34
  method: string
35
35
 
36
+ # Media types chosen over the heuristic's: the request body's, and the response's.
37
+ body?: {
38
+ media?: string
39
+ }
40
+ response?: {
41
+ media?: string
42
+ }
43
+
36
44
  transform?: {
37
45
  req?: top
38
46
  res?: top
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/apidef",
3
- "version": "8.22.1",
3
+ "version": "8.24.0",
4
4
  "main": "dist/apidef.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/apidef.d.ts",
package/src/apidef.ts CHANGED
@@ -74,6 +74,7 @@ import { contractTransform } from './transform/contract'
74
74
  import { operationTransform } from './transform/operation'
75
75
  import { graphqlTransform } from './transform/graphql'
76
76
  import { argsTransform } from './transform/args'
77
+ import { bodyTransform } from './transform/body'
77
78
  import { selectTransform } from './transform/select'
78
79
  import { fieldTransform } from './transform/field'
79
80
  import { casecollideTransform } from './transform/casecollide'
@@ -282,6 +283,7 @@ function ApiDef(opts: ApiDefOptions) {
282
283
  await graphqlTransform(ctx)
283
284
  await contractTransform(ctx)
284
285
  await argsTransform(ctx)
286
+ await bodyTransform(ctx)
285
287
  await selectTransform(ctx)
286
288
  await fieldTransform(ctx)
287
289
  // Before flowTransform, so no flow is built for an entity it drops.
@@ -533,6 +535,9 @@ export type {
533
535
  ModelField,
534
536
  ModelArg,
535
537
  ModelPoint,
538
+ BodyKind,
539
+ ModelBodyField,
540
+ ModelBody,
536
541
  ModelOp,
537
542
  ModelEntity,
538
543
  Model,
@@ -35,21 +35,7 @@ function resolveEntity(
35
35
  each(kit.entity, ((entity: any, entityName: string) => {
36
36
  const entityFile = (null == opts.outprefix ? '' : opts.outprefix) + entityName + '.aontu'
37
37
 
38
- const { model, relations } = entityAncestorSource(entity)
39
- let entityJSONIC = formatJSONIC(model).trim()
40
- entityJSONIC = entityJSONIC.substring(1, entityJSONIC.length - 1)
41
-
42
- const fieldAliasesSrc = fieldAliases(entity)
43
-
44
- const entitySrc =
45
- `# Entity: ${entity.name}\n\n` +
46
- `main: ${KIT}: entity: ${entity.name}: {\n\n` +
47
- ` alias: field: ${fieldAliasesSrc}\n` +
48
- entityJSONIC +
49
- relations +
50
- '\n\n}\n'
51
-
52
- entityFiles.push({ name: entityFile, src: entitySrc })
38
+ entityFiles.push({ name: entityFile, src: entitySource(entity) })
53
39
 
54
40
  barrel.push(`@"./${Path.basename(entityFile)}"`)
55
41
  }))
@@ -67,6 +53,21 @@ function resolveEntity(
67
53
  }
68
54
  }
69
55
 
56
+ // The text of one entity's model file.
57
+ function entitySource(entity: any): string {
58
+ const { model, relations } = entityAncestorSource(entity)
59
+ let entityJSONIC = formatJSONIC(model).trim()
60
+ entityJSONIC = entityJSONIC.substring(1, entityJSONIC.length - 1)
61
+
62
+ return `# Entity: ${entity.name}\n\n` +
63
+ `main: ${KIT}: entity: ${entity.name}: {\n\n` +
64
+ ` alias: field: ${fieldAliases(entity)}\n` +
65
+ entityJSONIC +
66
+ relations +
67
+ '\n\n}\n'
68
+ }
69
+
70
+
70
71
  function entityAncestorSource(entity: any): { model: any, relations: string } {
71
72
  const model = { ...entity }
72
73
  const ancestors: string[][] = entity.relations?.ancestors ?? []
@@ -144,6 +145,7 @@ function fieldAliases(_entity: any): string {
144
145
 
145
146
  export {
146
147
  resolveEntity,
148
+ entitySource,
147
149
  gcEntityFiles,
148
150
  entityAncestorSource,
149
151
  }
@@ -391,9 +391,11 @@ async function buildBaseGuide(ctx: ApiDefContext) {
391
391
  if (null != op.optype) {
392
392
  guideBlocks.push(` op: ${opname}: optype: *${op.optype}`)
393
393
  }
394
- if (null != op.transform.res) {
395
- guideBlocks.push(
396
- ` op: ${opname}: transform: res: *${qt(op.transform.res)}|top`)
394
+ // aontu generates a list default only when it is not parenthesized.
395
+ const res = op.transform.res
396
+ if (null != res) {
397
+ guideBlocks.push(` op: ${opname}: transform: res: ` +
398
+ `*${'string' === typeof res ? qt(res) : qs(res)}|top`)
397
399
  }
398
400
  const reqmap: any = op.transform.req
399
401
  if (null != reqmap && 'object' === typeof reqmap) {