remult 0.24.2-exp.0 → 0.25.0
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/README.md +4 -4
- package/esm/index.js +2 -2
- package/esm/remult-mongo.js +1 -1
- package/esm/remult-sql-js.js +113 -0
- package/esm/src/data-providers/array-entity-data-provider.js +1 -1
- package/esm/src/data-providers/json-data-provider.js +1 -1
- package/esm/src/data-providers/{ipfs-data-provider.js → json-entity-opfs-storage.js} +1 -1
- package/esm/src/data-providers/sql-database.js +10 -6
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +4 -5
- package/esm/src/remult-proxy.js +4 -0
- package/esm/src/remult3/Fields.js +22 -0
- package/esm/src/remult3/RepositoryImplementation.js +109 -60
- package/esm/src/remult3/entity.js +2 -2
- package/esm/src/remult3/getEntityRef.js +5 -5
- package/esm/src/remult3/relationInfoMember.js +1 -1
- package/esm/src/remult3/remult3.js +6 -7
- package/esm/src/server-action-info.js +1 -1
- package/esm/src/server-action.js +1 -1
- package/esm/src/validators.js +120 -28
- package/index.d.ts +3 -3
- package/index.js +8 -3
- package/package.json +6 -1
- package/remult-mongo.js +1 -1
- package/remult-sql-js.d.ts +18 -0
- package/remult-sql-js.js +211 -0
- package/src/column-interfaces.d.ts +12 -6
- package/src/data-providers/array-entity-data-provider.js +9 -10
- package/src/data-providers/json-data-provider.js +1 -1
- package/src/data-providers/{ipfs-data-provider.d.ts → json-entity-opfs-storage.d.ts} +1 -1
- package/src/data-providers/{ipfs-data-provider.js → json-entity-opfs-storage.js} +7 -7
- package/src/data-providers/sql-database.js +14 -6
- package/src/filter/filter-consumer-bridge-to-sql-request.js +4 -5
- package/src/remult-proxy.js +11 -0
- package/src/remult3/Fields.js +22 -0
- package/src/remult3/RepositoryImplementation.d.ts +6 -6
- package/src/remult3/RepositoryImplementation.js +136 -78
- package/src/remult3/entity.js +2 -2
- package/src/remult3/getEntityRef.js +5 -5
- package/src/remult3/relationInfoMember.js +1 -1
- package/src/remult3/remult3.d.ts +33 -0
- package/src/remult3/remult3.js +6 -7
- package/src/server-action-info.js +1 -1
- package/src/server-action.js +1 -1
- package/src/sql-command.d.ts +1 -0
- package/src/validators.d.ts +41 -9
- package/src/validators.js +183 -54
|
@@ -73,14 +73,14 @@ export type EntityOptionsFactory = (remult: Remult) => EntityOptions;
|
|
|
73
73
|
export declare const columnsOfType: Map<any, columnInfo[]>;
|
|
74
74
|
export declare function createOldEntity<T>(entity: ClassType<T>, remult: Remult): EntityFullInfo<T>;
|
|
75
75
|
declare abstract class rowHelperBase<T> {
|
|
76
|
-
protected
|
|
76
|
+
protected fieldsMetadata: FieldMetadata[];
|
|
77
77
|
instance: T;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
remult: Remult;
|
|
79
|
+
isNewRow: boolean;
|
|
80
80
|
_error: string;
|
|
81
81
|
get error(): string;
|
|
82
82
|
set error(val: string);
|
|
83
|
-
constructor(
|
|
83
|
+
constructor(fieldsMetadata: FieldMetadata[], instance: T, remult: Remult, isNewRow: boolean);
|
|
84
84
|
_subscribers: SubscribableImp;
|
|
85
85
|
subscribe(listener: RefSubscriber): Unsubscribe;
|
|
86
86
|
_isLoading: boolean;
|
|
@@ -146,7 +146,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
|
|
|
146
146
|
export declare function getFields<fieldsContainerType>(container: fieldsContainerType, remult?: Remult): FieldsRef<fieldsContainerType>;
|
|
147
147
|
export declare function getControllerRef<fieldsContainerType>(container: fieldsContainerType, remultArg?: Remult): ControllerRef<fieldsContainerType>;
|
|
148
148
|
export declare class controllerRefImpl<T = any> extends rowHelperBase<T> implements ControllerRef<T> {
|
|
149
|
-
constructor(columnsInfo:
|
|
149
|
+
constructor(columnsInfo: FieldMetadata[], instance: any, remult: Remult);
|
|
150
150
|
__performColumnAndEntityValidations(): Promise<void>;
|
|
151
151
|
fields: FieldsRef<T>;
|
|
152
152
|
}
|
|
@@ -239,12 +239,12 @@ export declare class columnDefsImpl implements FieldMetadata {
|
|
|
239
239
|
valueType: any;
|
|
240
240
|
}
|
|
241
241
|
declare class EntityFullInfo<T> implements EntityMetadata<T> {
|
|
242
|
-
columnsInfo: FieldOptions[];
|
|
243
242
|
entityInfo: EntityOptions;
|
|
244
243
|
private remult;
|
|
245
244
|
readonly entityType: ClassType<T>;
|
|
246
245
|
readonly key: string;
|
|
247
246
|
options: EntityOptions<T>;
|
|
247
|
+
fieldsMetadata: FieldMetadata[];
|
|
248
248
|
constructor(columnsInfo: FieldOptions[], entityInfo: EntityOptions, remult: Remult, entityType: ClassType<T>, key: string);
|
|
249
249
|
apiUpdateAllowed(item: T): boolean;
|
|
250
250
|
get apiReadAllowed(): boolean;
|
|
@@ -995,9 +995,11 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
995
995
|
var col = _c.value;
|
|
996
996
|
var ei = (0, getEntityRef_js_1.getEntitySettings)(col.valueType, false);
|
|
997
997
|
if (ei) {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
998
|
+
var val = json[col.key];
|
|
999
|
+
if (typeof val === 'string' || typeof val === 'number')
|
|
1000
|
+
result[col.key] = val;
|
|
1001
|
+
else
|
|
1002
|
+
result[col.key] = this.remult.repo(col.valueType).fromJson(val);
|
|
1001
1003
|
}
|
|
1002
1004
|
else {
|
|
1003
1005
|
if (json[col.key] !== undefined) {
|
|
@@ -1046,6 +1048,8 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
1046
1048
|
var r, cacheInfo, f, key;
|
|
1047
1049
|
var _this = this;
|
|
1048
1050
|
return tslib_1.__generator(this, function (_a) {
|
|
1051
|
+
if (!options)
|
|
1052
|
+
options = {};
|
|
1049
1053
|
if (options.useCache) {
|
|
1050
1054
|
f = (0, rest_data_provider_js_1.findOptionsToJson)(options, this.metadata);
|
|
1051
1055
|
key = JSON.stringify(f);
|
|
@@ -1309,11 +1313,11 @@ function createOldEntity(entity, remult) {
|
|
|
1309
1313
|
}
|
|
1310
1314
|
exports.createOldEntity = createOldEntity;
|
|
1311
1315
|
var rowHelperBase = /** @class */ (function () {
|
|
1312
|
-
function rowHelperBase(
|
|
1316
|
+
function rowHelperBase(fieldsMetadata, instance, remult, isNewRow) {
|
|
1313
1317
|
var e_21, _a;
|
|
1314
1318
|
var _this = this;
|
|
1315
1319
|
var _b;
|
|
1316
|
-
this.
|
|
1320
|
+
this.fieldsMetadata = fieldsMetadata;
|
|
1317
1321
|
this.instance = instance;
|
|
1318
1322
|
this.remult = remult;
|
|
1319
1323
|
this.isNewRow = isNewRow;
|
|
@@ -1329,7 +1333,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1329
1333
|
var _loop_5 = function (col) {
|
|
1330
1334
|
var ei = (0, getEntityRef_js_1.getEntitySettings)(col.valueType, false);
|
|
1331
1335
|
if (ei && remult) {
|
|
1332
|
-
var lookup_1 = new column_js_1.LookupColumn(remult.repo(col.valueType), Boolean(
|
|
1336
|
+
var lookup_1 = new column_js_1.LookupColumn(remult.repo(col.valueType), Boolean((0, relationInfoMember_js_1.getRelationInfo)(col.options)), col.allowNull);
|
|
1333
1337
|
this_2.lookups.set(col.key, lookup_1);
|
|
1334
1338
|
var val = instance[col.key];
|
|
1335
1339
|
var refImpl_1;
|
|
@@ -1363,7 +1367,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1363
1367
|
});
|
|
1364
1368
|
lookup_1.set(val);
|
|
1365
1369
|
}
|
|
1366
|
-
else if (((_b = (0, relationInfoMember_js_1.getRelationInfo)(col)) === null || _b === void 0 ? void 0 : _b.type) === 'toOne') {
|
|
1370
|
+
else if (((_b = (0, relationInfoMember_js_1.getRelationInfo)(col.options)) === null || _b === void 0 ? void 0 : _b.type) === 'toOne') {
|
|
1367
1371
|
var hasVal = instance.hasOwnProperty(col.key);
|
|
1368
1372
|
var val_1 = instance[col.key];
|
|
1369
1373
|
if (isNewRow && !val_1)
|
|
@@ -1376,10 +1380,10 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1376
1380
|
val_1 = newVal;
|
|
1377
1381
|
if (newVal === undefined)
|
|
1378
1382
|
return;
|
|
1379
|
-
var op = col;
|
|
1383
|
+
var op = col.options;
|
|
1380
1384
|
if (op.field) {
|
|
1381
1385
|
_this.instance[op.field] = _this.remult
|
|
1382
|
-
.repo((0, relationInfoMember_js_1.getRelationInfo)(col).toType())
|
|
1386
|
+
.repo((0, relationInfoMember_js_1.getRelationInfo)(col.options).toType())
|
|
1383
1387
|
.metadata.idMetadata.getId(newVal);
|
|
1384
1388
|
}
|
|
1385
1389
|
if (op.fields) {
|
|
@@ -1399,15 +1403,15 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1399
1403
|
};
|
|
1400
1404
|
var this_2 = this;
|
|
1401
1405
|
try {
|
|
1402
|
-
for (var
|
|
1403
|
-
var col =
|
|
1406
|
+
for (var fieldsMetadata_1 = tslib_1.__values(fieldsMetadata), fieldsMetadata_1_1 = fieldsMetadata_1.next(); !fieldsMetadata_1_1.done; fieldsMetadata_1_1 = fieldsMetadata_1.next()) {
|
|
1407
|
+
var col = fieldsMetadata_1_1.value;
|
|
1404
1408
|
_loop_5(col);
|
|
1405
1409
|
}
|
|
1406
1410
|
}
|
|
1407
1411
|
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
1408
1412
|
finally {
|
|
1409
1413
|
try {
|
|
1410
|
-
if (
|
|
1414
|
+
if (fieldsMetadata_1_1 && !fieldsMetadata_1_1.done && (_a = fieldsMetadata_1.return)) _a.call(fieldsMetadata_1);
|
|
1411
1415
|
}
|
|
1412
1416
|
finally { if (e_21) throw e_21.error; }
|
|
1413
1417
|
}
|
|
@@ -1460,7 +1464,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1460
1464
|
};
|
|
1461
1465
|
var this_3 = this;
|
|
1462
1466
|
try {
|
|
1463
|
-
for (var _b = tslib_1.__values(this.
|
|
1467
|
+
for (var _b = tslib_1.__values(this.fieldsMetadata), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1464
1468
|
var col = _c.value;
|
|
1465
1469
|
_loop_6(col);
|
|
1466
1470
|
}
|
|
@@ -1512,7 +1516,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1512
1516
|
};
|
|
1513
1517
|
if (!error.message) {
|
|
1514
1518
|
try {
|
|
1515
|
-
for (var _b = tslib_1.__values(this.
|
|
1519
|
+
for (var _b = tslib_1.__values(this.fieldsMetadata), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1516
1520
|
var col = _c.value;
|
|
1517
1521
|
if (this.errors[col.key]) {
|
|
1518
1522
|
error.message =
|
|
@@ -1590,11 +1594,11 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1590
1594
|
if (isNew === void 0) { isNew = false; }
|
|
1591
1595
|
var d = {};
|
|
1592
1596
|
try {
|
|
1593
|
-
for (var _b = tslib_1.__values(this.
|
|
1597
|
+
for (var _b = tslib_1.__values(this.fieldsMetadata), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1594
1598
|
var col = _c.value;
|
|
1595
1599
|
var lu = this.lookups.get(col.key);
|
|
1596
1600
|
var val = undefined;
|
|
1597
|
-
var rel = (0, relationInfoMember_js_1.getRelationInfo)(col);
|
|
1601
|
+
var rel = (0, relationInfoMember_js_1.getRelationInfo)(col.options);
|
|
1598
1602
|
if (lu)
|
|
1599
1603
|
val = lu.id;
|
|
1600
1604
|
else
|
|
@@ -1689,12 +1693,9 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1689
1693
|
if (notJustApi === void 0) { notJustApi = false; }
|
|
1690
1694
|
var result = {};
|
|
1691
1695
|
try {
|
|
1692
|
-
for (var _b = tslib_1.__values(this.
|
|
1696
|
+
for (var _b = tslib_1.__values(this.fieldsMetadata), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1693
1697
|
var col = _c.value;
|
|
1694
|
-
if (notJustApi ||
|
|
1695
|
-
!this.remult ||
|
|
1696
|
-
col.includeInApi === undefined ||
|
|
1697
|
-
this.remult.isAllowedForInstance(this.instance, col.includeInApi)) {
|
|
1698
|
+
if (notJustApi || !this.remult || col.includedInApi(this.instance)) {
|
|
1698
1699
|
var val = void 0;
|
|
1699
1700
|
var lu = this.lookups.get(col.key);
|
|
1700
1701
|
var disable = false;
|
|
@@ -1707,7 +1708,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1707
1708
|
else
|
|
1708
1709
|
val = lu.id;
|
|
1709
1710
|
else {
|
|
1710
|
-
if ((0, relationInfoMember_js_1.getRelationInfo)(col) && !includeRelatedEntities) {
|
|
1711
|
+
if ((0, relationInfoMember_js_1.getRelationInfo)(col.options) && !includeRelatedEntities) {
|
|
1711
1712
|
disable = true;
|
|
1712
1713
|
}
|
|
1713
1714
|
else {
|
|
@@ -1746,15 +1747,13 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1746
1747
|
case 0:
|
|
1747
1748
|
keys = Object.keys(body);
|
|
1748
1749
|
try {
|
|
1749
|
-
for (_a = tslib_1.__values(this.
|
|
1750
|
+
for (_a = tslib_1.__values(this.fieldsMetadata), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1750
1751
|
col = _b.value;
|
|
1751
1752
|
if (keys.includes(col.key))
|
|
1752
|
-
if (col.
|
|
1753
|
-
this.remult.isAllowedForInstance(this.instance, col.includeInApi)) {
|
|
1753
|
+
if (col.includedInApi(this.instance)) {
|
|
1754
1754
|
if (!this.remult ||
|
|
1755
1755
|
ignoreApiAllowed ||
|
|
1756
|
-
col.
|
|
1757
|
-
this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
1756
|
+
col.apiUpdateAllowed(this.instance)) {
|
|
1758
1757
|
lu = this.lookups.get(col.key);
|
|
1759
1758
|
if (lu)
|
|
1760
1759
|
lu.id = body[col.key];
|
|
@@ -1785,7 +1784,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
1785
1784
|
tslib_1.__extends(rowHelperImplementation, _super);
|
|
1786
1785
|
function rowHelperImplementation(info, instance, repository, edp, remult, _isNew) {
|
|
1787
1786
|
var e_28, _a;
|
|
1788
|
-
var _this = _super.call(this, info.
|
|
1787
|
+
var _this = _super.call(this, info.fieldsMetadata, instance, remult, _isNew) || this;
|
|
1789
1788
|
_this.info = info;
|
|
1790
1789
|
_this.repository = repository;
|
|
1791
1790
|
_this.edp = edp;
|
|
@@ -1795,14 +1794,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
1795
1794
|
_this.metadata = info;
|
|
1796
1795
|
if (_isNew) {
|
|
1797
1796
|
try {
|
|
1798
|
-
for (var _b = tslib_1.__values(info.
|
|
1797
|
+
for (var _b = tslib_1.__values(info.fieldsMetadata), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1799
1798
|
var col = _c.value;
|
|
1800
|
-
if (col.defaultValue && instance[col.key] === undefined) {
|
|
1801
|
-
if (typeof col.defaultValue === 'function') {
|
|
1802
|
-
instance[col.key] = col.defaultValue(instance);
|
|
1799
|
+
if (col.options.defaultValue && instance[col.key] === undefined) {
|
|
1800
|
+
if (typeof col.options.defaultValue === 'function') {
|
|
1801
|
+
instance[col.key] = col.options.defaultValue(instance);
|
|
1803
1802
|
}
|
|
1804
1803
|
else if (!instance[col.key])
|
|
1805
|
-
instance[col.key] = col.defaultValue;
|
|
1804
|
+
instance[col.key] = col.options.defaultValue;
|
|
1806
1805
|
}
|
|
1807
1806
|
}
|
|
1808
1807
|
}
|
|
@@ -1914,9 +1913,9 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
1914
1913
|
_a.toArray = function () { return _items_1; },
|
|
1915
1914
|
_a);
|
|
1916
1915
|
try {
|
|
1917
|
-
for (var _c = tslib_1.__values(this.info.
|
|
1916
|
+
for (var _c = tslib_1.__values(this.info.fieldsMetadata), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1918
1917
|
var c = _d.value;
|
|
1919
|
-
_items_1.push((r_1[c.key] = new FieldRefImplementation(c,
|
|
1918
|
+
_items_1.push((r_1[c.key] = new FieldRefImplementation(c.options, c, this.instance, this, this)));
|
|
1920
1919
|
}
|
|
1921
1920
|
}
|
|
1922
1921
|
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
@@ -2274,15 +2273,15 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
2274
2273
|
_f.label = 1;
|
|
2275
2274
|
case 1:
|
|
2276
2275
|
_f.trys.push([1, 6, 7, 8]);
|
|
2277
|
-
_a = tslib_1.__values(this.info.
|
|
2276
|
+
_a = tslib_1.__values(this.info.fieldsMetadata), _b = _a.next();
|
|
2278
2277
|
_f.label = 2;
|
|
2279
2278
|
case 2:
|
|
2280
2279
|
if (!!_b.done) return [3 /*break*/, 5];
|
|
2281
2280
|
col = _b.value;
|
|
2282
|
-
if (!col.serverExpression) return [3 /*break*/, 4];
|
|
2281
|
+
if (!col.options.serverExpression) return [3 /*break*/, 4];
|
|
2283
2282
|
_c = this.instance;
|
|
2284
2283
|
_d = col.key;
|
|
2285
|
-
return [4 /*yield*/, col.serverExpression(this.instance)];
|
|
2284
|
+
return [4 /*yield*/, col.options.serverExpression(this.instance)];
|
|
2286
2285
|
case 3:
|
|
2287
2286
|
_c[_d] = _f.sent();
|
|
2288
2287
|
_f.label = 4;
|
|
@@ -2340,13 +2339,13 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
2340
2339
|
switch (_g.label) {
|
|
2341
2340
|
case 0:
|
|
2342
2341
|
_g.trys.push([0, 5, 6, 7]);
|
|
2343
|
-
_a = tslib_1.__values(this.
|
|
2342
|
+
_a = tslib_1.__values(this.fieldsMetadata), _b = _a.next();
|
|
2344
2343
|
_g.label = 1;
|
|
2345
2344
|
case 1:
|
|
2346
2345
|
if (!!_b.done) return [3 /*break*/, 4];
|
|
2347
2346
|
c = _b.value;
|
|
2348
|
-
if (!c.validate) return [3 /*break*/, 3];
|
|
2349
|
-
col = new FieldRefImplementation(c,
|
|
2347
|
+
if (!c.options.validate) return [3 /*break*/, 3];
|
|
2348
|
+
col = new FieldRefImplementation(c.options, c, this.instance, this, this);
|
|
2350
2349
|
return [4 /*yield*/, col.__performValidation()];
|
|
2351
2350
|
case 2:
|
|
2352
2351
|
_g.sent();
|
|
@@ -2408,7 +2407,7 @@ var rowHelperImplementation = /** @class */ (function (_super) {
|
|
|
2408
2407
|
return rowHelperImplementation;
|
|
2409
2408
|
}(rowHelperBase));
|
|
2410
2409
|
exports.rowHelperImplementation = rowHelperImplementation;
|
|
2411
|
-
var controllerColumns = Symbol('controllerColumns');
|
|
2410
|
+
var controllerColumns = Symbol.for('controllerColumns');
|
|
2412
2411
|
function prepareColumnInfo(r, remult) {
|
|
2413
2412
|
return r.map(function (x) { return decorateColumnSettings(x.settings(remult), remult); });
|
|
2414
2413
|
}
|
|
@@ -2433,7 +2432,7 @@ function getControllerRef(container, remultArg) {
|
|
|
2433
2432
|
}
|
|
2434
2433
|
base = Object.getPrototypeOf(base);
|
|
2435
2434
|
}
|
|
2436
|
-
container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(columnSettings_1, remultVar), container, remultVar);
|
|
2435
|
+
container[controllerColumns] = result = new controllerRefImpl(prepareColumnInfo(columnSettings_1, remultVar).map(function (x) { return new columnDefsImpl(x, undefined, remultVar); }), container, remultVar);
|
|
2437
2436
|
}
|
|
2438
2437
|
return result;
|
|
2439
2438
|
}
|
|
@@ -2453,15 +2452,15 @@ var controllerRefImpl = /** @class */ (function (_super) {
|
|
|
2453
2452
|
_a.toArray = function () { return _items; },
|
|
2454
2453
|
_a);
|
|
2455
2454
|
try {
|
|
2456
|
-
for (var
|
|
2457
|
-
var col =
|
|
2458
|
-
_items.push((r[col.key] = new FieldRefImplementation(col,
|
|
2455
|
+
for (var columnsInfo_1 = tslib_1.__values(columnsInfo), columnsInfo_1_1 = columnsInfo_1.next(); !columnsInfo_1_1.done; columnsInfo_1_1 = columnsInfo_1.next()) {
|
|
2456
|
+
var col = columnsInfo_1_1.value;
|
|
2457
|
+
_items.push((r[col.key] = new FieldRefImplementation(col.options, col, instance, undefined, _this)));
|
|
2459
2458
|
}
|
|
2460
2459
|
}
|
|
2461
2460
|
catch (e_39_1) { e_39 = { error: e_39_1 }; }
|
|
2462
2461
|
finally {
|
|
2463
2462
|
try {
|
|
2464
|
-
if (
|
|
2463
|
+
if (columnsInfo_1_1 && !columnsInfo_1_1.done && (_b = columnsInfo_1.return)) _b.call(columnsInfo_1);
|
|
2465
2464
|
}
|
|
2466
2465
|
finally { if (e_39) throw e_39.error; }
|
|
2467
2466
|
}
|
|
@@ -2558,6 +2557,8 @@ var FieldRefImplementation = /** @class */ (function () {
|
|
|
2558
2557
|
val = _c.sent();
|
|
2559
2558
|
if (val)
|
|
2560
2559
|
this.container[this.metadata.key] = val;
|
|
2560
|
+
else
|
|
2561
|
+
return [2 /*return*/, null];
|
|
2561
2562
|
_c.label = 4;
|
|
2562
2563
|
case 4: return [3 /*break*/, 9];
|
|
2563
2564
|
case 5:
|
|
@@ -2679,50 +2680,80 @@ var FieldRefImplementation = /** @class */ (function () {
|
|
|
2679
2680
|
};
|
|
2680
2681
|
FieldRefImplementation.prototype.__performValidation = function () {
|
|
2681
2682
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
2682
|
-
var
|
|
2683
|
-
var e_41,
|
|
2684
|
-
|
|
2685
|
-
|
|
2683
|
+
var processValidation, self_1, event_1, _a, _b, v, _c, e_41_1, _d, error_1;
|
|
2684
|
+
var e_41, _e;
|
|
2685
|
+
var _this = this;
|
|
2686
|
+
return tslib_1.__generator(this, function (_f) {
|
|
2687
|
+
switch (_f.label) {
|
|
2686
2688
|
case 0:
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
+
_f.trys.push([0, 12, , 13]);
|
|
2690
|
+
processValidation = function (result) {
|
|
2691
|
+
if (result !== true && result !== undefined && !_this.error) {
|
|
2692
|
+
if (typeof result === 'string' && result.length > 0)
|
|
2693
|
+
_this.error = result;
|
|
2694
|
+
else
|
|
2695
|
+
_this.error = 'invalid value';
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
if (!this.settings.validate) return [3 /*break*/, 11];
|
|
2699
|
+
self_1 = this;
|
|
2700
|
+
event_1 = {
|
|
2701
|
+
entityRef: this.entityRef,
|
|
2702
|
+
get error() {
|
|
2703
|
+
return self_1.error;
|
|
2704
|
+
},
|
|
2705
|
+
set error(value) {
|
|
2706
|
+
self_1.error = value;
|
|
2707
|
+
},
|
|
2708
|
+
isNew: self_1.rowBase.isNewRow,
|
|
2709
|
+
load: function () { return self_1.load(); },
|
|
2710
|
+
metadata: self_1.metadata,
|
|
2711
|
+
originalValue: self_1.originalValue,
|
|
2712
|
+
value: self_1.value,
|
|
2713
|
+
valueChanged: function () { return self_1.valueChanged(); },
|
|
2714
|
+
originalValueIsNull: function () { return self_1.originalValueIsNull(); },
|
|
2715
|
+
valueIsNull: function () { return self_1.valueIsNull(); },
|
|
2716
|
+
isBackend: function () { var _a, _b, _c; return !((_c = (_b = (_a = self_1.rowBase) === null || _a === void 0 ? void 0 : _a.remult) === null || _b === void 0 ? void 0 : _b.dataProvider) === null || _c === void 0 ? void 0 : _c.isProxy); },
|
|
2717
|
+
};
|
|
2689
2718
|
if (!Array.isArray(this.settings.validate)) return [3 /*break*/, 9];
|
|
2690
|
-
|
|
2719
|
+
_f.label = 1;
|
|
2691
2720
|
case 1:
|
|
2692
|
-
|
|
2721
|
+
_f.trys.push([1, 6, 7, 8]);
|
|
2693
2722
|
_a = tslib_1.__values(this.settings.validate), _b = _a.next();
|
|
2694
|
-
|
|
2723
|
+
_f.label = 2;
|
|
2695
2724
|
case 2:
|
|
2696
2725
|
if (!!_b.done) return [3 /*break*/, 5];
|
|
2697
2726
|
v = _b.value;
|
|
2698
|
-
|
|
2727
|
+
_c = processValidation;
|
|
2728
|
+
return [4 /*yield*/, v(this.container, event_1)];
|
|
2699
2729
|
case 3:
|
|
2700
|
-
|
|
2701
|
-
|
|
2730
|
+
_c.apply(void 0, [_f.sent()]);
|
|
2731
|
+
_f.label = 4;
|
|
2702
2732
|
case 4:
|
|
2703
2733
|
_b = _a.next();
|
|
2704
2734
|
return [3 /*break*/, 2];
|
|
2705
2735
|
case 5: return [3 /*break*/, 8];
|
|
2706
2736
|
case 6:
|
|
2707
|
-
e_41_1 =
|
|
2737
|
+
e_41_1 = _f.sent();
|
|
2708
2738
|
e_41 = { error: e_41_1 };
|
|
2709
2739
|
return [3 /*break*/, 8];
|
|
2710
2740
|
case 7:
|
|
2711
2741
|
try {
|
|
2712
|
-
if (_b && !_b.done && (
|
|
2742
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
2713
2743
|
}
|
|
2714
2744
|
finally { if (e_41) throw e_41.error; }
|
|
2715
2745
|
return [7 /*endfinally*/];
|
|
2716
2746
|
case 8: return [3 /*break*/, 11];
|
|
2717
2747
|
case 9:
|
|
2718
2748
|
if (!(typeof this.settings.validate === 'function')) return [3 /*break*/, 11];
|
|
2719
|
-
|
|
2749
|
+
_d = processValidation;
|
|
2750
|
+
return [4 /*yield*/, this.settings.validate(this.container, event_1)];
|
|
2720
2751
|
case 10:
|
|
2721
|
-
_d.sent();
|
|
2722
|
-
|
|
2752
|
+
_d.apply(void 0, [_f.sent()]);
|
|
2753
|
+
_f.label = 11;
|
|
2723
2754
|
case 11: return [3 /*break*/, 13];
|
|
2724
2755
|
case 12:
|
|
2725
|
-
error_1 =
|
|
2756
|
+
error_1 = _f.sent();
|
|
2726
2757
|
if (typeof error_1 === 'string')
|
|
2727
2758
|
this.error = error_1;
|
|
2728
2759
|
else
|
|
@@ -2798,12 +2829,39 @@ function buildCaption(caption, key, remult, metaData) {
|
|
|
2798
2829
|
exports.buildCaption = buildCaption;
|
|
2799
2830
|
var columnDefsImpl = /** @class */ (function () {
|
|
2800
2831
|
function columnDefsImpl(settings, entityDefs, remult) {
|
|
2832
|
+
var _this = this;
|
|
2801
2833
|
this.settings = settings;
|
|
2802
2834
|
this.entityDefs = entityDefs;
|
|
2803
2835
|
this.remult = remult;
|
|
2804
2836
|
this.options = this.settings;
|
|
2805
2837
|
this.target = this.settings.target;
|
|
2806
|
-
this.valueConverter = this.settings.valueConverter
|
|
2838
|
+
this.valueConverter = new Proxy(this.settings.valueConverter, {
|
|
2839
|
+
get: function (target, prop) {
|
|
2840
|
+
var result = target[prop];
|
|
2841
|
+
if (typeof result === 'function') {
|
|
2842
|
+
return function () {
|
|
2843
|
+
var _a;
|
|
2844
|
+
var args = [];
|
|
2845
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2846
|
+
args[_i] = arguments[_i];
|
|
2847
|
+
}
|
|
2848
|
+
try {
|
|
2849
|
+
return target[prop].apply(target, tslib_1.__spreadArray([], tslib_1.__read(args), false));
|
|
2850
|
+
}
|
|
2851
|
+
catch (err) {
|
|
2852
|
+
var error = "".concat(String(prop), " failed for value ").concat(args === null || args === void 0 ? void 0 : args[0], ". Error: ").concat(typeof err === 'string' ? err : err.message);
|
|
2853
|
+
throw {
|
|
2854
|
+
message: _this.caption + ': ' + error,
|
|
2855
|
+
modelState: (_a = {},
|
|
2856
|
+
_a[_this.key] = error,
|
|
2857
|
+
_a),
|
|
2858
|
+
};
|
|
2859
|
+
}
|
|
2860
|
+
};
|
|
2861
|
+
}
|
|
2862
|
+
return result;
|
|
2863
|
+
},
|
|
2864
|
+
});
|
|
2807
2865
|
this.allowNull = !!this.settings.allowNull;
|
|
2808
2866
|
this.valueType = this.settings.valueType;
|
|
2809
2867
|
this.key = this.settings.key;
|
|
@@ -2861,11 +2919,11 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2861
2919
|
function EntityFullInfo(columnsInfo, entityInfo, remult, entityType, key) {
|
|
2862
2920
|
var _a, e_42, _b;
|
|
2863
2921
|
var _this = this;
|
|
2864
|
-
this.columnsInfo = columnsInfo;
|
|
2865
2922
|
this.entityInfo = entityInfo;
|
|
2866
2923
|
this.remult = remult;
|
|
2867
2924
|
this.entityType = entityType;
|
|
2868
2925
|
this.key = key;
|
|
2926
|
+
this.fieldsMetadata = [];
|
|
2869
2927
|
this.idMetadata = {
|
|
2870
2928
|
getId: function (item) {
|
|
2871
2929
|
if (item === undefined || item === null)
|
|
@@ -2934,25 +2992,25 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
2934
2992
|
this.key = entityType.name;
|
|
2935
2993
|
if (!entityInfo.dbName)
|
|
2936
2994
|
entityInfo.dbName = this.key;
|
|
2937
|
-
|
|
2995
|
+
this.dbName = entityInfo.dbName;
|
|
2938
2996
|
var r = (_a = {
|
|
2939
2997
|
find: function (c) {
|
|
2940
2998
|
return r[typeof c === 'string' ? c : c.key];
|
|
2941
2999
|
}
|
|
2942
3000
|
},
|
|
2943
|
-
_a[Symbol.iterator] = function () { return
|
|
2944
|
-
_a.toArray = function () { return
|
|
3001
|
+
_a[Symbol.iterator] = function () { return _this.fieldsMetadata[Symbol.iterator](); },
|
|
3002
|
+
_a.toArray = function () { return _this.fieldsMetadata; },
|
|
2945
3003
|
_a);
|
|
2946
3004
|
try {
|
|
2947
|
-
for (var
|
|
2948
|
-
var x =
|
|
2949
|
-
|
|
3005
|
+
for (var columnsInfo_2 = tslib_1.__values(columnsInfo), columnsInfo_2_1 = columnsInfo_2.next(); !columnsInfo_2_1.done; columnsInfo_2_1 = columnsInfo_2.next()) {
|
|
3006
|
+
var x = columnsInfo_2_1.value;
|
|
3007
|
+
this.fieldsMetadata.push((r[x.key] = new columnDefsImpl(x, this, remult)));
|
|
2950
3008
|
}
|
|
2951
3009
|
}
|
|
2952
3010
|
catch (e_42_1) { e_42 = { error: e_42_1 }; }
|
|
2953
3011
|
finally {
|
|
2954
3012
|
try {
|
|
2955
|
-
if (
|
|
3013
|
+
if (columnsInfo_2_1 && !columnsInfo_2_1.done && (_b = columnsInfo_2.return)) _b.call(columnsInfo_2);
|
|
2956
3014
|
}
|
|
2957
3015
|
finally { if (e_42) throw e_42.error; }
|
|
2958
3016
|
}
|
|
@@ -3029,7 +3087,7 @@ function FieldType() {
|
|
|
3029
3087
|
options = [];
|
|
3030
3088
|
}
|
|
3031
3089
|
options.splice(0, 0, { valueType: target });
|
|
3032
|
-
|
|
3090
|
+
target[exports.storableMember] = options;
|
|
3033
3091
|
return target;
|
|
3034
3092
|
};
|
|
3035
3093
|
}
|
|
@@ -3077,7 +3135,7 @@ var ValueListInfo = /** @class */ (function () {
|
|
|
3077
3135
|
if (this.isNumeric) {
|
|
3078
3136
|
this.fieldTypeInDb = 'integer';
|
|
3079
3137
|
}
|
|
3080
|
-
var options =
|
|
3138
|
+
var options = this.valueListType[exports.storableMember];
|
|
3081
3139
|
if (options) {
|
|
3082
3140
|
try {
|
|
3083
3141
|
for (var options_1 = tslib_1.__values(options), options_1_1 = options_1.next(); !options_1_1.done; options_1_1 = options_1.next()) {
|
|
@@ -3167,7 +3225,7 @@ function getValueList(type) {
|
|
|
3167
3225
|
return ValueListInfo.get(type).getValues();
|
|
3168
3226
|
}
|
|
3169
3227
|
exports.getValueList = getValueList;
|
|
3170
|
-
exports.storableMember = Symbol('storableMember');
|
|
3228
|
+
exports.storableMember = Symbol.for('storableMember');
|
|
3171
3229
|
function buildOptions(options, remult) {
|
|
3172
3230
|
var e_44, _a;
|
|
3173
3231
|
var r = {};
|
|
@@ -3194,7 +3252,7 @@ function buildOptions(options, remult) {
|
|
|
3194
3252
|
exports.buildOptions = buildOptions;
|
|
3195
3253
|
function decorateColumnSettings(settings, remult) {
|
|
3196
3254
|
if (settings.valueType) {
|
|
3197
|
-
var settingsOnTypeLevel =
|
|
3255
|
+
var settingsOnTypeLevel = settings.valueType[exports.storableMember];
|
|
3198
3256
|
if (settingsOnTypeLevel) {
|
|
3199
3257
|
settings = tslib_1.__assign(tslib_1.__assign({}, buildOptions(settingsOnTypeLevel, remult)), settings);
|
|
3200
3258
|
}
|
package/src/remult3/entity.js
CHANGED
|
@@ -79,8 +79,8 @@ function Entity(key) {
|
|
|
79
79
|
};
|
|
80
80
|
context_js_1.allEntities.push(target);
|
|
81
81
|
(0, context_js_1.setControllerSettings)(target, { key: key });
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
target[getEntityRef_js_1.entityInfo] = factory;
|
|
83
|
+
target[getEntityRef_js_1.entityInfo_key] = key;
|
|
84
84
|
return target;
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -12,9 +12,9 @@ function getEntityRef(entity, throwException) {
|
|
|
12
12
|
return x;
|
|
13
13
|
}
|
|
14
14
|
exports.getEntityRef = getEntityRef;
|
|
15
|
-
exports.entityMember = Symbol('entityMember');
|
|
16
|
-
exports.entityInfo = Symbol('entityInfo');
|
|
17
|
-
exports.entityInfo_key = Symbol('entityInfo_key');
|
|
15
|
+
exports.entityMember = Symbol.for('entityMember');
|
|
16
|
+
exports.entityInfo = Symbol.for('entityInfo');
|
|
17
|
+
exports.entityInfo_key = Symbol.for('entityInfo_key');
|
|
18
18
|
function getEntitySettings(entity, throwError) {
|
|
19
19
|
if (throwError === void 0) { throwError = true; }
|
|
20
20
|
if (entity === undefined)
|
|
@@ -23,7 +23,7 @@ function getEntitySettings(entity, throwError) {
|
|
|
23
23
|
}
|
|
24
24
|
else
|
|
25
25
|
return undefined;
|
|
26
|
-
var info =
|
|
26
|
+
var info = entity[exports.entityInfo];
|
|
27
27
|
if (!info && throwError)
|
|
28
28
|
throw new Error(entity.prototype.constructor.name +
|
|
29
29
|
" is not a known entity, did you forget to set @Entity() or did you forget to add the '@' before the call to Entity?");
|
|
@@ -31,6 +31,6 @@ function getEntitySettings(entity, throwError) {
|
|
|
31
31
|
}
|
|
32
32
|
exports.getEntitySettings = getEntitySettings;
|
|
33
33
|
function getEntityKey(entity) {
|
|
34
|
-
return
|
|
34
|
+
return entity[exports.entityInfo_key];
|
|
35
35
|
}
|
|
36
36
|
exports.getEntityKey = getEntityKey;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRelationInfo = exports.relationInfoMember = void 0;
|
|
4
|
-
exports.relationInfoMember = Symbol('relationInfo');
|
|
4
|
+
exports.relationInfoMember = Symbol.for('relationInfo');
|
|
5
5
|
function getRelationInfo(options) {
|
|
6
6
|
return options === null || options === void 0 ? void 0 : options[exports.relationInfoMember];
|
|
7
7
|
}
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -36,6 +36,19 @@ export interface EntityRefForEntityBase<entityType> extends EntityRefBase<entity
|
|
|
36
36
|
fields: FieldsRefForEntityBase<entityType>;
|
|
37
37
|
relations: RepositoryRelationsForEntityBase<entityType>;
|
|
38
38
|
}
|
|
39
|
+
export interface ValidateFieldEvent<entityType = any, valueType = any> {
|
|
40
|
+
error: string;
|
|
41
|
+
value: valueType;
|
|
42
|
+
originalValue: valueType;
|
|
43
|
+
valueChanged(): boolean;
|
|
44
|
+
entityRef: EntityRef<entityType>;
|
|
45
|
+
metadata: FieldMetadata<valueType>;
|
|
46
|
+
load(): Promise<valueType>;
|
|
47
|
+
valueIsNull(): boolean;
|
|
48
|
+
originalValueIsNull(): boolean;
|
|
49
|
+
isBackend(): boolean;
|
|
50
|
+
isNew: boolean;
|
|
51
|
+
}
|
|
39
52
|
/**
|
|
40
53
|
* Represents a lifecycle event associated with an entity instance. These events
|
|
41
54
|
* are triggered during various stages of the entity's lifecycle, such as validation,
|
|
@@ -588,6 +601,26 @@ export interface ClassDecoratorContextStub<Class extends new (...args: any) => a
|
|
|
588
601
|
addInitializer(initializer: (this: Class) => void): void;
|
|
589
602
|
}
|
|
590
603
|
export type ClassFieldDecorator<entityType, valueType> = (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
|
|
604
|
+
/**
|
|
605
|
+
* //p2 - doc this
|
|
606
|
+
remult.apiClient.httpClient = (
|
|
607
|
+
input: RequestInfo | URL,
|
|
608
|
+
init?: RequestInit
|
|
609
|
+
) => {
|
|
610
|
+
return fetch(input, {
|
|
611
|
+
...init,
|
|
612
|
+
headers: {
|
|
613
|
+
authorization: 'Bearer ' + sessionStorage.sessionId,
|
|
614
|
+
},
|
|
615
|
+
cache: 'no-store',
|
|
616
|
+
})
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
&&
|
|
620
|
+
remult.apiClient.url='localhost:3007/api
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
*/
|
|
591
624
|
/**
|
|
592
625
|
* our default is allow null false.
|
|
593
626
|
* for sql databases we add a db default of 0/''/false
|