@aeriajs/core 0.0.222 → 0.0.224

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/context.js CHANGED
@@ -90,7 +90,9 @@ const createContext = async (_options) => {
90
90
  }
91
91
  else {
92
92
  config = {
93
- security: {},
93
+ security: {
94
+ mutableUserProperties: [],
95
+ },
94
96
  };
95
97
  }
96
98
  let request, response, inherited = !!options.inherited;
package/dist/context.mjs CHANGED
@@ -55,7 +55,9 @@ export const createContext = async (_options) => {
55
55
  config = parentContext.config;
56
56
  } else {
57
57
  config = {
58
- security: {}
58
+ security: {
59
+ mutableUserProperties: []
60
+ }
59
61
  };
60
62
  }
61
63
  let request, response, inherited = !!options.inherited;
@@ -45,24 +45,37 @@ const internalInsert = async (payload, context) => {
45
45
  ? what._id
46
46
  : null;
47
47
  let newId = docId;
48
- if (!newId) {
49
- const content = prepareCreate(what, context.description);
50
- const now = new Date();
51
- Object.assign(content, {
52
- created_at: now,
53
- updated_at: now,
54
- });
55
- newId = (await context.collection.model.insertOne(content)).insertedId;
48
+ try {
49
+ if (!newId) {
50
+ const content = prepareCreate(what, context.description);
51
+ const now = new Date();
52
+ Object.assign(content, {
53
+ created_at: now,
54
+ updated_at: now,
55
+ });
56
+ newId = (await context.collection.model.insertOne(content)).insertedId;
57
+ }
58
+ else {
59
+ await context.collection.model.updateOne({
60
+ _id: newId,
61
+ }, {
62
+ $set: {
63
+ ...what,
64
+ updated_at: new Date(),
65
+ },
66
+ });
67
+ }
56
68
  }
57
- else {
58
- await context.collection.model.updateOne({
59
- _id: newId,
60
- }, {
61
- $set: {
62
- ...what,
63
- updated_at: new Date(),
64
- },
65
- });
69
+ catch (err) {
70
+ if (err instanceof mongodb_1.MongoServerError) {
71
+ switch (err.code) {
72
+ case 11000: return context.error(types_1.HTTPStatus.InternalServerError, {
73
+ code: types_1.ACError.UniquenessViolated,
74
+ });
75
+ default: throw err;
76
+ }
77
+ }
78
+ throw err;
66
79
  }
67
80
  const inheritedContext = {
68
81
  ...context,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- import { ObjectId } from "mongodb";
3
- import { Result, HTTPStatus } from "@aeriajs/types";
2
+ import { ObjectId, MongoServerError } from "mongodb";
3
+ import { Result, HTTPStatus, ACError } from "@aeriajs/types";
4
4
  import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
5
5
  import { traverseDocument } from "../collection/index.mjs";
6
6
  import { get } from "./get.mjs";
@@ -39,23 +39,37 @@ const internalInsert = async (payload, context) => {
39
39
  }
40
40
  const docId = "_id" in what && what._id instanceof ObjectId ? what._id : null;
41
41
  let newId = docId;
42
- if (!newId) {
43
- const content = prepareCreate(what, context.description);
44
- const now = /* @__PURE__ */ new Date();
45
- Object.assign(content, {
46
- created_at: now,
47
- updated_at: now
48
- });
49
- newId = (await context.collection.model.insertOne(content)).insertedId;
50
- } else {
51
- await context.collection.model.updateOne({
52
- _id: newId
53
- }, {
54
- $set: {
55
- ...what,
56
- updated_at: /* @__PURE__ */ new Date()
42
+ try {
43
+ if (!newId) {
44
+ const content = prepareCreate(what, context.description);
45
+ const now = /* @__PURE__ */ new Date();
46
+ Object.assign(content, {
47
+ created_at: now,
48
+ updated_at: now
49
+ });
50
+ newId = (await context.collection.model.insertOne(content)).insertedId;
51
+ } else {
52
+ await context.collection.model.updateOne({
53
+ _id: newId
54
+ }, {
55
+ $set: {
56
+ ...what,
57
+ updated_at: /* @__PURE__ */ new Date()
58
+ }
59
+ });
60
+ }
61
+ } catch (err) {
62
+ if (err instanceof MongoServerError) {
63
+ switch (err.code) {
64
+ case 11e3:
65
+ return context.error(HTTPStatus.InternalServerError, {
66
+ code: ACError.UniquenessViolated
67
+ });
68
+ default:
69
+ throw err;
57
70
  }
58
- });
71
+ }
72
+ throw err;
59
73
  }
60
74
  const inheritedContext = {
61
75
  ...context,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.222",
3
+ "version": "0.0.224",
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.222",
46
- "@aeriajs/common": "^0.0.128",
47
- "@aeriajs/entrypoint": "^0.0.131",
48
- "@aeriajs/http": "^0.0.155",
49
- "@aeriajs/security": "^0.0.222",
50
- "@aeriajs/types": "^0.0.110",
51
- "@aeriajs/validation": "^0.0.143"
45
+ "@aeriajs/builtins": "^0.0.224",
46
+ "@aeriajs/common": "^0.0.129",
47
+ "@aeriajs/entrypoint": "^0.0.132",
48
+ "@aeriajs/http": "^0.0.156",
49
+ "@aeriajs/security": "^0.0.224",
50
+ "@aeriajs/types": "^0.0.111",
51
+ "@aeriajs/validation": "^0.0.144"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",