@aeriajs/core 0.0.175 → 0.0.177

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.
@@ -128,7 +128,7 @@ const autoCast = (value, ctx) => {
128
128
  }
129
129
  }
130
130
  case 'object': {
131
- if (!value || (0, common_1.isObjectId)(value)) {
131
+ if (!value || value instanceof mongodb_1.ObjectId) {
132
132
  return value;
133
133
  }
134
134
  if (!('description' in ctx.options) || !ctx.options.recurseDeep) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { Result, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
3
- import { throwIfError, pipe, isReference, getValueFromPath, isObjectId, isError } from "@aeriajs/common";
3
+ import { throwIfError, pipe, isReference, getValueFromPath, isError } from "@aeriajs/common";
4
4
  import { makeValidationError, validateProperty, validateWholeness } from "@aeriajs/validation";
5
5
  import { getCollection } from "@aeriajs/entrypoint";
6
6
  import { ObjectId } from "mongodb";
@@ -96,7 +96,7 @@ const autoCast = (value, ctx) => {
96
96
  }
97
97
  }
98
98
  case "object": {
99
- if (!value || isObjectId(value)) {
99
+ if (!value || value instanceof ObjectId) {
100
100
  return value;
101
101
  }
102
102
  if (!("description" in ctx.options) || !ctx.options.recurseDeep) {
@@ -1,6 +1,6 @@
1
- import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
2
- import { Result } from '@aeriajs/types';
1
+ import type { Context, SchemaWithId, GetAllPayload, GetAllReturnType } from '@aeriajs/types';
3
2
  export type GetAllOptions = {
4
3
  bypassSecurity?: boolean;
4
+ noDefaultLimit?: boolean;
5
5
  };
6
- export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<Result.Either<any, any>>;
6
+ export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<GetAllReturnType<SchemaWithId<TContext["description"]>>>;
@@ -6,7 +6,7 @@ const types_1 = require("@aeriajs/types");
6
6
  const common_1 = require("@aeriajs/common");
7
7
  const index_js_1 = require("../collection/index.js");
8
8
  const internalGetAll = async (payload, context) => {
9
- const { limit = context.config.defaultPaginationLimit, sort, project, offset = 0, } = payload;
9
+ const { limit, sort, project, offset = 0, } = payload;
10
10
  const filters = payload.filters
11
11
  ? Object.assign({}, payload.filters)
12
12
  : {};
@@ -52,9 +52,11 @@ const internalGetAll = async (payload, context) => {
52
52
  $skip: offset,
53
53
  });
54
54
  }
55
- pipeline.push({
56
- $limit: limit,
57
- });
55
+ if (limit) {
56
+ pipeline.push({
57
+ $limit: limit,
58
+ });
59
+ }
58
60
  if (project) {
59
61
  const projection = (0, index_js_1.normalizeProjection)(project, context.description);
60
62
  if (projection) {
@@ -97,7 +99,12 @@ const getAll = async (payload, context, options = {}) => {
97
99
  const security = (0, security_1.useSecurity)(context);
98
100
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
99
101
  if (error) {
100
- return types_1.Result.error(error);
102
+ return context.error(types_1.HTTPStatus.Forbidden, {
103
+ code: error,
104
+ });
105
+ }
106
+ if (!options.noDefaultLimit) {
107
+ securedPayload.limit ||= context.config.defaultPaginationLimit;
101
108
  }
102
109
  return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalGetAll);
103
110
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
3
- import { Result } from "@aeriajs/types";
3
+ import { HTTPStatus, Result } from "@aeriajs/types";
4
4
  import { throwIfError } from "@aeriajs/common";
5
5
  import {
6
6
  traverseDocument,
@@ -10,7 +10,7 @@ import {
10
10
  } from "../collection/index.mjs";
11
11
  const internalGetAll = async (payload, context) => {
12
12
  const {
13
- limit = context.config.defaultPaginationLimit,
13
+ limit,
14
14
  sort,
15
15
  project,
16
16
  offset = 0
@@ -52,9 +52,11 @@ const internalGetAll = async (payload, context) => {
52
52
  $skip: offset
53
53
  });
54
54
  }
55
- pipeline.push({
56
- $limit: limit
57
- });
55
+ if (limit) {
56
+ pipeline.push({
57
+ $limit: limit
58
+ });
59
+ }
58
60
  if (project) {
59
61
  const projection = normalizeProjection(project, context.description);
60
62
  if (projection) {
@@ -95,7 +97,12 @@ export const getAll = async (payload, context, options = {}) => {
95
97
  const security = useSecurity(context);
96
98
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
97
99
  if (error) {
98
- return Result.error(error);
100
+ return context.error(HTTPStatus.Forbidden, {
101
+ code: error
102
+ });
103
+ }
104
+ if (!options.noDefaultLimit) {
105
+ securedPayload.limit ||= context.config.defaultPaginationLimit;
99
106
  }
100
107
  return applyReadMiddlewares(securedPayload, context, internalGetAll);
101
108
  };
@@ -17,10 +17,10 @@ export declare const insertErrorSchema: () => {
17
17
  readonly required: readonly ["httpStatus", "code"];
18
18
  readonly properties: {
19
19
  readonly httpStatus: {
20
- readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.UnprocessableContent];
20
+ readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.UnprocessableContent, HTTPStatus.BadRequest];
21
21
  };
22
22
  readonly code: {
23
- readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties, TraverseError.InvalidDocumentId, TraverseError.InvalidTempfile];
23
+ readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ACError.MalformedInput, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties, TraverseError.InvalidDocumentId, TraverseError.InvalidTempfile];
24
24
  };
25
25
  readonly message: {
26
26
  readonly type: "string";
@@ -12,12 +12,14 @@ const insertErrorSchema = () => (0, common_1.endpointErrorSchema)({
12
12
  types_1.HTTPStatus.Forbidden,
13
13
  types_1.HTTPStatus.NotFound,
14
14
  types_1.HTTPStatus.UnprocessableContent,
15
+ types_1.HTTPStatus.BadRequest,
15
16
  ],
16
17
  code: [
17
18
  types_1.ACError.InsecureOperator,
18
19
  types_1.ACError.OwnershipError,
19
20
  types_1.ACError.ResourceNotFound,
20
21
  types_1.ACError.TargetImmutable,
22
+ types_1.ACError.MalformedInput,
21
23
  types_1.ValidationErrorCode.EmptyTarget,
22
24
  types_1.ValidationErrorCode.InvalidProperties,
23
25
  types_1.ValidationErrorCode.MissingProperties,
@@ -74,13 +76,16 @@ const internalInsert = async (payload, context) => {
74
76
  ...context,
75
77
  inherited: true,
76
78
  };
77
- const newDocument = (0, common_1.throwIfError)(await (0, get_js_1.get)({
79
+ const { error: getError, result: newDocument } = await (0, get_js_1.get)({
78
80
  filters: {
79
81
  _id: newId,
80
82
  },
81
83
  }, inheritedContext, {
82
84
  bypassSecurity: true,
83
- }));
85
+ });
86
+ if (getError) {
87
+ return types_1.Result.error(getError);
88
+ }
84
89
  return types_1.Result.result(newDocument);
85
90
  };
86
91
  const insert = async (payload, context, options = {}) => {
@@ -2,20 +2,22 @@
2
2
  import { ObjectId } from "mongodb";
3
3
  import { Result, HTTPStatus, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
4
4
  import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
5
- import { throwIfError, endpointErrorSchema } from "@aeriajs/common";
5
+ import { endpointErrorSchema } from "@aeriajs/common";
6
6
  import { traverseDocument, prepareCreate, prepareUpdate } from "../collection/index.mjs";
7
7
  import { get } from "./get.mjs";
8
8
  export const insertErrorSchema = () => endpointErrorSchema({
9
9
  httpStatus: [
10
10
  HTTPStatus.Forbidden,
11
11
  HTTPStatus.NotFound,
12
- HTTPStatus.UnprocessableContent
12
+ HTTPStatus.UnprocessableContent,
13
+ HTTPStatus.BadRequest
13
14
  ],
14
15
  code: [
15
16
  ACError.InsecureOperator,
16
17
  ACError.OwnershipError,
17
18
  ACError.ResourceNotFound,
18
19
  ACError.TargetImmutable,
20
+ ACError.MalformedInput,
19
21
  ValidationErrorCode.EmptyTarget,
20
22
  ValidationErrorCode.InvalidProperties,
21
23
  ValidationErrorCode.MissingProperties,
@@ -66,13 +68,16 @@ const internalInsert = async (payload, context) => {
66
68
  ...context,
67
69
  inherited: true
68
70
  };
69
- const newDocument = throwIfError(await get({
71
+ const { error: getError, result: newDocument } = await get({
70
72
  filters: {
71
73
  _id: newId
72
74
  }
73
75
  }, inheritedContext, {
74
76
  bypassSecurity: true
75
- }));
77
+ });
78
+ if (getError) {
79
+ return Result.error(getError);
80
+ }
76
81
  return Result.result(newDocument);
77
82
  };
78
83
  export const insert = async (payload, context, options = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.175",
3
+ "version": "0.0.177",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "aeriaMain": "tests/fixtures/aeriaMain.js",
@@ -42,13 +42,13 @@
42
42
  "mongodb-memory-server": "^9.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@aeriajs/builtins": "^0.0.175",
46
- "@aeriajs/common": "^0.0.105",
47
- "@aeriajs/entrypoint": "^0.0.108",
48
- "@aeriajs/http": "^0.0.119",
49
- "@aeriajs/security": "^0.0.175",
50
- "@aeriajs/types": "^0.0.88",
51
- "@aeriajs/validation": "^0.0.108"
45
+ "@aeriajs/builtins": "^0.0.177",
46
+ "@aeriajs/common": "^0.0.107",
47
+ "@aeriajs/entrypoint": "^0.0.110",
48
+ "@aeriajs/http": "^0.0.121",
49
+ "@aeriajs/security": "^0.0.177",
50
+ "@aeriajs/types": "^0.0.90",
51
+ "@aeriajs/validation": "^0.0.110"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",