remult 0.13.29 → 0.14.1
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/remult-express.d.ts +5 -1
- package/remult-express.js +16 -1
- package/remult-middleware.d.ts +2 -0
- package/remult-middleware.js +69 -0
- package/server/expressBridge.d.ts +40 -14
- package/server/expressBridge.js +21 -28
- package/src/column-interfaces.d.ts +3 -3
- package/src/entity.d.ts +2 -2
- package/src/remult3/RepositoryImplementation.d.ts +6 -5
- package/src/remult3/RepositoryImplementation.js +6 -5
- package/src/remult3/remult3.d.ts +8 -3
package/package.json
CHANGED
package/remult-express.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { RemultMiddlewareOptions } from './server/expressBridge';
|
|
2
|
+
export declare function remultExpress(options?: RemultMiddlewareOptions & {
|
|
3
|
+
bodyParser?: boolean;
|
|
4
|
+
bodySizeLimit?: string;
|
|
5
|
+
}): import("./server/expressBridge").RemultExpressBridge;
|
package/remult-express.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.remultExpress = void 0;
|
|
4
|
+
var express = require("express");
|
|
4
5
|
var expressBridge_1 = require("./server/expressBridge");
|
|
5
|
-
|
|
6
|
+
function remultExpress(options) {
|
|
7
|
+
var app = express.Router();
|
|
8
|
+
if (!options) {
|
|
9
|
+
options = {};
|
|
10
|
+
}
|
|
11
|
+
if (options.bodySizeLimit === undefined) {
|
|
12
|
+
options.bodySizeLimit = '10mb';
|
|
13
|
+
}
|
|
14
|
+
if ((options === null || options === void 0 ? void 0 : options.bodyParser) !== false) {
|
|
15
|
+
app.use(express.json({ limit: options.bodySizeLimit }));
|
|
16
|
+
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
17
|
+
}
|
|
18
|
+
return expressBridge_1.remultMiddlewareBase(app, options);
|
|
19
|
+
}
|
|
20
|
+
exports.remultExpress = remultExpress;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remultMiddleware = void 0;
|
|
4
|
+
var expressBridge_1 = require("./server/expressBridge");
|
|
5
|
+
function remultMiddleware(options) {
|
|
6
|
+
var m = new middleware();
|
|
7
|
+
var app = Object.assign(m, function (req, res, next) { return m.handleRequest(req, res, next); });
|
|
8
|
+
return expressBridge_1.remultMiddlewareBase(app, options);
|
|
9
|
+
}
|
|
10
|
+
exports.remultMiddleware = remultMiddleware;
|
|
11
|
+
var middleware = /** @class */ (function () {
|
|
12
|
+
function middleware() {
|
|
13
|
+
this.map = new Map();
|
|
14
|
+
}
|
|
15
|
+
middleware.prototype.route = function (path) {
|
|
16
|
+
//consider using:
|
|
17
|
+
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
18
|
+
//* https://github.com/pillarjs/path-to-regexp
|
|
19
|
+
var r = path.toLowerCase();
|
|
20
|
+
var m = new Map();
|
|
21
|
+
this.map.set(r, m);
|
|
22
|
+
var route = {
|
|
23
|
+
get: function (h) {
|
|
24
|
+
m.set("get", h);
|
|
25
|
+
return route;
|
|
26
|
+
},
|
|
27
|
+
put: function (h) {
|
|
28
|
+
m.set("put", h);
|
|
29
|
+
return route;
|
|
30
|
+
},
|
|
31
|
+
post: function (h) {
|
|
32
|
+
m.set("post", h);
|
|
33
|
+
return route;
|
|
34
|
+
},
|
|
35
|
+
delete: function (h) {
|
|
36
|
+
m.set("delete", h);
|
|
37
|
+
return route;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return route;
|
|
41
|
+
};
|
|
42
|
+
middleware.prototype.handleRequest = function (req, res, next) {
|
|
43
|
+
var lowerPath = req.path.toLowerCase();
|
|
44
|
+
var m = this.map.get(lowerPath);
|
|
45
|
+
if (m) {
|
|
46
|
+
var h = m.get(req.method.toLowerCase());
|
|
47
|
+
if (h) {
|
|
48
|
+
h(req, res, next);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var idPosition = req.path.lastIndexOf('/');
|
|
53
|
+
if (idPosition >= 0) {
|
|
54
|
+
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
55
|
+
m = this.map.get(lowerPath);
|
|
56
|
+
if (m) {
|
|
57
|
+
var h = m.get(req.method.toLowerCase());
|
|
58
|
+
if (h) {
|
|
59
|
+
req.params.id = req.path.substring(idPosition + 1);
|
|
60
|
+
h(req, res, next);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
console.log(req.path);
|
|
66
|
+
next();
|
|
67
|
+
};
|
|
68
|
+
return middleware;
|
|
69
|
+
}());
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { DataProvider, Remult, IdEntity } from '../';
|
|
2
|
-
import * as express from 'express';
|
|
3
2
|
import { Repository } from '../src/remult3';
|
|
4
3
|
import { queuedJobInfoResponse } from '../src/server-action';
|
|
5
4
|
import { DataApi, DataApiRequest, DataApiResponse } from '../src/data-api';
|
|
6
5
|
import { AllowedForInstance } from '../src/context';
|
|
7
6
|
import { ClassType } from '../classType';
|
|
8
|
-
export declare
|
|
7
|
+
export declare type RemultMiddlewareOptions = {
|
|
9
8
|
/** Sets a database connection for Remult.
|
|
10
9
|
*
|
|
11
10
|
* @see [Connecting to a Database](https://remult.dev/docs/databases.html).
|
|
12
11
|
*/
|
|
13
12
|
dataProvider?: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
14
|
-
bodySizeLimit?: string;
|
|
15
13
|
disableAutoApi?: boolean;
|
|
16
14
|
queueStorage?: QueueStorage;
|
|
17
|
-
initRequest?: (remult: Remult, origReq:
|
|
15
|
+
initRequest?: (remult: Remult, origReq: GenericRequest) => Promise<void>;
|
|
18
16
|
initApi?: (remult: Remult) => void | Promise<void>;
|
|
19
17
|
logApiEndPoints?: boolean;
|
|
20
18
|
defaultGetLimit?: number;
|
|
@@ -22,42 +20,70 @@ export declare function remultExpress(options?: {
|
|
|
22
20
|
controllers?: ClassType<any>[];
|
|
23
21
|
bodyParser?: boolean;
|
|
24
22
|
rootPath?: string;
|
|
25
|
-
}
|
|
26
|
-
export
|
|
27
|
-
|
|
23
|
+
};
|
|
24
|
+
export declare function remultMiddlewareBase(app: GenericRouter, options: RemultMiddlewareOptions): RemultExpressBridge;
|
|
25
|
+
export interface RemultExpressBridge extends GenericRequestHandler {
|
|
26
|
+
getRemult(req: GenericRequest): Promise<Remult>;
|
|
28
27
|
openApiDoc(options: {
|
|
29
28
|
title: string;
|
|
30
29
|
}): any;
|
|
31
30
|
addArea(rootUrl: string): any;
|
|
32
31
|
}
|
|
32
|
+
export interface GenericRequest {
|
|
33
|
+
method: any;
|
|
34
|
+
path: any;
|
|
35
|
+
originalUrl: any;
|
|
36
|
+
query: any;
|
|
37
|
+
body: any;
|
|
38
|
+
params: any;
|
|
39
|
+
}
|
|
40
|
+
export interface GenericResponse {
|
|
41
|
+
status(arg0: number): any;
|
|
42
|
+
statusCode: number;
|
|
43
|
+
json(data: any): any;
|
|
44
|
+
writeHead(status: number): {
|
|
45
|
+
end: VoidFunction;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export declare type GenericRouter = GenericRequestHandler & {
|
|
49
|
+
route(path: string): SpecificRoute;
|
|
50
|
+
};
|
|
51
|
+
export declare type SpecificRoute = {
|
|
52
|
+
get(handler: GenericRequestHandler): SpecificRoute;
|
|
53
|
+
put(handler: GenericRequestHandler): SpecificRoute;
|
|
54
|
+
post(handler: GenericRequestHandler): SpecificRoute;
|
|
55
|
+
delete(handler: GenericRequestHandler): SpecificRoute;
|
|
56
|
+
};
|
|
57
|
+
export declare type GenericRequestHandler = (req: GenericRequest, res: GenericResponse, next: VoidFunction) => void;
|
|
33
58
|
declare class ExpressBridge {
|
|
34
59
|
private app;
|
|
35
60
|
queue: inProcessQueueHandler;
|
|
36
|
-
initRequest: (remult: Remult, origReq:
|
|
61
|
+
initRequest: (remult: Remult, origReq: GenericRequest) => Promise<void>;
|
|
37
62
|
dataProvider: DataProvider | Promise<DataProvider>;
|
|
38
63
|
openApiDoc(options: {
|
|
39
64
|
title: string;
|
|
65
|
+
version?: string;
|
|
40
66
|
}): any;
|
|
41
67
|
backendMethodsOpenApi: {
|
|
42
68
|
path: string;
|
|
43
69
|
allowed: AllowedForInstance<any>;
|
|
44
70
|
tag: string;
|
|
45
71
|
}[];
|
|
46
|
-
constructor(app:
|
|
72
|
+
constructor(app: GenericRouter, queue: inProcessQueueHandler, initRequest: (remult: Remult, origReq: GenericRequest) => Promise<void>, dataProvider: DataProvider | Promise<DataProvider>);
|
|
47
73
|
logApiEndPoints: boolean;
|
|
48
74
|
private firstArea;
|
|
49
75
|
addArea(rootUrl: string): SiteArea;
|
|
50
|
-
getRemult(req?:
|
|
76
|
+
getRemult(req?: GenericRequest): Promise<Remult>;
|
|
51
77
|
}
|
|
52
78
|
export declare class SiteArea {
|
|
53
79
|
private bridge;
|
|
54
80
|
private app;
|
|
55
81
|
private rootUrl;
|
|
56
82
|
private logApiEndpoints;
|
|
57
|
-
constructor(bridge: ExpressBridge, app:
|
|
83
|
+
constructor(bridge: ExpressBridge, app: GenericRouter, rootUrl: string, logApiEndpoints: boolean);
|
|
58
84
|
add(key: string, dataApiFactory: ((req: Remult) => DataApi)): void;
|
|
59
|
-
process(what: (remult: Remult, myReq: DataApiRequest, myRes: DataApiResponse, origReq:
|
|
60
|
-
getRemult(req:
|
|
85
|
+
process(what: (remult: Remult, myReq: DataApiRequest, myRes: DataApiResponse, origReq: GenericRequest) => Promise<void>): (req: GenericRequest, res: GenericResponse) => Promise<void>;
|
|
86
|
+
getRemult(req: GenericRequest): Promise<Remult>;
|
|
61
87
|
initQueue(): void;
|
|
62
88
|
addAction(action: {
|
|
63
89
|
__register: (reg: (url: string, queue: boolean, allowed: AllowedForInstance<any>, what: ((data: any, req: Remult, res: DataApiResponse) => void)) => void) => void;
|
|
@@ -66,7 +92,7 @@ export declare class SiteArea {
|
|
|
66
92
|
export declare class ExpressRequestBridgeToDataApiRequest implements DataApiRequest {
|
|
67
93
|
private r;
|
|
68
94
|
get(key: string): any;
|
|
69
|
-
constructor(r:
|
|
95
|
+
constructor(r: GenericRequest);
|
|
70
96
|
}
|
|
71
97
|
declare class inProcessQueueHandler {
|
|
72
98
|
private storage;
|
package/server/expressBridge.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JobsInQueueEntity = exports.EntityQueueStorage = exports.ExpressRequestBridgeToDataApiRequest = exports.SiteArea = exports.
|
|
3
|
+
exports.JobsInQueueEntity = exports.EntityQueueStorage = exports.ExpressRequestBridgeToDataApiRequest = exports.SiteArea = exports.remultMiddlewareBase = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var __1 = require("../");
|
|
6
|
-
var express = require("express");
|
|
7
6
|
var register_actions_on_server_1 = require("./register-actions-on-server");
|
|
8
7
|
var register_entities_on_server_1 = require("./register-entities-on-server");
|
|
9
8
|
var JsonEntityFileStorage_1 = require("./JsonEntityFileStorage");
|
|
@@ -12,9 +11,8 @@ var remult3_1 = require("../src/remult3");
|
|
|
12
11
|
var server_action_1 = require("../src/server-action");
|
|
13
12
|
var data_api_1 = require("../src/data-api");
|
|
14
13
|
var context_1 = require("../src/context");
|
|
15
|
-
function
|
|
14
|
+
function remultMiddlewareBase(app, options) {
|
|
16
15
|
var _this = this;
|
|
17
|
-
var app = express.Router();
|
|
18
16
|
if (!options) {
|
|
19
17
|
options = {};
|
|
20
18
|
}
|
|
@@ -22,16 +20,9 @@ function remultExpress(options) {
|
|
|
22
20
|
if (options.defaultGetLimit) {
|
|
23
21
|
data_api_1.DataApi.defaultGetLimit = options.defaultGetLimit;
|
|
24
22
|
}
|
|
25
|
-
if (options.bodySizeLimit === undefined) {
|
|
26
|
-
options.bodySizeLimit = '10mb';
|
|
27
|
-
}
|
|
28
23
|
if (!options.queueStorage) {
|
|
29
24
|
options.queueStorage = new InMemoryQueueStorage();
|
|
30
25
|
}
|
|
31
|
-
if ((options === null || options === void 0 ? void 0 : options.bodyParser) !== false) {
|
|
32
|
-
app.use(express.json({ limit: options.bodySizeLimit }));
|
|
33
|
-
app.use(express.urlencoded({ extended: true, limit: options.bodySizeLimit }));
|
|
34
|
-
}
|
|
35
26
|
var dataProvider;
|
|
36
27
|
if (typeof options.dataProvider === "function") {
|
|
37
28
|
dataProvider = options.dataProvider();
|
|
@@ -79,7 +70,7 @@ function remultExpress(options) {
|
|
|
79
70
|
addArea: function (x) { return bridge.addArea(x); }
|
|
80
71
|
});
|
|
81
72
|
}
|
|
82
|
-
exports.
|
|
73
|
+
exports.remultMiddlewareBase = remultMiddlewareBase;
|
|
83
74
|
var ExpressBridge = /** @class */ (function () {
|
|
84
75
|
function ExpressBridge(app, queue, initRequest, dataProvider) {
|
|
85
76
|
this.app = app;
|
|
@@ -93,11 +84,14 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
93
84
|
ExpressBridge.prototype.openApiDoc = function (options) {
|
|
94
85
|
var e_1, _a, e_2, _b;
|
|
95
86
|
var r = new __1.Remult();
|
|
87
|
+
if (!options.version)
|
|
88
|
+
options.version = "1.0.0";
|
|
96
89
|
var spec = {
|
|
97
|
-
info: { title: options.title },
|
|
90
|
+
info: { title: options.title, version: options.version },
|
|
98
91
|
openapi: "3.0.0",
|
|
99
92
|
//swagger: "2.0",
|
|
100
93
|
"components": {
|
|
94
|
+
"schemas": {},
|
|
101
95
|
"securitySchemes": {
|
|
102
96
|
"bearerAuth": {
|
|
103
97
|
"scheme": "bearer",
|
|
@@ -106,8 +100,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
106
100
|
}
|
|
107
101
|
}
|
|
108
102
|
},
|
|
109
|
-
paths: {}
|
|
110
|
-
definitions: {}
|
|
103
|
+
paths: {}
|
|
111
104
|
};
|
|
112
105
|
var validationError = {
|
|
113
106
|
"400": {
|
|
@@ -115,7 +108,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
115
108
|
"content": {
|
|
116
109
|
"application/json": {
|
|
117
110
|
"schema": {
|
|
118
|
-
"$ref": "#/
|
|
111
|
+
"$ref": "#/components/schemas/InvalidResponse"
|
|
119
112
|
}
|
|
120
113
|
}
|
|
121
114
|
}
|
|
@@ -182,12 +175,12 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
182
175
|
}
|
|
183
176
|
finally { if (e_3) throw e_3.error; }
|
|
184
177
|
}
|
|
185
|
-
spec.
|
|
178
|
+
spec.components.schemas[key] = {
|
|
186
179
|
type: "object",
|
|
187
180
|
properties: properties
|
|
188
181
|
};
|
|
189
182
|
var definition = {
|
|
190
|
-
"$ref": "#/
|
|
183
|
+
"$ref": "#/components/schemas/" + key
|
|
191
184
|
};
|
|
192
185
|
var secure = function (condition, def, item) {
|
|
193
186
|
item.tags = [meta.key];
|
|
@@ -206,28 +199,28 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
206
199
|
"description": "limit the number of returned rows, default 100",
|
|
207
200
|
"required": false,
|
|
208
201
|
"style": "simple",
|
|
209
|
-
"type": "
|
|
202
|
+
"schema": { "type": "integer" }
|
|
210
203
|
},
|
|
211
204
|
{
|
|
212
205
|
"name": "_page",
|
|
213
206
|
"in": "query",
|
|
214
207
|
"description": "to be used for paging",
|
|
215
208
|
"required": false,
|
|
216
|
-
"type": "
|
|
209
|
+
"schema": { "type": "integer" }
|
|
217
210
|
},
|
|
218
211
|
{
|
|
219
212
|
"name": "_sort",
|
|
220
213
|
"in": "query",
|
|
221
214
|
"description": "the columns to sort on",
|
|
222
215
|
"required": false,
|
|
223
|
-
"type": "string"
|
|
216
|
+
"schema": { "type": "string" }
|
|
224
217
|
},
|
|
225
218
|
{
|
|
226
219
|
"name": "_order",
|
|
227
220
|
"in": "query",
|
|
228
221
|
"description": "the sort order to user for the columns in `_sort`",
|
|
229
222
|
"required": false,
|
|
230
|
-
"type": "string"
|
|
223
|
+
"schema": { "type": "string" }
|
|
231
224
|
}], parameters),
|
|
232
225
|
responses: {
|
|
233
226
|
"200": {
|
|
@@ -248,14 +241,14 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
248
241
|
"in": "path",
|
|
249
242
|
"description": "id of " + key,
|
|
250
243
|
"required": true,
|
|
251
|
-
"type": "string"
|
|
244
|
+
"schema": { "type": "string" },
|
|
252
245
|
};
|
|
253
246
|
var itemInBody = {
|
|
254
247
|
"requestBody": {
|
|
255
248
|
"content": {
|
|
256
249
|
"application/json": {
|
|
257
250
|
"schema": {
|
|
258
|
-
"$ref": "#/
|
|
251
|
+
"$ref": "#/components/schemas/" + key
|
|
259
252
|
}
|
|
260
253
|
}
|
|
261
254
|
}
|
|
@@ -269,7 +262,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
269
262
|
"content": {
|
|
270
263
|
"application/json": {
|
|
271
264
|
"schema": {
|
|
272
|
-
"$ref": "#/
|
|
265
|
+
"$ref": "#/components/schemas/" + key
|
|
273
266
|
}
|
|
274
267
|
}
|
|
275
268
|
}
|
|
@@ -282,7 +275,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
282
275
|
"content": {
|
|
283
276
|
"application/json": {
|
|
284
277
|
"schema": {
|
|
285
|
-
"$ref": "#/
|
|
278
|
+
"$ref": "#/components/schemas/" + key
|
|
286
279
|
}
|
|
287
280
|
}
|
|
288
281
|
}
|
|
@@ -299,7 +292,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
299
292
|
"content": {
|
|
300
293
|
"application/json": {
|
|
301
294
|
"schema": {
|
|
302
|
-
"$ref": "#/
|
|
295
|
+
"$ref": "#/components/schemas/" + key
|
|
303
296
|
}
|
|
304
297
|
}
|
|
305
298
|
}
|
|
@@ -378,7 +371,7 @@ var ExpressBridge = /** @class */ (function () {
|
|
|
378
371
|
}
|
|
379
372
|
finally { if (e_2) throw e_2.error; }
|
|
380
373
|
}
|
|
381
|
-
spec.
|
|
374
|
+
spec.components.schemas["InvalidResponse"] = {
|
|
382
375
|
"type": "object",
|
|
383
376
|
properties: {
|
|
384
377
|
"message": {
|
|
@@ -14,18 +14,18 @@ export interface FieldOptions<entityType = any, valueType = any> {
|
|
|
14
14
|
allowApiUpdate?: AllowedForInstance<entityType>;
|
|
15
15
|
/** An arrow function that'll be used to perform validations on it
|
|
16
16
|
* @example
|
|
17
|
-
*
|
|
17
|
+
* @Fields.string({
|
|
18
18
|
* validate: Validators.required
|
|
19
19
|
* })
|
|
20
20
|
* @example
|
|
21
|
-
*
|
|
21
|
+
* @Fields.string<Task>({
|
|
22
22
|
* validate: task=>{
|
|
23
23
|
* if (task.title.length<3)
|
|
24
24
|
* throw "Too Short";
|
|
25
25
|
* }
|
|
26
26
|
* })
|
|
27
27
|
* @example
|
|
28
|
-
*
|
|
28
|
+
* @Fields.string({
|
|
29
29
|
* validate: (_, fieldRef)=>{
|
|
30
30
|
* if (fieldRef.value.length<3)
|
|
31
31
|
* fieldRef.error = "Too Short";
|
package/src/entity.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface EntityOptions<entityType = any> {
|
|
|
29
29
|
apiPrefilter?: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>);
|
|
30
30
|
/** A filter that will be used for all queries from this entity both from the API and from within the backend.
|
|
31
31
|
* @example
|
|
32
|
-
*
|
|
32
|
+
* backendPrefilter: { archive:false }
|
|
33
33
|
* @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
|
|
34
34
|
*/
|
|
35
35
|
backendPrefilter?: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>);
|
|
@@ -45,7 +45,7 @@ export interface EntityOptions<entityType = any> {
|
|
|
45
45
|
* If the `error` property of the entity's ref or any of it's fields will be set, the save will be aborted and an exception will be thrown.
|
|
46
46
|
* this is the place to run logic that we want to run in any case before an entity is saved.
|
|
47
47
|
* @example
|
|
48
|
-
*
|
|
48
|
+
* @Entity<Task>("tasks", {
|
|
49
49
|
* saving: async task => {
|
|
50
50
|
* task.lastUpdated = new Date()
|
|
51
51
|
* }
|
|
@@ -256,11 +256,11 @@ export declare function getValueList<T>(type: ClassType<T>): T[];
|
|
|
256
256
|
* FieldOptions can be set in two ways:
|
|
257
257
|
* @example
|
|
258
258
|
* // as an object
|
|
259
|
-
*
|
|
259
|
+
* @Fields.string({ includeInApi:false })
|
|
260
260
|
* title='';
|
|
261
261
|
* @example
|
|
262
262
|
* // as an arrow function that receives `remult` as a parameter
|
|
263
|
-
*
|
|
263
|
+
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
264
264
|
* title='';
|
|
265
265
|
*/
|
|
266
266
|
export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType>, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
|
|
@@ -289,13 +289,14 @@ export declare function BuildEntity<entityType>(c: ClassType<entityType>, key: s
|
|
|
289
289
|
* @Fields.boolean()
|
|
290
290
|
* completed = false;
|
|
291
291
|
* }
|
|
292
|
-
*
|
|
292
|
+
* @note
|
|
293
|
+
* EntityOptions can be set in two ways:
|
|
293
294
|
* @example
|
|
294
295
|
* // as an object
|
|
295
|
-
*
|
|
296
|
+
* @Entity("tasks",{ allowApiCrud:true })
|
|
296
297
|
* @example
|
|
297
298
|
* // as an arrow function that receives `remult` as a parameter
|
|
298
|
-
*
|
|
299
|
+
* @Entity("tasks", (options,remult) => options.allowApiCrud = true)
|
|
299
300
|
*/
|
|
300
301
|
export declare function Entity<entityType>(key: string, ...options: (EntityOptions<entityType> | ((options: EntityOptions<entityType>, remult: Remult) => void))[]): (target: any) => any;
|
|
301
302
|
export declare class EntityBase {
|
|
@@ -2467,11 +2467,11 @@ exports.getValueList = getValueList;
|
|
|
2467
2467
|
* FieldOptions can be set in two ways:
|
|
2468
2468
|
* @example
|
|
2469
2469
|
* // as an object
|
|
2470
|
-
*
|
|
2470
|
+
* @Fields.string({ includeInApi:false })
|
|
2471
2471
|
* title='';
|
|
2472
2472
|
* @example
|
|
2473
2473
|
* // as an arrow function that receives `remult` as a parameter
|
|
2474
|
-
*
|
|
2474
|
+
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
2475
2475
|
* title='';
|
|
2476
2476
|
*/
|
|
2477
2477
|
function Field(valueType) {
|
|
@@ -2637,13 +2637,14 @@ exports.BuildEntity = BuildEntity;
|
|
|
2637
2637
|
* @Fields.boolean()
|
|
2638
2638
|
* completed = false;
|
|
2639
2639
|
* }
|
|
2640
|
-
*
|
|
2640
|
+
* @note
|
|
2641
|
+
* EntityOptions can be set in two ways:
|
|
2641
2642
|
* @example
|
|
2642
2643
|
* // as an object
|
|
2643
|
-
*
|
|
2644
|
+
* @Entity("tasks",{ allowApiCrud:true })
|
|
2644
2645
|
* @example
|
|
2645
2646
|
* // as an arrow function that receives `remult` as a parameter
|
|
2646
|
-
*
|
|
2647
|
+
* @Entity("tasks", (options,remult) => options.allowApiCrud = true)
|
|
2647
2648
|
*/
|
|
2648
2649
|
function Entity(key) {
|
|
2649
2650
|
var options = [];
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -112,7 +112,12 @@ export declare type OmitEB<T> = Omit<T, keyof import('./RepositoryImplementation
|
|
|
112
112
|
export interface Repository<entityType> {
|
|
113
113
|
/** returns a result array based on the provided options */
|
|
114
114
|
find(options?: FindOptions<entityType>): Promise<entityType[]>;
|
|
115
|
-
/** returns the first item that matchers the `where` condition
|
|
115
|
+
/** returns the first item that matchers the `where` condition
|
|
116
|
+
* @example
|
|
117
|
+
* await taskRepo.findFirst({ completed:false })
|
|
118
|
+
* @example
|
|
119
|
+
* await taskRepo.findFirst({ completed:false },{ createIfNotFound: true })
|
|
120
|
+
* */
|
|
116
121
|
findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>): Promise<entityType>;
|
|
117
122
|
/** returns the items that matches the idm the result is cached unless specified differently in the `options` parameter */
|
|
118
123
|
findId(id: entityType extends {
|
|
@@ -285,7 +290,7 @@ export interface QueryResult<entityType> {
|
|
|
285
290
|
[Symbol.asyncIterator](): {
|
|
286
291
|
next: () => Promise<IteratorResult<entityType, entityType>>;
|
|
287
292
|
};
|
|
288
|
-
/** returns the number of rows that match the query
|
|
293
|
+
/** returns the number of rows that match the query criteria */
|
|
289
294
|
count(): Promise<number>;
|
|
290
295
|
/** Returns a `Paginator` object that is used for efficient paging */
|
|
291
296
|
paginator(): Promise<Paginator<entityType>>;
|
|
@@ -300,7 +305,7 @@ export interface Paginator<entityType> {
|
|
|
300
305
|
items: entityType[];
|
|
301
306
|
/** True if next page exists */
|
|
302
307
|
hasNextPage: boolean;
|
|
303
|
-
/**
|
|
308
|
+
/** Gets the next page in the `query`'s result set */
|
|
304
309
|
nextPage(): Promise<Paginator<entityType>>;
|
|
305
310
|
/** the count of the total items in the `query`'s result */
|
|
306
311
|
count(): Promise<number>;
|