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.js CHANGED
@@ -132,11 +132,25 @@ function computeBoundRoutes(controllers, manifest) {
132
132
  import Ajv from "ajv";
133
133
  import addFormats from "ajv-formats";
134
134
  var ValidationErrorResponse = class extends Error {
135
+ /**
136
+ * HTTP status code for validation errors.
137
+ */
138
+ statusCode;
139
+ /**
140
+ * Detailed validation errors.
141
+ */
142
+ errors;
143
+ /**
144
+ * Creates a new ValidationErrorResponse.
145
+ *
146
+ * @param statusCode - HTTP status code (typically 400)
147
+ * @param errors - Array of validation errors
148
+ */
135
149
  constructor(statusCode, errors) {
136
150
  super("Validation failed");
151
+ this.name = "ValidationErrorResponse";
137
152
  this.statusCode = statusCode;
138
153
  this.errors = errors;
139
- this.name = "ValidationErrorResponse";
140
154
  }
141
155
  };
142
156
  function createValidator() {
@@ -181,7 +195,7 @@ async function getMtime(filePath) {
181
195
  async function loadArtifacts(options) {
182
196
  const { outDir } = options;
183
197
  const cacheKey = path.resolve(outDir);
184
- let entry = artifactCache.get(cacheKey);
198
+ const entry = artifactCache.get(cacheKey);
185
199
  const openapiPath = path.join(outDir, "openapi.json");
186
200
  const manifestPath = path.join(outDir, "manifest.json");
187
201
  const validatorsPath = path.join(outDir, "validators.mjs");
@@ -442,13 +456,16 @@ function getRawQueryString(req) {
442
456
  if (index === -1) return "";
443
457
  return url.slice(index + 1);
444
458
  }
445
- function parseDeepObjectParams(rawQuery, names) {
459
+ function parseDeepObjectParams(rawQuery, names, maxDepth = 5) {
446
460
  const out = {};
447
461
  if (!rawQuery || names.size === 0) return out;
448
462
  const params = new URLSearchParams(rawQuery);
449
463
  for (const [key, value] of params.entries()) {
450
464
  const path3 = parseBracketPath(key);
451
465
  if (path3.length === 0) continue;
466
+ if (path3.length > maxDepth) {
467
+ throw new Error(`Query parameter nesting depth (${path3.length}) exceeds maximum of ${maxDepth}`);
468
+ }
452
469
  const root = path3[0];
453
470
  if (!names.has(root)) continue;
454
471
  assignDeepValue(out, path3, value);
@@ -561,10 +578,10 @@ function createAuthMiddleware(authConfig, routeAuth, globalSecurity) {
561
578
  }
562
579
 
563
580
  // src/adapter/express/validation.ts
564
- function validateRequestWithPrecompiled(route, req, validators) {
581
+ function validateRequestWithPrecompiled(route, req, validators, maxDepth = 5) {
565
582
  const errors = [];
566
583
  const deepNames = new Set(route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name));
567
- const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames) : {};
584
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
568
585
  if (route.args.body) {
569
586
  const validator = validators[route.operationId]?.body;
570
587
  if (validator) {
@@ -587,10 +604,10 @@ function validateRequestWithPrecompiled(route, req, validators) {
587
604
  if (q.content === "application/json" && typeof value === "string") {
588
605
  try {
589
606
  value = JSON.parse(value);
590
- } catch (e) {
607
+ } catch {
591
608
  errors.push({
592
609
  path: `#/query/${q.name}`,
593
- message: `Invalid JSON string`,
610
+ message: "Invalid JSON string",
594
611
  keyword: "json",
595
612
  params: {}
596
613
  });
@@ -600,11 +617,11 @@ function validateRequestWithPrecompiled(route, req, validators) {
600
617
  }
601
618
  return errors.length > 0 ? errors : null;
602
619
  }
603
- function validateRequest(route, req, openapi, validator) {
620
+ function validateRequest(route, req, openapi, validator, maxDepth = 5) {
604
621
  const openapiOperation = getOpenApiOperation(openapi, route);
605
622
  const paramSchemaIndex = getParamSchemaIndex(openapiOperation);
606
623
  const deepNames = new Set(route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name));
607
- const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames) : {};
624
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
608
625
  const errors = [];
609
626
  if (route.args.body) {
610
627
  const bodySchema = getSchemaByRef(openapi, route.args.body.schemaRef);
@@ -628,10 +645,10 @@ function validateRequest(route, req, openapi, validator) {
628
645
  if (q.content === "application/json" && typeof value === "string") {
629
646
  try {
630
647
  value = JSON.parse(value);
631
- } catch (e) {
648
+ } catch {
632
649
  errors.push({
633
650
  path: `#/query/${q.name}`,
634
- message: `Invalid JSON string`,
651
+ message: "Invalid JSON string",
635
652
  keyword: "json",
636
653
  params: {}
637
654
  });
@@ -709,7 +726,7 @@ function validateRequest(route, req, openapi, validator) {
709
726
 
710
727
  // src/adapter/express/router.ts
711
728
  async function createExpressRouter(options) {
712
- const { controllers, artifactsDir = ".adorn", middleware = {}, defaultPageSize = 10 } = options;
729
+ const { controllers, artifactsDir = ".adorn", middleware = {}, defaultPageSize = 10, queryOptions } = options;
713
730
  let manifest;
714
731
  let openapi;
715
732
  let precompiledValidators = null;
@@ -779,10 +796,15 @@ async function createExpressRouter(options) {
779
796
  }
780
797
  router[method](route.fullPath, ...middlewareChain, async (req, res, next) => {
781
798
  try {
782
- const validationErrors = precompiledValidators ? validateRequestWithPrecompiled(route, req, precompiledValidators) : validateRequest(route, req, openapi, validator);
799
+ const maxDepth = queryOptions?.maxNestingDepth ?? 5;
800
+ const validationErrors = precompiledValidators ? validateRequestWithPrecompiled(route, req, precompiledValidators, maxDepth) : validateRequest(route, req, openapi, validator, maxDepth);
783
801
  if (validationErrors) {
784
802
  return res.status(400).json(formatValidationErrors(validationErrors));
785
803
  }
804
+ const deepNames = new Set(
805
+ route.args.query.filter((q) => q.serialization?.style === "deepObject").map((q) => q.name)
806
+ );
807
+ const deepValues = deepNames.size > 0 ? parseDeepObjectParams(getRawQueryString(req), deepNames, maxDepth) : {};
786
808
  const instance = getInstance(route.controllerCtor);
787
809
  const handler = instance[route.methodName];
788
810
  if (typeof handler !== "function") {
@@ -808,13 +830,13 @@ async function createExpressRouter(options) {
808
830
  }
809
831
  if (jsonArgs.length > 0) {
810
832
  for (const q of jsonArgs) {
811
- const rawValue = req.query[q.name];
833
+ const rawValue = q.serialization?.style === "deepObject" ? deepValues[q.name] : req.query[q.name];
812
834
  if (rawValue === void 0 || rawValue === null) continue;
813
835
  let parsed = rawValue;
814
836
  if (typeof rawValue === "string" && rawValue.length > 0) {
815
837
  try {
816
838
  parsed = JSON.parse(rawValue);
817
- } catch (e) {
839
+ } catch {
818
840
  parsed = rawValue;
819
841
  }
820
842
  }
@@ -828,7 +850,7 @@ async function createExpressRouter(options) {
828
850
  }
829
851
  if (standardArgs.length > 0) {
830
852
  for (const q of standardArgs) {
831
- const rawValue = req.query[q.name];
853
+ const rawValue = q.serialization?.style === "deepObject" ? deepValues[q.name] : req.query[q.name];
832
854
  if (rawValue === void 0) continue;
833
855
  const parsed = parseQueryValue(rawValue, q);
834
856
  const paramSchema = getParamSchemaFromIndex(paramSchemaIndex, "query", q.name) ?? (q.schemaRef ? getSchemaByRef(openapi, q.schemaRef) : null) ?? schemaFromType(q.schemaType);
@@ -940,41 +962,40 @@ function setupSwagger(options = {}) {
940
962
  import express from "express";
941
963
  import path2 from "path";
942
964
  function bootstrap(options) {
943
- return new Promise(async (resolve2, reject) => {
944
- try {
945
- const {
946
- controllers,
947
- port: userPort,
948
- host: userHost,
949
- artifactsDir: userArtifactsDir = ".adorn",
950
- enableSwagger = true,
951
- swaggerPath = "/docs",
952
- swaggerJsonPath = "/docs/openapi.json",
953
- middleware,
954
- auth,
955
- coerce
956
- } = options;
957
- if (controllers.length === 0) {
958
- reject(new Error("At least one controller must be provided to bootstrap()."));
959
- return;
960
- }
961
- const envPort = process.env.PORT;
962
- const port = userPort ?? (envPort !== void 0 ? Number(envPort) : 3e3);
963
- const host = userHost ?? process.env.HOST ?? "0.0.0.0";
964
- if (isNaN(port) || port < 0 || port > 65535) {
965
- reject(new Error(`Invalid port: ${port}. Port must be between 0 and 65535.`));
966
- return;
967
- }
968
- const absoluteArtifactsDir = path2.isAbsolute(userArtifactsDir) ? userArtifactsDir : path2.resolve(process.cwd(), userArtifactsDir);
969
- const app = express();
970
- app.use(express.json());
971
- const router = await createExpressRouter({
972
- controllers,
973
- artifactsDir: absoluteArtifactsDir,
974
- middleware,
975
- auth,
976
- coerce
977
- });
965
+ return new Promise((resolve2, reject) => {
966
+ const {
967
+ controllers,
968
+ port: userPort,
969
+ host: userHost,
970
+ artifactsDir: userArtifactsDir = ".adorn",
971
+ enableSwagger = true,
972
+ swaggerPath = "/docs",
973
+ swaggerJsonPath = "/docs/openapi.json",
974
+ middleware,
975
+ auth,
976
+ coerce
977
+ } = options;
978
+ if (controllers.length === 0) {
979
+ reject(new Error("At least one controller must be provided to bootstrap()."));
980
+ return;
981
+ }
982
+ const envPort = process.env.PORT;
983
+ const port = userPort ?? (envPort !== void 0 ? Number(envPort) : 3e3);
984
+ const host = userHost ?? process.env.HOST ?? "0.0.0.0";
985
+ if (isNaN(port) || port < 0 || port > 65535) {
986
+ reject(new Error(`Invalid port: ${port}. Port must be between 0 and 65535.`));
987
+ return;
988
+ }
989
+ const absoluteArtifactsDir = path2.isAbsolute(userArtifactsDir) ? userArtifactsDir : path2.resolve(process.cwd(), userArtifactsDir);
990
+ const app = express();
991
+ app.use(express.json());
992
+ createExpressRouter({
993
+ controllers,
994
+ artifactsDir: absoluteArtifactsDir,
995
+ middleware,
996
+ auth,
997
+ coerce
998
+ }).then((router) => {
978
999
  app.use(router);
979
1000
  if (enableSwagger) {
980
1001
  const displayHost = host === "0.0.0.0" ? "localhost" : host;
@@ -1021,9 +1042,7 @@ function bootstrap(options) {
1021
1042
  reject(new Error(`Failed to start server: ${error.message}`));
1022
1043
  }
1023
1044
  });
1024
- } catch (error) {
1025
- reject(error);
1026
- }
1045
+ }).catch(reject);
1027
1046
  });
1028
1047
  }
1029
1048
  export {