remult 0.25.0 → 0.25.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/src/remult3/relation-loader.js +16 -5
- package/esm/src/remult3/remult3.js +3 -1
- package/esm/src/validators.js +9 -9
- package/package.json +1 -1
- package/src/remult3/relation-loader.d.ts +1 -1
- package/src/remult3/relation-loader.js +75 -49
- package/src/remult3/remult3.js +3 -1
- package/src/validators.d.ts +3 -0
- package/src/validators.js +10 -10
|
@@ -88,7 +88,7 @@ class PendingInStatements {
|
|
|
88
88
|
rel;
|
|
89
89
|
key;
|
|
90
90
|
options;
|
|
91
|
-
resolve() {
|
|
91
|
+
async resolve() {
|
|
92
92
|
const values = [...this.values.values()];
|
|
93
93
|
if (values.length == 1) {
|
|
94
94
|
this.rel.find(this.options).then(values[0].resolve, values[0].reject);
|
|
@@ -96,9 +96,19 @@ class PendingInStatements {
|
|
|
96
96
|
}
|
|
97
97
|
var op = { ...this.options };
|
|
98
98
|
op.where = { [this.key]: values.map((v) => v.value) };
|
|
99
|
-
|
|
99
|
+
op.limit = 1000;
|
|
100
|
+
op.page = 1;
|
|
101
|
+
let vals = [];
|
|
102
|
+
try {
|
|
103
|
+
while (true) {
|
|
104
|
+
const val = await this.rel.find(op);
|
|
105
|
+
vals.push(...val);
|
|
106
|
+
if (val.length < op.limit)
|
|
107
|
+
break;
|
|
108
|
+
op.page++;
|
|
109
|
+
}
|
|
100
110
|
for (const value of this.values.values()) {
|
|
101
|
-
value.resolve(
|
|
111
|
+
value.resolve(vals.filter((x) => {
|
|
102
112
|
const ref = getEntityRef(x);
|
|
103
113
|
const field = ref.fields.find(this.key);
|
|
104
114
|
const rel = getRelationInfo(field.metadata.options);
|
|
@@ -108,11 +118,12 @@ class PendingInStatements {
|
|
|
108
118
|
return value.value == val;
|
|
109
119
|
}));
|
|
110
120
|
}
|
|
111
|
-
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
112
123
|
for (const value of this.values.values()) {
|
|
113
124
|
value.reject(err);
|
|
114
125
|
}
|
|
115
|
-
}
|
|
126
|
+
}
|
|
116
127
|
}
|
|
117
128
|
find(where) {
|
|
118
129
|
const val = where[this.key];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//y1 -
|
|
2
|
+
//y1 - number default storage in knex is decimal and it by default has 8,2 - meaning only 999,999 - I think it should be way bigger than that. in firefly we do at least 18 - https://discord.com/channels/975754286384418847/1195162533447876658
|
|
3
3
|
//y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
|
|
4
4
|
//y2 - from the crm-demo(https://crm-demo.up.railway.app/deals), after editing a deal: - _updateEntityBasedOnApi
|
|
5
5
|
//y2 - Backend methods are transactions, it's not intuitive and maybe should be optional / opt in
|
|
@@ -70,3 +70,5 @@ remult.apiClient.url='localhost:3007/api
|
|
|
70
70
|
//[ ] V3 - all these fields will also appear in the where etc... in the typescript api - but we will not enforce them
|
|
71
71
|
//y2 - consider if field types should include validation in them by default (string,number that it's not NaN etc...) and if so, what message?
|
|
72
72
|
//y2 - should enforce integer - currently we probably round / truncate it
|
|
73
|
+
//p1 - adjust react tutorial to esm
|
|
74
|
+
//p1 - write docs on with remult - and usage in init api
|
package/esm/src/validators.js
CHANGED
|
@@ -39,6 +39,7 @@ export class Validators {
|
|
|
39
39
|
return Boolean(await e.load());
|
|
40
40
|
}, 'Relation value does not exist');
|
|
41
41
|
static maxLength = createValueValidatorWithArgs((val, maxLength) => val.length <= maxLength, (maxLength) => `Value must be at most ${maxLength} characters`);
|
|
42
|
+
static minLength = createValueValidatorWithArgs((val, minLength) => val.length >= minLength, (maxLength) => `Value must be at least ${maxLength} characters`);
|
|
42
43
|
static defaultMessage = 'Invalid value';
|
|
43
44
|
}
|
|
44
45
|
export function createValidator(validate, defaultMessage) {
|
|
@@ -63,16 +64,18 @@ export function createValidator(validate, defaultMessage) {
|
|
|
63
64
|
}
|
|
64
65
|
return validation(entityOrMessage, e, message);
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
withMessage: (message) => async (entity, e) => result(entity, e, message),
|
|
69
|
-
get defaultMessage() {
|
|
67
|
+
Object.defineProperty(result, 'defaultMessage', {
|
|
68
|
+
get: () => {
|
|
70
69
|
return defaultMessage;
|
|
71
70
|
},
|
|
72
|
-
set
|
|
71
|
+
set: (val) => {
|
|
73
72
|
defaultMessage = val;
|
|
74
73
|
},
|
|
75
|
-
|
|
74
|
+
enumerable: true,
|
|
75
|
+
});
|
|
76
|
+
//@ts-ignore
|
|
77
|
+
return Object.assign(result, {
|
|
78
|
+
withMessage: (message) => async (entity, e) => result(entity, e, message),
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
export function valueValidator(validate, defaultMessage) {
|
|
@@ -123,6 +126,3 @@ export function createValidatorWithArgs(validate, defaultMessage) {
|
|
|
123
126
|
},
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
|
-
//y1 - talk about the 3rd parameter as message
|
|
127
|
-
//y1 - talk about the changed signature breaking existing validations and preventing the usage of unique outside the normal flow
|
|
128
|
-
//y1 - talk about the defaultMessage value now being a function that get's too many arguments, that makes it's reuse that much harder
|
package/package.json
CHANGED
|
@@ -144,56 +144,82 @@ var PendingInStatements = /** @class */ (function () {
|
|
|
144
144
|
this.values = new Map();
|
|
145
145
|
}
|
|
146
146
|
PendingInStatements.prototype.resolve = function () {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
147
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
148
|
+
var values, op, vals, val, _loop_1, _a, _b, value, err_1, _c, _d, value;
|
|
149
|
+
var _e, e_4, _f, e_5, _g;
|
|
150
|
+
var _this = this;
|
|
151
|
+
return tslib_1.__generator(this, function (_h) {
|
|
152
|
+
switch (_h.label) {
|
|
153
|
+
case 0:
|
|
154
|
+
values = tslib_1.__spreadArray([], tslib_1.__read(this.values.values()), false);
|
|
155
|
+
if (values.length == 1) {
|
|
156
|
+
this.rel.find(this.options).then(values[0].resolve, values[0].reject);
|
|
157
|
+
return [2 /*return*/];
|
|
158
|
+
}
|
|
159
|
+
op = tslib_1.__assign({}, this.options);
|
|
160
|
+
op.where = (_e = {}, _e[this.key] = values.map(function (v) { return v.value; }), _e);
|
|
161
|
+
op.limit = 1000;
|
|
162
|
+
op.page = 1;
|
|
163
|
+
vals = [];
|
|
164
|
+
_h.label = 1;
|
|
165
|
+
case 1:
|
|
166
|
+
_h.trys.push([1, 5, , 6]);
|
|
167
|
+
_h.label = 2;
|
|
168
|
+
case 2:
|
|
169
|
+
if (!true) return [3 /*break*/, 4];
|
|
170
|
+
return [4 /*yield*/, this.rel.find(op)];
|
|
171
|
+
case 3:
|
|
172
|
+
val = _h.sent();
|
|
173
|
+
vals.push.apply(vals, tslib_1.__spreadArray([], tslib_1.__read(val), false));
|
|
174
|
+
if (val.length < op.limit)
|
|
175
|
+
return [3 /*break*/, 4];
|
|
176
|
+
op.page++;
|
|
177
|
+
return [3 /*break*/, 2];
|
|
178
|
+
case 4:
|
|
179
|
+
_loop_1 = function (value) {
|
|
180
|
+
value.resolve(vals.filter(function (x) {
|
|
181
|
+
var ref = (0, getEntityRef_js_1.getEntityRef)(x);
|
|
182
|
+
var field = ref.fields.find(_this.key);
|
|
183
|
+
var rel = (0, relationInfoMember_js_1.getRelationInfo)(field.metadata.options);
|
|
184
|
+
var val = (rel === null || rel === void 0 ? void 0 : rel.type) === 'reference'
|
|
185
|
+
? field.getId()
|
|
186
|
+
: x[_this.key];
|
|
187
|
+
return value.value == val;
|
|
188
|
+
}));
|
|
189
|
+
};
|
|
190
|
+
try {
|
|
191
|
+
for (_a = tslib_1.__values(this.values.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
192
|
+
value = _b.value;
|
|
193
|
+
_loop_1(value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
197
|
+
finally {
|
|
198
|
+
try {
|
|
199
|
+
if (_b && !_b.done && (_f = _a.return)) _f.call(_a);
|
|
200
|
+
}
|
|
201
|
+
finally { if (e_4) throw e_4.error; }
|
|
202
|
+
}
|
|
203
|
+
return [3 /*break*/, 6];
|
|
204
|
+
case 5:
|
|
205
|
+
err_1 = _h.sent();
|
|
206
|
+
try {
|
|
207
|
+
for (_c = tslib_1.__values(this.values.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
208
|
+
value = _d.value;
|
|
209
|
+
value.reject(err_1);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
213
|
+
finally {
|
|
214
|
+
try {
|
|
215
|
+
if (_d && !_d.done && (_g = _c.return)) _g.call(_c);
|
|
216
|
+
}
|
|
217
|
+
finally { if (e_5) throw e_5.error; }
|
|
218
|
+
}
|
|
219
|
+
return [3 /*break*/, 6];
|
|
220
|
+
case 6: return [2 /*return*/];
|
|
194
221
|
}
|
|
195
|
-
|
|
196
|
-
}
|
|
222
|
+
});
|
|
197
223
|
});
|
|
198
224
|
};
|
|
199
225
|
PendingInStatements.prototype.find = function (where) {
|
package/src/remult3/remult3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//y1 -
|
|
3
|
+
//y1 - number default storage in knex is decimal and it by default has 8,2 - meaning only 999,999 - I think it should be way bigger than that. in firefly we do at least 18 - https://discord.com/channels/975754286384418847/1195162533447876658
|
|
4
4
|
//y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
|
|
5
5
|
//y2 - from the crm-demo(https://crm-demo.up.railway.app/deals), after editing a deal: - _updateEntityBasedOnApi
|
|
6
6
|
//y2 - Backend methods are transactions, it's not intuitive and maybe should be optional / opt in
|
|
@@ -71,3 +71,5 @@ remult.apiClient.url='localhost:3007/api
|
|
|
71
71
|
//[ ] V3 - all these fields will also appear in the where etc... in the typescript api - but we will not enforce them
|
|
72
72
|
//y2 - consider if field types should include validation in them by default (string,number that it's not NaN etc...) and if so, what message?
|
|
73
73
|
//y2 - should enforce integer - currently we probably round / truncate it
|
|
74
|
+
//p1 - adjust react tutorial to esm
|
|
75
|
+
//p1 - write docs on with remult - and usage in init api
|
package/src/validators.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export declare class Validators {
|
|
|
23
23
|
static maxLength: ValidatorWithArgs<string, number> & {
|
|
24
24
|
defaultMessage: ValueValidationMessage<number>;
|
|
25
25
|
};
|
|
26
|
+
static minLength: ValidatorWithArgs<string, number> & {
|
|
27
|
+
defaultMessage: ValueValidationMessage<number>;
|
|
28
|
+
};
|
|
26
29
|
static defaultMessage: string;
|
|
27
30
|
}
|
|
28
31
|
export type Validator<valueType> = FieldValidator<any, valueType> & ((message?: ValidationMessage<valueType, undefined>) => FieldValidator<any, valueType>) & {
|
package/src/validators.js
CHANGED
|
@@ -71,6 +71,7 @@ var Validators = /** @class */ (function () {
|
|
|
71
71
|
});
|
|
72
72
|
}); }, 'Relation value does not exist');
|
|
73
73
|
Validators.maxLength = createValueValidatorWithArgs(function (val, maxLength) { return val.length <= maxLength; }, function (maxLength) { return "Value must be at most ".concat(maxLength, " characters"); });
|
|
74
|
+
Validators.minLength = createValueValidatorWithArgs(function (val, minLength) { return val.length >= minLength; }, function (maxLength) { return "Value must be at least ".concat(maxLength, " characters"); });
|
|
74
75
|
Validators.defaultMessage = 'Invalid value';
|
|
75
76
|
return Validators;
|
|
76
77
|
}());
|
|
@@ -111,6 +112,15 @@ function createValidator(validate, defaultMessage) {
|
|
|
111
112
|
}
|
|
112
113
|
return validation(entityOrMessage, e, message);
|
|
113
114
|
};
|
|
115
|
+
Object.defineProperty(result, 'defaultMessage', {
|
|
116
|
+
get: function () {
|
|
117
|
+
return defaultMessage;
|
|
118
|
+
},
|
|
119
|
+
set: function (val) {
|
|
120
|
+
defaultMessage = val;
|
|
121
|
+
},
|
|
122
|
+
enumerable: true,
|
|
123
|
+
});
|
|
114
124
|
//@ts-ignore
|
|
115
125
|
return Object.assign(result, {
|
|
116
126
|
withMessage: function (message) {
|
|
@@ -118,13 +128,6 @@ function createValidator(validate, defaultMessage) {
|
|
|
118
128
|
return [2 /*return*/, result(entity, e, message)];
|
|
119
129
|
}); }); };
|
|
120
130
|
},
|
|
121
|
-
get defaultMessage() {
|
|
122
|
-
return defaultMessage;
|
|
123
|
-
},
|
|
124
|
-
set defaultMessage(val) {
|
|
125
|
-
defaultMessage = val;
|
|
126
|
-
},
|
|
127
|
-
isValid: validate,
|
|
128
131
|
});
|
|
129
132
|
}
|
|
130
133
|
exports.createValidator = createValidator;
|
|
@@ -195,6 +198,3 @@ function createValidatorWithArgs(validate, defaultMessage) {
|
|
|
195
198
|
});
|
|
196
199
|
}
|
|
197
200
|
exports.createValidatorWithArgs = createValidatorWithArgs;
|
|
198
|
-
//y1 - talk about the 3rd parameter as message
|
|
199
|
-
//y1 - talk about the changed signature breaking existing validations and preventing the usage of unique outside the normal flow
|
|
200
|
-
//y1 - talk about the defaultMessage value now being a function that get's too many arguments, that makes it's reuse that much harder
|