remult 0.18.1 → 0.19.0-exp.2
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/live-query/data-provider-live-query-storage.js +8 -2
- package/esm/src/column-interfaces.d.ts +28 -5
- package/esm/src/column.d.ts +6 -1
- package/esm/src/column.js +12 -0
- package/esm/src/data-api.js +1 -2
- package/esm/src/entity.d.ts +1 -1
- package/esm/src/live-query/SubscriptionChannel.js +3 -4
- package/esm/src/remult-proxy.js +4 -0
- package/esm/src/remult3/RepositoryImplementation.d.ts +16 -6
- package/esm/src/remult3/RepositoryImplementation.js +92 -23
- package/esm/src/remult3/remult3.d.ts +36 -13
- package/esm/src/shared-tests/db-tests.db-tests.js +14 -1
- package/esm/src/valueConverters.d.ts +1 -1
- package/esm/src/valueConverters.js +4 -1
- package/live-query/data-provider-live-query-storage.js +23 -4
- package/package.json +1 -1
- package/src/column-interfaces.d.ts +28 -5
- package/src/column.d.ts +6 -1
- package/src/column.js +12 -0
- package/src/data-api.js +1 -2
- package/src/entity.d.ts +1 -1
- package/src/live-query/SubscriptionChannel.js +3 -4
- package/src/remult-proxy.js +12 -0
- package/src/remult3/RepositoryImplementation.d.ts +16 -6
- package/src/remult3/RepositoryImplementation.js +287 -161
- package/src/remult3/remult3.d.ts +36 -13
- package/src/shared-tests/db-tests.db-tests.js +35 -1
- package/src/valueConverters.d.ts +1 -1
- package/src/valueConverters.js +4 -1
|
@@ -14,17 +14,20 @@ var DataProviderLiveQueryStorage = /** @class */ (function () {
|
|
|
14
14
|
}
|
|
15
15
|
DataProviderLiveQueryStorage.prototype.ensureSchema = function () {
|
|
16
16
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
17
|
-
var _a, _b;
|
|
17
|
+
var dp, _a, _b;
|
|
18
18
|
return tslib_1.__generator(this, function (_c) {
|
|
19
19
|
switch (_c.label) {
|
|
20
20
|
case 0: return [4 /*yield*/, this.dataProvider];
|
|
21
21
|
case 1:
|
|
22
|
-
|
|
22
|
+
dp = _c.sent();
|
|
23
|
+
if (!dp.ensureSchema) return [3 /*break*/, 4];
|
|
24
|
+
_b = (_a = dp).ensureSchema;
|
|
23
25
|
return [4 /*yield*/, this.repo];
|
|
24
26
|
case 2: return [4 /*yield*/, _b.apply(_a, [[(_c.sent()).metadata]])];
|
|
25
27
|
case 3:
|
|
26
28
|
_c.sent();
|
|
27
|
-
|
|
29
|
+
_c.label = 4;
|
|
30
|
+
case 4: return [2 /*return*/];
|
|
28
31
|
}
|
|
29
32
|
});
|
|
30
33
|
});
|
|
@@ -58,9 +61,25 @@ var DataProviderLiveQueryStorage = /** @class */ (function () {
|
|
|
58
61
|
};
|
|
59
62
|
DataProviderLiveQueryStorage.prototype.remove = function (queryId) {
|
|
60
63
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var _this = this;
|
|
61
65
|
return tslib_1.__generator(this, function (_a) {
|
|
62
66
|
switch (_a.label) {
|
|
63
|
-
case 0: return [4 /*yield*/, this.repo.then(function (repo) { return
|
|
67
|
+
case 0: return [4 /*yield*/, this.repo.then(function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
68
|
+
var r;
|
|
69
|
+
return tslib_1.__generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0: return [4 /*yield*/, repo.findId(queryId)];
|
|
72
|
+
case 1:
|
|
73
|
+
r = _a.sent();
|
|
74
|
+
if (!r) return [3 /*break*/, 3];
|
|
75
|
+
return [4 /*yield*/, repo.delete(r)];
|
|
76
|
+
case 2:
|
|
77
|
+
_a.sent();
|
|
78
|
+
_a.label = 3;
|
|
79
|
+
case 3: return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); }).catch(function () { })];
|
|
64
83
|
case 1:
|
|
65
84
|
_a.sent();
|
|
66
85
|
return [2 /*return*/];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClassType } from '../classType';
|
|
2
2
|
import { Allowed, AllowedForInstance } from './context';
|
|
3
|
-
import { EntityMetadata, FieldRef } from './remult3';
|
|
3
|
+
import { EntityMetadata, FieldRef, OmitEB } from './remult3';
|
|
4
4
|
export interface FieldOptions<entityType = any, valueType = any> {
|
|
5
5
|
/** A human readable name for the field. Can be used to achieve a consistent caption for a field throughout the app
|
|
6
6
|
* @example
|
|
@@ -75,7 +75,7 @@ export interface FieldOptions<entityType = any, valueType = any> {
|
|
|
75
75
|
key?: string;
|
|
76
76
|
}
|
|
77
77
|
/**Metadata for a `Field`, this metadata can be used in the user interface to provide a richer UI experience */
|
|
78
|
-
export interface FieldMetadata<valueType = any> {
|
|
78
|
+
export interface FieldMetadata<valueType = any, entityType = any> {
|
|
79
79
|
/** The field's member name in an object.
|
|
80
80
|
* @example
|
|
81
81
|
* const taskRepo = remult.repo(Task);
|
|
@@ -109,15 +109,38 @@ export interface FieldMetadata<valueType = any> {
|
|
|
109
109
|
/** indicates that this field should only be included in select statement, and excluded from update or insert. useful for db generated ids etc... */
|
|
110
110
|
readonly dbReadOnly: boolean;
|
|
111
111
|
/** the Value converter for this field */
|
|
112
|
-
readonly valueConverter: ValueConverter<valueType
|
|
112
|
+
readonly valueConverter: Required<ValueConverter<valueType>>;
|
|
113
|
+
/** Get the display value for a specific item
|
|
114
|
+
* @example
|
|
115
|
+
* repo.fields.createDate.displayValue(task) //will display the date as defined in the `displayValue` option defined for it.
|
|
116
|
+
*/
|
|
117
|
+
displayValue(item: Partial<OmitEB<entityType>>): string;
|
|
118
|
+
apiUpdateAllowed(item: Partial<OmitEB<entityType>>): boolean;
|
|
119
|
+
readonly includedInApi: boolean;
|
|
120
|
+
/** Adapts the value for usage with html input
|
|
121
|
+
* @example
|
|
122
|
+
* @Fields.dateOnly()
|
|
123
|
+
* birthDate = new Date(1976,5,16)
|
|
124
|
+
* //...
|
|
125
|
+
* input.value = repo.fields.birthDate.toInput(person) // will return '1976-06-16'
|
|
126
|
+
*/
|
|
127
|
+
toInput(value: valueType, inputType?: string): string;
|
|
128
|
+
/** Adapts the value for usage with html input
|
|
129
|
+
* @example
|
|
130
|
+
* @Fields.dateOnly()
|
|
131
|
+
* birthDate = new Date(1976,5,16)
|
|
132
|
+
* //...
|
|
133
|
+
* person.birthDate = repo.fields.birthDate.fromInput(personFormState) // will return Date
|
|
134
|
+
*/
|
|
135
|
+
fromInput(inputValue: string, inputType?: string): valueType;
|
|
113
136
|
}
|
|
114
137
|
export interface ValueConverter<valueType> {
|
|
115
138
|
fromJson?(val: any): valueType;
|
|
116
139
|
toJson?(val: valueType): any;
|
|
117
140
|
fromDb?(val: any): valueType;
|
|
118
141
|
toDb?(val: valueType): any;
|
|
119
|
-
toInput?(val: valueType, inputType
|
|
120
|
-
fromInput?(val: string, inputType
|
|
142
|
+
toInput?(val: valueType, inputType?: string): string;
|
|
143
|
+
fromInput?(val: string, inputType?: string): valueType;
|
|
121
144
|
displayValue?(val: valueType): string;
|
|
122
145
|
readonly fieldTypeInDb?: string;
|
|
123
146
|
readonly inputType?: string;
|
package/src/column.d.ts
CHANGED
|
@@ -6,10 +6,15 @@ export declare function makeTitle(name: string): string;
|
|
|
6
6
|
export declare class CompoundIdField implements FieldMetadata<string> {
|
|
7
7
|
fields: FieldMetadata[];
|
|
8
8
|
constructor(...columns: FieldMetadata[]);
|
|
9
|
+
apiUpdateAllowed(item: any): boolean;
|
|
10
|
+
displayValue(item: any): string;
|
|
11
|
+
includedInApi: boolean;
|
|
12
|
+
toInput(value: string, inputType?: string): string;
|
|
13
|
+
fromInput(inputValue: string, inputType?: string): string;
|
|
9
14
|
getDbName(): Promise<string>;
|
|
10
15
|
getId(instance: any): string;
|
|
11
16
|
options: FieldOptions<any, any>;
|
|
12
|
-
get valueConverter(): ValueConverter<string
|
|
17
|
+
get valueConverter(): Required<ValueConverter<string>>;
|
|
13
18
|
target: ClassType<any>;
|
|
14
19
|
readonly: true;
|
|
15
20
|
allowNull: boolean;
|
package/src/column.js
CHANGED
|
@@ -20,6 +20,18 @@ var CompoundIdField = /** @class */ (function () {
|
|
|
20
20
|
}
|
|
21
21
|
this.fields = columns;
|
|
22
22
|
}
|
|
23
|
+
CompoundIdField.prototype.apiUpdateAllowed = function (item) {
|
|
24
|
+
throw new Error('Method not implemented.');
|
|
25
|
+
};
|
|
26
|
+
CompoundIdField.prototype.displayValue = function (item) {
|
|
27
|
+
throw new Error('Method not implemented.');
|
|
28
|
+
};
|
|
29
|
+
CompoundIdField.prototype.toInput = function (value, inputType) {
|
|
30
|
+
throw new Error('Method not implemented.');
|
|
31
|
+
};
|
|
32
|
+
CompoundIdField.prototype.fromInput = function (inputValue, inputType) {
|
|
33
|
+
throw new Error('Method not implemented.');
|
|
34
|
+
};
|
|
23
35
|
CompoundIdField.prototype.getDbName = function () {
|
|
24
36
|
return Promise.resolve("");
|
|
25
37
|
};
|
package/src/data-api.js
CHANGED
|
@@ -6,7 +6,6 @@ var filter_interfaces_1 = require("./filter/filter-interfaces");
|
|
|
6
6
|
var context_1 = require("./context");
|
|
7
7
|
var filter_interfaces_2 = require("./filter/filter-interfaces");
|
|
8
8
|
var server_action_1 = require("./server-action");
|
|
9
|
-
var getId_1 = require("./remult3/getId");
|
|
10
9
|
var rest_data_provider_1 = require("./data-providers/rest-data-provider");
|
|
11
10
|
var DataApi = /** @class */ (function () {
|
|
12
11
|
function DataApi(repository, remult) {
|
|
@@ -228,7 +227,7 @@ var DataApi = /** @class */ (function () {
|
|
|
228
227
|
data = {
|
|
229
228
|
requestJson: serializeRequest(),
|
|
230
229
|
findOptionsJson: rest_data_provider_1.findOptionsToJson(r.findOptions, this.repository.metadata),
|
|
231
|
-
lastIds: r.r.map(function (y) { return
|
|
230
|
+
lastIds: r.r.map(function (y) { return _this.repository.metadata.idMetadata.getId(y); })
|
|
232
231
|
};
|
|
233
232
|
return [4 /*yield*/, this.remult.liveQueryStorage.add({
|
|
234
233
|
entityKey: this.repository.metadata.key,
|
package/src/entity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Allowed, AllowedForInstance } from "./context";
|
|
2
|
-
import { FieldMetadata
|
|
2
|
+
import { FieldMetadata } from './column-interfaces';
|
|
3
3
|
import { EntityOrderBy, FieldsMetadata, EntityFilter, EntityRef, EntityMetadata } from "./remult3";
|
|
4
4
|
export interface EntityOptions<entityType = any> {
|
|
5
5
|
/**A human readable name for the entity */
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SubscriptionChannel = exports.liveQueryKeepAliveRoute = exports.LiveQuerySubscriber = exports.streamUrl = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var index_1 = require("../../index");
|
|
6
|
-
var getId_1 = require("../remult3/getId");
|
|
7
6
|
var uuid_1 = require("uuid");
|
|
8
7
|
var data_api_1 = require("../data-api");
|
|
9
8
|
exports.streamUrl = 'stream';
|
|
@@ -115,15 +114,15 @@ var LiveQuerySubscriber = /** @class */ (function () {
|
|
|
115
114
|
_this.setAllItems(message.data);
|
|
116
115
|
break;
|
|
117
116
|
case "replace": {
|
|
118
|
-
items = items.map(function (x) { return
|
|
117
|
+
items = items.map(function (x) { return _this.repo.metadata.idMetadata.getId(x) === message.data.oldId ? message.data.item : x; });
|
|
119
118
|
break;
|
|
120
119
|
}
|
|
121
120
|
case "add":
|
|
122
|
-
items = items.filter(function (x) { return
|
|
121
|
+
items = items.filter(function (x) { return _this.repo.metadata.idMetadata.getId(x) !== _this.repo.metadata.idMetadata.getId(message.data.item); });
|
|
123
122
|
items.push(message.data.item);
|
|
124
123
|
break;
|
|
125
124
|
case "remove":
|
|
126
|
-
items = items.filter(function (x) { return
|
|
125
|
+
items = items.filter(function (x) { return _this.repo.metadata.idMetadata.getId(x) !== message.data.id; });
|
|
127
126
|
break;
|
|
128
127
|
}
|
|
129
128
|
;
|
package/src/remult-proxy.js
CHANGED
|
@@ -16,6 +16,18 @@ var RemultProxy = /** @class */ (function () {
|
|
|
16
16
|
}
|
|
17
17
|
var self = _this;
|
|
18
18
|
return {
|
|
19
|
+
get fields() {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).metadata.fields;
|
|
22
|
+
},
|
|
23
|
+
validate: function () {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
var args2 = [];
|
|
26
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
27
|
+
args2[_i] = arguments[_i];
|
|
28
|
+
}
|
|
29
|
+
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).validate.apply(_a, tslib_1.__spread(args2));
|
|
30
|
+
},
|
|
19
31
|
addEventListener: function () {
|
|
20
32
|
var _a, _b;
|
|
21
33
|
var args2 = [];
|
|
@@ -5,7 +5,7 @@ import { EntityMetadata, FieldRef, FieldsRef, EntityFilter, FindOptions, Reposit
|
|
|
5
5
|
import { ClassType } from "../../classType";
|
|
6
6
|
import { Remult } from "../context";
|
|
7
7
|
import { entityEventListener } from "../__EntityValueProvider";
|
|
8
|
-
import { DataProvider, EntityDataProvider, EntityDataProviderFindOptions } from "../data-interfaces";
|
|
8
|
+
import { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo } from "../data-interfaces";
|
|
9
9
|
import { RefSubscriber } from ".";
|
|
10
10
|
import { Unsubscribe } from "../live-query/SubscriptionChannel";
|
|
11
11
|
export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
|
|
@@ -34,6 +34,8 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
34
34
|
delete(item: entityType): Promise<void>;
|
|
35
35
|
insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
36
36
|
insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
37
|
+
get fields(): FieldsMetadata<entityType>;
|
|
38
|
+
validate(entity: Partial<OmitEB<entityType>>, ...fields: (Extract<keyof OmitEB<entityType>, string>)[]): Promise<ErrorInfo<entityType> | undefined>;
|
|
37
39
|
update(id: (entityType extends {
|
|
38
40
|
id?: number;
|
|
39
41
|
} ? number : entityType extends {
|
|
@@ -54,6 +56,7 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
54
56
|
findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType>;
|
|
55
57
|
private fieldsOf;
|
|
56
58
|
create(item?: Partial<OmitEB<entityType>>): entityType;
|
|
59
|
+
fixTypes(item: any): Promise<any>;
|
|
57
60
|
findId(id: any, options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
|
|
58
61
|
}
|
|
59
62
|
export declare function __updateEntityBasedOnWhere<T>(entityDefs: EntityMetadata<T>, where: EntityFilter<T>, r: T): void;
|
|
@@ -84,6 +87,7 @@ declare abstract class rowHelperBase<T> {
|
|
|
84
87
|
[key: string]: string;
|
|
85
88
|
};
|
|
86
89
|
protected __assertValidity(): void;
|
|
90
|
+
buildErrorInfoObject(): ErrorInfo<any>;
|
|
87
91
|
abstract get fields(): FieldsRef<T>;
|
|
88
92
|
catchSaveErrors(err: any): any;
|
|
89
93
|
__clearErrorsAndReportChanged(): void;
|
|
@@ -93,7 +97,7 @@ declare abstract class rowHelperBase<T> {
|
|
|
93
97
|
originalValues: any;
|
|
94
98
|
saveOriginalData(): void;
|
|
95
99
|
saveMoreOriginalData(): void;
|
|
96
|
-
validate(): Promise<
|
|
100
|
+
validate(): Promise<ErrorInfo<any>>;
|
|
97
101
|
__validateEntity(): Promise<void>;
|
|
98
102
|
__performColumnAndEntityValidations(): Promise<void>;
|
|
99
103
|
toApiJson(): any;
|
|
@@ -180,12 +184,18 @@ export declare function buildCaption(caption: string | ((remult: Remult) => stri
|
|
|
180
184
|
export declare class columnDefsImpl implements FieldMetadata {
|
|
181
185
|
private settings;
|
|
182
186
|
private entityDefs;
|
|
187
|
+
private remult;
|
|
183
188
|
constructor(settings: FieldOptions, entityDefs: EntityFullInfo<any>, remult: Remult);
|
|
189
|
+
apiUpdateAllowed(item: any): boolean;
|
|
190
|
+
displayValue(item: any): string;
|
|
191
|
+
get includedInApi(): boolean;
|
|
192
|
+
toInput(value: any, inputType?: string): string;
|
|
193
|
+
fromInput(inputValue: string, inputType?: string): any;
|
|
184
194
|
getDbName(): Promise<string>;
|
|
185
195
|
options: FieldOptions<any, any>;
|
|
186
196
|
target: ClassType<any>;
|
|
187
197
|
readonly: boolean;
|
|
188
|
-
valueConverter: ValueConverter<any
|
|
198
|
+
valueConverter: Required<ValueConverter<any>>;
|
|
189
199
|
allowNull: boolean;
|
|
190
200
|
caption: string;
|
|
191
201
|
get dbName(): any;
|
|
@@ -203,10 +213,10 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
|
|
|
203
213
|
readonly key: string;
|
|
204
214
|
options: EntityOptions<any>;
|
|
205
215
|
constructor(columnsInfo: FieldOptions[], entityInfo: EntityOptions, remult: Remult, entityType: ClassType<T>, key: string);
|
|
206
|
-
|
|
216
|
+
apiUpdateAllowed(item: T): boolean;
|
|
207
217
|
get apiReadAllowed(): boolean;
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
apiDeleteAllowed(item: T): boolean;
|
|
219
|
+
apiInsertAllowed(item: T): boolean;
|
|
210
220
|
dbNamePromise: Promise<string>;
|
|
211
221
|
getDbName(): Promise<string>;
|
|
212
222
|
idMetadata: IdMetadata<T>;
|