@aeriajs/http 0.0.174 → 0.0.176

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/routing.js CHANGED
@@ -2,23 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRouter = exports.wrapRouteExecution = exports.registerRoute = exports.matches = void 0;
4
4
  const node_stream_1 = require("node:stream");
5
+ const mongodb_1 = require("mongodb");
5
6
  const types_1 = require("@aeriajs/types");
6
7
  const common_1 = require("@aeriajs/common");
7
8
  const validation_1 = require("@aeriajs/validation");
8
9
  const entrypoint_1 = require("@aeriajs/entrypoint");
9
10
  const payload_js_1 = require("./payload.js");
10
- const checkUnprocessable = (what, schema, context, validateOptions = {}) => {
11
+ const checkUnprocessable = async (what, schema, context, validateOptions = {}) => {
11
12
  let result;
12
13
  if (Array.isArray(schema)) {
13
14
  for (const property of schema) {
14
- result = (0, validation_1.validate)(what, property, validateOptions);
15
+ result = await (0, validation_1.validateWithRefs)(what, property, validateOptions);
15
16
  if (!result.error) {
16
17
  break;
17
18
  }
18
19
  }
19
20
  }
20
21
  else {
21
- result = (0, validation_1.validate)(what, schema, validateOptions);
22
+ result = await (0, validation_1.validateWithRefs)(what, schema, validateOptions);
22
23
  }
23
24
  const { error, result: validated } = result;
24
25
  if (error) {
@@ -94,14 +95,21 @@ const registerRoute = async (context, method, exp, cb, contract, options = {}) =
94
95
  }
95
96
  }
96
97
  if ('payload' in contract && contract.payload) {
97
- const { error } = checkUnprocessable(context.request.payload, contract.payload, context);
98
+ const { error } = await checkUnprocessable(context.request.payload, contract.payload, context, {
99
+ checkObjectIds: true,
100
+ context,
101
+ objectIdConstructor: mongodb_1.ObjectId,
102
+ });
98
103
  if (error) {
99
104
  return types_1.Result.error(error);
100
105
  }
101
106
  }
102
107
  if ('query' in contract && contract.query) {
103
- const { error, result: validated } = checkUnprocessable(context.request.query, contract.query, context, {
108
+ const { error, result: validated } = await checkUnprocessable(context.request.query, contract.query, context, {
109
+ checkObjectIds: true,
104
110
  coerce: true,
111
+ context,
112
+ objectIdConstructor: mongodb_1.ObjectId,
105
113
  });
106
114
  if (error) {
107
115
  return types_1.Result.error(error);
package/dist/routing.mjs CHANGED
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  import { Stream } from "node:stream";
3
+ import { ObjectId } from "mongodb";
3
4
  import { Result, ACError, HTTPStatus, REQUEST_METHODS, STREAMED_RESPONSE } from "@aeriajs/types";
4
5
  import { pipe, isGranted, deepMerge, endpointError } from "@aeriajs/common";
5
- import { validate } from "@aeriajs/validation";
6
+ import { validateWithRefs } from "@aeriajs/validation";
6
7
  import { getConfig } from "@aeriajs/entrypoint";
7
8
  import { safeJson } from "./payload.mjs";
8
- const checkUnprocessable = (what, schema, context, validateOptions = {}) => {
9
+ const checkUnprocessable = async (what, schema, context, validateOptions = {}) => {
9
10
  let result;
10
11
  if (Array.isArray(schema)) {
11
12
  for (const property of schema) {
12
- result = validate(what, property, validateOptions);
13
+ result = await validateWithRefs(what, property, validateOptions);
13
14
  if (!result.error) {
14
15
  break;
15
16
  }
16
17
  }
17
18
  } else {
18
- result = validate(what, schema, validateOptions);
19
+ result = await validateWithRefs(what, schema, validateOptions);
19
20
  }
20
21
  const { error, result: validated } = result;
21
22
  if (error) {
@@ -87,14 +88,21 @@ export const registerRoute = async (context, method, exp, cb, contract, options
87
88
  }
88
89
  }
89
90
  if ("payload" in contract && contract.payload) {
90
- const { error } = checkUnprocessable(context.request.payload, contract.payload, context);
91
+ const { error } = await checkUnprocessable(context.request.payload, contract.payload, context, {
92
+ checkObjectIds: true,
93
+ context,
94
+ objectIdConstructor: ObjectId
95
+ });
91
96
  if (error) {
92
97
  return Result.error(error);
93
98
  }
94
99
  }
95
100
  if ("query" in contract && contract.query) {
96
- const { error, result: validated } = checkUnprocessable(context.request.query, contract.query, context, {
97
- coerce: true
101
+ const { error, result: validated } = await checkUnprocessable(context.request.query, contract.query, context, {
102
+ checkObjectIds: true,
103
+ coerce: true,
104
+ context,
105
+ objectIdConstructor: ObjectId
98
106
  });
99
107
  if (error) {
100
108
  return Result.error(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/http",
3
- "version": "0.0.174",
3
+ "version": "0.0.176",
4
4
  "description": "## Installation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,13 +25,15 @@
25
25
  "@aeriajs/common": "link:../common",
26
26
  "@aeriajs/entrypoint": "link:../entrypoint",
27
27
  "@aeriajs/types": "link:../types",
28
- "@aeriajs/validation": "link:../validation"
28
+ "@aeriajs/validation": "link:../validation",
29
+ "mongodb": "^6.16.0"
29
30
  },
30
31
  "peerDependencies": {
31
- "@aeriajs/common": "^0.0.144",
32
- "@aeriajs/entrypoint": "^0.0.149",
33
- "@aeriajs/types": "^0.0.126",
34
- "@aeriajs/validation": "^0.0.161"
32
+ "@aeriajs/common": "^0.0.145",
33
+ "@aeriajs/entrypoint": "^0.0.150",
34
+ "@aeriajs/types": "^0.0.127",
35
+ "@aeriajs/validation": "^0.0.163",
36
+ "mongodb": "^6.16.0"
35
37
  },
36
38
  "scripts": {
37
39
  "test": "vitest run",