@aeriajs/core 0.0.277 → 0.0.279
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/__scripts__/postinstall.js +2 -37
- package/dist/accessControl.js +14 -18
- package/dist/assets.js +25 -31
- package/dist/collection/cascadingRemove.js +14 -19
- package/dist/collection/define.js +5 -10
- package/dist/collection/description.js +2 -7
- package/dist/collection/index.js +8 -24
- package/dist/collection/makePagination.js +5 -9
- package/dist/collection/normalizeProjection.js +1 -5
- package/dist/collection/preload.js +13 -18
- package/dist/collection/reference.js +19 -26
- package/dist/collection/traverseDocument.js +90 -127
- package/dist/context.js +16 -53
- package/dist/database.js +12 -52
- package/dist/endpoints.js +11 -48
- package/dist/functions/count.js +11 -15
- package/dist/functions/get.js +20 -24
- package/dist/functions/getAll.js +8 -12
- package/dist/functions/index.js +9 -27
- package/dist/functions/insert.js +19 -23
- package/dist/functions/remove.js +15 -19
- package/dist/functions/removeAll.js +11 -15
- package/dist/functions/removeFile.js +7 -11
- package/dist/functions/unpaginatedGetAll.js +15 -19
- package/dist/functions/upload.js +19 -57
- package/dist/index.js +11 -51
- package/dist/presets/add.js +1 -4
- package/dist/presets/crud.js +1 -4
- package/dist/presets/duplicate.js +1 -4
- package/dist/presets/index.js +17 -20
- package/dist/presets/owned.js +1 -4
- package/dist/presets/remove.js +1 -4
- package/dist/presets/removeAll.js +1 -4
- package/dist/presets/timestamped.js +1 -4
- package/dist/presets/view.js +1 -4
- package/dist/token.js +7 -15
- package/package.json +12 -17
- package/dist/__scripts__/postinstall.mjs +0 -50
- package/dist/accessControl.mjs +0 -31
- package/dist/assets.mjs +0 -67
- package/dist/collection/cascadingRemove.mjs +0 -71
- package/dist/collection/define.mjs +0 -13
- package/dist/collection/description.mjs +0 -8
- package/dist/collection/index.mjs +0 -9
- package/dist/collection/makePagination.mjs +0 -20
- package/dist/collection/normalizeProjection.mjs +0 -17
- package/dist/collection/preload.mjs +0 -88
- package/dist/collection/reference.mjs +0 -374
- package/dist/collection/traverseDocument.mjs +0 -454
- package/dist/context.mjs +0 -120
- package/dist/database.mjs +0 -49
- package/dist/endpoints.mjs +0 -52
- package/dist/functions/count.mjs +0 -50
- package/dist/functions/get.mjs +0 -89
- package/dist/functions/getAll.mjs +0 -14
- package/dist/functions/index.mjs +0 -12
- package/dist/functions/insert.mjs +0 -102
- package/dist/functions/remove.mjs +0 -41
- package/dist/functions/removeAll.mjs +0 -40
- package/dist/functions/removeFile.mjs +0 -29
- package/dist/functions/unpaginatedGetAll.mjs +0 -123
- package/dist/functions/upload.mjs +0 -91
- package/dist/index.mjs +0 -14
- package/dist/presets/add.mjs +0 -12
- package/dist/presets/crud.mjs +0 -35
- package/dist/presets/duplicate.mjs +0 -11
- package/dist/presets/index.mjs +0 -19
- package/dist/presets/owned.mjs +0 -9
- package/dist/presets/remove.mjs +0 -11
- package/dist/presets/removeAll.mjs +0 -11
- package/dist/presets/timestamped.mjs +0 -19
- package/dist/presets/view.mjs +0 -14
- package/dist/token.mjs +0 -31
package/dist/functions/count.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
|
-
import { Result, HTTPStatus } from "@aeriajs/types";
|
|
4
|
-
import { throwIfError } from "@aeriajs/common";
|
|
5
|
-
import { traverseDocument } from "../collection/index.mjs";
|
|
6
|
-
const internalCount = async (payload, context, options) => {
|
|
7
|
-
const { filters = {} } = payload;
|
|
8
|
-
const $text = "$text" in filters ? filters.$text : void 0;
|
|
9
|
-
if ("$text" in filters) {
|
|
10
|
-
delete filters.$text;
|
|
11
|
-
}
|
|
12
|
-
const traversedFilters = throwIfError(await traverseDocument(filters, context.description, {
|
|
13
|
-
autoCast: true,
|
|
14
|
-
allowOperators: true,
|
|
15
|
-
noRegExpEscaping: options.noRegExpEscaping,
|
|
16
|
-
context
|
|
17
|
-
}));
|
|
18
|
-
if ($text) {
|
|
19
|
-
const pipeline = [];
|
|
20
|
-
pipeline.push({
|
|
21
|
-
$match: {
|
|
22
|
-
$text
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
pipeline.push({
|
|
26
|
-
$match: traversedFilters
|
|
27
|
-
});
|
|
28
|
-
pipeline.push({
|
|
29
|
-
$count: "total"
|
|
30
|
-
});
|
|
31
|
-
const result = await context.collection.model.aggregate(pipeline).next();
|
|
32
|
-
return Result.result(result ? result.total : 0);
|
|
33
|
-
}
|
|
34
|
-
return Result.result(await context.collection.model.countDocuments(traversedFilters));
|
|
35
|
-
};
|
|
36
|
-
export const count = async (payload, context, options = {}) => {
|
|
37
|
-
if (options.bypassSecurity) {
|
|
38
|
-
return internalCount(payload, context, options);
|
|
39
|
-
}
|
|
40
|
-
const security = useSecurity(context);
|
|
41
|
-
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
42
|
-
if (error) {
|
|
43
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
44
|
-
code: error
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
|
|
48
|
-
return internalCount(payload2, context2, options);
|
|
49
|
-
});
|
|
50
|
-
};
|
package/dist/functions/get.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
|
-
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
4
|
-
import { throwIfError } from "@aeriajs/common";
|
|
5
|
-
import {
|
|
6
|
-
traverseDocument,
|
|
7
|
-
normalizeProjection,
|
|
8
|
-
getReferences,
|
|
9
|
-
buildLookupPipeline
|
|
10
|
-
} from "../collection/index.mjs";
|
|
11
|
-
const internalGet = async (payload, context, options) => {
|
|
12
|
-
const {
|
|
13
|
-
filters = {},
|
|
14
|
-
project
|
|
15
|
-
} = payload;
|
|
16
|
-
if (Object.keys(filters).length === 0) {
|
|
17
|
-
return context.error(HTTPStatus.BadRequest, {
|
|
18
|
-
code: ACError.MalformedInput
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
const pipeline = [];
|
|
22
|
-
const refMap = await getReferences(context.description.properties, {
|
|
23
|
-
memoize: context.description.$id
|
|
24
|
-
});
|
|
25
|
-
const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
|
|
26
|
-
autoCast: true,
|
|
27
|
-
allowOperators: true,
|
|
28
|
-
noRegExpEscaping: options.noRegExpEscaping,
|
|
29
|
-
context
|
|
30
|
-
});
|
|
31
|
-
if (filtersError) {
|
|
32
|
-
switch (filtersError) {
|
|
33
|
-
case ACError.InsecureOperator:
|
|
34
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
35
|
-
code: filtersError
|
|
36
|
-
});
|
|
37
|
-
default:
|
|
38
|
-
throw new Error();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
pipeline.push({
|
|
42
|
-
$match: traversedFilters
|
|
43
|
-
});
|
|
44
|
-
if (project) {
|
|
45
|
-
const projection = normalizeProjection(project, context.description);
|
|
46
|
-
if (projection) {
|
|
47
|
-
pipeline.push({
|
|
48
|
-
$project: projection
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
pipeline.push(...buildLookupPipeline(refMap, {
|
|
53
|
-
memoize: context.description.$id,
|
|
54
|
-
project: payload.populate ? payload.populate : project
|
|
55
|
-
}));
|
|
56
|
-
const doc = await context.collection.model.aggregate(pipeline).next();
|
|
57
|
-
if (!doc) {
|
|
58
|
-
return context.error(HTTPStatus.NotFound, {
|
|
59
|
-
code: ACError.ResourceNotFound
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
const result = throwIfError(await traverseDocument(doc, context.description, {
|
|
63
|
-
context,
|
|
64
|
-
getters: true,
|
|
65
|
-
fromProperties: true,
|
|
66
|
-
recurseReferences: true,
|
|
67
|
-
recurseDeep: true
|
|
68
|
-
}));
|
|
69
|
-
return Result.result(result);
|
|
70
|
-
};
|
|
71
|
-
export const get = async (payload, context, options = {}) => {
|
|
72
|
-
if (options.bypassSecurity) {
|
|
73
|
-
return internalGet(payload, context, options);
|
|
74
|
-
}
|
|
75
|
-
const security = useSecurity(context);
|
|
76
|
-
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
77
|
-
if (error) {
|
|
78
|
-
switch (error) {
|
|
79
|
-
case ACError.InvalidLimit:
|
|
80
|
-
throw new Error();
|
|
81
|
-
}
|
|
82
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
83
|
-
code: error
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
|
|
87
|
-
return internalGet(payload2, context2, options);
|
|
88
|
-
});
|
|
89
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result } from "@aeriajs/types";
|
|
3
|
-
import { makePagination } from "../collection/makePagination.mjs";
|
|
4
|
-
import { unpaginatedGetAll } from "./unpaginatedGetAll.mjs";
|
|
5
|
-
export const getAll = async (payload, context, options) => {
|
|
6
|
-
const { error, result } = await unpaginatedGetAll(payload, context, options);
|
|
7
|
-
if (error) {
|
|
8
|
-
return Result.error(error);
|
|
9
|
-
}
|
|
10
|
-
return Result.result({
|
|
11
|
-
data: result,
|
|
12
|
-
pagination: await makePagination(payload, result, context)
|
|
13
|
-
});
|
|
14
|
-
};
|
package/dist/functions/index.mjs
DELETED
|
@@ -1,12 +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 "./unpaginatedGetAll.mjs";
|
|
10
|
-
export {
|
|
11
|
-
upload
|
|
12
|
-
} from "./upload.mjs";
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { ObjectId, MongoServerError } from "mongodb";
|
|
3
|
-
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
4
|
-
import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
|
|
5
|
-
import { traverseDocument } from "../collection/index.mjs";
|
|
6
|
-
import { get } from "./get.mjs";
|
|
7
|
-
const prepareCreate = (doc, description) => {
|
|
8
|
-
const result = {};
|
|
9
|
-
if (description.defaults) {
|
|
10
|
-
Object.assign(result, description.defaults);
|
|
11
|
-
}
|
|
12
|
-
Object.assign(result, doc);
|
|
13
|
-
return result;
|
|
14
|
-
};
|
|
15
|
-
const internalInsert = async (payload, context) => {
|
|
16
|
-
const isUpdate = !!("_id" in payload.what && payload.what._id);
|
|
17
|
-
const { error, result: what } = await traverseDocument(payload.what, context.description, {
|
|
18
|
-
recurseDeep: true,
|
|
19
|
-
autoCast: true,
|
|
20
|
-
moveFiles: true,
|
|
21
|
-
cleanupReferences: true,
|
|
22
|
-
undefinedToNull: true,
|
|
23
|
-
preserveHidden: true,
|
|
24
|
-
validate: true,
|
|
25
|
-
validateWholeness: isUpdate ? "deep" : true,
|
|
26
|
-
fromProperties: !isUpdate,
|
|
27
|
-
context
|
|
28
|
-
});
|
|
29
|
-
if (error) {
|
|
30
|
-
if (typeof error === "string") {
|
|
31
|
-
return context.error(HTTPStatus.UnprocessableContent, {
|
|
32
|
-
code: error
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return context.error(HTTPStatus.UnprocessableContent, {
|
|
36
|
-
code: error.code,
|
|
37
|
-
details: error.details
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const docId = "_id" in what && what._id instanceof ObjectId ? what._id : null;
|
|
41
|
-
let newId = docId;
|
|
42
|
-
try {
|
|
43
|
-
if (!newId) {
|
|
44
|
-
const content = prepareCreate(what, context.description);
|
|
45
|
-
const now = /* @__PURE__ */ new Date();
|
|
46
|
-
Object.assign(content, {
|
|
47
|
-
created_at: now,
|
|
48
|
-
updated_at: now
|
|
49
|
-
});
|
|
50
|
-
newId = (await context.collection.model.insertOne(content)).insertedId;
|
|
51
|
-
} else {
|
|
52
|
-
await context.collection.model.updateOne({
|
|
53
|
-
_id: newId
|
|
54
|
-
}, {
|
|
55
|
-
$set: {
|
|
56
|
-
...what,
|
|
57
|
-
updated_at: /* @__PURE__ */ new Date()
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
} catch (err) {
|
|
62
|
-
if (err instanceof MongoServerError) {
|
|
63
|
-
switch (err.code) {
|
|
64
|
-
case 11e3:
|
|
65
|
-
return context.error(HTTPStatus.InternalServerError, {
|
|
66
|
-
code: ACError.UniquenessViolated
|
|
67
|
-
});
|
|
68
|
-
default:
|
|
69
|
-
throw err;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
const inheritedContext = {
|
|
75
|
-
...context,
|
|
76
|
-
inherited: true
|
|
77
|
-
};
|
|
78
|
-
const { error: getError, result: newDocument } = await get({
|
|
79
|
-
filters: {
|
|
80
|
-
_id: newId
|
|
81
|
-
}
|
|
82
|
-
}, inheritedContext, {
|
|
83
|
-
bypassSecurity: true
|
|
84
|
-
});
|
|
85
|
-
if (getError) {
|
|
86
|
-
return Result.error(getError);
|
|
87
|
-
}
|
|
88
|
-
return Result.result(newDocument);
|
|
89
|
-
};
|
|
90
|
-
export const insert = async (payload, context, options = {}) => {
|
|
91
|
-
if (options.bypassSecurity) {
|
|
92
|
-
return internalInsert(payload, context);
|
|
93
|
-
}
|
|
94
|
-
const security = useSecurity(context);
|
|
95
|
-
const { error, result: securedPayload } = await security.secureWritePayload(payload);
|
|
96
|
-
if (error) {
|
|
97
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
98
|
-
code: error
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return applyWriteMiddlewares(securedPayload, context, internalInsert);
|
|
102
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, HTTPStatus, 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 internalRemove = async (payload, context) => {
|
|
7
|
-
if (!payload.filters._id) {
|
|
8
|
-
return context.error(HTTPStatus.NotFound, {
|
|
9
|
-
code: ACError.ResourceNotFound
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
const filters = throwIfError(await traverseDocument(payload.filters, context.description, {
|
|
13
|
-
autoCast: true,
|
|
14
|
-
context
|
|
15
|
-
}));
|
|
16
|
-
const target = await context.collection.model.findOne(filters);
|
|
17
|
-
if (!target) {
|
|
18
|
-
return context.error(HTTPStatus.NotFound, {
|
|
19
|
-
code: ACError.ResourceNotFound
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
await cascadingRemove(target, context);
|
|
23
|
-
return Result.result(await context.collection.model.findOneAndDelete(filters));
|
|
24
|
-
};
|
|
25
|
-
export const remove = async (payload, context, options = {}) => {
|
|
26
|
-
if (options.bypassSecurity) {
|
|
27
|
-
return internalRemove(payload, context);
|
|
28
|
-
}
|
|
29
|
-
const security = useSecurity(context);
|
|
30
|
-
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
31
|
-
if (error) {
|
|
32
|
-
switch (error) {
|
|
33
|
-
case ACError.InvalidLimit:
|
|
34
|
-
throw new Error();
|
|
35
|
-
}
|
|
36
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
37
|
-
code: error
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return internalRemove(securedPayload, context);
|
|
41
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, ACError, HTTPStatus } 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 filters = throwIfError(await traverseDocument(payload.filters, context.description, {
|
|
8
|
-
autoCast: true,
|
|
9
|
-
context
|
|
10
|
-
}));
|
|
11
|
-
const it = context.collection.model.find(filters);
|
|
12
|
-
for await (const doc of it) {
|
|
13
|
-
await cascadingRemove(doc, context);
|
|
14
|
-
}
|
|
15
|
-
return Result.result(await context.collection.model.deleteMany(filters));
|
|
16
|
-
};
|
|
17
|
-
export const removeAll = async (_payload, context, options = {}) => {
|
|
18
|
-
const payload = {
|
|
19
|
-
filters: {
|
|
20
|
-
_id: {
|
|
21
|
-
$in: _payload.filters
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
if (options.bypassSecurity) {
|
|
26
|
-
return internalRemoveAll(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
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
36
|
-
code: error
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
return internalRemoveAll(securedPayload, context);
|
|
40
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, ACError, HTTPStatus } from "@aeriajs/types";
|
|
3
|
-
import { useSecurity } from "@aeriajs/security";
|
|
4
|
-
const internalRemoveFile = async (payload, context) => {
|
|
5
|
-
const {
|
|
6
|
-
propName,
|
|
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
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
25
|
-
code: error
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return internalRemoveFile(securedPayload, context);
|
|
29
|
-
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
|
-
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
4
|
-
import { throwIfError } from "@aeriajs/common";
|
|
5
|
-
import {
|
|
6
|
-
traverseDocument,
|
|
7
|
-
normalizeProjection,
|
|
8
|
-
getReferences,
|
|
9
|
-
buildLookupPipeline
|
|
10
|
-
} from "../collection/index.mjs";
|
|
11
|
-
const internalGetAll = async (payload, context, options) => {
|
|
12
|
-
const {
|
|
13
|
-
limit,
|
|
14
|
-
sort,
|
|
15
|
-
project,
|
|
16
|
-
offset = 0
|
|
17
|
-
} = payload;
|
|
18
|
-
const filters = payload.filters ? Object.assign({}, payload.filters) : {};
|
|
19
|
-
const $text = payload.filters && "$text" in payload.filters ? payload.filters.$text : void 0;
|
|
20
|
-
if ("$text" in filters) {
|
|
21
|
-
delete filters.$text;
|
|
22
|
-
}
|
|
23
|
-
const pipeline = [];
|
|
24
|
-
const refMap = await getReferences(context.description.properties, {
|
|
25
|
-
memoize: context.description.$id
|
|
26
|
-
});
|
|
27
|
-
if ($text) {
|
|
28
|
-
pipeline.push({
|
|
29
|
-
$match: {
|
|
30
|
-
$text
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const preferredSort = sort ? sort : context.description.timestamps !== false ? {
|
|
35
|
-
_id: -1
|
|
36
|
-
} : null;
|
|
37
|
-
if (preferredSort) {
|
|
38
|
-
pipeline.push({
|
|
39
|
-
$sort: preferredSort
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
const { error: filtersError, result: traversedFilters } = await traverseDocument(filters, context.description, {
|
|
43
|
-
autoCast: true,
|
|
44
|
-
allowOperators: true,
|
|
45
|
-
noRegExpEscaping: options.noRegExpEscaping,
|
|
46
|
-
context
|
|
47
|
-
});
|
|
48
|
-
if (filtersError) {
|
|
49
|
-
switch (filtersError) {
|
|
50
|
-
case ACError.InsecureOperator:
|
|
51
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
52
|
-
code: filtersError
|
|
53
|
-
});
|
|
54
|
-
default:
|
|
55
|
-
throw new Error();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (Object.keys(filters).length > 0) {
|
|
59
|
-
pipeline.push({
|
|
60
|
-
$match: traversedFilters
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (offset > 0) {
|
|
64
|
-
pipeline.push({
|
|
65
|
-
$skip: offset
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (limit) {
|
|
69
|
-
pipeline.push({
|
|
70
|
-
$limit: limit
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (project) {
|
|
74
|
-
const projection = normalizeProjection(project, context.description);
|
|
75
|
-
if (projection) {
|
|
76
|
-
pipeline.push({
|
|
77
|
-
$project: projection
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
pipeline.push(...buildLookupPipeline(refMap, {
|
|
82
|
-
memoize: context.description.$id,
|
|
83
|
-
project: payload.populate ? payload.populate : project
|
|
84
|
-
}));
|
|
85
|
-
if (Object.keys(refMap).length > 0 && preferredSort) {
|
|
86
|
-
pipeline.push({
|
|
87
|
-
$sort: preferredSort
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
const result = await context.collection.model.aggregate(pipeline).toArray();
|
|
91
|
-
const documents = [];
|
|
92
|
-
for (const doc of result) {
|
|
93
|
-
documents.push(throwIfError(await traverseDocument(doc, context.description, {
|
|
94
|
-
context,
|
|
95
|
-
getters: true,
|
|
96
|
-
fromProperties: true,
|
|
97
|
-
recurseReferences: true,
|
|
98
|
-
recurseDeep: true
|
|
99
|
-
})));
|
|
100
|
-
}
|
|
101
|
-
return Result.result(documents);
|
|
102
|
-
};
|
|
103
|
-
export const unpaginatedGetAll = async (payload, context, options = {}) => {
|
|
104
|
-
if (!payload) {
|
|
105
|
-
return internalGetAll({}, context, options);
|
|
106
|
-
}
|
|
107
|
-
if (options.bypassSecurity) {
|
|
108
|
-
return internalGetAll(payload, context, options);
|
|
109
|
-
}
|
|
110
|
-
const security = useSecurity(context);
|
|
111
|
-
const { error, result: securedPayload } = await security.secureReadPayload(payload);
|
|
112
|
-
if (error) {
|
|
113
|
-
return context.error(HTTPStatus.Forbidden, {
|
|
114
|
-
code: error
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (!options.noDefaultLimit) {
|
|
118
|
-
securedPayload.limit ||= context.config.defaultPaginationLimit;
|
|
119
|
-
}
|
|
120
|
-
return applyReadMiddlewares(securedPayload, context, (payload2, context2) => {
|
|
121
|
-
return internalGetAll(payload2, context2, options);
|
|
122
|
-
});
|
|
123
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { Result, ACError, HTTPStatus } from "@aeriajs/types";
|
|
3
|
-
import { validator } from "@aeriajs/validation";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import { createWriteStream } from "node:fs";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
|
-
export const [FileMetadata, validateFileMetadata] = validator({
|
|
8
|
-
type: "object",
|
|
9
|
-
required: ["name"],
|
|
10
|
-
properties: {
|
|
11
|
-
name: {
|
|
12
|
-
type: "string"
|
|
13
|
-
},
|
|
14
|
-
format: {
|
|
15
|
-
enum: [
|
|
16
|
-
"raw",
|
|
17
|
-
"base64"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export const [UploadHeaders, validateUploadHeaders] = validator({
|
|
23
|
-
type: "object",
|
|
24
|
-
additionalProperties: true,
|
|
25
|
-
required: [
|
|
26
|
-
"x-stream-request",
|
|
27
|
-
"content-type"
|
|
28
|
-
],
|
|
29
|
-
properties: {
|
|
30
|
-
"x-stream-request": {
|
|
31
|
-
const: "1"
|
|
32
|
-
},
|
|
33
|
-
"content-type": {
|
|
34
|
-
type: "string"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const streamToFs = (metadata, context) => {
|
|
39
|
-
const nameHash = createHash("sha1").update(metadata.name + Date.now()).digest("hex");
|
|
40
|
-
const extension = metadata.name.includes(".") ? metadata.name.split(".").at(-1) : "bin";
|
|
41
|
-
const tmpPath = context.config.storage ? context.config.storage.tempFs || context.config.storage.fs : null;
|
|
42
|
-
if (!tmpPath) {
|
|
43
|
-
throw new Error();
|
|
44
|
-
}
|
|
45
|
-
const absolutePath = path.join(tmpPath, `${nameHash}.${extension}`);
|
|
46
|
-
return new Promise(async (resolve, reject) => {
|
|
47
|
-
const stream = createWriteStream(absolutePath);
|
|
48
|
-
stream.on("close", () => resolve(absolutePath));
|
|
49
|
-
stream.on("error", (error) => reject(error));
|
|
50
|
-
switch (metadata.format) {
|
|
51
|
-
case void 0:
|
|
52
|
-
case "raw": {
|
|
53
|
-
stream.on("open", () => context.request.pipe(stream));
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case "base64": {
|
|
57
|
-
stream.write(Buffer.from(Buffer.concat(await Array.fromAsync(context.request)).toString(), "base64"));
|
|
58
|
-
stream.close();
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
export const upload = async (_props, context) => {
|
|
65
|
-
const { error: headersError } = validateUploadHeaders(context.request.headers);
|
|
66
|
-
if (headersError) {
|
|
67
|
-
return context.error(HTTPStatus.BadRequest, {
|
|
68
|
-
code: ACError.MalformedInput,
|
|
69
|
-
details: headersError
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
const { error, result: metadata } = validateFileMetadata(context.request.query);
|
|
73
|
-
if (error) {
|
|
74
|
-
return context.error(HTTPStatus.BadRequest, {
|
|
75
|
-
code: ACError.MalformedInput,
|
|
76
|
-
details: error
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
const path2 = await streamToFs(metadata, context);
|
|
80
|
-
const file = await context.collections.tempFile.model.insertOne({
|
|
81
|
-
created_at: /* @__PURE__ */ new Date(),
|
|
82
|
-
absolute_path: path2,
|
|
83
|
-
size: context.request.headers["content-length"],
|
|
84
|
-
type: context.request.headers["content-type"],
|
|
85
|
-
collection: context.description.$id,
|
|
86
|
-
name: metadata.name
|
|
87
|
-
});
|
|
88
|
-
return Result.result({
|
|
89
|
-
tempId: file.insertedId
|
|
90
|
-
});
|
|
91
|
-
};
|
package/dist/index.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export * from "./accessControl.mjs";
|
|
3
|
-
export * from "./assets.mjs";
|
|
4
|
-
export * from "./collection/index.mjs";
|
|
5
|
-
export * from "./context.mjs";
|
|
6
|
-
export * from "./database.mjs";
|
|
7
|
-
export * from "./functions/index.mjs";
|
|
8
|
-
export * from "./endpoints.mjs";
|
|
9
|
-
export * from "./token.mjs";
|
|
10
|
-
export * from "./functions/index.mjs";
|
|
11
|
-
export * as functions from "./functions/index.mjs";
|
|
12
|
-
export {
|
|
13
|
-
ObjectId
|
|
14
|
-
} from "mongodb";
|
package/dist/presets/add.mjs
DELETED
package/dist/presets/crud.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
export const crud = {
|
|
3
|
-
actions: {
|
|
4
|
-
spawnAdd: {
|
|
5
|
-
label: "action.add",
|
|
6
|
-
event: "spawnAdd",
|
|
7
|
-
icon: "plus",
|
|
8
|
-
button: true,
|
|
9
|
-
translate: true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
individualActions: {
|
|
13
|
-
spawnEdit: {
|
|
14
|
-
label: "action.edit",
|
|
15
|
-
event: "spawnEdit",
|
|
16
|
-
icon: "pencil-simple",
|
|
17
|
-
translate: true
|
|
18
|
-
},
|
|
19
|
-
viewItem: {
|
|
20
|
-
label: "action.view",
|
|
21
|
-
icon: "eye",
|
|
22
|
-
translate: true,
|
|
23
|
-
route: {
|
|
24
|
-
name: "/dashboard/:collection/:id",
|
|
25
|
-
setItem: true
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
remove: {
|
|
29
|
-
label: "action.remove",
|
|
30
|
-
icon: "trash",
|
|
31
|
-
ask: true,
|
|
32
|
-
translate: true
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
package/dist/presets/index.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { add } from "./add.mjs";
|
|
3
|
-
import { crud } from "./crud.mjs";
|
|
4
|
-
import { removeAll } from "./removeAll.mjs";
|
|
5
|
-
import { duplicate } from "./duplicate.mjs";
|
|
6
|
-
import { owned } from "./owned.mjs";
|
|
7
|
-
import { remove } from "./remove.mjs";
|
|
8
|
-
import { timestamped } from "./timestamped.mjs";
|
|
9
|
-
import { view } from "./view.mjs";
|
|
10
|
-
export const presets = {
|
|
11
|
-
add,
|
|
12
|
-
crud,
|
|
13
|
-
removeAll,
|
|
14
|
-
duplicate,
|
|
15
|
-
owned,
|
|
16
|
-
remove,
|
|
17
|
-
timestamped,
|
|
18
|
-
view
|
|
19
|
-
};
|