remult 0.13.20 → 0.13.21
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 +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +5 -4
- package/src/remult3/RepositoryImplementation.js +36 -28
- package/src/remult3/remult3.d.ts +16 -11
- package/src/shared-tests/entityWithValidations.js +5 -19
- package/src/tests/TestDataApiResponse.js +6 -6
- package/src/tests/d.d.ts +0 -1
- package/src/tests/d.js +0 -16
- package/src/tests/testModel/models.d.ts +0 -1
- package/src/tests/testModel/models.js +0 -3
package/package.json
CHANGED
|
@@ -26,17 +26,17 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
26
26
|
query(options?: QueryOptions<entityType>): QueryResult<entityType>;
|
|
27
27
|
getEntityRef(entity: entityType): EntityRef<entityType>;
|
|
28
28
|
delete(id: (entityType extends {
|
|
29
|
-
id
|
|
29
|
+
id?: number;
|
|
30
30
|
} ? number : entityType extends {
|
|
31
|
-
id
|
|
31
|
+
id?: string;
|
|
32
32
|
} ? string : (string | number))): Promise<void>;
|
|
33
33
|
delete(item: entityType): Promise<void>;
|
|
34
34
|
insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
35
35
|
insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
36
36
|
update(id: (entityType extends {
|
|
37
|
-
id
|
|
37
|
+
id?: number;
|
|
38
38
|
} ? number : entityType extends {
|
|
39
|
-
id
|
|
39
|
+
id?: string;
|
|
40
40
|
} ? string : (string | number)), entity: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
41
41
|
private getRefForExistingRow;
|
|
42
42
|
save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
@@ -157,6 +157,7 @@ export declare class FieldRefImplementation<entityType, valueType> implements Fi
|
|
|
157
157
|
get originalValue(): any;
|
|
158
158
|
private rawOriginalValue;
|
|
159
159
|
setId(id: (string | number)): void;
|
|
160
|
+
getId(): any;
|
|
160
161
|
get inputValue(): string;
|
|
161
162
|
set inputValue(val: string);
|
|
162
163
|
valueChanged(): boolean;
|
|
@@ -200,49 +200,50 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
200
200
|
};
|
|
201
201
|
RepositoryImplementation.prototype.insert = function (entity) {
|
|
202
202
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
203
|
-
var entity_1, entity_1_1, item, e_4_1, ref;
|
|
204
|
-
var e_4,
|
|
205
|
-
return tslib_1.__generator(this, function (
|
|
206
|
-
switch (
|
|
203
|
+
var r, entity_1, entity_1_1, item, _a, _b, e_4_1, ref;
|
|
204
|
+
var e_4, _c;
|
|
205
|
+
return tslib_1.__generator(this, function (_d) {
|
|
206
|
+
switch (_d.label) {
|
|
207
207
|
case 0:
|
|
208
208
|
if (!Array.isArray(entity)) return [3 /*break*/, 9];
|
|
209
|
-
|
|
209
|
+
r = [];
|
|
210
|
+
_d.label = 1;
|
|
210
211
|
case 1:
|
|
211
|
-
|
|
212
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
212
213
|
entity_1 = tslib_1.__values(entity), entity_1_1 = entity_1.next();
|
|
213
|
-
|
|
214
|
+
_d.label = 2;
|
|
214
215
|
case 2:
|
|
215
216
|
if (!!entity_1_1.done) return [3 /*break*/, 5];
|
|
216
217
|
item = entity_1_1.value;
|
|
218
|
+
_b = (_a = r).push;
|
|
217
219
|
return [4 /*yield*/, this.insert(item)];
|
|
218
220
|
case 3:
|
|
219
|
-
_b.sent();
|
|
220
|
-
|
|
221
|
+
_b.apply(_a, [_d.sent()]);
|
|
222
|
+
_d.label = 4;
|
|
221
223
|
case 4:
|
|
222
224
|
entity_1_1 = entity_1.next();
|
|
223
225
|
return [3 /*break*/, 2];
|
|
224
226
|
case 5: return [3 /*break*/, 8];
|
|
225
227
|
case 6:
|
|
226
|
-
e_4_1 =
|
|
228
|
+
e_4_1 = _d.sent();
|
|
227
229
|
e_4 = { error: e_4_1 };
|
|
228
230
|
return [3 /*break*/, 8];
|
|
229
231
|
case 7:
|
|
230
232
|
try {
|
|
231
|
-
if (entity_1_1 && !entity_1_1.done && (
|
|
233
|
+
if (entity_1_1 && !entity_1_1.done && (_c = entity_1.return)) _c.call(entity_1);
|
|
232
234
|
}
|
|
233
235
|
finally { if (e_4) throw e_4.error; }
|
|
234
236
|
return [7 /*endfinally*/];
|
|
235
|
-
case 8: return [
|
|
237
|
+
case 8: return [2 /*return*/, r];
|
|
236
238
|
case 9:
|
|
237
239
|
ref = getEntityRef(entity, false);
|
|
238
240
|
if (!ref) return [3 /*break*/, 11];
|
|
239
241
|
if (!ref.isNew())
|
|
240
242
|
throw "Item is not new";
|
|
241
243
|
return [4 /*yield*/, ref.save()];
|
|
242
|
-
case 10: return [2 /*return*/,
|
|
244
|
+
case 10: return [2 /*return*/, _d.sent()];
|
|
243
245
|
case 11: return [4 /*yield*/, this.getEntityRef(this.create(entity)).save()];
|
|
244
|
-
case 12: return [2 /*return*/,
|
|
245
|
-
case 13: return [2 /*return*/];
|
|
246
|
+
case 12: return [2 /*return*/, _d.sent()];
|
|
246
247
|
}
|
|
247
248
|
});
|
|
248
249
|
});
|
|
@@ -298,7 +299,7 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
298
299
|
switch (_a.label) {
|
|
299
300
|
case 0:
|
|
300
301
|
if (!Array.isArray(entity)) return [3 /*break*/, 1];
|
|
301
|
-
return [2 /*return*/, Promise.all(entity.map(function (x) { return _this.
|
|
302
|
+
return [2 /*return*/, Promise.all(entity.map(function (x) { return _this.save(x); }))];
|
|
302
303
|
case 1:
|
|
303
304
|
ref = getEntityRef(entity, false);
|
|
304
305
|
if (!ref) return [3 /*break*/, 3];
|
|
@@ -649,23 +650,24 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
649
650
|
exports.RepositoryImplementation = RepositoryImplementation;
|
|
650
651
|
function __updateEntityBasedOnWhere(entityDefs, where, r) {
|
|
651
652
|
var w = filter_interfaces_1.Filter.fromEntityFilter(entityDefs, where);
|
|
653
|
+
var emptyFunction = function () { };
|
|
652
654
|
if (w) {
|
|
653
655
|
w.__applyToConsumer({
|
|
654
|
-
custom:
|
|
655
|
-
databaseCustom:
|
|
656
|
-
containsCaseInsensitive:
|
|
657
|
-
isDifferentFrom:
|
|
656
|
+
custom: emptyFunction,
|
|
657
|
+
databaseCustom: emptyFunction,
|
|
658
|
+
containsCaseInsensitive: emptyFunction,
|
|
659
|
+
isDifferentFrom: emptyFunction,
|
|
658
660
|
isEqualTo: function (col, val) {
|
|
659
661
|
r[col.key] = val;
|
|
660
662
|
},
|
|
661
|
-
isGreaterOrEqualTo:
|
|
662
|
-
isGreaterThan:
|
|
663
|
-
isIn:
|
|
664
|
-
isLessOrEqualTo:
|
|
665
|
-
isLessThan:
|
|
666
|
-
isNotNull:
|
|
667
|
-
isNull:
|
|
668
|
-
or:
|
|
663
|
+
isGreaterOrEqualTo: emptyFunction,
|
|
664
|
+
isGreaterThan: emptyFunction,
|
|
665
|
+
isIn: emptyFunction,
|
|
666
|
+
isLessOrEqualTo: emptyFunction,
|
|
667
|
+
isLessThan: emptyFunction,
|
|
668
|
+
isNotNull: emptyFunction,
|
|
669
|
+
isNull: emptyFunction,
|
|
670
|
+
or: emptyFunction
|
|
669
671
|
});
|
|
670
672
|
}
|
|
671
673
|
}
|
|
@@ -1895,6 +1897,12 @@ var FieldRefImplementation = /** @class */ (function () {
|
|
|
1895
1897
|
FieldRefImplementation.prototype.setId = function (id) {
|
|
1896
1898
|
this.value = id;
|
|
1897
1899
|
};
|
|
1900
|
+
FieldRefImplementation.prototype.getId = function () {
|
|
1901
|
+
var lu = this.rowBase.lookups.get(this.metadata.key);
|
|
1902
|
+
if (lu)
|
|
1903
|
+
return lu.id != undefined ? lu.id : null;
|
|
1904
|
+
return this.value;
|
|
1905
|
+
};
|
|
1898
1906
|
Object.defineProperty(FieldRefImplementation.prototype, "inputValue", {
|
|
1899
1907
|
get: function () {
|
|
1900
1908
|
this.reportObserved();
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface Subscribable {
|
|
|
42
42
|
}
|
|
43
43
|
export declare type FieldsRef<entityType> = {
|
|
44
44
|
[Properties in keyof OmitEB<entityType>]: entityType[Properties] extends {
|
|
45
|
-
id
|
|
45
|
+
id?: (number | string);
|
|
46
46
|
} ? IdFieldRef<entityType, entityType[Properties]> : FieldRef<entityType, entityType[Properties]>;
|
|
47
47
|
} & {
|
|
48
48
|
find(fieldMetadataOrKey: FieldMetadata | string): FieldRef<entityType, any>;
|
|
@@ -63,10 +63,15 @@ export declare type SortSegments<entityType> = {
|
|
|
63
63
|
};
|
|
64
64
|
export interface IdFieldRef<entityType, valueType> extends FieldRef<entityType, valueType> {
|
|
65
65
|
setId(id: valueType extends {
|
|
66
|
-
id
|
|
66
|
+
id?: number;
|
|
67
67
|
} ? number : valueType extends {
|
|
68
|
-
id
|
|
68
|
+
id?: string;
|
|
69
69
|
} ? string : (string | number)): any;
|
|
70
|
+
getId(): (valueType extends {
|
|
71
|
+
id?: number;
|
|
72
|
+
} ? number : valueType extends {
|
|
73
|
+
id?: string;
|
|
74
|
+
} ? string : (string | number));
|
|
70
75
|
}
|
|
71
76
|
export interface FieldRef<entityType = any, valueType = any> extends Subscribable {
|
|
72
77
|
error: string;
|
|
@@ -111,9 +116,9 @@ export interface Repository<entityType> {
|
|
|
111
116
|
findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>): Promise<entityType>;
|
|
112
117
|
/** returns the items that matches the idm the result is cached unless specified differently in the `options` parameter */
|
|
113
118
|
findId(id: entityType extends {
|
|
114
|
-
id
|
|
119
|
+
id?: number;
|
|
115
120
|
} ? number : entityType extends {
|
|
116
|
-
id
|
|
121
|
+
id?: string;
|
|
117
122
|
} ? string : (string | number), options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
|
|
118
123
|
/** An alternative form of fetching data from the API server, which is intended for operating on large numbers of entity objects.
|
|
119
124
|
*
|
|
@@ -152,15 +157,15 @@ export interface Repository<entityType> {
|
|
|
152
157
|
* taskRepo.update(task.id,{...task,completed:true})
|
|
153
158
|
*/
|
|
154
159
|
update(id: (entityType extends {
|
|
155
|
-
id
|
|
160
|
+
id?: number;
|
|
156
161
|
} ? number : entityType extends {
|
|
157
|
-
id
|
|
162
|
+
id?: string;
|
|
158
163
|
} ? string : (string | number)), item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
159
164
|
/** Deletes an Item*/
|
|
160
165
|
delete(id: (entityType extends {
|
|
161
|
-
id
|
|
166
|
+
id?: number;
|
|
162
167
|
} ? number : entityType extends {
|
|
163
|
-
id
|
|
168
|
+
id?: string;
|
|
164
169
|
} ? string : (string | number))): Promise<void>;
|
|
165
170
|
delete(item: entityType): Promise<void>;
|
|
166
171
|
/** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
|
|
@@ -205,7 +210,7 @@ export declare type EntityOrderBy<entityType> = {
|
|
|
205
210
|
*/
|
|
206
211
|
export declare type EntityFilter<entityType> = {
|
|
207
212
|
[Properties in keyof Partial<OmitEB<entityType>>]?: (Partial<OmitEB<entityType>>[Properties] extends (number | Date | undefined) ? ComparisonValueFilter<Partial<OmitEB<entityType>>[Properties]> : Partial<OmitEB<entityType>>[Properties] extends (string | undefined) ? ContainsStringValueFilter & ComparisonValueFilter<string> : Partial<OmitEB<entityType>>[Properties] extends (boolean | undefined) ? ValueFilter<boolean> : Partial<OmitEB<entityType>>[Properties] extends ({
|
|
208
|
-
id
|
|
213
|
+
id?: (string | number);
|
|
209
214
|
} | undefined) ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>) & ContainsStringValueFilter;
|
|
210
215
|
} & {
|
|
211
216
|
$or?: EntityFilter<entityType>[];
|
|
@@ -230,7 +235,7 @@ export interface ContainsStringValueFilter {
|
|
|
230
235
|
}
|
|
231
236
|
export declare type IdFilter<valueType> = ValueFilter<valueType> | {
|
|
232
237
|
$id: ValueFilter<valueType extends {
|
|
233
|
-
id
|
|
238
|
+
id?: number;
|
|
234
239
|
} ? number : string>;
|
|
235
240
|
};
|
|
236
241
|
export interface LoadOptions<entityType> {
|
|
@@ -64,26 +64,12 @@ var entityWithValidations = /** @class */ (function (_super) {
|
|
|
64
64
|
remult3_1.Entity('', {
|
|
65
65
|
allowApiCrud: true,
|
|
66
66
|
saving: function (t) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
67
|
-
var e;
|
|
68
67
|
return tslib_1.__generator(this, function (_a) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return [4 /*yield*/, t.remult.repo(entityWithValidations_1).find({
|
|
75
|
-
orderBy: { myId: "desc" },
|
|
76
|
-
limit: 1
|
|
77
|
-
})];
|
|
78
|
-
case 1:
|
|
79
|
-
e = _a.sent();
|
|
80
|
-
t.myId = e.length ? e[0].myId + 1 : 1;
|
|
81
|
-
_a.label = 2;
|
|
82
|
-
case 2:
|
|
83
|
-
if (!exports.testConfiguration.restDbRunningOnServer)
|
|
84
|
-
entityWithValidations_1.savingRowCount++;
|
|
85
|
-
return [2 /*return*/];
|
|
86
|
-
}
|
|
68
|
+
if (!t.name || t.name.length < 3)
|
|
69
|
+
t._.fields.name.error = 'invalid';
|
|
70
|
+
if (!exports.testConfiguration.restDbRunningOnServer)
|
|
71
|
+
entityWithValidations_1.savingRowCount++;
|
|
72
|
+
return [2 /*return*/];
|
|
87
73
|
});
|
|
88
74
|
}); }
|
|
89
75
|
}),
|
|
@@ -7,22 +7,22 @@ var TestDataApiResponse = /** @class */ (function () {
|
|
|
7
7
|
TestDataApiResponse.prototype.progress = function (progress) {
|
|
8
8
|
};
|
|
9
9
|
TestDataApiResponse.prototype.success = function (data) {
|
|
10
|
-
|
|
10
|
+
throw new Error(('didnt expect success: ' + JSON.stringify(data)));
|
|
11
11
|
};
|
|
12
12
|
TestDataApiResponse.prototype.forbidden = function () {
|
|
13
|
-
|
|
13
|
+
throw new Error('didnt expect forbidden:');
|
|
14
14
|
};
|
|
15
15
|
TestDataApiResponse.prototype.created = function (data) {
|
|
16
|
-
|
|
16
|
+
throw new Error('didnt expect created: ' + JSON.stringify(data));
|
|
17
17
|
};
|
|
18
18
|
TestDataApiResponse.prototype.deleted = function () {
|
|
19
|
-
|
|
19
|
+
throw new Error('didnt expect deleted:');
|
|
20
20
|
};
|
|
21
21
|
TestDataApiResponse.prototype.notFound = function () {
|
|
22
|
-
|
|
22
|
+
throw new Error('not found');
|
|
23
23
|
};
|
|
24
24
|
TestDataApiResponse.prototype.error = function (data) {
|
|
25
|
-
|
|
25
|
+
throw new Error('error: ' + data + " " + JSON.stringify(data));
|
|
26
26
|
};
|
|
27
27
|
return TestDataApiResponse;
|
|
28
28
|
}());
|
package/src/tests/d.d.ts
CHANGED
package/src/tests/d.js
CHANGED
|
@@ -2,22 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.d = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var server_action_1 = require("../server-action");
|
|
6
5
|
var remult3_1 = require("../remult3");
|
|
7
|
-
var dWithPrefilter_1 = require("./dWithPrefilter");
|
|
8
6
|
var d = /** @class */ (function (_super) {
|
|
9
7
|
tslib_1.__extends(d, _super);
|
|
10
8
|
function d() {
|
|
11
9
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
12
10
|
}
|
|
13
|
-
d.prototype.doIt = function () {
|
|
14
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
15
|
-
return tslib_1.__generator(this, function (_a) {
|
|
16
|
-
dWithPrefilter_1.dWithPrefilter.count++;
|
|
17
|
-
return [2 /*return*/, true];
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
11
|
d.count = 0;
|
|
22
12
|
tslib_1.__decorate([
|
|
23
13
|
remult3_1.Fields.integer(),
|
|
@@ -27,12 +17,6 @@ var d = /** @class */ (function (_super) {
|
|
|
27
17
|
remult3_1.Fields.integer(),
|
|
28
18
|
tslib_1.__metadata("design:type", Number)
|
|
29
19
|
], d.prototype, "b", void 0);
|
|
30
|
-
tslib_1.__decorate([
|
|
31
|
-
server_action_1.BackendMethod({ allowed: true }),
|
|
32
|
-
tslib_1.__metadata("design:type", Function),
|
|
33
|
-
tslib_1.__metadata("design:paramtypes", []),
|
|
34
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
35
|
-
], d.prototype, "doIt", null);
|
|
36
20
|
d = tslib_1.__decorate([
|
|
37
21
|
remult3_1.Entity('d1', {
|
|
38
22
|
allowApiCrud: true
|
|
@@ -9,9 +9,6 @@ var Status = /** @class */ (function () {
|
|
|
9
9
|
this.name = name;
|
|
10
10
|
}
|
|
11
11
|
Status_1 = Status;
|
|
12
|
-
Status.prototype.toString = function () {
|
|
13
|
-
return this.name;
|
|
14
|
-
};
|
|
15
12
|
var Status_1;
|
|
16
13
|
Status.open = new Status_1(0, "open");
|
|
17
14
|
Status.closed = new Status_1(1, "closed");
|