@voxgig/apidef 1.1.0 → 1.2.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.
@@ -9,7 +9,7 @@ import type { TransformCtx, TransformSpec } from '../transform'
9
9
  const { deep } = Jsonic.util
10
10
 
11
11
  async function manualTransform(ctx: TransformCtx, tspec: TransformSpec, model: any, def: any) {
12
- const { guide: { guide: { manual } } } = ctx
12
+ const { model: { main: { guide: { manual } } } } = ctx
13
13
 
14
14
  deep(model, manual)
15
15
 
@@ -14,7 +14,7 @@ async function operationTransform(
14
14
  model: any,
15
15
  def: any
16
16
  ) {
17
- const { guide: { guide } } = ctx
17
+ const { model: { main: { guide } } } = ctx
18
18
  let msg = 'operations: '
19
19
 
20
20
  const paramBuilder = (paramMap: any, paramDef: any,
@@ -96,7 +96,6 @@ async function operationTransform(
96
96
  }
97
97
 
98
98
 
99
-
100
99
  each(guide.entity, (guideEntity: any) => {
101
100
  let opcount = 0
102
101
  const entityModel = model.main.api.entity[guideEntity.key$]
@@ -9,10 +9,10 @@ import { fixName } from '../transform'
9
9
  async function topTransform(ctx: TransformCtx, tspec: TransformSpec, model: any, def: any) {
10
10
  const { spec } = ctx
11
11
 
12
- fixName(model.main.api, spec.meta.name)
12
+ // fixName(model.main.api, spec.meta.name)
13
13
  model.main.def.desc = def.info.description
14
14
 
15
- return { ok: true, msg: spec.meta.name }
15
+ return { ok: true, msg: 'top' } // , msg: spec.meta.name }
16
16
  }
17
17
 
18
18
 
package/src/transform.ts CHANGED
@@ -17,7 +17,7 @@ import { manualTransform } from './transform/manual'
17
17
  type TransformCtx = {
18
18
  log: any,
19
19
  spec: any,
20
- guide: any,
20
+ model: any,
21
21
  opts: any,
22
22
  util: any,
23
23
  defpath: string,
@@ -30,12 +30,14 @@ type TransformSpec = {
30
30
  type TransformResult = {
31
31
  ok: boolean
32
32
  msg: string
33
+ err?: any
34
+ transform?: any
33
35
  }
34
36
 
35
37
  type Transform = (
36
38
  ctx: TransformCtx,
37
39
  tspec: TransformSpec,
38
- model: any,
40
+ apimodel: any,
39
41
  def: any,
40
42
  ) => Promise<TransformResult>
41
43
 
@@ -58,7 +60,9 @@ const TRANSFORM: Record<string, Transform> = {
58
60
 
59
61
 
60
62
  async function resolveTransforms(ctx: TransformCtx): Promise<TransformSpec> {
61
- const { log, guide: { guide } } = ctx
63
+ const { log, model: { main: { guide } } } = ctx
64
+
65
+ // console.dir(api, { depth: null })
62
66
 
63
67
  const tspec: TransformSpec = {
64
68
  transform: []
@@ -71,23 +75,28 @@ async function resolveTransforms(ctx: TransformCtx): Promise<TransformSpec> {
71
75
  .map((t: string) => t.trim())
72
76
  .filter((t: string) => '' != t)
73
77
 
74
- log.info({ point: 'transform', note: 'order', order: transformNames })
78
+ log.info({
79
+ point: 'transform', note: 'order: ' + transformNames.join(';'),
80
+ order: transformNames
81
+ })
75
82
 
76
83
  for (const tn of transformNames) {
77
- log.debug({ what: 'transform', transform: tn })
84
+ log.debug({ what: 'transform', transform: tn, note: tn })
78
85
  const transform = await resolveTransform(tn, ctx)
79
86
  tspec.transform.push(transform)
80
87
  }
81
88
 
89
+ // console.log('TSPEC', tspec)
82
90
  return tspec
83
91
  }
84
92
 
85
93
 
86
94
  async function resolveTransform(tn: string, ctx: TransformCtx) {
87
- const { log, defpath, guide: { guide } } = ctx
95
+ const { log, defpath, model: { guide } } = ctx
88
96
 
89
97
  let transform = TRANSFORM[tn]
90
98
  if (transform) {
99
+ // console.log('resolveTransform', tn, transform)
91
100
  return transform
92
101
  }
93
102
 
@@ -125,7 +134,7 @@ async function resolveTransform(tn: string, ctx: TransformCtx) {
125
134
  async function processTransforms(
126
135
  ctx: TransformCtx,
127
136
  spec: TransformSpec,
128
- model: any,
137
+ apimodel: any,
129
138
  def: any
130
139
  ): Promise<ProcessResult> {
131
140
  const pres: ProcessResult = {
@@ -138,17 +147,18 @@ async function processTransforms(
138
147
  const transform = spec.transform[tI]
139
148
 
140
149
  try {
141
- const tres = await transform(ctx, spec, model, def)
150
+ const tres = await transform(ctx, spec, apimodel, def)
142
151
  pres.ok = pres.ok && tres.ok
143
- pres.msg += tres.msg + '\n'
144
152
  pres.results.push(tres)
145
153
  }
146
154
  catch (err: any) {
147
155
  pres.ok = false
148
- pres.msg += err.message + '\n'
156
+ pres.msg += transform.name + ': ' + err.message + '\n'
149
157
  pres.results.push({
150
158
  ok: false,
151
- msg: err.message
159
+ msg: err.message,
160
+ err,
161
+ transform
152
162
  })
153
163
  }
154
164
  }