@flink-app/flink 0.12.1-alpha.5 → 0.12.1-alpha.7

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.
@@ -46,6 +46,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
49
60
  Object.defineProperty(exports, "__esModule", { value: true });
50
61
  exports.FlinkRepo = void 0;
51
62
  var mongodb_1 = require("mongodb");
@@ -129,12 +140,13 @@ var FlinkRepo = /** @class */ (function () {
129
140
  };
130
141
  FlinkRepo.prototype.updateOne = function (id, model) {
131
142
  return __awaiter(this, void 0, void 0, function () {
132
- var oid, res;
143
+ var oid, _id, modelWithoutId, res;
133
144
  return __generator(this, function (_a) {
134
145
  switch (_a.label) {
135
146
  case 0:
136
147
  oid = this.buildId(id);
137
- return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: model })];
148
+ _id = model._id, modelWithoutId = __rest(model, ["_id"]);
149
+ return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: modelWithoutId })];
138
150
  case 1:
139
151
  _a.sent();
140
152
  return [4 /*yield*/, this.collection.findOne({ _id: oid })];
@@ -150,14 +162,16 @@ var FlinkRepo = /** @class */ (function () {
150
162
  };
151
163
  FlinkRepo.prototype.updateMany = function (query, model) {
152
164
  return __awaiter(this, void 0, void 0, function () {
153
- var modifiedCount;
154
- return __generator(this, function (_a) {
155
- switch (_a.label) {
156
- case 0: return [4 /*yield*/, this.collection.updateMany(query, {
157
- $set: model,
158
- })];
165
+ var _a, _id, modelWithoutId, modifiedCount;
166
+ return __generator(this, function (_b) {
167
+ switch (_b.label) {
168
+ case 0:
169
+ _a = model, _id = _a._id, modelWithoutId = __rest(_a, ["_id"]);
170
+ return [4 /*yield*/, this.collection.updateMany(query, {
171
+ $set: modelWithoutId,
172
+ })];
159
173
  case 1:
160
- modifiedCount = (_a.sent()).modifiedCount;
174
+ modifiedCount = (_b.sent()).modifiedCount;
161
175
  return [2 /*return*/, modifiedCount];
162
176
  }
163
177
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "0.12.1-alpha.5",
3
+ "version": "0.12.1-alpha.7",
4
4
  "description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "main": "dist/src/index.js",
@@ -66,5 +66,5 @@
66
66
  "rimraf": "^3.0.2",
67
67
  "ts-node": "^9.1.1"
68
68
  },
69
- "gitHead": "1ff7b8cf9b30287d3be72af96c5767e90a562fbf"
69
+ "gitHead": "cd86dec5f9b3bf23c01374a729bb02d8a48c2869"
70
70
  }
package/src/FlinkRepo.ts CHANGED
@@ -54,7 +54,9 @@ export abstract class FlinkRepo<C extends FlinkContext, Model extends Document>
54
54
  async updateOne(id: string | ObjectId, model: PartialModel<Model>): Promise<Model | null> {
55
55
  const oid = this.buildId(id);
56
56
 
57
- await this.collection.updateOne({ _id: oid }, { $set: model });
57
+ const { _id, ...modelWithoutId } = model;
58
+
59
+ await this.collection.updateOne({ _id: oid }, { $set: modelWithoutId });
58
60
 
59
61
  const res = await this.collection.findOne<Model>({ _id: oid });
60
62
 
@@ -65,8 +67,10 @@ export abstract class FlinkRepo<C extends FlinkContext, Model extends Document>
65
67
  }
66
68
 
67
69
  async updateMany<U = PartialModel<Model>>(query: any, model: U): Promise<number> {
70
+ const { _id, ...modelWithoutId } = model as any;
71
+
68
72
  const { modifiedCount } = await this.collection.updateMany(query, {
69
- $set: model as any,
73
+ $set: modelWithoutId as any,
70
74
  });
71
75
  return modifiedCount;
72
76
  }