@aeriajs/core 0.0.94 → 0.0.96
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/accessControl.js +4 -4
- package/dist/accessControl.mjs +4 -4
- package/dist/assets.d.ts +39 -3
- package/dist/assets.js +18 -20
- package/dist/assets.mjs +19 -21
- package/dist/collection/cascadingRemove.js +6 -7
- package/dist/collection/cascadingRemove.mjs +6 -7
- package/dist/collection/preload.js +5 -4
- package/dist/collection/preload.mjs +6 -5
- package/dist/collection/prepareInsert.js +2 -1
- package/dist/collection/prepareInsert.mjs +2 -1
- package/dist/collection/reference.js +4 -4
- package/dist/collection/reference.mjs +5 -5
- package/dist/collection/traverseDocument.d.ts +9 -1
- package/dist/collection/traverseDocument.js +37 -34
- package/dist/collection/traverseDocument.mjs +41 -38
- package/dist/context.js +4 -4
- package/dist/context.mjs +5 -5
- package/dist/functions/builtin/count.d.ts +5 -1
- package/dist/functions/builtin/count.js +5 -5
- package/dist/functions/builtin/count.mjs +5 -5
- package/dist/functions/builtin/get.js +9 -6
- package/dist/functions/builtin/get.mjs +10 -7
- package/dist/functions/builtin/getAll.d.ts +5 -1
- package/dist/functions/builtin/getAll.js +4 -4
- package/dist/functions/builtin/getAll.mjs +5 -5
- package/dist/functions/builtin/insert.d.ts +11 -19
- package/dist/functions/builtin/insert.js +6 -8
- package/dist/functions/builtin/insert.mjs +7 -9
- package/dist/functions/builtin/remove.d.ts +10 -1
- package/dist/functions/builtin/remove.js +2 -2
- package/dist/functions/builtin/remove.mjs +3 -3
- package/dist/functions/builtin/removeAll.d.ts +5 -1
- package/dist/functions/builtin/removeAll.js +5 -5
- package/dist/functions/builtin/removeAll.mjs +6 -6
- package/dist/functions/builtin/removeFile.d.ts +5 -1
- package/dist/functions/builtin/removeFile.js +3 -1
- package/dist/functions/builtin/removeFile.mjs +3 -1
- package/dist/functions/builtin/upload.d.ts +6 -2
- package/dist/functions/builtin/upload.js +9 -10
- package/dist/functions/builtin/upload.mjs +9 -10
- package/package.json +8 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { useSecurity } from "@aeriajs/security";
|
|
3
|
-
import {
|
|
3
|
+
import { Result, throwIfError } from "@aeriajs/common";
|
|
4
4
|
import {
|
|
5
5
|
traverseDocument,
|
|
6
6
|
normalizeProjection,
|
|
@@ -17,7 +17,7 @@ export const getAll = async (_payload, context, options = {}) => {
|
|
|
17
17
|
sort,
|
|
18
18
|
project = [],
|
|
19
19
|
offset = 0
|
|
20
|
-
} = !options.bypassSecurity ?
|
|
20
|
+
} = !options.bypassSecurity ? throwIfError(await security.beforeRead(payload)) : payload;
|
|
21
21
|
const { $text, ...filtersRest } = filters;
|
|
22
22
|
const pipeline = [];
|
|
23
23
|
const references = await getReferences(context.description.properties, {
|
|
@@ -40,7 +40,7 @@ export const getAll = async (_payload, context, options = {}) => {
|
|
|
40
40
|
}
|
|
41
41
|
if (Object.keys(filtersRest).length > 0) {
|
|
42
42
|
pipeline.push({
|
|
43
|
-
$match:
|
|
43
|
+
$match: throwIfError(await traverseDocument(filtersRest, context.description, {
|
|
44
44
|
autoCast: true,
|
|
45
45
|
allowOperators: true
|
|
46
46
|
}))
|
|
@@ -73,12 +73,12 @@ export const getAll = async (_payload, context, options = {}) => {
|
|
|
73
73
|
const result = await context.collection.model.aggregate(pipeline).toArray();
|
|
74
74
|
const documents = [];
|
|
75
75
|
for (const document of result) {
|
|
76
|
-
documents.push(
|
|
76
|
+
documents.push(throwIfError(await traverseDocument(fill(document, context.description), context.description, {
|
|
77
77
|
getters: true,
|
|
78
78
|
fromProperties: true,
|
|
79
79
|
recurseReferences: true,
|
|
80
80
|
recurseDeep: true
|
|
81
81
|
})));
|
|
82
82
|
}
|
|
83
|
-
return documents;
|
|
83
|
+
return Result.result(documents);
|
|
84
84
|
};
|
|
@@ -5,28 +5,20 @@ export type InsertOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare const insertErrorSchema: () => {
|
|
7
7
|
readonly type: "object";
|
|
8
|
+
readonly required: readonly ["httpStatus", "code"];
|
|
8
9
|
readonly properties: {
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
10
|
+
readonly httpStatus: {
|
|
11
|
+
readonly enum: [HTTPStatus.UnprocessableContent, HTTPStatus.NotFound];
|
|
11
12
|
};
|
|
12
|
-
readonly
|
|
13
|
+
readonly code: {
|
|
14
|
+
readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties];
|
|
15
|
+
};
|
|
16
|
+
readonly message: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
};
|
|
19
|
+
readonly details: {
|
|
13
20
|
readonly type: "object";
|
|
14
|
-
readonly
|
|
15
|
-
readonly properties: {
|
|
16
|
-
readonly httpStatus: {
|
|
17
|
-
readonly enum: [HTTPStatus.UnprocessableContent, HTTPStatus.NotFound];
|
|
18
|
-
};
|
|
19
|
-
readonly code: {
|
|
20
|
-
readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties];
|
|
21
|
-
};
|
|
22
|
-
readonly message: {
|
|
23
|
-
readonly type: "string";
|
|
24
|
-
};
|
|
25
|
-
readonly details: {
|
|
26
|
-
readonly type: "object";
|
|
27
|
-
readonly variable: true;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
21
|
+
readonly variable: true;
|
|
30
22
|
};
|
|
31
23
|
};
|
|
32
24
|
};
|
|
@@ -5,7 +5,7 @@ const types_1 = require("@aeriajs/types");
|
|
|
5
5
|
const security_1 = require("@aeriajs/security");
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
7
|
const index_js_1 = require("../../collection/index.js");
|
|
8
|
-
const insertErrorSchema = () => (0, common_1.
|
|
8
|
+
const insertErrorSchema = () => (0, common_1.endpointErrorSchema)({
|
|
9
9
|
httpStatus: [
|
|
10
10
|
types_1.HTTPStatus.UnprocessableContent,
|
|
11
11
|
types_1.HTTPStatus.NotFound,
|
|
@@ -24,9 +24,9 @@ exports.insertErrorSchema = insertErrorSchema;
|
|
|
24
24
|
const insert = async (payload, context, options) => {
|
|
25
25
|
const security = (0, security_1.useSecurity)(context);
|
|
26
26
|
const query = !options?.bypassSecurity
|
|
27
|
-
? (0, common_1.
|
|
27
|
+
? (0, common_1.throwIfError)(await security.beforeWrite(payload))
|
|
28
28
|
: payload;
|
|
29
|
-
const
|
|
29
|
+
const { error, result: what } = await (0, index_js_1.traverseDocument)(query.what, context.description, {
|
|
30
30
|
recurseDeep: true,
|
|
31
31
|
autoCast: true,
|
|
32
32
|
validate: true,
|
|
@@ -36,8 +36,7 @@ const insert = async (payload, context, options) => {
|
|
|
36
36
|
moveFiles: true,
|
|
37
37
|
context,
|
|
38
38
|
});
|
|
39
|
-
if (
|
|
40
|
-
const error = (0, common_1.unwrapEither)(whatEither);
|
|
39
|
+
if (error) {
|
|
41
40
|
if (typeof error === 'string') {
|
|
42
41
|
return context.error(types_1.HTTPStatus.UnprocessableContent, {
|
|
43
42
|
code: error,
|
|
@@ -48,7 +47,6 @@ const insert = async (payload, context, options) => {
|
|
|
48
47
|
details: error.errors,
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
|
-
const what = (0, common_1.unwrapEither)(whatEither);
|
|
52
50
|
const docId = '_id' in what
|
|
53
51
|
? what._id
|
|
54
52
|
: null;
|
|
@@ -96,11 +94,11 @@ const insert = async (payload, context, options) => {
|
|
|
96
94
|
code: types_1.ACError.ResourceNotFound,
|
|
97
95
|
});
|
|
98
96
|
}
|
|
99
|
-
const result = (0, common_1.
|
|
97
|
+
const result = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(doc, context.description, {
|
|
100
98
|
getters: true,
|
|
101
99
|
fromProperties: true,
|
|
102
100
|
recurseReferences: true,
|
|
103
101
|
}));
|
|
104
|
-
return result;
|
|
102
|
+
return common_1.Result.result(result);
|
|
105
103
|
};
|
|
106
104
|
exports.insert = insert;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { HTTPStatus, ACError, ValidationErrorCode } from "@aeriajs/types";
|
|
3
3
|
import { useSecurity } from "@aeriajs/security";
|
|
4
|
-
import {
|
|
4
|
+
import { Result, throwIfError, endpointErrorSchema } from "@aeriajs/common";
|
|
5
5
|
import { traverseDocument, normalizeProjection, prepareInsert } from "../../collection/index.mjs";
|
|
6
|
-
export const insertErrorSchema = () =>
|
|
6
|
+
export const insertErrorSchema = () => endpointErrorSchema({
|
|
7
7
|
httpStatus: [
|
|
8
8
|
HTTPStatus.UnprocessableContent,
|
|
9
9
|
HTTPStatus.NotFound
|
|
@@ -20,8 +20,8 @@ export const insertErrorSchema = () => errorSchema({
|
|
|
20
20
|
});
|
|
21
21
|
export const insert = async (payload, context, options) => {
|
|
22
22
|
const security = useSecurity(context);
|
|
23
|
-
const query = !options?.bypassSecurity ?
|
|
24
|
-
const
|
|
23
|
+
const query = !options?.bypassSecurity ? throwIfError(await security.beforeWrite(payload)) : payload;
|
|
24
|
+
const { error, result: what } = await traverseDocument(query.what, context.description, {
|
|
25
25
|
recurseDeep: true,
|
|
26
26
|
autoCast: true,
|
|
27
27
|
validate: true,
|
|
@@ -29,8 +29,7 @@ export const insert = async (payload, context, options) => {
|
|
|
29
29
|
moveFiles: true,
|
|
30
30
|
context
|
|
31
31
|
});
|
|
32
|
-
if (
|
|
33
|
-
const error = unwrapEither(whatEither);
|
|
32
|
+
if (error) {
|
|
34
33
|
if (typeof error === "string") {
|
|
35
34
|
return context.error(HTTPStatus.UnprocessableContent, {
|
|
36
35
|
code: error
|
|
@@ -41,7 +40,6 @@ export const insert = async (payload, context, options) => {
|
|
|
41
40
|
details: error.errors
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
|
-
const what = unwrapEither(whatEither);
|
|
45
43
|
const docId = "_id" in what ? what._id : null;
|
|
46
44
|
const content = prepareInsert(what, context.description);
|
|
47
45
|
const projection = payload.project ? normalizeProjection(payload.project, context.description) : {};
|
|
@@ -83,10 +81,10 @@ export const insert = async (payload, context, options) => {
|
|
|
83
81
|
code: ACError.ResourceNotFound
|
|
84
82
|
});
|
|
85
83
|
}
|
|
86
|
-
const result =
|
|
84
|
+
const result = throwIfError(await traverseDocument(doc, context.description, {
|
|
87
85
|
getters: true,
|
|
88
86
|
fromProperties: true,
|
|
89
87
|
recurseReferences: true
|
|
90
88
|
}));
|
|
91
|
-
return result;
|
|
89
|
+
return Result.result(result);
|
|
92
90
|
};
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
|
|
2
|
-
|
|
2
|
+
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
3
|
+
export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext['description']>>, context: TContext) => Promise<{
|
|
4
|
+
readonly _tag: "Result";
|
|
5
|
+
readonly error: undefined;
|
|
6
|
+
readonly result: any;
|
|
7
|
+
} | import("@aeriajs/types/result.js").Result.Error<{
|
|
8
|
+
readonly code: ACError.ResourceNotFound;
|
|
9
|
+
} & {
|
|
10
|
+
httpStatus: HTTPStatus.NotFound;
|
|
11
|
+
}>>;
|
|
@@ -10,7 +10,7 @@ const remove = async (payload, context) => {
|
|
|
10
10
|
code: types_1.ACError.ResourceNotFound,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
const filters = (0, common_1.
|
|
13
|
+
const filters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(payload.filters, context.description, {
|
|
14
14
|
autoCast: true,
|
|
15
15
|
}));
|
|
16
16
|
const target = await context.collection.model.findOne(filters);
|
|
@@ -20,6 +20,6 @@ const remove = async (payload, context) => {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
await (0, index_js_1.cascadingRemove)(target, context);
|
|
23
|
-
return context.collection.model.findOneAndDelete(filters);
|
|
23
|
+
return common_1.Result.result(await context.collection.model.findOneAndDelete(filters));
|
|
24
24
|
};
|
|
25
25
|
exports.remove = remove;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
|
-
import {
|
|
3
|
+
import { Result, throwIfError } from "@aeriajs/common";
|
|
4
4
|
import { traverseDocument, cascadingRemove } from "../../collection/index.mjs";
|
|
5
5
|
export const remove = async (payload, context) => {
|
|
6
6
|
if (!payload.filters._id) {
|
|
@@ -8,7 +8,7 @@ export const remove = async (payload, context) => {
|
|
|
8
8
|
code: ACError.ResourceNotFound
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
const filters =
|
|
11
|
+
const filters = throwIfError(await traverseDocument(payload.filters, context.description, {
|
|
12
12
|
autoCast: true
|
|
13
13
|
}));
|
|
14
14
|
const target = await context.collection.model.findOne(filters);
|
|
@@ -18,5 +18,5 @@ export const remove = async (payload, context) => {
|
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
await cascadingRemove(target, context);
|
|
21
|
-
return context.collection.model.findOneAndDelete(filters);
|
|
21
|
+
return Result.result(await context.collection.model.findOneAndDelete(filters));
|
|
22
22
|
};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { Context, RemoveAllPayload } from '@aeriajs/types';
|
|
2
|
-
export declare const removeAll: <TContext extends Context>(payload: RemoveAllPayload, context: TContext) => Promise<
|
|
2
|
+
export declare const removeAll: <TContext extends Context>(payload: RemoveAllPayload, context: TContext) => Promise<{
|
|
3
|
+
readonly _tag: "Result";
|
|
4
|
+
readonly error: undefined;
|
|
5
|
+
readonly result: any;
|
|
6
|
+
}>;
|
|
@@ -10,14 +10,14 @@ const removeAll = async (payload, context) => {
|
|
|
10
10
|
$in: payload.filters,
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
|
-
const filters = (0, common_1.
|
|
13
|
+
const filters = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(filtersWithId, context.description, {
|
|
14
14
|
autoCast: true,
|
|
15
15
|
}));
|
|
16
16
|
const it = context.collection.model.find(filters);
|
|
17
|
-
let
|
|
18
|
-
while (
|
|
19
|
-
await (0, index_js_1.cascadingRemove)(
|
|
17
|
+
let doc;
|
|
18
|
+
while (doc = await it.next()) {
|
|
19
|
+
await (0, index_js_1.cascadingRemove)(doc, context);
|
|
20
20
|
}
|
|
21
|
-
return context.collection.model.deleteMany(filters);
|
|
21
|
+
return common_1.Result.result(await context.collection.model.deleteMany(filters));
|
|
22
22
|
};
|
|
23
23
|
exports.removeAll = removeAll;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { Result, throwIfError } from "@aeriajs/common";
|
|
3
3
|
import { traverseDocument, cascadingRemove } from "../../collection/index.mjs";
|
|
4
4
|
export const removeAll = async (payload, context) => {
|
|
5
5
|
const filtersWithId = {
|
|
@@ -8,13 +8,13 @@ export const removeAll = async (payload, context) => {
|
|
|
8
8
|
$in: payload.filters
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
-
const filters =
|
|
11
|
+
const filters = throwIfError(await traverseDocument(filtersWithId, context.description, {
|
|
12
12
|
autoCast: true
|
|
13
13
|
}));
|
|
14
14
|
const it = context.collection.model.find(filters);
|
|
15
|
-
let
|
|
16
|
-
while (
|
|
17
|
-
await cascadingRemove(
|
|
15
|
+
let doc;
|
|
16
|
+
while (doc = await it.next()) {
|
|
17
|
+
await cascadingRemove(doc, context);
|
|
18
18
|
}
|
|
19
|
-
return context.collection.model.deleteMany(filters);
|
|
19
|
+
return Result.result(await context.collection.model.deleteMany(filters));
|
|
20
20
|
};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { Context, RemoveFilePayload } from '@aeriajs/types';
|
|
2
|
-
export declare const removeFile: <TContext extends Context>(payload: RemoveFilePayload, context: TContext) => Promise<
|
|
2
|
+
export declare const removeFile: <TContext extends Context>(payload: RemoveFilePayload, context: TContext) => Promise<{
|
|
3
|
+
readonly _tag: "Result";
|
|
4
|
+
readonly error: undefined;
|
|
5
|
+
readonly result: any;
|
|
6
|
+
}>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeFile = void 0;
|
|
4
4
|
const security_1 = require("@aeriajs/security");
|
|
5
|
+
const common_1 = require("@aeriajs/common");
|
|
5
6
|
const removeFile = async (payload, context) => {
|
|
6
7
|
const { propertyName, parentId, ...props } = payload;
|
|
7
8
|
await (0, security_1.checkImmutability)({
|
|
@@ -10,6 +11,7 @@ const removeFile = async (payload, context) => {
|
|
|
10
11
|
childId: props.filters._id,
|
|
11
12
|
payload: props,
|
|
12
13
|
}, context);
|
|
13
|
-
|
|
14
|
+
const doc = await context.collections.file.functions.remove(props);
|
|
15
|
+
return common_1.Result.result(doc);
|
|
14
16
|
};
|
|
15
17
|
exports.removeFile = removeFile;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { checkImmutability } from "@aeriajs/security";
|
|
3
|
+
import { Result } from "@aeriajs/common";
|
|
3
4
|
export const removeFile = async (payload, context) => {
|
|
4
5
|
const {
|
|
5
6
|
propertyName,
|
|
@@ -12,5 +13,6 @@ export const removeFile = async (payload, context) => {
|
|
|
12
13
|
childId: props.filters._id,
|
|
13
14
|
payload: props
|
|
14
15
|
}, context);
|
|
15
|
-
|
|
16
|
+
const doc = await context.collections.file.functions.remove(props);
|
|
17
|
+
return Result.result(doc);
|
|
16
18
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ACError, HTTPStatus, type Context } from '@aeriajs/types';
|
|
2
|
-
export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<import("@aeriajs/types").
|
|
2
|
+
export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<import("@aeriajs/types/result").Result.Error<{
|
|
3
3
|
readonly code: ACError.MalformedInput;
|
|
4
4
|
readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
|
|
5
5
|
} & {
|
|
6
6
|
httpStatus: HTTPStatus.BadRequest;
|
|
7
7
|
}> | {
|
|
8
|
-
|
|
8
|
+
readonly _tag: "Result";
|
|
9
|
+
readonly error: undefined;
|
|
10
|
+
readonly result: {
|
|
11
|
+
readonly tempId: any;
|
|
12
|
+
};
|
|
9
13
|
}>;
|
|
@@ -25,9 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.upload = void 0;
|
|
27
27
|
const types_1 = require("@aeriajs/types");
|
|
28
|
-
const common_1 = require("@aeriajs/common");
|
|
29
28
|
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
30
29
|
const validation_1 = require("@aeriajs/validation");
|
|
30
|
+
const common_1 = require("@aeriajs/common");
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const fs_1 = require("fs");
|
|
33
33
|
const crypto_1 = require("crypto");
|
|
@@ -65,7 +65,7 @@ const upload = async (_props, context) => {
|
|
|
65
65
|
if (!tempFileCollection) {
|
|
66
66
|
throw new Error('The "tempFile" collection is absent, yet it is required to upload files.');
|
|
67
67
|
}
|
|
68
|
-
const
|
|
68
|
+
const { error: headersError } = (0, validation_1.validate)(context.request.headers, {
|
|
69
69
|
type: 'object',
|
|
70
70
|
properties: {
|
|
71
71
|
'x-stream-request': {
|
|
@@ -78,20 +78,19 @@ const upload = async (_props, context) => {
|
|
|
78
78
|
}, {
|
|
79
79
|
extraneous: true,
|
|
80
80
|
});
|
|
81
|
-
if (
|
|
81
|
+
if (headersError) {
|
|
82
82
|
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
83
83
|
code: types_1.ACError.MalformedInput,
|
|
84
|
-
details:
|
|
84
|
+
details: headersError,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
87
|
+
const { error, result: metadata } = validateFileMetadata(context.request.query);
|
|
88
|
+
if (error) {
|
|
89
89
|
return context.error(types_1.HTTPStatus.BadRequest, {
|
|
90
90
|
code: types_1.ACError.MalformedInput,
|
|
91
|
-
details:
|
|
91
|
+
details: error,
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
const metadata = (0, common_1.unwrapEither)(metadataEither);
|
|
95
94
|
const path = await streamToFs(metadata, context);
|
|
96
95
|
const file = await context.collections.tempFile.model.insertOne({
|
|
97
96
|
created_at: new Date(),
|
|
@@ -101,8 +100,8 @@ const upload = async (_props, context) => {
|
|
|
101
100
|
collection: context.description.$id,
|
|
102
101
|
name: metadata.name,
|
|
103
102
|
});
|
|
104
|
-
return {
|
|
103
|
+
return common_1.Result.result({
|
|
105
104
|
tempId: file.insertedId,
|
|
106
|
-
};
|
|
105
|
+
});
|
|
107
106
|
};
|
|
108
107
|
exports.upload = upload;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ACError, HTTPStatus } from "@aeriajs/types";
|
|
3
|
-
import { isLeft, unwrapEither } from "@aeriajs/common";
|
|
4
3
|
import { getCollection } from "@aeriajs/entrypoint";
|
|
5
4
|
import { validate, validator } from "@aeriajs/validation";
|
|
5
|
+
import { Result } from "@aeriajs/common";
|
|
6
6
|
import * as path from "path";
|
|
7
7
|
import { createWriteStream } from "fs";
|
|
8
8
|
import { createHash } from "crypto";
|
|
@@ -34,7 +34,7 @@ export const upload = async (_props, context) => {
|
|
|
34
34
|
if (!tempFileCollection) {
|
|
35
35
|
throw new Error('The "tempFile" collection is absent, yet it is required to upload files.');
|
|
36
36
|
}
|
|
37
|
-
const
|
|
37
|
+
const { error: headersError } = validate(context.request.headers, {
|
|
38
38
|
type: "object",
|
|
39
39
|
properties: {
|
|
40
40
|
"x-stream-request": {
|
|
@@ -47,20 +47,19 @@ export const upload = async (_props, context) => {
|
|
|
47
47
|
}, {
|
|
48
48
|
extraneous: true
|
|
49
49
|
});
|
|
50
|
-
if (
|
|
50
|
+
if (headersError) {
|
|
51
51
|
return context.error(HTTPStatus.BadRequest, {
|
|
52
52
|
code: ACError.MalformedInput,
|
|
53
|
-
details:
|
|
53
|
+
details: headersError
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
56
|
+
const { error, result: metadata } = validateFileMetadata(context.request.query);
|
|
57
|
+
if (error) {
|
|
58
58
|
return context.error(HTTPStatus.BadRequest, {
|
|
59
59
|
code: ACError.MalformedInput,
|
|
60
|
-
details:
|
|
60
|
+
details: error
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
const metadata = unwrapEither(metadataEither);
|
|
64
63
|
const path2 = await streamToFs(metadata, context);
|
|
65
64
|
const file = await context.collections.tempFile.model.insertOne({
|
|
66
65
|
created_at: /* @__PURE__ */ new Date(),
|
|
@@ -70,7 +69,7 @@ export const upload = async (_props, context) => {
|
|
|
70
69
|
collection: context.description.$id,
|
|
71
70
|
name: metadata.name
|
|
72
71
|
});
|
|
73
|
-
return {
|
|
72
|
+
return Result.result({
|
|
74
73
|
tempId: file.insertedId
|
|
75
|
-
};
|
|
74
|
+
});
|
|
76
75
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.96",
|
|
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.96",
|
|
45
|
+
"@aeriajs/common": "^0.0.60",
|
|
46
|
+
"@aeriajs/entrypoint": "^0.0.61",
|
|
47
|
+
"@aeriajs/http": "^0.0.69",
|
|
48
|
+
"@aeriajs/security": "^0.0.96",
|
|
49
|
+
"@aeriajs/types": "^0.0.56",
|
|
50
|
+
"@aeriajs/validation": "^0.0.63"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"mongodb": "^6.5.0",
|