@voxgig/apidef 2.4.1 → 3.0.2

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 (96) hide show
  1. package/dist/apidef.d.ts +5 -1
  2. package/dist/apidef.js +197 -112
  3. package/dist/apidef.js.map +1 -1
  4. package/dist/builder/entity/entity.d.ts +3 -0
  5. package/dist/builder/entity/{apiEntity.js → entity.js} +12 -9
  6. package/dist/builder/entity/entity.js.map +1 -0
  7. package/dist/builder/entity/info.d.ts +3 -0
  8. package/dist/builder/entity/info.js +22 -0
  9. package/dist/builder/entity/info.js.map +1 -0
  10. package/dist/builder/entity.js +7 -21
  11. package/dist/builder/entity.js.map +1 -1
  12. package/dist/builder/flow/flowHeuristic01.js +21 -11
  13. package/dist/builder/flow/flowHeuristic01.js.map +1 -1
  14. package/dist/builder/flow.d.ts +2 -1
  15. package/dist/builder/flow.js +29 -4
  16. package/dist/builder/flow.js.map +1 -1
  17. package/dist/def.d.ts +62 -0
  18. package/dist/def.js +4 -0
  19. package/dist/def.js.map +1 -0
  20. package/dist/desc.d.ts +89 -0
  21. package/dist/desc.js +4 -0
  22. package/dist/desc.js.map +1 -0
  23. package/dist/guide/guide.d.ts +2 -1
  24. package/dist/guide/guide.js +161 -30
  25. package/dist/guide/guide.js.map +1 -1
  26. package/dist/guide/heuristic01.d.ts +2 -1
  27. package/dist/guide/heuristic01.js +1120 -234
  28. package/dist/guide/heuristic01.js.map +1 -1
  29. package/dist/model.d.ts +55 -0
  30. package/dist/model.js +4 -0
  31. package/dist/model.js.map +1 -0
  32. package/dist/parse.d.ts +1 -2
  33. package/dist/parse.js +8 -47
  34. package/dist/parse.js.map +1 -1
  35. package/dist/transform/args.d.ts +3 -0
  36. package/dist/transform/args.js +58 -0
  37. package/dist/transform/args.js.map +1 -0
  38. package/dist/transform/clean.js +27 -3
  39. package/dist/transform/clean.js.map +1 -1
  40. package/dist/transform/entity.d.ts +11 -3
  41. package/dist/transform/entity.js +57 -41
  42. package/dist/transform/entity.js.map +1 -1
  43. package/dist/transform/field.d.ts +3 -3
  44. package/dist/transform/field.js +90 -65
  45. package/dist/transform/field.js.map +1 -1
  46. package/dist/transform/operation.d.ts +1 -1
  47. package/dist/transform/operation.js +94 -296
  48. package/dist/transform/operation.js.map +1 -1
  49. package/dist/transform/select.d.ts +3 -0
  50. package/dist/transform/select.js +44 -0
  51. package/dist/transform/select.js.map +1 -0
  52. package/dist/transform/top.d.ts +9 -0
  53. package/dist/transform/top.js +11 -2
  54. package/dist/transform/top.js.map +1 -1
  55. package/dist/transform.js +4 -0
  56. package/dist/transform.js.map +1 -1
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/dist/types.d.ts +112 -19
  59. package/dist/types.js +4 -2
  60. package/dist/types.js.map +1 -1
  61. package/dist/utility.d.ts +30 -2
  62. package/dist/utility.js +381 -6
  63. package/dist/utility.js.map +1 -1
  64. package/model/apidef.jsonic +75 -1
  65. package/model/guide.jsonic +14 -44
  66. package/package.json +17 -14
  67. package/src/apidef.ts +264 -121
  68. package/src/builder/entity/{apiEntity.ts → entity.ts} +18 -11
  69. package/src/builder/entity/info.ts +53 -0
  70. package/src/builder/entity.ts +9 -35
  71. package/src/builder/flow/flowHeuristic01.ts +46 -12
  72. package/src/builder/flow.ts +39 -5
  73. package/src/def.ts +91 -0
  74. package/src/desc.ts +143 -0
  75. package/src/guide/guide.ts +207 -134
  76. package/src/guide/heuristic01.ts +1651 -272
  77. package/src/model.ts +98 -0
  78. package/src/parse.ts +5 -61
  79. package/src/schematron.ts.off +317 -0
  80. package/src/transform/args.ts +102 -0
  81. package/src/transform/clean.ts +43 -8
  82. package/src/transform/entity.ts +100 -51
  83. package/src/transform/field.ts +150 -71
  84. package/src/transform/operation.ts +118 -414
  85. package/src/transform/select.ts +90 -0
  86. package/src/transform/top.ts +76 -3
  87. package/src/transform.ts +4 -0
  88. package/src/types.ts +185 -5
  89. package/src/utility.ts +481 -9
  90. package/dist/builder/entity/apiEntity.d.ts +0 -3
  91. package/dist/builder/entity/apiEntity.js.map +0 -1
  92. package/dist/builder/entity/def.d.ts +0 -3
  93. package/dist/builder/entity/def.js +0 -19
  94. package/dist/builder/entity/def.js.map +0 -1
  95. package/src/builder/entity/def.ts +0 -44
  96. package/src/guide.ts.off +0 -136
@@ -1,54 +1,28 @@
1
1
  /* Copyright (c) 2025 Voxgig, MIT License */
2
2
 
3
- import Path from 'node:path'
4
-
5
- // import { each } from 'jostraca'
6
-
7
-
8
- // import type {
9
- // ApiDefOptions,
10
- // Log,
11
- // FsUtil,
12
- // } from '../types'
13
-
14
-
15
- // import {
16
- // writeChanged
17
- // } from '../utility'
18
-
19
3
 
20
4
  import {
21
- resolveApiEntity
22
- } from './entity/apiEntity'
5
+ resolveEntity
6
+ } from './entity/entity'
23
7
 
24
8
  import {
25
- resolveDef
26
- } from './entity/def'
27
-
28
- // import {
29
- // resolveSdkEntity
30
- // } from './entity/sdkEntity'
31
-
9
+ resolveInfo
10
+ } from './entity/info'
32
11
 
33
12
 
34
13
  async function makeEntityBuilder(ctx: any) {
35
14
  const { apimodel, opts } = ctx
36
15
 
37
- const apiEntityBuilder = resolveApiEntity(apimodel, opts)
38
- const defBuilder = resolveDef(apimodel, opts)
39
- // const sdkEntityBuilder = resolveSdkEntity(apimodel, opts)
16
+ const entityBuilder = resolveEntity(apimodel, opts)
17
+ const infoBuilder = resolveInfo(apimodel, opts)
40
18
 
41
- return function entityBuilder() {
42
- apiEntityBuilder()
43
- defBuilder()
44
- // sdkEntityBuilder()
19
+ return function fullEntityBuilder() {
20
+ entityBuilder()
21
+ infoBuilder()
45
22
  }
46
23
  }
47
24
 
48
25
 
49
-
50
-
51
-
52
26
  export {
53
27
  makeEntityBuilder
54
28
  }
@@ -3,6 +3,27 @@ import { size } from '@voxgig/struct'
3
3
 
4
4
  import { each, names } from 'jostraca'
5
5
 
6
+ import { getelem } from '@voxgig/struct'
7
+
8
+
9
+ import type {
10
+ KitModel
11
+ } from '../../types'
12
+
13
+ import {
14
+ KIT
15
+ } from '../../types'
16
+
17
+ import type {
18
+ ModelEntity,
19
+ ModelOp,
20
+ ModelAlt,
21
+ } from '../../model'
22
+
23
+ import {
24
+ nom
25
+ } from '../../utility'
26
+
6
27
 
7
28
  async function flowHeuristic01(ctx: any): Promise<any[]> {
8
29
  let entity = ctx.guide.entity
@@ -21,10 +42,12 @@ async function flowHeuristic01(ctx: any): Promise<any[]> {
21
42
 
22
43
  function resolveBasicEntityFlow(ctx: any, entity: any) {
23
44
  const { apimodel, model } = ctx
24
- const apiEntity = apimodel.main.api.entity[entity.name]
45
+ const kit: KitModel = apimodel.main[KIT]
46
+
47
+ const apiEntity: ModelEntity = kit.entity[entity.name]
25
48
 
26
49
  const flow: any = {
27
- name: 'Basic' + apiEntity.Name + 'Flow'
50
+ name: 'Basic' + nom(apiEntity, 'Name') + 'Flow'
28
51
  }
29
52
 
30
53
  const refs = [
@@ -39,7 +62,7 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
39
62
  name: flow.name,
40
63
  active: true,
41
64
  param: {
42
- [`${model.NAME}_TEST_${apiEntity.NAME}_ENTID`]: idmap,
65
+ [`${model.NAME}_TEST_${nom(apiEntity, 'NAME')}_ENTID`]: idmap,
43
66
  [`${model.NAME}_TEST_LIVE`]: "FALSE",
44
67
  [`${model.NAME}_TEST_EXPLAIN`]: "FALSE",
45
68
  },
@@ -56,8 +79,8 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
56
79
  const id = idmap[ref]
57
80
  const ent: any = data[id] = {}
58
81
 
59
- let num = (i * size(apiEntity.field) * 10)
60
- each(apiEntity.field, (field) => {
82
+ let num = (i * size(apiEntity.fields) * 10)
83
+ each(apiEntity.fields, (field) => {
61
84
  ent[field.name] =
62
85
  'number' === field.type ? num :
63
86
  'boolean' === field.type ? 0 === num % 2 :
@@ -77,11 +100,15 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
77
100
  let name
78
101
 
79
102
  const am: any = {}
103
+ const entop = apiEntity.op ?? {}
104
+
105
+
106
+ if (entop.load) {
80
107
 
81
- if (apiEntity.op.load) {
108
+ const alt = findMainLoadAlt(entop.load)
82
109
 
83
110
  // Get additional required match properties
84
- each(apiEntity.op.load.param, (param: any) => {
111
+ each(alt?.args.param, (param: any) => {
85
112
  if (param.required) {
86
113
  let ancestorName = param.name
87
114
  let ancestorEntity = apimodel.main.api.entity[ancestorName]
@@ -98,7 +125,7 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
98
125
  am[param.name] =
99
126
  `\`dm$=p.${model.NAME}_TEST_${ancestorEntity.NAME}_ENTID.${ancestorEntity.name}01\``
100
127
 
101
- data[`${apiEntity.NAME}01`][param.name] = ancestorEntity.NAME + '01'
128
+ data[`${nom(apiEntity, 'NAME')}01`][param.name] = ancestorEntity.NAME + '01'
102
129
  }
103
130
  }
104
131
  })
@@ -111,7 +138,7 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
111
138
  entity: `${apiEntity.name}`,
112
139
  action: 'load',
113
140
  match: {
114
- id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01\``,
141
+ id: `\`dm$=p.${model.NAME}_TEST_${nom(apiEntity, 'NAME')}_ENTID.${apiEntity.name}01\``,
115
142
  ...am,
116
143
  },
117
144
  valid: {
@@ -122,7 +149,7 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
122
149
  })
123
150
  }
124
151
 
125
- if (apiEntity.op.update && apiEntity.op.load) {
152
+ if (entop.update && entop.load) {
126
153
  num++
127
154
  name = `update_${apiEntity.name}${num}`
128
155
  const id = idmap[`${apiEntity.name}01`]
@@ -151,7 +178,7 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
151
178
  entity: `${apiEntity.name}`,
152
179
  action: 'load',
153
180
  match: {
154
- id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01\``,
181
+ id: `\`dm$=p.${model.NAME}_TEST_${nom(apiEntity, 'NAME')}_ENTID.${apiEntity.name}01\``,
155
182
  ...am,
156
183
  },
157
184
  valid: {
@@ -169,11 +196,18 @@ function resolveBasicEntityFlow(ctx: any, entity: any) {
169
196
  }
170
197
 
171
198
 
199
+ function findMainLoadAlt(op: ModelOp): ModelAlt | undefined {
200
+ let cands = op.alts.filter(a => '{id}' === getelem(a.parts, -1))
201
+ return cands[0]
202
+ }
203
+
204
+
172
205
  function makeUpdateData(name: string, apiEntity: any, flow: any, id: string) {
173
206
  const ud: any = {}
174
207
  const data = flow.model.test.entity[apiEntity.name]
175
208
 
176
- const dataFields = each(apiEntity.field).filter(f => 'id' !== f.name && !f.name.includes('_id'))
209
+ const dataFields =
210
+ each(apiEntity.field).filter(f => 'id' !== f.name && !f.name.includes('_id'))
177
211
  const stringFields = each(dataFields).filter(f => 'string' === f.type)
178
212
 
179
213
  if (0 < size(stringFields)) {
@@ -1,8 +1,18 @@
1
1
 
2
+ // TODO: move this to sdkgen
3
+
4
+
2
5
  import Path from 'node:path'
3
6
 
4
7
  import { File, Content, Folder, each } from 'jostraca'
5
8
 
9
+
10
+ import {
11
+ ApiDefContext,
12
+ KIT,
13
+ } from '../types'
14
+
15
+
6
16
  import {
7
17
  formatJsonSrc,
8
18
  } from '../utility'
@@ -11,18 +21,40 @@ import {
11
21
  import { flowHeuristic01 } from './flow/flowHeuristic01'
12
22
 
13
23
 
14
- async function makeFlowBuilder(ctx: any) {
24
+ async function makeFlowBuilder(ctx: ApiDefContext): Promise<Function> {
15
25
  let flows: any[] = []
26
+ let flowBuilder = () => {
27
+ ctx.warn({
28
+ step: 'flow',
29
+ note: 'Unable to generate flow definitions as flows were not resolved.'
30
+ })
31
+ }
16
32
 
17
33
  if ('heuristic01' === ctx.opts.strategy) {
18
- flows = await flowHeuristic01(ctx)
34
+ try {
35
+ flows = await flowHeuristic01(ctx)
36
+ }
37
+ catch (err: any) {
38
+ err.foo = { x: 1, y: [2] }
39
+ err.foo.z = err.foo
40
+ ctx.warn({
41
+ step: 'flow',
42
+ note: 'Unable to resolve flows due to unexpected error: ' + err.message,
43
+ err,
44
+ })
45
+ return flowBuilder
46
+ }
19
47
  }
20
48
  else {
21
- throw new Error('Unknown guide strategy: ' + ctx.opts.strategy)
49
+ ctx.warn({
50
+ step: 'flow',
51
+ note: 'Unable to resolve flows: unknown guide strategy: ' + ctx.opts.strategy
52
+ })
53
+ return flowBuilder
22
54
  }
23
55
 
24
56
 
25
- return function flowBuilder() {
57
+ flowBuilder = () => {
26
58
 
27
59
  Folder({ name: 'flow' }, () => {
28
60
  const barrel = [
@@ -39,7 +71,7 @@ async function makeFlowBuilder(ctx: any) {
39
71
 
40
72
  let flowsrc = `# ${flow.Name}
41
73
 
42
- main: sdk: flow: ${flow.Name}:
74
+ main: ${KIT}: flow: ${flow.Name}:
43
75
  ` + flowModelSrc
44
76
 
45
77
  barrel.push(`@"${Path.basename(flowfile)}"`)
@@ -52,6 +84,8 @@ main: sdk: flow: ${flow.Name}:
52
84
  }, () => Content(barrel.join('\n')))
53
85
  })
54
86
  }
87
+
88
+ return flowBuilder
55
89
  }
56
90
 
57
91
 
package/src/def.ts ADDED
@@ -0,0 +1,91 @@
1
+ /* Copyright (c) 2024-2025 Voxgig, MIT License */
2
+
3
+ // Consolidated definitions for OpenAPI/Swagger API definition types
4
+
5
+
6
+ type PathDef = {
7
+ summary?: string
8
+ description?: string
9
+ get?: MethodDef
10
+ put?: MethodDef
11
+ post?: MethodDef
12
+ delete?: MethodDef
13
+ options?: MethodDef
14
+ head?: MethodDef
15
+ patch?: MethodDef
16
+ trace?: MethodDef
17
+ servers?: ServerDef[]
18
+ parameters?: ParameterDef[]
19
+ tags?: any
20
+ }
21
+
22
+
23
+ type MethodDef = {
24
+ tags?: string[]
25
+ summary?: string
26
+ description?: string
27
+ operationId?: string
28
+ parameters?: ParameterDef[]
29
+ // requestBody?: RequestBodyObject | ReferenceDef
30
+ // responses: Record<string, ResponseObject | ReferenceDef>
31
+ // callbacks?: Record<string, CallbackObject | ReferenceDef>
32
+ deprecated?: boolean
33
+ // security?: SecurityRequirementDef[]
34
+ servers?: ServerDef[]
35
+ }
36
+
37
+
38
+ type ServerDef = {
39
+ url: string
40
+ description?: string
41
+ variables?: Record<string, ServerVariableDef>
42
+ }
43
+
44
+
45
+ type ServerVariableDef = {
46
+ enum?: string[]
47
+ default: string
48
+ description?: string
49
+ }
50
+
51
+
52
+ type ParameterDef = {
53
+ name: string
54
+ in: "query" | "header" | "path" | "cookie"
55
+ description?: string
56
+ required?: boolean
57
+ deprecated?: boolean
58
+ schema?: SchemaDef
59
+ nullable?: boolean
60
+ example?: any
61
+ // examples?: Record<string, ExampleObject | ReferenceDef>
62
+ }
63
+
64
+
65
+ type SchemaDef = {
66
+ title?: string
67
+ description?: string
68
+ type?: string
69
+ format?: string
70
+ enum?: any[]
71
+ items?: SchemaDef
72
+ properties?: Record<string, SchemaDef>
73
+ required?: string[]
74
+ additionalProperties?: boolean | SchemaDef
75
+ allOf?: SchemaDef[]
76
+ oneOf?: SchemaDef[]
77
+ anyOf?: SchemaDef[]
78
+ nullable?: boolean
79
+ default?: any
80
+ example?: any
81
+ }
82
+
83
+
84
+ export type {
85
+ PathDef,
86
+ MethodDef,
87
+ ServerDef,
88
+ ServerVariableDef,
89
+ ParameterDef,
90
+ SchemaDef,
91
+ }
package/src/desc.ts ADDED
@@ -0,0 +1,143 @@
1
+ /* Copyright (c) 2024-2025 Voxgig, MIT License */
2
+
3
+ // Consolidated intermediate analysis types for OpenAPI definition processing
4
+
5
+ import type { PathMatch } from './utility'
6
+ import type { MethodName } from './types'
7
+ import type { ParameterDef } from './def'
8
+
9
+
10
+ // Intermediate Guide types used during analysis
11
+ type GuidePathRename = {
12
+ param?: Record<string, string>
13
+ }
14
+
15
+ type GuideOp = {
16
+ method: MethodName
17
+ }
18
+
19
+ type GuidePath = {
20
+ rename?: GuidePathRename
21
+ op?: Record<string, GuideOp>
22
+ }
23
+
24
+
25
+ // Component analysis description
26
+ type CmpDesc = {
27
+ namedesc?: any,
28
+ path_rate: number,
29
+ method_rate: number,
30
+ }
31
+
32
+
33
+ // Basic method description from types.ts (renamed to avoid conflict)
34
+ type BasicMethodDesc = {
35
+ name: MethodName,
36
+ def: Record<string, any>,
37
+ path: string,
38
+ }
39
+
40
+
41
+ // Detailed method analysis description from heuristic01.ts
42
+ type MethodDesc = {
43
+ path: string
44
+ method: string
45
+ summary: string
46
+ tags: string[]
47
+ parameters: any[]
48
+ responses: Record<string, any>
49
+ requestBody: Record<string, any>
50
+ MethodEntity: MethodEntityDesc
51
+ }
52
+
53
+
54
+ // Method entity relationship analysis
55
+ type MethodEntityDesc = {
56
+ ref: string
57
+
58
+ cmp: string | null
59
+ origcmp: string | null
60
+ origcmpref: string | null
61
+
62
+ why_cmp: string[]
63
+ cmpoccur: number
64
+ path_rate: number
65
+ method_rate: number
66
+ entname: string
67
+ why_op: string[]
68
+ rename: Record<string, any>
69
+ why_rename: Record<string, any>
70
+ rename_orig: string[]
71
+ opname: string
72
+ why_opname: string[]
73
+
74
+ pm?: any
75
+ }
76
+
77
+
78
+ // Entity analysis description
79
+ type EntityDesc = {
80
+ name: string
81
+ origname: string
82
+ plural: string
83
+ path: Record<string, EntityPathDesc>
84
+ alias: Record<string, string>,
85
+ cmp: CmpDesc
86
+ }
87
+
88
+
89
+ // Entity path relationship analysis
90
+ type EntityPathDesc = {
91
+ op: Record<string, any>
92
+ pm: PathMatch
93
+
94
+ rename: {
95
+ param: Record<string, string>
96
+ }
97
+ why_rename: {
98
+ why_param: Record<string, string[]>
99
+ }
100
+
101
+ action: Record<string, {
102
+ why_action: string[]
103
+ }>
104
+
105
+ why_action: Record<string, string[]>
106
+
107
+ why_ent: string[]
108
+ why_path: string[]
109
+ }
110
+
111
+
112
+ // Path analysis description
113
+ type PathDesc = {
114
+ orig: string
115
+ method: MethodName
116
+ parts: string[]
117
+ rename: GuidePathRename
118
+ op: GuidePath["op"]
119
+ def: {
120
+ parameters?: ParameterDef[]
121
+ }
122
+ }
123
+
124
+
125
+ // Operation analysis description
126
+ type OpDesc = {
127
+ paths: PathDesc[]
128
+ }
129
+
130
+
131
+ export type {
132
+ GuidePathRename,
133
+ GuideOp,
134
+ GuidePath,
135
+ CmpDesc,
136
+ BasicMethodDesc,
137
+ MethodDesc,
138
+ MethodEntityDesc,
139
+ EntityDesc,
140
+ EntityPathDesc,
141
+ PathDesc,
142
+ OpDesc,
143
+ }