@aeriajs/core 0.0.189 → 0.0.190

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.
@@ -7,6 +7,7 @@ export type TraverseOptionsBase = {
7
7
  validateWholeness?: boolean | 'deep';
8
8
  fromProperties?: boolean;
9
9
  allowOperators?: boolean;
10
+ allowInsecureOperators?: boolean;
10
11
  undefinedToNull?: boolean;
11
12
  preserveHidden?: boolean;
12
13
  recurseDeep?: boolean;
@@ -46,7 +47,7 @@ export declare const traverseDocument: <TWhat>(what: TWhat, description: Descrip
46
47
  readonly result: TWhat;
47
48
  } | {
48
49
  readonly _tag: "Error";
49
- readonly error: ACError.InsecureOperator | TraverseError | ValidationError;
50
+ readonly error: ACError.InsecureOperator | ValidationError | TraverseError;
50
51
  readonly result: undefined;
51
52
  }>;
52
53
  export {};
@@ -1,10 +1,6 @@
1
- import type { Context, SchemaWithId, CountPayload } from '@aeriajs/types';
2
- import { Result } from '@aeriajs/types';
1
+ import type { Context, SchemaWithId, CountPayload, CountReturnType } from '@aeriajs/types';
3
2
  export type CountOptions = {
4
3
  bypassSecurity?: boolean;
4
+ allowInsecureOperators?: boolean;
5
5
  };
6
- export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context ? TContext : never, options?: CountOptions) => Promise<Result.Error<any> | {
7
- readonly _tag: "Result";
8
- readonly error: undefined;
9
- readonly result: any;
10
- }>;
6
+ export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context ? TContext : never, options?: CountOptions) => Promise<CountReturnType>;
@@ -5,7 +5,7 @@ const security_1 = require("@aeriajs/security");
5
5
  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
- const internalCount = async (payload, context) => {
8
+ const internalCount = async (payload, context, options) => {
9
9
  const { filters = {} } = payload;
10
10
  const $text = '$text' in filters
11
11
  ? filters.$text
@@ -16,6 +16,7 @@ const internalCount = async (payload, context) => {
16
16
  const traversedFilters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filters, context.description, {
17
17
  autoCast: true,
18
18
  allowOperators: true,
19
+ allowInsecureOperators: options.allowInsecureOperators,
19
20
  context,
20
21
  }));
21
22
  if ($text) {
@@ -40,13 +41,17 @@ const internalCount = async (payload, context) => {
40
41
  };
41
42
  const count = async (payload, context, options = {}) => {
42
43
  if (options.bypassSecurity) {
43
- return internalCount(payload, context);
44
+ return internalCount(payload, context, options);
44
45
  }
45
46
  const security = (0, security_1.useSecurity)(context);
46
47
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
47
48
  if (error) {
48
- return types_1.Result.error(error);
49
+ return context.error(types_1.HTTPStatus.Forbidden, {
50
+ code: error,
51
+ });
49
52
  }
50
- return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalCount);
53
+ return (0, security_1.applyReadMiddlewares)(securedPayload, context, (payload, context) => {
54
+ return internalCount(payload, context, options);
55
+ });
51
56
  };
52
57
  exports.count = count;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
3
- import { Result } from "@aeriajs/types";
3
+ import { Result, HTTPStatus } from "@aeriajs/types";
4
4
  import { throwIfError } from "@aeriajs/common";
5
5
  import { traverseDocument } from "../collection/index.mjs";
6
- const internalCount = async (payload, context) => {
6
+ const internalCount = async (payload, context, options) => {
7
7
  const { filters = {} } = payload;
8
8
  const $text = "$text" in filters ? filters.$text : void 0;
9
9
  if ("$text" in filters) {
@@ -12,6 +12,7 @@ const internalCount = async (payload, context) => {
12
12
  const traversedFilters = throwIfError(await traverseDocument(filters, context.description, {
13
13
  autoCast: true,
14
14
  allowOperators: true,
15
+ allowInsecureOperators: options.allowInsecureOperators,
15
16
  context
16
17
  }));
17
18
  if ($text) {
@@ -34,12 +35,16 @@ const internalCount = async (payload, context) => {
34
35
  };
35
36
  export const count = async (payload, context, options = {}) => {
36
37
  if (options.bypassSecurity) {
37
- return internalCount(payload, context);
38
+ return internalCount(payload, context, options);
38
39
  }
39
40
  const security = useSecurity(context);
40
41
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
41
42
  if (error) {
42
- return Result.error(error);
43
+ return context.error(HTTPStatus.Forbidden, {
44
+ code: error
45
+ });
43
46
  }
44
- return applyReadMiddlewares(securedPayload, context, internalCount);
47
+ return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
48
+ return internalCount(payload2, context2, options);
49
+ });
45
50
  };
@@ -1,5 +1,6 @@
1
1
  import type { Context, SchemaWithId, GetPayload, GetReturnType } from '@aeriajs/types';
2
2
  export type GetOptions = {
3
3
  bypassSecurity?: boolean;
4
+ allowInsecureOperators?: boolean;
4
5
  };
5
6
  export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: GetOptions) => Promise<GetReturnType<SchemaWithId<TContext["description"]>>>;
@@ -5,7 +5,7 @@ const security_1 = require("@aeriajs/security");
5
5
  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
- const internalGet = async (payload, context) => {
8
+ const internalGet = async (payload, context, options) => {
9
9
  const { filters = {}, project, } = payload;
10
10
  if (Object.keys(filters).length === 0) {
11
11
  return context.error(types_1.HTTPStatus.BadRequest, {
@@ -19,6 +19,7 @@ const internalGet = async (payload, context) => {
19
19
  const { error: filtersError, result: traversedFilters } = await (0, index_js_1.traverseDocument)(filters, context.description, {
20
20
  autoCast: true,
21
21
  allowOperators: true,
22
+ allowInsecureOperators: options.allowInsecureOperators,
22
23
  context,
23
24
  });
24
25
  if (filtersError) {
@@ -63,7 +64,7 @@ const internalGet = async (payload, context) => {
63
64
  };
64
65
  const get = async (payload, context, options = {}) => {
65
66
  if (options.bypassSecurity) {
66
- return internalGet(payload, context);
67
+ return internalGet(payload, context, options);
67
68
  }
68
69
  const security = (0, security_1.useSecurity)(context);
69
70
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
@@ -75,6 +76,8 @@ const get = async (payload, context, options = {}) => {
75
76
  code: error,
76
77
  });
77
78
  }
78
- return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalGet);
79
+ return (0, security_1.applyReadMiddlewares)(securedPayload, context, (payload, context) => {
80
+ return internalGet(payload, context, options);
81
+ });
79
82
  };
80
83
  exports.get = get;
@@ -8,7 +8,7 @@ import {
8
8
  getReferences,
9
9
  buildLookupPipeline
10
10
  } from "../collection/index.mjs";
11
- const internalGet = async (payload, context) => {
11
+ const internalGet = async (payload, context, options) => {
12
12
  const {
13
13
  filters = {},
14
14
  project
@@ -25,6 +25,7 @@ const internalGet = async (payload, context) => {
25
25
  const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
26
26
  autoCast: true,
27
27
  allowOperators: true,
28
+ allowInsecureOperators: options.allowInsecureOperators,
28
29
  context
29
30
  });
30
31
  if (filtersError) {
@@ -69,7 +70,7 @@ const internalGet = async (payload, context) => {
69
70
  };
70
71
  export const get = async (payload, context, options = {}) => {
71
72
  if (options.bypassSecurity) {
72
- return internalGet(payload, context);
73
+ return internalGet(payload, context, options);
73
74
  }
74
75
  const security = useSecurity(context);
75
76
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
@@ -82,5 +83,7 @@ export const get = async (payload, context, options = {}) => {
82
83
  code: error
83
84
  });
84
85
  }
85
- return applyReadMiddlewares(securedPayload, context, internalGet);
86
+ return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
87
+ return internalGet(payload2, context2, options);
88
+ });
86
89
  };
@@ -2,5 +2,6 @@ import type { Context, SchemaWithId, GetAllPayload, GetAllReturnType } from '@ae
2
2
  export type GetAllOptions = {
3
3
  bypassSecurity?: boolean;
4
4
  noDefaultLimit?: boolean;
5
+ allowInsecureOperators?: boolean;
5
6
  };
6
7
  export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<GetAllReturnType<SchemaWithId<TContext["description"]>>>;
@@ -5,7 +5,7 @@ const security_1 = require("@aeriajs/security");
5
5
  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
- const internalGetAll = async (payload, context) => {
8
+ const internalGetAll = async (payload, context, options) => {
9
9
  const { limit, sort, project, offset = 0, } = payload;
10
10
  const filters = payload.filters
11
11
  ? Object.assign({}, payload.filters)
@@ -42,6 +42,7 @@ const internalGetAll = async (payload, context) => {
42
42
  const { error: filtersError, result: traversedFilters } = await (0, index_js_1.traverseDocument)(filters, context.description, {
43
43
  autoCast: true,
44
44
  allowOperators: true,
45
+ allowInsecureOperators: options.allowInsecureOperators,
45
46
  context,
46
47
  });
47
48
  if (filtersError) {
@@ -101,10 +102,10 @@ const internalGetAll = async (payload, context) => {
101
102
  };
102
103
  const getAll = async (payload, context, options = {}) => {
103
104
  if (!payload) {
104
- return internalGetAll({}, context);
105
+ return internalGetAll({}, context, options);
105
106
  }
106
107
  if (options.bypassSecurity) {
107
- return internalGetAll(payload, context);
108
+ return internalGetAll(payload, context, options);
108
109
  }
109
110
  const security = (0, security_1.useSecurity)(context);
110
111
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
@@ -116,6 +117,8 @@ const getAll = async (payload, context, options = {}) => {
116
117
  if (!options.noDefaultLimit) {
117
118
  securedPayload.limit ||= context.config.defaultPaginationLimit;
118
119
  }
119
- return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalGetAll);
120
+ return (0, security_1.applyReadMiddlewares)(securedPayload, context, (payload, context) => {
121
+ return internalGetAll(payload, context, options);
122
+ });
120
123
  };
121
124
  exports.getAll = getAll;
@@ -8,7 +8,7 @@ import {
8
8
  getReferences,
9
9
  buildLookupPipeline
10
10
  } from "../collection/index.mjs";
11
- const internalGetAll = async (payload, context) => {
11
+ const internalGetAll = async (payload, context, options) => {
12
12
  const {
13
13
  limit,
14
14
  sort,
@@ -42,6 +42,7 @@ const internalGetAll = async (payload, context) => {
42
42
  const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
43
43
  autoCast: true,
44
44
  allowOperators: true,
45
+ allowInsecureOperators: options.allowInsecureOperators,
45
46
  context
46
47
  });
47
48
  if (filtersError) {
@@ -101,10 +102,10 @@ const internalGetAll = async (payload, context) => {
101
102
  };
102
103
  export const getAll = async (payload, context, options = {}) => {
103
104
  if (!payload) {
104
- return internalGetAll({}, context);
105
+ return internalGetAll({}, context, options);
105
106
  }
106
107
  if (options.bypassSecurity) {
107
- return internalGetAll(payload, context);
108
+ return internalGetAll(payload, context, options);
108
109
  }
109
110
  const security = useSecurity(context);
110
111
  const { error, result: securedPayload } = await security.secureReadPayload(payload);
@@ -116,5 +117,7 @@ export const getAll = async (payload, context, options = {}) => {
116
117
  if (!options.noDefaultLimit) {
117
118
  securedPayload.limit ||= context.config.defaultPaginationLimit;
118
119
  }
119
- return applyReadMiddlewares(securedPayload, context, internalGetAll);
120
+ return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
121
+ return internalGetAll(payload2, context2, options);
122
+ });
120
123
  };
@@ -1,36 +1,5 @@
1
1
  import type { Context, SchemaWithId, InsertPayload, InsertReturnType } from '@aeriajs/types';
2
- import { HTTPStatus, ACError, ValidationErrorCode, TraverseError } from '@aeriajs/types';
3
2
  export type InsertOptions = {
4
3
  bypassSecurity?: boolean;
5
4
  };
6
- export declare const insertErrorSchema: () => {
7
- readonly type: "object";
8
- readonly properties: {
9
- readonly _tag: {
10
- readonly const: "Error";
11
- };
12
- readonly result: {
13
- readonly const: undefined;
14
- };
15
- readonly error: {
16
- readonly type: "object";
17
- readonly required: readonly ["httpStatus", "code"];
18
- readonly properties: {
19
- readonly httpStatus: {
20
- readonly enum: [HTTPStatus.Forbidden, HTTPStatus.NotFound, HTTPStatus.UnprocessableContent, HTTPStatus.BadRequest];
21
- };
22
- readonly code: {
23
- readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ACError.MalformedInput, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties, TraverseError.InvalidDocumentId, TraverseError.InvalidTempfile];
24
- };
25
- readonly message: {
26
- readonly type: "string";
27
- };
28
- readonly details: {
29
- readonly type: "object";
30
- readonly variable: true;
31
- };
32
- };
33
- };
34
- };
35
- };
36
5
  export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext["description"]>>>;
@@ -1,33 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.insert = exports.insertErrorSchema = void 0;
3
+ exports.insert = void 0;
4
4
  const mongodb_1 = require("mongodb");
5
5
  const types_1 = require("@aeriajs/types");
6
6
  const security_1 = require("@aeriajs/security");
7
- const common_1 = require("@aeriajs/common");
8
7
  const index_js_1 = require("../collection/index.js");
9
8
  const get_js_1 = require("./get.js");
10
- const insertErrorSchema = () => (0, common_1.endpointErrorSchema)({
11
- httpStatus: [
12
- types_1.HTTPStatus.Forbidden,
13
- types_1.HTTPStatus.NotFound,
14
- types_1.HTTPStatus.UnprocessableContent,
15
- types_1.HTTPStatus.BadRequest,
16
- ],
17
- code: [
18
- types_1.ACError.InsecureOperator,
19
- types_1.ACError.OwnershipError,
20
- types_1.ACError.ResourceNotFound,
21
- types_1.ACError.TargetImmutable,
22
- types_1.ACError.MalformedInput,
23
- types_1.ValidationErrorCode.EmptyTarget,
24
- types_1.ValidationErrorCode.InvalidProperties,
25
- types_1.ValidationErrorCode.MissingProperties,
26
- types_1.TraverseError.InvalidDocumentId,
27
- types_1.TraverseError.InvalidTempfile,
28
- ],
29
- });
30
- exports.insertErrorSchema = insertErrorSchema;
31
9
  const prepareCreate = (doc, description) => {
32
10
  const result = {};
33
11
  if (description.defaults) {
@@ -1,30 +1,9 @@
1
1
  "use strict";
2
2
  import { ObjectId } from "mongodb";
3
- import { Result, HTTPStatus, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
3
+ import { Result, HTTPStatus } from "@aeriajs/types";
4
4
  import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
5
- import { endpointErrorSchema } from "@aeriajs/common";
6
5
  import { traverseDocument } from "../collection/index.mjs";
7
6
  import { get } from "./get.mjs";
8
- export const insertErrorSchema = () => endpointErrorSchema({
9
- httpStatus: [
10
- HTTPStatus.Forbidden,
11
- HTTPStatus.NotFound,
12
- HTTPStatus.UnprocessableContent,
13
- HTTPStatus.BadRequest
14
- ],
15
- code: [
16
- ACError.InsecureOperator,
17
- ACError.OwnershipError,
18
- ACError.ResourceNotFound,
19
- ACError.TargetImmutable,
20
- ACError.MalformedInput,
21
- ValidationErrorCode.EmptyTarget,
22
- ValidationErrorCode.InvalidProperties,
23
- ValidationErrorCode.MissingProperties,
24
- TraverseError.InvalidDocumentId,
25
- TraverseError.InvalidTempfile
26
- ]
27
- });
28
7
  const prepareCreate = (doc, description) => {
29
8
  const result = {};
30
9
  if (description.defaults) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.189",
3
+ "version": "0.0.190",
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.189",
46
- "@aeriajs/common": "^0.0.115",
47
- "@aeriajs/entrypoint": "^0.0.118",
48
- "@aeriajs/http": "^0.0.129",
49
- "@aeriajs/security": "^0.0.189",
50
- "@aeriajs/types": "^0.0.98",
51
- "@aeriajs/validation": "^0.0.118"
45
+ "@aeriajs/builtins": "^0.0.190",
46
+ "@aeriajs/common": "^0.0.116",
47
+ "@aeriajs/entrypoint": "^0.0.119",
48
+ "@aeriajs/http": "^0.0.130",
49
+ "@aeriajs/security": "^0.0.190",
50
+ "@aeriajs/types": "^0.0.99",
51
+ "@aeriajs/validation": "^0.0.119"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",