remult 0.23.0-exp.14 → 0.23.0-exp.16
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/index.d.ts +1 -1
- package/esm/src/column-interfaces.d.ts +14 -2
- package/esm/src/remult3/Fields.d.ts +116 -3
- package/esm/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/esm/src/remult3/RepositoryImplementation.js +5 -2
- package/esm/src/remult3/remult3.d.ts +62 -3
- package/esm/src/remult3/remult3.js +2 -0
- package/esm/src/server-action.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/column-interfaces.d.ts +14 -2
- package/src/remult3/Fields.d.ts +116 -3
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/RepositoryImplementation.js +6 -2
- package/src/remult3/remult3.d.ts +62 -3
- package/src/remult3/remult3.js +2 -0
- package/src/server-action.js +1 -1
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassType } from './classType';
|
|
2
|
-
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions,
|
|
2
|
+
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator as MemberDecorator, ClassFieldDecoratorContextStub, } from './src/remult3/remult3';
|
|
3
3
|
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
4
4
|
export { Entity } from './src/remult3/entity';
|
|
5
5
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
|
@@ -69,8 +69,20 @@ export interface FieldOptions<entityType = any, valueType = any> {
|
|
|
69
69
|
defaultValue?: (entity: entityType) => valueType | Promise<valueType>;
|
|
70
70
|
/** The html input type for this field */
|
|
71
71
|
inputType?: string;
|
|
72
|
-
/**
|
|
73
|
-
* @
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated The 'lazy' option is deprecated and will be removed in future versions.
|
|
74
|
+
* Use 'Relations.toOne' instead.
|
|
75
|
+
*
|
|
76
|
+
* Example usage:
|
|
77
|
+
* ```
|
|
78
|
+
* // Deprecated usage with 'lazy' option
|
|
79
|
+
* @Field(() => Customer, { lazy: true })
|
|
80
|
+
* customer?: Customer;
|
|
81
|
+
*
|
|
82
|
+
* // Preferred usage with 'Relations.toOne'
|
|
83
|
+
* @Relations.toOne(() => Customer)
|
|
84
|
+
* customer?: Customer;
|
|
85
|
+
* ```
|
|
74
86
|
*/
|
|
75
87
|
lazy?: boolean;
|
|
76
88
|
/** The value type for this field */
|
|
@@ -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.
|
|
@@ -105,7 +105,7 @@ declare abstract class rowHelperBase<T> {
|
|
|
105
105
|
__validateEntity(): Promise<void>;
|
|
106
106
|
__performColumnAndEntityValidations(): Promise<void>;
|
|
107
107
|
toApiJson(includeRelatedEntities?: boolean): any;
|
|
108
|
-
_updateEntityBasedOnApi(body: any): Promise<void>;
|
|
108
|
+
_updateEntityBasedOnApi(body: any, ignoreApiAllowed?: boolean): Promise<void>;
|
|
109
109
|
}
|
|
110
110
|
export declare class rowHelperImplementation<T> extends rowHelperBase<T> implements EntityRef<T> {
|
|
111
111
|
private info;
|
|
@@ -999,7 +999,9 @@ class rowHelperBase {
|
|
|
999
999
|
if (val !== undefined && val !== null)
|
|
1000
1000
|
val = col.valueConverter.fromJson(JSON.parse(JSON.stringify(val)));
|
|
1001
1001
|
}
|
|
1002
|
-
|
|
1002
|
+
const rel = getRelationInfo(col);
|
|
1003
|
+
if (!rel || rel.type === 'reference')
|
|
1004
|
+
d[col.key] = val;
|
|
1003
1005
|
}
|
|
1004
1006
|
return d;
|
|
1005
1007
|
}
|
|
@@ -1062,13 +1064,14 @@ class rowHelperBase {
|
|
|
1062
1064
|
}
|
|
1063
1065
|
return result;
|
|
1064
1066
|
}
|
|
1065
|
-
async _updateEntityBasedOnApi(body) {
|
|
1067
|
+
async _updateEntityBasedOnApi(body, ignoreApiAllowed = false) {
|
|
1066
1068
|
let keys = Object.keys(body);
|
|
1067
1069
|
for (const col of this.columnsInfo) {
|
|
1068
1070
|
if (keys.includes(col.key))
|
|
1069
1071
|
if (col.includeInApi === undefined ||
|
|
1070
1072
|
this.remult.isAllowed(col.includeInApi)) {
|
|
1071
1073
|
if (!this.remult ||
|
|
1074
|
+
ignoreApiAllowed ||
|
|
1072
1075
|
col.allowApiUpdate === undefined ||
|
|
1073
1076
|
this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
1074
1077
|
let lu = this.lookups.get(col.key);
|
|
@@ -312,7 +312,7 @@ export declare type EntityOrderBy<entityType> = {
|
|
|
312
312
|
export declare type EntityFilter<entityType> = {
|
|
313
313
|
[Properties in keyof Partial<OmitEB<entityType>>]?: (Partial<OmitEB<entityType>>[Properties] extends number | Date | undefined ? ComparisonValueFilter<Partial<OmitEB<entityType>>[Properties]> : Partial<OmitEB<entityType>>[Properties] extends string | undefined ? ContainsStringValueFilter & ComparisonValueFilter<string> : Partial<OmitEB<entityType>>[Properties] extends boolean | undefined ? ValueFilter<boolean> : Partial<OmitEB<entityType>>[Properties] extends {
|
|
314
314
|
id?: string | number;
|
|
315
|
-
} | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>)
|
|
315
|
+
} | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>) | ContainsStringValueFilter;
|
|
316
316
|
} & {
|
|
317
317
|
$or?: EntityFilter<entityType>[];
|
|
318
318
|
$and?: EntityFilter<entityType>[];
|
|
@@ -342,7 +342,46 @@ export type IdFilter<valueType> = ValueFilter<valueType> | {
|
|
|
342
342
|
} ? number : string>;
|
|
343
343
|
};
|
|
344
344
|
export interface LoadOptions<entityType> {
|
|
345
|
+
/**
|
|
346
|
+
* @deprecated The 'load' option is deprecated and will be removed in future versions.
|
|
347
|
+
* Use 'Relations.toOne' along with the 'include' option instead.
|
|
348
|
+
*
|
|
349
|
+
* Example usage:
|
|
350
|
+
* ```
|
|
351
|
+
* // Deprecated usage with 'load' option
|
|
352
|
+
* await remult.repo(Order).find({
|
|
353
|
+
* load: (o) => [o.customer],
|
|
354
|
+
* });
|
|
355
|
+
*
|
|
356
|
+
*
|
|
357
|
+
* // Preferred usage with 'Relations.toOne' and 'include' option
|
|
358
|
+
* await remult.repo(Order).find({
|
|
359
|
+
* include: { customer: true },
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
345
363
|
load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[];
|
|
364
|
+
/**
|
|
365
|
+
* An option used in the `find` and `findFirst` methods to specify which related entities should be included
|
|
366
|
+
* when querying the source entity. It allows you to eagerly load related data to avoid N+1 query problems.
|
|
367
|
+
*
|
|
368
|
+
* @param include An object specifying the related entities to include, their options, and filtering criteria.
|
|
369
|
+
*
|
|
370
|
+
* Example usage:
|
|
371
|
+
* ```
|
|
372
|
+
* const orders = await customerRepo.find({
|
|
373
|
+
* include: {
|
|
374
|
+
* // Include the 'tags' relation for each customer.
|
|
375
|
+
* tags: true,
|
|
376
|
+
* },
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
379
|
+
* In this example, the `tags` relation for each customer will be loaded and included in the query result.
|
|
380
|
+
*
|
|
381
|
+
* @see {@link Relations.toMany}
|
|
382
|
+
* @see {@link Relations.toOne}
|
|
383
|
+
* @see {@link RelationOptions}
|
|
384
|
+
*/
|
|
346
385
|
include?: MembersToInclude<entityType>;
|
|
347
386
|
}
|
|
348
387
|
export interface FindOptionsBase<entityType> extends LoadOptions<entityType> {
|
|
@@ -413,14 +452,34 @@ export interface RelationInfo {
|
|
|
413
452
|
toType: () => any;
|
|
414
453
|
type: 'reference' | 'toOne' | 'toMany';
|
|
415
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Options for configuring a relation between entities.
|
|
457
|
+
*
|
|
458
|
+
* @template fromEntity The type of the source entity (the entity defining the relation).
|
|
459
|
+
* @template toEntity The type of the target entity (the related entity).
|
|
460
|
+
* @template matchIdEntity The type used for matching IDs in the relation.
|
|
461
|
+
* @template optionsType The type of find options to apply to the relation (default is FindOptionsBase<toEntity>).
|
|
462
|
+
*/
|
|
416
463
|
export type RelationOptions<fromEntity, toEntity, matchIdEntity, optionsType extends FindOptionsBase<toEntity> = FindOptionsBase<toEntity>> = {
|
|
417
464
|
fields?: {
|
|
418
465
|
[K in keyof toEntity]?: keyof fromEntity;
|
|
419
466
|
};
|
|
467
|
+
/**
|
|
468
|
+
* The name of the field for this relation.
|
|
469
|
+
*/
|
|
420
470
|
field?: keyof matchIdEntity;
|
|
421
|
-
|
|
422
|
-
|
|
471
|
+
/**
|
|
472
|
+
* Find options to apply to the relation when fetching related entities.
|
|
473
|
+
* You can specify a predefined set of find options or provide a function that takes the source entity
|
|
474
|
+
* and returns find options dynamically.
|
|
475
|
+
* These options allow you to customize how related entities are retrieved.
|
|
476
|
+
*/
|
|
423
477
|
findOptions?: optionsType | ((entity: fromEntity) => optionsType);
|
|
478
|
+
/**
|
|
479
|
+
* Determines whether the relation should be included by default when querying the source entity.
|
|
480
|
+
* When set to true, related entities will be automatically included when querying the source entity.
|
|
481
|
+
* If false or not specified, related entities will need to be explicitly included using the `include` option.
|
|
482
|
+
*/
|
|
424
483
|
defaultIncluded?: boolean;
|
|
425
484
|
} & Pick<FieldOptions, 'caption'>;
|
|
426
485
|
export type ObjectMembersOnly<T> = {
|
package/esm/src/server-action.js
CHANGED
|
@@ -268,7 +268,7 @@ export function BackendMethod(options) {
|
|
|
268
268
|
id: defs.getOriginalId(),
|
|
269
269
|
},
|
|
270
270
|
}, baseUrl, http);
|
|
271
|
-
await defs._updateEntityBasedOnApi(r.rowInfo.data);
|
|
271
|
+
await defs._updateEntityBasedOnApi(r.rowInfo.data, true);
|
|
272
272
|
return r.result;
|
|
273
273
|
}
|
|
274
274
|
catch (err) {
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassType } from './classType';
|
|
2
|
-
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions,
|
|
2
|
+
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, Subscribable, RefSubscriber, RefSubscriberBase, RelationOptions, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, ClassFieldDecorator as MemberDecorator, ClassFieldDecoratorContextStub, } from './src/remult3/remult3';
|
|
3
3
|
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
4
4
|
export { Entity } from './src/remult3/entity';
|
|
5
5
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
package/package.json
CHANGED
|
@@ -69,8 +69,20 @@ export interface FieldOptions<entityType = any, valueType = any> {
|
|
|
69
69
|
defaultValue?: (entity: entityType) => valueType | Promise<valueType>;
|
|
70
70
|
/** The html input type for this field */
|
|
71
71
|
inputType?: string;
|
|
72
|
-
/**
|
|
73
|
-
* @
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated The 'lazy' option is deprecated and will be removed in future versions.
|
|
74
|
+
* Use 'Relations.toOne' instead.
|
|
75
|
+
*
|
|
76
|
+
* Example usage:
|
|
77
|
+
* ```
|
|
78
|
+
* // Deprecated usage with 'lazy' option
|
|
79
|
+
* @Field(() => Customer, { lazy: true })
|
|
80
|
+
* customer?: Customer;
|
|
81
|
+
*
|
|
82
|
+
* // Preferred usage with 'Relations.toOne'
|
|
83
|
+
* @Relations.toOne(() => Customer)
|
|
84
|
+
* customer?: Customer;
|
|
85
|
+
* ```
|
|
74
86
|
*/
|
|
75
87
|
lazy?: boolean;
|
|
76
88
|
/** The value type for this field */
|
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.
|
|
@@ -105,7 +105,7 @@ declare abstract class rowHelperBase<T> {
|
|
|
105
105
|
__validateEntity(): Promise<void>;
|
|
106
106
|
__performColumnAndEntityValidations(): Promise<void>;
|
|
107
107
|
toApiJson(includeRelatedEntities?: boolean): any;
|
|
108
|
-
_updateEntityBasedOnApi(body: any): Promise<void>;
|
|
108
|
+
_updateEntityBasedOnApi(body: any, ignoreApiAllowed?: boolean): Promise<void>;
|
|
109
109
|
}
|
|
110
110
|
export declare class rowHelperImplementation<T> extends rowHelperBase<T> implements EntityRef<T> {
|
|
111
111
|
private info;
|
|
@@ -1554,7 +1554,9 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1554
1554
|
if (val !== undefined && val !== null)
|
|
1555
1555
|
val = col.valueConverter.fromJson(JSON.parse(JSON.stringify(val)));
|
|
1556
1556
|
}
|
|
1557
|
-
|
|
1557
|
+
var rel = (0, relationInfoMember_1.getRelationInfo)(col);
|
|
1558
|
+
if (!rel || rel.type === 'reference')
|
|
1559
|
+
d[col.key] = val;
|
|
1558
1560
|
}
|
|
1559
1561
|
}
|
|
1560
1562
|
catch (e_25_1) { e_25 = { error: e_25_1 }; }
|
|
@@ -1667,7 +1669,8 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1667
1669
|
}
|
|
1668
1670
|
return result;
|
|
1669
1671
|
};
|
|
1670
|
-
rowHelperBase.prototype._updateEntityBasedOnApi = function (body) {
|
|
1672
|
+
rowHelperBase.prototype._updateEntityBasedOnApi = function (body, ignoreApiAllowed) {
|
|
1673
|
+
if (ignoreApiAllowed === void 0) { ignoreApiAllowed = false; }
|
|
1671
1674
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1672
1675
|
var keys, _a, _b, col, lu;
|
|
1673
1676
|
var e_27, _c;
|
|
@@ -1682,6 +1685,7 @@ var rowHelperBase = /** @class */ (function () {
|
|
|
1682
1685
|
if (col.includeInApi === undefined ||
|
|
1683
1686
|
this.remult.isAllowed(col.includeInApi)) {
|
|
1684
1687
|
if (!this.remult ||
|
|
1688
|
+
ignoreApiAllowed ||
|
|
1685
1689
|
col.allowApiUpdate === undefined ||
|
|
1686
1690
|
this.remult.isAllowedForInstance(this.instance, col.allowApiUpdate)) {
|
|
1687
1691
|
lu = this.lookups.get(col.key);
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -312,7 +312,7 @@ export declare type EntityOrderBy<entityType> = {
|
|
|
312
312
|
export declare type EntityFilter<entityType> = {
|
|
313
313
|
[Properties in keyof Partial<OmitEB<entityType>>]?: (Partial<OmitEB<entityType>>[Properties] extends number | Date | undefined ? ComparisonValueFilter<Partial<OmitEB<entityType>>[Properties]> : Partial<OmitEB<entityType>>[Properties] extends string | undefined ? ContainsStringValueFilter & ComparisonValueFilter<string> : Partial<OmitEB<entityType>>[Properties] extends boolean | undefined ? ValueFilter<boolean> : Partial<OmitEB<entityType>>[Properties] extends {
|
|
314
314
|
id?: string | number;
|
|
315
|
-
} | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>)
|
|
315
|
+
} | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>) | ContainsStringValueFilter;
|
|
316
316
|
} & {
|
|
317
317
|
$or?: EntityFilter<entityType>[];
|
|
318
318
|
$and?: EntityFilter<entityType>[];
|
|
@@ -342,7 +342,46 @@ export type IdFilter<valueType> = ValueFilter<valueType> | {
|
|
|
342
342
|
} ? number : string>;
|
|
343
343
|
};
|
|
344
344
|
export interface LoadOptions<entityType> {
|
|
345
|
+
/**
|
|
346
|
+
* @deprecated The 'load' option is deprecated and will be removed in future versions.
|
|
347
|
+
* Use 'Relations.toOne' along with the 'include' option instead.
|
|
348
|
+
*
|
|
349
|
+
* Example usage:
|
|
350
|
+
* ```
|
|
351
|
+
* // Deprecated usage with 'load' option
|
|
352
|
+
* await remult.repo(Order).find({
|
|
353
|
+
* load: (o) => [o.customer],
|
|
354
|
+
* });
|
|
355
|
+
*
|
|
356
|
+
*
|
|
357
|
+
* // Preferred usage with 'Relations.toOne' and 'include' option
|
|
358
|
+
* await remult.repo(Order).find({
|
|
359
|
+
* include: { customer: true },
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
345
363
|
load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[];
|
|
364
|
+
/**
|
|
365
|
+
* An option used in the `find` and `findFirst` methods to specify which related entities should be included
|
|
366
|
+
* when querying the source entity. It allows you to eagerly load related data to avoid N+1 query problems.
|
|
367
|
+
*
|
|
368
|
+
* @param include An object specifying the related entities to include, their options, and filtering criteria.
|
|
369
|
+
*
|
|
370
|
+
* Example usage:
|
|
371
|
+
* ```
|
|
372
|
+
* const orders = await customerRepo.find({
|
|
373
|
+
* include: {
|
|
374
|
+
* // Include the 'tags' relation for each customer.
|
|
375
|
+
* tags: true,
|
|
376
|
+
* },
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
379
|
+
* In this example, the `tags` relation for each customer will be loaded and included in the query result.
|
|
380
|
+
*
|
|
381
|
+
* @see {@link Relations.toMany}
|
|
382
|
+
* @see {@link Relations.toOne}
|
|
383
|
+
* @see {@link RelationOptions}
|
|
384
|
+
*/
|
|
346
385
|
include?: MembersToInclude<entityType>;
|
|
347
386
|
}
|
|
348
387
|
export interface FindOptionsBase<entityType> extends LoadOptions<entityType> {
|
|
@@ -413,14 +452,34 @@ export interface RelationInfo {
|
|
|
413
452
|
toType: () => any;
|
|
414
453
|
type: 'reference' | 'toOne' | 'toMany';
|
|
415
454
|
}
|
|
455
|
+
/**
|
|
456
|
+
* Options for configuring a relation between entities.
|
|
457
|
+
*
|
|
458
|
+
* @template fromEntity The type of the source entity (the entity defining the relation).
|
|
459
|
+
* @template toEntity The type of the target entity (the related entity).
|
|
460
|
+
* @template matchIdEntity The type used for matching IDs in the relation.
|
|
461
|
+
* @template optionsType The type of find options to apply to the relation (default is FindOptionsBase<toEntity>).
|
|
462
|
+
*/
|
|
416
463
|
export type RelationOptions<fromEntity, toEntity, matchIdEntity, optionsType extends FindOptionsBase<toEntity> = FindOptionsBase<toEntity>> = {
|
|
417
464
|
fields?: {
|
|
418
465
|
[K in keyof toEntity]?: keyof fromEntity;
|
|
419
466
|
};
|
|
467
|
+
/**
|
|
468
|
+
* The name of the field for this relation.
|
|
469
|
+
*/
|
|
420
470
|
field?: keyof matchIdEntity;
|
|
421
|
-
|
|
422
|
-
|
|
471
|
+
/**
|
|
472
|
+
* Find options to apply to the relation when fetching related entities.
|
|
473
|
+
* You can specify a predefined set of find options or provide a function that takes the source entity
|
|
474
|
+
* and returns find options dynamically.
|
|
475
|
+
* These options allow you to customize how related entities are retrieved.
|
|
476
|
+
*/
|
|
423
477
|
findOptions?: optionsType | ((entity: fromEntity) => optionsType);
|
|
478
|
+
/**
|
|
479
|
+
* Determines whether the relation should be included by default when querying the source entity.
|
|
480
|
+
* When set to true, related entities will be automatically included when querying the source entity.
|
|
481
|
+
* If false or not specified, related entities will need to be explicitly included using the `include` option.
|
|
482
|
+
*/
|
|
424
483
|
defaultIncluded?: boolean;
|
|
425
484
|
} & Pick<FieldOptions, 'caption'>;
|
|
426
485
|
export type ObjectMembersOnly<T> = {
|
package/src/remult3/remult3.js
CHANGED
package/src/server-action.js
CHANGED
|
@@ -440,7 +440,7 @@ function BackendMethod(options) {
|
|
|
440
440
|
http])];
|
|
441
441
|
case 4:
|
|
442
442
|
r = _h.sent();
|
|
443
|
-
return [4 /*yield*/, defs._updateEntityBasedOnApi(r.rowInfo.data)];
|
|
443
|
+
return [4 /*yield*/, defs._updateEntityBasedOnApi(r.rowInfo.data, true)];
|
|
444
444
|
case 5:
|
|
445
445
|
_h.sent();
|
|
446
446
|
return [2 /*return*/, r.result];
|