@aeriajs/core 0.0.109 → 0.0.110

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/assets.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFunction = exports.getCollectionAsset = exports.internalGetCollectionAsset = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
- const common_1 = require("@aeriajs/common");
6
5
  const security_1 = require("@aeriajs/security");
7
6
  const entrypoint_1 = require("@aeriajs/entrypoint");
8
7
  const accessControl_js_1 = require("./accessControl.js");
@@ -13,23 +12,23 @@ const internalGetCollectionAsset = async (collectionName, assetName) => {
13
12
  const collection = await (0, entrypoint_1.getCollection)(collectionName);
14
13
  const asset = collection?.[assetName];
15
14
  if (!asset) {
16
- return common_1.Result.error(types_1.ACError.ResourceNotFound);
15
+ return types_1.Result.error(types_1.ACError.ResourceNotFound);
17
16
  }
18
- return common_1.Result.result(asset);
17
+ return types_1.Result.result(asset);
19
18
  };
20
19
  exports.internalGetCollectionAsset = internalGetCollectionAsset;
21
20
  const getCollectionAsset = async (collectionName, assetName) => {
22
21
  const cached = assetsMemo.assets[collectionName];
23
22
  if (cached?.[assetName]) {
24
- return common_1.Result.result(cached[assetName]);
23
+ return types_1.Result.result(cached[assetName]);
25
24
  }
26
25
  const { error, result: asset } = await (0, exports.internalGetCollectionAsset)(collectionName, assetName);
27
26
  if (error) {
28
- return common_1.Result.error(error);
27
+ return types_1.Result.error(error);
29
28
  }
30
29
  assetsMemo.assets[collectionName] ??= {};
31
30
  assetsMemo.assets[collectionName][assetName] = asset;
32
- return common_1.Result.result(asset);
31
+ return types_1.Result.result(asset);
33
32
  };
34
33
  exports.getCollectionAsset = getCollectionAsset;
35
34
  const getFunction = async (collectionName, functionName, token, options = {
@@ -37,21 +36,21 @@ const getFunction = async (collectionName, functionName, token, options = {
37
36
  }) => {
38
37
  const { error, result: functions } = await (0, exports.getCollectionAsset)(collectionName, 'functions');
39
38
  if (error) {
40
- return common_1.Result.error(error);
39
+ return types_1.Result.error(error);
41
40
  }
42
41
  if (!(functionName in functions)) {
43
- return common_1.Result.error(types_1.ACError.FunctionNotFound);
42
+ return types_1.Result.error(types_1.ACError.FunctionNotFound);
44
43
  }
45
44
  const collection = await (0, entrypoint_1.getCollection)(collectionName);
46
45
  const fn = functions[functionName];
47
46
  if (!collection) {
48
- return common_1.Result.error(types_1.ACError.ResourceNotFound);
47
+ return types_1.Result.error(types_1.ACError.ResourceNotFound);
49
48
  }
50
49
  if (options.exposedOnly) {
51
50
  const exposedStatus = await (0, accessControl_js_1.isFunctionExposed)(collection, functionName, token);
52
51
  switch (exposedStatus) {
53
- case accessControl_js_1.FunctionExposedStatus.FunctionNotExposed: return common_1.Result.error(types_1.ACError.FunctionNotExposed);
54
- case accessControl_js_1.FunctionExposedStatus.FunctionNotGranted: return common_1.Result.error(types_1.ACError.AuthorizationError);
52
+ case accessControl_js_1.FunctionExposedStatus.FunctionNotExposed: return types_1.Result.error(types_1.ACError.FunctionNotExposed);
53
+ case accessControl_js_1.FunctionExposedStatus.FunctionNotGranted: return types_1.Result.error(types_1.ACError.AuthorizationError);
55
54
  }
56
55
  }
57
56
  const wrapper = async (payload, context) => {
@@ -60,12 +59,12 @@ const getFunction = async (collectionName, functionName, token, options = {
60
59
  if (securityPolicy.rateLimiting) {
61
60
  const { error } = await (0, security_1.limitRate)(securityPolicy.rateLimiting, context);
62
61
  if (error) {
63
- return common_1.Result.error(error);
62
+ return types_1.Result.error(error);
64
63
  }
65
64
  }
66
65
  }
67
66
  return fn(payload, context);
68
67
  };
69
- return common_1.Result.result(wrapper);
68
+ return types_1.Result.result(wrapper);
70
69
  };
71
70
  exports.getFunction = getFunction;
package/dist/assets.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
- import { ACError } from "@aeriajs/types";
3
- import { Result } from "@aeriajs/common";
2
+ import { Result, ACError } from "@aeriajs/types";
4
3
  import { limitRate } from "@aeriajs/security";
5
4
  import { getCollection } from "@aeriajs/entrypoint";
6
5
  import { isFunctionExposed, FunctionExposedStatus } from "./accessControl.mjs";
@@ -65,7 +65,7 @@ const disposeOldFiles = async (ctx, options = {}) => {
65
65
  },
66
66
  });
67
67
  if (!doc) {
68
- return common_1.Result.error(TraverseError.InvalidDocumentId);
68
+ return types_1.Result.error(TraverseError.InvalidDocumentId);
69
69
  }
70
70
  let fileIds = (0, common_1.getValueFromPath)(doc, ctx.propPath);
71
71
  if (options.fromIds) {
@@ -173,7 +173,7 @@ const validate = (value, ctx) => {
173
173
  }
174
174
  const { error } = (0, validation_1.validateProperty)(ctx.propName, value, ctx.property);
175
175
  if (error) {
176
- return common_1.Result.error({
176
+ return types_1.Result.error({
177
177
  [ctx.propName]: error,
178
178
  });
179
179
  }
@@ -196,7 +196,7 @@ const moveFiles = async (value, ctx) => {
196
196
  _id: new mongodb_1.ObjectId(value.tempId),
197
197
  });
198
198
  if (!tempFile) {
199
- return common_1.Result.error(TraverseError.InvalidTempfile);
199
+ return types_1.Result.error(TraverseError.InvalidTempfile);
200
200
  }
201
201
  if (ctx.root._id) {
202
202
  await disposeOldFiles(ctx);
@@ -214,7 +214,7 @@ const recurseDeep = async (value, ctx) => {
214
214
  if ('properties' in ctx.property) {
215
215
  const { error, result } = await recurse(value, ctx);
216
216
  if (error) {
217
- return common_1.Result.error(error);
217
+ return types_1.Result.error(error);
218
218
  }
219
219
  return result;
220
220
  }
@@ -272,7 +272,7 @@ const recurse = async (target, ctx) => {
272
272
  // it contains MongoDB query operators
273
273
  if (Object.keys(value)[0]?.startsWith('$')) {
274
274
  if (!ctx.options.allowOperators) {
275
- return common_1.Result.error(types_1.ACError.InsecureOperator);
275
+ return types_1.Result.error(types_1.ACError.InsecureOperator);
276
276
  }
277
277
  entries.push([
278
278
  propName,
@@ -285,7 +285,7 @@ const recurse = async (target, ctx) => {
285
285
  for (const operation of value) {
286
286
  const { error, result } = await recurse(operation, ctx);
287
287
  if (error) {
288
- return common_1.Result.error(error);
288
+ return types_1.Result.error(error);
289
289
  }
290
290
  operations.push(result);
291
291
  }
@@ -297,7 +297,7 @@ const recurse = async (target, ctx) => {
297
297
  }
298
298
  const { error, result: operator } = await recurse(value, ctx);
299
299
  if (error) {
300
- return common_1.Result.error(error);
300
+ return types_1.Result.error(error);
301
301
  }
302
302
  entries.push([
303
303
  propName,
@@ -320,7 +320,7 @@ const recurse = async (target, ctx) => {
320
320
  }
321
321
  const { error, result } = await (0, exports.traverseDocument)(elem, targetDescription, ctx.options);
322
322
  if (error) {
323
- return common_1.Result.error(error);
323
+ return types_1.Result.error(error);
324
324
  }
325
325
  documents.push(result);
326
326
  }
@@ -332,7 +332,7 @@ const recurse = async (target, ctx) => {
332
332
  }
333
333
  const { error, result: document } = await (0, exports.traverseDocument)(value, targetDescription, ctx.options);
334
334
  if (error) {
335
- return common_1.Result.error(error);
335
+ return types_1.Result.error(error);
336
336
  }
337
337
  entries.push([
338
338
  propName,
@@ -355,13 +355,13 @@ const recurse = async (target, ctx) => {
355
355
  ]);
356
356
  }
357
357
  }
358
- return common_1.Result.result(Object.fromEntries(entries));
358
+ return types_1.Result.result(Object.fromEntries(entries));
359
359
  };
360
360
  const traverseDocument = async (what, description, _options) => {
361
361
  const options = Object.assign({}, _options);
362
362
  const functions = [];
363
363
  if (!options.validate && Object.keys(what).length === 0) {
364
- return common_1.Result.result({});
364
+ return types_1.Result.result({});
365
365
  }
366
366
  if (options.recurseDeep) {
367
367
  functions.push(recurseDeep);
@@ -379,7 +379,7 @@ const traverseDocument = async (what, description, _options) => {
379
379
  }
380
380
  const wholenessError = (0, validation_1.validateWholeness)(what, descriptionCopy);
381
381
  if (wholenessError) {
382
- return common_1.Result.error(wholenessError);
382
+ return types_1.Result.error(wholenessError);
383
383
  }
384
384
  functions.push(validate);
385
385
  }
@@ -412,14 +412,14 @@ const traverseDocument = async (what, description, _options) => {
412
412
  options,
413
413
  });
414
414
  if (error) {
415
- return common_1.Result.error(error);
415
+ return types_1.Result.error(error);
416
416
  }
417
417
  if (validationError) {
418
- return common_1.Result.error((0, validation_1.makeValidationError)({
418
+ return types_1.Result.error((0, validation_1.makeValidationError)({
419
419
  code: types_1.ValidationErrorCode.InvalidProperties,
420
420
  errors: validationError,
421
421
  }));
422
422
  }
423
- return common_1.Result.result(result);
423
+ return types_1.Result.result(result);
424
424
  };
425
425
  exports.traverseDocument = traverseDocument;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- import { ACError, ValidationErrorCode } from "@aeriajs/types";
3
- import { Result, throwIfError, pipe, isReference, getValueFromPath, isObjectId } from "@aeriajs/common";
2
+ import { Result, ACError, ValidationErrorCode } from "@aeriajs/types";
3
+ import { throwIfError, 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";
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.count = void 0;
4
4
  const security_1 = require("@aeriajs/security");
5
+ const types_1 = require("@aeriajs/types");
5
6
  const common_1 = require("@aeriajs/common");
6
7
  const index_js_1 = require("../../collection/index.js");
7
8
  const count = async (payload, context) => {
@@ -28,10 +29,10 @@ const count = async (payload, context) => {
28
29
  $count: 'total',
29
30
  });
30
31
  const result = await context.collection.model.aggregate(pipeline).next();
31
- return common_1.Result.result(result
32
+ return types_1.Result.result(result
32
33
  ? result.total
33
34
  : 0);
34
35
  }
35
- return common_1.Result.result(await context.collection.model.countDocuments(traversedFilters));
36
+ return types_1.Result.result(await context.collection.model.countDocuments(traversedFilters));
36
37
  };
37
38
  exports.count = count;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  import { useSecurity } from "@aeriajs/security";
3
- import { Result, throwIfError } from "@aeriajs/common";
3
+ import { Result } from "@aeriajs/types";
4
+ import { throwIfError } from "@aeriajs/common";
4
5
  import { traverseDocument } from "../../collection/index.mjs";
5
6
  export const count = async (payload, context) => {
6
7
  const security = useSecurity(context);
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.get = void 0;
4
- const types_1 = require("@aeriajs/types");
5
4
  const security_1 = require("@aeriajs/security");
5
+ const types_1 = require("@aeriajs/types");
6
6
  const common_1 = require("@aeriajs/common");
7
7
  const index_js_1 = require("../../collection/index.js");
8
8
  const get = async (payload, context, options) => {
@@ -48,6 +48,6 @@ const get = async (payload, context, options) => {
48
48
  recurseReferences: true,
49
49
  recurseDeep: true,
50
50
  })), context.description);
51
- return common_1.Result.result(result);
51
+ return types_1.Result.result(result);
52
52
  };
53
53
  exports.get = get;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- import { HTTPStatus, ACError } from "@aeriajs/types";
3
2
  import { useSecurity } from "@aeriajs/security";
4
- import { Result, throwIfError } from "@aeriajs/common";
3
+ import { Result, HTTPStatus, ACError } from "@aeriajs/types";
4
+ import { throwIfError } from "@aeriajs/common";
5
5
  import {
6
6
  traverseDocument,
7
7
  normalizeProjection,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAll = void 0;
4
4
  const security_1 = require("@aeriajs/security");
5
+ const types_1 = require("@aeriajs/types");
5
6
  const common_1 = require("@aeriajs/common");
6
7
  const index_js_1 = require("../../collection/index.js");
7
8
  const getAll = async (_payload, context, options = {}) => {
@@ -76,6 +77,6 @@ const getAll = async (_payload, context, options = {}) => {
76
77
  recurseDeep: true,
77
78
  })));
78
79
  }
79
- return common_1.Result.result(documents);
80
+ return types_1.Result.result(documents);
80
81
  };
81
82
  exports.getAll = getAll;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  import { useSecurity } from "@aeriajs/security";
3
- import { Result, throwIfError } from "@aeriajs/common";
3
+ import { Result } from "@aeriajs/types";
4
+ import { throwIfError } from "@aeriajs/common";
4
5
  import {
5
6
  traverseDocument,
6
7
  normalizeProjection,
@@ -99,6 +99,6 @@ const insert = async (payload, context, options) => {
99
99
  fromProperties: true,
100
100
  recurseReferences: true,
101
101
  }));
102
- return common_1.Result.result(result);
102
+ return types_1.Result.result(result);
103
103
  };
104
104
  exports.insert = insert;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- import { HTTPStatus, ACError, ValidationErrorCode } from "@aeriajs/types";
2
+ import { Result, HTTPStatus, ACError, ValidationErrorCode } from "@aeriajs/types";
3
3
  import { useSecurity } from "@aeriajs/security";
4
- import { Result, throwIfError, endpointErrorSchema } from "@aeriajs/common";
4
+ import { throwIfError, endpointErrorSchema } from "@aeriajs/common";
5
5
  import { traverseDocument, normalizeProjection, prepareInsert } from "../../collection/index.mjs";
6
6
  export const insertErrorSchema = () => endpointErrorSchema({
7
7
  httpStatus: [
@@ -1,10 +1,10 @@
1
1
  import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
2
- import { HTTPStatus, ACError } from '@aeriajs/types';
2
+ import { Result, HTTPStatus, ACError } from '@aeriajs/types';
3
3
  export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext['description']>>, context: TContext) => Promise<{
4
4
  readonly _tag: "Result";
5
5
  readonly error: undefined;
6
6
  readonly result: any;
7
- } | import("@aeriajs/types/result.js").Result.Error<{
7
+ } | Result.Error<{
8
8
  readonly code: ACError.ResourceNotFound;
9
9
  } & {
10
10
  httpStatus: HTTPStatus.NotFound;
@@ -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 common_1.Result.result(await context.collection.model.findOneAndDelete(filters));
23
+ return types_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
- import { HTTPStatus, ACError } from "@aeriajs/types";
3
- import { Result, throwIfError } from "@aeriajs/common";
2
+ import { Result, HTTPStatus, ACError } from "@aeriajs/types";
3
+ import { 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) {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeAll = void 0;
4
+ const types_1 = require("@aeriajs/types");
4
5
  const common_1 = require("@aeriajs/common");
5
6
  const index_js_1 = require("../../collection/index.js");
6
7
  const removeAll = async (payload, context) => {
@@ -18,6 +19,6 @@ const removeAll = async (payload, context) => {
18
19
  while (doc = await it.next()) {
19
20
  await (0, index_js_1.cascadingRemove)(doc, context);
20
21
  }
21
- return common_1.Result.result(await context.collection.model.deleteMany(filters));
22
+ return types_1.Result.result(await context.collection.model.deleteMany(filters));
22
23
  };
23
24
  exports.removeAll = removeAll;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
- import { Result, throwIfError } from "@aeriajs/common";
2
+ import { Result } from "@aeriajs/types";
3
+ import { throwIfError } from "@aeriajs/common";
3
4
  import { traverseDocument, cascadingRemove } from "../../collection/index.mjs";
4
5
  export const removeAll = async (payload, context) => {
5
6
  const filtersWithId = {
@@ -2,7 +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
+ const types_1 = require("@aeriajs/types");
6
6
  const removeFile = async (payload, context) => {
7
7
  const { propertyName, parentId, ...props } = payload;
8
8
  await (0, security_1.checkImmutability)({
@@ -12,6 +12,6 @@ const removeFile = async (payload, context) => {
12
12
  payload: props,
13
13
  }, context);
14
14
  const doc = await context.collections.file.functions.remove(props);
15
- return common_1.Result.result(doc);
15
+ return types_1.Result.result(doc);
16
16
  };
17
17
  exports.removeFile = removeFile;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { checkImmutability } from "@aeriajs/security";
3
- import { Result } from "@aeriajs/common";
3
+ import { Result } from "@aeriajs/types";
4
4
  export const removeFile = async (payload, context) => {
5
5
  const {
6
6
  propertyName,
@@ -1,5 +1,5 @@
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/result").Result.Error<{
1
+ import { Result, ACError, HTTPStatus, type Context } from '@aeriajs/types';
2
+ export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<Result.Error<{
3
3
  readonly code: ACError.MalformedInput;
4
4
  readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
5
5
  } & {
@@ -27,7 +27,6 @@ exports.upload = void 0;
27
27
  const types_1 = require("@aeriajs/types");
28
28
  const entrypoint_1 = require("@aeriajs/entrypoint");
29
29
  const validation_1 = require("@aeriajs/validation");
30
- const common_1 = require("@aeriajs/common");
31
30
  const path = __importStar(require("path"));
32
31
  const fs_1 = require("fs");
33
32
  const crypto_1 = require("crypto");
@@ -100,7 +99,7 @@ const upload = async (_props, context) => {
100
99
  collection: context.description.$id,
101
100
  name: metadata.name,
102
101
  });
103
- return common_1.Result.result({
102
+ return types_1.Result.result({
104
103
  tempId: file.insertedId,
105
104
  });
106
105
  };
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
- import { ACError, HTTPStatus } from "@aeriajs/types";
2
+ import { Result, ACError, HTTPStatus } from "@aeriajs/types";
3
3
  import { getCollection } from "@aeriajs/entrypoint";
4
4
  import { validate, validator } from "@aeriajs/validation";
5
- import { Result } from "@aeriajs/common";
6
5
  import * as path from "path";
7
6
  import { createWriteStream } from "fs";
8
7
  import { createHash } from "crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.109",
3
+ "version": "0.0.110",
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.109",
45
- "@aeriajs/common": "^0.0.68",
46
- "@aeriajs/entrypoint": "^0.0.70",
47
- "@aeriajs/http": "^0.0.79",
48
- "@aeriajs/security": "^0.0.109",
49
- "@aeriajs/types": "^0.0.60",
50
- "@aeriajs/validation": "^0.0.71"
44
+ "@aeriajs/builtins": "^0.0.110",
45
+ "@aeriajs/common": "^0.0.69",
46
+ "@aeriajs/entrypoint": "^0.0.71",
47
+ "@aeriajs/http": "^0.0.80",
48
+ "@aeriajs/security": "^0.0.110",
49
+ "@aeriajs/types": "^0.0.61",
50
+ "@aeriajs/validation": "^0.0.72"
51
51
  },
52
52
  "dependencies": {
53
53
  "mongodb": "^6.5.0",