remult 0.22.10 → 0.22.11

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,4 +1,4 @@
1
- import type { ClientSession, Db, MongoClient } from 'mongodb';
1
+ import { type ClientSession, type Db, type MongoClient } from 'mongodb';
2
2
  import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from '.';
3
3
  import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation';
4
4
  export declare class MongoDataProvider implements DataProvider {
@@ -1,3 +1,4 @@
1
+ import { ObjectId, } from 'mongodb';
1
2
  import { CompoundIdField, Filter } from '.';
2
3
  import { dbNamesOf } from './src/filter/filter-consumer-bridge-to-sql-request';
3
4
  import { remult as remultContext } from './src/remult-proxy';
@@ -72,14 +73,14 @@ class MongoEntityDataProvider {
72
73
  let val = row[nameProvider.$dbNameOf(col)];
73
74
  if (isNull(val))
74
75
  val = null;
75
- result[col.key] = col.valueConverter.fromDb(val);
76
+ result[col.key] = fromDb(col, val);
76
77
  }
77
78
  return result;
78
79
  }
79
80
  translateToDb(row, nameProvider) {
80
81
  let result = {};
81
82
  for (const col of this.entity.fields) {
82
- let val = col.valueConverter.toDb(row[col.key]);
83
+ let val = toDb(col, row[col.key]);
83
84
  if (val === null)
84
85
  val = NULL;
85
86
  result[nameProvider.$dbNameOf(col)] = val;
@@ -218,7 +219,7 @@ class FilterConsumerBridgeToMongo {
218
219
  isIn(col, val) {
219
220
  this.result.push(() => ({
220
221
  [this.nameProvider.$dbNameOf(col)]: {
221
- $in: val.map((x) => col.valueConverter.toDb(x)),
222
+ $in: val.map((x) => toDb(col, x)),
222
223
  },
223
224
  }));
224
225
  }
@@ -250,7 +251,7 @@ class FilterConsumerBridgeToMongo {
250
251
  add(col, val, operator) {
251
252
  this.result.push(() => ({
252
253
  [this.nameProvider.$dbNameOf(col)]: {
253
- [operator]: isNull(val) ? val : col.valueConverter.toDb(val),
254
+ [operator]: isNull(val) ? val : toDb(col, val),
254
255
  },
255
256
  }));
256
257
  }
@@ -267,3 +268,13 @@ class FilterConsumerBridgeToMongo {
267
268
  // })());
268
269
  }
269
270
  }
271
+ function toDb(col, val) {
272
+ if (col.valueConverter.fieldTypeInDb == 'dbid')
273
+ return val ? new ObjectId(val) : val === null ? null : undefined;
274
+ return col.valueConverter.toDb(val);
275
+ }
276
+ function fromDb(col, val) {
277
+ if (col.valueConverter.fieldTypeInDb == 'dbid')
278
+ return val ? val.toHexString() : val === null ? null : undefined;
279
+ return col.valueConverter.fromDb(val);
280
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.22.10",
3
+ "version": "0.22.11",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
package/remult-mongo.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ClientSession, Db, MongoClient } from 'mongodb';
1
+ import { type ClientSession, type Db, type MongoClient } from 'mongodb';
2
2
  import type { DataProvider, EntityDataProvider, EntityFilter, EntityMetadata, Remult } from '.';
3
3
  import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation';
4
4
  export declare class MongoDataProvider implements DataProvider {
package/remult-mongo.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MongoDataProvider = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var mongodb_1 = require("mongodb");
5
6
  var _1 = require(".");
6
7
  var filter_consumer_bridge_to_sql_request_1 = require("./src/filter/filter-consumer-bridge-to-sql-request");
7
8
  var remult_proxy_1 = require("./src/remult-proxy");
@@ -111,7 +112,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
111
112
  var val = row[nameProvider.$dbNameOf(col)];
112
113
  if (isNull(val))
113
114
  val = null;
114
- result[col.key] = col.valueConverter.fromDb(val);
115
+ result[col.key] = fromDb(col, val);
115
116
  }
116
117
  }
117
118
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -129,7 +130,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
129
130
  try {
130
131
  for (var _b = tslib_1.__values(this.entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
131
132
  var col = _c.value;
132
- var val = col.valueConverter.toDb(row[col.key]);
133
+ var val = toDb(col, row[col.key]);
133
134
  if (val === null)
134
135
  val = NULL;
135
136
  result[nameProvider.$dbNameOf(col)] = val;
@@ -458,7 +459,7 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
458
459
  var _a;
459
460
  return (_a = {},
460
461
  _a[_this.nameProvider.$dbNameOf(col)] = {
461
- $in: val.map(function (x) { return col.valueConverter.toDb(x); }),
462
+ $in: val.map(function (x) { return toDb(col, x); }),
462
463
  },
463
464
  _a);
464
465
  });
@@ -494,7 +495,7 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
494
495
  var _a, _b;
495
496
  return (_a = {},
496
497
  _a[_this.nameProvider.$dbNameOf(col)] = (_b = {},
497
- _b[operator] = isNull(val) ? val : col.valueConverter.toDb(val),
498
+ _b[operator] = isNull(val) ? val : toDb(col, val),
498
499
  _b),
499
500
  _a);
500
501
  });
@@ -513,3 +514,13 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
513
514
  };
514
515
  return FilterConsumerBridgeToMongo;
515
516
  }());
517
+ function toDb(col, val) {
518
+ if (col.valueConverter.fieldTypeInDb == 'dbid')
519
+ return val ? new mongodb_1.ObjectId(val) : val === null ? null : undefined;
520
+ return col.valueConverter.toDb(val);
521
+ }
522
+ function fromDb(col, val) {
523
+ if (col.valueConverter.fieldTypeInDb == 'dbid')
524
+ return val ? val.toHexString() : val === null ? null : undefined;
525
+ return col.valueConverter.fromDb(val);
526
+ }