remult 3.4.2 → 3.5.0-next.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/internals.js +1 -0
- package/esm/postgres/postgres-data-provider.js +4 -5
- package/esm/remult-duckdb.js +4 -0
- package/esm/remult-knex/index.js +69 -14
- package/esm/remult-mongo.js +25 -7
- package/esm/remult-sqlite-core.js +4 -1
- package/esm/server/remult-api-server.js +14 -6
- package/esm/src/buildRestDataProvider.js +8 -6
- package/esm/src/context.js +1 -1
- package/esm/src/data-api.js +2 -2
- package/esm/src/data-interfaces.js +2 -1
- package/esm/src/data-providers/array-entity-data-provider.js +9 -4
- package/esm/src/data-providers/rest-data-provider-using-fetch.js +13 -6
- package/esm/src/data-providers/retry.js +11 -6
- package/esm/src/data-providers/sql-database.js +40 -30
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +35 -4
- package/esm/src/filter/filter-interfaces.js +18 -4
- package/esm/src/live-query/SubscriptionChannel.js +13 -8
- package/esm/src/remult-proxy.js +12 -0
- package/esm/src/remult-static.js +2 -0
- package/esm/src/remult3/Fields.js +14 -14
- package/esm/src/remult3/RepositoryImplementation.js +69 -32
- package/esm/src/remult3/remult3.js +2 -0
- package/esm/src/server-action.js +43 -14
- package/esm/src/sort.js +18 -0
- package/index.d.ts +4 -3
- package/internals.d.ts +1 -0
- package/internals.js +3 -1
- package/package.json +41 -1
- package/postgres/postgres-data-provider.d.ts +2 -3
- package/postgres/postgres-data-provider.js +4 -4
- package/remult-duckdb.d.ts +2 -0
- package/remult-duckdb.js +4 -0
- package/remult-knex/index.d.ts +2 -0
- package/remult-knex/index.js +153 -83
- package/remult-mongo.js +28 -7
- package/remult-sqlite-core.d.ts +2 -1
- package/remult-sqlite-core.js +4 -0
- package/server/remult-api-server.d.ts +28 -1
- package/server/remult-api-server.js +19 -12
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +8 -6
- package/src/column-interfaces.d.ts +5 -1
- package/src/context.js +1 -1
- package/src/data-api.js +2 -2
- package/src/data-interfaces.d.ts +0 -1
- package/src/data-interfaces.js +3 -0
- package/src/data-providers/array-entity-data-provider.js +9 -4
- package/src/data-providers/rest-data-provider-using-fetch.d.ts +1 -1
- package/src/data-providers/rest-data-provider-using-fetch.js +11 -4
- package/src/data-providers/retry.d.ts +4 -1
- package/src/data-providers/retry.js +26 -16
- package/src/data-providers/sql-database.d.ts +7 -3
- package/src/data-providers/sql-database.js +99 -81
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +8 -0
- package/src/filter/filter-consumer-bridge-to-sql-request.js +58 -19
- package/src/filter/filter-interfaces.js +19 -2
- package/src/live-query/SubscriptionChannel.js +16 -10
- package/src/remult-proxy.js +28 -0
- package/src/remult-static.d.ts +4 -0
- package/src/remult-static.js +2 -0
- package/src/remult3/Fields.d.ts +5 -3
- package/src/remult3/Fields.js +24 -13
- package/src/remult3/RepositoryImplementation.d.ts +7 -0
- package/src/remult3/RepositoryImplementation.js +325 -264
- package/src/remult3/remult3.d.ts +68 -5
- package/src/remult3/remult3.js +2 -0
- package/src/server-action.d.ts +34 -2
- package/src/server-action.js +195 -115
- package/src/sort.d.ts +19 -0
- package/src/sort.js +20 -1
- package/src/sql-command.d.ts +2 -1
package/remult-mongo.js
CHANGED
|
@@ -10,6 +10,18 @@ var RepositoryImplementation_js_1 = require("./src/remult3/RepositoryImplementat
|
|
|
10
10
|
var repository_internals_js_1 = require("./src/remult3/repository-internals.js");
|
|
11
11
|
var sql_database_js_1 = require("./src/data-providers/sql-database.js");
|
|
12
12
|
var remult3_js_1 = require("./src/remult3/remult3.js");
|
|
13
|
+
var sort_js_1 = require("./src/sort.js");
|
|
14
|
+
var nullSortWarned = false;
|
|
15
|
+
// `$sort` has no NULL option, so Mongo sorts NULL lowest whatever NullSort says.
|
|
16
|
+
function warnIfNullSortIgnored() {
|
|
17
|
+
var order = sort_js_1.NullSort.order;
|
|
18
|
+
if (nullSortWarned || order === 'native')
|
|
19
|
+
return;
|
|
20
|
+
if (order.asc === 'NULLS FIRST' && order.desc === 'NULLS LAST')
|
|
21
|
+
return;
|
|
22
|
+
nullSortWarned = true;
|
|
23
|
+
console.warn('[remult] NullSort is ignored on Mongo, which sorts NULL lowest: paginator() can skip or repeat rows');
|
|
24
|
+
}
|
|
13
25
|
var MongoDataProvider = /** @class */ (function () {
|
|
14
26
|
function MongoDataProvider(db, client, options) {
|
|
15
27
|
this.db = db;
|
|
@@ -135,7 +147,13 @@ var MongoDataProvider = /** @class */ (function () {
|
|
|
135
147
|
return MongoDataProvider;
|
|
136
148
|
}());
|
|
137
149
|
exports.MongoDataProvider = MongoDataProvider;
|
|
150
|
+
// Older versions wrote NULL as this marker, which sorts above numbers and strings.
|
|
138
151
|
var NULL = { $null: '$null' };
|
|
152
|
+
// `$in: [null, NULL]` fails: Mongo cannot nest `$` under `$in`.
|
|
153
|
+
function nullFilter(name) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
return { $or: [(_a = {}, _a[name] = null, _a), (_b = {}, _b[name] = { $eq: NULL }, _b)] };
|
|
156
|
+
}
|
|
139
157
|
function isNull(x) {
|
|
140
158
|
return (x === null || x === void 0 ? void 0 : x.$null) === NULL.$null;
|
|
141
159
|
}
|
|
@@ -230,10 +248,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
230
248
|
var col = _c.value;
|
|
231
249
|
if (col.dbReadOnly || col.isServerExpression)
|
|
232
250
|
continue;
|
|
233
|
-
|
|
234
|
-
if (val === null)
|
|
235
|
-
val = NULL;
|
|
236
|
-
result[nameProvider.$dbNameOf(col)] = val;
|
|
251
|
+
result[nameProvider.$dbNameOf(col)] = toDb(col, row[col.key]);
|
|
237
252
|
}
|
|
238
253
|
}
|
|
239
254
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -365,6 +380,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
365
380
|
finally { if (e_6) throw e_6.error; }
|
|
366
381
|
}
|
|
367
382
|
if (options === null || options === void 0 ? void 0 : options.orderBy) {
|
|
383
|
+
warnIfNullSortIgnored();
|
|
368
384
|
sort = {};
|
|
369
385
|
try {
|
|
370
386
|
for (_d = tslib_1.__values(options.orderBy), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
@@ -452,6 +468,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
452
468
|
}
|
|
453
469
|
}
|
|
454
470
|
if (options.orderBy) {
|
|
471
|
+
warnIfNullSortIgnored();
|
|
455
472
|
op.sort = {};
|
|
456
473
|
try {
|
|
457
474
|
for (_b = tslib_1.__values(options.orderBy.Segments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -764,10 +781,14 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
|
764
781
|
}); })());
|
|
765
782
|
};
|
|
766
783
|
FilterConsumerBridgeToMongo.prototype.isNull = function (col) {
|
|
767
|
-
|
|
784
|
+
var _this = this;
|
|
785
|
+
this.result.push(function () { return nullFilter(_this.nameProvider.$dbNameOf(col)); });
|
|
768
786
|
};
|
|
769
787
|
FilterConsumerBridgeToMongo.prototype.isNotNull = function (col) {
|
|
770
|
-
|
|
788
|
+
var _this = this;
|
|
789
|
+
this.result.push(function () { return ({
|
|
790
|
+
$nor: [nullFilter(_this.nameProvider.$dbNameOf(col))],
|
|
791
|
+
}); });
|
|
771
792
|
};
|
|
772
793
|
FilterConsumerBridgeToMongo.prototype.isIn = function (col, val) {
|
|
773
794
|
var _this = this;
|
|
@@ -831,7 +852,7 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
|
831
852
|
this.result.push(function () {
|
|
832
853
|
var _a, _b;
|
|
833
854
|
return (_a = {},
|
|
834
|
-
_a[_this.nameProvider.$dbNameOf(col)] = tslib_1.__assign((_b = {}, _b[operator] =
|
|
855
|
+
_a[_this.nameProvider.$dbNameOf(col)] = tslib_1.__assign((_b = {}, _b[operator] = toDb(col, val), _b), moreOptions),
|
|
835
856
|
_a);
|
|
836
857
|
});
|
|
837
858
|
};
|
package/remult-sqlite-core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EntityMetadata } from './src/remult3/remult3.js';
|
|
2
|
+
import type { NativeNullSort } from './src/sort.js';
|
|
2
3
|
import type { SqlCommand, SqlImplementation } from './src/sql-command.js';
|
|
3
4
|
import type { FieldMetadata } from './src/column-interfaces.js';
|
|
4
5
|
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from './migrations/migration-types.js';
|
|
@@ -8,7 +9,7 @@ export declare class SqliteCoreDataProvider implements SqlImplementation, CanBui
|
|
|
8
9
|
doesNotSupportReturningSyntax: boolean;
|
|
9
10
|
doesNotSupportReturningSyntaxOnlyForUpdate: boolean;
|
|
10
11
|
constructor(createCommand: () => SqlCommand, end: () => Promise<void>, doesNotSupportReturningSyntax?: boolean, doesNotSupportReturningSyntaxOnlyForUpdate?: boolean);
|
|
11
|
-
|
|
12
|
+
nativeNullSort: NativeNullSort;
|
|
12
13
|
maxParametersInOneSqlStatement: number;
|
|
13
14
|
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
14
15
|
afterMutation?: VoidFunction;
|
package/remult-sqlite-core.js
CHANGED
|
@@ -13,6 +13,10 @@ var SqliteCoreDataProvider = /** @class */ (function () {
|
|
|
13
13
|
this.end = end;
|
|
14
14
|
this.doesNotSupportReturningSyntax = doesNotSupportReturningSyntax;
|
|
15
15
|
this.doesNotSupportReturningSyntaxOnlyForUpdate = doesNotSupportReturningSyntaxOnlyForUpdate;
|
|
16
|
+
this.nativeNullSort = {
|
|
17
|
+
order: { asc: 'NULLS FIRST', desc: 'NULLS LAST' },
|
|
18
|
+
syntax: 'NULLS FIRST/LAST',
|
|
19
|
+
};
|
|
16
20
|
this.maxParametersInOneSqlStatement = 999;
|
|
17
21
|
}
|
|
18
22
|
SqliteCoreDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|
|
@@ -38,6 +38,22 @@ export interface RemultServerOptions<RequestType> {
|
|
|
38
38
|
rootPath?: string;
|
|
39
39
|
/** The default limit to use for find requests that did not specify a limit */
|
|
40
40
|
defaultGetLimit?: number;
|
|
41
|
+
/** The status for an `Error` thrown without an `httpStatusCode`, like a failed
|
|
42
|
+
* query or a `TypeError`. Thrown strings, plain objects and `EntityError`s stay 400.
|
|
43
|
+
*
|
|
44
|
+
* The client retries reads on a 500 (`flags.error500RetryCount`), so keep that retry
|
|
45
|
+
* for dev only, where it covers a proxy while the backend restarts.
|
|
46
|
+
*
|
|
47
|
+
* @default 400
|
|
48
|
+
* @example
|
|
49
|
+
* // server
|
|
50
|
+
* remultApi({ defaultErrorStatus: 500 })
|
|
51
|
+
*
|
|
52
|
+
* // client
|
|
53
|
+
* import { flags } from 'remult/internals'
|
|
54
|
+
* flags.error500RetryCount = isDev ? 4 : 0 // isDev: your framework's flag, e.g. import.meta.env.DEV
|
|
55
|
+
*/
|
|
56
|
+
defaultErrorStatus?: number;
|
|
41
57
|
/** When set to true (default) it'll console log each api endpoint that is created */
|
|
42
58
|
logApiEndPoints?: boolean;
|
|
43
59
|
/** A subscription server to use for live query and message channels */
|
|
@@ -73,7 +89,7 @@ export interface RemultServerOptions<RequestType> {
|
|
|
73
89
|
* @param info.entity - (Optional) The entity metadata associated with the error, if applicable.
|
|
74
90
|
* @param info.exception - (Optional) The exception object or error that occurred.
|
|
75
91
|
* @param info.httpStatusCode - The HTTP status code.
|
|
76
|
-
* @param info.responseBody - The body of the response.
|
|
92
|
+
* @param info.responseBody - The body of the response, without the stack.
|
|
77
93
|
* @param info.sendError - A method to send a custom error response. Call this method with the desired HTTP status code and response body.
|
|
78
94
|
*
|
|
79
95
|
* @returns A promise that resolves when the error handling is complete.
|
|
@@ -85,6 +101,17 @@ export interface RemultServerOptions<RequestType> {
|
|
|
85
101
|
* }
|
|
86
102
|
* }
|
|
87
103
|
* })
|
|
104
|
+
* @example
|
|
105
|
+
* // Send the stack outside production
|
|
106
|
+
* export const api = remultApi({
|
|
107
|
+
* error: async (e) => {
|
|
108
|
+
* if (process.env.NODE_ENV === 'production') return
|
|
109
|
+
* e.sendError(e.httpStatusCode, {
|
|
110
|
+
* ...e.responseBody,
|
|
111
|
+
* stack: e.exception?.stack,
|
|
112
|
+
* })
|
|
113
|
+
* },
|
|
114
|
+
* })
|
|
88
115
|
*/
|
|
89
116
|
error?: (info: {
|
|
90
117
|
req?: RequestType;
|
|
@@ -6,6 +6,7 @@ var tslib_1 = require("tslib");
|
|
|
6
6
|
var SseSubscriptionServer_js_1 = require("../SseSubscriptionServer.js");
|
|
7
7
|
var context_js_1 = require("../src/context.js");
|
|
8
8
|
var data_api_js_1 = require("../src/data-api.js");
|
|
9
|
+
var data_interfaces_js_1 = require("../src/data-interfaces.js");
|
|
9
10
|
var SubscriptionChannel_js_1 = require("../src/live-query/SubscriptionChannel.js");
|
|
10
11
|
var SubscriptionServer_js_1 = require("../src/live-query/SubscriptionServer.js");
|
|
11
12
|
var IdEntity_js_1 = require("../src/remult3/IdEntity.js");
|
|
@@ -637,7 +638,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
637
638
|
genReq.params = req['_tempParams'];
|
|
638
639
|
}
|
|
639
640
|
myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
640
|
-
myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
|
|
641
|
+
myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error, this.options.defaultErrorStatus);
|
|
641
642
|
_b.label = 1;
|
|
642
643
|
case 1:
|
|
643
644
|
_b.trys.push([1, 6, , 7]);
|
|
@@ -1195,11 +1196,13 @@ var RequestBridgeToDataApiRequest = /** @class */ (function () {
|
|
|
1195
1196
|
return RequestBridgeToDataApiRequest;
|
|
1196
1197
|
}());
|
|
1197
1198
|
var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
1198
|
-
function ResponseBridgeToDataApiResponse(r, req, genReq, handleError) {
|
|
1199
|
+
function ResponseBridgeToDataApiResponse(r, req, genReq, handleError, defaultErrorStatus) {
|
|
1200
|
+
if (defaultErrorStatus === void 0) { defaultErrorStatus = 400; }
|
|
1199
1201
|
this.r = r;
|
|
1200
1202
|
this.req = req;
|
|
1201
1203
|
this.genReq = genReq;
|
|
1202
1204
|
this.handleError = handleError;
|
|
1205
|
+
this.defaultErrorStatus = defaultErrorStatus;
|
|
1203
1206
|
}
|
|
1204
1207
|
ResponseBridgeToDataApiResponse.prototype.forbidden = function (message) {
|
|
1205
1208
|
if (message === void 0) { message = 'Forbidden'; }
|
|
@@ -1223,24 +1226,28 @@ var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
|
1223
1226
|
};
|
|
1224
1227
|
ResponseBridgeToDataApiResponse.prototype.error = function (exception, entity, httpStatusCode) {
|
|
1225
1228
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1226
|
-
var data, responseSent, sendError;
|
|
1229
|
+
var data, explicitStatus, responseSent, sendError;
|
|
1227
1230
|
var _this = this;
|
|
1228
|
-
var _a;
|
|
1229
|
-
return tslib_1.__generator(this, function (
|
|
1230
|
-
switch (
|
|
1231
|
+
var _a, _b;
|
|
1232
|
+
return tslib_1.__generator(this, function (_c) {
|
|
1233
|
+
switch (_c.label) {
|
|
1231
1234
|
case 0:
|
|
1232
1235
|
data = (0, data_api_js_1.serializeError)(exception);
|
|
1233
1236
|
if (!httpStatusCode) {
|
|
1234
|
-
|
|
1235
|
-
|
|
1237
|
+
explicitStatus = (_a = exception.httpStatusCode) !== null && _a !== void 0 ? _a : data.httpStatusCode;
|
|
1238
|
+
if (explicitStatus) {
|
|
1239
|
+
httpStatusCode = explicitStatus;
|
|
1236
1240
|
}
|
|
1237
1241
|
else if ((0, isOfType_js_1.isOfType)(exception, 'isForbiddenError') &&
|
|
1238
1242
|
exception.isForbiddenError) {
|
|
1239
1243
|
httpStatusCode = 403;
|
|
1240
1244
|
}
|
|
1241
|
-
else if (data.modelState) {
|
|
1245
|
+
else if (data.modelState || exception instanceof data_interfaces_js_1.EntityError) {
|
|
1242
1246
|
httpStatusCode = 400;
|
|
1243
1247
|
}
|
|
1248
|
+
else if (exception instanceof Error) {
|
|
1249
|
+
httpStatusCode = this.defaultErrorStatus;
|
|
1250
|
+
}
|
|
1244
1251
|
else {
|
|
1245
1252
|
httpStatusCode = 400;
|
|
1246
1253
|
}
|
|
@@ -1255,14 +1262,14 @@ var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
|
1255
1262
|
console.error({
|
|
1256
1263
|
message: body.message,
|
|
1257
1264
|
httpStatusCode: httpStatusCode,
|
|
1258
|
-
stack: (_a =
|
|
1265
|
+
stack: (_a = exception === null || exception === void 0 ? void 0 : exception.stack) === null || _a === void 0 ? void 0 : _a.split('\n'),
|
|
1259
1266
|
url: (_b = _this.genReq) === null || _b === void 0 ? void 0 : _b.url,
|
|
1260
1267
|
method: (_c = _this.genReq) === null || _c === void 0 ? void 0 : _c.method,
|
|
1261
1268
|
});
|
|
1262
1269
|
var json = tslib_1.__assign(tslib_1.__assign({}, body), { message: body.message });
|
|
1263
1270
|
_this.setStatus(httpStatusCode).json(json);
|
|
1264
1271
|
};
|
|
1265
|
-
return [4 /*yield*/, ((
|
|
1272
|
+
return [4 /*yield*/, ((_b = this.handleError) === null || _b === void 0 ? void 0 : _b.call(this, {
|
|
1266
1273
|
httpStatusCode: httpStatusCode,
|
|
1267
1274
|
req: this.req,
|
|
1268
1275
|
entity: entity,
|
|
@@ -1271,7 +1278,7 @@ var ResponseBridgeToDataApiResponse = /** @class */ (function () {
|
|
|
1271
1278
|
sendError: sendError,
|
|
1272
1279
|
}))];
|
|
1273
1280
|
case 1:
|
|
1274
|
-
|
|
1281
|
+
_c.sent();
|
|
1275
1282
|
if (!responseSent) {
|
|
1276
1283
|
sendError(httpStatusCode, data);
|
|
1277
1284
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RestDataProviderHttpProvider } from './data-interfaces.js';
|
|
2
2
|
export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch | undefined): RestDataProviderHttpProvider;
|
|
3
3
|
export declare function isExternalHttpProvider(item: any): boolean;
|
|
4
4
|
export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
|
|
@@ -6,8 +6,10 @@ exports.isExternalHttpProvider = isExternalHttpProvider;
|
|
|
6
6
|
exports.toPromise = toPromise;
|
|
7
7
|
exports.processHttpException = processHttpException;
|
|
8
8
|
var tslib_1 = require("tslib");
|
|
9
|
+
var data_interfaces_js_1 = require("./data-interfaces.js");
|
|
9
10
|
var rest_data_provider_using_fetch_js_1 = require("./data-providers/rest-data-provider-using-fetch.js");
|
|
10
11
|
var retry_js_1 = require("./data-providers/retry.js");
|
|
12
|
+
var remult3_js_1 = require("./remult3/remult3.js");
|
|
11
13
|
function buildRestDataProvider(provider) {
|
|
12
14
|
if (!provider)
|
|
13
15
|
return new rest_data_provider_using_fetch_js_1.RestDataProviderHttpProviderUsingFetch();
|
|
@@ -39,7 +41,9 @@ var HttpProviderBridgeToRestDataProviderHttpProvider = /** @class */ (function (
|
|
|
39
41
|
var _this = this;
|
|
40
42
|
return tslib_1.__generator(this, function (_a) {
|
|
41
43
|
switch (_a.label) {
|
|
42
|
-
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () { return toPromise(_this.http.post(url, data)); }
|
|
44
|
+
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () { return toPromise(_this.http.post(url, data)); }, {
|
|
45
|
+
read: (0, retry_js_1.isReadPost)(url),
|
|
46
|
+
})];
|
|
43
47
|
case 1: return [2 /*return*/, _a.sent()];
|
|
44
48
|
}
|
|
45
49
|
});
|
|
@@ -96,7 +100,7 @@ function toPromise(p) {
|
|
|
96
100
|
}
|
|
97
101
|
function processHttpException(ex) {
|
|
98
102
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var z, error, httpStatusCode
|
|
103
|
+
var z, error, httpStatusCode;
|
|
100
104
|
var _a, _b, _c;
|
|
101
105
|
return tslib_1.__generator(this, function (_d) {
|
|
102
106
|
switch (_d.label) {
|
|
@@ -128,10 +132,8 @@ function processHttpException(ex) {
|
|
|
128
132
|
if (httpStatusCode !== undefined && httpStatusCode !== null) {
|
|
129
133
|
error.httpStatusCode = httpStatusCode;
|
|
130
134
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
return [2 /*return*/, result];
|
|
135
|
+
error !== null && error !== void 0 ? error : (error = {});
|
|
136
|
+
return [2 /*return*/, remult3_js_1.flags.clientErrorsAsEntityError ? new data_interfaces_js_1.EntityError(error) : error];
|
|
135
137
|
}
|
|
136
138
|
});
|
|
137
139
|
});
|
|
@@ -17,7 +17,11 @@ export interface FieldOptions<entityType = unknown, valueType = unknown> {
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
label?: string;
|
|
20
|
-
/** If it can store `null` in the database.
|
|
20
|
+
/** If it can store `null` in the database.
|
|
21
|
+
*
|
|
22
|
+
* Defaults to `true` on a Date, `Fields.json` or another custom `fieldTypeInDb` (except `integer`, or on a number or boolean), as migrations create those columns without a default value. `false` otherwise, on an id, and on `Fields.createdAt` / `updatedAt`.
|
|
23
|
+
* @see [allowNull by field type](https://remult.dev/docs/field-types#allownull-by-field-type)
|
|
24
|
+
*/
|
|
21
25
|
allowNull?: boolean;
|
|
22
26
|
/** If a value is required. Short-cut to say `validate: Validators.required`.
|
|
23
27
|
* @default false
|
package/src/context.js
CHANGED
|
@@ -304,7 +304,7 @@ var Remult = /** @class */ (function () {
|
|
|
304
304
|
if (!z.doWork)
|
|
305
305
|
throw Error('The method received is not a valid backend method');
|
|
306
306
|
//@ts-ignore
|
|
307
|
-
return z.doWork(args, classInstance, this
|
|
307
|
+
return z.doWork(args, classInstance, this);
|
|
308
308
|
};
|
|
309
309
|
Remult.prototype.clearAllCache = function () {
|
|
310
310
|
this.repCache.clear();
|
package/src/data-api.js
CHANGED
|
@@ -1127,11 +1127,11 @@ function serializeError(data) {
|
|
|
1127
1127
|
data = { message: data.message, modelState: data.modelState };
|
|
1128
1128
|
}
|
|
1129
1129
|
else if (data instanceof Error) {
|
|
1130
|
-
data = { message: data.message
|
|
1130
|
+
data = { message: data.message };
|
|
1131
1131
|
}
|
|
1132
1132
|
var x = JSON.parse(JSON.stringify(data));
|
|
1133
1133
|
if (!x.message && !x.modelState)
|
|
1134
|
-
data = { message: data.message
|
|
1134
|
+
data = { message: data.message };
|
|
1135
1135
|
if (typeof x === 'string')
|
|
1136
1136
|
data = { message: x };
|
|
1137
1137
|
return data;
|
package/src/data-interfaces.d.ts
CHANGED
package/src/data-interfaces.js
CHANGED
|
@@ -17,7 +17,10 @@ function extractSort(sort) {
|
|
|
17
17
|
var EntityError = /** @class */ (function (_super) {
|
|
18
18
|
tslib_1.__extends(EntityError, _super);
|
|
19
19
|
function EntityError(errorInfo) {
|
|
20
|
+
var _newTarget = this.constructor;
|
|
20
21
|
var _this = _super.call(this, errorInfo.message) || this;
|
|
22
|
+
// The ES5 build gets a plain Error back from super(), so instanceof EntityError would be false.
|
|
23
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
21
24
|
Object.assign(_this, errorInfo);
|
|
22
25
|
return _this;
|
|
23
26
|
}
|
|
@@ -795,25 +795,30 @@ var FilterConsumerBridgeToObject = /** @class */ (function () {
|
|
|
795
795
|
if (this.row[this.dbNames.$dbNameOf(col)] == col.valueConverter.toJson(val))
|
|
796
796
|
this.ok = false;
|
|
797
797
|
};
|
|
798
|
+
// As in SQL, NULL never matches an ordering comparison.
|
|
798
799
|
FilterConsumerBridgeToObject.prototype.isGreaterOrEqualTo = function (col, val) {
|
|
800
|
+
this.isNotNull(col);
|
|
799
801
|
if (this.row[this.dbNames.$dbNameOf(col)] < col.valueConverter.toJson(val))
|
|
800
802
|
this.ok = false;
|
|
801
803
|
};
|
|
802
804
|
FilterConsumerBridgeToObject.prototype.isGreaterThan = function (col, val) {
|
|
805
|
+
this.isNotNull(col);
|
|
803
806
|
if (this.row[this.dbNames.$dbNameOf(col)] <= col.valueConverter.toJson(val))
|
|
804
807
|
this.ok = false;
|
|
805
808
|
};
|
|
806
809
|
FilterConsumerBridgeToObject.prototype.isLessOrEqualTo = function (col, val) {
|
|
810
|
+
this.isNotNull(col);
|
|
807
811
|
if (this.row[this.dbNames.$dbNameOf(col)] > col.valueConverter.toJson(val))
|
|
808
812
|
this.ok = false;
|
|
809
813
|
};
|
|
810
814
|
FilterConsumerBridgeToObject.prototype.isLessThan = function (col, val) {
|
|
815
|
+
this.isNotNull(col);
|
|
811
816
|
if (this.row[this.dbNames.$dbNameOf(col)] >= col.valueConverter.toJson(val))
|
|
812
817
|
this.ok = false;
|
|
813
818
|
};
|
|
814
819
|
FilterConsumerBridgeToObject.prototype.containsCaseInsensitive = function (col, val) {
|
|
815
820
|
var v = this.row[this.dbNames.$dbNameOf(col)];
|
|
816
|
-
if (
|
|
821
|
+
if (v === undefined || v === null) {
|
|
817
822
|
this.ok = false;
|
|
818
823
|
return;
|
|
819
824
|
}
|
|
@@ -827,7 +832,7 @@ var FilterConsumerBridgeToObject = /** @class */ (function () {
|
|
|
827
832
|
};
|
|
828
833
|
FilterConsumerBridgeToObject.prototype.notContainsCaseInsensitive = function (col, val) {
|
|
829
834
|
var v = this.row[this.dbNames.$dbNameOf(col)];
|
|
830
|
-
if (
|
|
835
|
+
if (v === undefined || v === null) {
|
|
831
836
|
this.ok = false;
|
|
832
837
|
return;
|
|
833
838
|
}
|
|
@@ -841,7 +846,7 @@ var FilterConsumerBridgeToObject = /** @class */ (function () {
|
|
|
841
846
|
};
|
|
842
847
|
FilterConsumerBridgeToObject.prototype.startsWithCaseInsensitive = function (col, val) {
|
|
843
848
|
var v = this.row[this.dbNames.$dbNameOf(col)];
|
|
844
|
-
if (
|
|
849
|
+
if (v === undefined || v === null) {
|
|
845
850
|
this.ok = false;
|
|
846
851
|
return;
|
|
847
852
|
}
|
|
@@ -855,7 +860,7 @@ var FilterConsumerBridgeToObject = /** @class */ (function () {
|
|
|
855
860
|
};
|
|
856
861
|
FilterConsumerBridgeToObject.prototype.endsWithCaseInsensitive = function (col, val) {
|
|
857
862
|
var v = this.row[this.dbNames.$dbNameOf(col)];
|
|
858
|
-
if (
|
|
863
|
+
if (v === undefined || v === null) {
|
|
859
864
|
this.ok = false;
|
|
860
865
|
return;
|
|
861
866
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RestDataProviderHttpProvider } from '../data-interfaces.js';
|
|
2
2
|
export declare class RestDataProviderHttpProviderUsingFetch implements RestDataProviderHttpProvider {
|
|
3
3
|
private fetch?;
|
|
4
4
|
constructor(fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>) | undefined);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RestDataProviderHttpProviderUsingFetch = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var data_interfaces_js_1 = require("../data-interfaces.js");
|
|
6
|
+
var remult3_js_1 = require("../remult3/remult3.js");
|
|
5
7
|
var retry_js_1 = require("./retry.js");
|
|
6
8
|
var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
7
9
|
function RestDataProviderHttpProviderUsingFetch(fetch) {
|
|
@@ -43,7 +45,7 @@ var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
|
43
45
|
method: 'post',
|
|
44
46
|
body: JSON.stringify(data),
|
|
45
47
|
});
|
|
46
|
-
})];
|
|
48
|
+
}, { read: (0, retry_js_1.isReadPost)(url) })];
|
|
47
49
|
case 1: return [2 /*return*/, _a.sent()];
|
|
48
50
|
}
|
|
49
51
|
});
|
|
@@ -106,14 +108,19 @@ function onSuccess(response) {
|
|
|
106
108
|
throw response
|
|
107
109
|
.json()
|
|
108
110
|
.then(function (x) {
|
|
109
|
-
return tslib_1.__assign(tslib_1.__assign({}, x), { message: x.message || response.statusText, url: response.url, status: response.status });
|
|
111
|
+
return fetchError(tslib_1.__assign(tslib_1.__assign({}, x), { message: x.message || response.statusText, url: response.url, status: response.status }));
|
|
110
112
|
})
|
|
111
113
|
.catch(function () {
|
|
112
|
-
throw {
|
|
114
|
+
throw fetchError({
|
|
113
115
|
message: response.statusText,
|
|
114
116
|
url: response.url,
|
|
115
117
|
status: response.status,
|
|
116
|
-
};
|
|
118
|
+
});
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
121
|
}
|
|
122
|
+
function fetchError(info) {
|
|
123
|
+
return remult3_js_1.flags.clientErrorsAsEntityError
|
|
124
|
+
? new data_interfaces_js_1.EntityError(tslib_1.__assign(tslib_1.__assign({}, info), { httpStatusCode: info.status }))
|
|
125
|
+
: info;
|
|
126
|
+
}
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReadPost = void 0;
|
|
3
4
|
exports.retry = retry;
|
|
4
5
|
var tslib_1 = require("tslib");
|
|
5
6
|
var remult3_js_1 = require("../remult3/remult3.js");
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
// These mean the proxy never reached the server, so any request is safe to send again.
|
|
8
|
+
var isUnreachable = function (err) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
return ((_a = err.message) === null || _a === void 0 ? void 0 : _a.startsWith('Error occurred while trying to proxy')) ||
|
|
11
|
+
((_b = err.message) === null || _b === void 0 ? void 0 : _b.startsWith('Error occured while trying to proxy')) ||
|
|
12
|
+
((_c = err.message) === null || _c === void 0 ? void 0 : _c.includes('http proxy error'));
|
|
13
|
+
};
|
|
14
|
+
// The server may have run the request before failing, so only reads are safe to send again.
|
|
15
|
+
var isServerFailure = function (err) { var _a; return ((_a = err.message) === null || _a === void 0 ? void 0 : _a.startsWith('Gateway Timeout')) || err.status == 500; };
|
|
16
|
+
function retry(what_1) {
|
|
17
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (what, options) {
|
|
8
18
|
var i, err_1;
|
|
9
|
-
|
|
10
|
-
return tslib_1.__generator(this, function (
|
|
11
|
-
switch (
|
|
19
|
+
if (options === void 0) { options = { read: true }; }
|
|
20
|
+
return tslib_1.__generator(this, function (_a) {
|
|
21
|
+
switch (_a.label) {
|
|
12
22
|
case 0:
|
|
13
23
|
i = 0;
|
|
14
|
-
|
|
24
|
+
_a.label = 1;
|
|
15
25
|
case 1:
|
|
16
26
|
if (!true) return [3 /*break*/, 8];
|
|
17
|
-
|
|
27
|
+
_a.label = 2;
|
|
18
28
|
case 2:
|
|
19
|
-
|
|
29
|
+
_a.trys.push([2, 4, , 7]);
|
|
20
30
|
return [4 /*yield*/, what()];
|
|
21
|
-
case 3: return [2 /*return*/,
|
|
31
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
22
32
|
case 4:
|
|
23
|
-
err_1 =
|
|
24
|
-
if (!(((
|
|
25
|
-
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith('Error occured while trying to proxy')) ||
|
|
26
|
-
((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes('http proxy error')) ||
|
|
27
|
-
((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith('Gateway Timeout')) ||
|
|
28
|
-
err_1.status == 500) &&
|
|
33
|
+
err_1 = _a.sent();
|
|
34
|
+
if (!((isUnreachable(err_1) || (options.read && isServerFailure(err_1))) &&
|
|
29
35
|
i++ < remult3_js_1.flags.error500RetryCount)) return [3 /*break*/, 6];
|
|
30
36
|
return [4 /*yield*/, new Promise(function (res, req) {
|
|
31
37
|
setTimeout(function () {
|
|
@@ -33,7 +39,7 @@ function retry(what) {
|
|
|
33
39
|
}, 500);
|
|
34
40
|
})];
|
|
35
41
|
case 5:
|
|
36
|
-
|
|
42
|
+
_a.sent();
|
|
37
43
|
return [3 /*break*/, 1];
|
|
38
44
|
case 6: throw err_1;
|
|
39
45
|
case 7: return [3 /*break*/, 1];
|
|
@@ -42,3 +48,7 @@ function retry(what) {
|
|
|
42
48
|
});
|
|
43
49
|
});
|
|
44
50
|
}
|
|
51
|
+
// Finds with a long filter, counts and aggregates are POSTs too, but they only read.
|
|
52
|
+
var readActions = /[?&]__action=(?:(?:get|query|groupBy|count)(?:&|$)|liveQuery-)/;
|
|
53
|
+
var isReadPost = function (url) { return readActions.test(url); };
|
|
54
|
+
exports.isReadPost = isReadPost;
|
|
@@ -4,6 +4,7 @@ import type { FieldMetadata } from '../column-interfaces.js';
|
|
|
4
4
|
import type { CustomSqlFilterBuilderFunction, EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request.js';
|
|
5
5
|
import { type EntityFilter, type EntityMetadata, type FindOptions, type GroupByOptions, type GroupByResult, type MembersOnly, type NumericKeys, type Repository } from '../remult3/remult3.js';
|
|
6
6
|
import type { RepositoryOverloads } from '../remult3/RepositoryImplementation.js';
|
|
7
|
+
import type { NativeNullSort } from '../sort.js';
|
|
7
8
|
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from '../../migrations/migration-types.js';
|
|
8
9
|
/**
|
|
9
10
|
* A DataProvider for Sql Databases
|
|
@@ -39,6 +40,7 @@ export declare class SqlDatabase implements DataProvider, HasWrapIdentifier, Has
|
|
|
39
40
|
*/
|
|
40
41
|
wrapIdentifier: (name: string) => string;
|
|
41
42
|
get jsonColumnStorage(): JsonColumnStorage;
|
|
43
|
+
get nativeNullSort(): NativeNullSort;
|
|
42
44
|
ensureSchema(entities: EntityMetadata[]): Promise<void>;
|
|
43
45
|
/**
|
|
44
46
|
* Gets the entity data provider.
|
|
@@ -131,8 +133,10 @@ export interface RawSelectOptions {
|
|
|
131
133
|
}
|
|
132
134
|
export declare function jsonColumnStorageOf(r: Repository<any>): JsonColumnStorage;
|
|
133
135
|
export declare function getRowAfterUpdate<entityType>(meta: EntityMetadata<entityType>, dataProvider: EntityDataProvider, data: any, id: any, operation: string): any;
|
|
136
|
+
/** Writes the NULL order only on a nullable column, where NullSort differs from the database's own. */
|
|
137
|
+
export declare function orderBySql(expr: string, isDescending: boolean | undefined, nullable: boolean, native: NativeNullSort): string;
|
|
134
138
|
/** The select that `find` runs, and the mapping of one result row to field values. With `aliasColumns`, every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
|
|
135
|
-
export declare function buildFindSql(entity: EntityMetadata, options: EntityDataProviderFindOptions | undefined, e: EntityDbNamesBase, r: SqlCommandWithParameters,
|
|
139
|
+
export declare function buildFindSql(entity: EntityMetadata, options: EntityDataProviderFindOptions | undefined, e: EntityDbNamesBase, r: SqlCommandWithParameters, nativeNullSort: NativeNullSort, limitSyntax: (limit: number, offset: number) => string, { aliasColumns, jsonColumnStorage, }?: {
|
|
136
140
|
aliasColumns?: boolean;
|
|
137
141
|
jsonColumnStorage?: JsonColumnStorage;
|
|
138
142
|
}): Promise<{
|
|
@@ -141,9 +145,9 @@ export declare function buildFindSql(entity: EntityMetadata, options: EntityData
|
|
|
141
145
|
/** `valueAt` reads one column of a result row, by its position in the select or by its alias (the field key). */
|
|
142
146
|
toResult(valueAt: (indexInSelect: number, alias: string) => any): any;
|
|
143
147
|
}>;
|
|
144
|
-
export declare function groupByImpl(options: EntityDataProviderGroupByOptions | undefined, e: EntityDbNamesBase, r: SqlCommand,
|
|
148
|
+
export declare function groupByImpl(options: EntityDataProviderGroupByOptions | undefined, e: EntityDbNamesBase, r: SqlCommand, nativeNullSort: NativeNullSort, limitSyntax: (limit: number, offset: number) => string, jsonColumnStorage?: JsonColumnStorage): Promise<any[]>;
|
|
145
149
|
/** The select that `groupBy` runs, and the mapping of one result row back to a `GroupByResult`. Every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
|
|
146
|
-
export declare function buildGroupBySql(options: EntityDataProviderGroupByOptions | undefined, e: EntityDbNamesBase, r: SqlCommandWithParameters,
|
|
150
|
+
export declare function buildGroupBySql(options: EntityDataProviderGroupByOptions | undefined, e: EntityDbNamesBase, r: SqlCommandWithParameters, nativeNullSort: NativeNullSort, limitSyntax: (limit: number, offset: number) => string, jsonColumnStorage?: JsonColumnStorage): Promise<{
|
|
147
151
|
select: string;
|
|
148
152
|
/** `valueAt` reads one column of a result row, by its position in the select or by its alias. */
|
|
149
153
|
toResult(valueAt: (indexInSelect: number, alias: string) => any): any;
|