remult 0.23.0-exp.1 → 0.23.0-exp.2

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.
@@ -86,6 +86,7 @@ class KnexEntityDataProvider {
86
86
  return +element;
87
87
  }
88
88
  }
89
+ throw Error("couldn't find count member");
89
90
  }
90
91
  async find(options) {
91
92
  const e = await this.init();
@@ -4,7 +4,7 @@ import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation
4
4
  export declare class MongoDataProvider implements DataProvider {
5
5
  private db;
6
6
  private client;
7
- constructor(db: Db, client: MongoClient, options?: {
7
+ constructor(db: Db, client: MongoClient | undefined, options?: {
8
8
  session?: ClientSession;
9
9
  disableTransactions?: boolean;
10
10
  });
@@ -10,7 +10,7 @@ export class MongoDataProvider {
10
10
  this.db = db;
11
11
  this.client = client;
12
12
  this.session = options?.session;
13
- this.disableTransactions = options?.disableTransactions;
13
+ this.disableTransactions = Boolean(options?.disableTransactions);
14
14
  }
15
15
  session;
16
16
  disableTransactions = false;
@@ -28,6 +28,8 @@ export class MongoDataProvider {
28
28
  await action(this);
29
29
  }
30
30
  else {
31
+ if (!this.client)
32
+ throw new Error("Can't use transactions within transactions");
31
33
  let session = await this.client.startSession();
32
34
  session.startTransaction();
33
35
  const db = this.client.db(this.db.databaseName);
@@ -198,7 +200,7 @@ class FilterConsumerBridgeToMongo {
198
200
  f._addWhere = false;
199
201
  element.__applyToConsumer(f);
200
202
  let where = await f.resolveWhere();
201
- if (where?.$and?.length > 0) {
203
+ if (where?.$and?.length) {
202
204
  result.push(where);
203
205
  }
204
206
  else
@@ -414,7 +414,7 @@ export type RelationOptionsBase<fromEntity, toEntity, optionsType extends LoadOp
414
414
  } & FieldOptions<fromEntity, toEntity>;
415
415
  export type ObjectMembersOnly<T> = {
416
416
  [K in keyof Pick<T, {
417
- [K in keyof T]: T[K] extends object ? T[K] extends Date ? never : K : never;
417
+ [K in keyof T]: T[K] extends object | undefined | null ? T[K] extends Date | undefined | null ? never : K : never;
418
418
  }[keyof T]>]: T[K];
419
419
  };
420
420
  export type MembersToInclude<T> = {
@@ -1,3 +1,3 @@
1
1
  import type { CompoundIdField } from './CompoundIdField';
2
2
  import { Filter } from './filter/filter-interfaces';
3
- export declare function resultCompoundIdFilter(idField: CompoundIdField, id: string, data: any): Filter;
3
+ export declare function resultCompoundIdFilter(idField: CompoundIdField, id: string | undefined, data: any): Filter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.23.0-exp.1",
3
+ "version": "0.23.0-exp.2",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
@@ -151,7 +151,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
151
151
  return [2 /*return*/, +element];
152
152
  }
153
153
  }
154
- return [2 /*return*/];
154
+ throw Error("couldn't find count member");
155
155
  }
156
156
  });
157
157
  });
package/remult-mongo.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { RepositoryOverloads } from './src/remult3/RepositoryImplementation
4
4
  export declare class MongoDataProvider implements DataProvider {
5
5
  private db;
6
6
  private client;
7
- constructor(db: Db, client: MongoClient, options?: {
7
+ constructor(db: Db, client: MongoClient | undefined, options?: {
8
8
  session?: ClientSession;
9
9
  disableTransactions?: boolean;
10
10
  });
package/remult-mongo.js CHANGED
@@ -13,7 +13,7 @@ var MongoDataProvider = /** @class */ (function () {
13
13
  this.client = client;
14
14
  this.disableTransactions = false;
15
15
  this.session = options === null || options === void 0 ? void 0 : options.session;
16
- this.disableTransactions = options === null || options === void 0 ? void 0 : options.disableTransactions;
16
+ this.disableTransactions = Boolean(options === null || options === void 0 ? void 0 : options.disableTransactions);
17
17
  }
18
18
  MongoDataProvider.getDb = function (remult) {
19
19
  var r = (remult || remult_proxy_1.remult).dataProvider;
@@ -35,7 +35,10 @@ var MongoDataProvider = /** @class */ (function () {
35
35
  case 1:
36
36
  _a.sent();
37
37
  return [3 /*break*/, 11];
38
- case 2: return [4 /*yield*/, this.client.startSession()];
38
+ case 2:
39
+ if (!this.client)
40
+ throw new Error("Can't use transactions within transactions");
41
+ return [4 /*yield*/, this.client.startSession()];
39
42
  case 3:
40
43
  session = _a.sent();
41
44
  session.startTransaction();
@@ -417,7 +420,7 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
417
420
  return [4 /*yield*/, f.resolveWhere()];
418
421
  case 3:
419
422
  where = _c.sent();
420
- if (((_b = where === null || where === void 0 ? void 0 : where.$and) === null || _b === void 0 ? void 0 : _b.length) > 0) {
423
+ if ((_b = where === null || where === void 0 ? void 0 : where.$and) === null || _b === void 0 ? void 0 : _b.length) {
421
424
  result.push(where);
422
425
  }
423
426
  else
@@ -414,7 +414,7 @@ export type RelationOptionsBase<fromEntity, toEntity, optionsType extends LoadOp
414
414
  } & FieldOptions<fromEntity, toEntity>;
415
415
  export type ObjectMembersOnly<T> = {
416
416
  [K in keyof Pick<T, {
417
- [K in keyof T]: T[K] extends object ? T[K] extends Date ? never : K : never;
417
+ [K in keyof T]: T[K] extends object | undefined | null ? T[K] extends Date | undefined | null ? never : K : never;
418
418
  }[keyof T]>]: T[K];
419
419
  };
420
420
  export type MembersToInclude<T> = {
@@ -1,3 +1,3 @@
1
1
  import type { CompoundIdField } from './CompoundIdField';
2
2
  import { Filter } from './filter/filter-interfaces';
3
- export declare function resultCompoundIdFilter(idField: CompoundIdField, id: string, data: any): Filter;
3
+ export declare function resultCompoundIdFilter(idField: CompoundIdField, id: string | undefined, data: any): Filter;