@aeriajs/core 0.0.239 → 0.0.241

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.
@@ -47,11 +47,7 @@ const preferredRemove = async (targetId, reference, parentContext) => {
47
47
  const { result: removeAll } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'removeAll');
48
48
  if (removeAll) {
49
49
  return removeAll({
50
- filters: {
51
- _id: {
52
- $in: nonNullable,
53
- },
54
- },
50
+ filters: nonNullable,
55
51
  }, context);
56
52
  }
57
53
  return coll.deleteMany({
@@ -44,11 +44,7 @@ export const preferredRemove = async (targetId, reference, parentContext) => {
44
44
  const { result: removeAll } = await getFunction(reference.referencedCollection, "removeAll");
45
45
  if (removeAll) {
46
46
  return removeAll({
47
- filters: {
48
- _id: {
49
- $in: nonNullable
50
- }
51
- }
47
+ filters: nonNullable
52
48
  }, context);
53
49
  }
54
50
  return coll.deleteMany({
@@ -2,7 +2,7 @@ import type { FixedObjectProperty, Description } from '@aeriajs/types';
2
2
  import type { Document } from 'mongodb';
3
3
  export type Reference = {
4
4
  isArray?: boolean;
5
- isArrayElement?: boolean;
5
+ isArrayOrArrayElement?: boolean;
6
6
  isInline?: boolean;
7
7
  isRecursive?: boolean;
8
8
  deepReferences?: ReferenceMap;
@@ -16,7 +16,7 @@ export type GetReferenceOptions = {
16
16
  depth?: number;
17
17
  maxDepth?: number;
18
18
  populate?: string[];
19
- isArrayElement?: boolean;
19
+ isArrayOrArrayElement?: boolean;
20
20
  };
21
21
  export type BuildLookupPipelineOptions = {
22
22
  rootPipeline?: Document[];
@@ -9,7 +9,7 @@ const getTempName = (path) => {
9
9
  const referenceMemo = {};
10
10
  const lookupMemo = {};
11
11
  const getReferences = async (properties, options = {}) => {
12
- const { depth = 0, maxDepth = 3, memoize, populate, isArrayElement, } = options;
12
+ const { depth = 0, maxDepth = 3, memoize, populate, isArrayOrArrayElement, } = options;
13
13
  if (memoize) {
14
14
  if (referenceMemo[memoize]) {
15
15
  return referenceMemo[memoize];
@@ -35,7 +35,7 @@ const getReferences = async (properties, options = {}) => {
35
35
  populate: refProperty.populate
36
36
  ? Array.from(refProperty.populate)
37
37
  : undefined,
38
- isArrayElement: 'items' in property,
38
+ isArrayOrArrayElement: 'items' in property,
39
39
  });
40
40
  if (Object.keys(deepReferences).length > 0) {
41
41
  reference.deepReferences = deepReferences;
@@ -69,8 +69,8 @@ const getReferences = async (properties, options = {}) => {
69
69
  if ('items' in property) {
70
70
  reference.isArray = true;
71
71
  }
72
- if (isArrayElement) {
73
- reference.isArrayElement = true;
72
+ if ('items' in property || isArrayOrArrayElement) {
73
+ reference.isArrayOrArrayElement = true;
74
74
  }
75
75
  if (depth > 0) {
76
76
  reference.isRecursive = true;
@@ -95,7 +95,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
95
95
  noCond: false,
96
96
  }) => {
97
97
  const [refName, isRef] = path.at(-1);
98
- const shouldUseArrayIndex = reference.isRecursive && !(reference.isArrayElement && reference.isArray === false);
98
+ const shouldUseArrayIndex = reference.isRecursive && !(reference.isArrayOrArrayElement && reference.isArray === false);
99
99
  let indexOfArray;
100
100
  if (shouldUseArrayIndex) {
101
101
  if (isRef) {
@@ -155,7 +155,7 @@ const recurseSetStage = (reference, path, parentElem, options = {
155
155
  }
156
156
  let mapInput = parentElem;
157
157
  if (reference.isRecursive) {
158
- if (reference.isArrayElement) {
158
+ if (reference.isArrayOrArrayElement) {
159
159
  mapInput = {
160
160
  $arrayElemAt: [
161
161
  `$${getTempName(path.slice(0, -1))}.${refName}`,
@@ -12,7 +12,7 @@ export const getReferences = async (properties, options = {}) => {
12
12
  maxDepth = 3,
13
13
  memoize,
14
14
  populate,
15
- isArrayElement
15
+ isArrayOrArrayElement
16
16
  } = options;
17
17
  if (memoize) {
18
18
  if (referenceMemo[memoize]) {
@@ -37,7 +37,7 @@ export const getReferences = async (properties, options = {}) => {
37
37
  maxDepth: refProperty.populateDepth || maxDepth,
38
38
  memoize: `${memoize}.${propName}`,
39
39
  populate: refProperty.populate ? Array.from(refProperty.populate) : void 0,
40
- isArrayElement: "items" in property
40
+ isArrayOrArrayElement: "items" in property
41
41
  });
42
42
  if (Object.keys(deepReferences).length > 0) {
43
43
  reference.deepReferences = deepReferences;
@@ -63,8 +63,8 @@ export const getReferences = async (properties, options = {}) => {
63
63
  if ("items" in property) {
64
64
  reference.isArray = true;
65
65
  }
66
- if (isArrayElement) {
67
- reference.isArrayElement = true;
66
+ if ("items" in property || isArrayOrArrayElement) {
67
+ reference.isArrayOrArrayElement = true;
68
68
  }
69
69
  if (depth > 0) {
70
70
  reference.isRecursive = true;
@@ -88,7 +88,7 @@ export const recurseSetStage = (reference, path, parentElem, options = {
88
88
  noCond: false
89
89
  }) => {
90
90
  const [refName, isRef] = path.at(-1);
91
- const shouldUseArrayIndex = reference.isRecursive && !(reference.isArrayElement && reference.isArray === false);
91
+ const shouldUseArrayIndex = reference.isRecursive && !(reference.isArrayOrArrayElement && reference.isArray === false);
92
92
  let indexOfArray;
93
93
  if (shouldUseArrayIndex) {
94
94
  if (isRef) {
@@ -145,7 +145,7 @@ export const recurseSetStage = (reference, path, parentElem, options = {
145
145
  }
146
146
  let mapInput = parentElem;
147
147
  if (reference.isRecursive) {
148
- if (reference.isArrayElement) {
148
+ if (reference.isArrayOrArrayElement) {
149
149
  mapInput = {
150
150
  $arrayElemAt: [
151
151
  `$${getTempName(path.slice(0, -1))}.${refName}`,
@@ -1,9 +1,9 @@
1
- import type { Context, SchemaWithId, RemoveAllPayload } from '@aeriajs/types';
1
+ import type { Context, RemoveAllPayload } from '@aeriajs/types';
2
2
  import { Result } from '@aeriajs/types';
3
3
  export type RemoveAllOptions = {
4
4
  bypassSecurity?: boolean;
5
5
  };
6
- export declare const removeAll: <TContext extends Context>(payload: RemoveAllPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: RemoveAllOptions) => Promise<{
6
+ export declare const removeAll: <TContext extends Context>(_payload: RemoveAllPayload, context: TContext, options?: RemoveAllOptions) => Promise<{
7
7
  readonly _tag: "Result";
8
8
  readonly error: undefined;
9
9
  readonly result: import("mongodb").DeleteResult;
@@ -6,11 +6,7 @@ const common_1 = require("@aeriajs/common");
6
6
  const security_1 = require("@aeriajs/security");
7
7
  const index_js_1 = require("../collection/index.js");
8
8
  const internalRemoveAll = async (payload, context) => {
9
- const filters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)({
10
- _id: {
11
- $in: payload.filters,
12
- },
13
- }, context.description, {
9
+ const filters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(payload.filters, context.description, {
14
10
  autoCast: true,
15
11
  context,
16
12
  }));
@@ -21,7 +17,14 @@ const internalRemoveAll = async (payload, context) => {
21
17
  }
22
18
  return types_1.Result.result(await context.collection.model.deleteMany(filters));
23
19
  };
24
- const removeAll = async (payload, context, options = {}) => {
20
+ const removeAll = async (_payload, context, options = {}) => {
21
+ const payload = {
22
+ filters: {
23
+ _id: {
24
+ $in: _payload.filters,
25
+ },
26
+ },
27
+ };
25
28
  if (options.bypassSecurity) {
26
29
  return internalRemoveAll(payload, context);
27
30
  }
@@ -4,11 +4,7 @@ import { throwIfError } from "@aeriajs/common";
4
4
  import { useSecurity } from "@aeriajs/security";
5
5
  import { traverseDocument, cascadingRemove } from "../collection/index.mjs";
6
6
  const internalRemoveAll = async (payload, context) => {
7
- const filters = throwIfError(await traverseDocument({
8
- _id: {
9
- $in: payload.filters
10
- }
11
- }, context.description, {
7
+ const filters = throwIfError(await traverseDocument(payload.filters, context.description, {
12
8
  autoCast: true,
13
9
  context
14
10
  }));
@@ -19,7 +15,14 @@ const internalRemoveAll = async (payload, context) => {
19
15
  }
20
16
  return Result.result(await context.collection.model.deleteMany(filters));
21
17
  };
22
- export const removeAll = async (payload, context, options = {}) => {
18
+ export const removeAll = async (_payload, context, options = {}) => {
19
+ const payload = {
20
+ filters: {
21
+ _id: {
22
+ $in: _payload.filters
23
+ }
24
+ }
25
+ };
23
26
  if (options.bypassSecurity) {
24
27
  return internalRemoveAll(payload, context);
25
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.239",
3
+ "version": "0.0.241",
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.239",
46
- "@aeriajs/common": "^0.0.135",
47
- "@aeriajs/entrypoint": "^0.0.139",
48
- "@aeriajs/http": "^0.0.163",
49
- "@aeriajs/security": "^0.0.239",
50
- "@aeriajs/types": "^0.0.117",
51
- "@aeriajs/validation": "^0.0.151"
45
+ "@aeriajs/builtins": "^0.0.241",
46
+ "@aeriajs/common": "^0.0.136",
47
+ "@aeriajs/entrypoint": "^0.0.140",
48
+ "@aeriajs/http": "^0.0.164",
49
+ "@aeriajs/security": "^0.0.241",
50
+ "@aeriajs/types": "^0.0.118",
51
+ "@aeriajs/validation": "^0.0.152"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",
@@ -65,6 +65,6 @@
65
65
  "build:cjs": "tsc",
66
66
  "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
67
67
  "build:esm-transform": "pnpm -w esm-transform $PWD/dist",
68
- "postinstall": "node dist/__scripts__/postinstall.js || true"
68
+ "postinstall": "if test -f dist/__scripts__/postinstall.js; then node dist/__scripts__/postinstall.js; fi"
69
69
  }
70
70
  }