remult 0.13.8 → 0.13.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.13.8",
3
+ "version": "0.13.11",
4
4
  "description": "remult core lib",
5
5
  "homepage": "https://remult.dev/",
6
6
  "repository": {
@@ -247,6 +247,8 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
247
247
  fieldTypeInDb?: string;
248
248
  inputType?: string;
249
249
  }
250
+ export declare function getValueList<T>(field: FieldRef<T>): T[];
251
+ export declare function getValueList<T>(field: FieldMetadata<T>): T[];
250
252
  export declare function getValueList<T>(type: ClassType<T>): T[];
251
253
  export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType>, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
252
254
  export declare const storableMember: unique symbol;
@@ -473,7 +473,7 @@ var RepositoryImplementation = /** @class */ (function () {
473
473
  }
474
474
  _a.label = 2;
475
475
  case 2:
476
- r = this.find(options).then(function (items) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
476
+ r = this.find(tslib_1.__assign(tslib_1.__assign({}, options), { limit: 1 })).then(function (items) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
477
477
  var r;
478
478
  return tslib_1.__generator(this, function (_a) {
479
479
  switch (_a.label) {
@@ -2279,6 +2279,7 @@ exports.ValueListFieldType = ValueListFieldType;
2279
2279
  var ValueListInfo = /** @class */ (function () {
2280
2280
  function ValueListInfo(valueListType) {
2281
2281
  var e_30, _a, _b;
2282
+ var _this = this;
2282
2283
  this.valueListType = valueListType;
2283
2284
  this.byIdMap = new Map();
2284
2285
  this.values = [];
@@ -2306,9 +2307,11 @@ var ValueListInfo = /** @class */ (function () {
2306
2307
  var op = options_1_1.value;
2307
2308
  if (op === null || op === void 0 ? void 0 : op.getValues) {
2308
2309
  (_b = this.values).splice.apply(_b, tslib_1.__spread([0, this.values.length], op.getValues()));
2310
+ this.byIdMap.clear();
2309
2311
  this.values.forEach(function (s) {
2310
2312
  if (s.caption === undefined && s.id !== undefined)
2311
2313
  s.caption = column_1.makeTitle(s.id);
2314
+ _this.byIdMap.set(s.id, s);
2312
2315
  });
2313
2316
  }
2314
2317
  }
@@ -2372,6 +2375,17 @@ var ValueListInfo = /** @class */ (function () {
2372
2375
  exports.ValueListInfo = ValueListInfo;
2373
2376
  var typeCache = new Map();
2374
2377
  function getValueList(type) {
2378
+ var _a, _b, _c;
2379
+ {
2380
+ var fr = (_b = (_a = type) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.valueType;
2381
+ if (fr)
2382
+ return ValueListInfo.get(fr).getValues();
2383
+ }
2384
+ {
2385
+ var fr = (_c = type) === null || _c === void 0 ? void 0 : _c.valueType;
2386
+ if (fr)
2387
+ return ValueListInfo.get(fr).getValues();
2388
+ }
2375
2389
  return ValueListInfo.get(type).getValues();
2376
2390
  }
2377
2391
  exports.getValueList = getValueList;
@@ -14,3 +14,13 @@ export declare enum Priority {
14
14
  High = 1,
15
15
  Critical = 2
16
16
  }
17
+ export declare class tasksWithStringEnum extends IdEntity {
18
+ title: string;
19
+ completed: boolean;
20
+ priority: PriorityWithString;
21
+ }
22
+ export declare enum PriorityWithString {
23
+ Low = "Low",
24
+ High = "High",
25
+ Critical = "Critical"
26
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Priority = exports.tasksWithEnum = exports.stam = void 0;
3
+ exports.PriorityWithString = exports.tasksWithStringEnum = exports.Priority = exports.tasksWithEnum = exports.stam = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var data_api_1 = require("../data-api");
6
6
  var remult3_1 = require("../remult3");
@@ -1432,22 +1432,97 @@ var Priority;
1432
1432
  db_tests_setup_1.testAll("task with enum", function (_a) {
1433
1433
  var createEntity = _a.createEntity;
1434
1434
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1435
- var r, item;
1436
- return tslib_1.__generator(this, function (_b) {
1437
- switch (_b.label) {
1435
+ var r, item, _b, _c;
1436
+ return tslib_1.__generator(this, function (_d) {
1437
+ switch (_d.label) {
1438
1438
  case 0: return [4 /*yield*/, createEntity(tasksWithEnum)];
1439
1439
  case 1:
1440
- r = _b.sent();
1440
+ r = _d.sent();
1441
1441
  return [4 /*yield*/, r.insert({
1442
1442
  title: 'a',
1443
1443
  priority: Priority.Critical
1444
1444
  })];
1445
1445
  case 2:
1446
- _b.sent();
1446
+ _d.sent();
1447
1447
  return [4 /*yield*/, r.findFirst()];
1448
1448
  case 3:
1449
- item = _b.sent();
1449
+ item = _d.sent();
1450
1450
  expect(item.priority).toBe(Priority.Critical);
1451
+ _b = expect;
1452
+ return [4 /*yield*/, r.count({ priority: Priority.Critical })];
1453
+ case 4:
1454
+ _b.apply(void 0, [_d.sent()]).toBe(1);
1455
+ _c = expect;
1456
+ return [4 /*yield*/, r.count({ priority: Priority.Low })];
1457
+ case 5:
1458
+ _c.apply(void 0, [_d.sent()]).toBe(0);
1459
+ return [2 /*return*/];
1460
+ }
1461
+ });
1462
+ });
1463
+ });
1464
+ var tasksWithStringEnum = /** @class */ (function (_super) {
1465
+ tslib_1.__extends(tasksWithStringEnum, _super);
1466
+ function tasksWithStringEnum() {
1467
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1468
+ _this.title = '';
1469
+ _this.completed = false;
1470
+ _this.priority = PriorityWithString.Low;
1471
+ return _this;
1472
+ }
1473
+ tslib_1.__decorate([
1474
+ remult3_1.Fields.string(),
1475
+ tslib_1.__metadata("design:type", Object)
1476
+ ], tasksWithStringEnum.prototype, "title", void 0);
1477
+ tslib_1.__decorate([
1478
+ remult3_1.Fields.boolean(),
1479
+ tslib_1.__metadata("design:type", Object)
1480
+ ], tasksWithStringEnum.prototype, "completed", void 0);
1481
+ tslib_1.__decorate([
1482
+ remult3_1.Fields.object(),
1483
+ tslib_1.__metadata("design:type", Object)
1484
+ ], tasksWithStringEnum.prototype, "priority", void 0);
1485
+ tasksWithStringEnum = tslib_1.__decorate([
1486
+ remult3_1.Entity('tasksWithStringEnum', {
1487
+ allowApiCrud: true
1488
+ })
1489
+ ], tasksWithStringEnum);
1490
+ return tasksWithStringEnum;
1491
+ }(id_entity_1.IdEntity));
1492
+ exports.tasksWithStringEnum = tasksWithStringEnum;
1493
+ var PriorityWithString;
1494
+ (function (PriorityWithString) {
1495
+ PriorityWithString["Low"] = "Low";
1496
+ PriorityWithString["High"] = "High";
1497
+ PriorityWithString["Critical"] = "Critical";
1498
+ })(PriorityWithString = exports.PriorityWithString || (exports.PriorityWithString = {}));
1499
+ db_tests_setup_1.testAll("task with enum string", function (_a) {
1500
+ var createEntity = _a.createEntity;
1501
+ return tslib_1.__awaiter(void 0, void 0, void 0, function () {
1502
+ var r, item, _b, _c;
1503
+ return tslib_1.__generator(this, function (_d) {
1504
+ switch (_d.label) {
1505
+ case 0: return [4 /*yield*/, createEntity(tasksWithStringEnum)];
1506
+ case 1:
1507
+ r = _d.sent();
1508
+ return [4 /*yield*/, r.insert({
1509
+ title: 'a',
1510
+ priority: PriorityWithString.Critical
1511
+ })];
1512
+ case 2:
1513
+ _d.sent();
1514
+ return [4 /*yield*/, r.findFirst()];
1515
+ case 3:
1516
+ item = _d.sent();
1517
+ expect(item.priority).toBe(PriorityWithString.Critical);
1518
+ _b = expect;
1519
+ return [4 /*yield*/, r.count({ priority: PriorityWithString.Critical })];
1520
+ case 4:
1521
+ _b.apply(void 0, [_d.sent()]).toBe(1);
1522
+ _c = expect;
1523
+ return [4 /*yield*/, r.count({ priority: PriorityWithString.Low })];
1524
+ case 5:
1525
+ _c.apply(void 0, [_d.sent()]).toBe(0);
1451
1526
  return [2 /*return*/];
1452
1527
  }
1453
1528
  });