@aeriajs/core 0.0.137 → 0.0.139
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 -0
- package/dist/collection/reference.js +46 -31
- package/dist/collection/reference.mjs +43 -29
- package/dist/collection/traverseDocument.js +1 -1
- package/dist/collection/traverseDocument.mjs +1 -1
- package/dist/functions/{builtin/count.d.ts → count.d.ts} +8 -1
- package/dist/functions/{builtin/count.js → count.js} +16 -7
- package/dist/functions/{builtin/count.mjs → count.mjs} +15 -6
- package/dist/functions/{builtin/get.js → get.js} +18 -9
- package/dist/functions/{builtin/get.mjs → get.mjs} +18 -6
- package/dist/functions/getAll.d.ts +13 -0
- package/dist/functions/{builtin/getAll.js → getAll.js} +22 -13
- package/dist/functions/{builtin/getAll.mjs → getAll.mjs} +20 -9
- package/dist/functions/index.d.ts +8 -1
- package/dist/functions/index.js +8 -1
- package/dist/functions/index.mjs +8 -1
- package/dist/functions/{builtin/insert.d.ts → insert.d.ts} +5 -1
- package/dist/functions/{builtin/insert.js → insert.js} +14 -7
- package/dist/functions/{builtin/insert.mjs → insert.mjs} +14 -5
- package/dist/functions/{builtin/remove.d.ts → remove.d.ts} +9 -6
- package/dist/functions/{builtin/remove.js → remove.js} +16 -2
- package/dist/functions/{builtin/remove.mjs → remove.mjs} +17 -2
- package/dist/functions/{builtin/removeAll.d.ts → removeAll.d.ts} +4 -1
- package/dist/functions/{builtin/removeAll.js → removeAll.js} +16 -2
- package/dist/functions/removeAll.mjs +36 -0
- package/dist/functions/{builtin/removeFile.d.ts → removeFile.d.ts} +4 -1
- package/dist/functions/removeFile.js +24 -0
- package/dist/functions/removeFile.mjs +26 -0
- package/dist/functions/{builtin/upload.js → upload.js} +1 -2
- package/dist/functions/{builtin/upload.mjs → upload.mjs} +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.mjs +1 -2
- package/package.json +8 -8
- package/dist/functions/builtin/getAll.d.ts +0 -9
- package/dist/functions/builtin/index.d.ts +0 -8
- package/dist/functions/builtin/index.js +0 -24
- package/dist/functions/builtin/index.mjs +0 -9
- package/dist/functions/builtin/removeAll.mjs +0 -21
- package/dist/functions/builtin/removeFile.js +0 -17
- package/dist/functions/builtin/removeFile.mjs +0 -18
- /package/dist/functions/{builtin/get.d.ts → get.d.ts} +0 -0
- /package/dist/functions/{builtin/upload.d.ts → upload.d.ts} +0 -0
|
@@ -67,7 +67,7 @@ const buildArrayCleanupStages = (referenceMap) => {
|
|
|
67
67
|
: null;
|
|
68
68
|
};
|
|
69
69
|
const getReferences = async (properties, options) => {
|
|
70
|
-
const { depth = 0, memoize, } = options || {};
|
|
70
|
+
const { depth = 0, maxDepth = 3, memoize, } = options || {};
|
|
71
71
|
if (memoize) {
|
|
72
72
|
if (referenceMemo[memoize]) {
|
|
73
73
|
return referenceMemo[memoize];
|
|
@@ -77,10 +77,25 @@ const getReferences = async (properties, options) => {
|
|
|
77
77
|
for (const [propName, property] of Object.entries(properties)) {
|
|
78
78
|
const refProperty = (0, common_1.getReferenceProperty)(property);
|
|
79
79
|
const reference = {};
|
|
80
|
-
if (depth ===
|
|
80
|
+
if (depth === maxDepth || (refProperty && refProperty.populate && refProperty.populate.length === 0)) {
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
if (
|
|
83
|
+
if (refProperty) {
|
|
84
|
+
const description = (0, common_1.throwIfError)(await (0, assets_js_1.getCollectionAsset)(refProperty.$ref, 'description'));
|
|
85
|
+
const deepReferences = await (0, exports.getReferences)(description.properties, {
|
|
86
|
+
depth: depth + 1,
|
|
87
|
+
maxDepth: refProperty.populateDepth || maxDepth,
|
|
88
|
+
memoize: `${memoize}.${propName}`,
|
|
89
|
+
});
|
|
90
|
+
if (Object.keys(deepReferences).length > 0) {
|
|
91
|
+
reference.deepReferences = deepReferences;
|
|
92
|
+
}
|
|
93
|
+
const indexes = refProperty.indexes
|
|
94
|
+
? refProperty.indexes
|
|
95
|
+
: description.indexes || [];
|
|
96
|
+
reference.populatedProperties = (refProperty.populate || []).concat(indexes.filter((index) => typeof index === 'string'));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
84
99
|
const entrypoint = 'items' in property
|
|
85
100
|
? property.items
|
|
86
101
|
: property;
|
|
@@ -91,7 +106,6 @@ const getReferences = async (properties, options) => {
|
|
|
91
106
|
// }
|
|
92
107
|
if ('properties' in entrypoint) {
|
|
93
108
|
const deepReferences = await (0, exports.getReferences)(entrypoint.properties, {
|
|
94
|
-
depth: depth + 1,
|
|
95
109
|
memoize: `${memoize}.${propName}`,
|
|
96
110
|
});
|
|
97
111
|
if (Object.keys(deepReferences).length > 0) {
|
|
@@ -100,20 +114,6 @@ const getReferences = async (properties, options) => {
|
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
|
-
else {
|
|
104
|
-
const description = (0, common_1.throwIfError)(await (0, assets_js_1.getCollectionAsset)(refProperty.$ref, 'description'));
|
|
105
|
-
const deepReferences = await (0, exports.getReferences)(description.properties, {
|
|
106
|
-
depth: depth + 1,
|
|
107
|
-
memoize: `${memoize}.${propName}`,
|
|
108
|
-
});
|
|
109
|
-
if (Object.keys(deepReferences).length > 0) {
|
|
110
|
-
reference.deepReferences = deepReferences;
|
|
111
|
-
}
|
|
112
|
-
const indexes = refProperty.indexes
|
|
113
|
-
? refProperty.indexes
|
|
114
|
-
: description.indexes || [];
|
|
115
|
-
reference.populatedProperties = (refProperty.populate || []).concat(indexes.filter((index) => typeof index === 'string'));
|
|
116
|
-
}
|
|
117
117
|
if (!refProperty?.$ref && !reference.deepReferences) {
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
@@ -216,12 +216,14 @@ const buildLookupStages = async (reference, propName, options) => {
|
|
|
216
216
|
}
|
|
217
217
|
else if (reference.deepReferences && depth <= maxDepth) {
|
|
218
218
|
refHasDeepReferences = true;
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
if (reference.isArray) {
|
|
220
|
+
stages.push({
|
|
221
|
+
$unwind: {
|
|
222
|
+
path: `$${withParent(propName)}`,
|
|
223
|
+
preserveNullAndEmptyArrays: true,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
225
227
|
for (const [refName, refMap] of Object.entries(reference.deepReferences)) {
|
|
226
228
|
if (!refMap) {
|
|
227
229
|
continue;
|
|
@@ -237,15 +239,28 @@ const buildLookupStages = async (reference, propName, options) => {
|
|
|
237
239
|
continue;
|
|
238
240
|
}
|
|
239
241
|
const refProperties = properties[propName];
|
|
240
|
-
if (
|
|
242
|
+
if ('properties' in refProperties) {
|
|
243
|
+
const { stages: refStages } = await buildLookupStages(refMap, refName, {
|
|
244
|
+
depth: depth + 1,
|
|
245
|
+
parent: withParent(propName),
|
|
246
|
+
properties: refProperties.properties,
|
|
247
|
+
});
|
|
248
|
+
stages.push(...refStages);
|
|
249
|
+
}
|
|
250
|
+
else if ('items' in refProperties) {
|
|
251
|
+
if (!('properties' in refProperties.items)) {
|
|
252
|
+
throw new Error();
|
|
253
|
+
}
|
|
254
|
+
const { stages: refStages } = await buildLookupStages(refMap, refName, {
|
|
255
|
+
depth: depth + 1,
|
|
256
|
+
parent: withParent(propName),
|
|
257
|
+
properties: refProperties.items.properties,
|
|
258
|
+
});
|
|
259
|
+
stages.push(...refStages);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
241
262
|
throw new Error();
|
|
242
263
|
}
|
|
243
|
-
const { stages: result } = await buildLookupStages(refMap, refName, {
|
|
244
|
-
depth: depth + 1,
|
|
245
|
-
parent: withParent(propName),
|
|
246
|
-
properties: refProperties.properties,
|
|
247
|
-
});
|
|
248
|
-
stages.push(...result);
|
|
249
264
|
}
|
|
250
265
|
}
|
|
251
266
|
return {
|
|
@@ -63,6 +63,7 @@ const buildArrayCleanupStages = (referenceMap) => {
|
|
|
63
63
|
export const getReferences = async (properties, options) => {
|
|
64
64
|
const {
|
|
65
65
|
depth = 0,
|
|
66
|
+
maxDepth = 3,
|
|
66
67
|
memoize
|
|
67
68
|
} = options || {};
|
|
68
69
|
if (memoize) {
|
|
@@ -74,25 +75,14 @@ export const getReferences = async (properties, options) => {
|
|
|
74
75
|
for (const [propName, property] of Object.entries(properties)) {
|
|
75
76
|
const refProperty = getReferenceProperty(property);
|
|
76
77
|
const reference = {};
|
|
77
|
-
if (depth ===
|
|
78
|
+
if (depth === maxDepth || refProperty && refProperty.populate && refProperty.populate.length === 0) {
|
|
78
79
|
continue;
|
|
79
80
|
}
|
|
80
|
-
if (
|
|
81
|
-
const entrypoint = "items" in property ? property.items : property;
|
|
82
|
-
if ("properties" in entrypoint) {
|
|
83
|
-
const deepReferences = await getReferences(entrypoint.properties, {
|
|
84
|
-
depth: depth + 1,
|
|
85
|
-
memoize: `${memoize}.${propName}`
|
|
86
|
-
});
|
|
87
|
-
if (Object.keys(deepReferences).length > 0) {
|
|
88
|
-
reference.deepReferences ??= {};
|
|
89
|
-
reference.deepReferences = deepReferences;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
81
|
+
if (refProperty) {
|
|
93
82
|
const description = throwIfError(await getCollectionAsset(refProperty.$ref, "description"));
|
|
94
83
|
const deepReferences = await getReferences(description.properties, {
|
|
95
84
|
depth: depth + 1,
|
|
85
|
+
maxDepth: refProperty.populateDepth || maxDepth,
|
|
96
86
|
memoize: `${memoize}.${propName}`
|
|
97
87
|
});
|
|
98
88
|
if (Object.keys(deepReferences).length > 0) {
|
|
@@ -100,6 +90,17 @@ export const getReferences = async (properties, options) => {
|
|
|
100
90
|
}
|
|
101
91
|
const indexes = refProperty.indexes ? refProperty.indexes : description.indexes || [];
|
|
102
92
|
reference.populatedProperties = (refProperty.populate || []).concat(indexes.filter((index) => typeof index === "string"));
|
|
93
|
+
} else {
|
|
94
|
+
const entrypoint = "items" in property ? property.items : property;
|
|
95
|
+
if ("properties" in entrypoint) {
|
|
96
|
+
const deepReferences = await getReferences(entrypoint.properties, {
|
|
97
|
+
memoize: `${memoize}.${propName}`
|
|
98
|
+
});
|
|
99
|
+
if (Object.keys(deepReferences).length > 0) {
|
|
100
|
+
reference.deepReferences ??= {};
|
|
101
|
+
reference.deepReferences = deepReferences;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
if (!refProperty?.$ref && !reference.deepReferences) {
|
|
105
106
|
continue;
|
|
@@ -199,36 +200,49 @@ const buildLookupStages = async (reference, propName, options) => {
|
|
|
199
200
|
}
|
|
200
201
|
} else if (reference.deepReferences && depth <= maxDepth) {
|
|
201
202
|
refHasDeepReferences = true;
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
203
|
+
if (reference.isArray) {
|
|
204
|
+
stages.push({
|
|
205
|
+
$unwind: {
|
|
206
|
+
path: `$${withParent(propName)}`,
|
|
207
|
+
preserveNullAndEmptyArrays: true
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
208
211
|
for (const [refName, refMap] of Object.entries(reference.deepReferences)) {
|
|
209
212
|
if (!refMap) {
|
|
210
213
|
continue;
|
|
211
214
|
}
|
|
212
215
|
if (refMap.referencedCollection) {
|
|
213
216
|
const description = throwIfError(await getCollectionAsset(refMap.referencedCollection, "description"));
|
|
214
|
-
const { stages:
|
|
217
|
+
const { stages: result } = await buildLookupStages(refMap, refName, {
|
|
215
218
|
depth: depth + 1,
|
|
216
219
|
parent: withParent(propName),
|
|
217
220
|
properties: description.properties
|
|
218
221
|
});
|
|
219
|
-
stages.push(...
|
|
222
|
+
stages.push(...result);
|
|
220
223
|
continue;
|
|
221
224
|
}
|
|
222
225
|
const refProperties = properties[propName];
|
|
223
|
-
if (
|
|
226
|
+
if ("properties" in refProperties) {
|
|
227
|
+
const { stages: refStages } = await buildLookupStages(refMap, refName, {
|
|
228
|
+
depth: depth + 1,
|
|
229
|
+
parent: withParent(propName),
|
|
230
|
+
properties: refProperties.properties
|
|
231
|
+
});
|
|
232
|
+
stages.push(...refStages);
|
|
233
|
+
} else if ("items" in refProperties) {
|
|
234
|
+
if (!("properties" in refProperties.items)) {
|
|
235
|
+
throw new Error();
|
|
236
|
+
}
|
|
237
|
+
const { stages: refStages } = await buildLookupStages(refMap, refName, {
|
|
238
|
+
depth: depth + 1,
|
|
239
|
+
parent: withParent(propName),
|
|
240
|
+
properties: refProperties.items.properties
|
|
241
|
+
});
|
|
242
|
+
stages.push(...refStages);
|
|
243
|
+
} else {
|
|
224
244
|
throw new Error();
|
|
225
245
|
}
|
|
226
|
-
const { stages: result } = await buildLookupStages(refMap, refName, {
|
|
227
|
-
depth: depth + 1,
|
|
228
|
-
parent: withParent(propName),
|
|
229
|
-
properties: refProperties.properties
|
|
230
|
-
});
|
|
231
|
-
stages.push(...result);
|
|
232
246
|
}
|
|
233
247
|
}
|
|
234
248
|
return {
|
|
@@ -40,7 +40,7 @@ const getProperty = (propertyName, parentProperty) => {
|
|
|
40
40
|
if ('items' in parentProperty && 'properties' in parentProperty.items && propertyName in parentProperty.items.properties) {
|
|
41
41
|
return parentProperty.items.properties[propertyName];
|
|
42
42
|
}
|
|
43
|
-
if ('additionalProperties' in parentProperty) {
|
|
43
|
+
if ('additionalProperties' in parentProperty && typeof parentProperty.additionalProperties === 'object') {
|
|
44
44
|
return parentProperty.additionalProperties;
|
|
45
45
|
}
|
|
46
46
|
if ('properties' in parentProperty) {
|
|
@@ -15,7 +15,7 @@ const getProperty = (propertyName, parentProperty) => {
|
|
|
15
15
|
if ("items" in parentProperty && "properties" in parentProperty.items && propertyName in parentProperty.items.properties) {
|
|
16
16
|
return parentProperty.items.properties[propertyName];
|
|
17
17
|
}
|
|
18
|
-
if ("additionalProperties" in parentProperty) {
|
|
18
|
+
if ("additionalProperties" in parentProperty && typeof parentProperty.additionalProperties === "object") {
|
|
19
19
|
return parentProperty.additionalProperties;
|
|
20
20
|
}
|
|
21
21
|
if ("properties" in parentProperty) {
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, CountPayload } from '@aeriajs/types';
|
|
2
|
-
export
|
|
2
|
+
export type CountOptions = {
|
|
3
|
+
bypassSecurity?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never, options?: CountOptions) => Promise<{
|
|
3
6
|
readonly _tag: "Result";
|
|
4
7
|
readonly error: undefined;
|
|
5
8
|
readonly result: any;
|
|
9
|
+
} | {
|
|
10
|
+
readonly _tag: "Error";
|
|
11
|
+
readonly error: import("@aeriajs/types").ACError.InvalidLimit;
|
|
12
|
+
readonly result: undefined;
|
|
6
13
|
}>;
|
|
@@ -4,13 +4,11 @@ exports.count = void 0;
|
|
|
4
4
|
const security_1 = require("@aeriajs/security");
|
|
5
5
|
const types_1 = require("@aeriajs/types");
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
|
-
const index_js_1 = require("
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const $text = '$text' in sanitizedPayload.filters
|
|
13
|
-
? sanitizedPayload.filters.$text
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
|
+
const internalCount = async (payload, context) => {
|
|
9
|
+
const { filters = {} } = payload;
|
|
10
|
+
const $text = '$text' in filters
|
|
11
|
+
? filters.$text
|
|
14
12
|
: undefined;
|
|
15
13
|
if ('$text' in filters) {
|
|
16
14
|
delete filters.$text;
|
|
@@ -39,4 +37,15 @@ const count = async (payload, context) => {
|
|
|
39
37
|
}
|
|
40
38
|
return types_1.Result.result(await context.collection.model.countDocuments(traversedFilters));
|
|
41
39
|
};
|
|
40
|
+
const count = async (payload, context, options = {}) => {
|
|
41
|
+
if (options.bypassSecurity) {
|
|
42
|
+
return internalCount(payload, context);
|
|
43
|
+
}
|
|
44
|
+
const security = (0, security_1.useSecurity)(context);
|
|
45
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
46
|
+
if (error) {
|
|
47
|
+
return types_1.Result.error(error);
|
|
48
|
+
}
|
|
49
|
+
return internalCount(securedPayload, context);
|
|
50
|
+
};
|
|
42
51
|
exports.count = count;
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
import { useSecurity } from "@aeriajs/security";
|
|
3
3
|
import { Result } from "@aeriajs/types";
|
|
4
4
|
import { throwIfError } from "@aeriajs/common";
|
|
5
|
-
import { traverseDocument } from "
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const filters = sanitizedPayload.filters;
|
|
10
|
-
const $text = "$text" in sanitizedPayload.filters ? sanitizedPayload.filters.$text : void 0;
|
|
5
|
+
import { traverseDocument } from "../collection/index.mjs";
|
|
6
|
+
const internalCount = async (payload, context) => {
|
|
7
|
+
const { filters = {} } = payload;
|
|
8
|
+
const $text = "$text" in filters ? filters.$text : void 0;
|
|
11
9
|
if ("$text" in filters) {
|
|
12
10
|
delete filters.$text;
|
|
13
11
|
}
|
|
@@ -33,3 +31,14 @@ export const count = async (payload, context) => {
|
|
|
33
31
|
}
|
|
34
32
|
return Result.result(await context.collection.model.countDocuments(traversedFilters));
|
|
35
33
|
};
|
|
34
|
+
export const count = async (payload, context, options = {}) => {
|
|
35
|
+
if (options.bypassSecurity) {
|
|
36
|
+
return internalCount(payload, context);
|
|
37
|
+
}
|
|
38
|
+
const security = useSecurity(context);
|
|
39
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
40
|
+
if (error) {
|
|
41
|
+
return Result.error(error);
|
|
42
|
+
}
|
|
43
|
+
return internalCount(securedPayload, context);
|
|
44
|
+
};
|
|
@@ -4,13 +4,9 @@ exports.get = void 0;
|
|
|
4
4
|
const security_1 = require("@aeriajs/security");
|
|
5
5
|
const types_1 = require("@aeriajs/types");
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
|
-
const index_js_1 = require("
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const sanitizedPayload = !options?.bypassSecurity
|
|
11
|
-
? (0, common_1.throwIfError)(await security.beforeRead(payload))
|
|
12
|
-
: payload;
|
|
13
|
-
const { filters = {}, project = [], } = sanitizedPayload;
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
|
+
const internalGet = async (payload, context) => {
|
|
9
|
+
const { filters = {}, project = [], } = payload;
|
|
14
10
|
if (Object.keys(filters).length === 0) {
|
|
15
11
|
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
16
12
|
code: types_1.ACError.MalformedInput,
|
|
@@ -34,8 +30,8 @@ const get = async (payload, context, options) => {
|
|
|
34
30
|
}
|
|
35
31
|
pipeline.push(...await (0, index_js_1.buildLookupPipeline)(references, {
|
|
36
32
|
memoize: context.description.$id,
|
|
37
|
-
project:
|
|
38
|
-
?
|
|
33
|
+
project: payload.populate
|
|
34
|
+
? payload.populate
|
|
39
35
|
: project,
|
|
40
36
|
properties: context.description.properties,
|
|
41
37
|
}));
|
|
@@ -53,4 +49,17 @@ const get = async (payload, context, options) => {
|
|
|
53
49
|
})), context.description);
|
|
54
50
|
return types_1.Result.result(result);
|
|
55
51
|
};
|
|
52
|
+
const get = async (payload, context, options = {}) => {
|
|
53
|
+
if (options.bypassSecurity) {
|
|
54
|
+
return internalGet(payload, context);
|
|
55
|
+
}
|
|
56
|
+
const security = (0, security_1.useSecurity)(context);
|
|
57
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
58
|
+
if (error) {
|
|
59
|
+
switch (error) {
|
|
60
|
+
case types_1.ACError.InvalidLimit: throw new Error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return internalGet(securedPayload, context);
|
|
64
|
+
};
|
|
56
65
|
exports.get = get;
|
|
@@ -8,14 +8,12 @@ import {
|
|
|
8
8
|
getReferences,
|
|
9
9
|
buildLookupPipeline,
|
|
10
10
|
fill
|
|
11
|
-
} from "
|
|
12
|
-
|
|
13
|
-
const security = useSecurity(context);
|
|
14
|
-
const sanitizedPayload = !options?.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
|
|
11
|
+
} from "../collection/index.mjs";
|
|
12
|
+
const internalGet = async (payload, context) => {
|
|
15
13
|
const {
|
|
16
14
|
filters = {},
|
|
17
15
|
project = []
|
|
18
|
-
} =
|
|
16
|
+
} = payload;
|
|
19
17
|
if (Object.keys(filters).length === 0) {
|
|
20
18
|
return context.error(HTTPStatus.BadRequest, {
|
|
21
19
|
code: ACError.MalformedInput
|
|
@@ -39,7 +37,7 @@ export const get = async (payload, context, options) => {
|
|
|
39
37
|
}
|
|
40
38
|
pipeline.push(...await buildLookupPipeline(references, {
|
|
41
39
|
memoize: context.description.$id,
|
|
42
|
-
project:
|
|
40
|
+
project: payload.populate ? payload.populate : project,
|
|
43
41
|
properties: context.description.properties
|
|
44
42
|
}));
|
|
45
43
|
const doc = await context.collection.model.aggregate(pipeline).next();
|
|
@@ -56,3 +54,17 @@ export const get = async (payload, context, options) => {
|
|
|
56
54
|
})), context.description);
|
|
57
55
|
return Result.result(result);
|
|
58
56
|
};
|
|
57
|
+
export const get = async (payload, context, options = {}) => {
|
|
58
|
+
if (options.bypassSecurity) {
|
|
59
|
+
return internalGet(payload, context);
|
|
60
|
+
}
|
|
61
|
+
const security = useSecurity(context);
|
|
62
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
63
|
+
if (error) {
|
|
64
|
+
switch (error) {
|
|
65
|
+
case ACError.InvalidLimit:
|
|
66
|
+
throw new Error();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return internalGet(securedPayload, context);
|
|
70
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
|
|
2
|
+
export type GetAllOptions = {
|
|
3
|
+
bypassSecurity?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<{
|
|
6
|
+
readonly _tag: "Error";
|
|
7
|
+
readonly error: import("@aeriajs/types").ACError.InvalidLimit;
|
|
8
|
+
readonly result: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
readonly _tag: "Result";
|
|
11
|
+
readonly error: undefined;
|
|
12
|
+
readonly result: SchemaWithId<TContext["description"]>[];
|
|
13
|
+
}>;
|
|
@@ -4,17 +4,12 @@ exports.getAll = void 0;
|
|
|
4
4
|
const security_1 = require("@aeriajs/security");
|
|
5
5
|
const types_1 = require("@aeriajs/types");
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
|
-
const index_js_1 = require("
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
?
|
|
13
|
-
: payload;
|
|
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
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
|
+
const internalGetAll = async (payload, context) => {
|
|
9
|
+
const { limit = context.config.paginationLimit, sort, project = [], offset = 0, } = payload;
|
|
10
|
+
const filters = payload.filters || {};
|
|
11
|
+
const $text = payload.filters && '$text' in payload.filters
|
|
12
|
+
? payload.filters.$text
|
|
18
13
|
: undefined;
|
|
19
14
|
if ('$text' in filters) {
|
|
20
15
|
delete filters.$text;
|
|
@@ -66,8 +61,8 @@ const getAll = async (_payload, context, options = {}) => {
|
|
|
66
61
|
}
|
|
67
62
|
pipeline.push(...await (0, index_js_1.buildLookupPipeline)(references, {
|
|
68
63
|
memoize: context.description.$id,
|
|
69
|
-
project:
|
|
70
|
-
?
|
|
64
|
+
project: payload.populate
|
|
65
|
+
? payload.populate
|
|
71
66
|
: project,
|
|
72
67
|
properties: context.description.properties,
|
|
73
68
|
}));
|
|
@@ -88,4 +83,18 @@ const getAll = async (_payload, context, options = {}) => {
|
|
|
88
83
|
}
|
|
89
84
|
return types_1.Result.result(documents);
|
|
90
85
|
};
|
|
86
|
+
const getAll = async (payload, context, options = {}) => {
|
|
87
|
+
if (!payload) {
|
|
88
|
+
return internalGetAll({}, context);
|
|
89
|
+
}
|
|
90
|
+
if (options.bypassSecurity) {
|
|
91
|
+
return internalGetAll(payload, context);
|
|
92
|
+
}
|
|
93
|
+
const security = (0, security_1.useSecurity)(context);
|
|
94
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
95
|
+
if (error) {
|
|
96
|
+
return types_1.Result.error(error);
|
|
97
|
+
}
|
|
98
|
+
return internalGetAll(securedPayload, context);
|
|
99
|
+
};
|
|
91
100
|
exports.getAll = getAll;
|
|
@@ -8,19 +8,16 @@ import {
|
|
|
8
8
|
getReferences,
|
|
9
9
|
buildLookupPipeline,
|
|
10
10
|
fill
|
|
11
|
-
} from "
|
|
12
|
-
|
|
13
|
-
const security = useSecurity(context);
|
|
14
|
-
const payload = _payload || {};
|
|
15
|
-
const sanitizedPayload = !options.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
|
|
11
|
+
} from "../collection/index.mjs";
|
|
12
|
+
const internalGetAll = async (payload, context) => {
|
|
16
13
|
const {
|
|
17
14
|
limit = context.config.paginationLimit,
|
|
18
15
|
sort,
|
|
19
16
|
project = [],
|
|
20
17
|
offset = 0
|
|
21
|
-
} =
|
|
22
|
-
const filters =
|
|
23
|
-
const $text =
|
|
18
|
+
} = payload;
|
|
19
|
+
const filters = payload.filters || {};
|
|
20
|
+
const $text = payload.filters && "$text" in payload.filters ? payload.filters.$text : void 0;
|
|
24
21
|
if ("$text" in filters) {
|
|
25
22
|
delete filters.$text;
|
|
26
23
|
}
|
|
@@ -67,7 +64,7 @@ export const getAll = async (_payload, context, options = {}) => {
|
|
|
67
64
|
}
|
|
68
65
|
pipeline.push(...await buildLookupPipeline(references, {
|
|
69
66
|
memoize: context.description.$id,
|
|
70
|
-
project:
|
|
67
|
+
project: payload.populate ? payload.populate : project,
|
|
71
68
|
properties: context.description.properties
|
|
72
69
|
}));
|
|
73
70
|
if (Object.keys(references).length > 0 && preferredSort) {
|
|
@@ -87,3 +84,17 @@ export const getAll = async (_payload, context, options = {}) => {
|
|
|
87
84
|
}
|
|
88
85
|
return Result.result(documents);
|
|
89
86
|
};
|
|
87
|
+
export const getAll = async (payload, context, options = {}) => {
|
|
88
|
+
if (!payload) {
|
|
89
|
+
return internalGetAll({}, context);
|
|
90
|
+
}
|
|
91
|
+
if (options.bypassSecurity) {
|
|
92
|
+
return internalGetAll(payload, context);
|
|
93
|
+
}
|
|
94
|
+
const security = useSecurity(context);
|
|
95
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
96
|
+
if (error) {
|
|
97
|
+
return Result.error(error);
|
|
98
|
+
}
|
|
99
|
+
return internalGetAll(securedPayload, context);
|
|
100
|
+
};
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './count.js';
|
|
2
|
+
export * from './get.js';
|
|
3
|
+
export * from './getAll.js';
|
|
4
|
+
export * from './insert.js';
|
|
5
|
+
export * from './remove.js';
|
|
6
|
+
export * from './removeAll.js';
|
|
7
|
+
export * from './removeFile.js';
|
|
8
|
+
export * from './upload.js';
|
package/dist/functions/index.js
CHANGED
|
@@ -14,4 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./count.js"), exports);
|
|
18
|
+
__exportStar(require("./get.js"), exports);
|
|
19
|
+
__exportStar(require("./getAll.js"), exports);
|
|
20
|
+
__exportStar(require("./insert.js"), exports);
|
|
21
|
+
__exportStar(require("./remove.js"), exports);
|
|
22
|
+
__exportStar(require("./removeAll.js"), exports);
|
|
23
|
+
__exportStar(require("./removeFile.js"), exports);
|
|
24
|
+
__exportStar(require("./upload.js"), exports);
|
package/dist/functions/index.mjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./count.mjs";
|
|
3
|
+
export * from "./get.mjs";
|
|
4
|
+
export * from "./getAll.mjs";
|
|
5
|
+
export * from "./insert.mjs";
|
|
6
|
+
export * from "./remove.mjs";
|
|
7
|
+
export * from "./removeAll.mjs";
|
|
8
|
+
export * from "./removeFile.mjs";
|
|
9
|
+
export * from "./upload.mjs";
|
|
@@ -33,4 +33,8 @@ export declare const insertErrorSchema: () => {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext["description"]
|
|
36
|
+
export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext["description"]>> | {
|
|
37
|
+
readonly _tag: "Error";
|
|
38
|
+
readonly error: ACError;
|
|
39
|
+
readonly result: undefined;
|
|
40
|
+
}>;
|
|
@@ -4,7 +4,7 @@ exports.insert = exports.insertErrorSchema = void 0;
|
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const security_1 = require("@aeriajs/security");
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
|
-
const index_js_1 = require("
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
8
|
const insertErrorSchema = () => (0, common_1.endpointErrorSchema)({
|
|
9
9
|
httpStatus: [
|
|
10
10
|
types_1.HTTPStatus.UnprocessableContent,
|
|
@@ -23,12 +23,8 @@ const insertErrorSchema = () => (0, common_1.endpointErrorSchema)({
|
|
|
23
23
|
],
|
|
24
24
|
});
|
|
25
25
|
exports.insertErrorSchema = insertErrorSchema;
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const query = !options?.bypassSecurity
|
|
29
|
-
? (0, common_1.throwIfError)(await security.beforeWrite(payload))
|
|
30
|
-
: payload;
|
|
31
|
-
const { error, result: what } = await (0, index_js_1.traverseDocument)(query.what, context.description, {
|
|
26
|
+
const internalInsert = async (payload, context) => {
|
|
27
|
+
const { error, result: what } = await (0, index_js_1.traverseDocument)(payload.what, context.description, {
|
|
32
28
|
recurseDeep: true,
|
|
33
29
|
autoCast: true,
|
|
34
30
|
validate: true,
|
|
@@ -104,4 +100,15 @@ const insert = async (payload, context, options) => {
|
|
|
104
100
|
})), context.description);
|
|
105
101
|
return types_1.Result.result(result);
|
|
106
102
|
};
|
|
103
|
+
const insert = async (payload, context, options = {}) => {
|
|
104
|
+
if (options.bypassSecurity) {
|
|
105
|
+
return internalInsert(payload, context);
|
|
106
|
+
}
|
|
107
|
+
const security = (0, security_1.useSecurity)(context);
|
|
108
|
+
const { error, result: securedPayload } = await security.secureWritePayload(payload);
|
|
109
|
+
if (error) {
|
|
110
|
+
return types_1.Result.error(error);
|
|
111
|
+
}
|
|
112
|
+
return internalInsert(securedPayload, context);
|
|
113
|
+
};
|
|
107
114
|
exports.insert = insert;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Result, HTTPStatus, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
|
|
3
3
|
import { useSecurity } from "@aeriajs/security";
|
|
4
4
|
import { throwIfError, endpointErrorSchema } from "@aeriajs/common";
|
|
5
|
-
import { traverseDocument, normalizeProjection, prepareInsert, fill } from "
|
|
5
|
+
import { traverseDocument, normalizeProjection, prepareInsert, fill } from "../collection/index.mjs";
|
|
6
6
|
export const insertErrorSchema = () => endpointErrorSchema({
|
|
7
7
|
httpStatus: [
|
|
8
8
|
HTTPStatus.UnprocessableContent,
|
|
@@ -20,10 +20,8 @@ export const insertErrorSchema = () => endpointErrorSchema({
|
|
|
20
20
|
TraverseError.InvalidTempfile
|
|
21
21
|
]
|
|
22
22
|
});
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const query = !options?.bypassSecurity ? throwIfError(await security.beforeWrite(payload)) : payload;
|
|
26
|
-
const { error, result: what } = await traverseDocument(query.what, context.description, {
|
|
23
|
+
const internalInsert = async (payload, context) => {
|
|
24
|
+
const { error, result: what } = await traverseDocument(payload.what, context.description, {
|
|
27
25
|
recurseDeep: true,
|
|
28
26
|
autoCast: true,
|
|
29
27
|
validate: true,
|
|
@@ -91,3 +89,14 @@ export const insert = async (payload, context, options) => {
|
|
|
91
89
|
})), context.description);
|
|
92
90
|
return Result.result(result);
|
|
93
91
|
};
|
|
92
|
+
export const insert = async (payload, context, options = {}) => {
|
|
93
|
+
if (options.bypassSecurity) {
|
|
94
|
+
return internalInsert(payload, context);
|
|
95
|
+
}
|
|
96
|
+
const security = useSecurity(context);
|
|
97
|
+
const { error, result: securedPayload } = await security.secureWritePayload(payload);
|
|
98
|
+
if (error) {
|
|
99
|
+
return Result.error(error);
|
|
100
|
+
}
|
|
101
|
+
return internalInsert(securedPayload, context);
|
|
102
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
|
|
2
2
|
import { Result, HTTPStatus, ACError } from '@aeriajs/types';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
}> | {
|
|
3
|
+
export type RemoveOptions = {
|
|
4
|
+
bypassSecurity?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: RemoveOptions) => Promise<{
|
|
8
7
|
readonly _tag: "Result";
|
|
9
8
|
readonly error: undefined;
|
|
10
9
|
readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
|
|
11
|
-
}
|
|
10
|
+
} | Result.Error<{
|
|
11
|
+
readonly code: ACError.ResourceNotFound;
|
|
12
|
+
} & {
|
|
13
|
+
httpStatus: HTTPStatus.NotFound;
|
|
14
|
+
}>>;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.remove = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const common_1 = require("@aeriajs/common");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const security_1 = require("@aeriajs/security");
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
|
+
const internalRemove = async (payload, context) => {
|
|
8
9
|
if (!payload.filters._id) {
|
|
9
10
|
return context.error(types_1.HTTPStatus.NotFound, {
|
|
10
11
|
code: types_1.ACError.ResourceNotFound,
|
|
@@ -22,4 +23,17 @@ const remove = async (payload, context) => {
|
|
|
22
23
|
await (0, index_js_1.cascadingRemove)(target, context);
|
|
23
24
|
return types_1.Result.result(await context.collection.model.findOneAndDelete(filters));
|
|
24
25
|
};
|
|
26
|
+
const remove = async (payload, context, options = {}) => {
|
|
27
|
+
if (options.bypassSecurity) {
|
|
28
|
+
return internalRemove(payload, context);
|
|
29
|
+
}
|
|
30
|
+
const security = (0, security_1.useSecurity)(context);
|
|
31
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
32
|
+
if (error) {
|
|
33
|
+
switch (error) {
|
|
34
|
+
case types_1.ACError.InvalidLimit: throw new Error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return internalRemove(securedPayload, context);
|
|
38
|
+
};
|
|
25
39
|
exports.remove = remove;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
3
|
import { throwIfError } from "@aeriajs/common";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { useSecurity } from "@aeriajs/security";
|
|
5
|
+
import { traverseDocument, cascadingRemove } from "../collection/index.mjs";
|
|
6
|
+
const internalRemove = async (payload, context) => {
|
|
6
7
|
if (!payload.filters._id) {
|
|
7
8
|
return context.error(HTTPStatus.NotFound, {
|
|
8
9
|
code: ACError.ResourceNotFound
|
|
@@ -20,3 +21,17 @@ export const remove = async (payload, context) => {
|
|
|
20
21
|
await cascadingRemove(target, context);
|
|
21
22
|
return Result.result(await context.collection.model.findOneAndDelete(filters));
|
|
22
23
|
};
|
|
24
|
+
export const remove = async (payload, context, options = {}) => {
|
|
25
|
+
if (options.bypassSecurity) {
|
|
26
|
+
return internalRemove(payload, context);
|
|
27
|
+
}
|
|
28
|
+
const security = useSecurity(context);
|
|
29
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
30
|
+
if (error) {
|
|
31
|
+
switch (error) {
|
|
32
|
+
case ACError.InvalidLimit:
|
|
33
|
+
throw new Error();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return internalRemove(securedPayload, context);
|
|
37
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Context, RemoveAllPayload } from '@aeriajs/types';
|
|
2
|
-
export
|
|
2
|
+
export type RemoveAllOptions = {
|
|
3
|
+
bypassSecurity?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const removeAll: <TContext extends Context>(payload: RemoveAllPayload, context: TContext, options?: RemoveAllOptions) => Promise<{
|
|
3
6
|
readonly _tag: "Result";
|
|
4
7
|
readonly error: undefined;
|
|
5
8
|
readonly result: import("mongodb").DeleteResult;
|
|
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.removeAll = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const common_1 = require("@aeriajs/common");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const security_1 = require("@aeriajs/security");
|
|
7
|
+
const index_js_1 = require("../collection/index.js");
|
|
8
|
+
const internalRemoveAll = async (payload, context) => {
|
|
8
9
|
const filtersWithId = {
|
|
9
10
|
...payload.filters,
|
|
10
11
|
_id: {
|
|
@@ -21,4 +22,17 @@ const removeAll = async (payload, context) => {
|
|
|
21
22
|
}
|
|
22
23
|
return types_1.Result.result(await context.collection.model.deleteMany(filters));
|
|
23
24
|
};
|
|
25
|
+
const removeAll = async (payload, context, options = {}) => {
|
|
26
|
+
if (options.bypassSecurity) {
|
|
27
|
+
return internalRemoveAll(payload, context);
|
|
28
|
+
}
|
|
29
|
+
const security = (0, security_1.useSecurity)(context);
|
|
30
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
31
|
+
if (error) {
|
|
32
|
+
switch (error) {
|
|
33
|
+
case types_1.ACError.InvalidLimit: throw new Error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return internalRemoveAll(securedPayload, context);
|
|
37
|
+
};
|
|
24
38
|
exports.removeAll = removeAll;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { Result, ACError } from "@aeriajs/types";
|
|
3
|
+
import { throwIfError } from "@aeriajs/common";
|
|
4
|
+
import { useSecurity } from "@aeriajs/security";
|
|
5
|
+
import { traverseDocument, cascadingRemove } from "../collection/index.mjs";
|
|
6
|
+
const internalRemoveAll = async (payload, context) => {
|
|
7
|
+
const filtersWithId = {
|
|
8
|
+
...payload.filters,
|
|
9
|
+
_id: {
|
|
10
|
+
$in: payload.filters
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const filters = throwIfError(await traverseDocument(filtersWithId, context.description, {
|
|
14
|
+
autoCast: true
|
|
15
|
+
}));
|
|
16
|
+
const it = context.collection.model.find(filters);
|
|
17
|
+
let doc;
|
|
18
|
+
while (doc = await it.next()) {
|
|
19
|
+
await cascadingRemove(doc, context);
|
|
20
|
+
}
|
|
21
|
+
return Result.result(await context.collection.model.deleteMany(filters));
|
|
22
|
+
};
|
|
23
|
+
export const removeAll = async (payload, context, options = {}) => {
|
|
24
|
+
if (options.bypassSecurity) {
|
|
25
|
+
return internalRemoveAll(payload, context);
|
|
26
|
+
}
|
|
27
|
+
const security = useSecurity(context);
|
|
28
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
29
|
+
if (error) {
|
|
30
|
+
switch (error) {
|
|
31
|
+
case ACError.InvalidLimit:
|
|
32
|
+
throw new Error();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return internalRemoveAll(securedPayload, context);
|
|
36
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Context, RemoveFilePayload } from '@aeriajs/types';
|
|
2
|
-
export
|
|
2
|
+
export type RemoveFileOptions = {
|
|
3
|
+
bypassSecurity?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const removeFile: <TContext extends Context>(payload: RemoveFilePayload, context: TContext, options?: RemoveFileOptions) => Promise<{
|
|
3
6
|
readonly _tag: "Result";
|
|
4
7
|
readonly error: undefined;
|
|
5
8
|
readonly result: any;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeFile = void 0;
|
|
4
|
+
const types_1 = require("@aeriajs/types");
|
|
5
|
+
const security_1 = require("@aeriajs/security");
|
|
6
|
+
const internalRemoveFile = async (payload, context) => {
|
|
7
|
+
const { propertyName, parentId, ...props } = payload;
|
|
8
|
+
const doc = await context.collections.file.functions.remove(props);
|
|
9
|
+
return types_1.Result.result(doc);
|
|
10
|
+
};
|
|
11
|
+
const removeFile = async (payload, context, options = {}) => {
|
|
12
|
+
if (options.bypassSecurity) {
|
|
13
|
+
return internalRemoveFile(payload, context);
|
|
14
|
+
}
|
|
15
|
+
const security = (0, security_1.useSecurity)(context);
|
|
16
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
17
|
+
if (error) {
|
|
18
|
+
switch (error) {
|
|
19
|
+
case types_1.ACError.InvalidLimit: throw new Error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return internalRemoveFile(securedPayload, context);
|
|
23
|
+
};
|
|
24
|
+
exports.removeFile = removeFile;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { Result, ACError } from "@aeriajs/types";
|
|
3
|
+
import { useSecurity } from "@aeriajs/security";
|
|
4
|
+
const internalRemoveFile = async (payload, context) => {
|
|
5
|
+
const {
|
|
6
|
+
propertyName,
|
|
7
|
+
parentId,
|
|
8
|
+
...props
|
|
9
|
+
} = payload;
|
|
10
|
+
const doc = await context.collections.file.functions.remove(props);
|
|
11
|
+
return Result.result(doc);
|
|
12
|
+
};
|
|
13
|
+
export const removeFile = async (payload, context, options = {}) => {
|
|
14
|
+
if (options.bypassSecurity) {
|
|
15
|
+
return internalRemoveFile(payload, context);
|
|
16
|
+
}
|
|
17
|
+
const security = useSecurity(context);
|
|
18
|
+
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
19
|
+
if (error) {
|
|
20
|
+
switch (error) {
|
|
21
|
+
case ACError.InvalidLimit:
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return internalRemoveFile(securedPayload, context);
|
|
26
|
+
};
|
|
@@ -66,6 +66,7 @@ const upload = async (_props, context) => {
|
|
|
66
66
|
}
|
|
67
67
|
const { error: headersError } = (0, validation_1.validate)(context.request.headers, {
|
|
68
68
|
type: 'object',
|
|
69
|
+
additionalProperties: true,
|
|
69
70
|
properties: {
|
|
70
71
|
'x-stream-request': {
|
|
71
72
|
const: '1',
|
|
@@ -74,8 +75,6 @@ const upload = async (_props, context) => {
|
|
|
74
75
|
type: 'string',
|
|
75
76
|
},
|
|
76
77
|
},
|
|
77
|
-
}, {
|
|
78
|
-
extraneous: true,
|
|
79
78
|
});
|
|
80
79
|
if (headersError) {
|
|
81
80
|
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
@@ -35,6 +35,7 @@ export const upload = async (_props, context) => {
|
|
|
35
35
|
}
|
|
36
36
|
const { error: headersError } = validate(context.request.headers, {
|
|
37
37
|
type: "object",
|
|
38
|
+
additionalProperties: true,
|
|
38
39
|
properties: {
|
|
39
40
|
"x-stream-request": {
|
|
40
41
|
const: "1"
|
|
@@ -43,8 +44,6 @@ export const upload = async (_props, context) => {
|
|
|
43
44
|
type: "string"
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
}, {
|
|
47
|
-
extraneous: true
|
|
48
47
|
});
|
|
49
48
|
if (headersError) {
|
|
50
49
|
return context.error(HTTPStatus.BadRequest, {
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,5 @@ export * from './endpoints.js';
|
|
|
8
8
|
export * from './token.js';
|
|
9
9
|
export * from './use.js';
|
|
10
10
|
export * from './functions/index.js';
|
|
11
|
-
export * from './functions/
|
|
12
|
-
export * as functions from './functions/builtin/index.js';
|
|
11
|
+
export * as functions from './functions/index.js';
|
|
13
12
|
export { ObjectId, } from 'mongodb';
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ __exportStar(require("./endpoints.js"), exports);
|
|
|
37
37
|
__exportStar(require("./token.js"), exports);
|
|
38
38
|
__exportStar(require("./use.js"), exports);
|
|
39
39
|
__exportStar(require("./functions/index.js"), exports);
|
|
40
|
-
|
|
41
|
-
exports.functions = __importStar(require("./functions/builtin/index.js"));
|
|
40
|
+
exports.functions = __importStar(require("./functions/index.js"));
|
|
42
41
|
var mongodb_1 = require("mongodb");
|
|
43
42
|
Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return mongodb_1.ObjectId; } });
|
package/dist/index.mjs
CHANGED
|
@@ -9,8 +9,7 @@ export * from "./endpoints.mjs";
|
|
|
9
9
|
export * from "./token.mjs";
|
|
10
10
|
export * from "./use.mjs";
|
|
11
11
|
export * from "./functions/index.mjs";
|
|
12
|
-
export * from "./functions/
|
|
13
|
-
export * as functions from "./functions/builtin/index.mjs";
|
|
12
|
+
export * as functions from "./functions/index.mjs";
|
|
14
13
|
export {
|
|
15
14
|
ObjectId
|
|
16
15
|
} from "mongodb";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.139",
|
|
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.
|
|
45
|
-
"@aeriajs/common": "^0.0.
|
|
46
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
47
|
-
"@aeriajs/http": "^0.0.
|
|
48
|
-
"@aeriajs/security": "^0.0.
|
|
49
|
-
"@aeriajs/types": "^0.0.
|
|
50
|
-
"@aeriajs/validation": "^0.0.
|
|
44
|
+
"@aeriajs/builtins": "^0.0.139",
|
|
45
|
+
"@aeriajs/common": "^0.0.88",
|
|
46
|
+
"@aeriajs/entrypoint": "^0.0.90",
|
|
47
|
+
"@aeriajs/http": "^0.0.99",
|
|
48
|
+
"@aeriajs/security": "^0.0.139",
|
|
49
|
+
"@aeriajs/types": "^0.0.76",
|
|
50
|
+
"@aeriajs/validation": "^0.0.91"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"mongodb": "^6.5.0",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
|
|
2
|
-
export type GetAllOptions = {
|
|
3
|
-
bypassSecurity?: boolean;
|
|
4
|
-
};
|
|
5
|
-
export declare const getAll: <TContext extends Context>(_payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<{
|
|
6
|
-
readonly _tag: "Result";
|
|
7
|
-
readonly error: undefined;
|
|
8
|
-
readonly result: SchemaWithId<TContext["description"]>[];
|
|
9
|
-
}>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./count.js"), exports);
|
|
18
|
-
__exportStar(require("./get.js"), exports);
|
|
19
|
-
__exportStar(require("./getAll.js"), exports);
|
|
20
|
-
__exportStar(require("./insert.js"), exports);
|
|
21
|
-
__exportStar(require("./remove.js"), exports);
|
|
22
|
-
__exportStar(require("./removeAll.js"), exports);
|
|
23
|
-
__exportStar(require("./removeFile.js"), exports);
|
|
24
|
-
__exportStar(require("./upload.js"), exports);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export * from "./count.mjs";
|
|
3
|
-
export * from "./get.mjs";
|
|
4
|
-
export * from "./getAll.mjs";
|
|
5
|
-
export * from "./insert.mjs";
|
|
6
|
-
export * from "./remove.mjs";
|
|
7
|
-
export * from "./removeAll.mjs";
|
|
8
|
-
export * from "./removeFile.mjs";
|
|
9
|
-
export * from "./upload.mjs";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result } from "@aeriajs/types";
|
|
3
|
-
import { throwIfError } from "@aeriajs/common";
|
|
4
|
-
import { traverseDocument, cascadingRemove } from "../../collection/index.mjs";
|
|
5
|
-
export const removeAll = async (payload, context) => {
|
|
6
|
-
const filtersWithId = {
|
|
7
|
-
...payload.filters,
|
|
8
|
-
_id: {
|
|
9
|
-
$in: payload.filters
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const filters = throwIfError(await traverseDocument(filtersWithId, context.description, {
|
|
13
|
-
autoCast: true
|
|
14
|
-
}));
|
|
15
|
-
const it = context.collection.model.find(filters);
|
|
16
|
-
let doc;
|
|
17
|
-
while (doc = await it.next()) {
|
|
18
|
-
await cascadingRemove(doc, context);
|
|
19
|
-
}
|
|
20
|
-
return Result.result(await context.collection.model.deleteMany(filters));
|
|
21
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeFile = void 0;
|
|
4
|
-
const security_1 = require("@aeriajs/security");
|
|
5
|
-
const types_1 = require("@aeriajs/types");
|
|
6
|
-
const removeFile = async (payload, context) => {
|
|
7
|
-
const { propertyName, parentId, ...props } = payload;
|
|
8
|
-
await (0, security_1.checkImmutabilityRead)({
|
|
9
|
-
propertyName,
|
|
10
|
-
parentId,
|
|
11
|
-
childId: props.filters._id,
|
|
12
|
-
payload: props,
|
|
13
|
-
}, context);
|
|
14
|
-
const doc = await context.collections.file.functions.remove(props);
|
|
15
|
-
return types_1.Result.result(doc);
|
|
16
|
-
};
|
|
17
|
-
exports.removeFile = removeFile;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { checkImmutabilityRead } from "@aeriajs/security";
|
|
3
|
-
import { Result } from "@aeriajs/types";
|
|
4
|
-
export const removeFile = async (payload, context) => {
|
|
5
|
-
const {
|
|
6
|
-
propertyName,
|
|
7
|
-
parentId,
|
|
8
|
-
...props
|
|
9
|
-
} = payload;
|
|
10
|
-
await checkImmutabilityRead({
|
|
11
|
-
propertyName,
|
|
12
|
-
parentId,
|
|
13
|
-
childId: props.filters._id,
|
|
14
|
-
payload: props
|
|
15
|
-
}, context);
|
|
16
|
-
const doc = await context.collections.file.functions.remove(props);
|
|
17
|
-
return Result.result(doc);
|
|
18
|
-
};
|
|
File without changes
|
|
File without changes
|