remult 0.13.7 → 0.13.10

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.7",
3
+ "version": "0.13.10",
4
4
  "description": "remult core lib",
5
5
  "homepage": "https://remult.dev/",
6
6
  "repository": {
@@ -235,8 +235,6 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
235
235
  private values;
236
236
  isNumeric: boolean;
237
237
  private constructor();
238
- private loadedFromOptions;
239
- loadFromDecoratorOptions(): void;
240
238
  getValues(): T[];
241
239
  byId(key: any): T;
242
240
  fromJson(val: any): T;
@@ -2273,17 +2273,17 @@ function ValueListFieldType() {
2273
2273
  o.valueConverter = ValueListInfo.get(type),
2274
2274
  o.displayValue = function (item, val) { return val.caption; };
2275
2275
  }], options))(type);
2276
- ValueListInfo.get(type).loadFromDecoratorOptions();
2277
2276
  };
2278
2277
  }
2279
2278
  exports.ValueListFieldType = ValueListFieldType;
2280
2279
  var ValueListInfo = /** @class */ (function () {
2281
2280
  function ValueListInfo(valueListType) {
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 = [];
2285
2286
  this.isNumeric = false;
2286
- this.loadedFromOptions = false;
2287
2287
  for (var member in this.valueListType) {
2288
2288
  var s = this.valueListType[member];
2289
2289
  if (s instanceof this.valueListType) {
@@ -2300,30 +2300,18 @@ var ValueListInfo = /** @class */ (function () {
2300
2300
  if (this.isNumeric) {
2301
2301
  this.fieldTypeInDb = 'integer';
2302
2302
  }
2303
- }
2304
- ValueListInfo.get = function (type) {
2305
- var r = typeCache.get(type);
2306
- if (!r) {
2307
- r = new ValueListInfo(type);
2308
- typeCache.set(type, r);
2309
- }
2310
- return r;
2311
- };
2312
- ValueListInfo.prototype.loadFromDecoratorOptions = function () {
2313
- var e_30, _a, _b;
2314
- if (this.loadedFromOptions)
2315
- return;
2316
2303
  var options = Reflect.getMetadata(exports.storableMember, this.valueListType);
2317
2304
  if (options) {
2318
- this.loadedFromOptions = true;
2319
2305
  try {
2320
2306
  for (var options_1 = tslib_1.__values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
2321
2307
  var op = options_1_1.value;
2322
2308
  if (op === null || op === void 0 ? void 0 : op.getValues) {
2323
2309
  (_b = this.values).splice.apply(_b, tslib_1.__spread([0, this.values.length], op.getValues()));
2310
+ this.byIdMap.clear();
2324
2311
  this.values.forEach(function (s) {
2325
2312
  if (s.caption === undefined && s.id !== undefined)
2326
2313
  s.caption = column_1.makeTitle(s.id);
2314
+ _this.byIdMap.set(s.id, s);
2327
2315
  });
2328
2316
  }
2329
2317
  }
@@ -2336,15 +2324,23 @@ var ValueListInfo = /** @class */ (function () {
2336
2324
  finally { if (e_30) throw e_30.error; }
2337
2325
  }
2338
2326
  if (this.values.find(function (s) { return s.id === undefined; }))
2339
- throw new Error("Type " + this.valueListType + " has values without an id");
2327
+ throw new Error("ValueType " + this.valueListType + " has values without an id");
2328
+ }
2329
+ else
2330
+ throw new Error("ValueType not yet initialized, did you forget to call @ValueListFieldType on " + valueListType);
2331
+ }
2332
+ ValueListInfo.get = function (type) {
2333
+ var r = typeCache.get(type);
2334
+ if (!r) {
2335
+ r = new ValueListInfo(type);
2336
+ typeCache.set(type, r);
2340
2337
  }
2338
+ return r;
2341
2339
  };
2342
2340
  ValueListInfo.prototype.getValues = function () {
2343
- this.loadFromDecoratorOptions();
2344
2341
  return this.values;
2345
2342
  };
2346
2343
  ValueListInfo.prototype.byId = function (key) {
2347
- this.loadFromDecoratorOptions();
2348
2344
  if (this.isNumeric)
2349
2345
  key = +key;
2350
2346
  return this.byIdMap.get(key);
@@ -1,5 +1,16 @@
1
1
  import { EntityBase } from "../remult3";
2
+ import { IdEntity } from "../id-entity";
2
3
  export declare class stam extends EntityBase {
3
4
  id: number;
4
5
  title: string;
5
6
  }
7
+ export declare class tasksWithEnum extends IdEntity {
8
+ title: string;
9
+ completed: boolean;
10
+ priority: Priority;
11
+ }
12
+ export declare enum Priority {
13
+ Low = 0,
14
+ High = 1,
15
+ Critical = 2
16
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stam = void 0;
3
+ 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");
@@ -20,6 +20,7 @@ var entityForCustomFilter_1 = require("../tests/entityForCustomFilter");
20
20
  var entityWithValidationsOnColumn_1 = require("../tests/entityWithValidationsOnColumn");
21
21
  var validators_1 = require("../validators");
22
22
  var models_1 = require("../tests/testModel/models");
23
+ var id_entity_1 = require("../id-entity");
23
24
  db_tests_setup_1.testAll("what", function (_a) {
24
25
  var remult = _a.remult, createEntity = _a.createEntity;
25
26
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
@@ -1393,3 +1394,62 @@ var p = /** @class */ (function (_super) {
1393
1394
  ], p);
1394
1395
  return p;
1395
1396
  }(remult3_1.EntityBase));
1397
+ var tasksWithEnum = /** @class */ (function (_super) {
1398
+ tslib_1.__extends(tasksWithEnum, _super);
1399
+ function tasksWithEnum() {
1400
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1401
+ _this.title = '';
1402
+ _this.completed = false;
1403
+ _this.priority = Priority.Low;
1404
+ return _this;
1405
+ }
1406
+ tslib_1.__decorate([
1407
+ remult3_1.Fields.string(),
1408
+ tslib_1.__metadata("design:type", Object)
1409
+ ], tasksWithEnum.prototype, "title", void 0);
1410
+ tslib_1.__decorate([
1411
+ remult3_1.Fields.boolean(),
1412
+ tslib_1.__metadata("design:type", Object)
1413
+ ], tasksWithEnum.prototype, "completed", void 0);
1414
+ tslib_1.__decorate([
1415
+ remult3_1.Fields.object(),
1416
+ tslib_1.__metadata("design:type", Object)
1417
+ ], tasksWithEnum.prototype, "priority", void 0);
1418
+ tasksWithEnum = tslib_1.__decorate([
1419
+ remult3_1.Entity('tasksWithEnum', {
1420
+ allowApiCrud: true
1421
+ })
1422
+ ], tasksWithEnum);
1423
+ return tasksWithEnum;
1424
+ }(id_entity_1.IdEntity));
1425
+ exports.tasksWithEnum = tasksWithEnum;
1426
+ var Priority;
1427
+ (function (Priority) {
1428
+ Priority[Priority["Low"] = 0] = "Low";
1429
+ Priority[Priority["High"] = 1] = "High";
1430
+ Priority[Priority["Critical"] = 2] = "Critical";
1431
+ })(Priority = exports.Priority || (exports.Priority = {}));
1432
+ db_tests_setup_1.testAll("task with enum", function (_a) {
1433
+ var createEntity = _a.createEntity;
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) {
1438
+ case 0: return [4 /*yield*/, createEntity(tasksWithEnum)];
1439
+ case 1:
1440
+ r = _b.sent();
1441
+ return [4 /*yield*/, r.insert({
1442
+ title: 'a',
1443
+ priority: Priority.Critical
1444
+ })];
1445
+ case 2:
1446
+ _b.sent();
1447
+ return [4 /*yield*/, r.findFirst()];
1448
+ case 3:
1449
+ item = _b.sent();
1450
+ expect(item.priority).toBe(Priority.Critical);
1451
+ return [2 /*return*/];
1452
+ }
1453
+ });
1454
+ });
1455
+ });
@@ -28,9 +28,15 @@ var TestStatus = /** @class */ (function () {
28
28
  this.id = id;
29
29
  this.caption = caption;
30
30
  }
31
- TestStatus.open = new TestStatus();
32
- TestStatus.closed = new TestStatus('cc');
33
- TestStatus.hold = new TestStatus(undefined, 'hh');
31
+ TestStatus_1 = TestStatus;
32
+ var TestStatus_1;
33
+ TestStatus.open = new TestStatus_1();
34
+ TestStatus.closed = new TestStatus_1('cc');
35
+ TestStatus.hold = new TestStatus_1(undefined, 'hh');
36
+ TestStatus = TestStatus_1 = tslib_1.__decorate([
37
+ remult3_1.ValueListFieldType(),
38
+ tslib_1.__metadata("design:paramtypes", [String, String])
39
+ ], TestStatus);
34
40
  return TestStatus;
35
41
  }());
36
42
  exports.TestStatus = TestStatus;