remult 0.23.0-exp.2 → 0.23.0-exp.3

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 CHANGED
@@ -1,8 +1,9 @@
1
- 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, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, } from './src/remult3/remult3';
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, RelationOptionsBase, ObjectMembersOnly, MembersToInclude, RepositoryRelations, EntityIdFields, } from './src/remult3/remult3';
2
3
  export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
3
4
  export { Entity } from './src/remult3/entity';
4
5
  export { getEntityRef } from './src/remult3/getEntityRef';
5
- export { Field, Fields, StringFieldOptions } from './src/remult3/Fields';
6
+ export { Field, Fields, StringFieldOptions, Relations, } from './src/remult3/Fields';
6
7
  export { IdEntity } from './src/remult3/IdEntity';
7
8
  export { describeClass } from './src/remult3/DecoratorReplacer';
8
9
  export { EntityOptions } from './src/entity';
@@ -21,7 +22,6 @@ export { Controller, BackendMethodOptions, BackendMethod, ProgressListener, } fr
21
22
  export { Allowed, Allow, Remult, RemultContext, ApiClient, isBackend, AllowedForInstance, EventDispatcher, EventSource, UserInfo, } from './src/context';
22
23
  export { ExternalHttpProvider } from './src/buildRestDataProvider';
23
24
  export { SortSegment, Sort } from './src/sort';
24
- export { OneToMany } from './src/column';
25
25
  export { CompoundIdField } from './src/CompoundIdField';
26
26
  export { Filter } from './src/filter/filter-interfaces';
27
27
  export { UrlBuilder } from './urlBuilder';
@@ -30,3 +30,4 @@ export { ValueConverters } from './src/valueConverters';
30
30
  export { remult } from './src/remult-proxy';
31
31
  export { SubscriptionServer, LiveQueryStorage, StoredQuery, InMemoryLiveQueryStorage, } from './src/live-query/SubscriptionServer';
32
32
  export { SubscriptionListener, SubscriptionClientConnection, SubscriptionClient, SubscriptionChannel, LiveQueryChange, Unsubscribe, } from './src/live-query/SubscriptionChannel';
33
+ export declare function repo<entityType>(entity: ClassType<entityType>): import("./src/remult3/remult3").Repository<entityType>;
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
2
2
  export { Entity } from './src/remult3/entity';
3
3
  export { getEntityRef } from './src/remult3/getEntityRef';
4
- export { Field, Fields } from './src/remult3/Fields';
4
+ export { Field, Fields, Relations, } from './src/remult3/Fields';
5
5
  export { IdEntity } from './src/remult3/IdEntity';
6
6
  export { describeClass } from './src/remult3/DecoratorReplacer';
7
7
  export { RestDataProvider } from './src/data-providers/rest-data-provider'; //V
@@ -15,13 +15,16 @@ export { JsonDataProvider, } from './src/data-providers/json-data-provider'; //V
15
15
  export { Controller, BackendMethod, ProgressListener, } from './src/server-action';
16
16
  export { Allow, Remult, isBackend, EventSource, } from './src/context';
17
17
  export { Sort } from './src/sort';
18
- export { OneToMany } from './src/column';
19
18
  export { CompoundIdField } from './src/CompoundIdField';
20
19
  export { Filter } from './src/filter/filter-interfaces';
21
20
  export { UrlBuilder } from './urlBuilder';
22
21
  export { Validators } from './src/validators';
23
22
  export { ValueConverters } from './src/valueConverters';
24
23
  export { remult } from './src/remult-proxy';
24
+ import { remult } from './src/remult-proxy';
25
25
  //export { getId } from './src/remult3/getId';
26
26
  export { InMemoryLiveQueryStorage, } from './src/live-query/SubscriptionServer';
27
27
  export { SubscriptionChannel, } from './src/live-query/SubscriptionChannel';
28
+ export function repo(entity) {
29
+ return remult.repo(entity);
30
+ }
@@ -1,6 +1,6 @@
1
1
  import type { ClassType } from '../classType';
2
2
  import type { Allowed, AllowedForInstance } from './context';
3
- import type { EntityMetadata, FieldRef, OmitEB } from './remult3/remult3';
3
+ import type { EntityMetadata, FieldRef, LifeCycleEvent, OmitEB } from './remult3/remult3';
4
4
  export interface FieldOptions<entityType = any, valueType = any> {
5
5
  /** A human readable name for the field. Can be used to achieve a consistent caption for a field throughout the app
6
6
  * @example
@@ -37,7 +37,7 @@ export interface FieldOptions<entityType = any, valueType = any> {
37
37
  */
38
38
  validate?: ((entity: entityType, fieldRef: FieldRef<entityType, valueType>) => any | Promise<any>) | ((entity: entityType, fieldRef: FieldRef<entityType, valueType>) => any | Promise<any>)[];
39
39
  /** Will be fired before this field is saved to the server/database */
40
- saving?: (entity: entityType, fieldRef: FieldRef<entityType, valueType>) => any | Promise<any>;
40
+ saving?: (entity: entityType, e: LifeCycleEvent<entityType>, fieldRef: FieldRef<entityType, valueType>) => any | Promise<any>;
41
41
  /** An expression that will determine this fields value on the backend and be provided to the front end*/
42
42
  serverExpression?: (entity: entityType) => valueType | Promise<valueType>;
43
43
  /** The name of the column in the database that holds the data for this field. If no name is set, the key will be used instead.
@@ -1,9 +1,9 @@
1
- import type { FindOptions, idType, Repository } from './remult3/remult3';
1
+ import type { idType } from './remult3/remult3';
2
2
  import type { RepositoryImplementation } from './remult3/RepositoryImplementation';
3
3
  export declare function makeTitle(name: string): string;
4
4
  export declare class LookupColumn<T> {
5
5
  private repository;
6
- private isManyToOneRelation;
6
+ private isReferenceRelation;
7
7
  toJson(): any;
8
8
  setId(val: any): void;
9
9
  waitLoadOf(id: any): Promise<T>;
@@ -13,20 +13,7 @@ export declare class LookupColumn<T> {
13
13
  };
14
14
  set(item: T): void;
15
15
  id: idType<T>;
16
- constructor(repository: RepositoryImplementation<T>, isManyToOneRelation: any);
16
+ constructor(repository: RepositoryImplementation<T>, isReferenceRelation: any);
17
17
  get item(): T;
18
18
  waitLoad(): Promise<T>;
19
19
  }
20
- export declare class OneToMany<T> {
21
- private provider;
22
- private settings?;
23
- constructor(provider: Repository<T>, settings?: {
24
- create?: (newItem: T) => void;
25
- } & FindOptions<T>);
26
- private _items;
27
- private _currentPromise;
28
- get lazyItems(): T[];
29
- load(): Promise<T[]>;
30
- private find;
31
- create(item?: Partial<T>): T;
32
- }
package/esm/src/column.js CHANGED
@@ -1,5 +1,3 @@
1
- import { assign } from '../assign';
2
- import { __updateEntityBasedOnWhere } from './remult3/__updateEntityBasedOnWhere';
3
1
  import { getEntityRef } from './remult3/getEntityRef';
4
2
  export function makeTitle(name) {
5
3
  // insert a space before all caps
@@ -12,7 +10,7 @@ export function makeTitle(name) {
12
10
  }
13
11
  export class LookupColumn {
14
12
  repository;
15
- isManyToOneRelation;
13
+ isReferenceRelation;
16
14
  toJson() {
17
15
  if (!this.storedItem)
18
16
  return undefined;
@@ -33,7 +31,9 @@ export class LookupColumn {
33
31
  get(id) {
34
32
  if (id === undefined || id === null)
35
33
  return null;
36
- return this.repository.getCachedById(id, this.isManyToOneRelation);
34
+ if (this.isReferenceRelation && !this.storedItem)
35
+ return undefined;
36
+ return this.repository.getCachedById(id, this.isReferenceRelation);
37
37
  }
38
38
  storedItem;
39
39
  set(item) {
@@ -43,7 +43,7 @@ export class LookupColumn {
43
43
  this.id = item;
44
44
  else {
45
45
  let eo = getEntityRef(item, false);
46
- if (eo) {
46
+ if (eo && !this.isReferenceRelation) {
47
47
  this.repository.addToCache(item);
48
48
  this.id = eo.getId();
49
49
  }
@@ -61,9 +61,9 @@ export class LookupColumn {
61
61
  }
62
62
  }
63
63
  id;
64
- constructor(repository, isManyToOneRelation) {
64
+ constructor(repository, isReferenceRelation) {
65
65
  this.repository = repository;
66
- this.isManyToOneRelation = isManyToOneRelation;
66
+ this.isReferenceRelation = isReferenceRelation;
67
67
  }
68
68
  get item() {
69
69
  if (this.storedItem)
@@ -74,38 +74,3 @@ export class LookupColumn {
74
74
  return this.waitLoadOf(this.id);
75
75
  }
76
76
  }
77
- 9000;
78
- export class OneToMany {
79
- provider;
80
- settings;
81
- constructor(provider, settings) {
82
- this.provider = provider;
83
- this.settings = settings;
84
- }
85
- _items;
86
- _currentPromise;
87
- get lazyItems() {
88
- this.load();
89
- return this._items;
90
- }
91
- async load() {
92
- if (this._currentPromise != null)
93
- return this._currentPromise;
94
- if (this._items === undefined)
95
- this._items = [];
96
- return (this._currentPromise = this.find().then((x) => {
97
- this._items.splice(0);
98
- this._items.push(...x);
99
- return this._items;
100
- }));
101
- }
102
- async find() {
103
- return this.provider.find(this.settings);
104
- }
105
- create(item) {
106
- let r = this.provider.create();
107
- __updateEntityBasedOnWhere(this.provider.metadata, this.settings.where, r);
108
- assign(r, item);
109
- return r;
110
- }
111
- }
@@ -1,6 +1,6 @@
1
1
  import type { Allowed, AllowedForInstance } from './context';
2
2
  import type { FieldMetadata } from './column-interfaces';
3
- import type { EntityFilter, EntityMetadata, EntityOrderBy, EntityRef, FieldsMetadata } from './remult3/remult3';
3
+ import type { EntityFilter, EntityIdFields, EntityMetadata, EntityOrderBy, EntityRef, FieldsMetadata, LifeCycleEvent } from './remult3/remult3';
4
4
  export interface EntityOptions<entityType = any> {
5
5
  /**A human readable name for the entity */
6
6
  caption?: string;
@@ -60,13 +60,13 @@ export interface EntityOptions<entityType = any> {
60
60
  * }
61
61
  *})
62
62
  */
63
- saving?: (row: entityType, proceedWithoutSavingToDb: () => void) => Promise<any> | any;
63
+ saving?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
64
64
  /** will be called after the Entity was saved to the data source. */
65
- saved?: (row: entityType) => Promise<any> | any;
65
+ saved?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
66
66
  /** Will be called before an Entity is deleted. */
67
- deleting?: (row: entityType) => Promise<any> | any;
67
+ deleting?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
68
68
  /** Will be called after an Entity is deleted */
69
- deleted?: (row: entityType) => Promise<any> | any;
69
+ deleted?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
70
70
  /** Will be called when the entity is being validated, usually prior to the `saving` event */
71
71
  validation?: (row: entityType, ref: EntityRef<entityType>) => Promise<any> | any;
72
72
  /** The name of the table in the database that holds the data for this entity.
@@ -89,7 +89,7 @@ export interface EntityOptions<entityType = any> {
89
89
  * //Multiple columns id
90
90
  * @Entity<OrderDetails>("orderDetails", { id:od=> [od.orderId, od.productCode] })
91
91
  */
92
- id?: (entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[];
92
+ id?: EntityIdFields<entityType> | ((entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[]);
93
93
  entityRefInit?: (ref: EntityRef<entityType>, row: entityType) => void;
94
94
  apiRequireId?: Allowed;
95
95
  }
@@ -14,20 +14,6 @@ export declare class Filter {
14
14
  static entityFilterFromJson<T>(entityDefs: EntityMetadata<T>, packed: any): EntityFilter<T>;
15
15
  static translateCustomWhere<T>(r: Filter, entity: EntityMetadata<T>, remult: Remult): Promise<Filter>;
16
16
  }
17
- export declare class filterHelper {
18
- metadata: FieldMetadata;
19
- constructor(metadata: FieldMetadata);
20
- processVal(val: any): any;
21
- contains(val: string): Filter;
22
- isLessThan(val: any): Filter;
23
- isGreaterOrEqualTo(val: any): Filter;
24
- isNotIn(values: any[]): Filter;
25
- isDifferentFrom(val: any): Filter;
26
- isLessOrEqualTo(val: any): Filter;
27
- isGreaterThan(val: any): Filter;
28
- isEqualTo(val: any): Filter;
29
- isIn(val: any[]): Filter;
30
- }
31
17
  export interface FilterConsumer {
32
18
  or(orElements: Filter[]): any;
33
19
  isEqualTo(col: FieldMetadata, val: any): void;
@@ -1,4 +1,5 @@
1
1
  import { getEntityRef, getEntitySettings } from '../remult3/getEntityRef';
2
+ import { getRelationInfo } from '../remult3/relationInfoMember';
2
3
  export class Filter {
3
4
  apply;
4
5
  constructor(apply) {
@@ -49,7 +50,14 @@ export class Filter {
49
50
  result.push(new Filter((x) => x.databaseCustom(fieldToFilter)));
50
51
  }
51
52
  else {
52
- let fh = new filterHelper(entity.fields[key]);
53
+ const field = entity.fields[key];
54
+ const rel = getRelationInfo(field.options);
55
+ const op = field.options;
56
+ let fh = rel?.type === 'toOne'
57
+ ? op.fields
58
+ ? new manyToOneFilterHelper(field, entity.fields, op)
59
+ : new toOneFilterHelper(entity.fields[op.field])
60
+ : new filterHelper(field);
53
61
  let found = false;
54
62
  if (fieldToFilter !== undefined && fieldToFilter != null) {
55
63
  if (fieldToFilter.$id)
@@ -147,7 +155,7 @@ export class Filter {
147
155
  return r;
148
156
  }
149
157
  }
150
- export class filterHelper {
158
+ class filterHelper {
151
159
  metadata;
152
160
  constructor(metadata) {
153
161
  this.metadata = metadata;
@@ -206,6 +214,79 @@ export class filterHelper {
206
214
  return new Filter((add) => add.isIn(this.metadata, val));
207
215
  }
208
216
  }
217
+ class toOneFilterHelper extends filterHelper {
218
+ processVal(val) {
219
+ if (!val)
220
+ return null;
221
+ if (typeof val === 'string' || typeof val === 'number')
222
+ return val;
223
+ return getEntityRef(val).getId();
224
+ }
225
+ }
226
+ class manyToOneFilterHelper {
227
+ metadata;
228
+ fields;
229
+ relationOptions;
230
+ constructor(metadata, fields, relationOptions) {
231
+ this.metadata = metadata;
232
+ this.fields = fields;
233
+ this.relationOptions = relationOptions;
234
+ }
235
+ processVal(val) {
236
+ throw new Error('Invalid for Many To One Relation Field');
237
+ }
238
+ contains(val) {
239
+ throw new Error('Invalid for Many To One Relation Field');
240
+ }
241
+ isLessThan(val) {
242
+ throw new Error('Invalid for Many To One Relation Field');
243
+ }
244
+ isGreaterOrEqualTo(val) {
245
+ throw new Error('Invalid for Many To One Relation Field');
246
+ }
247
+ isNotIn(values) {
248
+ return new Filter((add) => {
249
+ values.forEach((v) => this.isDifferentFrom(v).__applyToConsumer(add));
250
+ });
251
+ }
252
+ isDifferentFrom(val) {
253
+ return new Filter((add) => {
254
+ const or = [];
255
+ for (const key in this.relationOptions.fields) {
256
+ if (Object.prototype.hasOwnProperty.call(this.relationOptions.fields, key)) {
257
+ const keyInMyEntity = this.relationOptions.fields[key];
258
+ or.push(new Filter((add) => new filterHelper(this.fields.find(keyInMyEntity))
259
+ .isDifferentFrom(val[key])
260
+ .__applyToConsumer(add)));
261
+ }
262
+ }
263
+ add.or(or);
264
+ });
265
+ }
266
+ isLessOrEqualTo(val) {
267
+ throw new Error('Invalid for Many To One Relation Field');
268
+ }
269
+ isGreaterThan(val) {
270
+ throw new Error('Invalid for Many To One Relation Field');
271
+ }
272
+ isEqualTo(val) {
273
+ return new Filter((add) => {
274
+ for (const key in this.relationOptions.fields) {
275
+ if (Object.prototype.hasOwnProperty.call(this.relationOptions.fields, key)) {
276
+ const keyInMyEntity = this.relationOptions.fields[key];
277
+ new filterHelper(this.fields.find(keyInMyEntity))
278
+ .isEqualTo(val[key])
279
+ .__applyToConsumer(add);
280
+ }
281
+ }
282
+ });
283
+ }
284
+ isIn(val) {
285
+ return new Filter((add) => {
286
+ add.or(val.map((v) => this.isEqualTo(v)));
287
+ });
288
+ }
289
+ }
209
290
  export class AndFilter extends Filter {
210
291
  filters;
211
292
  constructor(...filters) {
@@ -350,7 +431,6 @@ export function buildFilterFromRequestParameters(entity, filterInfo) {
350
431
  }
351
432
  }
352
433
  }
353
- let c = new filterHelper(col);
354
434
  addFilter('', (val) => val);
355
435
  addFilter('.gt', (val) => ({ $gt: val }));
356
436
  addFilter('.gte', (val) => ({ $gte: val }));
@@ -81,6 +81,10 @@ export class RemultProxy {
81
81
  get fields() {
82
82
  return self.remultFactory().repo(...args).metadata.fields;
83
83
  },
84
+ relations: (args2) => self
85
+ .remultFactory()
86
+ .repo(...args)
87
+ .relations(args2),
84
88
  validate: (a, b) => self
85
89
  .remultFactory()
86
90
  .repo(...args)
@@ -135,7 +139,9 @@ export class RemultProxy {
135
139
  .repo(...args)
136
140
  .liveQuery(...args2),
137
141
  //@ts-ignore
138
- addToCache: (a) => self.remultFactory().repo(...args).addToCache(a),
142
+ addToCache: (a) => self
143
+ .remultFactory()
144
+ .repo(...args).addToCache(a),
139
145
  get metadata() {
140
146
  return self.remultFactory().repo(...args).metadata;
141
147
  },
@@ -1,7 +1,7 @@
1
1
  import type { ClassType } from '../../classType';
2
2
  import type { FieldOptions } from '../column-interfaces';
3
3
  import type { Remult } from '../context';
4
- import type { FindOptions, RelationOptions, RelationOptionsBase } from './remult3';
4
+ import type { FindOptions, RelationOptions } from './remult3';
5
5
  import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
6
6
  export declare class Fields {
7
7
  /**
@@ -20,11 +20,12 @@ export declare class Fields {
20
20
  static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
21
21
  static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
22
22
  static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, boolean | undefined>, c?: any) => void;
23
- static reference<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: RelationOptionsBase<entityType, toEntityType>): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, toEntityType>, c?: any) => void;
24
- static many<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
23
+ }
24
+ export declare class Relations {
25
+ static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, toEntityType>, c?: any) => void;
26
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
25
27
  fromEntityType?: ClassType<entityType>;
26
28
  }) | keyof toEntityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
27
- static one<entityType, toEntityType>(entity: ClassType<entityType>, toEntityType: () => ClassType<toEntityType>, options?: RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
28
29
  }
29
30
  /**Decorates fields that should be used as fields.
30
31
  * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
@@ -1,7 +1,6 @@
1
1
  import { createId } from '@paralleldrive/cuid2';
2
2
  import { v4 as uuid } from 'uuid';
3
3
  import { ValueConverters } from '../valueConverters';
4
- import { getEntityRef } from './getEntityRef';
5
4
  import { buildOptions, columnsOfType, } from './RepositoryImplementation';
6
5
  import { relationInfoMember } from './relationInfoMember';
7
6
  export class Fields {
@@ -47,8 +46,8 @@ export class Fields {
47
46
  static createdAt(...options) {
48
47
  return Field(() => Date, {
49
48
  allowApiUpdate: false,
50
- saving: (_, ref) => {
51
- if (getEntityRef(_).isNew())
49
+ saving: (_, { isNew }, ref) => {
50
+ if (isNew)
52
51
  ref.value = new Date();
53
52
  },
54
53
  }, ...options);
@@ -56,7 +55,7 @@ export class Fields {
56
55
  static updatedAt(...options) {
57
56
  return Field(() => Date, {
58
57
  allowApiUpdate: false,
59
- saving: (_, ref) => {
58
+ saving: (_, _1, ref) => {
60
59
  ref.value = new Date();
61
60
  },
62
61
  }, ...options);
@@ -65,7 +64,7 @@ export class Fields {
65
64
  return Field(() => String, {
66
65
  allowApiUpdate: false,
67
66
  defaultValue: () => uuid(),
68
- saving: (_, r) => {
67
+ saving: (_, _1, r) => {
69
68
  if (!r.value)
70
69
  r.value = uuid();
71
70
  },
@@ -75,7 +74,7 @@ export class Fields {
75
74
  return Field(() => String, {
76
75
  allowApiUpdate: false,
77
76
  defaultValue: () => createId(),
78
- saving: (_, r) => {
77
+ saving: (_, _1, r) => {
79
78
  if (!r.value)
80
79
  r.value = createId();
81
80
  },
@@ -87,25 +86,24 @@ export class Fields {
87
86
  static boolean(...options) {
88
87
  return Field(() => Boolean, ...options);
89
88
  }
90
- //[ ] docking the move from reference to one will not be fun,since the parameter order changes
91
- static reference(toEntityType, options) {
92
- let op = (!options
93
- ? {}
94
- : options);
95
- return Field(toEntityType, {
96
- ...op,
97
- //@ts-ignore
98
- [relationInfoMember]: {
99
- //field,
100
- toType: toEntityType,
101
- type: 'reference',
102
- },
103
- });
104
- }
105
- static many(toEntityType, options) {
89
+ }
90
+ export class Relations {
91
+ static toOne(toEntityType, options) {
106
92
  let op = (typeof options === 'string'
107
93
  ? { field: options }
108
- : options);
94
+ : !options
95
+ ? {}
96
+ : options);
97
+ if (!op.field && !op.fields && !op.findOptions)
98
+ return Field(toEntityType, {
99
+ ...op,
100
+ //@ts-ignore
101
+ [relationInfoMember]: {
102
+ //field,
103
+ toType: toEntityType,
104
+ type: 'reference',
105
+ },
106
+ });
109
107
  return Field(() => undefined, {
110
108
  ...op,
111
109
  serverExpression: () => undefined,
@@ -113,16 +111,14 @@ export class Fields {
113
111
  [relationInfoMember]: {
114
112
  //field,
115
113
  toType: toEntityType,
116
- type: 'toMany',
114
+ type: 'toOne',
117
115
  },
118
116
  });
119
117
  }
120
- static one(entity, toEntityType, options) {
118
+ static toMany(toEntityType, options) {
121
119
  let op = (typeof options === 'string'
122
120
  ? { field: options }
123
- : !options
124
- ? {}
125
- : options);
121
+ : options);
126
122
  return Field(() => undefined, {
127
123
  ...op,
128
124
  serverExpression: () => undefined,
@@ -130,7 +126,7 @@ export class Fields {
130
126
  [relationInfoMember]: {
131
127
  //field,
132
128
  toType: toEntityType,
133
- type: 'toOne',
129
+ type: 'toMany',
134
130
  },
135
131
  });
136
132
  }
@@ -197,3 +193,4 @@ export function checkTarget(target) {
197
193
  if (!target)
198
194
  throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
199
195
  }
196
+ //[ ] there is a duplicity between the oneToMany and manyToOne - maybe we should allow some derivation from one to another?
@@ -111,6 +111,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
111
111
  private edp;
112
112
  private _isNew;
113
113
  constructor(info: EntityFullInfo<T>, instance: T, repository: RepositoryImplementation<T>, edp: EntityDataProvider, remult: Remult, _isNew: boolean);
114
+ get relations(): RepositoryRelations<T>;
114
115
  get apiUpdateAllowed(): boolean;
115
116
  get apiDeleteAllowed(): boolean;
116
117
  get apiInsertAllowed(): boolean;
@@ -125,6 +126,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
125
126
  get fields(): FieldsRef<T>;
126
127
  private _saving;
127
128
  save(onlyTheseFieldsSentOnlyInTheCaseOfProxySaveWithPartialObject?: string[]): Promise<T>;
129
+ private buildLifeCycleEvent;
128
130
  private getIdFilter;
129
131
  delete(): Promise<void>;
130
132
  loadDataFrom(data: any, loadItems?: FieldMetadata[]): Promise<void>;