@voxgig/apidef 1.2.0 → 1.4.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/dist/apidef.d.ts +5 -7
- package/dist/apidef.js +36 -108
- package/dist/apidef.js.map +1 -1
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +26 -0
- package/dist/parse.js.map +1 -0
- package/dist/transform/entity.d.ts +2 -5
- package/dist/transform/entity.js +15 -8
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.d.ts +2 -5
- package/dist/transform/field.js +11 -8
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/manual.d.ts +2 -5
- package/dist/transform/manual.js +4 -3
- package/dist/transform/manual.js.map +1 -1
- package/dist/transform/operation.d.ts +2 -5
- package/dist/transform/operation.js +83 -7
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform/top.d.ts +2 -5
- package/dist/transform/top.js +7 -6
- package/dist/transform/top.js.map +1 -1
- package/dist/transform.d.ts +67 -3
- package/dist/transform.js +30 -1
- package/dist/transform.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/model/apidef.jsonic +4 -1
- package/package.json +9 -9
- package/src/apidef.ts +48 -112
- package/src/parse.ts +36 -0
- package/src/transform/entity.ts +20 -9
- package/src/transform/field.ts +12 -8
- package/src/transform/manual.ts +9 -2
- package/src/transform/operation.ts +105 -8
- package/src/transform/top.ts +11 -5
- package/src/transform.ts +40 -1
- package/model/guide.jsonic +0 -41
package/dist/apidef.d.ts
CHANGED
|
@@ -6,23 +6,21 @@ type ApiDefOptions = {
|
|
|
6
6
|
debug?: boolean | string;
|
|
7
7
|
folder?: string;
|
|
8
8
|
meta?: Record<string, any>;
|
|
9
|
+
outprefix?: string;
|
|
9
10
|
};
|
|
10
11
|
declare function ApiDef(opts: ApiDefOptions): {
|
|
11
12
|
generate: (spec: any) => Promise<{
|
|
12
13
|
ok: boolean;
|
|
14
|
+
name: string;
|
|
13
15
|
processResult: {
|
|
14
16
|
ok: boolean;
|
|
15
17
|
msg: string;
|
|
16
|
-
results:
|
|
17
|
-
ok: boolean;
|
|
18
|
-
msg: string;
|
|
19
|
-
err?: any;
|
|
20
|
-
transform?: any;
|
|
21
|
-
}[];
|
|
18
|
+
results: import("./transform").TransformResult[];
|
|
22
19
|
};
|
|
23
20
|
apimodel?: undefined;
|
|
24
21
|
} | {
|
|
25
22
|
ok: boolean;
|
|
23
|
+
name: string;
|
|
26
24
|
apimodel: {
|
|
27
25
|
main: {
|
|
28
26
|
api: {
|
|
@@ -36,7 +34,7 @@ declare function ApiDef(opts: ApiDefOptions): {
|
|
|
36
34
|
};
|
|
37
35
|
declare namespace ApiDef {
|
|
38
36
|
var makeBuild: (opts: ApiDefOptions) => Promise<{
|
|
39
|
-
(model: any, build: any, ctx: any): Promise<
|
|
37
|
+
(model: any, build: any, ctx: any): Promise<any>;
|
|
40
38
|
step: string;
|
|
41
39
|
}>;
|
|
42
40
|
}
|
package/dist/apidef.js
CHANGED
|
@@ -42,16 +42,42 @@ const Fs = __importStar(require("node:fs"));
|
|
|
42
42
|
const node_path_1 = __importDefault(require("node:path"));
|
|
43
43
|
const node_util_1 = require("node:util");
|
|
44
44
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
45
|
+
const gubu_1 = require("gubu");
|
|
45
46
|
const util_1 = require("@voxgig/util");
|
|
46
47
|
const transform_1 = require("./transform");
|
|
48
|
+
const ModelShape = (0, gubu_1.Gubu)({
|
|
49
|
+
def: String,
|
|
50
|
+
main: {
|
|
51
|
+
guide: {},
|
|
52
|
+
sdk: {},
|
|
53
|
+
def: {},
|
|
54
|
+
api: {},
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const OpenModelShape = (0, gubu_1.Gubu)((0, gubu_1.Open)(ModelShape));
|
|
58
|
+
const BuildShape = (0, gubu_1.Gubu)({
|
|
59
|
+
spec: {
|
|
60
|
+
base: '',
|
|
61
|
+
path: '',
|
|
62
|
+
debug: '',
|
|
63
|
+
use: {},
|
|
64
|
+
res: [],
|
|
65
|
+
require: '',
|
|
66
|
+
log: {},
|
|
67
|
+
fs: (0, gubu_1.Any)()
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const OpenBuildShape = (0, gubu_1.Gubu)((0, gubu_1.Open)(BuildShape));
|
|
47
71
|
function ApiDef(opts) {
|
|
48
72
|
const fs = opts.fs || Fs;
|
|
49
73
|
const pino = (0, util_1.prettyPino)('apidef', opts);
|
|
50
74
|
const log = pino.child({ cmp: 'apidef' });
|
|
51
75
|
async function generate(spec) {
|
|
52
76
|
const start = Date.now();
|
|
53
|
-
const
|
|
54
|
-
|
|
77
|
+
const model = OpenModelShape(spec.model);
|
|
78
|
+
const build = OpenBuildShape(spec.build);
|
|
79
|
+
const buildspec = build.spec;
|
|
80
|
+
let defpath = model.def;
|
|
55
81
|
// TOOD: defpath should be independently defined
|
|
56
82
|
defpath = node_path_1.default.join(buildspec.base, '..', 'def', defpath);
|
|
57
83
|
log.info({
|
|
@@ -65,7 +91,7 @@ function ApiDef(opts) {
|
|
|
65
91
|
opts,
|
|
66
92
|
util: { fixName: transform_1.fixName },
|
|
67
93
|
defpath: node_path_1.default.dirname(defpath),
|
|
68
|
-
model
|
|
94
|
+
model,
|
|
69
95
|
};
|
|
70
96
|
const transformSpec = await (0, transform_1.resolveTransforms)(ctx);
|
|
71
97
|
log.debug({
|
|
@@ -109,7 +135,7 @@ function ApiDef(opts) {
|
|
|
109
135
|
result: processResult, note: processResult.msg,
|
|
110
136
|
err: processResult.results[0]?.err
|
|
111
137
|
});
|
|
112
|
-
return { ok: false, processResult };
|
|
138
|
+
return { ok: false, name: 'apidef', processResult };
|
|
113
139
|
}
|
|
114
140
|
const modelapi = { main: { api: apimodel.main.api } };
|
|
115
141
|
let modelSrc = JSON.stringify(modelapi, null, 2);
|
|
@@ -120,7 +146,7 @@ function ApiDef(opts) {
|
|
|
120
146
|
// console.log('modelPath', modelPath)
|
|
121
147
|
writeChanged('api-model', modelPath, modelSrc);
|
|
122
148
|
const modelBasePath = node_path_1.default.dirname(modelPath);
|
|
123
|
-
const defFilePath = node_path_1.default.join(modelBasePath, 'def-generated.jsonic');
|
|
149
|
+
const defFilePath = node_path_1.default.join(modelBasePath, (null == opts.outprefix ? '' : opts.outprefix) + 'def-generated.jsonic');
|
|
124
150
|
const modelDef = { main: { def: apimodel.main.def } };
|
|
125
151
|
let modelDefSrc = JSON.stringify(modelDef, null, 2);
|
|
126
152
|
modelDefSrc =
|
|
@@ -130,6 +156,7 @@ function ApiDef(opts) {
|
|
|
130
156
|
log.info({ point: 'generate-end', note: 'success', break: true });
|
|
131
157
|
return {
|
|
132
158
|
ok: true,
|
|
159
|
+
name: 'apidef',
|
|
133
160
|
apimodel,
|
|
134
161
|
};
|
|
135
162
|
}
|
|
@@ -167,127 +194,28 @@ function ApiDef(opts) {
|
|
|
167
194
|
throw err;
|
|
168
195
|
}
|
|
169
196
|
}
|
|
170
|
-
/*
|
|
171
|
-
async function resolveGuide(spec: any, _opts: any) {
|
|
172
|
-
if (null == spec.guide) {
|
|
173
|
-
spec.guide = spec.def + '-guide.jsonic'
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const path = Path.normalize(spec.guide)
|
|
177
|
-
let src: string
|
|
178
|
-
|
|
179
|
-
let action = ''
|
|
180
|
-
let exists = false
|
|
181
|
-
try {
|
|
182
|
-
|
|
183
|
-
action = 'exists'
|
|
184
|
-
let exists = fs.existsSync(path)
|
|
185
|
-
|
|
186
|
-
log.debug({ read: 'file', what: 'guide', file: path, exists })
|
|
187
|
-
|
|
188
|
-
if (exists) {
|
|
189
|
-
action = 'read'
|
|
190
|
-
src = fs.readFileSync(path, 'utf8')
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
src = `
|
|
194
|
-
# API Specification Transform Guide
|
|
195
|
-
|
|
196
|
-
@"@voxgig/apidef/model/guide.jsonic"
|
|
197
|
-
|
|
198
|
-
guide: entity: {
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
guide: control: transform: openapi: order: \`
|
|
203
|
-
top,
|
|
204
|
-
entity,
|
|
205
|
-
operation,
|
|
206
|
-
field,
|
|
207
|
-
manual,
|
|
208
|
-
\`
|
|
209
|
-
|
|
210
|
-
`
|
|
211
|
-
action = 'write'
|
|
212
|
-
fs.writeFileSync(path, src)
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (err: any) {
|
|
216
|
-
log.error({ fail: action, what: 'guide', file: path, exists, err })
|
|
217
|
-
throw err
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const aopts = { path }
|
|
221
|
-
const root = Aontu(src, aopts)
|
|
222
|
-
const hasErr = root.err && 0 < root.err.length
|
|
223
|
-
|
|
224
|
-
if (hasErr) {
|
|
225
|
-
for (let serr of root.err) {
|
|
226
|
-
let err: any = new Error('Guide model: ' + serr.msg)
|
|
227
|
-
err.cause$ = [serr]
|
|
228
|
-
|
|
229
|
-
if ('syntax' === serr.why) {
|
|
230
|
-
err.uxmsg$ = true
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
log.error({ fail: 'parse', point: 'guide-parse', file: path, err })
|
|
234
|
-
|
|
235
|
-
if (err.uxmsg$) {
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
err.rooterrs$ = root.err
|
|
240
|
-
throw err
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
let genctx = new Context({ root })
|
|
246
|
-
const guide = spec.guideModel = root.gen(genctx)
|
|
247
|
-
|
|
248
|
-
// TODO: collect all errors
|
|
249
|
-
if (genctx.err && 0 < genctx.err.length) {
|
|
250
|
-
const err: any = new Error('Guide build error:\n' +
|
|
251
|
-
(genctx.err.map((pe: any) => pe.msg)).join('\n'))
|
|
252
|
-
log.error({ fail: 'build', what: 'guide', file: path, err })
|
|
253
|
-
err.errs = () => genctx.err
|
|
254
|
-
throw err
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const pathParts = Path.parse(path)
|
|
258
|
-
spec.guideModelPath = Path.join(pathParts.dir, pathParts.name + '.json')
|
|
259
|
-
|
|
260
|
-
const updatedSrc = JSON.stringify(guide, null, 2)
|
|
261
|
-
|
|
262
|
-
writeChanged('guide-model', spec.guideModelPath, updatedSrc)
|
|
263
|
-
|
|
264
|
-
return guide
|
|
265
|
-
}
|
|
266
|
-
*/
|
|
267
197
|
return {
|
|
268
|
-
// watch,
|
|
269
198
|
generate,
|
|
270
199
|
};
|
|
271
200
|
}
|
|
272
201
|
ApiDef.makeBuild = async function (opts) {
|
|
273
202
|
let apidef = undefined;
|
|
203
|
+
const outprefix = null == opts.outprefix ? '' : opts.outprefix;
|
|
274
204
|
const config = {
|
|
275
205
|
def: opts.def || 'no-def',
|
|
276
206
|
kind: 'openapi3',
|
|
277
|
-
model: opts.folder ?
|
|
207
|
+
model: opts.folder ?
|
|
208
|
+
(opts.folder + '/' + outprefix + 'api-generated.jsonic') : 'no-model',
|
|
278
209
|
meta: opts.meta || {},
|
|
279
210
|
};
|
|
280
211
|
const build = async function (model, build, ctx) {
|
|
281
|
-
// console.log('APIDEF build')
|
|
282
|
-
// console.dir(ctx, { depth: null })
|
|
283
|
-
// console.dir(build, { depth: null })
|
|
284
212
|
if (null == apidef) {
|
|
285
213
|
apidef = ApiDef({
|
|
286
214
|
...opts,
|
|
287
215
|
pino: build.log,
|
|
288
216
|
});
|
|
289
217
|
}
|
|
290
|
-
await apidef.generate({ model, build, config });
|
|
218
|
+
return await apidef.generate({ model, build, config });
|
|
291
219
|
};
|
|
292
220
|
build.step = 'pre';
|
|
293
221
|
return build;
|
package/dist/apidef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|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K,CAAA;AACd,CAAC,CAAA"}
|
package/dist/parse.d.ts
ADDED
package/dist/parse.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2024 Voxgig, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parse = parse;
|
|
5
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
6
|
+
async function parse(kind, source) {
|
|
7
|
+
if ('OpenAPI' === kind) {
|
|
8
|
+
return parseOpenAPI(source);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
throw new Error('@voxgig/apidef-parse: unknown kind: ' + kind);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async function parseOpenAPI(source) {
|
|
15
|
+
const config = await (0, openapi_core_1.createConfig)({});
|
|
16
|
+
let bundle;
|
|
17
|
+
bundle = await (0, openapi_core_1.bundleFromString)({
|
|
18
|
+
source,
|
|
19
|
+
config,
|
|
20
|
+
dereference: true,
|
|
21
|
+
});
|
|
22
|
+
// console.dir(bundle.bundle, { depth: 1 })
|
|
23
|
+
const def = bundle.bundle.parsed;
|
|
24
|
+
return def;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";AAAA,4CAA4C;;AAkC1C,sBAAK;AAhCP,wDAAsE;AAGtE,KAAK,UAAU,KAAK,CAAC,IAAY,EAAE,MAAW;IAC5C,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO,YAAY,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;SACI,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,IAAI,CAAC,CAAA;IAChE,CAAC;AACH,CAAC;AAGD,KAAK,UAAU,YAAY,CAAC,MAAW;IACrC,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAY,EAAC,EAAE,CAAC,CAAA;IACrC,IAAI,MAAM,CAAA;IAEV,MAAM,GAAG,MAAM,IAAA,+BAAgB,EAAC;QAC9B,MAAM;QACN,MAAM;QACN,WAAW,EAAE,IAAI;KAClB,CAAC,CAAA;IAEF,2CAA2C;IAE3C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAA;IAEhC,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare
|
|
3
|
-
ok: boolean;
|
|
4
|
-
msg: string;
|
|
5
|
-
}>;
|
|
1
|
+
import type { Transform } from '../transform';
|
|
2
|
+
declare const entityTransform: Transform;
|
|
6
3
|
export { entityTransform };
|
package/dist/transform/entity.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.entityTransform =
|
|
3
|
+
exports.entityTransform = void 0;
|
|
4
4
|
const jostraca_1 = require("jostraca");
|
|
5
5
|
const transform_1 = require("../transform");
|
|
6
|
-
async function
|
|
7
|
-
const { model: { main: { guide } } } = ctx;
|
|
6
|
+
const entityTransform = async function (ctx, guide, tspec, model, def) {
|
|
8
7
|
let msg = '';
|
|
9
8
|
// console.log('DEF', def)
|
|
9
|
+
// console.log('GUIDE', guide)
|
|
10
10
|
(0, jostraca_1.each)(guide.entity, (guideEntity) => {
|
|
11
|
-
const
|
|
11
|
+
const entityName = guideEntity.key$;
|
|
12
|
+
ctx.log.debug({ point: 'guide-entity', note: entityName });
|
|
13
|
+
const entityModel = model.main.api.entity[entityName] = {
|
|
12
14
|
op: {},
|
|
13
15
|
field: {},
|
|
14
16
|
cmd: {},
|
|
@@ -19,12 +21,16 @@ async function entityTransform(ctx, tspec, model, def) {
|
|
|
19
21
|
};
|
|
20
22
|
(0, transform_1.fixName)(entityModel, guideEntity.key$);
|
|
21
23
|
(0, jostraca_1.each)(guideEntity.path, (guidePath) => {
|
|
22
|
-
const
|
|
24
|
+
const path = guidePath.key$;
|
|
25
|
+
const pathdef = def.paths[path];
|
|
26
|
+
// console.log('APIDEF FIND PATH', guidePath.key$, Object.keys(def.paths),
|
|
27
|
+
// Object.keys(def.paths).includes(guidePath.key$))
|
|
23
28
|
if (null == pathdef) {
|
|
24
|
-
throw new Error('
|
|
29
|
+
throw new Error('path not found in OpenAPI: ' + path +
|
|
25
30
|
' (entity: ' + guideEntity.name + ')');
|
|
26
31
|
}
|
|
27
|
-
|
|
32
|
+
// TODO: is this needed?
|
|
33
|
+
guidePath.parts$ = path.split('/');
|
|
28
34
|
guidePath.params$ = guidePath.parts$
|
|
29
35
|
.filter((p) => p.startsWith('{'))
|
|
30
36
|
.map((p) => p.substring(1, p.length - 1));
|
|
@@ -32,5 +38,6 @@ async function entityTransform(ctx, tspec, model, def) {
|
|
|
32
38
|
msg += guideEntity.name + ' ';
|
|
33
39
|
});
|
|
34
40
|
return { ok: true, msg };
|
|
35
|
-
}
|
|
41
|
+
};
|
|
42
|
+
exports.entityTransform = entityTransform;
|
|
36
43
|
//# sourceMappingURL=entity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/transform/entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/transform/entity.ts"],"names":[],"mappings":";;;AAEA,uCAA+B;AAI/B,4CAAsC;AAGtC,MAAM,eAAe,GAAc,KAAK,WACtC,GAAiB,EACjB,KAAY,EACZ,KAAoB,EACpB,KAAU,EACV,GAAQ;IAER,IAAI,GAAG,GAAG,EAAE,CAAA;IAEZ,0BAA0B;IAC1B,8BAA8B;IAE9B,IAAA,eAAI,EAAC,KAAK,CAAC,MAAM,EAAE,CAAC,WAAgB,EAAE,EAAE;QACtC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAA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AAG,GAAG,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;AAC1B,CAAC,CAAA;AAIC,0CAAe"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
declare
|
|
3
|
-
ok: boolean;
|
|
4
|
-
msg: string;
|
|
5
|
-
}>;
|
|
1
|
+
import type { Transform } from '../transform';
|
|
2
|
+
declare const fieldTransform: Transform;
|
|
6
3
|
export { fieldTransform };
|
package/dist/transform/field.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fieldTransform =
|
|
3
|
+
exports.fieldTransform = void 0;
|
|
4
4
|
const jostraca_1 = require("jostraca");
|
|
5
5
|
const transform_1 = require("../transform");
|
|
6
|
-
async function
|
|
7
|
-
const { model: { main: { guide } } } = ctx;
|
|
6
|
+
const fieldTransform = async function (ctx, guide, tspec, model, def) {
|
|
8
7
|
let msg = 'fields: ';
|
|
9
8
|
(0, jostraca_1.each)(guide.entity, (guideEntity) => {
|
|
10
|
-
const
|
|
9
|
+
const entityName = guideEntity.key$;
|
|
10
|
+
const entityModel = model.main.api.entity[entityName];
|
|
11
11
|
let fieldCount = 0;
|
|
12
12
|
(0, jostraca_1.each)(guideEntity.path, (guidePath) => {
|
|
13
|
-
const
|
|
13
|
+
const path = guidePath.key$;
|
|
14
|
+
const pathdef = def.paths[path];
|
|
14
15
|
(0, jostraca_1.each)(guidePath.op, (op) => {
|
|
15
|
-
|
|
16
|
+
const opname = op.key$;
|
|
17
|
+
if ('load' === opname) {
|
|
16
18
|
fieldCount = fieldbuild(entityModel, pathdef, op, guidePath, guideEntity, model);
|
|
17
19
|
}
|
|
18
20
|
});
|
|
@@ -20,7 +22,8 @@ async function fieldTransform(ctx, tspec, model, def) {
|
|
|
20
22
|
msg += guideEntity.name + '=' + fieldCount + ' ';
|
|
21
23
|
});
|
|
22
24
|
return { ok: true, msg };
|
|
23
|
-
}
|
|
25
|
+
};
|
|
26
|
+
exports.fieldTransform = fieldTransform;
|
|
24
27
|
function fieldbuild(entityModel, pathdef, op, path, entity, model) {
|
|
25
28
|
// console.log('FB-A', op, pathdef)
|
|
26
29
|
let fieldCount = 0;
|
|
@@ -85,7 +88,7 @@ guide: transform: customField: {
|
|
|
85
88
|
guide: entity: {
|
|
86
89
|
pet: path: {
|
|
87
90
|
'/pet/{petId}': {
|
|
88
|
-
op:{ load: 'get', create: 'post',
|
|
91
|
+
op:{ load: 'get', create: 'post', update: 'put' }
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
pet: test: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/transform/field.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/transform/field.ts"],"names":[],"mappings":";;;AAEA,uCAAqC;AAIrC,4CAAsC;AAItC,MAAM,cAAc,GAAc,KAAK,WACrC,GAAiB,EACjB,KAAY,EACZ,KAAoB,EACpB,KAAU,EACV,GAAQ;IAGR,IAAI,GAAG,GAAG,UAAU,CAAA;IAEpB,IAAA,eAAI,EAAC,KAAK,CAAC,MAAM,EAAE,CAAC,WAAgB,EAAE,EAAE;QACtC,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAA;QACnC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAErD,IAAI,UAAU,GAAG,CAAC,CAAA;QAClB,IAAA,eAAI,EAAC,WAAW,CAAC,IAAI,EAAE,CAAC,SAAc,EAAE,EAAE;YACxC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;YAC3B,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAE/B,IAAA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
|
|
1
|
-
import type { TransformCtx, TransformSpec } from '../transform';
|
|
2
|
-
declare
|
|
3
|
-
ok: boolean;
|
|
4
|
-
msg: string;
|
|
5
|
-
}>;
|
|
1
|
+
import type { TransformCtx, TransformSpec, TransformResult, Guide } from '../transform';
|
|
2
|
+
declare const manualTransform: (ctx: TransformCtx, guide: Guide, tspec: TransformSpec, model: any, def: any) => Promise<TransformResult>;
|
|
6
3
|
export { manualTransform };
|
package/dist/transform/manual.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.manualTransform =
|
|
3
|
+
exports.manualTransform = void 0;
|
|
4
4
|
const jsonic_next_1 = require("@jsonic/jsonic-next");
|
|
5
5
|
const { deep } = jsonic_next_1.Jsonic.util;
|
|
6
|
-
async function
|
|
6
|
+
const manualTransform = async function (ctx, guide, tspec, model, def) {
|
|
7
7
|
const { model: { main: { guide: { manual } } } } = ctx;
|
|
8
8
|
deep(model, manual);
|
|
9
9
|
return { ok: true, msg: 'manual' };
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
exports.manualTransform = manualTransform;
|
|
11
12
|
//# sourceMappingURL=manual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../../src/transform/manual.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../../src/transform/manual.ts"],"names":[],"mappings":";;;AACA,qDAA4C;AAO5C,MAAM,EAAE,IAAI,EAAE,GAAG,oBAAM,CAAC,IAAI,CAAA;AAE5B,MAAM,eAAe,GAAG,KAAK,WAC3B,GAAiB,EACjB,KAAY,EACZ,KAAoB,EACpB,KAAU,EACV,GAAQ;IAGR,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,GAAG,CAAA;IAEtD,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAEnB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAA;AACpC,CAAC,CAAA;AAIC,0CAAe"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type { TransformCtx, TransformSpec } from '../transform';
|
|
2
|
-
declare
|
|
3
|
-
ok: boolean;
|
|
4
|
-
msg: string;
|
|
5
|
-
}>;
|
|
1
|
+
import type { TransformCtx, TransformSpec, TransformResult, Guide } from '../transform';
|
|
2
|
+
declare const operationTransform: (ctx: TransformCtx, guide: Guide, tspec: TransformSpec, model: any, def: any) => Promise<TransformResult>;
|
|
6
3
|
export { operationTransform };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.operationTransform =
|
|
3
|
+
exports.operationTransform = void 0;
|
|
4
4
|
const jostraca_1 = require("jostraca");
|
|
5
5
|
const transform_1 = require("../transform");
|
|
6
|
-
async function
|
|
7
|
-
const { model: { main: { guide } } } = ctx;
|
|
6
|
+
const operationTransform = async function (ctx, guide, tspec, model, def) {
|
|
8
7
|
let msg = 'operations: ';
|
|
9
8
|
const paramBuilder = (paramMap, paramDef, entityModel, pathdef, op, path, entity, model) => {
|
|
10
9
|
paramMap[paramDef.name] = {
|
|
@@ -22,18 +21,94 @@ async function operationTransform(ctx, tspec, model, def) {
|
|
|
22
21
|
const type = queryDef.schema ? queryDef.schema.type : queryDef.type;
|
|
23
22
|
(0, transform_1.fixName)(queryMap[queryDef.name], type, 'type');
|
|
24
23
|
};
|
|
24
|
+
// Resolve the JSON path to the data (the "place").
|
|
25
|
+
const resolvePlace = (op, kind, pathdef) => {
|
|
26
|
+
const opname = op.key$;
|
|
27
|
+
// console.log('RP', kind, op)
|
|
28
|
+
let place = null == op.place ? '' : op.place;
|
|
29
|
+
if (null != place && '' !== place) {
|
|
30
|
+
return place;
|
|
31
|
+
}
|
|
32
|
+
const method = op.method;
|
|
33
|
+
const mdef = pathdef[method];
|
|
34
|
+
// TODO: fix getx
|
|
35
|
+
const content = 'res' === kind ?
|
|
36
|
+
((0, jostraca_1.getx)(mdef, 'responses.200.content') ||
|
|
37
|
+
(0, jostraca_1.getx)(mdef, 'responses.201.content')) :
|
|
38
|
+
(0, jostraca_1.getx)(mdef, 'requestBody.content');
|
|
39
|
+
// console.log('RP', kind, op, 'content', null == content)
|
|
40
|
+
if (null == content) {
|
|
41
|
+
return place;
|
|
42
|
+
}
|
|
43
|
+
const schema = content['application/json']?.schema;
|
|
44
|
+
// console.log('RP', kind, op, 'schema', null == schema)
|
|
45
|
+
if (null == schema) {
|
|
46
|
+
return place;
|
|
47
|
+
}
|
|
48
|
+
const propkeys = null == schema.properties ? [] : Object.keys(schema.properties);
|
|
49
|
+
// HEURISTIC: guess place
|
|
50
|
+
if ('list' === opname) {
|
|
51
|
+
if ('array' === schema.type) {
|
|
52
|
+
place = '';
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (1 === propkeys.length) {
|
|
56
|
+
place = propkeys[0];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// Use sub property that is an array
|
|
60
|
+
for (let pk of propkeys) {
|
|
61
|
+
if ('array' === schema.properties[pk]?.type) {
|
|
62
|
+
place = pk;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if ('object' === schema.type) {
|
|
71
|
+
if (schema.properties.id) {
|
|
72
|
+
place = ''; // top level
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (1 === propkeys.length) {
|
|
76
|
+
place = propkeys[0];
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Use sub property with an id
|
|
80
|
+
for (let pk of propkeys) {
|
|
81
|
+
if (schema.properties[pk].properties?.id) {
|
|
82
|
+
place = pk;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// console.log('PLACE', op, kind, schema.type, 'P=', place)
|
|
91
|
+
return place;
|
|
92
|
+
};
|
|
25
93
|
const opBuilder = {
|
|
26
94
|
any: (entityModel, pathdef, op, path, entity, model) => {
|
|
27
|
-
|
|
95
|
+
// console.log('OP', op, pathdef, path, entity)
|
|
96
|
+
const opname = op.key$;
|
|
97
|
+
const method = op.val$;
|
|
98
|
+
const kind = transform_1.OPKIND[opname];
|
|
99
|
+
// console.log('EM', entityModel.name)
|
|
100
|
+
const em = entityModel.op[opname] = {
|
|
28
101
|
path: path.key$,
|
|
29
102
|
method: op.val$,
|
|
103
|
+
kind,
|
|
30
104
|
param: {},
|
|
31
105
|
query: {},
|
|
106
|
+
place: resolvePlace(op, kind, pathdef)
|
|
32
107
|
};
|
|
33
108
|
(0, transform_1.fixName)(em, op.key$);
|
|
34
109
|
// Params are in the path
|
|
35
110
|
if (0 < path.params$.length) {
|
|
36
|
-
let params = (0, jostraca_1.getx)(pathdef[
|
|
111
|
+
let params = (0, jostraca_1.getx)(pathdef[method], 'parameters?in=path') || [];
|
|
37
112
|
if (Array.isArray(params)) {
|
|
38
113
|
params.reduce((a, p) => (paramBuilder(a, p, entityModel, pathdef, op, path, entity, model), a), em.param);
|
|
39
114
|
}
|
|
@@ -54,7 +129,7 @@ async function operationTransform(ctx, tspec, model, def) {
|
|
|
54
129
|
create: (entityModel, pathdef, op, path, entity, model) => {
|
|
55
130
|
return opBuilder.any(entityModel, pathdef, op, path, entity, model);
|
|
56
131
|
},
|
|
57
|
-
|
|
132
|
+
update: (entityModel, pathdef, op, path, entity, model) => {
|
|
58
133
|
return opBuilder.any(entityModel, pathdef, op, path, entity, model);
|
|
59
134
|
},
|
|
60
135
|
remove: (entityModel, pathdef, op, path, entity, model) => {
|
|
@@ -77,5 +152,6 @@ async function operationTransform(ctx, tspec, model, def) {
|
|
|
77
152
|
msg += guideEntity.name + '=' + opcount + ' ';
|
|
78
153
|
});
|
|
79
154
|
return { ok: true, msg };
|
|
80
|
-
}
|
|
155
|
+
};
|
|
156
|
+
exports.operationTransform = operationTransform;
|
|
81
157
|
//# sourceMappingURL=operation.js.map
|