@aeriajs/core 0.0.135 → 0.0.137

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.
@@ -63,6 +63,9 @@ const disposeOldFiles = async (ctx, options = {}) => {
63
63
  return types_1.Result.error(types_1.TraverseError.InvalidDocumentId);
64
64
  }
65
65
  let fileIds = (0, common_1.getValueFromPath)(doc, ctx.propPath);
66
+ if (!fileIds) {
67
+ return;
68
+ }
66
69
  if (options.preserveIds) {
67
70
  fileIds = fileIds.filter((id) => !id || !options.preserveIds.some((fromId) => {
68
71
  return id.equals(fromId);
@@ -38,6 +38,9 @@ const disposeOldFiles = async (ctx, options = {}) => {
38
38
  return Result.error(TraverseError.InvalidDocumentId);
39
39
  }
40
40
  let fileIds = getValueFromPath(doc, ctx.propPath);
41
+ if (!fileIds) {
42
+ return;
43
+ }
41
44
  if (options.preserveIds) {
42
45
  fileIds = fileIds.filter((id) => !id || !options.preserveIds.some((fromId) => {
43
46
  return id.equals(fromId);
@@ -7,21 +7,25 @@ const common_1 = require("@aeriajs/common");
7
7
  const index_js_1 = require("../../collection/index.js");
8
8
  const count = async (payload, context) => {
9
9
  const security = (0, security_1.useSecurity)(context);
10
- const { filters } = (0, common_1.throwIfError)(await security.beforeRead(payload));
11
- const { $text, ...filtersRest } = filters;
12
- const traversedFilters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
10
+ const sanitizedPayload = (0, common_1.throwIfError)(await security.beforeRead(payload));
11
+ const filters = sanitizedPayload.filters;
12
+ const $text = '$text' in sanitizedPayload.filters
13
+ ? sanitizedPayload.filters.$text
14
+ : undefined;
15
+ if ('$text' in filters) {
16
+ delete filters.$text;
17
+ }
18
+ const traversedFilters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filters, context.description, {
13
19
  autoCast: true,
14
20
  allowOperators: true,
15
21
  }));
16
22
  if ($text) {
17
23
  const pipeline = [];
18
- if ($text) {
19
- pipeline.push({
20
- $match: {
21
- $text,
22
- },
23
- });
24
- }
24
+ pipeline.push({
25
+ $match: {
26
+ $text,
27
+ },
28
+ });
25
29
  pipeline.push({
26
30
  $match: traversedFilters,
27
31
  });
@@ -5,21 +5,23 @@ import { throwIfError } from "@aeriajs/common";
5
5
  import { traverseDocument } from "../../collection/index.mjs";
6
6
  export const count = async (payload, context) => {
7
7
  const security = useSecurity(context);
8
- const { filters } = throwIfError(await security.beforeRead(payload));
9
- const { $text, ...filtersRest } = filters;
10
- const traversedFilters = throwIfError(await traverseDocument(filtersRest, context.description, {
8
+ const sanitizedPayload = throwIfError(await security.beforeRead(payload));
9
+ const filters = sanitizedPayload.filters;
10
+ const $text = "$text" in sanitizedPayload.filters ? sanitizedPayload.filters.$text : void 0;
11
+ if ("$text" in filters) {
12
+ delete filters.$text;
13
+ }
14
+ const traversedFilters = throwIfError(await traverseDocument(filters, context.description, {
11
15
  autoCast: true,
12
16
  allowOperators: true
13
17
  }));
14
18
  if ($text) {
15
19
  const pipeline = [];
16
- if ($text) {
17
- pipeline.push({
18
- $match: {
19
- $text
20
- }
21
- });
22
- }
20
+ pipeline.push({
21
+ $match: {
22
+ $text
23
+ }
24
+ });
23
25
  pipeline.push({
24
26
  $match: traversedFilters
25
27
  });
@@ -7,9 +7,10 @@ const common_1 = require("@aeriajs/common");
7
7
  const index_js_1 = require("../../collection/index.js");
8
8
  const get = async (payload, context, options) => {
9
9
  const security = (0, security_1.useSecurity)(context);
10
- const { filters = {}, project = [], } = !options?.bypassSecurity
10
+ const sanitizedPayload = !options?.bypassSecurity
11
11
  ? (0, common_1.throwIfError)(await security.beforeRead(payload))
12
12
  : payload;
13
+ const { filters = {}, project = [], } = sanitizedPayload;
13
14
  if (Object.keys(filters).length === 0) {
14
15
  return context.error(types_1.HTTPStatus.BadRequest, {
15
16
  code: types_1.ACError.MalformedInput,
@@ -33,7 +34,9 @@ const get = async (payload, context, options) => {
33
34
  }
34
35
  pipeline.push(...await (0, index_js_1.buildLookupPipeline)(references, {
35
36
  memoize: context.description.$id,
36
- project: payload.populate || project,
37
+ project: sanitizedPayload.populate
38
+ ? sanitizedPayload.populate
39
+ : project,
37
40
  properties: context.description.properties,
38
41
  }));
39
42
  const doc = await context.collection.model.aggregate(pipeline).next();
@@ -11,10 +11,11 @@ import {
11
11
  } from "../../collection/index.mjs";
12
12
  export const get = async (payload, context, options) => {
13
13
  const security = useSecurity(context);
14
+ const sanitizedPayload = !options?.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
14
15
  const {
15
16
  filters = {},
16
17
  project = []
17
- } = !options?.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
18
+ } = sanitizedPayload;
18
19
  if (Object.keys(filters).length === 0) {
19
20
  return context.error(HTTPStatus.BadRequest, {
20
21
  code: ACError.MalformedInput
@@ -38,7 +39,7 @@ export const get = async (payload, context, options) => {
38
39
  }
39
40
  pipeline.push(...await buildLookupPipeline(references, {
40
41
  memoize: context.description.$id,
41
- project: payload.populate || project,
42
+ project: sanitizedPayload.populate ? sanitizedPayload.populate : project,
42
43
  properties: context.description.properties
43
44
  }));
44
45
  const doc = await context.collection.model.aggregate(pipeline).next();
@@ -8,10 +8,17 @@ const index_js_1 = require("../../collection/index.js");
8
8
  const getAll = async (_payload, context, options = {}) => {
9
9
  const security = (0, security_1.useSecurity)(context);
10
10
  const payload = _payload || {};
11
- const { filters = {}, limit = context.config.paginationLimit, sort, project = [], offset = 0, } = !options.bypassSecurity
11
+ const sanitizedPayload = !options.bypassSecurity
12
12
  ? (0, common_1.throwIfError)(await security.beforeRead(payload))
13
13
  : payload;
14
- const { $text, ...filtersRest } = filters;
14
+ const { limit = context.config.paginationLimit, sort, project = [], offset = 0, } = sanitizedPayload;
15
+ const filters = sanitizedPayload.filters || {};
16
+ const $text = sanitizedPayload.filters && '$text' in sanitizedPayload.filters
17
+ ? sanitizedPayload.filters.$text
18
+ : undefined;
19
+ if ('$text' in filters) {
20
+ delete filters.$text;
21
+ }
15
22
  const pipeline = [];
16
23
  const references = await (0, index_js_1.getReferences)(context.description.properties, {
17
24
  memoize: context.description.$id,
@@ -35,9 +42,9 @@ const getAll = async (_payload, context, options = {}) => {
35
42
  $sort: preferredSort,
36
43
  });
37
44
  }
38
- if (Object.keys(filtersRest).length > 0) {
45
+ if (Object.keys(filters).length > 0) {
39
46
  pipeline.push({
40
- $match: (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
47
+ $match: (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filters, context.description, {
41
48
  autoCast: true,
42
49
  allowOperators: true,
43
50
  })),
@@ -59,7 +66,9 @@ const getAll = async (_payload, context, options = {}) => {
59
66
  }
60
67
  pipeline.push(...await (0, index_js_1.buildLookupPipeline)(references, {
61
68
  memoize: context.description.$id,
62
- project: payload.populate || project,
69
+ project: sanitizedPayload.populate
70
+ ? sanitizedPayload.populate
71
+ : project,
63
72
  properties: context.description.properties,
64
73
  }));
65
74
  if (Object.keys(references).length > 0 && preferredSort) {
@@ -12,14 +12,18 @@ import {
12
12
  export const getAll = async (_payload, context, options = {}) => {
13
13
  const security = useSecurity(context);
14
14
  const payload = _payload || {};
15
+ const sanitizedPayload = !options.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
15
16
  const {
16
- filters = {},
17
17
  limit = context.config.paginationLimit,
18
18
  sort,
19
19
  project = [],
20
20
  offset = 0
21
- } = !options.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
22
- const { $text, ...filtersRest } = filters;
21
+ } = sanitizedPayload;
22
+ const filters = sanitizedPayload.filters || {};
23
+ const $text = sanitizedPayload.filters && "$text" in sanitizedPayload.filters ? sanitizedPayload.filters.$text : void 0;
24
+ if ("$text" in filters) {
25
+ delete filters.$text;
26
+ }
23
27
  const pipeline = [];
24
28
  const references = await getReferences(context.description.properties, {
25
29
  memoize: context.description.$id
@@ -39,9 +43,9 @@ export const getAll = async (_payload, context, options = {}) => {
39
43
  $sort: preferredSort
40
44
  });
41
45
  }
42
- if (Object.keys(filtersRest).length > 0) {
46
+ if (Object.keys(filters).length > 0) {
43
47
  pipeline.push({
44
- $match: throwIfError(await traverseDocument(filtersRest, context.description, {
48
+ $match: throwIfError(await traverseDocument(filters, context.description, {
45
49
  autoCast: true,
46
50
  allowOperators: true
47
51
  }))
@@ -63,7 +67,7 @@ export const getAll = async (_payload, context, options = {}) => {
63
67
  }
64
68
  pipeline.push(...await buildLookupPipeline(references, {
65
69
  memoize: context.description.$id,
66
- project: payload.populate || project,
70
+ project: sanitizedPayload.populate ? sanitizedPayload.populate : project,
67
71
  properties: context.description.properties
68
72
  }));
69
73
  if (Object.keys(references).length > 0 && preferredSort) {
@@ -5,7 +5,7 @@ const security_1 = require("@aeriajs/security");
5
5
  const types_1 = require("@aeriajs/types");
6
6
  const removeFile = async (payload, context) => {
7
7
  const { propertyName, parentId, ...props } = payload;
8
- await (0, security_1.checkImmutability)({
8
+ await (0, security_1.checkImmutabilityRead)({
9
9
  propertyName,
10
10
  parentId,
11
11
  childId: props.filters._id,
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { checkImmutability } from "@aeriajs/security";
2
+ import { checkImmutabilityRead } from "@aeriajs/security";
3
3
  import { Result } from "@aeriajs/types";
4
4
  export const removeFile = async (payload, context) => {
5
5
  const {
@@ -7,7 +7,7 @@ export const removeFile = async (payload, context) => {
7
7
  parentId,
8
8
  ...props
9
9
  } = payload;
10
- await checkImmutability({
10
+ await checkImmutabilityRead({
11
11
  propertyName,
12
12
  parentId,
13
13
  childId: props.filters._id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.135",
3
+ "version": "0.0.137",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,13 +41,13 @@
41
41
  "mongodb-memory-server": "^9.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@aeriajs/builtins": "^0.0.135",
45
- "@aeriajs/common": "^0.0.85",
46
- "@aeriajs/entrypoint": "^0.0.87",
47
- "@aeriajs/http": "^0.0.96",
48
- "@aeriajs/security": "^0.0.135",
49
- "@aeriajs/types": "^0.0.73",
50
- "@aeriajs/validation": "^0.0.88"
44
+ "@aeriajs/builtins": "^0.0.137",
45
+ "@aeriajs/common": "^0.0.86",
46
+ "@aeriajs/entrypoint": "^0.0.88",
47
+ "@aeriajs/http": "^0.0.97",
48
+ "@aeriajs/security": "^0.0.137",
49
+ "@aeriajs/types": "^0.0.74",
50
+ "@aeriajs/validation": "^0.0.89"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",