remult 0.13.6 → 0.13.9

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.6",
3
+ "version": "0.13.9",
4
4
  "description": "remult core lib",
5
5
  "homepage": "https://remult.dev/",
6
6
  "repository": {
@@ -2,28 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  var __1 = require("../..");
5
- var context_1 = require("../context");
6
5
  var remult_knex_1 = require("../../remult-knex");
7
- var Knex = require("knex");
8
6
  var dotenv_1 = require("dotenv");
9
7
  var backend_database_test_setup_backend_spec_1 = require("./backend-database-test-setup.backend-spec");
10
8
  var entityWithValidations_1 = require("../shared-tests/entityWithValidations");
11
9
  dotenv_1.config();
12
- describe("test", function () {
13
- var remult;
14
- var knex;
15
- beforeAll(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
16
- return tslib_1.__generator(this, function (_a) {
17
- knex =
18
- Knex.default({
19
- client: 'pg',
20
- connection: process.env.DATABASE_URL
21
- });
22
- remult = new context_1.Remult(new remult_knex_1.KnexDataProvider(knex));
23
- return [2 /*return*/];
24
- });
25
- }); });
26
- });
27
10
  backend_database_test_setup_backend_spec_1.testPostgresImplementation("sql filter", function (_a) {
28
11
  var createEntity = _a.createEntity;
29
12
  return tslib_1.__awaiter(void 0, void 0, void 0, function () {
@@ -224,7 +224,7 @@ export declare function isAutoIncrement(f: FieldMetadata): boolean;
224
224
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
225
225
  maxLength?: number;
226
226
  }
227
- export declare function ValueListFieldType<entityType = any, valueType extends ValueListItem = any>(...options: (ValueListFieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (type: ClassType<valueType>) => any;
227
+ export declare function ValueListFieldType<entityType = any, valueType extends ValueListItem = any>(...options: (ValueListFieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (type: ClassType<valueType>) => void;
228
228
  export interface ValueListFieldOptions<entityType, valueType> extends FieldOptions<entityType, valueType> {
229
229
  getValues?: () => valueType[];
230
230
  }
@@ -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
- private loadFromDecoratorOptions;
240
238
  getValues(): T[];
241
239
  byId(key: any): T;
242
240
  fromJson(val: any): T;
@@ -2269,7 +2269,7 @@ function ValueListFieldType() {
2269
2269
  options[_i] = arguments[_i];
2270
2270
  }
2271
2271
  return function (type) {
2272
- return FieldType.apply(void 0, tslib_1.__spread([function (o) {
2272
+ FieldType.apply(void 0, tslib_1.__spread([function (o) {
2273
2273
  o.valueConverter = ValueListInfo.get(type),
2274
2274
  o.displayValue = function (item, val) { return val.caption; };
2275
2275
  }], options))(type);
@@ -2278,11 +2278,12 @@ function ValueListFieldType() {
2278
2278
  exports.ValueListFieldType = ValueListFieldType;
2279
2279
  var ValueListInfo = /** @class */ (function () {
2280
2280
  function ValueListInfo(valueListType) {
2281
+ var e_30, _a, _b;
2282
+ var _this = this;
2281
2283
  this.valueListType = valueListType;
2282
2284
  this.byIdMap = new Map();
2283
2285
  this.values = [];
2284
2286
  this.isNumeric = false;
2285
- this.loadedFromOptions = false;
2286
2287
  for (var member in this.valueListType) {
2287
2288
  var s = this.valueListType[member];
2288
2289
  if (s instanceof this.valueListType) {
@@ -2299,30 +2300,18 @@ var ValueListInfo = /** @class */ (function () {
2299
2300
  if (this.isNumeric) {
2300
2301
  this.fieldTypeInDb = 'integer';
2301
2302
  }
2302
- }
2303
- ValueListInfo.get = function (type) {
2304
- var r = typeCache.get(type);
2305
- if (!r) {
2306
- r = new ValueListInfo(type);
2307
- typeCache.set(type, r);
2308
- }
2309
- return r;
2310
- };
2311
- ValueListInfo.prototype.loadFromDecoratorOptions = function () {
2312
- var e_30, _a, _b;
2313
- if (this.loadedFromOptions)
2314
- return;
2315
2303
  var options = Reflect.getMetadata(exports.storableMember, this.valueListType);
2316
2304
  if (options) {
2317
- this.loadedFromOptions = true;
2318
2305
  try {
2319
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()) {
2320
2307
  var op = options_1_1.value;
2321
2308
  if (op === null || op === void 0 ? void 0 : op.getValues) {
2322
2309
  (_b = this.values).splice.apply(_b, tslib_1.__spread([0, this.values.length], op.getValues()));
2310
+ this.byIdMap.clear();
2323
2311
  this.values.forEach(function (s) {
2324
2312
  if (s.caption === undefined && s.id !== undefined)
2325
2313
  s.caption = column_1.makeTitle(s.id);
2314
+ _this.byIdMap.set(s.id, s);
2326
2315
  });
2327
2316
  }
2328
2317
  }
@@ -2335,15 +2324,23 @@ var ValueListInfo = /** @class */ (function () {
2335
2324
  finally { if (e_30) throw e_30.error; }
2336
2325
  }
2337
2326
  if (this.values.find(function (s) { return s.id === undefined; }))
2338
- 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);
2339
2337
  }
2338
+ return r;
2340
2339
  };
2341
2340
  ValueListInfo.prototype.getValues = function () {
2342
- this.loadFromDecoratorOptions();
2343
2341
  return this.values;
2344
2342
  };
2345
2343
  ValueListInfo.prototype.byId = function (key) {
2346
- this.loadFromDecoratorOptions();
2347
2344
  if (this.isNumeric)
2348
2345
  key = +key;
2349
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;