adorn-api 1.0.9 → 1.0.11
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/adapter/express/index.d.ts.map +1 -1
- package/dist/adapter/express/merge.d.ts +3 -0
- package/dist/adapter/express/merge.d.ts.map +1 -1
- package/dist/cli.cjs +117 -52
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +117 -52
- package/dist/cli.js.map +1 -1
- package/dist/compiler/analyze/scanControllers.d.ts +2 -0
- package/dist/compiler/analyze/scanControllers.d.ts.map +1 -1
- package/dist/compiler/manifest/format.d.ts +1 -0
- package/dist/compiler/manifest/format.d.ts.map +1 -1
- package/dist/compiler/schema/typeToJsonSchema.d.ts.map +1 -1
- package/dist/decorators/Paginated.d.ts +5 -0
- package/dist/decorators/Paginated.d.ts.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/express.cjs +10 -1
- package/dist/express.cjs.map +1 -1
- package/dist/express.js +10 -1
- package/dist/express.js.map +1 -1
- package/dist/http.d.ts +10 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/metal/searchWhere.d.ts +20 -9
- package/dist/metal/searchWhere.d.ts.map +1 -1
- package/dist/runtime/metadata/types.d.ts +3 -0
- package/dist/runtime/metadata/types.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapter/express/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAIjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAGpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,M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GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC;KAChF,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,WAAW,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACvD,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAcD,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiTvF;AAijBD,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElE,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CA4BtE"}
|
|
@@ -14,6 +14,9 @@ export interface BoundRoute {
|
|
|
14
14
|
optional?: boolean;
|
|
15
15
|
} | "public";
|
|
16
16
|
controllerUse?: Array<string | ((req: any, res: any, next: (err?: any) => void) => any)>;
|
|
17
|
+
paginationConfig?: {
|
|
18
|
+
defaultPageSize: number;
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
export declare function bindRoutes(params: {
|
|
19
22
|
controllers: Array<new (...args: any[]) => any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/adapter/express/merge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAMpF,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,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c,CAAC,MAAM,CAAC,CAAC;IAC7B,SAAS,EAAE,cAAc,CAAC,WAAW,CAAC,CAAC;IACvC,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/E,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,QAAQ,CAAC;IAC5E,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACzF,gBAAgB,CAAC,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD;AA+BD,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,WAAW,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;IAChD,QAAQ,EAAE,UAAU,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,UAAU,EAAE,CAyBf;AAqED,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED,wBAAgB,kBAAkB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAKrE"}
|
package/dist/cli.cjs
CHANGED
|
@@ -154,6 +154,7 @@ function analyzeMethod(node, className, checker) {
|
|
|
154
154
|
if (!signature) return null;
|
|
155
155
|
let returnType = checker.getReturnTypeOfSignature(signature);
|
|
156
156
|
returnType = unwrapPromise(returnType, checker);
|
|
157
|
+
const returnTypeNode = unwrapPromiseTypeNode(node.type);
|
|
157
158
|
const parameters = [];
|
|
158
159
|
for (let i = 0; i < node.parameters.length; i++) {
|
|
159
160
|
const param = node.parameters[i];
|
|
@@ -170,7 +171,7 @@ function analyzeMethod(node, className, checker) {
|
|
|
170
171
|
}
|
|
171
172
|
const pathParamNames = extractPathParams(path4);
|
|
172
173
|
const pathParamIndices = matchPathParamsToIndices(pathParamNames, parameters);
|
|
173
|
-
const { bodyParamIndex, queryParamIndices, queryObjectParamIndex, headerObjectParamIndex, cookieObjectParamIndex, bodyContentType } = classifyParameters(parameters, httpMethod, pathParamIndices, checker);
|
|
174
|
+
const { bodyParamIndex, queryParamIndices, queryObjectParamIndex, headerObjectParamIndex, cookieObjectParamIndex, paginationParamIndex, bodyContentType } = classifyParameters(parameters, httpMethod, pathParamIndices, checker);
|
|
174
175
|
return {
|
|
175
176
|
methodName,
|
|
176
177
|
httpMethod,
|
|
@@ -178,6 +179,7 @@ function analyzeMethod(node, className, checker) {
|
|
|
178
179
|
operationId: defaultOperationId(className, methodName),
|
|
179
180
|
methodDeclaration: node,
|
|
180
181
|
returnType,
|
|
182
|
+
returnTypeNode,
|
|
181
183
|
parameters,
|
|
182
184
|
pathParamIndices,
|
|
183
185
|
bodyParamIndex,
|
|
@@ -185,6 +187,7 @@ function analyzeMethod(node, className, checker) {
|
|
|
185
187
|
queryObjectParamIndex,
|
|
186
188
|
headerObjectParamIndex,
|
|
187
189
|
cookieObjectParamIndex,
|
|
190
|
+
paginationParamIndex,
|
|
188
191
|
bodyContentType
|
|
189
192
|
};
|
|
190
193
|
}
|
|
@@ -210,6 +213,7 @@ function classifyParameters(parameters, httpMethod, pathParamIndices, checker) {
|
|
|
210
213
|
let queryObjectParamIndex = null;
|
|
211
214
|
let headerObjectParamIndex = null;
|
|
212
215
|
let cookieObjectParamIndex = null;
|
|
216
|
+
let paginationParamIndex = null;
|
|
213
217
|
const isBodyMethod = ["POST", "PUT", "PATCH"].includes(httpMethod);
|
|
214
218
|
for (let i = 0; i < parameters.length; i++) {
|
|
215
219
|
const param = parameters[i];
|
|
@@ -236,6 +240,11 @@ function classifyParameters(parameters, httpMethod, pathParamIndices, checker) {
|
|
|
236
240
|
usedIndices.add(i);
|
|
237
241
|
continue;
|
|
238
242
|
}
|
|
243
|
+
if (typeStr === "PaginationParams") {
|
|
244
|
+
paginationParamIndex = i;
|
|
245
|
+
usedIndices.add(i);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
239
248
|
if (isBodyMethod && bodyParamIndex === null) {
|
|
240
249
|
bodyParamIndex = i;
|
|
241
250
|
usedIndices.add(i);
|
|
@@ -256,6 +265,7 @@ function classifyParameters(parameters, httpMethod, pathParamIndices, checker) {
|
|
|
256
265
|
queryObjectParamIndex,
|
|
257
266
|
headerObjectParamIndex,
|
|
258
267
|
cookieObjectParamIndex,
|
|
268
|
+
paginationParamIndex,
|
|
259
269
|
bodyContentType: void 0
|
|
260
270
|
};
|
|
261
271
|
}
|
|
@@ -308,6 +318,15 @@ function unwrapPromise(type, checker) {
|
|
|
308
318
|
}
|
|
309
319
|
return type;
|
|
310
320
|
}
|
|
321
|
+
function unwrapPromiseTypeNode(typeNode) {
|
|
322
|
+
if (!typeNode) return void 0;
|
|
323
|
+
if (import_typescript2.default.isTypeReferenceNode(typeNode)) {
|
|
324
|
+
if (import_typescript2.default.isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise") {
|
|
325
|
+
return typeNode.typeArguments?.[0] ?? typeNode;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return typeNode;
|
|
329
|
+
}
|
|
311
330
|
|
|
312
331
|
// src/compiler/schema/openapi.ts
|
|
313
332
|
var import_typescript6 = __toESM(require("typescript"), 1);
|
|
@@ -354,10 +373,10 @@ function typeToJsonSchema(type, ctx, typeNode) {
|
|
|
354
373
|
return { type: "boolean", enum: [intrinsic === "true"] };
|
|
355
374
|
}
|
|
356
375
|
if (type.isUnion()) {
|
|
357
|
-
return handleUnion(type
|
|
376
|
+
return handleUnion(type, ctx, typeNode);
|
|
358
377
|
}
|
|
359
378
|
if (type.isIntersection()) {
|
|
360
|
-
return handleIntersection(type
|
|
379
|
+
return handleIntersection(type, ctx, typeNode);
|
|
361
380
|
}
|
|
362
381
|
if (checker.isArrayType(type)) {
|
|
363
382
|
const typeArgs = type.typeArguments;
|
|
@@ -394,56 +413,96 @@ function isSetType(type, checker) {
|
|
|
394
413
|
if (name === "Set") return true;
|
|
395
414
|
return false;
|
|
396
415
|
}
|
|
397
|
-
function
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const enumValues = otherTypes.map((t) => t.value);
|
|
403
|
-
const schema = { type: "string", enum: enumValues };
|
|
404
|
-
if (nullType) {
|
|
405
|
-
schema.type = ["string", "null"];
|
|
406
|
-
}
|
|
407
|
-
return schema;
|
|
416
|
+
function getSchemaName(type, typeNode) {
|
|
417
|
+
const aliasSymbol = type.aliasSymbol ?? type.aliasSymbol;
|
|
418
|
+
const aliasName = aliasSymbol?.getName();
|
|
419
|
+
if (aliasName && aliasName !== "__type") {
|
|
420
|
+
return aliasName;
|
|
408
421
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
return innerSchema;
|
|
415
|
-
}
|
|
416
|
-
if (otherTypes.length > 1) {
|
|
417
|
-
const branches = otherTypes.map((t) => typeToJsonSchema(t, ctx));
|
|
418
|
-
const hasNull = !!nullType;
|
|
419
|
-
const result = {};
|
|
420
|
-
if (hasNull) {
|
|
421
|
-
result.anyOf = [...branches, { type: "null" }];
|
|
422
|
-
} else {
|
|
423
|
-
result.anyOf = branches;
|
|
424
|
-
}
|
|
425
|
-
const discriminatorResult = detectDiscriminatedUnion(otherTypes, ctx, branches);
|
|
426
|
-
if (discriminatorResult) {
|
|
427
|
-
result.oneOf = branches;
|
|
428
|
-
result.discriminator = discriminatorResult;
|
|
429
|
-
}
|
|
430
|
-
return result;
|
|
422
|
+
const symbol = type.getSymbol();
|
|
423
|
+
const symbolName = symbol?.getName?.();
|
|
424
|
+
if (symbolName && symbolName !== "__type") {
|
|
425
|
+
return symbolName;
|
|
431
426
|
}
|
|
432
|
-
|
|
433
|
-
|
|
427
|
+
const nodeName = getExplicitTypeNameFromNode(typeNode);
|
|
428
|
+
if (nodeName && nodeName !== "__type") {
|
|
429
|
+
return nodeName;
|
|
434
430
|
}
|
|
435
|
-
return
|
|
431
|
+
return null;
|
|
436
432
|
}
|
|
437
|
-
function
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
return
|
|
433
|
+
function buildNamedSchema(type, ctx, typeNode, build) {
|
|
434
|
+
const name = getSchemaName(type, typeNode);
|
|
435
|
+
if (!name) {
|
|
436
|
+
return build();
|
|
441
437
|
}
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
438
|
+
const { components, typeStack } = ctx;
|
|
439
|
+
if (components.has(name) || typeStack.has(type)) {
|
|
440
|
+
return { $ref: `#/components/schemas/${name}` };
|
|
445
441
|
}
|
|
446
|
-
|
|
442
|
+
typeStack.add(type);
|
|
443
|
+
const schema = build();
|
|
444
|
+
typeStack.delete(type);
|
|
445
|
+
if (!components.has(name)) {
|
|
446
|
+
components.set(name, schema);
|
|
447
|
+
}
|
|
448
|
+
return { $ref: `#/components/schemas/${name}` };
|
|
449
|
+
}
|
|
450
|
+
function handleUnion(type, ctx, typeNode) {
|
|
451
|
+
return buildNamedSchema(type, ctx, typeNode, () => {
|
|
452
|
+
const types = type.types;
|
|
453
|
+
const nullType = types.find((t) => t.flags & import_typescript3.default.TypeFlags.Null);
|
|
454
|
+
const otherTypes = types.filter((t) => !(t.flags & import_typescript3.default.TypeFlags.Null) && !(t.flags & import_typescript3.default.TypeFlags.Undefined));
|
|
455
|
+
const allStringLiterals = otherTypes.every((t) => t.flags & import_typescript3.default.TypeFlags.StringLiteral);
|
|
456
|
+
if (allStringLiterals && otherTypes.length > 0) {
|
|
457
|
+
const enumValues = otherTypes.map((t) => t.value);
|
|
458
|
+
const schema = { type: "string", enum: enumValues };
|
|
459
|
+
if (nullType) {
|
|
460
|
+
schema.type = ["string", "null"];
|
|
461
|
+
}
|
|
462
|
+
return schema;
|
|
463
|
+
}
|
|
464
|
+
if (otherTypes.length === 1 && nullType) {
|
|
465
|
+
const innerSchema = typeToJsonSchema(otherTypes[0], ctx);
|
|
466
|
+
if (typeof innerSchema.type === "string") {
|
|
467
|
+
innerSchema.type = [innerSchema.type, "null"];
|
|
468
|
+
}
|
|
469
|
+
return innerSchema;
|
|
470
|
+
}
|
|
471
|
+
if (otherTypes.length > 1) {
|
|
472
|
+
const branches = otherTypes.map((t) => typeToJsonSchema(t, ctx));
|
|
473
|
+
const hasNull = !!nullType;
|
|
474
|
+
const result = {};
|
|
475
|
+
if (hasNull) {
|
|
476
|
+
result.anyOf = [...branches, { type: "null" }];
|
|
477
|
+
} else {
|
|
478
|
+
result.anyOf = branches;
|
|
479
|
+
}
|
|
480
|
+
const discriminatorResult = detectDiscriminatedUnion(otherTypes, ctx, branches);
|
|
481
|
+
if (discriminatorResult) {
|
|
482
|
+
result.oneOf = branches;
|
|
483
|
+
result.discriminator = discriminatorResult;
|
|
484
|
+
}
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
if (otherTypes.length === 1) {
|
|
488
|
+
return typeToJsonSchema(otherTypes[0], ctx);
|
|
489
|
+
}
|
|
490
|
+
return {};
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
function handleIntersection(type, ctx, typeNode) {
|
|
494
|
+
return buildNamedSchema(type, ctx, typeNode, () => {
|
|
495
|
+
const types = type.types;
|
|
496
|
+
const brandCollapsed = tryCollapseBrandedIntersection(types, ctx, typeNode);
|
|
497
|
+
if (brandCollapsed) {
|
|
498
|
+
return brandCollapsed;
|
|
499
|
+
}
|
|
500
|
+
const allOf = [];
|
|
501
|
+
for (const t of types) {
|
|
502
|
+
allOf.push(typeToJsonSchema(t, ctx));
|
|
503
|
+
}
|
|
504
|
+
return { allOf };
|
|
505
|
+
});
|
|
447
506
|
}
|
|
448
507
|
function tryCollapseBrandedIntersection(types, ctx, typeNode) {
|
|
449
508
|
const { checker } = ctx;
|
|
@@ -574,8 +633,8 @@ function handleObjectType(type, ctx, typeNode) {
|
|
|
574
633
|
typeStack.delete(type);
|
|
575
634
|
return schema;
|
|
576
635
|
}
|
|
577
|
-
function
|
|
578
|
-
if (!typeNode) return
|
|
636
|
+
function getExplicitTypeNameFromNode(typeNode) {
|
|
637
|
+
if (!typeNode) return null;
|
|
579
638
|
if (import_typescript3.default.isTypeReferenceNode(typeNode)) {
|
|
580
639
|
if (import_typescript3.default.isIdentifier(typeNode.typeName)) {
|
|
581
640
|
return typeNode.typeName.text;
|
|
@@ -586,6 +645,11 @@ function getTypeNameFromNode(typeNode, ctx) {
|
|
|
586
645
|
return typeNode.parent.name.text;
|
|
587
646
|
}
|
|
588
647
|
}
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
function getTypeNameFromNode(typeNode, ctx) {
|
|
651
|
+
const explicitName = getExplicitTypeNameFromNode(typeNode);
|
|
652
|
+
if (explicitName) return explicitName;
|
|
589
653
|
return `Anonymous_${ctx.typeNameStack.length}`;
|
|
590
654
|
}
|
|
591
655
|
function buildObjectSchema(type, ctx, typeNode) {
|
|
@@ -884,7 +948,7 @@ function buildOperation(operation, ctx, controllerConsumes) {
|
|
|
884
948
|
if (parameters.length > 0) {
|
|
885
949
|
op.parameters = parameters;
|
|
886
950
|
}
|
|
887
|
-
const responseSchema = typeToJsonSchema(operation.returnType, ctx);
|
|
951
|
+
const responseSchema = typeToJsonSchema(operation.returnType, ctx, operation.returnTypeNode);
|
|
888
952
|
const status = operation.httpMethod === "POST" ? 201 : 200;
|
|
889
953
|
op.responses[status] = {
|
|
890
954
|
description: status === 201 ? "Created" : "OK",
|
|
@@ -1102,7 +1166,8 @@ function buildOperationEntry(op, ctx) {
|
|
|
1102
1166
|
path: [],
|
|
1103
1167
|
query: [],
|
|
1104
1168
|
headers: [],
|
|
1105
|
-
cookies: []
|
|
1169
|
+
cookies: [],
|
|
1170
|
+
paginationParamIndex: op.paginationParamIndex
|
|
1106
1171
|
};
|
|
1107
1172
|
buildPathArgs(op, ctx, args);
|
|
1108
1173
|
buildQueryArgs(op, ctx, args);
|
|
@@ -1121,7 +1186,7 @@ function buildOperationEntry(op, ctx) {
|
|
|
1121
1186
|
};
|
|
1122
1187
|
}
|
|
1123
1188
|
}
|
|
1124
|
-
const responseSchema = typeToJsonSchema(op.returnType, ctx);
|
|
1189
|
+
const responseSchema = typeToJsonSchema(op.returnType, ctx, op.returnTypeNode);
|
|
1125
1190
|
const status = op.httpMethod === "POST" ? 201 : 200;
|
|
1126
1191
|
let schemaRef = responseSchema.$ref;
|
|
1127
1192
|
let isArray = false;
|