remult 0.26.23 → 0.27.0
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/SseSubscriptionServer.d.ts +3 -4
- package/assign.js +1 -2
- package/esm/graphql.js +1 -1
- package/esm/remult-hono.js +3 -1
- package/esm/remult-knex/index.js +3 -1
- package/esm/remult-sqlite3.js +4 -1
- package/esm/remult-sveltekit.js +1 -0
- package/esm/server/index.js +3 -2
- package/esm/server/initAsyncHooks.js +3 -3
- package/esm/server/remult-admin.js +1 -4
- package/esm/server/remult-api-server.js +47 -48
- package/esm/src/CompoundIdField.js +9 -9
- package/esm/src/data-api.js +1 -1
- package/esm/src/data-providers/json-entity-opfs-storage.js +9 -5
- package/esm/src/data-providers/sql-database.js +9 -9
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +3 -1
- package/esm/src/filter/filter-interfaces.js +1 -1
- package/esm/src/live-query/LiveQueryClient.js +0 -1
- package/esm/src/remult-proxy.js +1 -3
- package/esm/src/remult-static.js +1 -0
- package/esm/src/remult3/Fields.js +15 -7
- package/esm/src/remult3/RepositoryImplementation.js +165 -125
- package/esm/src/remult3/entity.js +1 -1
- package/esm/src/remult3/relation-loader.js +2 -2
- package/esm/src/remult3/remult3.js +15 -0
- package/esm/src/server-action.js +16 -12
- package/esm/src/sort.js +0 -2
- package/esm/src/validators.js +3 -3
- package/esm/src/valueConverters.js +2 -2
- package/graphql.js +3 -4
- package/index.js +2 -2
- package/live-query/data-provider-live-query-storage.js +6 -6
- package/migrations/compare-migration-snapshots.js +48 -49
- package/migrations/generate-migrations.js +1 -2
- package/migrations/migrate.js +2 -3
- package/migrations/migration-types.d.ts +1 -1
- package/migrations/migration-types.js +4 -4
- package/migrations/update-migrations-ts-file.js +1 -2
- package/myLog.js +1 -2
- package/package.json +1 -1
- package/postgres/postgres-data-provider.d.ts +2 -2
- package/postgres/postgres-data-provider.js +5 -5
- package/postgres/schema-builder.d.ts +1 -1
- package/postgres/schema-builder.js +3 -3
- package/remult-express.js +4 -3
- package/remult-fastify.js +4 -3
- package/remult-fresh.js +1 -2
- package/remult-hapi.js +4 -3
- package/remult-hono.js +6 -3
- package/remult-knex/index.d.ts +2 -2
- package/remult-knex/index.js +7 -5
- package/remult-mongo.d.ts +1 -1
- package/remult-next.d.ts +5 -6
- package/remult-next.js +11 -6
- package/remult-nuxt.js +1 -2
- package/remult-solid-start.js +1 -2
- package/remult-sqlite3.js +4 -1
- package/remult-sveltekit.d.ts +1 -1
- package/remult-sveltekit.js +33 -35
- package/server/JsonEntityFileStorage.d.ts +1 -1
- package/server/get-remult-admin-html.js +1 -2
- package/server/index.js +4 -3
- package/server/initAsyncHooks.d.ts +10 -10
- package/server/initAsyncHooks.js +5 -2
- package/server/initDataProvider.js +1 -2
- package/server/initDataProviderOrJson.js +1 -2
- package/server/remult-admin.js +3 -7
- package/server/remult-api-server.d.ts +21 -21
- package/server/remult-api-server.js +54 -48
- package/src/CompoundIdField.d.ts +2 -2
- package/src/CompoundIdField.js +9 -0
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +8 -8
- package/src/column-interfaces.d.ts +4 -4
- package/src/column-interfaces.js +1 -2
- package/src/column.d.ts +4 -4
- package/src/column.js +2 -2
- package/src/context.d.ts +4 -4
- package/src/context.js +5 -5
- package/src/data-api.d.ts +4 -4
- package/src/data-api.js +4 -4
- package/src/data-interfaces.d.ts +1 -1
- package/src/data-interfaces.js +1 -2
- package/src/data-providers/json-entity-opfs-storage.js +30 -16
- package/src/data-providers/rest-data-provider.d.ts +3 -3
- package/src/data-providers/rest-data-provider.js +4 -4
- package/src/data-providers/sql-database.d.ts +1 -1
- package/src/data-providers/sql-database.js +11 -11
- package/src/data-providers/web-sql-data-provider.d.ts +2 -2
- package/src/entity.d.ts +1 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +3 -3
- package/src/filter/filter-consumer-bridge-to-sql-request.js +21 -19
- package/src/filter/filter-interfaces.d.ts +2 -1
- package/src/filter/filter-interfaces.js +10 -7
- package/src/isOfType.js +2 -3
- package/src/live-query/SubscriptionServer.js +95 -97
- package/src/remult-proxy.js +1 -3
- package/src/remult-static.d.ts +2 -2
- package/src/remult-static.js +7 -4
- package/src/remult3/Fields.d.ts +17 -17
- package/src/remult3/Fields.js +22 -13
- package/src/remult3/RepositoryImplementation.d.ts +51 -46
- package/src/remult3/RepositoryImplementation.js +421 -368
- package/src/remult3/__updateEntityBasedOnWhere.js +1 -2
- package/src/remult3/addValidator.d.ts +1 -1
- package/src/remult3/addValidator.js +1 -2
- package/src/remult3/classDescribers.d.ts +4 -4
- package/src/remult3/classDescribers.js +3 -4
- package/src/remult3/columnInfo.d.ts +1 -1
- package/src/remult3/entity.js +2 -4
- package/src/remult3/getEntityRef.js +4 -4
- package/src/remult3/relation-loader.d.ts +1 -1
- package/src/remult3/relationInfoMember.d.ts +3 -3
- package/src/remult3/relationInfoMember.js +4 -5
- package/src/remult3/remult3.d.ts +23 -20
- package/src/remult3/remult3.js +15 -0
- package/src/remult3/repository-internals.d.ts +3 -3
- package/src/remult3/repository-internals.js +2 -2
- package/src/server-action.d.ts +2 -2
- package/src/server-action.js +65 -58
- package/src/sort.d.ts +1 -1
- package/src/sort.js +0 -2
- package/src/sql-command.d.ts +1 -1
- package/src/validators.d.ts +1 -1
- package/src/validators.js +13 -11
- package/src/valueConverters.js +3 -2
|
@@ -17,109 +17,107 @@ var LiveQueryPublisher = /** @class */ (function () {
|
|
|
17
17
|
var _this = this;
|
|
18
18
|
return tslib_1.__generator(this, function (_a) {
|
|
19
19
|
switch (_a.label) {
|
|
20
|
-
case 0: return [4 /*yield*/, this.liveQueryStorage().forEach(entityKey, function (_a) {
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
20
|
+
case 0: return [4 /*yield*/, this.liveQueryStorage().forEach(entityKey, function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
|
|
21
|
+
var query;
|
|
22
|
+
var _this = this;
|
|
23
|
+
var q = _b.query, setData = _b.setData;
|
|
24
|
+
return tslib_1.__generator(this, function (_c) {
|
|
25
|
+
switch (_c.label) {
|
|
26
|
+
case 0:
|
|
27
|
+
query = tslib_1.__assign({}, q.data);
|
|
28
|
+
return [4 /*yield*/, this.performWithContext(query.requestJson, entityKey, function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
29
|
+
var messages, currentItems, currentIds, _loop_1, _a, _b, id, _loop_2, currentItems_1, currentItems_1_1, item;
|
|
30
|
+
var e_1, _c, e_2, _d;
|
|
31
|
+
return tslib_1.__generator(this, function (_e) {
|
|
32
|
+
switch (_e.label) {
|
|
33
|
+
case 0:
|
|
34
|
+
messages = [];
|
|
35
|
+
return [4 /*yield*/, repo.find((0, rest_data_provider_js_1.findOptionsFromJson)(query.findOptionsJson, repo.metadata))];
|
|
36
|
+
case 1:
|
|
37
|
+
currentItems = _e.sent();
|
|
38
|
+
currentIds = currentItems.map(function (x) {
|
|
39
|
+
return repo.getEntityRef(x).getId();
|
|
40
|
+
});
|
|
41
|
+
_loop_1 = function (id) {
|
|
42
|
+
var c = changes.find(function (c) { return c.oldId == id; });
|
|
43
|
+
if (c === undefined ||
|
|
44
|
+
id != c.oldId ||
|
|
45
|
+
!currentIds.includes(c.id))
|
|
46
|
+
messages.push({
|
|
47
|
+
type: 'remove',
|
|
48
|
+
data: {
|
|
49
|
+
id: id,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
for (_a = tslib_1.__values(query.lastIds.filter(function (y) { return !currentIds.includes(y); })), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
55
|
+
id = _b.value;
|
|
56
|
+
_loop_1(id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
60
|
+
finally {
|
|
54
61
|
try {
|
|
55
|
-
|
|
56
|
-
id = _b.value;
|
|
57
|
-
_loop_1(id);
|
|
58
|
-
}
|
|
62
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
finally { if (e_1) throw e_1.error; }
|
|
65
|
+
}
|
|
66
|
+
_loop_2 = function (item) {
|
|
67
|
+
var itemRef = repo.getEntityRef(item);
|
|
68
|
+
var c = changes.find(function (c) { return c.id == itemRef.getId(); });
|
|
69
|
+
if (c !== undefined && query.lastIds.includes(c.oldId)) {
|
|
70
|
+
messages.push({
|
|
71
|
+
type: 'replace',
|
|
72
|
+
data: {
|
|
73
|
+
oldId: c.oldId,
|
|
74
|
+
item: itemRef.toApiJson(),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
66
77
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
type: 'replace',
|
|
73
|
-
data: {
|
|
74
|
-
oldId: c.oldId,
|
|
75
|
-
item: itemRef.toApiJson(),
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else if (!query.lastIds.includes(itemRef.getId())) {
|
|
80
|
-
messages.push({
|
|
81
|
-
type: 'add',
|
|
82
|
-
data: { item: itemRef.toApiJson() },
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
try {
|
|
87
|
-
for (currentItems_1 = tslib_1.__values(currentItems), currentItems_1_1 = currentItems_1.next(); !currentItems_1_1.done; currentItems_1_1 = currentItems_1.next()) {
|
|
88
|
-
item = currentItems_1_1.value;
|
|
89
|
-
_loop_2(item);
|
|
90
|
-
}
|
|
78
|
+
else if (!query.lastIds.includes(itemRef.getId())) {
|
|
79
|
+
messages.push({
|
|
80
|
+
type: 'add',
|
|
81
|
+
data: { item: itemRef.toApiJson() },
|
|
82
|
+
});
|
|
91
83
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
finally { if (e_2) throw e_2.error; }
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
for (currentItems_1 = tslib_1.__values(currentItems), currentItems_1_1 = currentItems_1.next(); !currentItems_1_1.done; currentItems_1_1 = currentItems_1.next()) {
|
|
87
|
+
item = currentItems_1_1.value;
|
|
88
|
+
_loop_2(item);
|
|
98
89
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
90
|
+
}
|
|
91
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
92
|
+
finally {
|
|
93
|
+
try {
|
|
94
|
+
if (currentItems_1_1 && !currentItems_1_1.done && (_d = currentItems_1.return)) _d.call(currentItems_1);
|
|
95
|
+
}
|
|
96
|
+
finally { if (e_2) throw e_2.error; }
|
|
97
|
+
}
|
|
98
|
+
this.debugFileSaver({
|
|
99
|
+
query: q.id,
|
|
100
|
+
currentIds: currentIds,
|
|
101
|
+
changes: changes,
|
|
102
|
+
lastIds: query.lastIds,
|
|
103
|
+
messages: messages,
|
|
104
|
+
});
|
|
105
|
+
query.lastIds = currentIds;
|
|
106
|
+
return [4 /*yield*/, setData(query)];
|
|
107
|
+
case 2:
|
|
108
|
+
_e.sent();
|
|
109
|
+
if (messages.length > 0)
|
|
110
|
+
this.subscriptionServer().publishMessage(q.id, messages);
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); })];
|
|
115
|
+
case 1:
|
|
116
|
+
_c.sent();
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
121
119
|
});
|
|
122
|
-
})];
|
|
120
|
+
}); })];
|
|
123
121
|
case 1:
|
|
124
122
|
_a.sent();
|
|
125
123
|
return [2 /*return*/];
|
package/src/remult-proxy.js
CHANGED
|
@@ -35,9 +35,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
35
35
|
//@ts-ignore
|
|
36
36
|
_a[repository_internals_js_1.getInternalKey] = function () {
|
|
37
37
|
var _a;
|
|
38
|
-
return (_a = self
|
|
39
|
-
.remultFactory())
|
|
40
|
-
.repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_js_1.getInternalKey]();
|
|
38
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_js_1.getInternalKey]();
|
|
41
39
|
},
|
|
42
40
|
_a.relations = function (args2) {
|
|
43
41
|
var _a;
|
package/src/remult-static.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClassType } from '../classType.js';
|
|
2
2
|
import type { ClassHelper, Remult, RemultAsyncLocalStorage } from './context.js';
|
|
3
|
-
import { DataProvider } from './data-interfaces';
|
|
3
|
+
import type { DataProvider } from './data-interfaces.js';
|
|
4
4
|
import type { columnInfo } from './remult3/columnInfo.js';
|
|
5
5
|
export declare const remultStatic: {
|
|
6
6
|
defaultRemultFactory: () => Remult;
|
|
@@ -20,7 +20,7 @@ export declare const remultStatic: {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
captionTransformer: any;
|
|
23
|
-
defaultDataProvider: () => Promise<DataProvider>;
|
|
23
|
+
defaultDataProvider: () => Promise<DataProvider | undefined>;
|
|
24
24
|
};
|
|
25
25
|
export declare function defaultFactory(): Remult;
|
|
26
26
|
export declare function resetFactory(): void;
|
package/src/remult-static.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.remultStatic = void 0;
|
|
4
|
+
exports.defaultFactory = defaultFactory;
|
|
5
|
+
exports.resetFactory = resetFactory;
|
|
4
6
|
var remultStaticKey = Symbol.for('remult-static1');
|
|
5
7
|
var x = {
|
|
6
8
|
defaultRemultFactory: undefined,
|
|
@@ -22,11 +24,14 @@ var x = {
|
|
|
22
24
|
}); },
|
|
23
25
|
},
|
|
24
26
|
captionTransformer: undefined,
|
|
25
|
-
defaultDataProvider: function () {
|
|
27
|
+
defaultDataProvider: function () {
|
|
28
|
+
return undefined;
|
|
29
|
+
},
|
|
26
30
|
};
|
|
27
31
|
if ((typeof process !== 'undefined' &&
|
|
28
32
|
process.env['IGNORE_GLOBAL_REMULT_IN_TESTS']) ||
|
|
29
33
|
typeof globalThis[remultStaticKey] === 'undefined') {
|
|
34
|
+
;
|
|
30
35
|
globalThis[remultStaticKey] = x;
|
|
31
36
|
x.remultFactory = function () { return defaultFactory(); };
|
|
32
37
|
}
|
|
@@ -40,8 +45,6 @@ function defaultFactory() {
|
|
|
40
45
|
}
|
|
41
46
|
return exports.remultStatic.defaultRemult;
|
|
42
47
|
}
|
|
43
|
-
exports.defaultFactory = defaultFactory;
|
|
44
48
|
function resetFactory() {
|
|
45
49
|
exports.remultStatic.remultFactory = function () { return defaultFactory(); };
|
|
46
50
|
}
|
|
47
|
-
exports.resetFactory = resetFactory;
|
package/src/remult3/Fields.d.ts
CHANGED
|
@@ -6,22 +6,22 @@ export declare class Fields {
|
|
|
6
6
|
/**
|
|
7
7
|
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
8
8
|
*/
|
|
9
|
-
static object<entityType =
|
|
10
|
-
static json<entityType =
|
|
11
|
-
static dateOnly<entityType =
|
|
12
|
-
static date<entityType =
|
|
13
|
-
static integer<entityType =
|
|
14
|
-
static autoIncrement<entityType =
|
|
15
|
-
static number<entityType =
|
|
16
|
-
static createdAt<entityType =
|
|
17
|
-
static updatedAt<entityType =
|
|
18
|
-
static uuid<entityType =
|
|
9
|
+
static object<entityType = unknown, valueType = unknown>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
10
|
+
static json<entityType = unknown, valueType = unknown>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
11
|
+
static dateOnly<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
12
|
+
static date<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
13
|
+
static integer<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
14
|
+
static autoIncrement<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
15
|
+
static number<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
16
|
+
static createdAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
17
|
+
static updatedAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
18
|
+
static uuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
19
19
|
/**
|
|
20
20
|
* A CUID (Collision Resistant Unique Identifier) field.
|
|
21
21
|
* This id value is determined on the backend on insert, and can't be updated through the API.
|
|
22
22
|
* The CUID is generated using the `@paralleldrive/cuid2` npm package.
|
|
23
23
|
*/
|
|
24
|
-
static cuid<entityType =
|
|
24
|
+
static cuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
25
25
|
/**
|
|
26
26
|
* Defines a field that can hold a value from a specified set of string literals.
|
|
27
27
|
* @param {() => readonly valueType[]} optionalValues - A function that returns an array of allowed string literals.
|
|
@@ -51,10 +51,10 @@ export declare class Fields {
|
|
|
51
51
|
*
|
|
52
52
|
* // This approach allows easy management and updates of the allowed values for the `status` field.
|
|
53
53
|
*/
|
|
54
|
-
static literal<entityType =
|
|
55
|
-
static enum<entityType =
|
|
56
|
-
static string<entityType =
|
|
57
|
-
static boolean<entityType =
|
|
54
|
+
static literal<entityType = unknown, valueType extends string = string>(optionalValues: () => readonly valueType[], ...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
55
|
+
static enum<entityType = unknown, theEnum = object>(enumType: () => theEnum, ...options: (FieldOptions<entityType, theEnum[keyof theEnum]> | ((options: FieldOptions<entityType, theEnum[keyof theEnum]>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, theEnum[keyof theEnum] | undefined>;
|
|
56
|
+
static string<entityType = unknown, valueType = string>(...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
57
|
+
static boolean<entityType = unknown>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
58
58
|
}
|
|
59
59
|
export declare class Relations {
|
|
60
60
|
/**
|
|
@@ -162,8 +162,8 @@ export declare class Relations {
|
|
|
162
162
|
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
163
163
|
* title='';
|
|
164
164
|
*/
|
|
165
|
-
export declare function Field<entityType =
|
|
166
|
-
export interface StringFieldOptions<entityType =
|
|
165
|
+
export declare function Field<entityType = unknown, valueType = unknown>(valueType: (() => valueType extends number ? Number : valueType extends string ? String : valueType extends boolean ? Boolean : ClassType<valueType>) | undefined, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
|
|
166
|
+
export interface StringFieldOptions<entityType = unknown, valueType = string> extends FieldOptions<entityType, valueType> {
|
|
167
167
|
maxLength?: number;
|
|
168
168
|
minLength?: number;
|
|
169
169
|
}
|
package/src/remult3/Fields.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Relations = exports.Fields = void 0;
|
|
4
|
+
exports.Field = Field;
|
|
5
|
+
exports.checkTarget = checkTarget;
|
|
4
6
|
var tslib_1 = require("tslib");
|
|
5
7
|
var cuid2_1 = require("@paralleldrive/cuid2");
|
|
6
8
|
var uuid_1 = require("uuid");
|
|
@@ -10,6 +12,7 @@ var validators_js_1 = require("../validators.js");
|
|
|
10
12
|
var relationInfoMember_js_1 = require("./relationInfoMember.js");
|
|
11
13
|
var remult_static_js_1 = require("../remult-static.js");
|
|
12
14
|
var addValidator_js_1 = require("./addValidator.js");
|
|
15
|
+
var isOfType_js_1 = require("../isOfType.js");
|
|
13
16
|
var validateNumber = (0, validators_js_1.createValueValidator)(function (x) {
|
|
14
17
|
return !isNaN(x) && isFinite(x);
|
|
15
18
|
});
|
|
@@ -155,7 +158,7 @@ var Fields = /** @class */ (function () {
|
|
|
155
158
|
},
|
|
156
159
|
}], tslib_1.__read(options), false));
|
|
157
160
|
};
|
|
158
|
-
// static id<entityType =
|
|
161
|
+
// static id<entityType = unknown>(
|
|
159
162
|
// options?: FieldOptions<entityType, string> & { idFactory?: () => string },
|
|
160
163
|
// ): ClassFieldDecorator<entityType, string | undefined> {
|
|
161
164
|
// let buildId = options?.idFactory ?? createId
|
|
@@ -218,14 +221,16 @@ var Fields = /** @class */ (function () {
|
|
|
218
221
|
options[_i - 1] = arguments[_i];
|
|
219
222
|
}
|
|
220
223
|
var valueConverter;
|
|
221
|
-
return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([
|
|
225
|
+
//@ts-ignore
|
|
226
|
+
function () { return enumType(); }, (_a = {
|
|
227
|
+
validate: function (entity, event) {
|
|
228
|
+
return validators_js_1.Validators.enum(enumType())(entity, event);
|
|
229
|
+
}
|
|
226
230
|
},
|
|
227
231
|
_a[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () { return (0, validators_js_1.getEnumValues)(enumType()); },
|
|
228
232
|
_a)], tslib_1.__read(options), false), [function (options) {
|
|
233
|
+
;
|
|
229
234
|
options[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () {
|
|
230
235
|
return (0, validators_js_1.getEnumValues)(enumType());
|
|
231
236
|
};
|
|
@@ -354,11 +359,17 @@ function Field(valueType) {
|
|
|
354
359
|
if (r.required) {
|
|
355
360
|
r.validate = (0, addValidator_js_1.addValidator)(r.validate, validators_js_1.Validators.required, true);
|
|
356
361
|
}
|
|
357
|
-
if (r
|
|
358
|
-
|
|
362
|
+
if ((0, isOfType_js_1.isOfType)(r, 'maxLength')) {
|
|
363
|
+
var z = r;
|
|
364
|
+
if (z.maxLength) {
|
|
365
|
+
z.validate = (0, addValidator_js_1.addValidator)(z.validate, validators_js_1.Validators.maxLength(z.maxLength));
|
|
366
|
+
}
|
|
359
367
|
}
|
|
360
|
-
if (r
|
|
361
|
-
|
|
368
|
+
if ((0, isOfType_js_1.isOfType)(r, 'minLength')) {
|
|
369
|
+
var z = r;
|
|
370
|
+
if (z.minLength) {
|
|
371
|
+
z.validate = (0, addValidator_js_1.addValidator)(z.validate, validators_js_1.Validators.minLength(z.minLength));
|
|
372
|
+
}
|
|
362
373
|
}
|
|
363
374
|
if (!r.valueType && valueType) {
|
|
364
375
|
r.valueType = valueType();
|
|
@@ -402,9 +413,7 @@ function Field(valueType) {
|
|
|
402
413
|
}
|
|
403
414
|
};
|
|
404
415
|
}
|
|
405
|
-
exports.Field = Field;
|
|
406
416
|
function checkTarget(target) {
|
|
407
417
|
if (!target)
|
|
408
418
|
throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
|
|
409
419
|
}
|
|
410
|
-
exports.checkTarget = checkTarget;
|