remult 0.23.0-exp.2 → 0.23.0-exp.21

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.
Files changed (92) hide show
  1. package/README.md +26 -27
  2. package/esm/graphql.js +7 -1
  3. package/esm/index.d.ts +16 -3
  4. package/esm/index.js +17 -2
  5. package/esm/internals.d.ts +2 -1
  6. package/esm/internals.js +1 -1
  7. package/esm/remult-express.js +1 -1
  8. package/esm/remult-knex/index.js +2 -1
  9. package/esm/remult-mongo.js +2 -1
  10. package/esm/server/JsonEntityFileStorage.js +1 -1
  11. package/esm/server/expressBridge.js +1 -1
  12. package/esm/src/CompoundIdField.d.ts +1 -1
  13. package/esm/src/CompoundIdField.js +3 -1
  14. package/esm/src/buildRestDataProvider.d.ts +1 -2
  15. package/esm/src/column-interfaces.d.ts +19 -7
  16. package/esm/src/column.d.ts +4 -18
  17. package/esm/src/column.js +10 -44
  18. package/esm/src/context.d.ts +1 -1
  19. package/esm/src/context.js +5 -1
  20. package/esm/src/data-interfaces.js +1 -2
  21. package/esm/src/data-providers/array-entity-data-provider.d.ts +1 -1
  22. package/esm/src/data-providers/array-entity-data-provider.js +6 -6
  23. package/esm/src/data-providers/sql-database.js +2 -1
  24. package/esm/src/data-providers/web-sql-data-provider.js +3 -3
  25. package/esm/src/entity.d.ts +48 -17
  26. package/esm/src/filter/filter-interfaces.d.ts +2 -16
  27. package/esm/src/filter/filter-interfaces.js +87 -6
  28. package/esm/src/live-query/LiveQueryClient.js +2 -1
  29. package/esm/src/live-query/SubscriptionChannel.js +4 -3
  30. package/esm/src/remult-proxy.js +10 -2
  31. package/esm/src/remult3/Fields.d.ts +140 -21
  32. package/esm/src/remult3/Fields.js +26 -30
  33. package/esm/src/remult3/RepositoryImplementation.d.ts +10 -16
  34. package/esm/src/remult3/RepositoryImplementation.js +165 -48
  35. package/esm/src/remult3/entity.d.ts +1 -1
  36. package/esm/src/remult3/entity.js +0 -1
  37. package/esm/src/remult3/getEntityRef.d.ts +1 -1
  38. package/esm/src/remult3/getEntityRef.js +1 -1
  39. package/esm/src/remult3/relation-loader.js +4 -1
  40. package/esm/src/remult3/remult3.d.ts +132 -7
  41. package/esm/src/remult3/remult3.js +30 -0
  42. package/esm/src/remult3/repository-internals.d.ts +14 -0
  43. package/esm/src/remult3/repository-internals.js +7 -0
  44. package/esm/src/server-action.js +1 -1
  45. package/esm/src/sort.d.ts +3 -3
  46. package/esm/src/sort.js +36 -8
  47. package/graphql.js +10 -2
  48. package/index.d.ts +16 -3
  49. package/index.js +19 -3
  50. package/internals.d.ts +2 -1
  51. package/internals.js +3 -1
  52. package/package.json +1 -1
  53. package/remult-express.js +1 -1
  54. package/remult-knex/index.js +2 -1
  55. package/remult-mongo.js +2 -1
  56. package/server/JsonEntityFileStorage.js +1 -1
  57. package/server/expressBridge.js +1 -1
  58. package/src/CompoundIdField.d.ts +1 -1
  59. package/src/CompoundIdField.js +3 -0
  60. package/src/buildRestDataProvider.d.ts +1 -2
  61. package/src/column-interfaces.d.ts +19 -7
  62. package/src/column.d.ts +4 -18
  63. package/src/column.js +10 -56
  64. package/src/context.d.ts +1 -1
  65. package/src/context.js +5 -1
  66. package/src/data-interfaces.js +1 -2
  67. package/src/data-providers/array-entity-data-provider.d.ts +1 -1
  68. package/src/data-providers/array-entity-data-provider.js +5 -6
  69. package/src/data-providers/sql-database.js +2 -1
  70. package/src/data-providers/web-sql-data-provider.js +3 -3
  71. package/src/entity.d.ts +48 -17
  72. package/src/filter/filter-interfaces.d.ts +2 -16
  73. package/src/filter/filter-interfaces.js +101 -9
  74. package/src/live-query/LiveQueryClient.js +2 -1
  75. package/src/live-query/SubscriptionChannel.js +4 -3
  76. package/src/remult-proxy.js +43 -29
  77. package/src/remult3/Fields.d.ts +140 -21
  78. package/src/remult3/Fields.js +32 -32
  79. package/src/remult3/RepositoryImplementation.d.ts +10 -16
  80. package/src/remult3/RepositoryImplementation.js +286 -163
  81. package/src/remult3/entity.d.ts +1 -1
  82. package/src/remult3/entity.js +0 -1
  83. package/src/remult3/getEntityRef.d.ts +1 -1
  84. package/src/remult3/getEntityRef.js +2 -1
  85. package/src/remult3/relation-loader.js +4 -1
  86. package/src/remult3/remult3.d.ts +132 -7
  87. package/src/remult3/remult3.js +30 -0
  88. package/src/remult3/repository-internals.d.ts +14 -0
  89. package/src/remult3/repository-internals.js +11 -0
  90. package/src/server-action.js +1 -1
  91. package/src/sort.d.ts +3 -3
  92. package/src/sort.js +43 -11
@@ -116,7 +116,7 @@ class WebSqlBridgeToSQLCommand {
116
116
  });
117
117
  t.executeSql(s, v, (t1, r) => resolve(new WebSqlBridgeToSQLQueryResult(r)), (t2, err) => {
118
118
  reject(err.message);
119
- return undefined;
119
+ return false;
120
120
  });
121
121
  }));
122
122
  }
@@ -125,13 +125,13 @@ class WebSqlBridgeToSQLQueryResult {
125
125
  r;
126
126
  getColumnKeyInResultForIndexInSelect(index) {
127
127
  if (this.rows.length == 0)
128
- return undefined;
128
+ throw Error('No rows');
129
129
  let i = 0;
130
130
  for (let m in this.rows[0]) {
131
131
  if (i++ == index)
132
132
  return m;
133
133
  }
134
- return undefined;
134
+ throw Error('index not found');
135
135
  }
136
136
  //@ts-ignore
137
137
  constructor(r) {
@@ -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;
@@ -55,20 +55,51 @@ export interface EntityOptions<entityType = any> {
55
55
  * this is the place to run logic that we want to run in any case before an entity is saved.
56
56
  * @example
57
57
  * @Entity<Task>("tasks", {
58
- * saving: async task => {
59
- * task.lastUpdated = new Date()
60
- * }
61
- *})
58
+ * saving: async (task, e) => {
59
+ * if (e.isNew) {
60
+ * task.createdAt = new Date(); // Set the creation date for new tasks.
61
+ * }
62
+ * task.lastUpdated = new Date(); // Update the last updated date.
63
+ * },
64
+ * })
65
+ * @param entity - The instance of the entity being saved.
66
+ * @param event - an @link LifeCycleEvent object
67
+ * @see [Entity Lifecycle Hooks](http://remult.dev/docs/lifecycle-hooks)
62
68
  */
63
- saving?: (row: entityType, proceedWithoutSavingToDb: () => void) => Promise<any> | any;
64
- /** will be called after the Entity was saved to the data source. */
65
- saved?: (row: entityType) => Promise<any> | any;
66
- /** Will be called before an Entity is deleted. */
67
- deleting?: (row: entityType) => Promise<any> | any;
68
- /** Will be called after an Entity is deleted */
69
- deleted?: (row: entityType) => Promise<any> | any;
70
- /** Will be called when the entity is being validated, usually prior to the `saving` event */
71
- validation?: (row: entityType, ref: EntityRef<entityType>) => Promise<any> | any;
69
+ saving?: (entity: entityType, event: LifecycleEvent<entityType>) => Promise<any> | any;
70
+ /**
71
+ * A hook that runs after an entity has been successfully saved.
72
+ *
73
+ * @param entity The instance of the entity that was saved.
74
+ * @param event - an @link LifeCycleEvent object
75
+ * @see [Entity Lifecycle Hooks](http://remult.dev/docs/lifecycle-hooks)
76
+ */
77
+ saved?: (entity: entityType, e: LifecycleEvent<entityType>) => Promise<any> | any;
78
+ /**
79
+ * A hook that runs before an entity is deleted.
80
+ *
81
+ * @param entity The instance of the entity being deleted.
82
+ * @param event - an @link LifeCycleEvent object
83
+ * @see [Entity Lifecycle Hooks](http://remult.dev/docs/lifecycle-hooks)
84
+ */
85
+ deleting?: (entity: entityType, e: LifecycleEvent<entityType>) => Promise<any> | any;
86
+ /**
87
+ * A hook that runs after an entity has been successfully deleted.
88
+ *
89
+ * @param entity The instance of the entity that was deleted.
90
+ * @param event - an @link LifeCycleEvent object
91
+ * @see [Entity Lifecycle Hooks](http://remult.dev/docs/lifecycle-hooks)
92
+ */
93
+ deleted?: (entity: entityType, e: LifecycleEvent<entityType>) => Promise<any> | any;
94
+ /**
95
+ * A hook that runs to perform validation checks on an entity before saving.
96
+ * This hook is also executed on the frontend.
97
+ *
98
+ * @param entity The instance of the entity being validated.
99
+ * @param event - an @link LifeCycleEvent object
100
+ * @see [Entity Lifecycle Hooks](http://remult.dev/docs/lifecycle-hooks)
101
+ */
102
+ validation?: (entity: entityType, ref: LifecycleEvent<entityType>) => Promise<any> | any;
72
103
  /** The name of the table in the database that holds the data for this entity.
73
104
  * If no name is set, the `key` will be used instead.
74
105
  * @example
@@ -84,12 +115,12 @@ export interface EntityOptions<entityType = any> {
84
115
  /** An arrow function that identifies the `id` column to use for this entity
85
116
  * @example
86
117
  * //Single column id
87
- * @Entity<Products>("products", { id:p=>p.productCode })
118
+ * @Entity<Products>("products", { id: {productCode: true} })
88
119
  * @example
89
120
  * //Multiple columns id
90
- * @Entity<OrderDetails>("orderDetails", { id:od=> [od.orderId, od.productCode] })
121
+ * @Entity<OrderDetails>("orderDetails", { id:{ orderId:true, productCode:true} })
91
122
  */
92
- id?: (entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[];
123
+ id?: EntityIdFields<entityType> | ((entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[]);
93
124
  entityRefInit?: (ref: EntityRef<entityType>, row: entityType) => void;
94
125
  apiRequireId?: Allowed;
95
126
  }
@@ -2,8 +2,8 @@ import type { FieldMetadata } from '../column-interfaces';
2
2
  import type { Remult } from '../context';
3
3
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
4
4
  export declare class Filter {
5
- private apply?;
6
- constructor(apply?: (add: FilterConsumer) => void);
5
+ private apply;
6
+ constructor(apply: (add: FilterConsumer) => void);
7
7
  __applyToConsumer(add: FilterConsumer): void;
8
8
  static resolve<entityType>(filter: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)): Promise<EntityFilter<entityType>>;
9
9
  static createCustom<entityType>(rawFilterTranslator: (unused: never, r: Remult) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>, key?: string): (() => EntityFilter<entityType>) & customFilterInfo<entityType>;
@@ -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,11 +1,9 @@
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) {
5
6
  this.apply = apply;
6
- if (!this.apply) {
7
- this.apply = () => { };
8
- }
9
7
  }
10
8
  __applyToConsumer(add) {
11
9
  this.apply(add);
@@ -49,7 +47,14 @@ export class Filter {
49
47
  result.push(new Filter((x) => x.databaseCustom(fieldToFilter)));
50
48
  }
51
49
  else {
52
- let fh = new filterHelper(entity.fields[key]);
50
+ const field = entity.fields[key];
51
+ const rel = getRelationInfo(field.options);
52
+ const op = field.options;
53
+ let fh = rel?.type === 'toOne'
54
+ ? op.fields
55
+ ? new manyToOneFilterHelper(field, entity.fields, op)
56
+ : new toOneFilterHelper(entity.fields[op.field])
57
+ : new filterHelper(field);
53
58
  let found = false;
54
59
  if (fieldToFilter !== undefined && fieldToFilter != null) {
55
60
  if (fieldToFilter.$id)
@@ -147,7 +152,7 @@ export class Filter {
147
152
  return r;
148
153
  }
149
154
  }
150
- export class filterHelper {
155
+ class filterHelper {
151
156
  metadata;
152
157
  constructor(metadata) {
153
158
  this.metadata = metadata;
@@ -203,9 +208,84 @@ export class filterHelper {
203
208
  }
204
209
  isIn(val) {
205
210
  val = val.map((x) => this.processVal(x));
211
+ if (val?.length == 1 && val[0] != undefined && val[0] !== null)
212
+ return new Filter((add) => add.isEqualTo(this.metadata, val[0]));
206
213
  return new Filter((add) => add.isIn(this.metadata, val));
207
214
  }
208
215
  }
216
+ class toOneFilterHelper extends filterHelper {
217
+ processVal(val) {
218
+ if (!val)
219
+ return null;
220
+ if (typeof val === 'string' || typeof val === 'number')
221
+ return val;
222
+ return getEntityRef(val).getId();
223
+ }
224
+ }
225
+ class manyToOneFilterHelper {
226
+ metadata;
227
+ fields;
228
+ relationOptions;
229
+ constructor(metadata, fields, relationOptions) {
230
+ this.metadata = metadata;
231
+ this.fields = fields;
232
+ this.relationOptions = relationOptions;
233
+ }
234
+ processVal(val) {
235
+ throw new Error('Invalid for Many To One Relation Field');
236
+ }
237
+ contains(val) {
238
+ throw new Error('Invalid for Many To One Relation Field');
239
+ }
240
+ isLessThan(val) {
241
+ throw new Error('Invalid for Many To One Relation Field');
242
+ }
243
+ isGreaterOrEqualTo(val) {
244
+ throw new Error('Invalid for Many To One Relation Field');
245
+ }
246
+ isNotIn(values) {
247
+ return new Filter((add) => {
248
+ values.forEach((v) => this.isDifferentFrom(v).__applyToConsumer(add));
249
+ });
250
+ }
251
+ isDifferentFrom(val) {
252
+ return new Filter((add) => {
253
+ const or = [];
254
+ for (const key in this.relationOptions.fields) {
255
+ if (Object.prototype.hasOwnProperty.call(this.relationOptions.fields, key)) {
256
+ const keyInMyEntity = this.relationOptions.fields[key];
257
+ or.push(new Filter((add) => new filterHelper(this.fields.find(keyInMyEntity))
258
+ .isDifferentFrom(val[key])
259
+ .__applyToConsumer(add)));
260
+ }
261
+ }
262
+ add.or(or);
263
+ });
264
+ }
265
+ isLessOrEqualTo(val) {
266
+ throw new Error('Invalid for Many To One Relation Field');
267
+ }
268
+ isGreaterThan(val) {
269
+ throw new Error('Invalid for Many To One Relation Field');
270
+ }
271
+ isEqualTo(val) {
272
+ return new Filter((add) => {
273
+ for (const key in this.relationOptions.fields) {
274
+ if (Object.prototype.hasOwnProperty.call(this.relationOptions.fields, key)) {
275
+ const keyInMyEntity = this.relationOptions.fields[key];
276
+ new filterHelper(this.fields.find(keyInMyEntity))
277
+ .isEqualTo(val[key])
278
+ .__applyToConsumer(add);
279
+ }
280
+ }
281
+ });
282
+ }
283
+ isIn(val) {
284
+ return new Filter((add) => {
285
+ add.or(val.map((v) => this.isEqualTo(v)));
286
+ });
287
+ }
288
+ }
209
289
  export class AndFilter extends Filter {
210
290
  filters;
211
291
  constructor(...filters) {
@@ -350,7 +430,6 @@ export function buildFilterFromRequestParameters(entity, filterInfo) {
350
430
  }
351
431
  }
352
432
  }
353
- let c = new filterHelper(col);
354
433
  addFilter('', (val) => val);
355
434
  addFilter('.gt', (val) => ({ $gt: val }));
356
435
  addFilter('.gte', (val) => ({ $gte: val }));
@@ -523,3 +602,5 @@ export function __updateEntityBasedOnWhere(entityDefs, where, r) {
523
602
  });
524
603
  }
525
604
  }
605
+ // toRaw of default remult threw and exception
606
+ // toRaw didn't respect
@@ -1,5 +1,6 @@
1
1
  import { buildRestDataProvider } from '../buildRestDataProvider';
2
2
  import { RestDataProvider } from '../data-providers/rest-data-provider';
3
+ import { getRepositoryInternals } from '../remult3/repository-internals';
3
4
  import { liveQueryKeepAliveRoute, LiveQuerySubscriber, } from './SubscriptionChannel';
4
5
  /* @internal*/
5
6
  export class LiveQueryClient {
@@ -79,7 +80,7 @@ export class LiveQueryClient {
79
80
  let onUnsubscribe = () => {
80
81
  alive = false;
81
82
  };
82
- this.runPromise(repo
83
+ this.runPromise(getRepositoryInternals(repo)
83
84
  .buildEntityDataProviderFindOptions(options)
84
85
  .then((opts) => {
85
86
  if (!alive)
@@ -1,6 +1,7 @@
1
1
  import { v4 as uuid } from 'uuid';
2
2
  import { Sort } from '../sort';
3
3
  import { remult as defaultRemult } from '../remult-proxy';
4
+ import { getRepositoryInternals } from '../remult3/repository-internals';
4
5
  export const streamUrl = 'stream';
5
6
  //@internal
6
7
  export class LiveQuerySubscriber {
@@ -13,9 +14,9 @@ export class LiveQuerySubscriber {
13
14
  subscribeCode;
14
15
  unsubscribe = () => { };
15
16
  async setAllItems(result) {
16
- const items = await this.repo.fromJsonArray(result, this.query.options);
17
+ const items = await getRepositoryInternals(this.repo).fromJsonArray(result, this.query.options);
17
18
  this.forListeners((listener) => {
18
- listener((x) => {
19
+ listener(() => {
19
20
  return items;
20
21
  });
21
22
  }, this.allItemsMessage(items));
@@ -54,7 +55,7 @@ export class LiveQuerySubscriber {
54
55
  async handle(messages) {
55
56
  {
56
57
  let x = messages.filter(({ type }) => type == 'add' || type == 'replace');
57
- let loadedItems = await this.repo.fromJsonArray(x.map((m) => m.data.item), this.query.options);
58
+ let loadedItems = await getRepositoryInternals(this.repo).fromJsonArray(x.map((m) => m.data.item), this.query.options);
58
59
  for (let index = 0; index < x.length; index++) {
59
60
  const element = x[index];
60
61
  element.data.item = loadedItems[index];
@@ -1,3 +1,4 @@
1
+ import { getInternalKey } from './remult3/repository-internals';
1
2
  let defaultRemult;
2
3
  function defaultFactory() {
3
4
  if (!defaultRemult) {
@@ -81,6 +82,15 @@ export class RemultProxy {
81
82
  get fields() {
82
83
  return self.remultFactory().repo(...args).metadata.fields;
83
84
  },
85
+ [getInternalKey]() {
86
+ return self
87
+ .remultFactory()
88
+ .repo(...args)[getInternalKey]();
89
+ },
90
+ relations: (args2) => self
91
+ .remultFactory()
92
+ .repo(...args)
93
+ .relations(args2),
84
94
  validate: (a, b) => self
85
95
  .remultFactory()
86
96
  .repo(...args)
@@ -134,8 +144,6 @@ export class RemultProxy {
134
144
  .remultFactory()
135
145
  .repo(...args)
136
146
  .liveQuery(...args2),
137
- //@ts-ignore
138
- addToCache: (a) => self.remultFactory().repo(...args).addToCache(a),
139
147
  get metadata() {
140
148
  return self.remultFactory().repo(...args).metadata;
141
149
  },
@@ -1,30 +1,149 @@
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';
5
- import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
4
+ import type { FindOptions, RelationOptions, ClassFieldDecorator, ClassFieldDecoratorContextStub } from './remult3';
6
5
  export declare class Fields {
7
6
  /**
8
7
  * Stored as a JSON.stringify - to store as json use Fields.json
9
8
  */
10
- static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
11
- static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
12
- static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
13
- static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
14
- static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
15
- static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
16
- static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
17
- static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
18
- static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
19
- static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
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
- 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
- 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>> & {
25
- fromEntityType?: ClassType<entityType>;
26
- }) | 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;
9
+ static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
10
+ static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
11
+ static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
12
+ static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
13
+ static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
14
+ static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
15
+ static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
16
+ static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
17
+ static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
+ static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
19
+ static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
20
+ static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
21
+ static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
22
+ }
23
+ export declare class Relations {
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
+ */
39
+ static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
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
+ */
56
+ static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
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
+ */
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>;
98
+ /** A to one relation with fields defined in the field/fields parameter */
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
+ */
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
+ */
146
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
28
147
  }
29
148
  /**Decorates fields that should be used as fields.
30
149
  * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
@@ -39,7 +158,7 @@ export declare class Fields {
39
158
  * @Fields.string((options,remult) => options.includeInApi = true)
40
159
  * title='';
41
160
  */
42
- export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType>, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
161
+ export declare function Field<entityType = any, valueType = any>(valueType: (() => ClassType<valueType>) | undefined, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
43
162
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
44
163
  maxLength?: number;
45
164
  }