remult 0.22.9 → 0.22.11-exp2.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/README.md +1 -0
- package/esm/server/JsonEntityFileStorage.d.ts +2 -2
- package/esm/server/JsonEntityFileStorage.js +6 -4
- package/esm/src/context.js +3 -0
- package/esm/src/data-providers/json-data-provider.d.ts +2 -2
- package/esm/src/data-providers/json-data-provider.js +8 -8
- package/esm/src/remult-proxy.js +3 -2
- package/esm/src/remult3/Fields.d.ts +116 -3
- package/package.json +1 -1
- package/server/JsonEntityFileStorage.d.ts +2 -2
- package/server/JsonEntityFileStorage.js +35 -11
- package/src/context.js +3 -0
- package/src/data-providers/json-data-provider.d.ts +2 -2
- package/src/data-providers/json-data-provider.js +39 -16
- package/src/remult-proxy.js +9 -4
- package/src/remult3/Fields.d.ts +116 -3
package/README.md
CHANGED
|
@@ -278,6 +278,7 @@ with a Node.js Express backend.
|
|
|
278
278
|
- [Tutorial with Angular](https://remult.dev/tutorials/angular/)
|
|
279
279
|
- [Tutorial with Vue](https://remult.dev/tutorials/vue/)
|
|
280
280
|
- [Tutorial with Next.js](https://remult.dev/tutorials/react-next/)
|
|
281
|
+
- [Tutorial with Sveltekit](https://remult.dev/tutorials/sveltekit/)
|
|
281
282
|
|
|
282
283
|
## Documentation
|
|
283
284
|
|
|
@@ -2,8 +2,8 @@ import type { JsonEntityStorage } from '../index';
|
|
|
2
2
|
import { JsonDataProvider } from '../index';
|
|
3
3
|
export declare class JsonEntityFileStorage implements JsonEntityStorage {
|
|
4
4
|
private folderPath;
|
|
5
|
-
getItem(entityDbName: string): string
|
|
6
|
-
setItem(entityDbName: string, json: string): void
|
|
5
|
+
getItem(entityDbName: string): Promise<string>;
|
|
6
|
+
setItem(entityDbName: string, json: string): Promise<void>;
|
|
7
7
|
constructor(folderPath: string);
|
|
8
8
|
}
|
|
9
9
|
export declare class JsonFileDataProvider extends JsonDataProvider {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
1
|
import { JsonDataProvider } from '../index';
|
|
4
2
|
export class JsonEntityFileStorage {
|
|
5
3
|
folderPath;
|
|
6
|
-
getItem(entityDbName) {
|
|
4
|
+
async getItem(entityDbName) {
|
|
5
|
+
const path = await import('path');
|
|
6
|
+
const fs = await import('fs');
|
|
7
7
|
let fn = path.join(this.folderPath, entityDbName) + '.json';
|
|
8
8
|
if (fs.existsSync(fn)) {
|
|
9
9
|
return fs.readFileSync(fn).toString();
|
|
10
10
|
}
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
setItem(entityDbName, json) {
|
|
13
|
+
async setItem(entityDbName, json) {
|
|
14
|
+
const path = await import('path');
|
|
15
|
+
const fs = await import('fs');
|
|
14
16
|
if (!fs.existsSync(this.folderPath)) {
|
|
15
17
|
fs.mkdirSync(this.folderPath);
|
|
16
18
|
}
|
package/esm/src/context.js
CHANGED
|
@@ -285,3 +285,6 @@ class transactionLiveQueryPublisher {
|
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
+
//p1 - seems that after backend methods relations are loaded for some reason - see trempim - intake doRequest backend method
|
|
289
|
+
//p1 - reconsider the case in tremping where create user id was updated with some user and not the actual user
|
|
290
|
+
//[ ] - when value changes for field with error, clear error - so the user will feel comfortable
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DataProvider, EntityDataProvider } from '../data-interfaces';
|
|
2
2
|
import type { EntityMetadata } from '../remult3/remult3';
|
|
3
3
|
export interface JsonEntityStorage {
|
|
4
|
-
getItem(entityDbName: string): string | null
|
|
5
|
-
setItem(entityDbName: string, json: string):
|
|
4
|
+
getItem(entityDbName: string): Promise<string | null>;
|
|
5
|
+
setItem(entityDbName: string, json: string): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
export declare class JsonDataProvider implements DataProvider {
|
|
8
8
|
private storage;
|
|
@@ -21,11 +21,11 @@ class JsonEntityDataProvider {
|
|
|
21
21
|
async loadEntityData(what) {
|
|
22
22
|
let data = [];
|
|
23
23
|
let dbName = await this.entity.getDbName();
|
|
24
|
-
let s = this.helper.getItem(dbName);
|
|
24
|
+
let s = await this.helper.getItem(dbName);
|
|
25
25
|
if (s)
|
|
26
26
|
data = JSON.parse(s);
|
|
27
27
|
let dp = new ArrayEntityDataProvider(this.entity, data);
|
|
28
|
-
return what(dp, () => this.helper.setItem(dbName, JSON.stringify(data, undefined, 2)));
|
|
28
|
+
return what(dp, async () => await this.helper.setItem(dbName, JSON.stringify(data, undefined, 2)));
|
|
29
29
|
}
|
|
30
30
|
p = Promise.resolve();
|
|
31
31
|
find(options) {
|
|
@@ -35,20 +35,20 @@ class JsonEntityDataProvider {
|
|
|
35
35
|
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.count(where))));
|
|
36
36
|
}
|
|
37
37
|
update(id, data) {
|
|
38
|
-
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.update(id, data).then((x) => {
|
|
39
|
-
save();
|
|
38
|
+
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.update(id, data).then(async (x) => {
|
|
39
|
+
await save();
|
|
40
40
|
return x;
|
|
41
41
|
}))));
|
|
42
42
|
}
|
|
43
43
|
delete(id) {
|
|
44
|
-
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.delete(id).then((x) => {
|
|
45
|
-
save();
|
|
44
|
+
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.delete(id).then(async (x) => {
|
|
45
|
+
await save();
|
|
46
46
|
return x;
|
|
47
47
|
}))));
|
|
48
48
|
}
|
|
49
49
|
async insert(data) {
|
|
50
|
-
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.insert(data).then((x) => {
|
|
51
|
-
save();
|
|
50
|
+
return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.insert(data).then(async (x) => {
|
|
51
|
+
await save();
|
|
52
52
|
return x;
|
|
53
53
|
}))));
|
|
54
54
|
}
|
package/esm/src/remult-proxy.js
CHANGED
|
@@ -81,10 +81,11 @@ export class RemultProxy {
|
|
|
81
81
|
get fields() {
|
|
82
82
|
return self.remultFactory().repo(...args).metadata.fields;
|
|
83
83
|
},
|
|
84
|
-
validate: (a, b) => self
|
|
84
|
+
validate: (a, ...b) => self
|
|
85
85
|
.remultFactory()
|
|
86
86
|
.repo(...args)
|
|
87
|
-
|
|
87
|
+
//@ts-ignore
|
|
88
|
+
.validate(a, ...b),
|
|
88
89
|
addEventListener: (...args2) => self
|
|
89
90
|
.remultFactory()
|
|
90
91
|
.repo(...args)
|
|
@@ -21,15 +21,128 @@ export declare class Fields {
|
|
|
21
21
|
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
22
22
|
}
|
|
23
23
|
export declare class Relations {
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
26
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
27
|
+
* to represent the relation.
|
|
28
|
+
*
|
|
29
|
+
* @param toEntityType A function that returns the target entity type.
|
|
30
|
+
* @param options (Optional): An object containing options for configuring the to-one relation.
|
|
31
|
+
* @returns A decorator function to apply the to-one relation to an entity field.
|
|
32
|
+
*
|
|
33
|
+
* Example usage:
|
|
34
|
+
* ```
|
|
35
|
+
* @Relations.toOne(() => Customer)
|
|
36
|
+
* customer?: Customer;
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
25
39
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
26
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
42
|
+
* If no `fieldInMyEntity` is provided, this overload will automatically create a field in the database
|
|
43
|
+
* to represent the relation.
|
|
44
|
+
*
|
|
45
|
+
* @param toEntityType A function that returns the target entity type.
|
|
46
|
+
* @param fieldInMyEntity (Optional): The field in the current entity that represents the relation.
|
|
47
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
48
|
+
* @returns A decorator function to apply the to-one relation to an entity field.
|
|
49
|
+
*
|
|
50
|
+
* Example usage:
|
|
51
|
+
* ```
|
|
52
|
+
* @Relations.toOne(() => Customer)
|
|
53
|
+
* customer?: Customer;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
27
56
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
28
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
59
|
+
* This overload allows you to define the relation using options.
|
|
60
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
61
|
+
* to represent the relation.
|
|
62
|
+
*
|
|
63
|
+
* @param toEntityType A function that returns the target entity type.
|
|
64
|
+
* @param options An object containing options for configuring the to-one relation.
|
|
65
|
+
* - field (Optional): The name of the field in the related entity that corresponds to this relation.
|
|
66
|
+
* @returns A decorator function to apply the virtual to-one relation to an entity field.
|
|
67
|
+
*
|
|
68
|
+
* Example usage:
|
|
69
|
+
* ```
|
|
70
|
+
* @Relations.toOne(() => Customer, {
|
|
71
|
+
* field: "customerId",
|
|
72
|
+
* })
|
|
73
|
+
* customer?: Customer;
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
79
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
80
|
+
* to represent the relation.
|
|
81
|
+
*
|
|
82
|
+
* @param toEntityType A function that returns the target entity type.
|
|
83
|
+
* @param options An object containing options for configuring the to-one relation.
|
|
84
|
+
* - fields (Optional): An object specifying custom field names for the relation.
|
|
85
|
+
* @returns A decorator function to apply the virtual to-one relation to an entity field.
|
|
86
|
+
*
|
|
87
|
+
* Example usage:
|
|
88
|
+
* ```
|
|
89
|
+
* @Relations.toOne(() => Customer, {
|
|
90
|
+
* fields: {
|
|
91
|
+
* customerId: "id",
|
|
92
|
+
* },
|
|
93
|
+
* })
|
|
94
|
+
* customer?: Customer;
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
29
97
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'field'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
30
98
|
/** A to one relation with fields defined in the field/fields parameter */
|
|
31
99
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'fields'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Define a toMany relation between entities, indicating a one-to-many relationship.
|
|
102
|
+
* This method allows you to establish a relationship where one entity can have multiple related entities.
|
|
103
|
+
*
|
|
104
|
+
* @param toEntityType A function that returns the target entity type.
|
|
105
|
+
* @param fieldInToEntity (Optional) The field in the target entity that represents the relation.
|
|
106
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
107
|
+
* @returns A decorator function to apply the toMany relation to an entity field.
|
|
108
|
+
*
|
|
109
|
+
* Example usage:
|
|
110
|
+
* ```
|
|
111
|
+
* @Relations.toMany(() => Order)
|
|
112
|
+
* orders?: Order[];
|
|
113
|
+
*
|
|
114
|
+
* // or with a custom field name:
|
|
115
|
+
* @Relations.toMany(() => Order, "customerId")
|
|
116
|
+
* orders?: Order[];
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
32
119
|
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
120
|
+
/**
|
|
121
|
+
* Define a toMany relation between entities, indicating a one-to-many relationship.
|
|
122
|
+
* This method allows you to establish a relationship where one entity can have multiple related entities.
|
|
123
|
+
* You can also specify various options to customize the relation and control related data retrieval.
|
|
124
|
+
*
|
|
125
|
+
* @param toEntityType A function that returns the target entity type.
|
|
126
|
+
* @param options An object containing options for configuring the toMany relation.
|
|
127
|
+
* - field (Optional): The field in the target entity that represents the relation.
|
|
128
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
129
|
+
* - findOptions (Optional): Customize the options for finding related entities.
|
|
130
|
+
* You can set limits, order, where conditions, and more.
|
|
131
|
+
* @returns A decorator function to apply the toMany relation to an entity field.
|
|
132
|
+
*
|
|
133
|
+
* Example usage:
|
|
134
|
+
* ```
|
|
135
|
+
* @Relations.toMany(() => Order, {
|
|
136
|
+
* field: "customerOrders",
|
|
137
|
+
* findOptions: {
|
|
138
|
+
* limit: 10,
|
|
139
|
+
* orderBy: { amount: "desc" },
|
|
140
|
+
* where: { completed: true },
|
|
141
|
+
* },
|
|
142
|
+
* })
|
|
143
|
+
* orders?: Order[];
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
33
146
|
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
34
147
|
}
|
|
35
148
|
/**Decorates fields that should be used as fields.
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@ import type { JsonEntityStorage } from '../index';
|
|
|
2
2
|
import { JsonDataProvider } from '../index';
|
|
3
3
|
export declare class JsonEntityFileStorage implements JsonEntityStorage {
|
|
4
4
|
private folderPath;
|
|
5
|
-
getItem(entityDbName: string): string
|
|
6
|
-
setItem(entityDbName: string, json: string): void
|
|
5
|
+
getItem(entityDbName: string): Promise<string>;
|
|
6
|
+
setItem(entityDbName: string, json: string): Promise<void>;
|
|
7
7
|
constructor(folderPath: string);
|
|
8
8
|
}
|
|
9
9
|
export declare class JsonFileDataProvider extends JsonDataProvider {
|
|
@@ -2,25 +2,49 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonFileDataProvider = exports.JsonEntityFileStorage = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var fs = tslib_1.__importStar(require("fs"));
|
|
6
|
-
var path = tslib_1.__importStar(require("path"));
|
|
7
5
|
var index_1 = require("../index");
|
|
8
6
|
var JsonEntityFileStorage = /** @class */ (function () {
|
|
9
7
|
function JsonEntityFileStorage(folderPath) {
|
|
10
8
|
this.folderPath = folderPath;
|
|
11
9
|
}
|
|
12
10
|
JsonEntityFileStorage.prototype.getItem = function (entityDbName) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
12
|
+
var path, fs, fn;
|
|
13
|
+
return tslib_1.__generator(this, function (_a) {
|
|
14
|
+
switch (_a.label) {
|
|
15
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('path')); })];
|
|
16
|
+
case 1:
|
|
17
|
+
path = _a.sent();
|
|
18
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('fs')); })];
|
|
19
|
+
case 2:
|
|
20
|
+
fs = _a.sent();
|
|
21
|
+
fn = path.join(this.folderPath, entityDbName) + '.json';
|
|
22
|
+
if (fs.existsSync(fn)) {
|
|
23
|
+
return [2 /*return*/, fs.readFileSync(fn).toString()];
|
|
24
|
+
}
|
|
25
|
+
return [2 /*return*/, undefined];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
18
29
|
};
|
|
19
30
|
JsonEntityFileStorage.prototype.setItem = function (entityDbName, json) {
|
|
20
|
-
|
|
21
|
-
fs
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
32
|
+
var path, fs;
|
|
33
|
+
return tslib_1.__generator(this, function (_a) {
|
|
34
|
+
switch (_a.label) {
|
|
35
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('path')); })];
|
|
36
|
+
case 1:
|
|
37
|
+
path = _a.sent();
|
|
38
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('fs')); })];
|
|
39
|
+
case 2:
|
|
40
|
+
fs = _a.sent();
|
|
41
|
+
if (!fs.existsSync(this.folderPath)) {
|
|
42
|
+
fs.mkdirSync(this.folderPath);
|
|
43
|
+
}
|
|
44
|
+
return [2 /*return*/, fs.writeFileSync(path.join(this.folderPath, entityDbName) + '.json', json)];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
24
48
|
};
|
|
25
49
|
return JsonEntityFileStorage;
|
|
26
50
|
}());
|
package/src/context.js
CHANGED
|
@@ -449,3 +449,6 @@ var transactionLiveQueryPublisher = /** @class */ (function () {
|
|
|
449
449
|
};
|
|
450
450
|
return transactionLiveQueryPublisher;
|
|
451
451
|
}());
|
|
452
|
+
//p1 - seems that after backend methods relations are loaded for some reason - see trempim - intake doRequest backend method
|
|
453
|
+
//p1 - reconsider the case in tremping where create user id was updated with some user and not the actual user
|
|
454
|
+
//[ ] - when value changes for field with error, clear error - so the user will feel comfortable
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { DataProvider, EntityDataProvider } from '../data-interfaces';
|
|
2
2
|
import type { EntityMetadata } from '../remult3/remult3';
|
|
3
3
|
export interface JsonEntityStorage {
|
|
4
|
-
getItem(entityDbName: string): string | null
|
|
5
|
-
setItem(entityDbName: string, json: string):
|
|
4
|
+
getItem(entityDbName: string): Promise<string | null>;
|
|
5
|
+
setItem(entityDbName: string, json: string): Promise<void>;
|
|
6
6
|
}
|
|
7
7
|
export declare class JsonDataProvider implements DataProvider {
|
|
8
8
|
private storage;
|
|
@@ -42,13 +42,18 @@ var JsonEntityDataProvider = /** @class */ (function () {
|
|
|
42
42
|
return [4 /*yield*/, this.entity.getDbName()];
|
|
43
43
|
case 1:
|
|
44
44
|
dbName = _a.sent();
|
|
45
|
-
|
|
45
|
+
return [4 /*yield*/, this.helper.getItem(dbName)];
|
|
46
|
+
case 2:
|
|
47
|
+
s = _a.sent();
|
|
46
48
|
if (s)
|
|
47
49
|
data = JSON.parse(s);
|
|
48
50
|
dp = new array_entity_data_provider_1.ArrayEntityDataProvider(this.entity, data);
|
|
49
|
-
return [2 /*return*/, what(dp, function () {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
return [2 /*return*/, what(dp, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, this.helper.setItem(dbName, JSON.stringify(data, undefined, 2))];
|
|
54
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
55
|
+
}
|
|
56
|
+
}); }); })];
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
59
|
});
|
|
@@ -69,10 +74,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
|
|
|
69
74
|
var _this = this;
|
|
70
75
|
return (this.p = this.p.then(function () {
|
|
71
76
|
return _this.loadEntityData(function (dp, save) {
|
|
72
|
-
return dp.update(id, data).then(function (x) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
return dp.update(id, data).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
78
|
+
return tslib_1.__generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, save()];
|
|
81
|
+
case 1:
|
|
82
|
+
_a.sent();
|
|
83
|
+
return [2 /*return*/, x];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}); });
|
|
76
87
|
});
|
|
77
88
|
}));
|
|
78
89
|
};
|
|
@@ -80,10 +91,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
|
|
|
80
91
|
var _this = this;
|
|
81
92
|
return (this.p = this.p.then(function () {
|
|
82
93
|
return _this.loadEntityData(function (dp, save) {
|
|
83
|
-
return dp.delete(id).then(function (x) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
return dp.delete(id).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
95
|
+
return tslib_1.__generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, save()];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.sent();
|
|
100
|
+
return [2 /*return*/, x];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}); });
|
|
87
104
|
});
|
|
88
105
|
}));
|
|
89
106
|
};
|
|
@@ -93,10 +110,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
|
|
|
93
110
|
return tslib_1.__generator(this, function (_a) {
|
|
94
111
|
return [2 /*return*/, (this.p = this.p.then(function () {
|
|
95
112
|
return _this.loadEntityData(function (dp, save) {
|
|
96
|
-
return dp.insert(data).then(function (x) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
return dp.insert(data).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
114
|
+
return tslib_1.__generator(this, function (_a) {
|
|
115
|
+
switch (_a.label) {
|
|
116
|
+
case 0: return [4 /*yield*/, save()];
|
|
117
|
+
case 1:
|
|
118
|
+
_a.sent();
|
|
119
|
+
return [2 /*return*/, x];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); });
|
|
100
123
|
});
|
|
101
124
|
}))];
|
|
102
125
|
});
|
package/src/remult-proxy.js
CHANGED
|
@@ -35,11 +35,16 @@ var RemultProxy = /** @class */ (function () {
|
|
|
35
35
|
var _a;
|
|
36
36
|
return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata.fields;
|
|
37
37
|
},
|
|
38
|
-
validate: function (a
|
|
39
|
-
var _a;
|
|
40
|
-
|
|
38
|
+
validate: function (a) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
var b = [];
|
|
41
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
42
|
+
b[_i - 1] = arguments[_i];
|
|
43
|
+
}
|
|
44
|
+
return (_a = (_b = self
|
|
41
45
|
.remultFactory())
|
|
42
|
-
.repo.apply(
|
|
46
|
+
.repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
|
|
47
|
+
.validate.apply(_a, tslib_1.__spreadArray([a], tslib_1.__read(b), false));
|
|
43
48
|
},
|
|
44
49
|
addEventListener: function () {
|
|
45
50
|
var _a, _b;
|
package/src/remult3/Fields.d.ts
CHANGED
|
@@ -21,15 +21,128 @@ export declare class Fields {
|
|
|
21
21
|
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
22
22
|
}
|
|
23
23
|
export declare class Relations {
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
26
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
27
|
+
* to represent the relation.
|
|
28
|
+
*
|
|
29
|
+
* @param toEntityType A function that returns the target entity type.
|
|
30
|
+
* @param options (Optional): An object containing options for configuring the to-one relation.
|
|
31
|
+
* @returns A decorator function to apply the to-one relation to an entity field.
|
|
32
|
+
*
|
|
33
|
+
* Example usage:
|
|
34
|
+
* ```
|
|
35
|
+
* @Relations.toOne(() => Customer)
|
|
36
|
+
* customer?: Customer;
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
25
39
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
26
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
42
|
+
* If no `fieldInMyEntity` is provided, this overload will automatically create a field in the database
|
|
43
|
+
* to represent the relation.
|
|
44
|
+
*
|
|
45
|
+
* @param toEntityType A function that returns the target entity type.
|
|
46
|
+
* @param fieldInMyEntity (Optional): The field in the current entity that represents the relation.
|
|
47
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
48
|
+
* @returns A decorator function to apply the to-one relation to an entity field.
|
|
49
|
+
*
|
|
50
|
+
* Example usage:
|
|
51
|
+
* ```
|
|
52
|
+
* @Relations.toOne(() => Customer)
|
|
53
|
+
* customer?: Customer;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
27
56
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
28
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
59
|
+
* This overload allows you to define the relation using options.
|
|
60
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
61
|
+
* to represent the relation.
|
|
62
|
+
*
|
|
63
|
+
* @param toEntityType A function that returns the target entity type.
|
|
64
|
+
* @param options An object containing options for configuring the to-one relation.
|
|
65
|
+
* - field (Optional): The name of the field in the related entity that corresponds to this relation.
|
|
66
|
+
* @returns A decorator function to apply the virtual to-one relation to an entity field.
|
|
67
|
+
*
|
|
68
|
+
* Example usage:
|
|
69
|
+
* ```
|
|
70
|
+
* @Relations.toOne(() => Customer, {
|
|
71
|
+
* field: "customerId",
|
|
72
|
+
* })
|
|
73
|
+
* customer?: Customer;
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
79
|
+
* If no field or fields are provided, it will automatically create a field in the database
|
|
80
|
+
* to represent the relation.
|
|
81
|
+
*
|
|
82
|
+
* @param toEntityType A function that returns the target entity type.
|
|
83
|
+
* @param options An object containing options for configuring the to-one relation.
|
|
84
|
+
* - fields (Optional): An object specifying custom field names for the relation.
|
|
85
|
+
* @returns A decorator function to apply the virtual to-one relation to an entity field.
|
|
86
|
+
*
|
|
87
|
+
* Example usage:
|
|
88
|
+
* ```
|
|
89
|
+
* @Relations.toOne(() => Customer, {
|
|
90
|
+
* fields: {
|
|
91
|
+
* customerId: "id",
|
|
92
|
+
* },
|
|
93
|
+
* })
|
|
94
|
+
* customer?: Customer;
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
29
97
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'field'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
30
98
|
/** A to one relation with fields defined in the field/fields parameter */
|
|
31
99
|
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'fields'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Define a toMany relation between entities, indicating a one-to-many relationship.
|
|
102
|
+
* This method allows you to establish a relationship where one entity can have multiple related entities.
|
|
103
|
+
*
|
|
104
|
+
* @param toEntityType A function that returns the target entity type.
|
|
105
|
+
* @param fieldInToEntity (Optional) The field in the target entity that represents the relation.
|
|
106
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
107
|
+
* @returns A decorator function to apply the toMany relation to an entity field.
|
|
108
|
+
*
|
|
109
|
+
* Example usage:
|
|
110
|
+
* ```
|
|
111
|
+
* @Relations.toMany(() => Order)
|
|
112
|
+
* orders?: Order[];
|
|
113
|
+
*
|
|
114
|
+
* // or with a custom field name:
|
|
115
|
+
* @Relations.toMany(() => Order, "customerId")
|
|
116
|
+
* orders?: Order[];
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
32
119
|
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
120
|
+
/**
|
|
121
|
+
* Define a toMany relation between entities, indicating a one-to-many relationship.
|
|
122
|
+
* This method allows you to establish a relationship where one entity can have multiple related entities.
|
|
123
|
+
* You can also specify various options to customize the relation and control related data retrieval.
|
|
124
|
+
*
|
|
125
|
+
* @param toEntityType A function that returns the target entity type.
|
|
126
|
+
* @param options An object containing options for configuring the toMany relation.
|
|
127
|
+
* - field (Optional): The field in the target entity that represents the relation.
|
|
128
|
+
* Use this if you want to specify a custom field name for the relation.
|
|
129
|
+
* - findOptions (Optional): Customize the options for finding related entities.
|
|
130
|
+
* You can set limits, order, where conditions, and more.
|
|
131
|
+
* @returns A decorator function to apply the toMany relation to an entity field.
|
|
132
|
+
*
|
|
133
|
+
* Example usage:
|
|
134
|
+
* ```
|
|
135
|
+
* @Relations.toMany(() => Order, {
|
|
136
|
+
* field: "customerOrders",
|
|
137
|
+
* findOptions: {
|
|
138
|
+
* limit: 10,
|
|
139
|
+
* orderBy: { amount: "desc" },
|
|
140
|
+
* where: { completed: true },
|
|
141
|
+
* },
|
|
142
|
+
* })
|
|
143
|
+
* orders?: Order[];
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
33
146
|
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
34
147
|
}
|
|
35
148
|
/**Decorates fields that should be used as fields.
|