remult 0.20.1-exp.1 → 0.20.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/README.md +1 -1
- package/esm/graphql.js +8 -2
- package/esm/src/buildRestDataProvider.js +1 -1
- package/esm/src/remult-proxy.js +16 -5
- package/esm/src/remult3/RepositoryImplementation.d.ts +2 -1
- package/esm/src/remult3/RepositoryImplementation.js +5 -1
- package/esm/src/remult3/remult3.d.ts +4 -3
- package/esm/src/server-action.d.ts +5 -0
- package/esm/src/server-action.js +4 -4
- package/esm/src/sort.js +2 -0
- package/graphql.js +63 -59
- package/package.json +1 -1
- package/src/buildRestDataProvider.js +1 -1
- package/src/remult-proxy.js +23 -24
- package/src/remult3/RepositoryImplementation.d.ts +2 -1
- package/src/remult3/RepositoryImplementation.js +5 -1
- package/src/remult3/remult3.d.ts +4 -3
- package/src/server-action.d.ts +5 -0
- package/src/server-action.js +4 -4
- package/src/sort.js +2 -0
- package/remult-svletekit.d.ts +0 -3
- package/remult-svletekit.js +0 -136
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<a href="http://remult.dev/">
|
|
3
|
-
<img src="https://github.com/remult/remult/raw/master/docs
|
|
3
|
+
<img src="https://github.com/remult/remult/raw/master/docs/public/logo.png" width="140" height="140">
|
|
4
4
|
</a>
|
|
5
5
|
<h1>Remult</h1>
|
|
6
6
|
<p>A CRUD framework for full-stack TypeScript</p>
|
package/esm/graphql.js
CHANGED
|
@@ -77,9 +77,10 @@ export function remultGraphql(api) {
|
|
|
77
77
|
}
|
|
78
78
|
filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
|
|
79
79
|
query += q;
|
|
80
|
-
root[key] = async (
|
|
80
|
+
root[key] = async (arg1, req, a) => {
|
|
81
|
+
const { options, filter } = arg1;
|
|
81
82
|
return new Promise(async (res, error) => {
|
|
82
|
-
//TODO - consider this with remult usage
|
|
83
|
+
//TODO - consider this with remult usage when working with other servers
|
|
83
84
|
api.withRemult(req, undefined, async () => {
|
|
84
85
|
let remult = await api.getRemult(req);
|
|
85
86
|
let repo = remult.repo(e);
|
|
@@ -140,3 +141,8 @@ input options{
|
|
|
140
141
|
`
|
|
141
142
|
};
|
|
142
143
|
}
|
|
144
|
+
//TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
|
|
145
|
+
//TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
|
|
146
|
+
//TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
|
|
147
|
+
//TODO - it doesn't support mutations
|
|
148
|
+
//TODO - it doesn't support backend methods
|
|
@@ -49,7 +49,7 @@ export async function retry(what) {
|
|
|
49
49
|
err.message?.startsWith("Error occured while trying to proxy") ||
|
|
50
50
|
err.message?.includes("http proxy error") ||
|
|
51
51
|
err.message?.startsWith("Gateway Timeout") ||
|
|
52
|
-
err.status == 500) && i++ <
|
|
52
|
+
err.status == 500) && i++ < 50) {
|
|
53
53
|
await new Promise((res, req) => {
|
|
54
54
|
setTimeout(() => {
|
|
55
55
|
res({});
|
package/esm/src/remult-proxy.js
CHANGED
|
@@ -3,33 +3,44 @@ export class RemultProxy {
|
|
|
3
3
|
constructor() {
|
|
4
4
|
/*@internal*/
|
|
5
5
|
this.remultFactory = () => RemultProxy.defaultRemult;
|
|
6
|
+
this.repoCache = new Map();
|
|
6
7
|
//@ts-ignore
|
|
7
8
|
this.repo = (...args) => {
|
|
8
9
|
let self = this;
|
|
9
|
-
|
|
10
|
+
let entityCache = self.repoCache.get(args[0]);
|
|
11
|
+
if (!entityCache) {
|
|
12
|
+
self.repoCache.set(args[0], entityCache = new Map());
|
|
13
|
+
}
|
|
14
|
+
let result = entityCache.get(args[1]);
|
|
15
|
+
if (result)
|
|
16
|
+
return result;
|
|
17
|
+
result = {
|
|
10
18
|
get fields() {
|
|
11
19
|
return self.remultFactory().repo(...args).metadata.fields;
|
|
12
20
|
},
|
|
13
|
-
validate: (
|
|
21
|
+
validate: (a, b) => self.remultFactory().repo(...args).validate(a, b),
|
|
14
22
|
addEventListener: (...args2) => self.remultFactory().repo(...args).addEventListener(...args2),
|
|
15
23
|
count: (...args2) => self.remultFactory().repo(...args).count(...args2),
|
|
16
24
|
create: (...args2) => self.remultFactory().repo(...args).create(...args2),
|
|
17
25
|
delete: (args2) => self.remultFactory().repo(...args).delete(args2),
|
|
18
26
|
find: (...args2) => self.remultFactory().repo(...args).find(...args2),
|
|
19
27
|
findFirst: (...args2) => self.remultFactory().repo(...args).findFirst(...args2),
|
|
20
|
-
findId: (
|
|
28
|
+
findId: (a, b) => self.remultFactory().repo(...args).findId(a, b),
|
|
21
29
|
fromJson: (...args2) => self.remultFactory().repo(...args).fromJson(...args2),
|
|
22
30
|
getEntityRef: (...args2) => self.remultFactory().repo(...args).getEntityRef(...args2),
|
|
23
31
|
insert: (args2) => self.remultFactory().repo(...args).insert(args2),
|
|
24
32
|
liveQuery: (...args2) => self.remultFactory().repo(...args).liveQuery(...args2),
|
|
25
|
-
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
addToCache: (a) => self.remultFactory().repo(...args).addToCache(a),
|
|
26
35
|
get metadata() {
|
|
27
36
|
return self.remultFactory().repo(...args).metadata;
|
|
28
37
|
},
|
|
29
38
|
query: (...args2) => self.remultFactory().repo(...args).query(...args2),
|
|
30
39
|
save: (args2) => self.remultFactory().repo(...args).save(args2),
|
|
31
|
-
update: (
|
|
40
|
+
update: (a, b) => self.remultFactory().repo(...args).update(a, b),
|
|
32
41
|
};
|
|
42
|
+
entityCache.set(args[1], result);
|
|
43
|
+
return result;
|
|
33
44
|
};
|
|
34
45
|
}
|
|
35
46
|
/* @internal*/
|
|
@@ -40,7 +40,8 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
40
40
|
id?: number;
|
|
41
41
|
} ? number : entityType extends {
|
|
42
42
|
id?: string;
|
|
43
|
-
} ? string : (string | number)),
|
|
43
|
+
} ? string : (string | number)), item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
44
|
+
update(originalItem: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
44
45
|
private getRefForExistingRow;
|
|
45
46
|
save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
46
47
|
save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
@@ -192,6 +192,8 @@ export class RepositoryImplementation {
|
|
|
192
192
|
}
|
|
193
193
|
this.fixTypes(instance);
|
|
194
194
|
let row = new rowHelperImplementation(this._info, instance, this, this.edp, this.remult, false);
|
|
195
|
+
if (typeof (id) === "object")
|
|
196
|
+
id = this.metadata.idMetadata.getId(id);
|
|
195
197
|
if (id) {
|
|
196
198
|
row.id = id;
|
|
197
199
|
row.originalId = id;
|
|
@@ -217,7 +219,7 @@ export class RepositoryImplementation {
|
|
|
217
219
|
return await this.getEntityRef(entity).save();
|
|
218
220
|
}
|
|
219
221
|
else {
|
|
220
|
-
let id =
|
|
222
|
+
let id = this.metadata.idMetadata.getId(entity);
|
|
221
223
|
if (id === undefined)
|
|
222
224
|
return this.insert(entity);
|
|
223
225
|
return this.update(id, entity);
|
|
@@ -1482,6 +1484,7 @@ export class Fields {
|
|
|
1482
1484
|
}
|
|
1483
1485
|
static createdAt(...options) {
|
|
1484
1486
|
return Field(() => Date, {
|
|
1487
|
+
allowApiUpdate: false,
|
|
1485
1488
|
saving: (_, ref) => {
|
|
1486
1489
|
if (getEntityRef(_).isNew())
|
|
1487
1490
|
ref.value = new Date();
|
|
@@ -1490,6 +1493,7 @@ export class Fields {
|
|
|
1490
1493
|
}
|
|
1491
1494
|
static updatedAt(...options) {
|
|
1492
1495
|
return Field(() => Date, {
|
|
1496
|
+
allowApiUpdate: false,
|
|
1493
1497
|
saving: (_, ref) => {
|
|
1494
1498
|
ref.value = new Date();
|
|
1495
1499
|
}
|
|
@@ -95,11 +95,11 @@ export interface IdMetadata<entityType = any> {
|
|
|
95
95
|
* @example
|
|
96
96
|
* repo.metadata.idMetadata.getId(task)
|
|
97
97
|
*/
|
|
98
|
-
getId(item: entityType): any;
|
|
98
|
+
getId(item: Partial<OmitEB<entityType>>): any;
|
|
99
99
|
field: FieldMetadata<any>;
|
|
100
100
|
getIdFilter(...ids: any[]): EntityFilter<entityType>;
|
|
101
101
|
isIdField(col: FieldMetadata): boolean;
|
|
102
|
-
createIdInFilter(items: entityType[]): EntityFilter<entityType>;
|
|
102
|
+
createIdInFilter(items: Partial<OmitEB<entityType>>[]): EntityFilter<entityType>;
|
|
103
103
|
}
|
|
104
104
|
/** Metadata for an `Entity`, this metadata can be used in the user interface to provide a richer UI experience */
|
|
105
105
|
export interface EntityMetadata<entityType = any> {
|
|
@@ -226,13 +226,14 @@ export interface Repository<entityType> {
|
|
|
226
226
|
} ? number : entityType extends {
|
|
227
227
|
id?: string;
|
|
228
228
|
} ? string : (string | number)), item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
229
|
+
update(id: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
229
230
|
/** Deletes an Item*/
|
|
230
231
|
delete(id: (entityType extends {
|
|
231
232
|
id?: number;
|
|
232
233
|
} ? number : entityType extends {
|
|
233
234
|
id?: string;
|
|
234
235
|
} ? string : (string | number))): Promise<void>;
|
|
235
|
-
delete(item: entityType): Promise<void>;
|
|
236
|
+
delete(item: Partial<OmitEB<entityType>>): Promise<void>;
|
|
236
237
|
/** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
|
|
237
238
|
create(item?: Partial<OmitEB<entityType>>): entityType;
|
|
238
239
|
/** Translates a json object to an item instance */
|
|
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
|
|
|
33
33
|
export interface BackendMethodOptions<type> {
|
|
34
34
|
/**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
|
|
35
35
|
allowed: AllowedForInstance<type>;
|
|
36
|
+
/** Used to determine the route for the BackendMethod.
|
|
37
|
+
* @example
|
|
38
|
+
* {allowed:true, apiPrefix:'someFolder/'}
|
|
39
|
+
*/
|
|
40
|
+
apiPrefix?: string;
|
|
36
41
|
/** EXPERIMENTAL: Determines if this method should be queued for later execution */
|
|
37
42
|
queue?: boolean;
|
|
38
43
|
/** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
|
package/esm/src/server-action.js
CHANGED
|
@@ -119,7 +119,7 @@ export function BackendMethod(options) {
|
|
|
119
119
|
if (options.paramTypes)
|
|
120
120
|
types = options.paramTypes;
|
|
121
121
|
// if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
|
|
122
|
-
let serverAction = new myServerAction(key, types, options, args => originalMethod.apply(undefined, args));
|
|
122
|
+
let serverAction = new myServerAction((options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, types, options, args => originalMethod.apply(undefined, args));
|
|
123
123
|
serverAction.doWork = async (args, self, url, http) => {
|
|
124
124
|
args = prepareArgsToSend(types, args);
|
|
125
125
|
if (options.blockUser === false) {
|
|
@@ -156,7 +156,7 @@ export function BackendMethod(options) {
|
|
|
156
156
|
if (!controllerOptions.key) {
|
|
157
157
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
158
158
|
}
|
|
159
|
-
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
|
|
159
|
+
reg(controllerOptions.key + '/' + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, async (d, req, res) => {
|
|
160
160
|
d.args = d.args.map(x => isCustomUndefined(x) ? undefined : x);
|
|
161
161
|
let allowed = options.allowed;
|
|
162
162
|
try {
|
|
@@ -243,7 +243,7 @@ export function BackendMethod(options) {
|
|
|
243
243
|
}
|
|
244
244
|
try {
|
|
245
245
|
let r = await (new class extends Action {
|
|
246
|
-
}(classOptions.key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
246
|
+
}(classOptions.key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
|
|
247
247
|
args,
|
|
248
248
|
rowInfo: {
|
|
249
249
|
data: await defs.toApiJson(),
|
|
@@ -264,7 +264,7 @@ export function BackendMethod(options) {
|
|
|
264
264
|
try {
|
|
265
265
|
await defs.__validateEntity();
|
|
266
266
|
let r = await (new class extends Action {
|
|
267
|
-
}(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed).run({
|
|
267
|
+
}(x.classes.get(self.constructor).key + "/" + (options?.apiPrefix ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed).run({
|
|
268
268
|
args,
|
|
269
269
|
fields: await defs.toApiJson()
|
|
270
270
|
}, baseUrl, http));
|
package/esm/src/sort.js
CHANGED
|
@@ -85,6 +85,8 @@ export class Sort {
|
|
|
85
85
|
orderBy = entityMetadata.options.defaultOrderBy;
|
|
86
86
|
if (!orderBy)
|
|
87
87
|
orderBy = { [entityMetadata.idMetadata.field.key]: "asc" };
|
|
88
|
+
else
|
|
89
|
+
orderBy = { ...orderBy };
|
|
88
90
|
if (entityMetadata.idMetadata.field instanceof CompoundIdField) {
|
|
89
91
|
for (const field of entityMetadata.idMetadata.field.fields) {
|
|
90
92
|
if (!orderBy[field.key]) {
|
package/graphql.js
CHANGED
|
@@ -142,67 +142,66 @@ function remultGraphql(api) {
|
|
|
142
142
|
}
|
|
143
143
|
filterTypes += "input " + key + "Filter{" + filterFields + "\n\tOR:[" + key + "Filter]\n}\n";
|
|
144
144
|
query += q;
|
|
145
|
-
root[key] = function (
|
|
146
|
-
var options
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return [2 /*return*/];
|
|
194
|
-
}
|
|
195
|
-
res(result);
|
|
145
|
+
root[key] = function (arg1, req, a) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
146
|
+
var options, filter;
|
|
147
|
+
var _this = this;
|
|
148
|
+
return tslib_1.__generator(this, function (_a) {
|
|
149
|
+
options = arg1.options, filter = arg1.filter;
|
|
150
|
+
return [2 /*return*/, new Promise(function (res, error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
151
|
+
var _this = this;
|
|
152
|
+
return tslib_1.__generator(this, function (_a) {
|
|
153
|
+
//TODO - consider this with remult usage when working with other servers
|
|
154
|
+
api.withRemult(req, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
155
|
+
var remult, repo, dApi, result, err;
|
|
156
|
+
return tslib_1.__generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, api.getRemult(req)];
|
|
159
|
+
case 1:
|
|
160
|
+
remult = _a.sent();
|
|
161
|
+
repo = remult.repo(e);
|
|
162
|
+
dApi = new data_api_1.DataApi(repo, remult);
|
|
163
|
+
return [4 /*yield*/, dApi.getArray({
|
|
164
|
+
success: function (x) { return result = x.map(function (y) {
|
|
165
|
+
t.resultProcessors.forEach(function (z) { return z(y); });
|
|
166
|
+
return y;
|
|
167
|
+
}); },
|
|
168
|
+
created: undefined,
|
|
169
|
+
deleted: undefined,
|
|
170
|
+
error: function (x) { return err = x; },
|
|
171
|
+
forbidden: function () { return err = 'forbidden'; },
|
|
172
|
+
notFound: function () { return err = 'not found'; },
|
|
173
|
+
progress: undefined
|
|
174
|
+
}, {
|
|
175
|
+
get: function (key) {
|
|
176
|
+
if (options)
|
|
177
|
+
switch (key) {
|
|
178
|
+
case "_limit":
|
|
179
|
+
return options.limit;
|
|
180
|
+
case "_page":
|
|
181
|
+
return options.page;
|
|
182
|
+
case "_sort":
|
|
183
|
+
return options.sort;
|
|
184
|
+
case "_order":
|
|
185
|
+
return options.order;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, filter)];
|
|
189
|
+
case 2:
|
|
190
|
+
_a.sent();
|
|
191
|
+
if (err) {
|
|
192
|
+
error(err);
|
|
196
193
|
return [2 /*return*/];
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
194
|
+
}
|
|
195
|
+
res(result);
|
|
196
|
+
return [2 /*return*/];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}); });
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
});
|
|
202
|
+
}); })];
|
|
204
203
|
});
|
|
205
|
-
};
|
|
204
|
+
}); };
|
|
206
205
|
}
|
|
207
206
|
};
|
|
208
207
|
try {
|
|
@@ -230,3 +229,8 @@ function remultGraphql(api) {
|
|
|
230
229
|
};
|
|
231
230
|
}
|
|
232
231
|
exports.remultGraphql = remultGraphql;
|
|
232
|
+
//TODO - filter doesn't work since we changed id_eq to be id.eq in rest, but graphql doesn't allow it.
|
|
233
|
+
//TODO - the list of entities, is based on allEntities - that's wrong - it should be based on the api entities - or a separate array.
|
|
234
|
+
//TODO - it's currently only planned for express server - it uses it's 'withRemult' that doesn't exist in all other servers.
|
|
235
|
+
//TODO - it doesn't support mutations
|
|
236
|
+
//TODO - it doesn't support backend methods
|
package/package.json
CHANGED
|
@@ -81,7 +81,7 @@ function retry(what) {
|
|
|
81
81
|
case 4:
|
|
82
82
|
err_1 = _e.sent();
|
|
83
83
|
if (!((((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")) || ((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes("http proxy error")) || ((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith("Gateway Timeout")) ||
|
|
84
|
-
err_1.status == 500) && i++ <
|
|
84
|
+
err_1.status == 500) && i++ < 50)) return [3 /*break*/, 6];
|
|
85
85
|
return [4 /*yield*/, new Promise(function (res, req) {
|
|
86
86
|
setTimeout(function () {
|
|
87
87
|
res({});
|
package/src/remult-proxy.js
CHANGED
|
@@ -8,6 +8,7 @@ var RemultProxy = /** @class */ (function () {
|
|
|
8
8
|
var _this = this;
|
|
9
9
|
/*@internal*/
|
|
10
10
|
this.remultFactory = function () { return RemultProxy.defaultRemult; };
|
|
11
|
+
this.repoCache = new Map();
|
|
11
12
|
//@ts-ignore
|
|
12
13
|
this.repo = function () {
|
|
13
14
|
var args = [];
|
|
@@ -15,18 +16,21 @@ var RemultProxy = /** @class */ (function () {
|
|
|
15
16
|
args[_i] = arguments[_i];
|
|
16
17
|
}
|
|
17
18
|
var self = _this;
|
|
18
|
-
|
|
19
|
+
var entityCache = self.repoCache.get(args[0]);
|
|
20
|
+
if (!entityCache) {
|
|
21
|
+
self.repoCache.set(args[0], entityCache = new Map());
|
|
22
|
+
}
|
|
23
|
+
var result = entityCache.get(args[1]);
|
|
24
|
+
if (result)
|
|
25
|
+
return result;
|
|
26
|
+
result = {
|
|
19
27
|
get fields() {
|
|
20
28
|
var _a;
|
|
21
29
|
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).metadata.fields;
|
|
22
30
|
},
|
|
23
|
-
validate: function () {
|
|
24
|
-
var _a
|
|
25
|
-
|
|
26
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
27
|
-
args2[_i] = arguments[_i];
|
|
28
|
-
}
|
|
29
|
-
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).validate.apply(_a, tslib_1.__spread(args2));
|
|
31
|
+
validate: function (a, b) {
|
|
32
|
+
var _a;
|
|
33
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).validate(a, b);
|
|
30
34
|
},
|
|
31
35
|
addEventListener: function () {
|
|
32
36
|
var _a, _b;
|
|
@@ -72,13 +76,9 @@ var RemultProxy = /** @class */ (function () {
|
|
|
72
76
|
}
|
|
73
77
|
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).findFirst.apply(_a, tslib_1.__spread(args2));
|
|
74
78
|
},
|
|
75
|
-
findId: function () {
|
|
76
|
-
var _a
|
|
77
|
-
|
|
78
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
79
|
-
args2[_i] = arguments[_i];
|
|
80
|
-
}
|
|
81
|
-
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).findId.apply(_a, tslib_1.__spread(args2));
|
|
79
|
+
findId: function (a, b) {
|
|
80
|
+
var _a;
|
|
81
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).findId(a, b);
|
|
82
82
|
},
|
|
83
83
|
fromJson: function () {
|
|
84
84
|
var _a, _b;
|
|
@@ -108,9 +108,10 @@ var RemultProxy = /** @class */ (function () {
|
|
|
108
108
|
}
|
|
109
109
|
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).liveQuery.apply(_a, tslib_1.__spread(args2));
|
|
110
110
|
},
|
|
111
|
-
|
|
111
|
+
//@ts-ignore
|
|
112
|
+
addToCache: function (a) {
|
|
112
113
|
var _a;
|
|
113
|
-
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).addToCache(
|
|
114
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).addToCache(a);
|
|
114
115
|
},
|
|
115
116
|
get metadata() {
|
|
116
117
|
var _a;
|
|
@@ -128,15 +129,13 @@ var RemultProxy = /** @class */ (function () {
|
|
|
128
129
|
var _a;
|
|
129
130
|
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).save(args2);
|
|
130
131
|
},
|
|
131
|
-
update: function () {
|
|
132
|
-
var _a
|
|
133
|
-
|
|
134
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
135
|
-
args2[_i] = arguments[_i];
|
|
136
|
-
}
|
|
137
|
-
return (_a = (_b = self.remultFactory()).repo.apply(_b, tslib_1.__spread(args))).update.apply(_a, tslib_1.__spread(args2));
|
|
132
|
+
update: function (a, b) {
|
|
133
|
+
var _a;
|
|
134
|
+
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spread(args)).update(a, b);
|
|
138
135
|
},
|
|
139
136
|
};
|
|
137
|
+
entityCache.set(args[1], result);
|
|
138
|
+
return result;
|
|
140
139
|
};
|
|
141
140
|
}
|
|
142
141
|
Object.defineProperty(RemultProxy.prototype, "liveQuerySubscriber", {
|
|
@@ -40,7 +40,8 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
40
40
|
id?: number;
|
|
41
41
|
} ? number : entityType extends {
|
|
42
42
|
id?: string;
|
|
43
|
-
} ? string : (string | number)),
|
|
43
|
+
} ? string : (string | number)), item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
44
|
+
update(originalItem: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
44
45
|
private getRefForExistingRow;
|
|
45
46
|
save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
46
47
|
save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
@@ -346,6 +346,8 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
346
346
|
}
|
|
347
347
|
this.fixTypes(instance);
|
|
348
348
|
var row_1 = new rowHelperImplementation(this._info, instance, this, this.edp, this.remult, false);
|
|
349
|
+
if (typeof (id) === "object")
|
|
350
|
+
id = this.metadata.idMetadata.getId(id);
|
|
349
351
|
if (id) {
|
|
350
352
|
row_1.id = id;
|
|
351
353
|
row_1.originalId = id;
|
|
@@ -378,7 +380,7 @@ var RepositoryImplementation = /** @class */ (function () {
|
|
|
378
380
|
return [4 /*yield*/, this.getEntityRef(entity).save()];
|
|
379
381
|
case 4: return [2 /*return*/, _a.sent()];
|
|
380
382
|
case 5:
|
|
381
|
-
id =
|
|
383
|
+
id = this.metadata.idMetadata.getId(entity);
|
|
382
384
|
if (id === undefined)
|
|
383
385
|
return [2 /*return*/, this.insert(entity)];
|
|
384
386
|
return [2 /*return*/, this.update(id, entity)];
|
|
@@ -2609,6 +2611,7 @@ var Fields = /** @class */ (function () {
|
|
|
2609
2611
|
options[_i] = arguments[_i];
|
|
2610
2612
|
}
|
|
2611
2613
|
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
|
|
2614
|
+
allowApiUpdate: false,
|
|
2612
2615
|
saving: function (_, ref) {
|
|
2613
2616
|
if (getEntityRef(_).isNew())
|
|
2614
2617
|
ref.value = new Date();
|
|
@@ -2621,6 +2624,7 @@ var Fields = /** @class */ (function () {
|
|
|
2621
2624
|
options[_i] = arguments[_i];
|
|
2622
2625
|
}
|
|
2623
2626
|
return Field.apply(void 0, tslib_1.__spread([function () { return Date; }, {
|
|
2627
|
+
allowApiUpdate: false,
|
|
2624
2628
|
saving: function (_, ref) {
|
|
2625
2629
|
ref.value = new Date();
|
|
2626
2630
|
}
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -95,11 +95,11 @@ export interface IdMetadata<entityType = any> {
|
|
|
95
95
|
* @example
|
|
96
96
|
* repo.metadata.idMetadata.getId(task)
|
|
97
97
|
*/
|
|
98
|
-
getId(item: entityType): any;
|
|
98
|
+
getId(item: Partial<OmitEB<entityType>>): any;
|
|
99
99
|
field: FieldMetadata<any>;
|
|
100
100
|
getIdFilter(...ids: any[]): EntityFilter<entityType>;
|
|
101
101
|
isIdField(col: FieldMetadata): boolean;
|
|
102
|
-
createIdInFilter(items: entityType[]): EntityFilter<entityType>;
|
|
102
|
+
createIdInFilter(items: Partial<OmitEB<entityType>>[]): EntityFilter<entityType>;
|
|
103
103
|
}
|
|
104
104
|
/** Metadata for an `Entity`, this metadata can be used in the user interface to provide a richer UI experience */
|
|
105
105
|
export interface EntityMetadata<entityType = any> {
|
|
@@ -226,13 +226,14 @@ export interface Repository<entityType> {
|
|
|
226
226
|
} ? number : entityType extends {
|
|
227
227
|
id?: string;
|
|
228
228
|
} ? string : (string | number)), item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
229
|
+
update(id: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
229
230
|
/** Deletes an Item*/
|
|
230
231
|
delete(id: (entityType extends {
|
|
231
232
|
id?: number;
|
|
232
233
|
} ? number : entityType extends {
|
|
233
234
|
id?: string;
|
|
234
235
|
} ? string : (string | number))): Promise<void>;
|
|
235
|
-
delete(item: entityType): Promise<void>;
|
|
236
|
+
delete(item: Partial<OmitEB<entityType>>): Promise<void>;
|
|
236
237
|
/** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
|
|
237
238
|
create(item?: Partial<OmitEB<entityType>>): entityType;
|
|
238
239
|
/** Translates a json object to an item instance */
|
package/src/server-action.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export declare class myServerAction extends Action<inArgs, result> {
|
|
|
33
33
|
export interface BackendMethodOptions<type> {
|
|
34
34
|
/**Determines when this `BackendMethod` can execute, see: [Allowed](https://remult.dev/docs/allowed.html) */
|
|
35
35
|
allowed: AllowedForInstance<type>;
|
|
36
|
+
/** Used to determine the route for the BackendMethod.
|
|
37
|
+
* @example
|
|
38
|
+
* {allowed:true, apiPrefix:'someFolder/'}
|
|
39
|
+
*/
|
|
40
|
+
apiPrefix?: string;
|
|
36
41
|
/** EXPERIMENTAL: Determines if this method should be queued for later execution */
|
|
37
42
|
queue?: boolean;
|
|
38
43
|
/** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
|
package/src/server-action.js
CHANGED
|
@@ -196,7 +196,7 @@ function BackendMethod(options) {
|
|
|
196
196
|
if (options.paramTypes)
|
|
197
197
|
types = options.paramTypes;
|
|
198
198
|
// if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
|
|
199
|
-
var serverAction_1 = new myServerAction(key, types, options, function (args) { return originalMethod.apply(undefined, args); });
|
|
199
|
+
var serverAction_1 = new myServerAction(((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, types, options, function (args) { return originalMethod.apply(undefined, args); });
|
|
200
200
|
serverAction_1.doWork = function (args, self, url, http) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
201
201
|
var _this = this;
|
|
202
202
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -257,7 +257,7 @@ function BackendMethod(options) {
|
|
|
257
257
|
if (!controllerOptions.key) {
|
|
258
258
|
controllerOptions.key = c.repo(constructor).metadata.key;
|
|
259
259
|
}
|
|
260
|
-
reg(controllerOptions.key + '/' + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
260
|
+
reg(controllerOptions.key + '/' + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed, function (d, req, res) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
261
261
|
var allowed, remult_1, r_1, err_3;
|
|
262
262
|
var _this = this;
|
|
263
263
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -415,7 +415,7 @@ function BackendMethod(options) {
|
|
|
415
415
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
416
416
|
}
|
|
417
417
|
return class_1;
|
|
418
|
-
}(Action))(classOptions_1.key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
418
|
+
}(Action))(classOptions_1.key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
|
|
419
419
|
_e = {
|
|
420
420
|
args: args
|
|
421
421
|
};
|
|
@@ -451,7 +451,7 @@ function BackendMethod(options) {
|
|
|
451
451
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
452
452
|
}
|
|
453
453
|
return class_2;
|
|
454
|
-
}(Action))(x.classes.get(self.constructor).key + "/" + key, options ? options.queue : false, options.allowed)).run;
|
|
454
|
+
}(Action))(x.classes.get(self.constructor).key + "/" + ((options === null || options === void 0 ? void 0 : options.apiPrefix) ? (options.apiPrefix + '/') : '') + key, options ? options.queue : false, options.allowed)).run;
|
|
455
455
|
_g = {
|
|
456
456
|
args: args
|
|
457
457
|
};
|
package/src/sort.js
CHANGED
|
@@ -130,6 +130,8 @@ var Sort = /** @class */ (function () {
|
|
|
130
130
|
orderBy = entityMetadata.options.defaultOrderBy;
|
|
131
131
|
if (!orderBy)
|
|
132
132
|
orderBy = (_a = {}, _a[entityMetadata.idMetadata.field.key] = "asc", _a);
|
|
133
|
+
else
|
|
134
|
+
orderBy = tslib_1.__assign({}, orderBy);
|
|
133
135
|
if (entityMetadata.idMetadata.field instanceof column_1.CompoundIdField) {
|
|
134
136
|
try {
|
|
135
137
|
for (var _c = tslib_1.__values(entityMetadata.idMetadata.field.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
|
package/remult-svletekit.d.ts
DELETED
package/remult-svletekit.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remultSveltekit = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var server_1 = require("./server");
|
|
6
|
-
function remultSveltekit(options) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
var result = server_1.createRemultServer(options, {
|
|
9
|
-
buildGenericRequest: function (event) {
|
|
10
|
-
return ({
|
|
11
|
-
url: event.request.url,
|
|
12
|
-
method: event.request.method,
|
|
13
|
-
body: event.locals["_tempJson"],
|
|
14
|
-
on: function (e, do1) {
|
|
15
|
-
if (e === 'close') {
|
|
16
|
-
event.locals["_tempOnClose"] = do1;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var handler = function (_a) {
|
|
23
|
-
var event = _a.event, resolve = _a.resolve;
|
|
24
|
-
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
25
|
-
var json, error_1, sseResponse_1, response_1, responseFromRemultHandler;
|
|
26
|
-
var _this = this;
|
|
27
|
-
return tslib_1.__generator(this, function (_b) {
|
|
28
|
-
switch (_b.label) {
|
|
29
|
-
case 0:
|
|
30
|
-
if (!event.url.pathname.startsWith(options.rootPath)) return [3 /*break*/, 7];
|
|
31
|
-
json = {};
|
|
32
|
-
_b.label = 1;
|
|
33
|
-
case 1:
|
|
34
|
-
_b.trys.push([1, 4, , 5]);
|
|
35
|
-
if (!(event.request.method == 'POST' || event.request.method == 'PUT')) return [3 /*break*/, 3];
|
|
36
|
-
return [4 /*yield*/, event.request.json()];
|
|
37
|
-
case 2:
|
|
38
|
-
json = _b.sent();
|
|
39
|
-
_b.label = 3;
|
|
40
|
-
case 3: return [3 /*break*/, 5];
|
|
41
|
-
case 4:
|
|
42
|
-
error_1 = _b.sent();
|
|
43
|
-
console.log(error_1);
|
|
44
|
-
return [3 /*break*/, 5];
|
|
45
|
-
case 5:
|
|
46
|
-
sseResponse_1 = undefined;
|
|
47
|
-
event.locals["_tempOnClose"] = function () { };
|
|
48
|
-
response_1 = {
|
|
49
|
-
end: function () { },
|
|
50
|
-
json: function () { },
|
|
51
|
-
status: function () {
|
|
52
|
-
return response_1;
|
|
53
|
-
},
|
|
54
|
-
write: function () { },
|
|
55
|
-
writeHead: function (status, headers) {
|
|
56
|
-
if (status === 200 && headers) {
|
|
57
|
-
var contentType = headers['Content-Type'];
|
|
58
|
-
if (contentType === 'text/event-stream') {
|
|
59
|
-
var messages_1 = [];
|
|
60
|
-
response_1.write = function (x) { return messages_1.push(x); };
|
|
61
|
-
var stream = new ReadableStream({
|
|
62
|
-
start: function (controller) {
|
|
63
|
-
var e_1, _a;
|
|
64
|
-
try {
|
|
65
|
-
for (var messages_2 = tslib_1.__values(messages_1), messages_2_1 = messages_2.next(); !messages_2_1.done; messages_2_1 = messages_2.next()) {
|
|
66
|
-
var message = messages_2_1.value;
|
|
67
|
-
controller.enqueue(message);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
71
|
-
finally {
|
|
72
|
-
try {
|
|
73
|
-
if (messages_2_1 && !messages_2_1.done && (_a = messages_2.return)) _a.call(messages_2);
|
|
74
|
-
}
|
|
75
|
-
finally { if (e_1) throw e_1.error; }
|
|
76
|
-
}
|
|
77
|
-
response_1.write = function (data) {
|
|
78
|
-
controller.enqueue(data);
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
cancel: function () {
|
|
82
|
-
response_1.write = function () { };
|
|
83
|
-
event.locals["_tempOnClose"]();
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
sseResponse_1 = new Response(stream, { headers: headers });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
event.locals["_tempJson"] = json;
|
|
92
|
-
return [4 /*yield*/, result.handle(event, response_1)];
|
|
93
|
-
case 6:
|
|
94
|
-
responseFromRemultHandler = _b.sent();
|
|
95
|
-
if (sseResponse_1 !== undefined) {
|
|
96
|
-
return [2 /*return*/, sseResponse_1];
|
|
97
|
-
}
|
|
98
|
-
if (responseFromRemultHandler) {
|
|
99
|
-
return [2 /*return*/, new Response(JSON.stringify(responseFromRemultHandler.data), {
|
|
100
|
-
status: responseFromRemultHandler.statusCode
|
|
101
|
-
})];
|
|
102
|
-
}
|
|
103
|
-
_b.label = 7;
|
|
104
|
-
case 7: return [2 /*return*/, new Promise(function (res) {
|
|
105
|
-
result.withRemult(event, undefined, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
106
|
-
var _a;
|
|
107
|
-
return tslib_1.__generator(this, function (_b) {
|
|
108
|
-
switch (_b.label) {
|
|
109
|
-
case 0:
|
|
110
|
-
_a = res;
|
|
111
|
-
return [4 /*yield*/, resolve(event)];
|
|
112
|
-
case 1:
|
|
113
|
-
_a.apply(void 0, [_b.sent()]);
|
|
114
|
-
return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}); });
|
|
118
|
-
})];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
return Object.assign(handler, {
|
|
124
|
-
getRemult: function (req) { return result.getRemult(req); },
|
|
125
|
-
openApiDoc: function (options) { return result.openApiDoc(options); },
|
|
126
|
-
registerRouter: function (x) { return result.registerRouter(x); },
|
|
127
|
-
withRemult: function () {
|
|
128
|
-
var args = [];
|
|
129
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
130
|
-
args[_i] = arguments[_i];
|
|
131
|
-
}
|
|
132
|
-
return result.withRemult.apply(result, tslib_1.__spread(args));
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
exports.remultSveltekit = remultSveltekit;
|