@voxgig/apidef 2.0.0 → 2.1.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.js +14 -20
- package/dist/apidef.js.map +1 -1
- package/dist/builder/flow/flowHeuristic01.js +37 -9
- package/dist/builder/flow/flowHeuristic01.js.map +1 -1
- package/dist/builder/flow.js +3 -3
- package/dist/builder/flow.js.map +1 -1
- package/dist/guide/heuristic01.js +197 -117
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/guide.js +37 -11
- package/dist/guide.js.map +1 -1
- package/dist/parse.d.ts +2 -1
- package/dist/parse.js +81 -3
- package/dist/parse.js.map +1 -1
- package/dist/transform/clean.d.ts +3 -0
- package/dist/transform/clean.js +16 -0
- package/dist/transform/clean.js.map +1 -0
- package/dist/transform/entity.js +21 -2
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.js +24 -1
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/operation.js +131 -47
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform.d.ts +1 -8
- package/dist/transform.js +121 -95
- package/dist/transform.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.js +3 -2
- package/dist/types.js.map +1 -1
- package/dist/utility.d.ts +7 -1
- package/dist/utility.js +85 -32
- package/dist/utility.js.map +1 -1
- package/model/apidef.jsonic +1 -0
- package/package.json +8 -9
- package/src/apidef.ts +23 -33
- package/src/builder/flow/flowHeuristic01.ts +44 -9
- package/src/builder/flow.ts +4 -3
- package/src/guide/heuristic01.ts +281 -124
- package/src/guide.ts +49 -14
- package/src/parse.ts +106 -4
- package/src/transform/clean.ts +28 -0
- package/src/transform/entity.ts +26 -3
- package/src/transform/field.ts +27 -1
- package/src/transform/operation.ts +203 -64
- package/src/transform.ts +29 -23
- package/src/types.ts +3 -2
- package/src/utility.ts +113 -1
- package/src/builder/flow/flowHeuristic01.ts~ +0 -45
package/dist/apidef.js
CHANGED
|
@@ -54,8 +54,11 @@ const top_1 = require("./transform/top");
|
|
|
54
54
|
const entity_1 = require("./transform/entity");
|
|
55
55
|
const operation_1 = require("./transform/operation");
|
|
56
56
|
const field_1 = require("./transform/field");
|
|
57
|
+
const clean_1 = require("./transform/clean");
|
|
57
58
|
const entity_2 = require("./builder/entity");
|
|
58
59
|
const flow_1 = require("./builder/flow");
|
|
60
|
+
// Log non-fatal wierdness.
|
|
61
|
+
const dlog = (0, utility_1.getdlog)('apidef', __filename);
|
|
59
62
|
function ApiDef(opts) {
|
|
60
63
|
// TODO: gubu opts!
|
|
61
64
|
const fs = opts.fs || Fs;
|
|
@@ -64,8 +67,7 @@ function ApiDef(opts) {
|
|
|
64
67
|
opts.strategy = opts.strategy || 'heuristic01';
|
|
65
68
|
async function generate(spec) {
|
|
66
69
|
const start = Date.now();
|
|
67
|
-
//
|
|
68
|
-
// console.dir(spec, { depth: null })
|
|
70
|
+
// dlog('start')
|
|
69
71
|
const model = (0, types_1.OpenModelShape)(spec.model);
|
|
70
72
|
const build = (0, types_1.OpenBuildShape)(spec.build);
|
|
71
73
|
(0, jostraca_1.names)(model, model.name);
|
|
@@ -98,7 +100,9 @@ function ApiDef(opts) {
|
|
|
98
100
|
def: undefined
|
|
99
101
|
};
|
|
100
102
|
const defsrc = (0, utility_1.loadFile)(defpath, 'def', fs, log);
|
|
101
|
-
|
|
103
|
+
let def = await (0, parse_1.parse)('OpenAPI', defsrc, { file: defpath });
|
|
104
|
+
def = (0, parse_1.rewrite)(def);
|
|
105
|
+
fs.writeFileSync(defpath + '.full.json', JSON.stringify(def, null, 2));
|
|
102
106
|
ctx.def = def;
|
|
103
107
|
const guideBuilder = await (0, guide_1.resolveGuide)(ctx);
|
|
104
108
|
// const transformSpec = await resolveTransforms(ctx)
|
|
@@ -107,27 +111,12 @@ function ApiDef(opts) {
|
|
|
107
111
|
entity: entity_1.entityTransform,
|
|
108
112
|
operation: operation_1.operationTransform,
|
|
109
113
|
field: field_1.fieldTransform,
|
|
114
|
+
clean: clean_1.cleanTransform,
|
|
110
115
|
});
|
|
111
|
-
// log.debug({
|
|
112
|
-
// point: 'transform', spec: transformSpec,
|
|
113
|
-
// note: log.levelVal <= 20 ? inspect(transformSpec) : ''
|
|
114
|
-
// })
|
|
115
|
-
// const processResult = await processTransforms(ctx, transforms, apimodel, def)
|
|
116
|
-
// if (!processResult.ok) {
|
|
117
|
-
// log.error({
|
|
118
|
-
// fail: 'process', point: 'transform-result',
|
|
119
|
-
// result: processResult, note: processResult.msg,
|
|
120
|
-
// err: processResult.results[0]?.err
|
|
121
|
-
// })
|
|
122
|
-
// return { ok: false, name: 'apidef', processResult }
|
|
123
|
-
// }
|
|
124
116
|
const builders = await (0, resolver_1.resolveElements)(ctx, 'builder', 'standard', {
|
|
125
117
|
entity: entity_2.makeEntityBuilder,
|
|
126
118
|
flow: flow_1.makeFlowBuilder,
|
|
127
119
|
});
|
|
128
|
-
// const entityBuilder = resolveEntity(apimodel, spec, opts)
|
|
129
|
-
// const entityBuilder = await resolveEntity(ctx)
|
|
130
|
-
// const flowBuilder = await resolveFlows(ctx)
|
|
131
120
|
const jostraca = (0, jostraca_1.Jostraca)({
|
|
132
121
|
now: spec.now,
|
|
133
122
|
fs: () => fs,
|
|
@@ -148,7 +137,12 @@ function ApiDef(opts) {
|
|
|
148
137
|
model: jmodel,
|
|
149
138
|
existing: { txt: { merge: true } }
|
|
150
139
|
}, root);
|
|
151
|
-
|
|
140
|
+
const dlogs = dlog.log();
|
|
141
|
+
if (0 < dlogs.length) {
|
|
142
|
+
for (let dlogentry of dlogs) {
|
|
143
|
+
log.debug({ point: 'generate-warning', dlogentry, note: String(dlogentry) });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
152
146
|
log.info({ point: 'generate-end', note: 'success', break: true });
|
|
153
147
|
return {
|
|
154
148
|
ok: true,
|
package/dist/apidef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apid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,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -15,7 +15,7 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
15
15
|
const { apimodel, model } = ctx;
|
|
16
16
|
const apiEntity = apimodel.main.api.entity[entity.name];
|
|
17
17
|
const flow = {
|
|
18
|
-
name: 'Basic' + apiEntity.Name
|
|
18
|
+
name: 'Basic' + apiEntity.Name + 'Flow'
|
|
19
19
|
};
|
|
20
20
|
const refs = [
|
|
21
21
|
`${apiEntity.name}01`,
|
|
@@ -24,15 +24,18 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
24
24
|
];
|
|
25
25
|
const idmap = refs.reduce((a, ref) => (a[ref] = ref.toUpperCase(), a), {});
|
|
26
26
|
flow.model = {
|
|
27
|
-
name: flow.
|
|
27
|
+
name: flow.name,
|
|
28
|
+
active: true,
|
|
28
29
|
param: {
|
|
29
|
-
[`${model.NAME}_TEST_${apiEntity.NAME}_ENTID`]: idmap
|
|
30
|
+
[`${model.NAME}_TEST_${apiEntity.NAME}_ENTID`]: idmap,
|
|
31
|
+
[`${model.NAME}_TEST_LIVE`]: "FALSE",
|
|
32
|
+
[`${model.NAME}_TEST_EXPLAIN`]: "FALSE",
|
|
30
33
|
},
|
|
31
|
-
test: { entity: { [apiEntity.
|
|
34
|
+
test: { entity: { [apiEntity.name]: {} } },
|
|
32
35
|
step: []
|
|
33
36
|
};
|
|
34
37
|
(0, jostraca_1.names)(flow, flow.name);
|
|
35
|
-
const data = flow.model.test.entity[apiEntity.
|
|
38
|
+
const data = flow.model.test.entity[apiEntity.name];
|
|
36
39
|
refs.map((ref, i) => {
|
|
37
40
|
const id = idmap[ref];
|
|
38
41
|
const ent = data[id] = {};
|
|
@@ -51,7 +54,27 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
51
54
|
const steps = flow.model.step;
|
|
52
55
|
let num = 0;
|
|
53
56
|
let name;
|
|
57
|
+
const am = {};
|
|
54
58
|
if (apiEntity.op.load) {
|
|
59
|
+
// Get additional required match properties
|
|
60
|
+
(0, jostraca_1.each)(apiEntity.op.load.param, (param) => {
|
|
61
|
+
if (param.required) {
|
|
62
|
+
let ancestorName = param.name;
|
|
63
|
+
let ancestorEntity = apimodel.main.api.entity[ancestorName];
|
|
64
|
+
if (null == ancestorEntity) {
|
|
65
|
+
ancestorName = ancestorName.replace('_id', '');
|
|
66
|
+
ancestorEntity = apimodel.main.api.entity[ancestorName];
|
|
67
|
+
}
|
|
68
|
+
if (ancestorEntity && ancestorName !== apiEntity.name) {
|
|
69
|
+
flow.model.param[`${model.NAME}_TEST_${ancestorEntity.NAME}_ENTID`] = {
|
|
70
|
+
[ancestorEntity.name + '01']: ancestorEntity.NAME + '01'
|
|
71
|
+
};
|
|
72
|
+
am[param.name] =
|
|
73
|
+
`\`dm$=p.${model.NAME}_TEST_${ancestorEntity.NAME}_ENTID.${ancestorEntity.name}01\``;
|
|
74
|
+
data[`${apiEntity.NAME}01`][param.name] = ancestorEntity.NAME + '01';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
55
78
|
name = `load_${apiEntity.name}${num}`;
|
|
56
79
|
steps.push({
|
|
57
80
|
name,
|
|
@@ -59,11 +82,13 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
59
82
|
entity: `${apiEntity.name}`,
|
|
60
83
|
action: 'load',
|
|
61
84
|
match: {
|
|
62
|
-
id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01
|
|
85
|
+
id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01\``,
|
|
86
|
+
...am,
|
|
63
87
|
},
|
|
64
88
|
valid: {
|
|
65
89
|
'`$OPEN`': true,
|
|
66
|
-
id: `\`dm$=s.${name}.match.id
|
|
90
|
+
id: `\`dm$=s.${name}.match.id\``,
|
|
91
|
+
...am,
|
|
67
92
|
}
|
|
68
93
|
});
|
|
69
94
|
}
|
|
@@ -82,6 +107,7 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
82
107
|
valid: {
|
|
83
108
|
'`$OPEN`': true,
|
|
84
109
|
id: `\`dm$=s.${loadref}.match.id\``,
|
|
110
|
+
...am,
|
|
85
111
|
...valid
|
|
86
112
|
}
|
|
87
113
|
});
|
|
@@ -93,11 +119,13 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
93
119
|
entity: `${apiEntity.name}`,
|
|
94
120
|
action: 'load',
|
|
95
121
|
match: {
|
|
96
|
-
id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01
|
|
122
|
+
id: `\`dm$=p.${model.NAME}_TEST_${apiEntity.NAME}_ENTID.${apiEntity.name}01\``,
|
|
123
|
+
...am,
|
|
97
124
|
},
|
|
98
125
|
valid: {
|
|
99
126
|
'`$OPEN`': true,
|
|
100
127
|
id: `\`dm$=s.${loadref}.match.id\``,
|
|
128
|
+
...am,
|
|
101
129
|
...valid
|
|
102
130
|
}
|
|
103
131
|
});
|
|
@@ -106,7 +134,7 @@ function resolveBasicEntityFlow(ctx, entity) {
|
|
|
106
134
|
}
|
|
107
135
|
function makeUpdateData(name, apiEntity, flow, id) {
|
|
108
136
|
const ud = {};
|
|
109
|
-
const data = flow.model.test.entity[apiEntity.
|
|
137
|
+
const data = flow.model.test.entity[apiEntity.name];
|
|
110
138
|
const dataFields = (0, jostraca_1.each)(apiEntity.field).filter(f => 'id' !== f.name && !f.name.includes('_id'));
|
|
111
139
|
const stringFields = (0, jostraca_1.each)(dataFields).filter(f => 'string' === f.type);
|
|
112
140
|
if (0 < (0, struct_1.size)(stringFields)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowHeuristic01.js","sourceRoot":"","sources":["../../../src/builder/flow/flowHeuristic01.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"flowHeuristic01.js","sourceRoot":"","sources":["../../../src/builder/flow/flowHeuristic01.ts"],"names":[],"mappings":";;AAsME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AA,eAAI,EAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,KAAK,CAAC,CAAC,IAAI,CAAC,CAAA;IAEtE,IAAI,CAAC,GAAG,IAAA,aAAI,EAAC,YAAY,CAAC,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;QACzB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAA;IAC5C,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC;AAGD,SAAS,eAAe,CAAC,IAAY,EAAE,SAAc,EAAE,IAAS,EAAE,EAAU,EAAE,OAAY;IACxF,MAAM,EAAE,GAAQ,EAAE,CAAA;IAElB,IAAA,eAAI,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QAClB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,IAAI,YAAY,CAAC,CAAC,IAAI,IAAI,CAAA;IACpD,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,CAAA;AACX,CAAC"}
|
package/dist/builder/flow.js
CHANGED
|
@@ -23,11 +23,11 @@ async function makeFlowBuilder(ctx) {
|
|
|
23
23
|
];
|
|
24
24
|
(0, jostraca_1.each)(flows, (flow) => {
|
|
25
25
|
let flowfile = node_path_1.default.join(ctx.opts.folder, 'flow', (null == ctx.opts.outprefix ? '' : ctx.opts.outprefix) +
|
|
26
|
-
flow.Name + '
|
|
26
|
+
flow.Name + '.jsonic');
|
|
27
27
|
let flowModelSrc = (0, utility_1.formatJsonSrc)(JSON.stringify(flow.model, null, 2));
|
|
28
|
-
let flowsrc = `# ${flow.Name}
|
|
28
|
+
let flowsrc = `# ${flow.Name}
|
|
29
29
|
|
|
30
|
-
main: sdk: flow: ${flow.Name}
|
|
30
|
+
main: sdk: flow: ${flow.Name}:
|
|
31
31
|
` + flowModelSrc;
|
|
32
32
|
barrel.push(`@"${node_path_1.default.basename(flowfile)}"`);
|
|
33
33
|
(0, jostraca_1.File)({ name: node_path_1.default.basename(flowfile) }, () => (0, jostraca_1.Content)(flowsrc));
|
package/dist/builder/flow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/builder/flow.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../../src/builder/flow.ts"],"names":[],"mappings":";;;;;AA2DE,0CAAe;AA1DjB,0DAA4B;AAE5B,uCAAsD;AAEtD,wCAEmB;AAGnB,4DAAwD;AAGxD,KAAK,UAAU,eAAe,CAAC,GAAQ;IACrC,IAAI,KAAK,GAAU,EAAE,CAAA;IAErB,IAAI,aAAa,KAAK,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxC,KAAK,GAAG,MAAM,IAAA,iCAAe,EAAC,GAAG,CAAC,CAAA;IACpC,CAAC;SACI,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjE,CAAC;IAGD,OAAO,SAAS,WAAW;QAEzB,IAAA,iBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE;YAC5B,MAAM,MAAM,GAAG;gBACb,WAAW;aACZ,CAAA;YAED,IAAA,eAAI,EAAC,KAAK,EAAE,CAAC,IAAS,EAAE,EAAE;gBACxB,IAAI,QAAQ,GACV,mBAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAC/B,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;oBACtD,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAA;gBAE1B,IAAI,YAAY,GAAG,IAAA,uBAAa,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;gBAErE,IAAI,OAAO,GAAG,KAAK,IAAI,CAAC,IAAI;;mBAEjB,IAAI,CAAC,IAAI;CAC3B,GAAG,YAAY,CAAA;gBAER,MAAM,CAAC,IAAI,CAAC,KAAK,mBAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;gBAE5C,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,mBAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAA,kBAAO,EAAC,OAAO,CAAC,CAAC,CAAA;YACjE,CAAC,CAAC,CAAA;YAEF,IAAA,eAAI,EAAC;gBACH,IAAI,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,mBAAmB;aACnF,EAAE,GAAG,EAAE,CAAC,IAAA,kBAAO,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACtC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.heuristic01 = heuristic01;
|
|
4
4
|
const jostraca_1 = require("jostraca");
|
|
5
|
+
const struct_1 = require("@voxgig/struct");
|
|
6
|
+
const utility_1 = require("../utility");
|
|
7
|
+
// Log non-fatal wierdness.
|
|
8
|
+
const dlog = (0, utility_1.getdlog)('apidef', __filename);
|
|
5
9
|
async function heuristic01(ctx) {
|
|
6
10
|
let guide = ctx.model.main.api.guide;
|
|
7
11
|
const entityDescs = resolveEntityDescs(ctx);
|
|
@@ -11,6 +15,8 @@ async function heuristic01(ctx) {
|
|
|
11
15
|
control: guide.control,
|
|
12
16
|
entity: entityDescs,
|
|
13
17
|
};
|
|
18
|
+
// console.log('GUIDE')
|
|
19
|
+
// console.dir(guide, { depth: null })
|
|
14
20
|
return guide;
|
|
15
21
|
}
|
|
16
22
|
const METHOD_IDOP = {
|
|
@@ -23,156 +29,230 @@ const METHOD_IDOP = {
|
|
|
23
29
|
function resolveEntityDescs(ctx) {
|
|
24
30
|
const entityDescs = {};
|
|
25
31
|
const paths = ctx.def.paths;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
// Analyze paths ending in .../foo/{foo}
|
|
33
|
+
(0, jostraca_1.each)(paths, (pathDef, pathStr) => {
|
|
34
|
+
// Look for rightmmost /entname/{entid}.
|
|
35
|
+
let m = pathStr.match(/\/([a-zA-Z0-1_-]+)(\/\{([a-zA-Z0-1_-]+)\})?$/);
|
|
36
|
+
// const m = pathStr.match(/\/([a-zA-Z0-1_-]+)\/\{([a-zA-Z0-1_-]+)\}$/)
|
|
29
37
|
if (m) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
entdesc
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
// const entdesc = resolveEntity(entityDescs, pathStr, m[1], m[2])
|
|
39
|
+
(0, jostraca_1.each)(pathDef, (methodDef, methodStr) => {
|
|
40
|
+
methodStr = methodStr.toLowerCase();
|
|
41
|
+
if (!METHOD_IDOP[methodStr]) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const entdesc = resolveEntity(entityDescs, pathDef, pathStr, methodDef, methodStr);
|
|
45
|
+
if (null == entdesc) {
|
|
46
|
+
console.log('WARNING: unable to resolve entity for method ' + methodStr +
|
|
47
|
+
' path ' + pathStr);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// if (pathStr.includes('courses')) {
|
|
51
|
+
// console.log('ENTRES', pathStr, methodStr)
|
|
52
|
+
// console.dir(ent2, { depth: null })
|
|
53
|
+
// }
|
|
54
|
+
let opname = resolveOpName(methodStr, methodDef, pathStr, entdesc);
|
|
55
|
+
if (null == opname) {
|
|
56
|
+
console.log('WARNING: unable to resolve operation for method ' + methodStr +
|
|
57
|
+
' path ' + pathStr);
|
|
46
58
|
return;
|
|
59
|
+
}
|
|
47
60
|
const transform = {
|
|
48
61
|
// reqform: '`reqdata`',
|
|
49
62
|
// resform: '`body`',
|
|
50
63
|
};
|
|
51
|
-
const resokdef =
|
|
64
|
+
const resokdef = methodDef.responses[200] || methodDef.responses[201];
|
|
52
65
|
const resbody = resokdef?.content?.['application/json']?.schema;
|
|
53
66
|
if (resbody) {
|
|
54
|
-
if (resbody[
|
|
55
|
-
|
|
56
|
-
// transform.resform = '`body."'+origentname+'"`'
|
|
57
|
-
transform.resform = '`body.' + origentname + '`';
|
|
67
|
+
if (resbody[entdesc.origname]) {
|
|
68
|
+
transform.resform = '`body.' + entdesc.origname + '`';
|
|
58
69
|
}
|
|
59
|
-
else if (resbody[
|
|
60
|
-
transform.resform = '`body.' +
|
|
70
|
+
else if (resbody[entdesc.name]) {
|
|
71
|
+
transform.resform = '`body.' + entdesc.name + '`';
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
|
-
const reqdef =
|
|
74
|
+
const reqdef = methodDef.requestBody?.content?.['application/json']?.schema?.properties;
|
|
64
75
|
if (reqdef) {
|
|
65
|
-
if (reqdef[
|
|
66
|
-
transform.reqform = { [
|
|
76
|
+
if (reqdef[entdesc.origname]) {
|
|
77
|
+
transform.reqform = { [entdesc.origname]: '`reqdata`' };
|
|
67
78
|
}
|
|
68
|
-
else if (reqdef[
|
|
69
|
-
transform.reqform = { [
|
|
79
|
+
else if (reqdef[entdesc.origname]) {
|
|
80
|
+
transform.reqform = { [entdesc.origname]: '`reqdata`' };
|
|
70
81
|
}
|
|
71
82
|
}
|
|
83
|
+
const op = entdesc.path[pathStr].op;
|
|
72
84
|
op[opname] = {
|
|
73
85
|
// TODO: in actual guide, remove "standard" method ops since redundant
|
|
74
|
-
method,
|
|
86
|
+
method: methodStr,
|
|
75
87
|
};
|
|
76
88
|
if (0 < Object.entries(transform).length) {
|
|
77
89
|
op[opname].transform = transform;
|
|
78
90
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
(0, jostraca_1.each)(paths, (pathdef, pathname) => {
|
|
83
|
-
// look for rightmmost /entname/{entid}
|
|
84
|
-
const m = pathname.match(/\/([a-zA-Z0-1_-]+)$/);
|
|
85
|
-
if (m) {
|
|
86
|
-
let origentname = (0, jostraca_1.snakify)(m[1]);
|
|
87
|
-
let entname = depluralize(origentname);
|
|
88
|
-
let entdesc = entityDescs[entname];
|
|
89
|
-
if (entdesc) {
|
|
90
|
-
entdesc.path = (entdesc.path || {});
|
|
91
|
-
if (pathdef.get) {
|
|
92
|
-
const op = { list: { method: 'get' } };
|
|
93
|
-
entdesc.path[pathname] = { op };
|
|
94
|
-
const transform = {};
|
|
95
|
-
const mdef = pathdef.get;
|
|
96
|
-
const resokdef = mdef.responses[200] || mdef.responses[201];
|
|
97
|
-
const resbody = resokdef?.content?.['application/json']?.schema;
|
|
98
|
-
if (resbody) {
|
|
99
|
-
if (resbody[origentname]) {
|
|
100
|
-
// TODO: use quotes when @voxgig/struct updated to support them
|
|
101
|
-
// transform.resform = '`body."'+origentname+'"`'
|
|
102
|
-
transform.resform = '`body.' + origentname + '`';
|
|
103
|
-
}
|
|
104
|
-
else if (resbody[entname]) {
|
|
105
|
-
transform.resform = '`body.' + entname + '`';
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (0 < Object.entries(transform).length) {
|
|
109
|
-
op.transform = transform;
|
|
110
|
-
}
|
|
91
|
+
if ('/v2/users/{user_id}/enrollment' === pathStr) {
|
|
92
|
+
console.log('ENT');
|
|
93
|
+
console.dir(entdesc, { depth: null });
|
|
111
94
|
}
|
|
112
|
-
}
|
|
95
|
+
});
|
|
113
96
|
}
|
|
114
97
|
});
|
|
98
|
+
// console.log('USER')
|
|
99
|
+
// console.dir(entityDescs.user, { depth: null })
|
|
115
100
|
return entityDescs;
|
|
116
101
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
function resolveEntity(entityDescs, pathDef, pathStr, methodDef, methodStr) {
|
|
103
|
+
let entdesc;
|
|
104
|
+
let entname = '';
|
|
105
|
+
let origentname = '';
|
|
106
|
+
const m = pathStr.match(/\/([a-zA-Z0-1_-]+)(\/\{([a-zA-Z0-1_-]+)\})?$/);
|
|
107
|
+
if (m) {
|
|
108
|
+
let pathName = m[1];
|
|
109
|
+
origentname = (0, jostraca_1.snakify)(pathName);
|
|
110
|
+
// Check schema
|
|
111
|
+
const compname = resolveComponentName(methodDef, methodStr);
|
|
112
|
+
if (compname) {
|
|
113
|
+
origentname = (0, jostraca_1.snakify)(compname);
|
|
114
|
+
}
|
|
115
|
+
entname = (0, utility_1.depluralize)(origentname);
|
|
116
|
+
entdesc = (entityDescs[entname] = entityDescs[entname] || {
|
|
117
|
+
name: entname,
|
|
118
|
+
id: Math.random(),
|
|
119
|
+
alias: {}
|
|
120
|
+
});
|
|
121
|
+
let pathParam = m[3];
|
|
122
|
+
if (null != pathParam) {
|
|
123
|
+
const pathParamCanon = (0, jostraca_1.snakify)(pathParam);
|
|
124
|
+
if ('id' != pathParamCanon) {
|
|
125
|
+
entdesc.alias.id = pathParamCanon;
|
|
126
|
+
entdesc.alias[pathParamCanon] = 'id';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
120
129
|
}
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
'
|
|
124
|
-
|
|
125
|
-
'women': 'woman',
|
|
126
|
-
'teeth': 'tooth',
|
|
127
|
-
'feet': 'foot',
|
|
128
|
-
'geese': 'goose',
|
|
129
|
-
'mice': 'mouse',
|
|
130
|
-
'people': 'person',
|
|
131
|
-
'data': 'datum',
|
|
132
|
-
'criteria': 'criterion',
|
|
133
|
-
'phenomena': 'phenomenon',
|
|
134
|
-
'indices': 'index',
|
|
135
|
-
'matrices': 'matrix',
|
|
136
|
-
'vertices': 'vertex',
|
|
137
|
-
'analyses': 'analysis',
|
|
138
|
-
'axes': 'axis',
|
|
139
|
-
'crises': 'crisis',
|
|
140
|
-
'diagnoses': 'diagnosis',
|
|
141
|
-
'oases': 'oasis',
|
|
142
|
-
'theses': 'thesis',
|
|
143
|
-
'appendices': 'appendix'
|
|
144
|
-
};
|
|
145
|
-
if (irregulars[word]) {
|
|
146
|
-
return irregulars[word];
|
|
130
|
+
// Can't figure out the entity
|
|
131
|
+
else {
|
|
132
|
+
console.log('NO ENTTIY', pathStr);
|
|
133
|
+
return;
|
|
147
134
|
}
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
135
|
+
// entdesc.plural = origentname
|
|
136
|
+
entdesc.origname = origentname;
|
|
137
|
+
(0, jostraca_1.names)(entdesc, entname);
|
|
138
|
+
entdesc.alias = entdesc.alias || {};
|
|
139
|
+
entdesc.path = (entdesc.path || {});
|
|
140
|
+
entdesc.path[pathStr] = entdesc.path[pathStr] || {};
|
|
141
|
+
entdesc.path[pathStr].op = entdesc.path[pathStr].op || {};
|
|
142
|
+
return entdesc;
|
|
143
|
+
}
|
|
144
|
+
const REQKIND = {
|
|
145
|
+
get: 'res',
|
|
146
|
+
post: 'req',
|
|
147
|
+
put: 'req',
|
|
148
|
+
patch: 'req',
|
|
149
|
+
};
|
|
150
|
+
function resolveComponentName(methodDef, methodStr) {
|
|
151
|
+
const kind = REQKIND[methodStr];
|
|
152
|
+
let compname = undefined;
|
|
153
|
+
const responses = methodDef.responses;
|
|
154
|
+
const schemalist = [
|
|
155
|
+
methodDef.requestBody?.content,
|
|
156
|
+
responses?.['201'],
|
|
157
|
+
responses?.['200'],
|
|
158
|
+
]
|
|
159
|
+
.filter(cmp => null != cmp)
|
|
160
|
+
.map(content => content['application/json']?.schema)
|
|
161
|
+
.filter(schema => null != schema)
|
|
162
|
+
.filter(schema => null != schema['x-ref'])
|
|
163
|
+
.map(schema => {
|
|
164
|
+
let xrefm = schema['x-ref'].match(/\/components\/schemas\/(.+)$/);
|
|
165
|
+
if (xrefm) {
|
|
166
|
+
schema['x-ref-cmp'] = xrefm[1];
|
|
167
|
+
}
|
|
168
|
+
return schema;
|
|
169
|
+
})
|
|
170
|
+
.filter(schema => null != schema['x-ref-cmp']);
|
|
171
|
+
let schema = undefined;
|
|
172
|
+
let splen = -1;
|
|
173
|
+
for (let sI = 0; sI < schemalist.length; sI++) {
|
|
174
|
+
let nextschema = schemalist[sI];
|
|
175
|
+
let nsplen = nextschema.properties?.length || -1;
|
|
176
|
+
// console.log('QQQ', splen, nsplen, schema?.['x-ref-cmp'], nextschema?.['x-ref-cmp'])
|
|
177
|
+
if (
|
|
178
|
+
// More properties probably means it is the full entity.
|
|
179
|
+
splen < nsplen ||
|
|
180
|
+
// Shorter name probably means it is the full entity (no suffix/prefix).
|
|
181
|
+
(schema && splen === nsplen && nextschema['x-ref-cmp'].length < schema['x-ref-cmp'].length)) {
|
|
182
|
+
schema = nextschema;
|
|
183
|
+
splen = nsplen;
|
|
184
|
+
}
|
|
152
185
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
if (schema) {
|
|
187
|
+
let xref = schema['x-ref'];
|
|
188
|
+
// console.log('RCN-XREF', methodStr, 'xref-0', xref)
|
|
189
|
+
if (null == xref) {
|
|
190
|
+
const properties = schema.properties || {};
|
|
191
|
+
(0, jostraca_1.each)(properties, (prop) => {
|
|
192
|
+
if (null == xref) {
|
|
193
|
+
if (prop.type === 'array') {
|
|
194
|
+
xref = prop.items?.['x-ref'];
|
|
195
|
+
// console.log('RCN', methodStr, 'xref-1', xref)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (null != xref && 'string' === typeof xref) {
|
|
201
|
+
let xrefm = xref.match(/\/components\/schemas\/(.+)$/);
|
|
202
|
+
if (xrefm) {
|
|
203
|
+
compname = xrefm[1];
|
|
204
|
+
}
|
|
159
205
|
}
|
|
160
|
-
return stem + 'f';
|
|
161
206
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
207
|
+
return compname;
|
|
208
|
+
}
|
|
209
|
+
function resolveOpName(methodStr, methodDef, pathStr, entdesc) {
|
|
210
|
+
let opname = METHOD_IDOP[methodStr];
|
|
211
|
+
if (null == opname)
|
|
212
|
+
return;
|
|
213
|
+
if ('load' === opname) {
|
|
214
|
+
const islist = isListResponse(methodDef, pathStr, entdesc);
|
|
215
|
+
opname = islist ? 'list' : opname;
|
|
216
|
+
console.log('ISLIST', entdesc.name, methodStr, opname, pathStr);
|
|
165
217
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
218
|
+
return opname;
|
|
219
|
+
}
|
|
220
|
+
function isListResponse(methodDef, pathStr, entdesc) {
|
|
221
|
+
const responses = methodDef.responses;
|
|
222
|
+
const resdef = responses?.['201'] || responses?.['200'];
|
|
223
|
+
const content = resdef?.content;
|
|
224
|
+
let islist = false;
|
|
225
|
+
if (null != content) {
|
|
226
|
+
const schema = content['application/json']?.schema;
|
|
227
|
+
if (schema) {
|
|
228
|
+
if (schema.type === 'array') {
|
|
229
|
+
islist = true;
|
|
230
|
+
}
|
|
231
|
+
if (!islist) {
|
|
232
|
+
const properties = schema.properties || {};
|
|
233
|
+
(0, jostraca_1.each)(properties, (prop) => {
|
|
234
|
+
if (prop.type === 'array') {
|
|
235
|
+
if (1 === (0, struct_1.size)(properties) ||
|
|
236
|
+
prop.key$ === entdesc.name ||
|
|
237
|
+
prop.key$ === entdesc.origname ||
|
|
238
|
+
listedEntity(prop) === entdesc.name) {
|
|
239
|
+
islist = true;
|
|
240
|
+
}
|
|
241
|
+
if ('/v2/users' === pathStr) {
|
|
242
|
+
console.log('islistresponse', islist, pathStr, entdesc.name, listedEntity(prop), properties);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
170
248
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
249
|
+
return islist;
|
|
250
|
+
}
|
|
251
|
+
function listedEntity(prop) {
|
|
252
|
+
const xref = prop?.items?.['x-ref'];
|
|
253
|
+
const m = 'string' === typeof xref && xref.match(/^#\/components\/schemas\/(.+)$/);
|
|
254
|
+
if (m) {
|
|
255
|
+
return (0, utility_1.depluralize)((0, jostraca_1.snakify)(m[1]));
|
|
174
256
|
}
|
|
175
|
-
// If none of the rules apply, return as is
|
|
176
|
-
return word;
|
|
177
257
|
}
|
|
178
258
|
//# sourceMappingURL=heuristic01.js.map
|