@voxgig/apidef 1.8.0 → 2.0.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 +3 -29
- package/dist/apidef.js +84 -186
- package/dist/apidef.js.map +1 -1
- package/dist/builder/entity/apiEntity.d.ts +3 -0
- package/dist/builder/entity/apiEntity.js +51 -0
- package/dist/builder/entity/apiEntity.js.map +1 -0
- package/dist/builder/entity/def.d.ts +3 -0
- package/dist/builder/entity/def.js +19 -0
- package/dist/builder/entity/def.js.map +1 -0
- package/dist/builder/entity.d.ts +2 -0
- package/dist/builder/entity.js +30 -0
- package/dist/builder/entity.js.map +1 -0
- package/dist/builder/flow/flowHeuristic01.d.ts +2 -0
- package/dist/builder/flow/flowHeuristic01.js +125 -0
- package/dist/builder/flow/flowHeuristic01.js.map +1 -0
- package/dist/builder/flow.d.ts +2 -0
- package/dist/builder/flow.js +41 -0
- package/dist/builder/flow.js.map +1 -0
- package/dist/guide/heuristic01.d.ts +2 -0
- package/dist/guide/heuristic01.js +178 -0
- package/dist/guide/heuristic01.js.map +1 -0
- package/dist/guide.d.ts +2 -0
- package/dist/guide.js +62 -0
- package/dist/guide.js.map +1 -0
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +5 -4
- package/dist/parse.js.map +1 -1
- package/dist/resolver.d.ts +2 -0
- package/dist/resolver.js +62 -0
- package/dist/resolver.js.map +1 -0
- package/dist/transform/entity.js +4 -2
- package/dist/transform/entity.js.map +1 -1
- package/dist/transform/field.js +4 -84
- package/dist/transform/field.js.map +1 -1
- package/dist/transform/operation.d.ts +2 -2
- package/dist/transform/operation.js +22 -11
- package/dist/transform/operation.js.map +1 -1
- package/dist/transform/top.d.ts +2 -2
- package/dist/transform/top.js +5 -4
- package/dist/transform/top.js.map +1 -1
- package/dist/transform.d.ts +1 -1
- package/dist/transform.js +21 -10
- package/dist/transform.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +682 -0
- package/dist/types.js +38 -0
- package/dist/types.js.map +1 -0
- package/dist/utility.d.ts +4 -0
- package/dist/utility.js +59 -0
- package/dist/utility.js.map +1 -0
- package/model/apidef.jsonic +28 -24
- package/package.json +11 -9
- package/src/apidef.ts +117 -263
- package/src/builder/entity/apiEntity.ts +88 -0
- package/src/builder/entity/def.ts +44 -0
- package/src/builder/entity.ts +54 -0
- package/src/builder/flow/flowHeuristic01.ts +165 -0
- package/src/builder/flow/flowHeuristic01.ts~ +45 -0
- package/src/builder/flow.ts +60 -0
- package/src/guide/heuristic01.ts +225 -0
- package/src/guide.ts +91 -0
- package/src/parse.ts +6 -4
- package/src/resolver.ts +91 -0
- package/src/transform/entity.ts +10 -7
- package/src/transform/field.ts +9 -92
- package/src/transform/operation.ts +39 -25
- package/src/transform/top.ts +11 -9
- package/src/transform.ts +23 -11
- package/src/types.ts +88 -0
- package/src/utility.ts +83 -0
- package/dist/transform/manual.d.ts +0 -3
- package/dist/transform/manual.js +0 -12
- package/dist/transform/manual.js.map +0 -1
- package/src/transform/manual.ts +0 -29
package/dist/apidef.d.ts
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
def?: string;
|
|
4
|
-
fs?: any;
|
|
5
|
-
pino?: ReturnType<typeof Pino>;
|
|
6
|
-
debug?: boolean | string;
|
|
7
|
-
folder?: string;
|
|
8
|
-
meta?: Record<string, any>;
|
|
9
|
-
outprefix?: string;
|
|
10
|
-
};
|
|
11
|
-
type ApiModel = {
|
|
12
|
-
main: {
|
|
13
|
-
api: {
|
|
14
|
-
entity: Record<string, any>;
|
|
15
|
-
};
|
|
16
|
-
def: Record<string, any>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
1
|
+
import type { ApiDefOptions, ApiModel } from './types';
|
|
2
|
+
import { parse } from './parse';
|
|
19
3
|
declare function ApiDef(opts: ApiDefOptions): {
|
|
20
4
|
generate: (spec: any) => Promise<{
|
|
21
|
-
ok: boolean;
|
|
22
|
-
name: string;
|
|
23
|
-
processResult: {
|
|
24
|
-
ok: boolean;
|
|
25
|
-
msg: string;
|
|
26
|
-
results: import("./transform").TransformResult[];
|
|
27
|
-
};
|
|
28
|
-
apimodel?: undefined;
|
|
29
|
-
} | {
|
|
30
5
|
ok: boolean;
|
|
31
6
|
name: string;
|
|
32
7
|
apimodel: ApiModel;
|
|
33
|
-
processResult?: undefined;
|
|
34
8
|
}>;
|
|
35
9
|
};
|
|
36
10
|
declare namespace ApiDef {
|
|
@@ -40,4 +14,4 @@ declare namespace ApiDef {
|
|
|
40
14
|
}>;
|
|
41
15
|
}
|
|
42
16
|
export type { ApiDefOptions, };
|
|
43
|
-
export { ApiDef, };
|
|
17
|
+
export { ApiDef, parse, };
|
package/dist/apidef.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* Copyright (c) 2024 Voxgig, MIT License */
|
|
2
|
+
/* Copyright (c) 2024-2025 Voxgig, MIT License */
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -37,50 +37,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.parse = void 0;
|
|
40
41
|
exports.ApiDef = ApiDef;
|
|
41
42
|
const Fs = __importStar(require("node:fs"));
|
|
42
43
|
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
-
const node_util_1 = require("node:util");
|
|
44
|
-
const openapi_core_1 = require("@redocly/openapi-core");
|
|
45
|
-
const gubu_1 = require("gubu");
|
|
46
44
|
const jostraca_1 = require("jostraca");
|
|
47
45
|
const util_1 = require("@voxgig/util");
|
|
46
|
+
const types_1 = require("./types");
|
|
47
|
+
const guide_1 = require("./guide");
|
|
48
|
+
const parse_1 = require("./parse");
|
|
49
|
+
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
|
|
48
50
|
const transform_1 = require("./transform");
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
watch: {
|
|
69
|
-
mod: true,
|
|
70
|
-
add: true,
|
|
71
|
-
rem: true,
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const OpenBuildShape = (0, gubu_1.Gubu)((0, gubu_1.Open)(BuildShape));
|
|
51
|
+
const resolver_1 = require("./resolver");
|
|
52
|
+
const utility_1 = require("./utility");
|
|
53
|
+
const top_1 = require("./transform/top");
|
|
54
|
+
const entity_1 = require("./transform/entity");
|
|
55
|
+
const operation_1 = require("./transform/operation");
|
|
56
|
+
const field_1 = require("./transform/field");
|
|
57
|
+
const entity_2 = require("./builder/entity");
|
|
58
|
+
const flow_1 = require("./builder/flow");
|
|
76
59
|
function ApiDef(opts) {
|
|
60
|
+
// TODO: gubu opts!
|
|
77
61
|
const fs = opts.fs || Fs;
|
|
78
62
|
const pino = (0, util_1.prettyPino)('apidef', opts);
|
|
79
63
|
const log = pino.child({ cmp: 'apidef' });
|
|
64
|
+
opts.strategy = opts.strategy || 'heuristic01';
|
|
80
65
|
async function generate(spec) {
|
|
81
66
|
const start = Date.now();
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
// console.log('APIDEF GENERATE')
|
|
68
|
+
// console.dir(spec, { depth: null })
|
|
69
|
+
const model = (0, types_1.OpenModelShape)(spec.model);
|
|
70
|
+
const build = (0, types_1.OpenBuildShape)(spec.build);
|
|
71
|
+
(0, jostraca_1.names)(model, model.name);
|
|
72
|
+
const apimodel = {
|
|
73
|
+
main: {
|
|
74
|
+
api: {
|
|
75
|
+
entity: {}
|
|
76
|
+
},
|
|
77
|
+
def: {},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
84
80
|
const buildspec = build.spec;
|
|
85
81
|
let defpath = model.def;
|
|
86
82
|
// TOOD: defpath should be independently defined
|
|
@@ -91,61 +87,68 @@ function ApiDef(opts) {
|
|
|
91
87
|
});
|
|
92
88
|
// TODO: Validate spec
|
|
93
89
|
const ctx = {
|
|
90
|
+
fs,
|
|
94
91
|
log,
|
|
95
92
|
spec,
|
|
96
93
|
opts,
|
|
97
94
|
util: { fixName: transform_1.fixName },
|
|
98
95
|
defpath: node_path_1.default.dirname(defpath),
|
|
99
96
|
model,
|
|
97
|
+
apimodel,
|
|
98
|
+
def: undefined
|
|
100
99
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
const defsrc = (0, utility_1.loadFile)(defpath, 'def', fs, log);
|
|
101
|
+
const def = await (0, parse_1.parse)('OpenAPI', defsrc, { file: defpath });
|
|
102
|
+
ctx.def = def;
|
|
103
|
+
const guideBuilder = await (0, guide_1.resolveGuide)(ctx);
|
|
104
|
+
// const transformSpec = await resolveTransforms(ctx)
|
|
105
|
+
const transforms = await (0, resolver_1.resolveElements)(ctx, 'transform', 'openapi', {
|
|
106
|
+
top: top_1.topTransform,
|
|
107
|
+
entity: entity_1.entityTransform,
|
|
108
|
+
operation: operation_1.operationTransform,
|
|
109
|
+
field: field_1.fieldTransform,
|
|
105
110
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
buildModel_def(apimodel, modelPath);
|
|
148
|
-
buildModel_entity(apimodel, modelPath);
|
|
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
|
+
const builders = await (0, resolver_1.resolveElements)(ctx, 'builder', 'standard', {
|
|
125
|
+
entity: entity_2.makeEntityBuilder,
|
|
126
|
+
flow: flow_1.makeFlowBuilder,
|
|
127
|
+
});
|
|
128
|
+
// const entityBuilder = resolveEntity(apimodel, spec, opts)
|
|
129
|
+
// const entityBuilder = await resolveEntity(ctx)
|
|
130
|
+
// const flowBuilder = await resolveFlows(ctx)
|
|
131
|
+
const jostraca = (0, jostraca_1.Jostraca)({
|
|
132
|
+
now: spec.now,
|
|
133
|
+
fs: () => fs,
|
|
134
|
+
log,
|
|
135
|
+
});
|
|
136
|
+
const jmodel = {};
|
|
137
|
+
const root = () => (0, jostraca_1.Project)({ folder: '.' }, async () => {
|
|
138
|
+
guideBuilder();
|
|
139
|
+
// entityBuilder()
|
|
140
|
+
// flowBuilder()
|
|
141
|
+
for (let builder of builders) {
|
|
142
|
+
builder();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
const jres = await jostraca.generate({
|
|
146
|
+
// folder: Path.dirname(opts.folder as string),
|
|
147
|
+
folder: opts.folder,
|
|
148
|
+
model: jmodel,
|
|
149
|
+
existing: { txt: { merge: true } }
|
|
150
|
+
}, root);
|
|
151
|
+
// console.log('JRES', jres)
|
|
149
152
|
log.info({ point: 'generate-end', note: 'success', break: true });
|
|
150
153
|
return {
|
|
151
154
|
ok: true,
|
|
@@ -153,102 +156,16 @@ function ApiDef(opts) {
|
|
|
153
156
|
apimodel,
|
|
154
157
|
};
|
|
155
158
|
}
|
|
156
|
-
function buildModel_api(apimodel, modelPath) {
|
|
157
|
-
const modelapi = { main: { api: apimodel.main.api } };
|
|
158
|
-
let modelSrc = JSON.stringify(modelapi, null, 2);
|
|
159
|
-
modelSrc =
|
|
160
|
-
'# GENERATED FILE - DO NOT EDIT\n\n' +
|
|
161
|
-
modelSrc.substring(1, modelSrc.length - 1).replace(/\n /g, '\n');
|
|
162
|
-
writeChanged('api-model', modelPath, modelSrc);
|
|
163
|
-
return modelPath;
|
|
164
|
-
}
|
|
165
|
-
function buildModel_def(apimodel, modelPath) {
|
|
166
|
-
const modelBasePath = node_path_1.default.dirname(modelPath);
|
|
167
|
-
const defFilePath = node_path_1.default.join(modelBasePath, (null == opts.outprefix ? '' : opts.outprefix) + 'def-generated.jsonic');
|
|
168
|
-
const modelDef = { main: { def: apimodel.main.def } };
|
|
169
|
-
let modelDefSrc = JSON.stringify(modelDef, null, 2);
|
|
170
|
-
modelDefSrc =
|
|
171
|
-
'# GENERATED FILE - DO NOT EDIT\n\n' +
|
|
172
|
-
modelDefSrc.substring(1, modelDefSrc.length - 1).replace(/\n /g, '\n');
|
|
173
|
-
writeChanged('def-model', defFilePath, modelDefSrc);
|
|
174
|
-
}
|
|
175
|
-
function buildModel_entity(apimodel, modelPath) {
|
|
176
|
-
const modelBasePath = node_path_1.default.dirname(modelPath);
|
|
177
|
-
const entityIncludes = [];
|
|
178
|
-
(0, jostraca_1.each)(apimodel.main.api.entity, ((entity) => {
|
|
179
|
-
entityIncludes.push(entity.name);
|
|
180
|
-
// HEURISTIC: id may be name_id or nameId
|
|
181
|
-
const fieldAliases = (0, jostraca_1.each)(entity.op, (op) => (0, jostraca_1.each)(op.param))
|
|
182
|
-
.flat()
|
|
183
|
-
.reduce((a, p) => (entity.field[p.keys] ? null :
|
|
184
|
-
(p.key$.toLowerCase().includes(entity.name) ?
|
|
185
|
-
(a[p.key$] = 'id', a.id = p.key$) :
|
|
186
|
-
null)
|
|
187
|
-
, a), {});
|
|
188
|
-
const fieldAliasesSrc = JSON.stringify(fieldAliases, null, 2)
|
|
189
|
-
.replace(/\n/g, '\n ');
|
|
190
|
-
const entityFileSrc = `
|
|
191
|
-
# Entity ${entity.name}
|
|
192
|
-
|
|
193
|
-
main: sdk: entity: ${entity.name}: {
|
|
194
|
-
alias: field: ${fieldAliasesSrc}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
`;
|
|
198
|
-
const entityFilePath = node_path_1.default.join(modelBasePath, 'entity', (null == opts.outprefix ? '' : opts.outprefix) + entity.name + '.jsonic');
|
|
199
|
-
fs.mkdirSync(node_path_1.default.dirname(entityFilePath), { recursive: true });
|
|
200
|
-
// TODO: diff merge
|
|
201
|
-
writeChanged('entity-model', entityFilePath, entityFileSrc, { update: false });
|
|
202
|
-
}));
|
|
203
|
-
modifyModel(fs, node_path_1.default.join(modelBasePath, (null == opts.outprefix ? '' : opts.outprefix) + 'sdk.jsonic'), entityIncludes);
|
|
204
|
-
}
|
|
205
|
-
function writeChanged(point, path, content, flags) {
|
|
206
|
-
let exists = false;
|
|
207
|
-
let changed = false;
|
|
208
|
-
flags = flags || {};
|
|
209
|
-
flags.update = null == flags.update ? true : !!flags.update;
|
|
210
|
-
let action = '';
|
|
211
|
-
try {
|
|
212
|
-
let existingContent = '';
|
|
213
|
-
path = node_path_1.default.normalize(path);
|
|
214
|
-
exists = fs.existsSync(path);
|
|
215
|
-
if (exists) {
|
|
216
|
-
action = 'read';
|
|
217
|
-
existingContent = fs.readFileSync(path, 'utf8');
|
|
218
|
-
}
|
|
219
|
-
changed = existingContent !== content;
|
|
220
|
-
action = flags.update ? 'write' : 'skip';
|
|
221
|
-
log.info({
|
|
222
|
-
point: 'write-' + point,
|
|
223
|
-
note: (changed ? '' : 'not-') + 'changed ' + path,
|
|
224
|
-
write: 'file', skip: !changed, exists, changed,
|
|
225
|
-
contentLength: content.length, file: path
|
|
226
|
-
});
|
|
227
|
-
if (!exists || (changed && flags.update)) {
|
|
228
|
-
fs.writeFileSync(path, content);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
log.error({
|
|
233
|
-
fail: action, point, file: path, exists, changed,
|
|
234
|
-
contentLength: content.length, err
|
|
235
|
-
});
|
|
236
|
-
err.__logged__ = true;
|
|
237
|
-
throw err;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
159
|
return {
|
|
241
160
|
generate,
|
|
242
161
|
};
|
|
243
162
|
}
|
|
244
163
|
ApiDef.makeBuild = async function (opts) {
|
|
245
164
|
let apidef = undefined;
|
|
246
|
-
const outprefix = null == opts.outprefix ? '' : opts.outprefix
|
|
165
|
+
// const outprefix = null == opts.outprefix ? '' : opts.outprefix
|
|
247
166
|
const config = {
|
|
248
167
|
def: opts.def || 'no-def',
|
|
249
168
|
kind: 'openapi3',
|
|
250
|
-
model: opts.folder ?
|
|
251
|
-
(opts.folder + '/' + outprefix + 'api-generated.jsonic') : 'no-model',
|
|
252
169
|
meta: opts.meta || {},
|
|
253
170
|
};
|
|
254
171
|
const build = async function (model, build, ctx) {
|
|
@@ -263,23 +180,4 @@ ApiDef.makeBuild = async function (opts) {
|
|
|
263
180
|
build.step = 'pre';
|
|
264
181
|
return build;
|
|
265
182
|
};
|
|
266
|
-
async function modifyModel(fs, path, entityIncludes) {
|
|
267
|
-
// TODO: This is a kludge.
|
|
268
|
-
// Aontu should provide option for as-is AST so that can be used
|
|
269
|
-
// to find injection point more reliably
|
|
270
|
-
let src = fs.existsSync(path) ? fs.readFileSync(path, 'utf8') :
|
|
271
|
-
'main: sdk: entity: {}\n';
|
|
272
|
-
let newsrc = '' + src;
|
|
273
|
-
// Inject target file references into model
|
|
274
|
-
entityIncludes.sort().map((entname) => {
|
|
275
|
-
const lineRE = new RegExp(`@"entity/${entname}.jsonic"`);
|
|
276
|
-
if (!src.match(lineRE)) {
|
|
277
|
-
newsrc = newsrc.replace(/(main:\s+sdk:\s+entity:\s+\{\s*\}\n)/, '$1' +
|
|
278
|
-
`@"entity/${entname}.jsonic"\n`);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
if (newsrc.length !== src.length) {
|
|
282
|
-
fs.writeFileSync(path, newsrc);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
183
|
//# sourceMappingURL=apidef.js.map
|
package/dist/apidef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkP/C,wBAAM;AAhPR,4CAA6B;AAC7B,0DAA4B;AAG5B,uCAAmD;AAEnD,uCAAyC;AAUzC,mCAGgB;AAGhB,mCAEgB;AAGhB,mCAEgB;AAoNd,sFArNA,aAAK,OAqNA;AAjNP,2CAIoB;AAIpB,yCAEmB;A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,IAAI,CAAC,IAAI,IAAI,EAAE;KACtB,CAAA;IAED,MAAM,KAAK,GAAG,KAAK,WAAU,KAAU,EAAE,KAAU,EAAE,GAAQ;QAE3D,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;YACnB,MAAM,GAAG,MAAM,CAAC;gBACd,GAAG,IAAI;gBACP,IAAI,EAAE,KAAK,CAAC,GAAG;aAChB,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACxD,CAAC,CAAA;IAED,KAAK,CAAC,IAAI,GAAG,KAAK,CAAA;IAElB,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Voxgig, MIT License */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveApiEntity = resolveApiEntity;
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const jostraca_1 = require("jostraca");
|
|
10
|
+
const utility_1 = require("../../utility");
|
|
11
|
+
function resolveApiEntity(apimodel, opts) {
|
|
12
|
+
const barrel = [
|
|
13
|
+
'# Entity Models\n'
|
|
14
|
+
];
|
|
15
|
+
const entityFiles = [];
|
|
16
|
+
(0, jostraca_1.each)(apimodel.main.api.entity, ((entity, entityName) => {
|
|
17
|
+
const entityFile = (null == opts.outprefix ? '' : opts.outprefix) + entityName + '.jsonic';
|
|
18
|
+
const entityJSON = JSON.stringify(entity, null, 2);
|
|
19
|
+
const fieldAliasesSrc = fieldAliases(entity);
|
|
20
|
+
const entitySrc = `# Entity: ${entity.name}\n\n` +
|
|
21
|
+
`main: api: entity: ${entity.name}: {\n\n` +
|
|
22
|
+
` alias: field: ${fieldAliasesSrc}\n` +
|
|
23
|
+
(0, utility_1.formatJsonSrc)(entityJSON.substring(1, entityJSON.length - 1)) +
|
|
24
|
+
'\n\n}\n';
|
|
25
|
+
entityFiles.push({ name: entityFile, src: entitySrc });
|
|
26
|
+
barrel.push(`@"${node_path_1.default.basename(entityFile)}"`);
|
|
27
|
+
}));
|
|
28
|
+
const indexFile = (null == opts.outprefix ? '' : opts.outprefix) + 'api-entity-index.jsonic';
|
|
29
|
+
return function apiEntityBuilder() {
|
|
30
|
+
(0, jostraca_1.Folder)({ name: 'api' }, () => {
|
|
31
|
+
(0, jostraca_1.each)(entityFiles, (entityFile) => {
|
|
32
|
+
(0, jostraca_1.File)({ name: entityFile.name }, () => (0, jostraca_1.Content)(entityFile.src));
|
|
33
|
+
});
|
|
34
|
+
(0, jostraca_1.File)({ name: indexFile }, () => (0, jostraca_1.Content)(barrel.join('\n')));
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function fieldAliases(entity) {
|
|
39
|
+
// HEURISTIC: id may be name_id or nameId
|
|
40
|
+
const fieldAliases = (0, jostraca_1.each)(entity.op, (op) => (0, jostraca_1.each)(op.param))
|
|
41
|
+
.flat()
|
|
42
|
+
.reduce((a, p) => (entity.field[p.keys] ? null :
|
|
43
|
+
(p.key$.toLowerCase().includes(entity.name) ?
|
|
44
|
+
(a[p.key$] = 'id', a.id = p.key$) :
|
|
45
|
+
null)
|
|
46
|
+
, a), {});
|
|
47
|
+
const fieldAliasesSrc = JSON.stringify(fieldAliases, null, 2)
|
|
48
|
+
.replace(/\n/g, '\n ');
|
|
49
|
+
return fieldAliasesSrc;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=apiEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiEntity.js","sourceRoot":"","sources":["../../../src/builder/entity/apiEntity.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;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AAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;SAClC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAE3B,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Voxgig, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.resolveDef = resolveDef;
|
|
5
|
+
const jostraca_1 = require("jostraca");
|
|
6
|
+
function resolveDef(apimodel, opts) {
|
|
7
|
+
const defFile = (null == opts.outprefix ? '' : opts.outprefix) + 'api-def.jsonic';
|
|
8
|
+
const modelDef = { main: { def: apimodel.main.def } };
|
|
9
|
+
let modelDefSrc = JSON.stringify(modelDef, null, 2);
|
|
10
|
+
modelDefSrc =
|
|
11
|
+
'# API Definition\n\n' +
|
|
12
|
+
modelDefSrc.substring(1, modelDefSrc.length - 1).replace(/\n /g, '\n');
|
|
13
|
+
return function defBuilder() {
|
|
14
|
+
(0, jostraca_1.Folder)({ name: 'api' }, () => {
|
|
15
|
+
(0, jostraca_1.File)({ name: defFile }, () => (0, jostraca_1.Content)(modelDefSrc));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=def.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"def.js","sourceRoot":"","sources":["../../../src/builder/entity/def.ts"],"names":[],"mappings":";AAAA,4CAA4C;;AA0C1C,gCAAU;AA/BZ,uCAIiB;AAGjB,SAAS,UAAU,CACjB,QAAkB,EAClB,IAAmB;IAEnB,MAAM,OAAO,GACX,CAAC,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,gBAAgB,CAAA;IAEnE,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAA;IACrD,IAAI,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAEnD,WAAW;QACT,sBAAsB;YACtB,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAEzE,OAAO,SAAS,UAAU;QACxB,IAAA,iBAAM,EAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE;YAC3B,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,IAAA,kBAAO,EAAC,WAAW,CAAC,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AAEH,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2025 Voxgig, MIT License */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.makeEntityBuilder = makeEntityBuilder;
|
|
5
|
+
// import { each } from 'jostraca'
|
|
6
|
+
// import type {
|
|
7
|
+
// ApiDefOptions,
|
|
8
|
+
// Log,
|
|
9
|
+
// FsUtil,
|
|
10
|
+
// } from '../types'
|
|
11
|
+
// import {
|
|
12
|
+
// writeChanged
|
|
13
|
+
// } from '../utility'
|
|
14
|
+
const apiEntity_1 = require("./entity/apiEntity");
|
|
15
|
+
const def_1 = require("./entity/def");
|
|
16
|
+
// import {
|
|
17
|
+
// resolveSdkEntity
|
|
18
|
+
// } from './entity/sdkEntity'
|
|
19
|
+
async function makeEntityBuilder(ctx) {
|
|
20
|
+
const { apimodel, opts } = ctx;
|
|
21
|
+
const apiEntityBuilder = (0, apiEntity_1.resolveApiEntity)(apimodel, opts);
|
|
22
|
+
const defBuilder = (0, def_1.resolveDef)(apimodel, opts);
|
|
23
|
+
// const sdkEntityBuilder = resolveSdkEntity(apimodel, opts)
|
|
24
|
+
return function entityBuilder() {
|
|
25
|
+
apiEntityBuilder();
|
|
26
|
+
defBuilder();
|
|
27
|
+
// sdkEntityBuilder()
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/builder/entity.ts"],"names":[],"mappings":";AAAA,4CAA4C;;AAoD1C,8CAAiB;AAhDnB,kCAAkC;AAGlC,gBAAgB;AAChB,mBAAmB;AACnB,SAAS;AACT,YAAY;AACZ,oBAAoB;AAGpB,WAAW;AACX,iBAAiB;AACjB,sBAAsB;AAGtB,kDAE2B;AAE3B,sCAEqB;AAErB,WAAW;AACX,qBAAqB;AACrB,8BAA8B;AAI9B,KAAK,UAAU,iBAAiB,CAAC,GAAQ;IACvC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IAE9B,MAAM,gBAAgB,GAAG,IAAA,4BAAgB,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACzD,MAAM,UAAU,GAAG,IAAA,gBAAU,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IAC7C,4DAA4D;IAE5D,OAAO,SAAS,aAAa;QAC3B,gBAAgB,EAAE,CAAA;QAClB,UAAU,EAAE,CAAA;QACZ,qBAAqB;IACvB,CAAC,CAAA;AACH,CAAC"}
|