@voxgig/apidef 2.2.0 → 2.3.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.
package/src/transform.ts CHANGED
@@ -79,126 +79,6 @@ const GuideShape = Gubu({
79
79
  type Guide = ReturnType<typeof GuideShape>
80
80
 
81
81
 
82
- /*
83
- async function resolveTransforms(ctx: TransformCtx): Promise<TransformSpec> {
84
- const { log, model: { main: { api: { guide } } } } = ctx
85
-
86
- const tspec: TransformSpec = {
87
- transform: []
88
- }
89
-
90
- // TODO: parameterize
91
- const defkind = 'openapi'
92
- const transformNames = guide.control.transform[defkind].order
93
- .split(/\s*,\s* /)
94
- .map((t: string) => t.trim())
95
- .filter((t: string) => '' != t)
96
-
97
- log.info({
98
- point: 'transform', note: 'order: ' + transformNames.join(';'),
99
- order: transformNames
100
- })
101
-
102
- try {
103
- for (const tn of transformNames) {
104
- log.debug({ what: 'transform', transform: tn, note: tn })
105
- const transform = await resolveTransform(tn, ctx)
106
- tspec.transform.push(transform)
107
- }
108
- }
109
- catch (err: any) {
110
- throw err
111
- }
112
-
113
- return tspec
114
- }
115
-
116
-
117
- async function resolveTransform(tn: string, ctx: TransformCtx) {
118
- const { log, defpath, model: { main: { api: { guide } } } } = ctx
119
-
120
- let transform = TRANSFORM[tn]
121
- if (transform) {
122
- return transform
123
- }
124
-
125
- const tdef = guide.transform[tn]
126
- if (null == tdef) {
127
- const err = new Error('Unknown transform: ' + tn)
128
- log.error({ what: 'transform', transform: tn, fail: 'unknown', err })
129
- throw err
130
- }
131
-
132
- if (!tn.startsWith('custom')) {
133
- const err =
134
- new Error('Custom transform name must start with "custom": ' + tn)
135
- log.error({ what: 'transform', transform: tn, fail: 'prefix', err })
136
- throw err
137
- }
138
-
139
- const customtpath = Path.join(defpath, tdef.load)
140
- try {
141
- const transformModule = require(customtpath)
142
- transform = transformModule[tn]
143
- }
144
- catch (e: any) {
145
- const err = new Error('Custom transform not found: ' +
146
- customtpath + ': ' + e.message)
147
- log.error({ what: 'transform', transform: tn, fail: 'require', err })
148
- throw err
149
- }
150
-
151
- return transform
152
- }
153
-
154
-
155
- async function processTransforms(
156
- ctx: TransformCtx,
157
- // spec: TransformSpec,
158
- transforms: any[],
159
- apimodel: any,
160
- def: any
161
- ): Promise<ProcessResult> {
162
- const pres: ProcessResult = {
163
- ok: true,
164
- msg: '',
165
- results: []
166
- }
167
-
168
- const guide: Guide = GuideShape(ctx.model.main.api.guide)
169
-
170
-
171
- // for (let tI = 0; tI < spec.transform.length; tI++) {
172
- // const transform = spec.transform[tI]
173
-
174
- for (let tI = 0; tI < transforms.length; tI++) {
175
- const transform = transforms[tI]
176
-
177
- try {
178
- const tres = await transform(ctx, guide, apimodel, def)
179
- pres.ok = pres.ok && tres.ok
180
- pres.results.push(tres)
181
- }
182
- catch (err: any) {
183
- // TODO: fix: this error does not get printed
184
- console.error(err)
185
-
186
- pres.ok = false
187
- pres.msg += transform.name + ': ' + err.message + '\n'
188
- pres.results.push({
189
- ok: false,
190
- msg: err.message,
191
- err,
192
- transform
193
- })
194
- }
195
- }
196
-
197
- return pres
198
- }
199
- */
200
-
201
-
202
82
 
203
83
  function fixName(base: any, name: string, prop = 'name') {
204
84
  if (null != base && 'object' === typeof base && 'string' === typeof name) {
package/src/types.ts CHANGED
@@ -49,6 +49,8 @@ const BuildShape = Gubu({
49
49
  require: '',
50
50
  log: {},
51
51
  fs: Any(),
52
+ dryrun: false,
53
+ buildargs: {},
52
54
  watch: {
53
55
  mod: true,
54
56
  add: true,
package/src/utility.ts CHANGED
@@ -118,6 +118,12 @@ function depluralize(word: string): string {
118
118
  return word.slice(0, -2)
119
119
  }
120
120
 
121
+ // Handle words ending in -nses (like responses, expenses, licenses)
122
+ // These should only lose the final -s, not -es
123
+ if (word.endsWith('nses')) {
124
+ return word.slice(0, -1)
125
+ }
126
+
121
127
  // -ses, -xes, -zes, -shes, -ches -> remove -es (boxes -> box)
122
128
  if (word.endsWith('ses') || word.endsWith('xes') || word.endsWith('zes') ||
123
129
  word.endsWith('shes') || word.endsWith('ches')) {