adorn-api 1.0.12 → 1.0.14

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.
Files changed (171) hide show
  1. package/dist/adapter/express/auth.d.ts +8 -0
  2. package/dist/adapter/express/auth.d.ts.map +1 -1
  3. package/dist/adapter/express/bootstrap.d.ts +12 -0
  4. package/dist/adapter/express/bootstrap.d.ts.map +1 -1
  5. package/dist/adapter/express/coercion.d.ts +81 -1
  6. package/dist/adapter/express/coercion.d.ts.map +1 -1
  7. package/dist/adapter/express/index.d.ts +1 -0
  8. package/dist/adapter/express/index.d.ts.map +1 -1
  9. package/dist/adapter/express/merge.d.ts +17 -0
  10. package/dist/adapter/express/merge.d.ts.map +1 -1
  11. package/dist/adapter/express/openapi.d.ts +55 -0
  12. package/dist/adapter/express/openapi.d.ts.map +1 -1
  13. package/dist/adapter/express/router.d.ts +6 -0
  14. package/dist/adapter/express/router.d.ts.map +1 -1
  15. package/dist/adapter/express/swagger.d.ts +6 -0
  16. package/dist/adapter/express/swagger.d.ts.map +1 -1
  17. package/dist/adapter/express/types.d.ts +26 -0
  18. package/dist/adapter/express/types.d.ts.map +1 -1
  19. package/dist/adapter/express/validation.d.ts +19 -2
  20. package/dist/adapter/express/validation.d.ts.map +1 -1
  21. package/dist/cli.cjs +1016 -445
  22. package/dist/cli.cjs.map +1 -1
  23. package/dist/cli.js +1016 -445
  24. package/dist/cli.js.map +1 -1
  25. package/dist/compiler/analyze/index.d.ts +5 -0
  26. package/dist/compiler/analyze/index.d.ts.map +1 -0
  27. package/dist/compiler/analyze/scanControllers.d.ts +52 -0
  28. package/dist/compiler/analyze/scanControllers.d.ts.map +1 -1
  29. package/dist/compiler/cache/isStale.d.ts +26 -0
  30. package/dist/compiler/cache/isStale.d.ts.map +1 -1
  31. package/dist/compiler/cache/loadArtifacts.d.ts +36 -0
  32. package/dist/compiler/cache/loadArtifacts.d.ts.map +1 -1
  33. package/dist/compiler/cache/schema.d.ts +14 -0
  34. package/dist/compiler/cache/schema.d.ts.map +1 -1
  35. package/dist/compiler/cache/writeCache.d.ts +6 -0
  36. package/dist/compiler/cache/writeCache.d.ts.map +1 -1
  37. package/dist/compiler/gems.d.ts +75 -0
  38. package/dist/compiler/gems.d.ts.map +1 -0
  39. package/dist/compiler/generator/index.d.ts +7 -0
  40. package/dist/compiler/generator/index.d.ts.map +1 -0
  41. package/dist/compiler/generator/manifest.d.ts +23 -0
  42. package/dist/compiler/generator/manifest.d.ts.map +1 -0
  43. package/dist/compiler/generator/openapi.d.ts +118 -0
  44. package/dist/compiler/generator/openapi.d.ts.map +1 -0
  45. package/dist/compiler/graph/builder.d.ts +24 -0
  46. package/dist/compiler/graph/builder.d.ts.map +1 -0
  47. package/dist/compiler/graph/index.d.ts +7 -0
  48. package/dist/compiler/graph/index.d.ts.map +1 -0
  49. package/dist/compiler/graph/schemaGraph.d.ts +67 -0
  50. package/dist/compiler/graph/schemaGraph.d.ts.map +1 -0
  51. package/dist/compiler/graph/types.d.ts +203 -0
  52. package/dist/compiler/graph/types.d.ts.map +1 -0
  53. package/dist/compiler/index.d.ts +12 -0
  54. package/dist/compiler/index.d.ts.map +1 -0
  55. package/dist/compiler/ir/index.d.ts +7 -0
  56. package/dist/compiler/ir/index.d.ts.map +1 -0
  57. package/dist/compiler/ir/pipeline.d.ts +82 -0
  58. package/dist/compiler/ir/pipeline.d.ts.map +1 -0
  59. package/dist/compiler/ir/stages.d.ts +40 -0
  60. package/dist/compiler/ir/stages.d.ts.map +1 -0
  61. package/dist/compiler/ir/visitor.d.ts +98 -0
  62. package/dist/compiler/ir/visitor.d.ts.map +1 -0
  63. package/dist/compiler/manifest/emit.d.ts +14 -0
  64. package/dist/compiler/manifest/emit.d.ts.map +1 -1
  65. package/dist/compiler/manifest/format.d.ts +42 -0
  66. package/dist/compiler/manifest/format.d.ts.map +1 -1
  67. package/dist/compiler/manifest/index.d.ts +6 -0
  68. package/dist/compiler/manifest/index.d.ts.map +1 -0
  69. package/dist/compiler/runner/createProgram.d.ts +16 -0
  70. package/dist/compiler/runner/createProgram.d.ts.map +1 -1
  71. package/dist/compiler/runner/index.d.ts +5 -0
  72. package/dist/compiler/runner/index.d.ts.map +1 -0
  73. package/dist/compiler/schema/extractAnnotations.d.ts +47 -0
  74. package/dist/compiler/schema/extractAnnotations.d.ts.map +1 -1
  75. package/dist/compiler/schema/index.d.ts +6 -0
  76. package/dist/compiler/schema/index.d.ts.map +1 -0
  77. package/dist/compiler/schema/intersectionHandler.d.ts +44 -0
  78. package/dist/compiler/schema/intersectionHandler.d.ts.map +1 -0
  79. package/dist/compiler/schema/objectHandler.d.ts +106 -0
  80. package/dist/compiler/schema/objectHandler.d.ts.map +1 -0
  81. package/dist/compiler/schema/openapi.d.ts +16 -1
  82. package/dist/compiler/schema/openapi.d.ts.map +1 -1
  83. package/dist/compiler/schema/parameters.d.ts +90 -0
  84. package/dist/compiler/schema/parameters.d.ts.map +1 -0
  85. package/dist/compiler/schema/primitives.d.ts +68 -0
  86. package/dist/compiler/schema/primitives.d.ts.map +1 -0
  87. package/dist/compiler/schema/typeToJsonSchema.d.ts +22 -51
  88. package/dist/compiler/schema/typeToJsonSchema.d.ts.map +1 -1
  89. package/dist/compiler/schema/types.d.ts +69 -0
  90. package/dist/compiler/schema/types.d.ts.map +1 -0
  91. package/dist/compiler/schema/unionHandler.d.ts +70 -0
  92. package/dist/compiler/schema/unionHandler.d.ts.map +1 -0
  93. package/dist/compiler/transform/dedup.d.ts +35 -0
  94. package/dist/compiler/transform/dedup.d.ts.map +1 -0
  95. package/dist/compiler/transform/flatten.d.ts +50 -0
  96. package/dist/compiler/transform/flatten.d.ts.map +1 -0
  97. package/dist/compiler/transform/index.d.ts +7 -0
  98. package/dist/compiler/transform/index.d.ts.map +1 -0
  99. package/dist/compiler/transform/inline.d.ts +46 -0
  100. package/dist/compiler/transform/inline.d.ts.map +1 -0
  101. package/dist/compiler/validation/emitPrecompiledValidators.d.ts +16 -0
  102. package/dist/compiler/validation/emitPrecompiledValidators.d.ts.map +1 -1
  103. package/dist/compiler/validation/index.d.ts +5 -0
  104. package/dist/compiler/validation/index.d.ts.map +1 -0
  105. package/dist/decorators/Auth.d.ts +17 -0
  106. package/dist/decorators/Auth.d.ts.map +1 -1
  107. package/dist/decorators/Controller.d.ts +15 -0
  108. package/dist/decorators/Controller.d.ts.map +1 -1
  109. package/dist/decorators/Public.d.ts +13 -0
  110. package/dist/decorators/Public.d.ts.map +1 -1
  111. package/dist/decorators/Use.d.ts +18 -0
  112. package/dist/decorators/Use.d.ts.map +1 -1
  113. package/dist/decorators/methods.d.ts +20 -0
  114. package/dist/decorators/methods.d.ts.map +1 -1
  115. package/dist/express.cjs +73 -54
  116. package/dist/express.cjs.map +1 -1
  117. package/dist/express.js +73 -54
  118. package/dist/express.js.map +1 -1
  119. package/dist/http.d.ts +1 -2
  120. package/dist/http.d.ts.map +1 -1
  121. package/dist/index.cjs +161 -4
  122. package/dist/index.cjs.map +1 -1
  123. package/dist/index.d.ts +2 -0
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +156 -3
  126. package/dist/index.js.map +1 -1
  127. package/dist/metal/applyListQuery.d.ts +73 -0
  128. package/dist/metal/applyListQuery.d.ts.map +1 -1
  129. package/dist/metal/index.cjs +2 -2
  130. package/dist/metal/index.cjs.map +1 -1
  131. package/dist/metal/index.d.ts +4 -0
  132. package/dist/metal/index.d.ts.map +1 -1
  133. package/dist/metal/index.js +2 -2
  134. package/dist/metal/index.js.map +1 -1
  135. package/dist/metal/listQuery.d.ts +19 -0
  136. package/dist/metal/listQuery.d.ts.map +1 -1
  137. package/dist/metal/queryOptions.d.ts +8 -0
  138. package/dist/metal/queryOptions.d.ts.map +1 -1
  139. package/dist/metal/readMetalBag.d.ts +36 -0
  140. package/dist/metal/readMetalBag.d.ts.map +1 -1
  141. package/dist/metal/registerMetalEntities.d.ts +20 -0
  142. package/dist/metal/registerMetalEntities.d.ts.map +1 -1
  143. package/dist/metal/schemaFromEntity.d.ts +30 -0
  144. package/dist/metal/schemaFromEntity.d.ts.map +1 -1
  145. package/dist/metal/searchWhere.d.ts +39 -0
  146. package/dist/metal/searchWhere.d.ts.map +1 -1
  147. package/dist/metal/symbolMetadata.d.ts +6 -0
  148. package/dist/metal/symbolMetadata.d.ts.map +1 -1
  149. package/dist/runtime/auth/runtime.d.ts +155 -6
  150. package/dist/runtime/auth/runtime.d.ts.map +1 -1
  151. package/dist/runtime/metadata/bucket.d.ts +1 -2
  152. package/dist/runtime/metadata/bucket.d.ts.map +1 -1
  153. package/dist/runtime/metadata/key.d.ts +1 -1
  154. package/dist/runtime/metadata/key.d.ts.map +1 -1
  155. package/dist/runtime/metadata/read.d.ts +1 -2
  156. package/dist/runtime/metadata/read.d.ts.map +1 -1
  157. package/dist/runtime/metadata/types.d.ts +74 -0
  158. package/dist/runtime/metadata/types.d.ts.map +1 -1
  159. package/dist/runtime/polyfill.d.ts +1 -1
  160. package/dist/runtime/polyfill.d.ts.map +1 -1
  161. package/dist/runtime/upload.d.ts +37 -0
  162. package/dist/runtime/upload.d.ts.map +1 -1
  163. package/dist/runtime/validation/ajv.d.ts +100 -0
  164. package/dist/runtime/validation/ajv.d.ts.map +1 -1
  165. package/dist/runtime/validation/index.d.ts +9 -0
  166. package/dist/runtime/validation/index.d.ts.map +1 -1
  167. package/dist/scripts/adorn-example.cjs +238 -6
  168. package/dist/scripts/adorn-example.cjs.map +1 -1
  169. package/dist/utils/port.d.ts +9 -0
  170. package/dist/utils/port.d.ts.map +1 -0
  171. package/package.json +4 -1
package/dist/express.cjs CHANGED
@@ -167,11 +167,25 @@ function computeBoundRoutes(controllers, manifest) {
167
167
  var import_ajv = __toESM(require("ajv"), 1);
168
168
  var import_ajv_formats = __toESM(require("ajv-formats"), 1);
169
169
  var ValidationErrorResponse = class extends Error {
170
+ /**
171
+ * HTTP status code for validation errors.
172
+ */
173
+ statusCode;
174
+ /**
175
+ * Detailed validation errors.
176
+ */
177
+ errors;
178
+ /**
179
+ * Creates a new ValidationErrorResponse.
180
+ *
181
+ * @param statusCode - HTTP status code (typically 400)
182
+ * @param errors - Array of validation errors
183
+ */
170
184
  constructor(statusCode, errors) {
171
185
  super("Validation failed");
186
+ this.name = "ValidationErrorResponse";
172
187
  this.statusCode = statusCode;
173
188
  this.errors = errors;
174
- this.name = "ValidationErrorResponse";
175
189
  }
176
190
  };
177
191
  function createValidator() {
@@ -216,7 +230,7 @@ async function getMtime(filePath) {
216
230
  async function loadArtifacts(options) {
217
231
  const { outDir } = options;
218
232
  const cacheKey = import_node_path.default.resolve(outDir);
219
- let entry = artifactCache.get(cacheKey);
233
+ const entry = artifactCache.get(cacheKey);
220
234
  const openapiPath = import_node_path.default.join(outDir, "openapi.json");
221
235
  const manifestPath = import_node_path.default.join(outDir, "manifest.json");
222
236
  const validatorsPath = import_node_path.default.join(outDir, "validators.mjs");
@@ -477,13 +491,16 @@ function getRawQueryString(req) {
477
491
  if (index === -1) return "";
478
492
  return url.slice(index + 1);
479
493
  }
480
- function parseDeepObjectParams(rawQuery, names) {
494
+ function parseDeepObjectParams(rawQuery, names, maxDepth = 5) {
481
495
  const out = {};
482
496
  if (!rawQuery || names.size === 0) return out;
483
497
  const params = new URLSearchParams(rawQuery);
484
498
  for (const [key, value] of params.entries()) {
485
499
  const path3 = parseBracketPath(key);
486
500
  if (path3.length === 0) continue;
501
+ if (path3.length > maxDepth) {
502
+ throw new Error(`Query parameter nesting depth (${path3.length}) exceeds maximum of ${maxDepth}`);
503
+ }
487
504
  const root = path3[0];
488
505
  if (!names.has(root)) continue;
489
506
  assignDeepValue(out, path3, value);
@@ -596,10 +613,10 @@ function createAuthMiddleware(authConfig, routeAuth, globalSecurity) {
596
613
  }
597
614
 
598
615
  // src/adapter/express/validation.ts
599
- function validateRequestWithPrecompiled(route, req, validators) {
616
+ function validateRequestWithPrecompiled(route, req, validators, maxDepth = 5) {
600
617
  const errors = [];
601
618
  const deepNames = new Set(route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name));
602
- const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames) : {};
619
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
603
620
  if (route.args.body) {
604
621
  const validator = validators[route.operationId]?.body;
605
622
  if (validator) {
@@ -622,10 +639,10 @@ function validateRequestWithPrecompiled(route, req, validators) {
622
639
  if (q.content === "application/json" && typeof value === "string") {
623
640
  try {
624
641
  value = JSON.parse(value);
625
- } catch (e) {
642
+ } catch {
626
643
  errors.push({
627
644
  path: `#/query/${q.name}`,
628
- message: `Invalid JSON string`,
645
+ message: "Invalid JSON string",
629
646
  keyword: "json",
630
647
  params: {}
631
648
  });
@@ -635,11 +652,11 @@ function validateRequestWithPrecompiled(route, req, validators) {
635
652
  }
636
653
  return errors.length > 0 ? errors : null;
637
654
  }
638
- function validateRequest(route, req, openapi, validator) {
655
+ function validateRequest(route, req, openapi, validator, maxDepth = 5) {
639
656
  const openapiOperation = getOpenApiOperation(openapi, route);
640
657
  const paramSchemaIndex = getParamSchemaIndex(openapiOperation);
641
658
  const deepNames = new Set(route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name));
642
- const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames) : {};
659
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
643
660
  const errors = [];
644
661
  if (route.args.body) {
645
662
  const bodySchema = getSchemaByRef(openapi, route.args.body.schemaRef);
@@ -663,10 +680,10 @@ function validateRequest(route, req, openapi, validator) {
663
680
  if (q.content === "application/json" && typeof value === "string") {
664
681
  try {
665
682
  value = JSON.parse(value);
666
- } catch (e) {
683
+ } catch {
667
684
  errors.push({
668
685
  path: `#/query/${q.name}`,
669
- message: `Invalid JSON string`,
686
+ message: "Invalid JSON string",
670
687
  keyword: "json",
671
688
  params: {}
672
689
  });
@@ -744,7 +761,7 @@ function validateRequest(route, req, openapi, validator) {
744
761
 
745
762
  // src/adapter/express/router.ts
746
763
  async function createExpressRouter(options) {
747
- const { controllers, artifactsDir = ".adorn", middleware = {}, defaultPageSize = 10 } = options;
764
+ const { controllers, artifactsDir = ".adorn", middleware = {}, defaultPageSize = 10, queryOptions } = options;
748
765
  let manifest;
749
766
  let openapi;
750
767
  let precompiledValidators = null;
@@ -814,10 +831,15 @@ async function createExpressRouter(options) {
814
831
  }
815
832
  router[method](route.fullPath, ...middlewareChain, async (req, res, next) => {
816
833
  try {
817
- const validationErrors = precompiledValidators ? validateRequestWithPrecompiled(route, req, precompiledValidators) : validateRequest(route, req, openapi, validator);
834
+ const maxDepth = queryOptions?.maxNestingDepth ?? 5;
835
+ const validationErrors = precompiledValidators ? validateRequestWithPrecompiled(route, req, precompiledValidators, maxDepth) : validateRequest(route, req, openapi, validator, maxDepth);
818
836
  if (validationErrors) {
819
837
  return res.status(400).json(formatValidationErrors(validationErrors));
820
838
  }
839
+ const deepNames = new Set(
840
+ route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name)
841
+ );
842
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
821
843
  const instance = getInstance(route.controllerCtor);
822
844
  const handler = instance[route.methodName];
823
845
  if (typeof handler !== "function") {
@@ -843,13 +865,13 @@ async function createExpressRouter(options) {
843
865
  }
844
866
  if (jsonArgs.length > 0) {
845
867
  for (const q of jsonArgs) {
846
- const rawValue = req.query[q.name];
868
+ const rawValue = q.serialization?.style === "deepObject" ? deepValues[q.name] : req.query[q.name];
847
869
  if (rawValue === void 0 || rawValue === null) continue;
848
870
  let parsed = rawValue;
849
871
  if (typeof rawValue === "string" && rawValue.length > 0) {
850
872
  try {
851
873
  parsed = JSON.parse(rawValue);
852
- } catch (e) {
874
+ } catch {
853
875
  parsed = rawValue;
854
876
  }
855
877
  }
@@ -863,7 +885,7 @@ async function createExpressRouter(options) {
863
885
  }
864
886
  if (standardArgs.length > 0) {
865
887
  for (const q of standardArgs) {
866
- const rawValue = req.query[q.name];
888
+ const rawValue = q.serialization?.style === "deepObject" ? deepValues[q.name] : req.query[q.name];
867
889
  if (rawValue === void 0) continue;
868
890
  const parsed = parseQueryValue(rawValue, q);
869
891
  const paramSchema = getParamSchemaFromIndex(paramSchemaIndex, "query", q.name) ?? (q.schemaRef ? getSchemaByRef(openapi, q.schemaRef) : null) ?? schemaFromType(q.schemaType);
@@ -975,41 +997,40 @@ function setupSwagger(options = {}) {
975
997
  var import_express3 = __toESM(require("express"), 1);
976
998
  var import_node_path4 = __toESM(require("path"), 1);
977
999
  function bootstrap(options) {
978
- return new Promise(async (resolve2, reject) => {
979
- try {
980
- const {
981
- controllers,
982
- port: userPort,
983
- host: userHost,
984
- artifactsDir: userArtifactsDir = ".adorn",
985
- enableSwagger = true,
986
- swaggerPath = "/docs",
987
- swaggerJsonPath = "/docs/openapi.json",
988
- middleware,
989
- auth,
990
- coerce
991
- } = options;
992
- if (controllers.length === 0) {
993
- reject(new Error("At least one controller must be provided to bootstrap()."));
994
- return;
995
- }
996
- const envPort = process.env.PORT;
997
- const port = userPort ?? (envPort !== void 0 ? Number(envPort) : 3e3);
998
- const host = userHost ?? process.env.HOST ?? "0.0.0.0";
999
- if (isNaN(port) || port < 0 || port > 65535) {
1000
- reject(new Error(`Invalid port: ${port}. Port must be between 0 and 65535.`));
1001
- return;
1002
- }
1003
- const absoluteArtifactsDir = import_node_path4.default.isAbsolute(userArtifactsDir) ? userArtifactsDir : import_node_path4.default.resolve(process.cwd(), userArtifactsDir);
1004
- const app = (0, import_express3.default)();
1005
- app.use(import_express3.default.json());
1006
- const router = await createExpressRouter({
1007
- controllers,
1008
- artifactsDir: absoluteArtifactsDir,
1009
- middleware,
1010
- auth,
1011
- coerce
1012
- });
1000
+ return new Promise((resolve2, reject) => {
1001
+ const {
1002
+ controllers,
1003
+ port: userPort,
1004
+ host: userHost,
1005
+ artifactsDir: userArtifactsDir = ".adorn",
1006
+ enableSwagger = true,
1007
+ swaggerPath = "/docs",
1008
+ swaggerJsonPath = "/docs/openapi.json",
1009
+ middleware,
1010
+ auth,
1011
+ coerce
1012
+ } = options;
1013
+ if (controllers.length === 0) {
1014
+ reject(new Error("At least one controller must be provided to bootstrap()."));
1015
+ return;
1016
+ }
1017
+ const envPort = process.env.PORT;
1018
+ const port = userPort ?? (envPort !== void 0 ? Number(envPort) : 3e3);
1019
+ const host = userHost ?? process.env.HOST ?? "0.0.0.0";
1020
+ if (isNaN(port) || port < 0 || port > 65535) {
1021
+ reject(new Error(`Invalid port: ${port}. Port must be between 0 and 65535.`));
1022
+ return;
1023
+ }
1024
+ const absoluteArtifactsDir = import_node_path4.default.isAbsolute(userArtifactsDir) ? userArtifactsDir : import_node_path4.default.resolve(process.cwd(), userArtifactsDir);
1025
+ const app = (0, import_express3.default)();
1026
+ app.use(import_express3.default.json());
1027
+ createExpressRouter({
1028
+ controllers,
1029
+ artifactsDir: absoluteArtifactsDir,
1030
+ middleware,
1031
+ auth,
1032
+ coerce
1033
+ }).then((router) => {
1013
1034
  app.use(router);
1014
1035
  if (enableSwagger) {
1015
1036
  const displayHost = host === "0.0.0.0" ? "localhost" : host;
@@ -1056,9 +1077,7 @@ function bootstrap(options) {
1056
1077
  reject(new Error(`Failed to start server: ${error.message}`));
1057
1078
  }
1058
1079
  });
1059
- } catch (error) {
1060
- reject(error);
1061
- }
1080
+ }).catch(reject);
1062
1081
  });
1063
1082
  }
1064
1083
  // Annotate the CommonJS export names for ESM import in node: