@aeriajs/core 0.0.191 → 0.0.193
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/collection/reference.d.ts +1 -1
- package/dist/collection/traverseDocument.d.ts +1 -1
- package/dist/collection/traverseDocument.js +19 -10
- package/dist/collection/traverseDocument.mjs +19 -8
- package/dist/functions/count.d.ts +1 -1
- package/dist/functions/count.js +1 -1
- package/dist/functions/count.mjs +1 -1
- package/dist/functions/get.d.ts +1 -1
- package/dist/functions/get.js +1 -1
- package/dist/functions/get.mjs +1 -1
- package/dist/functions/getAll.d.ts +1 -1
- package/dist/functions/getAll.js +1 -1
- package/dist/functions/getAll.mjs +1 -1
- package/package.json +8 -8
|
@@ -25,7 +25,7 @@ export type BuildLookupPipelineOptions = {
|
|
|
25
25
|
memoize?: string;
|
|
26
26
|
project?: string[];
|
|
27
27
|
};
|
|
28
|
-
export declare const getReferences: (properties: FixedObjectProperty["properties"], options?: GetReferenceOptions) => Promise<
|
|
28
|
+
export declare const getReferences: (properties: FixedObjectProperty["properties"], options?: GetReferenceOptions) => Promise<ReferenceMap>;
|
|
29
29
|
export declare const recurseSetStage: (reference: Reference, path: string[], parentElem: {}, options?: {
|
|
30
30
|
noCond: boolean;
|
|
31
31
|
}) => Document;
|
|
@@ -7,7 +7,7 @@ export type TraverseOptionsBase = {
|
|
|
7
7
|
validateWholeness?: boolean | 'deep';
|
|
8
8
|
fromProperties?: boolean;
|
|
9
9
|
allowOperators?: boolean;
|
|
10
|
-
|
|
10
|
+
noRegExpEscaping?: boolean;
|
|
11
11
|
undefinedToNull?: boolean;
|
|
12
12
|
preserveHidden?: boolean;
|
|
13
13
|
recurseDeep?: boolean;
|
|
@@ -28,7 +28,6 @@ const types_1 = require("@aeriajs/types");
|
|
|
28
28
|
const common_1 = require("@aeriajs/common");
|
|
29
29
|
const validation_1 = require("@aeriajs/validation");
|
|
30
30
|
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
31
|
-
const security_1 = require("@aeriajs/security");
|
|
32
31
|
const mongodb_1 = require("mongodb");
|
|
33
32
|
const assets_js_1 = require("../assets.js");
|
|
34
33
|
const context_js_1 = require("../context.js");
|
|
@@ -37,6 +36,9 @@ const reference_js_1 = require("./reference.js");
|
|
|
37
36
|
const cascadingRemove_js_1 = require("./cascadingRemove.js");
|
|
38
37
|
const path = __importStar(require("path"));
|
|
39
38
|
const fs = __importStar(require("fs/promises"));
|
|
39
|
+
const escapeRegExp = (text) => {
|
|
40
|
+
return text.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
|
|
41
|
+
};
|
|
40
42
|
const getProperty = (propName, parentProperty) => {
|
|
41
43
|
if (propName === '_id') {
|
|
42
44
|
return {
|
|
@@ -86,9 +88,10 @@ const cleanupReferences = async (value, ctx) => {
|
|
|
86
88
|
return value;
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
|
-
const refMap = await (0, reference_js_1.getReferences)(
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const refMap = await (0, reference_js_1.getReferences)({
|
|
92
|
+
[ctx.propName]: ctx.property,
|
|
93
|
+
});
|
|
94
|
+
await (0, cascadingRemove_js_1.preferredRemove)(referenceIds, refMap[ctx.propName], await (0, context_js_1.createContext)({
|
|
92
95
|
parentContext: context,
|
|
93
96
|
collectionName: refProperty.$ref,
|
|
94
97
|
}));
|
|
@@ -270,7 +273,7 @@ const recurse = async (target, ctx) => {
|
|
|
270
273
|
...ctx.property.properties,
|
|
271
274
|
}
|
|
272
275
|
: target;
|
|
273
|
-
for (const propName in entrypoint) {
|
|
276
|
+
entrypoint: for (const propName in entrypoint) {
|
|
274
277
|
const value = target[propName];
|
|
275
278
|
const property = getProperty(propName, ctx.property);
|
|
276
279
|
if (propName === '_id') {
|
|
@@ -312,11 +315,17 @@ const recurse = async (target, ctx) => {
|
|
|
312
315
|
if (!ctx.options.allowOperators) {
|
|
313
316
|
return types_1.Result.error(types_1.ACError.InsecureOperator);
|
|
314
317
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
318
|
+
if (key === '$regex' && typeof value[key] === 'string') {
|
|
319
|
+
if (!ctx.options.noRegExpEscaping) {
|
|
320
|
+
entries.push([
|
|
321
|
+
propName,
|
|
322
|
+
{
|
|
323
|
+
...value,
|
|
324
|
+
$regex: escapeRegExp(value[key]),
|
|
325
|
+
},
|
|
326
|
+
]);
|
|
327
|
+
continue entrypoint;
|
|
328
|
+
}
|
|
320
329
|
}
|
|
321
330
|
}
|
|
322
331
|
}
|
|
@@ -3,7 +3,6 @@ import { Result, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/ty
|
|
|
3
3
|
import { throwIfError, pipe, isReference, getReferenceProperty, getValueFromPath, isError } from "@aeriajs/common";
|
|
4
4
|
import { makeValidationError, validateProperty, validateWholeness } from "@aeriajs/validation";
|
|
5
5
|
import { getCollection } from "@aeriajs/entrypoint";
|
|
6
|
-
import { INSECURE_OPERATORS } from "@aeriajs/security";
|
|
7
6
|
import { ObjectId } from "mongodb";
|
|
8
7
|
import { getCollectionAsset } from "../assets.mjs";
|
|
9
8
|
import { createContext } from "../context.mjs";
|
|
@@ -12,6 +11,9 @@ import { getReferences } from "./reference.mjs";
|
|
|
12
11
|
import { preferredRemove } from "./cascadingRemove.mjs";
|
|
13
12
|
import * as path from "path";
|
|
14
13
|
import * as fs from "fs/promises";
|
|
14
|
+
const escapeRegExp = (text) => {
|
|
15
|
+
return text.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
|
16
|
+
};
|
|
15
17
|
const getProperty = (propName, parentProperty) => {
|
|
16
18
|
if (propName === "_id") {
|
|
17
19
|
return {
|
|
@@ -60,9 +62,10 @@ const cleanupReferences = async (value, ctx) => {
|
|
|
60
62
|
return value;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
const refMap = await getReferences(
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const refMap = await getReferences({
|
|
66
|
+
[ctx.propName]: ctx.property
|
|
67
|
+
});
|
|
68
|
+
await preferredRemove(referenceIds, refMap[ctx.propName], await createContext({
|
|
66
69
|
parentContext: context,
|
|
67
70
|
collectionName: refProperty.$ref
|
|
68
71
|
}));
|
|
@@ -235,7 +238,7 @@ const recurse = async (target, ctx) => {
|
|
|
235
238
|
_id: null,
|
|
236
239
|
...ctx.property.properties
|
|
237
240
|
} : target;
|
|
238
|
-
for (const propName in entrypoint) {
|
|
241
|
+
entrypoint: for (const propName in entrypoint) {
|
|
239
242
|
const value = target[propName];
|
|
240
243
|
const property = getProperty(propName, ctx.property);
|
|
241
244
|
if (propName === "_id") {
|
|
@@ -276,9 +279,17 @@ const recurse = async (target, ctx) => {
|
|
|
276
279
|
if (!ctx.options.allowOperators) {
|
|
277
280
|
return Result.error(ACError.InsecureOperator);
|
|
278
281
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
+
if (key === "$regex" && typeof value[key] === "string") {
|
|
283
|
+
if (!ctx.options.noRegExpEscaping) {
|
|
284
|
+
entries.push([
|
|
285
|
+
propName,
|
|
286
|
+
{
|
|
287
|
+
...value,
|
|
288
|
+
$regex: escapeRegExp(value[key])
|
|
289
|
+
}
|
|
290
|
+
]);
|
|
291
|
+
continue entrypoint;
|
|
292
|
+
}
|
|
282
293
|
}
|
|
283
294
|
}
|
|
284
295
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, CountPayload, CountReturnType } from '@aeriajs/types';
|
|
2
2
|
export type CountOptions = {
|
|
3
3
|
bypassSecurity?: boolean;
|
|
4
|
-
|
|
4
|
+
noRegExpEscaping?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context ? TContext : never, options?: CountOptions) => Promise<CountReturnType>;
|
package/dist/functions/count.js
CHANGED
|
@@ -16,7 +16,7 @@ const internalCount = async (payload, context, options) => {
|
|
|
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
|
-
|
|
19
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
20
20
|
context,
|
|
21
21
|
}));
|
|
22
22
|
if ($text) {
|
package/dist/functions/count.mjs
CHANGED
|
@@ -12,7 +12,7 @@ const internalCount = async (payload, context, options) => {
|
|
|
12
12
|
const traversedFilters = throwIfError(await traverseDocument(filters, context.description, {
|
|
13
13
|
autoCast: true,
|
|
14
14
|
allowOperators: true,
|
|
15
|
-
|
|
15
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
16
16
|
context
|
|
17
17
|
}));
|
|
18
18
|
if ($text) {
|
package/dist/functions/get.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, GetPayload, GetReturnType } from '@aeriajs/types';
|
|
2
2
|
export type GetOptions = {
|
|
3
3
|
bypassSecurity?: boolean;
|
|
4
|
-
|
|
4
|
+
noRegExpEscaping?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: GetOptions) => Promise<GetReturnType<SchemaWithId<TContext["description"]>>>;
|
package/dist/functions/get.js
CHANGED
|
@@ -19,7 +19,7 @@ const internalGet = async (payload, context, options) => {
|
|
|
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
|
-
|
|
22
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
23
23
|
context,
|
|
24
24
|
});
|
|
25
25
|
if (filtersError) {
|
package/dist/functions/get.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const internalGet = async (payload, context, options) => {
|
|
|
25
25
|
const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
|
|
26
26
|
autoCast: true,
|
|
27
27
|
allowOperators: true,
|
|
28
|
-
|
|
28
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
29
29
|
context
|
|
30
30
|
});
|
|
31
31
|
if (filtersError) {
|
|
@@ -2,6 +2,6 @@ import type { Context, SchemaWithId, GetAllPayload, GetAllReturnType } from '@ae
|
|
|
2
2
|
export type GetAllOptions = {
|
|
3
3
|
bypassSecurity?: boolean;
|
|
4
4
|
noDefaultLimit?: boolean;
|
|
5
|
-
|
|
5
|
+
noRegExpEscaping?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<GetAllReturnType<SchemaWithId<TContext["description"]>>>;
|
package/dist/functions/getAll.js
CHANGED
|
@@ -42,7 +42,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
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
|
-
|
|
45
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
46
46
|
context,
|
|
47
47
|
});
|
|
48
48
|
if (filtersError) {
|
|
@@ -42,7 +42,7 @@ const internalGetAll = async (payload, context, options) => {
|
|
|
42
42
|
const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
|
|
43
43
|
autoCast: true,
|
|
44
44
|
allowOperators: true,
|
|
45
|
-
|
|
45
|
+
noRegExpEscaping: options.noRegExpEscaping,
|
|
46
46
|
context
|
|
47
47
|
});
|
|
48
48
|
if (filtersError) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.193",
|
|
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.
|
|
46
|
-
"@aeriajs/common": "^0.0.
|
|
47
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
48
|
-
"@aeriajs/http": "^0.0.
|
|
49
|
-
"@aeriajs/security": "^0.0.
|
|
50
|
-
"@aeriajs/types": "^0.0.
|
|
51
|
-
"@aeriajs/validation": "^0.0.
|
|
45
|
+
"@aeriajs/builtins": "^0.0.193",
|
|
46
|
+
"@aeriajs/common": "^0.0.119",
|
|
47
|
+
"@aeriajs/entrypoint": "^0.0.122",
|
|
48
|
+
"@aeriajs/http": "^0.0.133",
|
|
49
|
+
"@aeriajs/security": "^0.0.193",
|
|
50
|
+
"@aeriajs/types": "^0.0.102",
|
|
51
|
+
"@aeriajs/validation": "^0.0.122"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mongodb": "^6.5.0",
|