remult 0.19.2 → 0.19.3
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/esm/src/remult3/RepositoryImplementation.js +1 -4
- package/esm/src/shared-tests/db-tests.db-tests.js +8 -0
- package/esm/src/valueConverters.d.ts +1 -0
- package/esm/src/valueConverters.js +15 -0
- package/package.json +1 -1
- package/src/remult3/RepositoryImplementation.js +1 -4
- package/src/shared-tests/db-tests.db-tests.js +20 -0
- package/src/valueConverters.d.ts +1 -0
- package/src/valueConverters.js +15 -0
|
@@ -1711,10 +1711,7 @@ export function decorateColumnSettings(settings, remult) {
|
|
|
1711
1711
|
if (settings.valueType == String) {
|
|
1712
1712
|
let x = settings;
|
|
1713
1713
|
if (!settings.valueConverter)
|
|
1714
|
-
x.valueConverter =
|
|
1715
|
-
toJson: x => x,
|
|
1716
|
-
fromJson: x => x
|
|
1717
|
-
};
|
|
1714
|
+
x.valueConverter = ValueConverters.String;
|
|
1718
1715
|
}
|
|
1719
1716
|
if (settings.valueType == Number) {
|
|
1720
1717
|
let x = settings;
|
|
@@ -25,6 +25,14 @@ testAll("what", async ({ remult, createEntity }) => {
|
|
|
25
25
|
await (await createEntity(stam)).create({ id: 1, title: 'noam' }).save();
|
|
26
26
|
expect(await remult.repo(stam).count()).toBe(1);
|
|
27
27
|
}, false);
|
|
28
|
+
testAll("data types", async ({ remult, createEntity }) => {
|
|
29
|
+
let r = await (await createEntity(stam)).create({
|
|
30
|
+
id: 1,
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
title: 42
|
|
33
|
+
}).save();
|
|
34
|
+
expect(r.title).toEqual("42");
|
|
35
|
+
}, false);
|
|
28
36
|
testAll("filter works on all db", async ({ createEntity }) => {
|
|
29
37
|
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
30
38
|
expect((await s.find({ where: { myId: [1, 3] } })).length).toBe(2);
|
|
@@ -5,6 +5,7 @@ export declare class ValueConverters {
|
|
|
5
5
|
static readonly DateOnlyString: ValueConverter<Date>;
|
|
6
6
|
static readonly Boolean: ValueConverter<Boolean>;
|
|
7
7
|
static readonly Number: ValueConverter<number>;
|
|
8
|
+
static readonly String: ValueConverter<String>;
|
|
8
9
|
static readonly Integer: ValueConverter<number>;
|
|
9
10
|
static readonly Default: Required<ValueConverter<any>>;
|
|
10
11
|
static readonly JsonString: ValueConverter<any>;
|
|
@@ -141,6 +141,14 @@ ValueConverters.Number = {
|
|
|
141
141
|
},
|
|
142
142
|
inputType: InputTypes.number
|
|
143
143
|
};
|
|
144
|
+
ValueConverters.String = {
|
|
145
|
+
fromDb: enforceString,
|
|
146
|
+
toDb: enforceString,
|
|
147
|
+
fromJson: enforceString,
|
|
148
|
+
toJson: enforceString,
|
|
149
|
+
fromInput: enforceString,
|
|
150
|
+
toInput: enforceString,
|
|
151
|
+
};
|
|
144
152
|
ValueConverters.Integer = {
|
|
145
153
|
...ValueConverters.Number,
|
|
146
154
|
toJson: value => {
|
|
@@ -180,3 +188,10 @@ ValueConverters.JsonValue = {
|
|
|
180
188
|
toInput: x => ValueConverters.JsonString.toJson(x),
|
|
181
189
|
fieldTypeInDb: 'json'
|
|
182
190
|
};
|
|
191
|
+
function enforceString(value) {
|
|
192
|
+
if (value === null || value === undefined)
|
|
193
|
+
return value;
|
|
194
|
+
if (typeof (value) !== "string")
|
|
195
|
+
return value.toString();
|
|
196
|
+
return value;
|
|
197
|
+
}
|
package/package.json
CHANGED
|
@@ -2896,10 +2896,7 @@ function decorateColumnSettings(settings, remult) {
|
|
|
2896
2896
|
if (settings.valueType == String) {
|
|
2897
2897
|
var x = settings;
|
|
2898
2898
|
if (!settings.valueConverter)
|
|
2899
|
-
x.valueConverter =
|
|
2900
|
-
toJson: function (x) { return x; },
|
|
2901
|
-
fromJson: function (x) { return x; }
|
|
2902
|
-
};
|
|
2899
|
+
x.valueConverter = valueConverters_1.ValueConverters.String;
|
|
2903
2900
|
}
|
|
2904
2901
|
if (settings.valueType == Number) {
|
|
2905
2902
|
var x = settings;
|
|
@@ -43,6 +43,26 @@ db_tests_setup_1.testAll("what", function (_a) {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
}, false);
|
|
46
|
+
db_tests_setup_1.testAll("data types", function (_a) {
|
|
47
|
+
var remult = _a.remult, createEntity = _a.createEntity;
|
|
48
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
49
|
+
var r;
|
|
50
|
+
return tslib_1.__generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, createEntity(stam)];
|
|
53
|
+
case 1: return [4 /*yield*/, (_b.sent()).create({
|
|
54
|
+
id: 1,
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
title: 42
|
|
57
|
+
}).save()];
|
|
58
|
+
case 2:
|
|
59
|
+
r = _b.sent();
|
|
60
|
+
expect(r.title).toEqual("42");
|
|
61
|
+
return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}, false);
|
|
46
66
|
db_tests_setup_1.testAll("filter works on all db", function (_a) {
|
|
47
67
|
var createEntity = _a.createEntity;
|
|
48
68
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
package/src/valueConverters.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class ValueConverters {
|
|
|
5
5
|
static readonly DateOnlyString: ValueConverter<Date>;
|
|
6
6
|
static readonly Boolean: ValueConverter<Boolean>;
|
|
7
7
|
static readonly Number: ValueConverter<number>;
|
|
8
|
+
static readonly String: ValueConverter<String>;
|
|
8
9
|
static readonly Integer: ValueConverter<number>;
|
|
9
10
|
static readonly Default: Required<ValueConverter<any>>;
|
|
10
11
|
static readonly JsonString: ValueConverter<any>;
|
package/src/valueConverters.js
CHANGED
|
@@ -142,6 +142,14 @@ var ValueConverters = /** @class */ (function () {
|
|
|
142
142
|
},
|
|
143
143
|
inputType: inputTypes_1.InputTypes.number
|
|
144
144
|
};
|
|
145
|
+
ValueConverters.String = {
|
|
146
|
+
fromDb: enforceString,
|
|
147
|
+
toDb: enforceString,
|
|
148
|
+
fromJson: enforceString,
|
|
149
|
+
toJson: enforceString,
|
|
150
|
+
fromInput: enforceString,
|
|
151
|
+
toInput: enforceString,
|
|
152
|
+
};
|
|
145
153
|
ValueConverters.Integer = tslib_1.__assign(tslib_1.__assign({}, ValueConverters.Number), { toJson: function (value) {
|
|
146
154
|
var val = ValueConverters.Number.toDb(value);
|
|
147
155
|
if (!val)
|
|
@@ -179,3 +187,10 @@ var ValueConverters = /** @class */ (function () {
|
|
|
179
187
|
return ValueConverters;
|
|
180
188
|
}());
|
|
181
189
|
exports.ValueConverters = ValueConverters;
|
|
190
|
+
function enforceString(value) {
|
|
191
|
+
if (value === null || value === undefined)
|
|
192
|
+
return value;
|
|
193
|
+
if (typeof (value) !== "string")
|
|
194
|
+
return value.toString();
|
|
195
|
+
return value;
|
|
196
|
+
}
|