@aeriajs/core 0.0.95 → 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.
Files changed (40) hide show
  1. package/dist/assets.d.ts +39 -3
  2. package/dist/assets.js +18 -20
  3. package/dist/assets.mjs +19 -21
  4. package/dist/collection/cascadingRemove.js +6 -7
  5. package/dist/collection/cascadingRemove.mjs +6 -7
  6. package/dist/collection/preload.js +5 -4
  7. package/dist/collection/preload.mjs +6 -5
  8. package/dist/collection/prepareInsert.js +2 -1
  9. package/dist/collection/prepareInsert.mjs +2 -1
  10. package/dist/collection/reference.js +4 -4
  11. package/dist/collection/reference.mjs +5 -5
  12. package/dist/collection/traverseDocument.d.ts +9 -1
  13. package/dist/collection/traverseDocument.js +37 -34
  14. package/dist/collection/traverseDocument.mjs +41 -38
  15. package/dist/context.js +4 -4
  16. package/dist/context.mjs +5 -5
  17. package/dist/functions/builtin/count.d.ts +5 -1
  18. package/dist/functions/builtin/count.js +5 -5
  19. package/dist/functions/builtin/count.mjs +5 -5
  20. package/dist/functions/builtin/get.js +9 -6
  21. package/dist/functions/builtin/get.mjs +10 -7
  22. package/dist/functions/builtin/getAll.d.ts +5 -1
  23. package/dist/functions/builtin/getAll.js +4 -4
  24. package/dist/functions/builtin/getAll.mjs +5 -5
  25. package/dist/functions/builtin/insert.d.ts +11 -19
  26. package/dist/functions/builtin/insert.js +6 -8
  27. package/dist/functions/builtin/insert.mjs +7 -9
  28. package/dist/functions/builtin/remove.d.ts +10 -1
  29. package/dist/functions/builtin/remove.js +2 -2
  30. package/dist/functions/builtin/remove.mjs +3 -3
  31. package/dist/functions/builtin/removeAll.d.ts +5 -1
  32. package/dist/functions/builtin/removeAll.js +5 -5
  33. package/dist/functions/builtin/removeAll.mjs +6 -6
  34. package/dist/functions/builtin/removeFile.d.ts +5 -1
  35. package/dist/functions/builtin/removeFile.js +3 -1
  36. package/dist/functions/builtin/removeFile.mjs +3 -1
  37. package/dist/functions/builtin/upload.d.ts +6 -2
  38. package/dist/functions/builtin/upload.js +9 -10
  39. package/dist/functions/builtin/upload.mjs +9 -10
  40. package/package.json +8 -8
@@ -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.throwIfLeft)(await (0, index_js_1.traverseDocument)(payload.filters, context.description, {
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 { throwIfLeft } from "@aeriajs/common";
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 = throwIfLeft(await traverseDocument(payload.filters, context.description, {
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<any>;
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.throwIfLeft)(await (0, index_js_1.traverseDocument)(filtersWithId, context.description, {
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 document;
18
- while (document = await it.next()) {
19
- await (0, index_js_1.cascadingRemove)(document, context);
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 { throwIfLeft } from "@aeriajs/common";
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 = throwIfLeft(await traverseDocument(filtersWithId, context.description, {
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 document;
16
- while (document = await it.next()) {
17
- await cascadingRemove(document, context);
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<any>;
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
- return context.collections.file.functions.remove(props);
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
- return context.collections.file.functions.remove(props);
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").EndpointError<{
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
- tempId: any;
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 headersEither = (0, validation_1.validate)(context.request.headers, {
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 ((0, common_1.isLeft)(headersEither)) {
81
+ if (headersError) {
82
82
  return context.error(types_1.HTTPStatus.BadRequest, {
83
83
  code: types_1.ACError.MalformedInput,
84
- details: (0, common_1.unwrapEither)(headersEither),
84
+ details: headersError,
85
85
  });
86
86
  }
87
- const metadataEither = validateFileMetadata(context.request.query);
88
- if ((0, common_1.isLeft)(metadataEither)) {
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: (0, common_1.unwrapEither)(metadataEither),
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 headersEither = validate(context.request.headers, {
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 (isLeft(headersEither)) {
50
+ if (headersError) {
51
51
  return context.error(HTTPStatus.BadRequest, {
52
52
  code: ACError.MalformedInput,
53
- details: unwrapEither(headersEither)
53
+ details: headersError
54
54
  });
55
55
  }
56
- const metadataEither = validateFileMetadata(context.request.query);
57
- if (isLeft(metadataEither)) {
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: unwrapEither(metadataEither)
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.95",
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.95",
45
- "@aeriajs/common": "^0.0.59",
46
- "@aeriajs/entrypoint": "^0.0.60",
47
- "@aeriajs/http": "^0.0.68",
48
- "@aeriajs/security": "^0.0.95",
49
- "@aeriajs/types": "^0.0.55",
50
- "@aeriajs/validation": "^0.0.62"
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",