@aeriajs/core 0.0.89 → 0.0.90

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.
@@ -101,7 +101,7 @@ const getReferences = async (properties, options) => {
101
101
  }
102
102
  }
103
103
  else {
104
- const description = (0, common_1.unsafe)(await (0, assets_js_1.getCollectionAsset)(refProperty.$ref, 'description'));
104
+ const description = (0, common_1.throwIfLeft)(await (0, assets_js_1.getCollectionAsset)(refProperty.$ref, 'description'));
105
105
  const deepReferences = await (0, exports.getReferences)(description.properties, {
106
106
  depth: depth + 1,
107
107
  memoize: `${memoize}.${propName}`,
@@ -159,7 +159,7 @@ const buildLookupStages = async (reference, propName, options) => {
159
159
  else {
160
160
  const subPipeline = [];
161
161
  if (reference.deepReferences) {
162
- const subProperties = (0, common_1.unsafe)(await (0, assets_js_1.getCollectionAsset)(reference.referencedCollection, 'description')).properties;
162
+ const subProperties = (0, common_1.throwIfLeft)(await (0, assets_js_1.getCollectionAsset)(reference.referencedCollection, 'description')).properties;
163
163
  subPipeline.push(...await (0, exports.buildLookupPipeline)(reference.deepReferences, {
164
164
  project: reference.populatedProperties,
165
165
  properties: subProperties,
@@ -227,7 +227,7 @@ const buildLookupStages = async (reference, propName, options) => {
227
227
  continue;
228
228
  }
229
229
  if (refMap.referencedCollection) {
230
- const description = (0, common_1.unsafe)(await (0, assets_js_1.getCollectionAsset)(refMap.referencedCollection, 'description'));
230
+ const description = (0, common_1.throwIfLeft)(await (0, assets_js_1.getCollectionAsset)(refMap.referencedCollection, 'description'));
231
231
  const { stages: result } = await buildLookupStages(refMap, refName, {
232
232
  depth: depth + 1,
233
233
  parent: withParent(propName),
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { unsafe, getReferenceProperty } from "@aeriajs/common";
2
+ import { throwIfLeft, getReferenceProperty } from "@aeriajs/common";
3
3
  import { getCollectionAsset } from "../assets.mjs";
4
4
  import { prepareCollectionName } from "../database.mjs";
5
5
  const referenceMemo = {};
@@ -90,7 +90,7 @@ export const getReferences = async (properties, options) => {
90
90
  }
91
91
  }
92
92
  } else {
93
- const description = unsafe(await getCollectionAsset(refProperty.$ref, "description"));
93
+ const description = throwIfLeft(await getCollectionAsset(refProperty.$ref, "description"));
94
94
  const deepReferences = await getReferences(description.properties, {
95
95
  depth: depth + 1,
96
96
  memoize: `${memoize}.${propName}`
@@ -147,7 +147,7 @@ const buildLookupStages = async (reference, propName, options) => {
147
147
  } else {
148
148
  const subPipeline = [];
149
149
  if (reference.deepReferences) {
150
- const subProperties = unsafe(await getCollectionAsset(reference.referencedCollection, "description")).properties;
150
+ const subProperties = throwIfLeft(await getCollectionAsset(reference.referencedCollection, "description")).properties;
151
151
  subPipeline.push(...await buildLookupPipeline(reference.deepReferences, {
152
152
  project: reference.populatedProperties,
153
153
  properties: subProperties
@@ -210,7 +210,7 @@ const buildLookupStages = async (reference, propName, options) => {
210
210
  continue;
211
211
  }
212
212
  if (refMap.referencedCollection) {
213
- const description = unsafe(await getCollectionAsset(refMap.referencedCollection, "description"));
213
+ const description = throwIfLeft(await getCollectionAsset(refMap.referencedCollection, "description"));
214
214
  const { stages: result2 } = await buildLookupStages(refMap, refName, {
215
215
  depth: depth + 1,
216
216
  parent: withParent(propName),
@@ -31,5 +31,5 @@ type PhaseContext = {
31
31
  property: Property;
32
32
  options: TraverseOptions & TraverseNormalized;
33
33
  };
34
- export declare const traverseDocument: <const TWhat extends Record<string, any>>(what: TWhat, description: Description, _options: TraverseOptions) => Promise<import("@aeriajs/types").Right<any> | import("@aeriajs/types").Left<ACError | ValidationError>>;
34
+ export declare const traverseDocument: <const TWhat extends Record<string, unknown>>(what: TWhat, description: Description, _options: TraverseOptions) => Promise<import("@aeriajs/types").Right<any> | import("@aeriajs/types").Left<ACError.InsecureOperator | ValidationError>>;
35
35
  export {};
@@ -307,7 +307,7 @@ const recurse = async (target, ctx) => {
307
307
  ? property.items
308
308
  : property;
309
309
  if ('$ref' in propCast && value && !(value instanceof mongodb_1.ObjectId)) {
310
- const targetDescription = await (0, preload_js_1.preloadDescription)((0, common_1.unsafe)(await (0, assets_js_1.getCollectionAsset)(propCast.$ref, 'description')));
310
+ const targetDescription = await (0, preload_js_1.preloadDescription)((0, common_1.throwIfLeft)(await (0, assets_js_1.getCollectionAsset)(propCast.$ref, 'description')));
311
311
  if (Array.isArray(value)) {
312
312
  const documents = [];
313
313
  for (const elem of value) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { ACError, ValidationErrorCode } from "@aeriajs/types";
3
- import { left, right, isLeft, unwrapEither, unsafe, pipe, isReference, getValueFromPath, isObjectId } from "@aeriajs/common";
3
+ import { left, right, isLeft, unwrapEither, throwIfLeft, pipe, isReference, getValueFromPath, isObjectId } from "@aeriajs/common";
4
4
  import { makeValidationError, validateProperty, validateWholeness } from "@aeriajs/validation";
5
5
  import { ObjectId } from "mongodb";
6
6
  import { getCollectionAsset } from "../assets.mjs";
@@ -267,7 +267,7 @@ const recurse = async (target, ctx) => {
267
267
  if (ctx.options.recurseReferences) {
268
268
  const propCast = "items" in property ? property.items : property;
269
269
  if ("$ref" in propCast && value && !(value instanceof ObjectId)) {
270
- const targetDescription = await preloadDescription(unsafe(await getCollectionAsset(propCast.$ref, "description")));
270
+ const targetDescription = await preloadDescription(throwIfLeft(await getCollectionAsset(propCast.$ref, "description")));
271
271
  if (Array.isArray(value)) {
272
272
  const documents = [];
273
273
  for (const elem of value) {
package/dist/context.js CHANGED
@@ -85,7 +85,7 @@ const createContext = async (options = {}) => {
85
85
  return (0, security_1.limitRate)(params, context);
86
86
  };
87
87
  if (collectionName) {
88
- const description = (0, common_1.unsafe)(await getCollectionAsset(collectionName, 'description'));
88
+ const description = (0, common_1.throwIfLeft)(await getCollectionAsset(collectionName, 'description'));
89
89
  context.description = await (0, preload_js_1.preloadDescription)(description);
90
90
  context.collectionName = collectionName;
91
91
  context.collection = indepthCollection(collectionName, collections, context);
package/dist/context.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { unsafe, error } from "@aeriajs/common";
2
+ import { throwIfLeft, error } from "@aeriajs/common";
3
3
  import { getCollections } from "@aeriajs/entrypoint";
4
4
  import { limitRate } from "@aeriajs/security";
5
5
  import { getDatabaseCollection } from "./database.mjs";
@@ -60,7 +60,7 @@ export const createContext = async (options = {}) => {
60
60
  return limitRate(params, context);
61
61
  };
62
62
  if (collectionName) {
63
- const description = unsafe(await getCollectionAsset(collectionName, "description"));
63
+ const description = throwIfLeft(await getCollectionAsset(collectionName, "description"));
64
64
  context.description = await preloadDescription(description);
65
65
  context.collectionName = collectionName;
66
66
  context.collection = indepthCollection(collectionName, collections, context);
@@ -6,9 +6,9 @@ const common_1 = require("@aeriajs/common");
6
6
  const index_js_1 = require("../../collection/index.js");
7
7
  const count = async (payload, context) => {
8
8
  const security = (0, security_1.useSecurity)(context);
9
- const { filters } = (0, common_1.unsafe)(await security.beforeRead(payload));
9
+ const { filters } = (0, common_1.throwIfLeft)(await security.beforeRead(payload));
10
10
  const { $text, ...filtersRest } = filters;
11
- const traversedFilters = (0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
11
+ const traversedFilters = (0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
12
12
  autoCast: true,
13
13
  allowOperators: true,
14
14
  }));
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  import { useSecurity } from "@aeriajs/security";
3
- import { unsafe } from "@aeriajs/common";
3
+ import { throwIfLeft } from "@aeriajs/common";
4
4
  import { traverseDocument } from "../../collection/index.mjs";
5
5
  export const count = async (payload, context) => {
6
6
  const security = useSecurity(context);
7
- const { filters } = unsafe(await security.beforeRead(payload));
7
+ const { filters } = throwIfLeft(await security.beforeRead(payload));
8
8
  const { $text, ...filtersRest } = filters;
9
- const traversedFilters = unsafe(await traverseDocument(filtersRest, context.description, {
9
+ const traversedFilters = throwIfLeft(await traverseDocument(filtersRest, context.description, {
10
10
  autoCast: true,
11
11
  allowOperators: true
12
12
  }));
@@ -8,7 +8,7 @@ const index_js_1 = require("../../collection/index.js");
8
8
  const get = async (payload, context, options) => {
9
9
  const security = (0, security_1.useSecurity)(context);
10
10
  const { filters = {}, project = [], } = !options?.bypassSecurity
11
- ? (0, common_1.unsafe)(await security.beforeRead(payload))
11
+ ? (0, common_1.throwIfLeft)(await security.beforeRead(payload))
12
12
  : payload;
13
13
  if (Object.keys(filters).length === 0) {
14
14
  throw new Error('no filters were passed');
@@ -18,7 +18,7 @@ const get = async (payload, context, options) => {
18
18
  memoize: context.description.$id,
19
19
  });
20
20
  pipeline.push({
21
- $match: (0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(filters, context.description, {
21
+ $match: (0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(filters, context.description, {
22
22
  autoCast: true,
23
23
  allowOperators: true,
24
24
  })),
@@ -40,7 +40,7 @@ const get = async (payload, context, options) => {
40
40
  code: types_1.ACError.ResourceNotFound,
41
41
  });
42
42
  }
43
- return (0, index_js_1.fill)((0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(result, context.description, {
43
+ return (0, index_js_1.fill)((0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(result, context.description, {
44
44
  getters: true,
45
45
  fromProperties: true,
46
46
  recurseReferences: true,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError } from "@aeriajs/types";
3
3
  import { useSecurity } from "@aeriajs/security";
4
- import { unsafe } from "@aeriajs/common";
4
+ import { throwIfLeft } from "@aeriajs/common";
5
5
  import {
6
6
  traverseDocument,
7
7
  normalizeProjection,
@@ -14,7 +14,7 @@ export const get = async (payload, context, options) => {
14
14
  const {
15
15
  filters = {},
16
16
  project = []
17
- } = !options?.bypassSecurity ? unsafe(await security.beforeRead(payload)) : payload;
17
+ } = !options?.bypassSecurity ? throwIfLeft(await security.beforeRead(payload)) : payload;
18
18
  if (Object.keys(filters).length === 0) {
19
19
  throw new Error("no filters were passed");
20
20
  }
@@ -23,7 +23,7 @@ export const get = async (payload, context, options) => {
23
23
  memoize: context.description.$id
24
24
  });
25
25
  pipeline.push({
26
- $match: unsafe(await traverseDocument(filters, context.description, {
26
+ $match: throwIfLeft(await traverseDocument(filters, context.description, {
27
27
  autoCast: true,
28
28
  allowOperators: true
29
29
  }))
@@ -45,7 +45,7 @@ export const get = async (payload, context, options) => {
45
45
  code: ACError.ResourceNotFound
46
46
  });
47
47
  }
48
- return fill(unsafe(await traverseDocument(result, context.description, {
48
+ return fill(throwIfLeft(await traverseDocument(result, context.description, {
49
49
  getters: true,
50
50
  fromProperties: true,
51
51
  recurseReferences: true,
@@ -8,7 +8,7 @@ const getAll = async (_payload, context, options = {}) => {
8
8
  const security = (0, security_1.useSecurity)(context);
9
9
  const payload = _payload || {};
10
10
  const { filters = {}, limit = context.config.paginationLimit, sort, project = [], offset = 0, } = !options.bypassSecurity
11
- ? (0, common_1.unsafe)(await security.beforeRead(payload))
11
+ ? (0, common_1.throwIfLeft)(await security.beforeRead(payload))
12
12
  : payload;
13
13
  const { $text, ...filtersRest } = filters;
14
14
  const pipeline = [];
@@ -36,7 +36,7 @@ const getAll = async (_payload, context, options = {}) => {
36
36
  }
37
37
  if (Object.keys(filtersRest).length > 0) {
38
38
  pipeline.push({
39
- $match: (0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
39
+ $match: (0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(filtersRest, context.description, {
40
40
  autoCast: true,
41
41
  allowOperators: true,
42
42
  })),
@@ -69,7 +69,7 @@ const getAll = async (_payload, context, options = {}) => {
69
69
  const result = await context.collection.model.aggregate(pipeline).toArray();
70
70
  const documents = [];
71
71
  for (const document of result) {
72
- documents.push((0, common_1.unsafe)(await (0, index_js_1.traverseDocument)((0, index_js_1.fill)(document, context.description), context.description, {
72
+ documents.push((0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)((0, index_js_1.fill)(document, context.description), context.description, {
73
73
  getters: true,
74
74
  fromProperties: true,
75
75
  recurseReferences: true,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { useSecurity } from "@aeriajs/security";
3
- import { unsafe } from "@aeriajs/common";
3
+ import { throwIfLeft } 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 ? unsafe(await security.beforeRead(payload)) : payload;
20
+ } = !options.bypassSecurity ? throwIfLeft(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: unsafe(await traverseDocument(filtersRest, context.description, {
43
+ $match: throwIfLeft(await traverseDocument(filtersRest, context.description, {
44
44
  autoCast: true,
45
45
  allowOperators: true
46
46
  }))
@@ -73,7 +73,7 @@ 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(unsafe(await traverseDocument(fill(document, context.description), context.description, {
76
+ documents.push(throwIfLeft(await traverseDocument(fill(document, context.description), context.description, {
77
77
  getters: true,
78
78
  fromProperties: true,
79
79
  recurseReferences: true,
@@ -6,15 +6,18 @@ export type InsertOptions = {
6
6
  export declare const insertErrorSchema: {
7
7
  readonly type: "object";
8
8
  readonly properties: {
9
+ readonly _tag: {
10
+ readonly const: "Error";
11
+ };
9
12
  readonly value: {
10
13
  readonly type: "object";
11
14
  readonly required: readonly ["httpStatus", "code"];
12
15
  readonly properties: {
13
16
  readonly httpStatus: {
14
- readonly enum: (HTTPStatus.NotFound | HTTPStatus.UnprocessableContent)[];
17
+ readonly enum: [HTTPStatus.UnprocessableContent, HTTPStatus.NotFound];
15
18
  };
16
19
  readonly code: {
17
- readonly enum: (ACError | ValidationErrorCode)[];
20
+ readonly enum: [ACError.InsecureOperator, ACError.OwnershipError, ACError.ResourceNotFound, ACError.TargetImmutable, ValidationErrorCode.EmptyTarget, ValidationErrorCode.InvalidProperties, ValidationErrorCode.MissingProperties];
18
21
  };
19
22
  readonly message: {
20
23
  readonly type: "string";
@@ -23,7 +23,7 @@ exports.insertErrorSchema = (0, common_1.endpointErrorSchema)({
23
23
  const insert = async (payload, context, options) => {
24
24
  const security = (0, security_1.useSecurity)(context);
25
25
  const query = !options?.bypassSecurity
26
- ? (0, common_1.unsafe)(await security.beforeWrite(payload))
26
+ ? (0, common_1.throwIfLeft)(await security.beforeWrite(payload))
27
27
  : payload;
28
28
  const whatEither = await (0, index_js_1.traverseDocument)(query.what, context.description, {
29
29
  recurseDeep: true,
@@ -95,7 +95,7 @@ const insert = async (payload, context, options) => {
95
95
  code: types_1.ACError.ResourceNotFound,
96
96
  });
97
97
  }
98
- const result = (0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(doc, context.description, {
98
+ const result = (0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(doc, context.description, {
99
99
  getters: true,
100
100
  fromProperties: true,
101
101
  recurseReferences: true,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError, ValidationErrorCode } from "@aeriajs/types";
3
3
  import { useSecurity } from "@aeriajs/security";
4
- import { isLeft, unwrapEither, unsafe, endpointErrorSchema } from "@aeriajs/common";
4
+ import { isLeft, unwrapEither, throwIfLeft, endpointErrorSchema } from "@aeriajs/common";
5
5
  import { traverseDocument, normalizeProjection, prepareInsert } from "../../collection/index.mjs";
6
6
  export const insertErrorSchema = endpointErrorSchema({
7
7
  httpStatus: [
@@ -20,7 +20,7 @@ export const insertErrorSchema = endpointErrorSchema({
20
20
  });
21
21
  export const insert = async (payload, context, options) => {
22
22
  const security = useSecurity(context);
23
- const query = !options?.bypassSecurity ? unsafe(await security.beforeWrite(payload)) : payload;
23
+ const query = !options?.bypassSecurity ? throwIfLeft(await security.beforeWrite(payload)) : payload;
24
24
  const whatEither = await traverseDocument(query.what, context.description, {
25
25
  recurseDeep: true,
26
26
  autoCast: true,
@@ -83,7 +83,7 @@ export const insert = async (payload, context, options) => {
83
83
  code: ACError.ResourceNotFound
84
84
  });
85
85
  }
86
- const result = unsafe(await traverseDocument(doc, context.description, {
86
+ const result = throwIfLeft(await traverseDocument(doc, context.description, {
87
87
  getters: true,
88
88
  fromProperties: true,
89
89
  recurseReferences: true
@@ -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.unsafe)(await (0, index_js_1.traverseDocument)(payload.filters, context.description, {
13
+ const filters = (0, common_1.throwIfLeft)(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);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError } from "@aeriajs/types";
3
- import { unsafe } from "@aeriajs/common";
3
+ import { throwIfLeft } 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 = unsafe(await traverseDocument(payload.filters, context.description, {
11
+ const filters = throwIfLeft(await traverseDocument(payload.filters, context.description, {
12
12
  autoCast: true
13
13
  }));
14
14
  const target = await context.collection.model.findOne(filters);
@@ -10,7 +10,7 @@ const removeAll = async (payload, context) => {
10
10
  $in: payload.filters,
11
11
  },
12
12
  };
13
- const filters = (0, common_1.unsafe)(await (0, index_js_1.traverseDocument)(filtersWithId, context.description, {
13
+ const filters = (0, common_1.throwIfLeft)(await (0, index_js_1.traverseDocument)(filtersWithId, context.description, {
14
14
  autoCast: true,
15
15
  }));
16
16
  const it = context.collection.model.find(filters);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- import { unsafe } from "@aeriajs/common";
2
+ import { throwIfLeft } 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,7 +8,7 @@ export const removeAll = async (payload, context) => {
8
8
  $in: payload.filters
9
9
  }
10
10
  };
11
- const filters = unsafe(await traverseDocument(filtersWithId, context.description, {
11
+ const filters = throwIfLeft(await traverseDocument(filtersWithId, context.description, {
12
12
  autoCast: true
13
13
  }));
14
14
  const it = context.collection.model.find(filters);
@@ -1,4 +1,9 @@
1
- import type { Context } from '@aeriajs/types';
2
- export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<import("@aeriajs/types").Left<import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError> | {
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").EndpointError<{
3
+ readonly code: ACError.MalformedInput;
4
+ readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
5
+ } & {
6
+ httpStatus: HTTPStatus.BadRequest;
7
+ }> | {
3
8
  tempId: any;
4
9
  }>;
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.upload = void 0;
27
+ const types_1 = require("@aeriajs/types");
27
28
  const common_1 = require("@aeriajs/common");
28
29
  const entrypoint_1 = require("@aeriajs/entrypoint");
29
30
  const validation_1 = require("@aeriajs/validation");
@@ -78,11 +79,17 @@ const upload = async (_props, context) => {
78
79
  extraneous: true,
79
80
  });
80
81
  if ((0, common_1.isLeft)(headersEither)) {
81
- return (0, common_1.left)((0, common_1.unwrapEither)(headersEither));
82
+ return context.error(types_1.HTTPStatus.BadRequest, {
83
+ code: types_1.ACError.MalformedInput,
84
+ details: (0, common_1.unwrapEither)(headersEither),
85
+ });
82
86
  }
83
87
  const metadataEither = validateFileMetadata(context.request.query);
84
88
  if ((0, common_1.isLeft)(metadataEither)) {
85
- return (0, common_1.left)((0, common_1.unwrapEither)(metadataEither));
89
+ return context.error(types_1.HTTPStatus.BadRequest, {
90
+ code: types_1.ACError.MalformedInput,
91
+ details: (0, common_1.unwrapEither)(metadataEither),
92
+ });
86
93
  }
87
94
  const metadata = (0, common_1.unwrapEither)(metadataEither);
88
95
  const path = await streamToFs(metadata, context);
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
- import { isLeft, unwrapEither, left } from "@aeriajs/common";
2
+ import { ACError, HTTPStatus } from "@aeriajs/types";
3
+ import { isLeft, unwrapEither } from "@aeriajs/common";
3
4
  import { getCollection } from "@aeriajs/entrypoint";
4
5
  import { validate, validator } from "@aeriajs/validation";
5
6
  import * as path from "path";
@@ -47,11 +48,17 @@ export const upload = async (_props, context) => {
47
48
  extraneous: true
48
49
  });
49
50
  if (isLeft(headersEither)) {
50
- return left(unwrapEither(headersEither));
51
+ return context.error(HTTPStatus.BadRequest, {
52
+ code: ACError.MalformedInput,
53
+ details: unwrapEither(headersEither)
54
+ });
51
55
  }
52
56
  const metadataEither = validateFileMetadata(context.request.query);
53
57
  if (isLeft(metadataEither)) {
54
- return left(unwrapEither(metadataEither));
58
+ return context.error(HTTPStatus.BadRequest, {
59
+ code: ACError.MalformedInput,
60
+ details: unwrapEither(metadataEither)
61
+ });
55
62
  }
56
63
  const metadata = unwrapEither(metadataEither);
57
64
  const path2 = await streamToFs(metadata, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.89",
3
+ "version": "0.0.90",
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.89",
45
- "@aeriajs/common": "^0.0.55",
46
- "@aeriajs/entrypoint": "^0.0.55",
47
- "@aeriajs/http": "^0.0.63",
48
- "@aeriajs/security": "^0.0.89",
49
- "@aeriajs/types": "^0.0.52",
50
- "@aeriajs/validation": "^0.0.58"
44
+ "@aeriajs/builtins": "^0.0.90",
45
+ "@aeriajs/common": "^0.0.56",
46
+ "@aeriajs/entrypoint": "^0.0.56",
47
+ "@aeriajs/http": "^0.0.64",
48
+ "@aeriajs/security": "^0.0.90",
49
+ "@aeriajs/types": "^0.0.53",
50
+ "@aeriajs/validation": "^0.0.59"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",