@aeriajs/core 0.0.168 → 0.0.170

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makePagination = void 0;
4
+ const count_js_1 = require("../functions/count.js");
4
5
  const common_1 = require("@aeriajs/common");
5
6
  const makePagination = async (payload, documents, context) => {
6
7
  const { offset = 0, limit = context.config.defaultPaginationLimit, } = payload;
@@ -8,7 +9,9 @@ const makePagination = async (payload, documents, context) => {
8
9
  ? (0, common_1.throwIfError)(await context.collection.functions.count({
9
10
  filters: payload.filters,
10
11
  }))
11
- : await context.collection.model.countDocuments(payload.filters);
12
+ : (0, common_1.throwIfError)(await (0, count_js_1.count)({
13
+ filters: payload.filters,
14
+ }, context));
12
15
  return {
13
16
  recordsCount: documents.length,
14
17
  recordsTotal,
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ import { count } from "../functions/count.mjs";
2
3
  import { throwIfError } from "@aeriajs/common";
3
4
  export const makePagination = async (payload, documents, context) => {
4
5
  const {
@@ -7,7 +8,9 @@ export const makePagination = async (payload, documents, context) => {
7
8
  } = payload;
8
9
  const recordsTotal = typeof context.collection.functions.count === "function" ? throwIfError(await context.collection.functions.count({
9
10
  filters: payload.filters
10
- })) : await context.collection.model.countDocuments(payload.filters);
11
+ })) : throwIfError(await count({
12
+ filters: payload.filters
13
+ }, context));
11
14
  return {
12
15
  recordsCount: documents.length,
13
16
  recordsTotal,
@@ -221,6 +221,7 @@ const moveFiles = async (value, ctx) => {
221
221
  }
222
222
  const { _id: fileId, ...newFile } = tempFile;
223
223
  newFile.absolute_path = `${ctx.options.context.config.storage.fs}/${tempFile.absolute_path.split(path.sep).at(-1)}`;
224
+ newFile.owner = ctx.options.context.token.sub;
224
225
  await fs.rename(tempFile.absolute_path, newFile.absolute_path);
225
226
  const file = await ctx.options.context.collections.file.model.insertOne(newFile);
226
227
  return file.insertedId;
@@ -186,6 +186,7 @@ const moveFiles = async (value, ctx) => {
186
186
  }
187
187
  const { _id: fileId, ...newFile } = tempFile;
188
188
  newFile.absolute_path = `${ctx.options.context.config.storage.fs}/${tempFile.absolute_path.split(path.sep).at(-1)}`;
189
+ newFile.owner = ctx.options.context.token.sub;
189
190
  await fs.rename(tempFile.absolute_path, newFile.absolute_path);
190
191
  const file = await ctx.options.context.collections.file.model.insertOne(newFile);
191
192
  return file.insertedId;
package/dist/context.js CHANGED
@@ -61,11 +61,17 @@ const indepthCollection = (collectionName, collections, parentContext) => {
61
61
  };
62
62
  };
63
63
  const createContext = async (options = {}) => {
64
- const { collectionName, parentContext = {}, token = {}, } = options;
64
+ const { collectionName, parentContext, token = {
65
+ authenticated: false,
66
+ sub: null,
67
+ }, } = options;
65
68
  const { getCollectionAsset } = await Promise.resolve().then(() => __importStar(require('./assets.js')));
66
69
  const collections = await (0, entrypoint_1.getCollections)();
67
70
  const context = Object.assign({}, parentContext);
68
- Object.assign(context, options);
71
+ Object.assign(context, {
72
+ ...options,
73
+ token,
74
+ });
69
75
  context.log = async (message, details) => {
70
76
  return (0, database_js_1.getDatabaseCollection)('log').insertOne({
71
77
  message,
package/dist/context.mjs CHANGED
@@ -36,13 +36,19 @@ const indepthCollection = (collectionName, collections, parentContext) => {
36
36
  export const createContext = async (options = {}) => {
37
37
  const {
38
38
  collectionName,
39
- parentContext = {},
40
- token = {}
39
+ parentContext,
40
+ token = {
41
+ authenticated: false,
42
+ sub: null
43
+ }
41
44
  } = options;
42
45
  const { getCollectionAsset } = await import("./assets.mjs");
43
46
  const collections = await getCollections();
44
47
  const context = Object.assign({}, parentContext);
45
- Object.assign(context, options);
48
+ Object.assign(context, {
49
+ ...options,
50
+ token
51
+ });
46
52
  context.log = async (message, details) => {
47
53
  return getDatabaseCollection("log").insertOne({
48
54
  message,
@@ -3,4 +3,8 @@ import { Result } from '@aeriajs/types';
3
3
  export type CountOptions = {
4
4
  bypassSecurity?: boolean;
5
5
  };
6
- export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context ? TContext : never, options?: CountOptions) => Promise<Result.Either<any, any>>;
6
+ export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context ? TContext : never, options?: CountOptions) => Promise<Result.Error<any> | {
7
+ readonly _tag: "Result";
8
+ readonly error: undefined;
9
+ readonly result: any;
10
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.168",
3
+ "version": "0.0.170",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "aeriaMain": "tests/fixtures/aeriaMain.js",
@@ -42,13 +42,13 @@
42
42
  "mongodb-memory-server": "^9.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@aeriajs/builtins": "^0.0.168",
46
- "@aeriajs/common": "^0.0.103",
47
- "@aeriajs/entrypoint": "^0.0.105",
48
- "@aeriajs/http": "^0.0.116",
49
- "@aeriajs/security": "^0.0.168",
45
+ "@aeriajs/builtins": "^0.0.170",
46
+ "@aeriajs/common": "^0.0.104",
47
+ "@aeriajs/entrypoint": "^0.0.106",
48
+ "@aeriajs/http": "^0.0.117",
49
+ "@aeriajs/security": "^0.0.170",
50
50
  "@aeriajs/types": "^0.0.87",
51
- "@aeriajs/validation": "^0.0.106"
51
+ "@aeriajs/validation": "^0.0.107"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",