remult 3.0.6-next.0 → 3.0.6
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/graphql.js +3 -3
- package/esm/index.js +7 -1
- package/esm/remult-d1-http.js +32 -0
- package/esm/remult-d1.js +90 -0
- package/esm/remult-express.js +4 -1
- package/esm/remult-fastify.js +9 -1
- package/esm/remult-fresh.js +5 -1
- package/esm/remult-hapi.js +7 -6
- package/esm/remult-hono.js +16 -14
- package/esm/remult-next.js +14 -8
- package/esm/remult-nuxt.js +7 -4
- package/esm/remult-solid-start.js +9 -6
- package/esm/remult-sveltekit.js +11 -8
- package/esm/server/index.js +4 -1
- package/esm/server/module.js +1 -1
- package/esm/server/remult-admin.js +9 -5
- package/esm/server/remult-api-server.js +14 -2
- package/esm/server/test-api-data-provider.js +4 -1
- package/esm/src/CompoundIdField.js +1 -0
- package/esm/src/context.js +9 -1
- package/esm/src/remult-static.js +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +37 -21
- package/graphql.js +3 -3
- package/index.d.ts +9 -1
- package/index.js +9 -2
- package/package.json +11 -1
- package/remult-d1-http.d.ts +16 -0
- package/remult-d1-http.js +46 -0
- package/remult-d1.d.ts +27 -0
- package/remult-d1.js +128 -0
- package/remult-express.js +4 -1
- package/remult-fastify.js +6 -1
- package/remult-fresh.js +5 -1
- package/remult-hapi.js +4 -7
- package/remult-hono.js +16 -14
- package/remult-next.js +14 -8
- package/remult-nuxt.js +7 -4
- package/remult-solid-start.js +9 -6
- package/remult-sveltekit.js +11 -8
- package/server/core.d.ts +1 -1
- package/server/index.js +4 -1
- package/server/module.js +1 -1
- package/server/remult-admin.js +9 -5
- package/server/remult-api-server.d.ts +24 -11
- package/server/remult-api-server.js +23 -11
- package/server/test-api-data-provider.js +4 -1
- package/src/CompoundIdField.d.ts +1 -0
- package/src/CompoundIdField.js +1 -0
- package/src/column-interfaces.d.ts +12 -0
- package/src/context.d.ts +15 -2
- package/src/context.js +9 -1
- package/src/entity.d.ts +5 -0
- package/src/remult-static.d.ts +1 -1
- package/src/remult-static.js +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +23 -17
- package/src/remult3/RepositoryImplementation.js +48 -22
- package/src/remult3/remult3.d.ts +8 -2
package/remult-sveltekit.js
CHANGED
|
@@ -8,14 +8,17 @@ function remultApi(options) {
|
|
|
8
8
|
var _this = this;
|
|
9
9
|
var result = (0, index_js_1.createRemultServer)(options, {
|
|
10
10
|
buildGenericRequestInfo: function (event) { return ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
internal: {
|
|
12
|
+
url: event.request.url,
|
|
13
|
+
method: event.request.method,
|
|
14
|
+
on: function (e, do1) {
|
|
15
|
+
if (e === 'close') {
|
|
16
|
+
;
|
|
17
|
+
event.locals['_tempOnClose'] = do1;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
18
20
|
},
|
|
21
|
+
public: { headers: event.request.headers },
|
|
19
22
|
}); },
|
|
20
23
|
getRequestBody: function (event) { return event.request.json(); },
|
|
21
24
|
});
|
|
@@ -88,7 +91,7 @@ function remultApi(options) {
|
|
|
88
91
|
status: responseFromRemultHandler.statusCode,
|
|
89
92
|
headers: {
|
|
90
93
|
'Content-Type': 'application/json',
|
|
91
|
-
}
|
|
94
|
+
},
|
|
92
95
|
});
|
|
93
96
|
return [2 /*return*/, res];
|
|
94
97
|
}
|
package/server/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { queuedJobInfo, QueueStorage, GenericRequestInfo, GenericRequestHandler, GenericResponse, GenericRouter, createRemultServerCore, RemultServerOptions, SpecificRoute, RemultServer, } from './remult-api-server.js';
|
|
1
|
+
export { type queuedJobInfo, type QueueStorage, type GenericRequestInfo, type GenericRequestHandler, type GenericResponse, type GenericRouter, createRemultServerCore, type RemultServerOptions, type SpecificRoute, type RemultServer, } from './remult-api-server.js';
|
|
2
2
|
export { JsonEntityFileStorage, JsonFileDataProvider, } from './JsonEntityFileStorage.js';
|
|
3
3
|
export { SseSubscriptionServer } from '../SseSubscriptionServer.js';
|
|
4
4
|
export { DataProviderLiveQueryStorage } from '../live-query/data-provider-live-query-storage.js';
|
package/server/index.js
CHANGED
|
@@ -21,7 +21,10 @@ function createRemultServer(options, serverCoreOptions) {
|
|
|
21
21
|
var _this = this;
|
|
22
22
|
(0, initAsyncHooks_js_1.initAsyncHooks)();
|
|
23
23
|
return (0, remult_api_server_js_1.createRemultServerCore)(options, serverCoreOptions || {
|
|
24
|
-
buildGenericRequestInfo: function (req) { return (
|
|
24
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
25
|
+
internal: (0, isOfType_js_1.cast)(req, 'method'),
|
|
26
|
+
public: { headers: new Headers(req.headers) },
|
|
27
|
+
}); },
|
|
25
28
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
26
29
|
return [2 /*return*/, req.body];
|
|
27
30
|
}); }); },
|
package/server/module.js
CHANGED
|
@@ -9,8 +9,8 @@ var Module = /** @class */ (function () {
|
|
|
9
9
|
this.priority = (_a = options.priority) !== null && _a !== void 0 ? _a : 0;
|
|
10
10
|
this.entities = options.entities;
|
|
11
11
|
this.controllers = options.controllers;
|
|
12
|
-
this.initRequest = options.initRequest;
|
|
13
12
|
this.initApi = options.initApi;
|
|
13
|
+
this.initRequest = options.initRequest;
|
|
14
14
|
this.modules = options.modules;
|
|
15
15
|
}
|
|
16
16
|
return Module;
|
package/server/remult-admin.js
CHANGED
|
@@ -12,7 +12,11 @@ function remultAdminHtml(options) {
|
|
|
12
12
|
var head = options.head, rootPath = options.rootPath, requireAuthToken = options.requireAuthToken, disableLiveQuery = options.disableLiveQuery;
|
|
13
13
|
return (0, get_remult_admin_html_js_1.getHtml)()
|
|
14
14
|
.replace('<!--PLACE_HERE_HEAD-->', head)
|
|
15
|
-
.replace('<!--PLACE_HERE_BODY-->', "<script>\n window.optionsFromServer = ".concat(JSON.stringify({
|
|
15
|
+
.replace('<!--PLACE_HERE_BODY-->', "<script>\n window.optionsFromServer = ".concat(JSON.stringify({
|
|
16
|
+
rootPath: rootPath,
|
|
17
|
+
requireAuthToken: requireAuthToken,
|
|
18
|
+
disableLiveQuery: disableLiveQuery,
|
|
19
|
+
}), "\n</script>"));
|
|
16
20
|
}
|
|
17
21
|
function buildEntityInfo(options) {
|
|
18
22
|
var e_1, _a;
|
|
@@ -68,7 +72,7 @@ function buildEntityInfo(options) {
|
|
|
68
72
|
}
|
|
69
73
|
else if (info.type === 'toMany') {
|
|
70
74
|
if (relRepo.metadata.apiReadAllowed) {
|
|
71
|
-
relations.push(tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, key: x.key, caption: x.
|
|
75
|
+
relations.push(tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, key: x.key, caption: x.label }));
|
|
72
76
|
}
|
|
73
77
|
return "continue";
|
|
74
78
|
}
|
|
@@ -78,7 +82,7 @@ function buildEntityInfo(options) {
|
|
|
78
82
|
readOnly: !x.apiUpdateAllowed(),
|
|
79
83
|
values: (0, RepositoryImplementation_js_1.getValueList)(x),
|
|
80
84
|
valFieldKey: valFieldKey,
|
|
81
|
-
caption: x.
|
|
85
|
+
caption: x.label,
|
|
82
86
|
relationToOne: relation,
|
|
83
87
|
inputType: x.inputType,
|
|
84
88
|
type: x.inputType === inputTypes_js_1.InputTypes.json
|
|
@@ -112,11 +116,11 @@ function buildEntityInfo(options) {
|
|
|
112
116
|
}
|
|
113
117
|
if (metadata.apiReadAllowed) {
|
|
114
118
|
var superKey = metadata.key;
|
|
115
|
-
var caption = metadata.
|
|
119
|
+
var caption = metadata.label;
|
|
116
120
|
var nbOfEntities = entities.filter(function (e) { return e.key === metadata.key; }).length;
|
|
117
121
|
if (nbOfEntities > 0) {
|
|
118
122
|
superKey = metadata.key + '_ext_' + nbOfEntities;
|
|
119
|
-
caption = metadata.
|
|
123
|
+
caption = metadata.label + '*'.repeat(nbOfEntities);
|
|
120
124
|
}
|
|
121
125
|
entities.push({
|
|
122
126
|
superKey: superKey,
|
|
@@ -99,16 +99,23 @@ export interface RemultServerOptions<RequestType> {
|
|
|
99
99
|
* @example
|
|
100
100
|
* import { Module } from 'remult/server'
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
102
|
+
* // create an analytics module
|
|
103
|
+
* const analytics = () => new Module({
|
|
104
|
+
* key: 'analytics',
|
|
105
|
+
* priority: 11, // Default: 0, Prioritized by ascending order.
|
|
106
|
+
* entities: [AnalyticsEvent],
|
|
107
|
+
* controllers: [AnalyticsController],
|
|
108
|
+
* initApi: () => console.log('analytics module initialized'),
|
|
109
|
+
* initRequest: () => {},
|
|
110
|
+
* modules: [] // You can nest modules
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* // use the module in the remultApi
|
|
114
|
+
* remultApi({
|
|
115
|
+
* modules: [
|
|
116
|
+
* analytics(),
|
|
117
|
+
* ]
|
|
118
|
+
* })
|
|
112
119
|
*/
|
|
113
120
|
modules?: Module<RequestType>[];
|
|
114
121
|
}
|
|
@@ -145,6 +152,9 @@ export type SpecificRoute<RequestType> = {
|
|
|
145
152
|
post(handler: GenericRequestHandler<RequestType>): SpecificRoute<RequestType>;
|
|
146
153
|
delete(handler: GenericRequestHandler<RequestType>): SpecificRoute<RequestType>;
|
|
147
154
|
};
|
|
155
|
+
export interface GenericRequest {
|
|
156
|
+
headers: Headers;
|
|
157
|
+
}
|
|
148
158
|
export interface GenericRequestInfo {
|
|
149
159
|
url?: string;
|
|
150
160
|
method?: any;
|
|
@@ -199,7 +209,10 @@ export declare class JobsInQueueEntity extends IdEntity {
|
|
|
199
209
|
progress: number;
|
|
200
210
|
}
|
|
201
211
|
export interface ServerCoreOptions<RequestType> {
|
|
202
|
-
buildGenericRequestInfo(req: RequestType):
|
|
212
|
+
buildGenericRequestInfo(req: RequestType): {
|
|
213
|
+
internal: GenericRequestInfo;
|
|
214
|
+
public: GenericRequest;
|
|
215
|
+
};
|
|
203
216
|
getRequestBody(req: RequestType): Promise<any>;
|
|
204
217
|
ignoreAsyncStorage?: boolean;
|
|
205
218
|
}
|
|
@@ -629,12 +629,14 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
629
629
|
RemultServerImplementation.prototype.process = function (what, doNotReuseInitRequest) {
|
|
630
630
|
var _this = this;
|
|
631
631
|
return function (req, origRes) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
632
|
-
var genReq, myReq, myRes, err_2;
|
|
632
|
+
var _a, genReq, genReqPublic, myReq, myRes, err_2;
|
|
633
633
|
var _this = this;
|
|
634
|
-
return tslib_1.__generator(this, function (
|
|
635
|
-
switch (
|
|
634
|
+
return tslib_1.__generator(this, function (_b) {
|
|
635
|
+
switch (_b.label) {
|
|
636
636
|
case 0:
|
|
637
|
-
|
|
637
|
+
_a = req
|
|
638
|
+
? this.coreOptions.buildGenericRequestInfo(req)
|
|
639
|
+
: { internal: {}, public: { headers: new Headers() } }, genReq = _a.internal, genReqPublic = _a.public;
|
|
638
640
|
if (req) {
|
|
639
641
|
if (!genReq.query) {
|
|
640
642
|
genReq.query = req['_tempQuery'];
|
|
@@ -644,13 +646,13 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
644
646
|
}
|
|
645
647
|
myReq = new RequestBridgeToDataApiRequest(genReq);
|
|
646
648
|
myRes = new ResponseBridgeToDataApiResponse(origRes, req, genReq, this.options.error);
|
|
647
|
-
|
|
649
|
+
_b.label = 1;
|
|
648
650
|
case 1:
|
|
649
|
-
|
|
651
|
+
_b.trys.push([1, 6, , 7]);
|
|
650
652
|
if (!(remult_static_js_1.remultStatic.asyncContext.isInInitRequest() &&
|
|
651
653
|
!doNotReuseInitRequest)) return [3 /*break*/, 3];
|
|
652
654
|
return [4 /*yield*/, what(remult_static_js_1.remultStatic.asyncContext.getStore().remult, myReq, myRes, genReq, origRes, req)];
|
|
653
|
-
case 2: return [2 /*return*/,
|
|
655
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
654
656
|
case 3: return [4 /*yield*/, this.runWithRemult(function (remult) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
655
657
|
var user, i, _initRequest;
|
|
656
658
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -659,6 +661,16 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
659
661
|
if (!req) return [3 /*break*/, 11];
|
|
660
662
|
;
|
|
661
663
|
remult.context.request = req;
|
|
664
|
+
remult.context.headers = {
|
|
665
|
+
get: function (key) { var _a; return (_a = genReqPublic.headers.get(key)) !== null && _a !== void 0 ? _a : undefined; },
|
|
666
|
+
getAll: function () {
|
|
667
|
+
var result = {};
|
|
668
|
+
genReqPublic.headers.forEach(function (value, key) {
|
|
669
|
+
result[key] = value;
|
|
670
|
+
});
|
|
671
|
+
return result;
|
|
672
|
+
},
|
|
673
|
+
};
|
|
662
674
|
remult_static_js_1.remultStatic.asyncContext.setInInitRequest(true);
|
|
663
675
|
_a.label = 1;
|
|
664
676
|
case 1:
|
|
@@ -712,11 +724,11 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
712
724
|
});
|
|
713
725
|
}); })];
|
|
714
726
|
case 4:
|
|
715
|
-
|
|
716
|
-
|
|
727
|
+
_b.sent();
|
|
728
|
+
_b.label = 5;
|
|
717
729
|
case 5: return [3 /*break*/, 7];
|
|
718
730
|
case 6:
|
|
719
|
-
err_2 =
|
|
731
|
+
err_2 = _b.sent();
|
|
720
732
|
if (origRes)
|
|
721
733
|
myRes.error(err_2, undefined);
|
|
722
734
|
else
|
|
@@ -1581,7 +1593,7 @@ var RouteImplementation = /** @class */ (function () {
|
|
|
1581
1593
|
RouteImplementation.prototype.middleware = function (origReq, res, next) {
|
|
1582
1594
|
var e_8, _a;
|
|
1583
1595
|
var _b;
|
|
1584
|
-
var req = this.coreOptions.buildGenericRequestInfo(origReq);
|
|
1596
|
+
var req = this.coreOptions.buildGenericRequestInfo(origReq).internal;
|
|
1585
1597
|
var theUrl = ((_b = req.url) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
1586
1598
|
if (theUrl.startsWith('/'))
|
|
1587
1599
|
//next sends a partial url '/api/tasks' and not the full url
|
|
@@ -21,7 +21,10 @@ function TestApiDataProvider(options) {
|
|
|
21
21
|
getRequestBody: function (req) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
22
22
|
return [2 /*return*/, req.body];
|
|
23
23
|
}); }); },
|
|
24
|
-
buildGenericRequestInfo: function (req) { return
|
|
24
|
+
buildGenericRequestInfo: function (req) { return ({
|
|
25
|
+
internal: req,
|
|
26
|
+
public: { headers: new Headers() },
|
|
27
|
+
}); },
|
|
25
28
|
ignoreAsyncStorage: true,
|
|
26
29
|
});
|
|
27
30
|
var lock = new AsyncLock();
|
package/src/CompoundIdField.d.ts
CHANGED
package/src/CompoundIdField.js
CHANGED
|
@@ -7,6 +7,11 @@ export interface FieldOptions<entityType = unknown, valueType = unknown> {
|
|
|
7
7
|
* <input placeholder={taskRepo.metadata.fields.title.caption}/>
|
|
8
8
|
*/
|
|
9
9
|
caption?: string;
|
|
10
|
+
/** A human readable name for the field. Can be used to achieve a consistent label for a field throughout the app
|
|
11
|
+
* @example
|
|
12
|
+
* <input placeholder={taskRepo.metadata.fields.title.label}/>
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
10
15
|
/** If it can store null in the database */
|
|
11
16
|
allowNull?: boolean;
|
|
12
17
|
/** If a value is required. Short-cut to say `validate: Validators.required`.
|
|
@@ -141,6 +146,12 @@ export interface FieldMetadata<valueType = unknown, entityType = unknown> {
|
|
|
141
146
|
* @see {@link FieldOptions#caption} for configuration details
|
|
142
147
|
*/
|
|
143
148
|
readonly caption: string;
|
|
149
|
+
/** A human readable label for the field. Can be used to achieve a consistent label for a field throughout the app
|
|
150
|
+
* @example
|
|
151
|
+
* <input placeholder={taskRepo.metadata.fields.title.label}/>
|
|
152
|
+
* @see {@link FieldOptions.label} for configuration details
|
|
153
|
+
*/
|
|
154
|
+
readonly label: string;
|
|
144
155
|
/** The name of the column in the database that holds the data for this field. If no name is set, the key will be used instead.
|
|
145
156
|
* @example
|
|
146
157
|
*
|
|
@@ -336,4 +347,5 @@ export declare function valueOrExpressionToValue<valueType>(f: ValueOrExpression
|
|
|
336
347
|
export interface ValueListItem {
|
|
337
348
|
id?: any;
|
|
338
349
|
caption?: any;
|
|
350
|
+
label?: any;
|
|
339
351
|
}
|
package/src/context.d.ts
CHANGED
|
@@ -90,7 +90,15 @@ export declare class Remult {
|
|
|
90
90
|
clearAllCache(): any;
|
|
91
91
|
/** A helper callback that is called whenever an entity is created. */
|
|
92
92
|
static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
|
|
93
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* context that can be used to store custom information that will be disposed as part of the `remult` object.
|
|
95
|
+
*
|
|
96
|
+
* `remult.context` is pre-filled in a framework-agnostic way with:
|
|
97
|
+
* - `headers.get(key: string)` _of request_
|
|
98
|
+
* - `headers.getAll()` _of request_
|
|
99
|
+
*
|
|
100
|
+
* Check out the [extensibility section](/docs/custom-options#enhancing-field-and-entity-definitions-with-custom-options) for more custom options.
|
|
101
|
+
*/
|
|
94
102
|
readonly context: RemultContext;
|
|
95
103
|
/** The api client that will be used by `remult` to perform calls to the `api` */
|
|
96
104
|
apiClient: ApiClient;
|
|
@@ -102,13 +110,18 @@ export type GetArguments<T> = T extends (...args: infer FirstArgument) => any ?
|
|
|
102
110
|
* To type it correctly, you can extend it with your own properties.
|
|
103
111
|
* @example
|
|
104
112
|
* import type express from 'express'
|
|
113
|
+
*
|
|
105
114
|
* declare module 'remult' {
|
|
106
115
|
* export interface RemultContext {
|
|
107
116
|
* request?: express.Request
|
|
108
117
|
* }
|
|
109
118
|
* }
|
|
110
|
-
|
|
119
|
+
*/
|
|
111
120
|
export interface RemultContext {
|
|
121
|
+
headers?: {
|
|
122
|
+
get: (key: string) => string | undefined;
|
|
123
|
+
getAll: () => Record<string, string>;
|
|
124
|
+
};
|
|
112
125
|
}
|
|
113
126
|
/**
|
|
114
127
|
* Interface for configuring the API client used by Remult to perform HTTP calls to the backend.
|
package/src/context.js
CHANGED
|
@@ -121,7 +121,15 @@ var Remult = /** @class */ (function () {
|
|
|
121
121
|
};
|
|
122
122
|
/* @internal*/
|
|
123
123
|
this.liveQuerySubscriber = new LiveQueryClient_js_1.LiveQueryClient(function () { return _this.apiClient; }, function () { var _a; return (_a = _this.user) === null || _a === void 0 ? void 0 : _a.id; });
|
|
124
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* context that can be used to store custom information that will be disposed as part of the `remult` object.
|
|
126
|
+
*
|
|
127
|
+
* `remult.context` is pre-filled in a framework-agnostic way with:
|
|
128
|
+
* - `headers.get(key: string)` _of request_
|
|
129
|
+
* - `headers.getAll()` _of request_
|
|
130
|
+
*
|
|
131
|
+
* Check out the [extensibility section](/docs/custom-options#enhancing-field-and-entity-definitions-with-custom-options) for more custom options.
|
|
132
|
+
*/
|
|
125
133
|
this.context = {};
|
|
126
134
|
/** The api client that will be used by `remult` to perform calls to the `api` */
|
|
127
135
|
this.apiClient = {
|
package/src/entity.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ import type { DataProvider } from './data-interfaces.js';
|
|
|
6
6
|
export interface EntityOptions<entityType = unknown> {
|
|
7
7
|
/**A human readable name for the entity */
|
|
8
8
|
caption?: string;
|
|
9
|
+
/** A human readable label for the entity. Can be used to achieve a consistent label for a field throughout the app
|
|
10
|
+
* @example
|
|
11
|
+
* <h1>Create a new item in {taskRepo.metadata.label}</h1>
|
|
12
|
+
*/
|
|
13
|
+
label?: string;
|
|
9
14
|
/**
|
|
10
15
|
* Determines if this Entity is available for get requests using Rest Api
|
|
11
16
|
* @description
|
package/src/remult-static.d.ts
CHANGED
package/src/remult-static.js
CHANGED
|
@@ -211,39 +211,43 @@ export declare class FieldRefImplementation<entityType, valueType> implements Fi
|
|
|
211
211
|
export declare const fieldOptionsEnricher: {
|
|
212
212
|
enrichFieldOptions: (options: FieldOptions) => void;
|
|
213
213
|
};
|
|
214
|
-
export declare const
|
|
214
|
+
export declare const LabelTransformer: {
|
|
215
215
|
/**
|
|
216
|
-
* Transforms the
|
|
216
|
+
* Transforms the label of a column based on custom rules or criteria.
|
|
217
217
|
*
|
|
218
218
|
* This method can be assigned an arrow function that dynamically alters the
|
|
219
|
-
*
|
|
220
|
-
* applying specific labeling conventions, or any other custom
|
|
219
|
+
* label of a column. It is particularly useful for internationalization,
|
|
220
|
+
* applying specific labeling conventions, or any other custom label transformation
|
|
221
221
|
* logic that your application requires.
|
|
222
222
|
*
|
|
223
223
|
* @param {Remult} remult - The Remult context, providing access to various framework features.
|
|
224
|
-
* @param {string} key - The key (name) of the field whose
|
|
225
|
-
* @param {string}
|
|
224
|
+
* @param {string} key - The key (name) of the field whose label is being transformed.
|
|
225
|
+
* @param {string} label - The original label of the field.
|
|
226
226
|
* @param {EntityMetadata<any>} entityMetaData - Metadata of the entity that the field belongs to.
|
|
227
|
-
* @returns {string} The transformed
|
|
228
|
-
* the original
|
|
227
|
+
* @returns {string} The transformed label for the field. If no transformation is applied,
|
|
228
|
+
* the original label is returned.
|
|
229
229
|
*
|
|
230
230
|
* @example
|
|
231
|
-
* // Example of translating a field
|
|
232
|
-
*
|
|
233
|
-
* remult, key,
|
|
231
|
+
* // Example of translating a field label to French
|
|
232
|
+
* LabelTransformer.transformLabel = (
|
|
233
|
+
* remult, key, label, entityMetaData
|
|
234
234
|
* ) => {
|
|
235
235
|
* if (key === 'firstName') {
|
|
236
236
|
* return 'Prénom'; // French translation for 'firstName'
|
|
237
237
|
* }
|
|
238
|
-
* return
|
|
238
|
+
* return label;
|
|
239
239
|
* };
|
|
240
240
|
*
|
|
241
241
|
* // Usage
|
|
242
|
-
* const
|
|
242
|
+
* const firstNameLabel = repo(Person).fields.firstName.label; // Returns 'Prénom'
|
|
243
243
|
*/
|
|
244
|
-
|
|
244
|
+
transformLabel: (remult: Remult, key: string, label: string, entityMetaData: EntityMetadata<any>) => string;
|
|
245
|
+
/**
|
|
246
|
+
* @obsolete use LabelTransformer.transformLabel instead
|
|
247
|
+
*/
|
|
248
|
+
transformCaption: (remult: Remult, key: string, label: string, entityMetaData: EntityMetadata<any>) => string;
|
|
245
249
|
};
|
|
246
|
-
export declare function
|
|
250
|
+
export declare function buildLabel(label: string | ((remult: Remult) => string) | undefined, key: string, remult: Remult, metaData: EntityMetadata<any>): string;
|
|
247
251
|
export declare class columnDefsImpl implements FieldMetadata {
|
|
248
252
|
private settings;
|
|
249
253
|
private entityDefs;
|
|
@@ -260,7 +264,8 @@ export declare class columnDefsImpl implements FieldMetadata {
|
|
|
260
264
|
readonly: boolean;
|
|
261
265
|
valueConverter: Required<ValueConverter<any>>;
|
|
262
266
|
allowNull: boolean;
|
|
263
|
-
|
|
267
|
+
label: string;
|
|
268
|
+
get caption(): string;
|
|
264
269
|
dbName: string;
|
|
265
270
|
inputType: string;
|
|
266
271
|
key: string;
|
|
@@ -285,7 +290,8 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
|
|
|
285
290
|
idMetadata: IdMetadata<T>;
|
|
286
291
|
fields: FieldsMetadata<T>;
|
|
287
292
|
dbName: string;
|
|
288
|
-
|
|
293
|
+
label: string;
|
|
294
|
+
get caption(): string;
|
|
289
295
|
}
|
|
290
296
|
export declare function FieldType<valueType = unknown>(...options: (FieldOptions<any, valueType> | ((options: FieldOptions<any, valueType>, remult: Remult) => void))[]): (target: any, context?: any) => any;
|
|
291
297
|
export declare function isAutoIncrement(f: FieldMetadata): boolean;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControllerBase = exports.EntityBase = exports.fieldOptionalValuesFunctionKey = exports.storableMember = exports.ValueListInfo = exports.columnDefsImpl = exports.
|
|
3
|
+
exports.ControllerBase = exports.EntityBase = exports.fieldOptionalValuesFunctionKey = exports.storableMember = exports.ValueListInfo = exports.columnDefsImpl = exports.LabelTransformer = exports.fieldOptionsEnricher = exports.FieldRefImplementation = exports.controllerRefImpl = exports.rowHelperImplementation = exports.RepositoryImplementation = void 0;
|
|
4
4
|
exports.createOldEntity = createOldEntity;
|
|
5
5
|
exports.getFields = getFields;
|
|
6
6
|
exports.getControllerRef = getControllerRef;
|
|
7
|
-
exports.
|
|
7
|
+
exports.buildLabel = buildLabel;
|
|
8
8
|
exports.FieldType = FieldType;
|
|
9
9
|
exports.isAutoIncrement = isAutoIncrement;
|
|
10
10
|
exports.ValueListFieldType = ValueListFieldType;
|
|
@@ -1955,7 +1955,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1955
1955
|
var col = _d.value;
|
|
1956
1956
|
if ((_b = this.errors) === null || _b === void 0 ? void 0 : _b[col.key]) {
|
|
1957
1957
|
error.message =
|
|
1958
|
-
this.fields[col.key].metadata.
|
|
1958
|
+
this.fields[col.key].metadata.label +
|
|
1959
1959
|
': ' +
|
|
1960
1960
|
this.errors[col.key];
|
|
1961
1961
|
this.error = error.message;
|
|
@@ -3334,23 +3334,26 @@ var FieldRefImplementation = /** @class */ (function () {
|
|
|
3334
3334
|
return FieldRefImplementation;
|
|
3335
3335
|
}());
|
|
3336
3336
|
exports.FieldRefImplementation = FieldRefImplementation;
|
|
3337
|
-
var
|
|
3338
|
-
|
|
3337
|
+
var tempLabelTransformer = {
|
|
3338
|
+
transformLabel: function (remult, key, label, entityMetaData) { return label; },
|
|
3339
|
+
set transformCaption(val) {
|
|
3340
|
+
this.transformLabel = val;
|
|
3341
|
+
},
|
|
3339
3342
|
};
|
|
3340
3343
|
exports.fieldOptionsEnricher = remult_static_js_1.remultStatic.fieldOptionsEnricher || {
|
|
3341
3344
|
enrichFieldOptions: function (options) { return options; },
|
|
3342
3345
|
};
|
|
3343
|
-
exports.
|
|
3344
|
-
(remult_static_js_1.remultStatic.
|
|
3345
|
-
function
|
|
3346
|
+
exports.LabelTransformer = remult_static_js_1.remultStatic.labelTransformer ||
|
|
3347
|
+
(remult_static_js_1.remultStatic.labelTransformer = tempLabelTransformer);
|
|
3348
|
+
function buildLabel(label, key, remult, metaData) {
|
|
3346
3349
|
var result = undefined;
|
|
3347
|
-
if (typeof
|
|
3350
|
+
if (typeof label === 'function') {
|
|
3348
3351
|
if (remult)
|
|
3349
|
-
result =
|
|
3352
|
+
result = label(remult);
|
|
3350
3353
|
}
|
|
3351
|
-
else if (
|
|
3352
|
-
result =
|
|
3353
|
-
result = exports.
|
|
3354
|
+
else if (label)
|
|
3355
|
+
result = label;
|
|
3356
|
+
result = exports.LabelTransformer.transformLabel(remult, key, result !== null && result !== void 0 ? result : '', metaData);
|
|
3354
3357
|
if (result)
|
|
3355
3358
|
return result;
|
|
3356
3359
|
if (key)
|
|
@@ -3360,7 +3363,7 @@ function buildCaption(caption, key, remult, metaData) {
|
|
|
3360
3363
|
var columnDefsImpl = /** @class */ (function () {
|
|
3361
3364
|
function columnDefsImpl(settings, entityDefs, remult) {
|
|
3362
3365
|
var _this = this;
|
|
3363
|
-
var _a;
|
|
3366
|
+
var _a, _b;
|
|
3364
3367
|
this.settings = settings;
|
|
3365
3368
|
this.entityDefs = entityDefs;
|
|
3366
3369
|
this.remult = remult;
|
|
@@ -3384,7 +3387,7 @@ var columnDefsImpl = /** @class */ (function () {
|
|
|
3384
3387
|
catch (err) {
|
|
3385
3388
|
var error = "".concat(String(prop), " failed for value ").concat(args === null || args === void 0 ? void 0 : args[0], ". Error: ").concat(typeof err === 'string' ? err : err.message);
|
|
3386
3389
|
throw new data_interfaces_js_1.EntityError({
|
|
3387
|
-
message: _this.
|
|
3390
|
+
message: _this.label + ': ' + error,
|
|
3388
3391
|
modelState: (_a = {},
|
|
3389
3392
|
_a[_this.key] = error,
|
|
3390
3393
|
_a),
|
|
@@ -3408,7 +3411,7 @@ var columnDefsImpl = /** @class */ (function () {
|
|
|
3408
3411
|
this.dbName = settings.dbName;
|
|
3409
3412
|
if (this.dbName == undefined)
|
|
3410
3413
|
this.dbName = settings.key;
|
|
3411
|
-
this.
|
|
3414
|
+
this.label = buildLabel((_b = settings.label) !== null && _b !== void 0 ? _b : settings.caption, settings.key, remult, entityDefs);
|
|
3412
3415
|
}
|
|
3413
3416
|
columnDefsImpl.prototype.apiUpdateAllowed = function (item) {
|
|
3414
3417
|
if (this.options.allowApiUpdate === undefined)
|
|
@@ -3438,6 +3441,13 @@ var columnDefsImpl = /** @class */ (function () {
|
|
|
3438
3441
|
});
|
|
3439
3442
|
});
|
|
3440
3443
|
};
|
|
3444
|
+
Object.defineProperty(columnDefsImpl.prototype, "caption", {
|
|
3445
|
+
get: function () {
|
|
3446
|
+
return this.label;
|
|
3447
|
+
},
|
|
3448
|
+
enumerable: false,
|
|
3449
|
+
configurable: true
|
|
3450
|
+
});
|
|
3441
3451
|
Object.defineProperty(columnDefsImpl.prototype, "dbReadOnly", {
|
|
3442
3452
|
get: function () {
|
|
3443
3453
|
return Boolean(this.settings.dbReadOnly);
|
|
@@ -3452,6 +3462,7 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
3452
3462
|
function EntityFullInfo(columnsInfo, entityInfo, remult, entityType, key) {
|
|
3453
3463
|
var _a, e_49, _b;
|
|
3454
3464
|
var _this = this;
|
|
3465
|
+
var _c;
|
|
3455
3466
|
this.entityInfo = entityInfo;
|
|
3456
3467
|
this.remult = remult;
|
|
3457
3468
|
this.entityType = entityType;
|
|
@@ -3562,7 +3573,7 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
3562
3573
|
finally { if (e_49) throw e_49.error; }
|
|
3563
3574
|
}
|
|
3564
3575
|
this.fields = r;
|
|
3565
|
-
this.
|
|
3576
|
+
this.label = buildLabel((_c = entityInfo.label) !== null && _c !== void 0 ? _c : entityInfo.caption, this.key, remult, this);
|
|
3566
3577
|
if (entityInfo.id) {
|
|
3567
3578
|
var r_2 = typeof entityInfo.id === 'string'
|
|
3568
3579
|
? this.fields.find(entityInfo.id)
|
|
@@ -3627,6 +3638,13 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
3627
3638
|
EntityFullInfo.prototype.getDbName = function () {
|
|
3628
3639
|
return (0, entityDbName_js_1.entityDbName)(this);
|
|
3629
3640
|
};
|
|
3641
|
+
Object.defineProperty(EntityFullInfo.prototype, "caption", {
|
|
3642
|
+
get: function () {
|
|
3643
|
+
return this.label;
|
|
3644
|
+
},
|
|
3645
|
+
enumerable: false,
|
|
3646
|
+
configurable: true
|
|
3647
|
+
});
|
|
3630
3648
|
return EntityFullInfo;
|
|
3631
3649
|
}());
|
|
3632
3650
|
function FieldType() {
|
|
@@ -3656,7 +3674,7 @@ function ValueListFieldType() {
|
|
|
3656
3674
|
FieldType.apply(void 0, tslib_1.__spreadArray([function (o) {
|
|
3657
3675
|
;
|
|
3658
3676
|
(o.valueConverter = ValueListInfo.get(type)),
|
|
3659
|
-
(o.displayValue = function (item, val) { return val === null || val === void 0 ? void 0 : val.caption; });
|
|
3677
|
+
(o.displayValue = function (item, val) { var _a; return (_a = val === null || val === void 0 ? void 0 : val.label) !== null && _a !== void 0 ? _a : val === null || val === void 0 ? void 0 : val.caption; });
|
|
3660
3678
|
o.validate = function (entity, ref) {
|
|
3661
3679
|
var values = ValueListInfo.get(type).getValues();
|
|
3662
3680
|
if (ref.value && !values.find(function (v) { return v === ref.value; })) {
|
|
@@ -3682,8 +3700,7 @@ var ValueListInfo = /** @class */ (function () {
|
|
|
3682
3700
|
s.id = member;
|
|
3683
3701
|
if (typeof s.id === 'number')
|
|
3684
3702
|
this.isNumeric = true;
|
|
3685
|
-
|
|
3686
|
-
s.caption = (0, column_js_1.makeTitle)(s.id !== undefined ? s.id.toString() : member);
|
|
3703
|
+
setLabelAndCaption(s, member);
|
|
3687
3704
|
this.byIdMap.set(s.id, s);
|
|
3688
3705
|
this.values.push(s);
|
|
3689
3706
|
}
|
|
@@ -3700,8 +3717,7 @@ var ValueListInfo = /** @class */ (function () {
|
|
|
3700
3717
|
(_b = this.values).splice.apply(_b, tslib_1.__spreadArray([0, this.values.length], tslib_1.__read(op.getValues()), false));
|
|
3701
3718
|
this.byIdMap.clear();
|
|
3702
3719
|
this.values.forEach(function (s) {
|
|
3703
|
-
|
|
3704
|
-
s.caption = (0, column_js_1.makeTitle)(s.id);
|
|
3720
|
+
setLabelAndCaption(s, '');
|
|
3705
3721
|
_this.byIdMap.set(s.id, s);
|
|
3706
3722
|
});
|
|
3707
3723
|
}
|
|
@@ -3766,6 +3782,16 @@ var ValueListInfo = /** @class */ (function () {
|
|
|
3766
3782
|
}());
|
|
3767
3783
|
exports.ValueListInfo = ValueListInfo;
|
|
3768
3784
|
var typeCache = new Map();
|
|
3785
|
+
function setLabelAndCaption(s, member) {
|
|
3786
|
+
var _a;
|
|
3787
|
+
var label = (_a = s.label) !== null && _a !== void 0 ? _a : s.caption;
|
|
3788
|
+
if (label === undefined)
|
|
3789
|
+
label = (0, column_js_1.makeTitle)(s.id !== undefined ? s.id.toString() : member);
|
|
3790
|
+
if (s.label === undefined)
|
|
3791
|
+
s.label = label;
|
|
3792
|
+
if (s.caption === undefined)
|
|
3793
|
+
s.caption = label;
|
|
3794
|
+
}
|
|
3769
3795
|
function getValueList(type) {
|
|
3770
3796
|
var meta = type === null || type === void 0 ? void 0 : type.metadata;
|
|
3771
3797
|
if (!meta && (0, isOfType_js_1.isOfType)(type, 'options'))
|