remult 0.14.2 → 0.14.5
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/assign.js +1 -5
- package/classType.js +1 -2
- package/graphql.js +84 -146
- package/index.d.ts +13 -0
- package/index.js +25 -55
- package/inputTypes.js +9 -16
- package/package.json +6 -1
- package/postgres/index.js +1 -4
- package/postgres/postgres-data-provider.js +165 -364
- package/postgres/postgresColumnSyntax.js +4 -8
- package/remult-express.js +6 -10
- package/remult-knex/index.js +300 -720
- package/remult-middleware.js +24 -30
- package/remult-mongo.js +172 -406
- package/server/JsonEntityFileStorage.js +10 -15
- package/server/expressBridge.js +383 -569
- package/server/index.js +4 -11
- package/server/register-actions-on-server.js +12 -38
- package/server/register-entities-on-server.js +9 -13
- package/src/__EntityValueProvider.js +1 -2
- package/src/__RowsOfDataForTesting.js +1 -2
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +72 -190
- package/src/backend-tests/my-test.backend-spec.js +45 -114
- package/src/column-interfaces.js +2 -6
- package/src/column.js +71 -113
- package/src/context.js +174 -330
- package/src/data-api.js +162 -326
- package/src/data-interfaces.js +7 -11
- package/src/data-providers/array-entity-data-provider.js +171 -286
- package/src/data-providers/in-memory-database.js +12 -27
- package/src/data-providers/json-data-provider.js +41 -77
- package/src/data-providers/rest-data-provider.js +102 -189
- package/src/data-providers/sql-database.js +223 -403
- package/src/data-providers/web-sql-data-provider.js +78 -139
- package/src/entity.js +1 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.js +106 -248
- package/src/filter/filter-consumer-bridge-to-url-builder.js +1 -2
- package/src/filter/filter-interfaces.js +277 -440
- package/src/id-entity.js +8 -17
- package/src/remult3/RepositoryImplementation.js +1191 -2367
- package/src/remult3/index.js +2 -5
- package/src/remult3/remult3.js +1 -2
- package/src/server-action.js +294 -528
- package/src/shared-tests/db-tests-setup.js +49 -153
- package/src/shared-tests/db-tests.db-tests.js +660 -1566
- package/src/shared-tests/deleteAll.js +3 -20
- package/src/shared-tests/entityWithValidations.js +52 -79
- package/src/shared-tests/index.js +4 -6
- package/src/shared-tests/test-custom-id-column.spec.js +37 -85
- package/src/shared-tests/test-special-value.spec.js +64 -104
- package/src/shared-tests/test-update-with-null.spec.js +28 -49
- package/src/sort.js +38 -95
- package/src/sql-command.js +1 -2
- package/src/tests/Done.js +7 -13
- package/src/tests/TestDataApiResponse.js +15 -22
- package/src/tests/c.js +21 -27
- package/src/tests/createData.js +20 -48
- package/src/tests/d.js +19 -27
- package/src/tests/dWithPrefilter.js +31 -44
- package/src/tests/entityForCustomFilter.js +42 -66
- package/src/tests/entityWithValidationsOnColumn.js +21 -29
- package/src/tests/frontend-database-tests-setup.spec.js +35 -98
- package/src/tests/h.js +35 -44
- package/src/tests/remult-3-entities.js +71 -80
- package/src/tests/tasks.js +23 -29
- package/src/tests/testHelper.spec.js +170 -322
- package/src/tests/testModel/models.js +25 -33
- package/src/validators.js +32 -59
- package/urlBuilder.js +8 -14
- package/valueConverters.js +161 -160
package/src/validators.js
CHANGED
|
@@ -1,60 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { isBackend } from "..";
|
|
2
|
+
export class Validators {
|
|
3
|
+
}
|
|
4
|
+
Validators.required = Object.assign((entity, col, message = undefined) => {
|
|
5
|
+
if (!col.value || typeof (col.value) === "string" && col.value.trim().length == 0)
|
|
6
|
+
col.error = message || Validators.required.defaultMessage;
|
|
7
|
+
}, {
|
|
8
|
+
withMessage: (message) => {
|
|
9
|
+
return (entity, col) => Validators.required(entity, col, message);
|
|
10
|
+
},
|
|
11
|
+
defaultMessage: 'Should not be empty'
|
|
12
|
+
});
|
|
13
|
+
Validators.unique = Object.assign(async (entity, col, message = undefined) => {
|
|
14
|
+
if (!col.entityRef)
|
|
15
|
+
throw "unique validation may only work on columns that are attached to an entity";
|
|
16
|
+
if (col.entityRef.isNew() || col.valueChanged()) {
|
|
17
|
+
if (await col.entityRef.repository.count({ [col.metadata.key]: col.value }))
|
|
18
|
+
col.error = message || Validators.unique.defaultMessage;
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return tslib_1.__generator(this, function (_b) {
|
|
24
|
-
switch (_b.label) {
|
|
25
|
-
case 0:
|
|
26
|
-
if (!col.entityRef)
|
|
27
|
-
throw "unique validation may only work on columns that are attached to an entity";
|
|
28
|
-
if (!(col.entityRef.isNew() || col.valueChanged())) return [3 /*break*/, 2];
|
|
29
|
-
return [4 /*yield*/, col.entityRef.repository.count((_a = {}, _a[col.metadata.key] = col.value, _a))];
|
|
30
|
-
case 1:
|
|
31
|
-
if (_b.sent())
|
|
32
|
-
col.error = message || Validators.unique.defaultMessage;
|
|
33
|
-
_b.label = 2;
|
|
34
|
-
case 2: return [2 /*return*/];
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}, {
|
|
39
|
-
withMessage: function (message) {
|
|
40
|
-
return function (entity, col) { return Validators.unique(entity, col, message); };
|
|
41
|
-
},
|
|
42
|
-
defaultMessage: 'already exists'
|
|
43
|
-
});
|
|
44
|
-
Validators.uniqueOnBackend = Object.assign(function (entity, col, message) {
|
|
45
|
-
if (message === void 0) { message = undefined; }
|
|
46
|
-
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
return tslib_1.__generator(this, function (_a) {
|
|
48
|
-
if (__1.isBackend())
|
|
49
|
-
return [2 /*return*/, Validators.unique(entity, col, message)];
|
|
50
|
-
return [2 /*return*/];
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}, {
|
|
54
|
-
withMessage: function (message) {
|
|
55
|
-
return function (entity, col) { return Validators.uniqueOnBackend(entity, col, message); };
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return Validators;
|
|
59
|
-
}());
|
|
60
|
-
exports.Validators = Validators;
|
|
20
|
+
}, {
|
|
21
|
+
withMessage: (message) => {
|
|
22
|
+
return (entity, col) => Validators.unique(entity, col, message);
|
|
23
|
+
},
|
|
24
|
+
defaultMessage: 'already exists'
|
|
25
|
+
});
|
|
26
|
+
Validators.uniqueOnBackend = Object.assign(async (entity, col, message = undefined) => {
|
|
27
|
+
if (isBackend())
|
|
28
|
+
return Validators.unique(entity, col, message);
|
|
29
|
+
}, {
|
|
30
|
+
withMessage: (message) => {
|
|
31
|
+
return (entity, col) => Validators.uniqueOnBackend(entity, col, message);
|
|
32
|
+
}
|
|
33
|
+
});
|
package/urlBuilder.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.UrlBuilder = void 0;
|
|
4
|
-
var UrlBuilder = /** @class */ (function () {
|
|
5
|
-
function UrlBuilder(url) {
|
|
1
|
+
export class UrlBuilder {
|
|
2
|
+
constructor(url) {
|
|
6
3
|
this.url = url;
|
|
7
4
|
}
|
|
8
|
-
|
|
5
|
+
add(key, value) {
|
|
9
6
|
if (this.url.indexOf('?') >= 0)
|
|
10
7
|
this.url += '&';
|
|
11
8
|
else
|
|
12
9
|
this.url += '?';
|
|
13
10
|
this.url += encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (suffix === void 0) { suffix = ''; }
|
|
11
|
+
}
|
|
12
|
+
addObject(object, suffix = '') {
|
|
17
13
|
if (object != undefined)
|
|
18
14
|
for (var key in object) {
|
|
19
|
-
|
|
15
|
+
let val = object[key];
|
|
20
16
|
this.add(key + suffix, val);
|
|
21
17
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}());
|
|
25
|
-
exports.UrlBuilder = UrlBuilder;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/valueConverters.js
CHANGED
|
@@ -1,164 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return '';
|
|
13
|
-
if (typeof (val) === "string")
|
|
14
|
-
val = new Date(val);
|
|
15
|
-
if (val instanceof Date) {
|
|
16
|
-
return val.toISOString();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
console.log("ToJsonError", val);
|
|
20
|
-
throw new Error("Expected date but got val");
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
fromJson: function (val) {
|
|
24
|
-
if (val == undefined)
|
|
25
|
-
return undefined;
|
|
26
|
-
if (val == '')
|
|
27
|
-
return undefined;
|
|
28
|
-
if (val.startsWith('0000-00-00'))
|
|
29
|
-
return undefined;
|
|
30
|
-
return new Date(Date.parse(val));
|
|
31
|
-
},
|
|
32
|
-
toDb: function (x) { return x; },
|
|
33
|
-
fromDb: function (x) { return x; },
|
|
34
|
-
fromInput: function (x) { return ValueConverters.Date.fromJson(x); },
|
|
35
|
-
toInput: function (x) { return ValueConverters.Date.toJson(x); },
|
|
36
|
-
displayValue: function (val) {
|
|
37
|
-
if (!val)
|
|
38
|
-
return '';
|
|
39
|
-
return val.toLocaleString();
|
|
1
|
+
import { InputTypes } from "./inputTypes";
|
|
2
|
+
export class ValueConverters {
|
|
3
|
+
}
|
|
4
|
+
ValueConverters.Date = {
|
|
5
|
+
toJson: (val) => {
|
|
6
|
+
if (!val)
|
|
7
|
+
return '';
|
|
8
|
+
if (typeof (val) === "string")
|
|
9
|
+
val = new Date(val);
|
|
10
|
+
if (val instanceof Date) {
|
|
11
|
+
return val.toISOString();
|
|
40
12
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
toInput: function (x) { return ValueConverters.DateOnly.toJson(x); },
|
|
45
|
-
toJson: function (val) {
|
|
46
|
-
var d = val;
|
|
47
|
-
if (typeof d === "string" || typeof (d) === "number")
|
|
48
|
-
d = new Date(d);
|
|
49
|
-
if (!d || d == null)
|
|
50
|
-
return null;
|
|
51
|
-
if (d.getHours() == 0)
|
|
52
|
-
return new Date(d.valueOf() - d.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
|
|
53
|
-
else
|
|
54
|
-
return d.toISOString().substring(0, 10);
|
|
55
|
-
},
|
|
56
|
-
fromJson: function (value) {
|
|
57
|
-
if (!value || value == '' || value == '0000-00-00')
|
|
58
|
-
return null;
|
|
59
|
-
var d = new Date(Date.parse(value));
|
|
60
|
-
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
|
|
61
|
-
return d;
|
|
62
|
-
},
|
|
63
|
-
inputType: inputTypes_1.InputTypes.date,
|
|
64
|
-
toDb: function (val) {
|
|
65
|
-
if (!val)
|
|
66
|
-
return null;
|
|
67
|
-
return ValueConverters.DateOnly.fromJson(ValueConverters.DateOnly.toJson(val));
|
|
68
|
-
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
69
|
-
,
|
|
70
|
-
fromDb: function (val) {
|
|
71
|
-
var d = val;
|
|
72
|
-
if (!d)
|
|
73
|
-
return null;
|
|
74
|
-
return val;
|
|
75
|
-
},
|
|
76
|
-
fieldTypeInDb: 'date',
|
|
77
|
-
displayValue: function (value) {
|
|
78
|
-
if (!value)
|
|
79
|
-
return '';
|
|
80
|
-
return value.toLocaleDateString(undefined);
|
|
13
|
+
else {
|
|
14
|
+
console.log("ToJsonError", val);
|
|
15
|
+
throw new Error("Expected date but got val");
|
|
81
16
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
17
|
+
},
|
|
18
|
+
fromJson: (val) => {
|
|
19
|
+
if (val == undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (val == '')
|
|
22
|
+
return undefined;
|
|
23
|
+
if (val.startsWith('0000-00-00'))
|
|
24
|
+
return undefined;
|
|
25
|
+
return new Date(Date.parse(val));
|
|
26
|
+
},
|
|
27
|
+
toDb: x => x,
|
|
28
|
+
fromDb: x => x,
|
|
29
|
+
fromInput: x => ValueConverters.Date.fromJson(x),
|
|
30
|
+
toInput: x => ValueConverters.Date.toJson(x),
|
|
31
|
+
displayValue: (val) => {
|
|
32
|
+
if (!val)
|
|
33
|
+
return '';
|
|
34
|
+
return val.toLocaleString();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
ValueConverters.DateOnly = {
|
|
38
|
+
fromInput: x => ValueConverters.DateOnly.fromJson(x),
|
|
39
|
+
toInput: x => ValueConverters.DateOnly.toJson(x),
|
|
40
|
+
toJson: (val) => {
|
|
41
|
+
var d = val;
|
|
42
|
+
if (typeof d === "string" || typeof (d) === "number")
|
|
43
|
+
d = new Date(d);
|
|
44
|
+
if (!d || d == null)
|
|
45
|
+
return null;
|
|
46
|
+
if (d.getHours() == 0)
|
|
47
|
+
return new Date(d.valueOf() - d.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
|
|
48
|
+
else
|
|
49
|
+
return d.toISOString().substring(0, 10);
|
|
50
|
+
},
|
|
51
|
+
fromJson: (value) => {
|
|
52
|
+
if (!value || value == '' || value == '0000-00-00')
|
|
53
|
+
return null;
|
|
54
|
+
let d = new Date(Date.parse(value));
|
|
55
|
+
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
|
|
56
|
+
return d;
|
|
57
|
+
},
|
|
58
|
+
inputType: InputTypes.date,
|
|
59
|
+
toDb: (val) => {
|
|
60
|
+
if (!val)
|
|
61
|
+
return null;
|
|
62
|
+
return ValueConverters.DateOnly.fromJson(ValueConverters.DateOnly.toJson(val));
|
|
63
|
+
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
64
|
+
,
|
|
65
|
+
fromDb: (val) => {
|
|
66
|
+
var d = val;
|
|
67
|
+
if (!d)
|
|
68
|
+
return null;
|
|
69
|
+
return val;
|
|
70
|
+
},
|
|
71
|
+
fieldTypeInDb: 'date',
|
|
72
|
+
displayValue: (value) => {
|
|
73
|
+
if (!value)
|
|
74
|
+
return '';
|
|
75
|
+
return value.toLocaleDateString(undefined);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
ValueConverters.DateOnlyString = {
|
|
79
|
+
...ValueConverters.DateOnly,
|
|
80
|
+
toDb: (d) => {
|
|
81
|
+
let val = ValueConverters.DateOnly.toJson(d);
|
|
82
|
+
if (!val)
|
|
83
|
+
return undefined;
|
|
84
|
+
return val.replace(/-/g, '');
|
|
85
|
+
},
|
|
86
|
+
fromDb: (val) => {
|
|
87
|
+
if (!val)
|
|
88
|
+
return undefined;
|
|
89
|
+
return new Date(val.substring(0, 4) + '-' + val.substring(4, 6) + '-' + val.substring(6, 8));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
ValueConverters.Boolean = {
|
|
93
|
+
toDb: (val) => val,
|
|
94
|
+
inputType: InputTypes.checkbox,
|
|
95
|
+
fromDb: (value) => {
|
|
96
|
+
return ValueConverters.Boolean.fromJson(value);
|
|
97
|
+
},
|
|
98
|
+
fromJson: value => {
|
|
99
|
+
if (typeof value === "boolean")
|
|
105
100
|
return value;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
if (value !== undefined && value !== null) {
|
|
102
|
+
return value.toString().trim().toLowerCase() == 'true';
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
},
|
|
106
|
+
toJson: x => x,
|
|
107
|
+
fromInput: x => ValueConverters.Boolean.fromJson(x),
|
|
108
|
+
toInput: x => ValueConverters.Boolean.toJson(x)
|
|
109
|
+
};
|
|
110
|
+
ValueConverters.Number = {
|
|
111
|
+
fromDb: value => {
|
|
112
|
+
if (value !== undefined)
|
|
113
|
+
return +value;
|
|
114
|
+
return undefined;
|
|
115
|
+
},
|
|
116
|
+
toDb: value => value,
|
|
117
|
+
fromJson: value => ValueConverters.Number.fromDb(value),
|
|
118
|
+
toJson: value => ValueConverters.Number.toDb(value),
|
|
119
|
+
fromInput: (x, type) => {
|
|
120
|
+
let r = +x;
|
|
121
|
+
if (!x)
|
|
115
122
|
return undefined;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
ValueConverters.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
ValueConverters.JsonString
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
toInput: function (x) { return ValueConverters.JsonString.toJson(x); },
|
|
160
|
-
fieldTypeInDb: 'json'
|
|
161
|
-
};
|
|
162
|
-
return ValueConverters;
|
|
163
|
-
}());
|
|
164
|
-
exports.ValueConverters = ValueConverters;
|
|
123
|
+
return r;
|
|
124
|
+
},
|
|
125
|
+
toInput: (x, type) => {
|
|
126
|
+
return x?.toString();
|
|
127
|
+
},
|
|
128
|
+
inputType: InputTypes.number
|
|
129
|
+
};
|
|
130
|
+
ValueConverters.Integer = {
|
|
131
|
+
...ValueConverters.Number,
|
|
132
|
+
toJson: value => {
|
|
133
|
+
let val = ValueConverters.Number.toDb(value);
|
|
134
|
+
if (!val)
|
|
135
|
+
return val;
|
|
136
|
+
return +(+val).toFixed(0);
|
|
137
|
+
},
|
|
138
|
+
toDb: value => ValueConverters.Integer.toJson(value),
|
|
139
|
+
fieldTypeInDb: 'integer'
|
|
140
|
+
};
|
|
141
|
+
ValueConverters.Default = {
|
|
142
|
+
fromJson: x => x,
|
|
143
|
+
toJson: x => x,
|
|
144
|
+
fromDb: x => ValueConverters.JsonString.fromDb(x),
|
|
145
|
+
toDb: x => ValueConverters.JsonString.toDb(x),
|
|
146
|
+
fromInput: x => ValueConverters.Default.fromJson(x),
|
|
147
|
+
toInput: x => ValueConverters.Default.toJson(x)
|
|
148
|
+
};
|
|
149
|
+
ValueConverters.JsonString = {
|
|
150
|
+
fromJson: x => x,
|
|
151
|
+
toJson: x => x,
|
|
152
|
+
fromDb: x => x == null ? null : x ? JSON.parse(ValueConverters.JsonString.fromJson(x)) : undefined,
|
|
153
|
+
toDb: x => x !== undefined ? x === null ? null : JSON.stringify(ValueConverters.JsonString.toJson(x)) : undefined,
|
|
154
|
+
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
155
|
+
toInput: x => ValueConverters.JsonString.toJson(x)
|
|
156
|
+
};
|
|
157
|
+
ValueConverters.JsonValue = {
|
|
158
|
+
fromJson: x => x,
|
|
159
|
+
toJson: x => x,
|
|
160
|
+
fromDb: x => x,
|
|
161
|
+
toDb: x => x,
|
|
162
|
+
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
163
|
+
toInput: x => ValueConverters.JsonString.toJson(x),
|
|
164
|
+
fieldTypeInDb: 'json'
|
|
165
|
+
};
|