remult 0.23.0-exp.8 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +1 -0
  2. package/esm/graphql.js +19 -2
  3. package/esm/index.d.ts +18 -4
  4. package/esm/index.js +13 -1
  5. package/esm/internals.d.ts +1 -1
  6. package/esm/internals.js +1 -1
  7. package/esm/postgres/schema-builder.d.ts +1 -0
  8. package/esm/postgres/schema-builder.js +13 -1
  9. package/esm/remult-express.js +1 -1
  10. package/esm/remult-hapi.d.ts +6 -0
  11. package/esm/remult-hapi.js +112 -0
  12. package/esm/remult-knex/index.js +4 -2
  13. package/esm/remult-mongo.d.ts +1 -1
  14. package/esm/remult-mongo.js +17 -5
  15. package/esm/remult-sveltekit.d.ts +3 -1
  16. package/esm/remult-sveltekit.js +3 -0
  17. package/esm/server/expressBridge.d.ts +8 -0
  18. package/esm/server/expressBridge.js +12 -7
  19. package/esm/src/CompoundIdField.d.ts +1 -1
  20. package/esm/src/CompoundIdField.js +3 -1
  21. package/esm/src/column-interfaces.d.ts +21 -9
  22. package/esm/src/column.d.ts +3 -3
  23. package/esm/src/column.js +19 -5
  24. package/esm/src/context.js +2 -0
  25. package/esm/src/data-api.js +4 -1
  26. package/esm/src/data-interfaces.d.ts +2 -2
  27. package/esm/src/data-providers/array-entity-data-provider.d.ts +0 -21
  28. package/esm/src/data-providers/array-entity-data-provider.js +8 -0
  29. package/esm/src/data-providers/sql-database.js +2 -1
  30. package/esm/src/entity.d.ts +47 -16
  31. package/esm/src/entity.js +0 -1
  32. package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +2 -2
  33. package/esm/src/filter/filter-interfaces.js +4 -0
  34. package/esm/src/live-query/LiveQueryClient.js +2 -1
  35. package/esm/src/live-query/SubscriptionChannel.js +3 -2
  36. package/esm/src/remult-proxy.js +9 -6
  37. package/esm/src/remult3/DecoratorReplacer.d.ts +1 -2
  38. package/esm/src/remult3/Fields.d.ts +105 -19
  39. package/esm/src/remult3/Fields.js +48 -8
  40. package/esm/src/remult3/RepositoryImplementation.d.ts +21 -29
  41. package/esm/src/remult3/RepositoryImplementation.js +125 -54
  42. package/esm/src/remult3/entity.d.ts +1 -1
  43. package/esm/src/remult3/entity.js +0 -1
  44. package/esm/src/remult3/remult3.d.ts +195 -33
  45. package/esm/src/remult3/remult3.js +63 -0
  46. package/esm/src/remult3/repository-internals.d.ts +14 -0
  47. package/esm/src/remult3/repository-internals.js +7 -0
  48. package/esm/src/server-action.js +1 -1
  49. package/esm/src/sort.js +13 -3
  50. package/graphql.js +19 -3
  51. package/index.d.ts +18 -4
  52. package/index.js +12 -0
  53. package/internals.d.ts +1 -1
  54. package/internals.js +3 -1
  55. package/package.json +9 -1
  56. package/postgres/schema-builder.d.ts +1 -0
  57. package/postgres/schema-builder.js +12 -2
  58. package/remult-express.js +1 -1
  59. package/remult-hapi.d.ts +6 -0
  60. package/remult-hapi.js +124 -0
  61. package/remult-knex/index.js +13 -7
  62. package/remult-mongo.d.ts +1 -1
  63. package/remult-mongo.js +17 -5
  64. package/remult-sveltekit.d.ts +3 -1
  65. package/remult-sveltekit.js +3 -0
  66. package/server/expressBridge.d.ts +8 -0
  67. package/server/expressBridge.js +13 -7
  68. package/src/CompoundIdField.d.ts +1 -1
  69. package/src/CompoundIdField.js +3 -0
  70. package/src/column-interfaces.d.ts +21 -9
  71. package/src/column.d.ts +3 -3
  72. package/src/column.js +18 -5
  73. package/src/context.js +2 -0
  74. package/src/data-api.js +4 -1
  75. package/src/data-interfaces.d.ts +2 -2
  76. package/src/data-providers/array-entity-data-provider.d.ts +0 -21
  77. package/src/data-providers/array-entity-data-provider.js +6 -0
  78. package/src/data-providers/sql-database.js +2 -1
  79. package/src/entity.d.ts +47 -16
  80. package/src/entity.js +0 -1
  81. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +2 -2
  82. package/src/filter/filter-interfaces.js +4 -0
  83. package/src/live-query/LiveQueryClient.js +2 -1
  84. package/src/live-query/SubscriptionChannel.js +3 -2
  85. package/src/remult-proxy.js +46 -35
  86. package/src/remult3/DecoratorReplacer.d.ts +1 -2
  87. package/src/remult3/Fields.d.ts +105 -19
  88. package/src/remult3/Fields.js +47 -7
  89. package/src/remult3/RepositoryImplementation.d.ts +21 -29
  90. package/src/remult3/RepositoryImplementation.js +143 -75
  91. package/src/remult3/entity.d.ts +1 -1
  92. package/src/remult3/entity.js +0 -1
  93. package/src/remult3/remult3.d.ts +195 -33
  94. package/src/remult3/remult3.js +63 -0
  95. package/src/remult3/repository-internals.d.ts +14 -0
  96. package/src/remult3/repository-internals.js +11 -0
  97. package/src/server-action.js +1 -1
  98. package/src/sort.js +13 -3
package/esm/src/column.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getEntityRef } from './remult3/getEntityRef';
2
+ import { getRepositoryInternals } from './remult3/repository-internals';
2
3
  export function makeTitle(name) {
3
4
  // insert a space before all caps
4
5
  return (name
@@ -11,6 +12,7 @@ export function makeTitle(name) {
11
12
  export class LookupColumn {
12
13
  repository;
13
14
  isReferenceRelation;
15
+ allowNull;
14
16
  toJson() {
15
17
  if (!this.storedItem)
16
18
  return undefined;
@@ -26,17 +28,28 @@ export class LookupColumn {
26
28
  waitLoadOf(id) {
27
29
  if (id === undefined || id === null)
28
30
  return null;
29
- return this.repository.getCachedByIdAsync(id, false);
31
+ return getRepositoryInternals(this.repository).getCachedByIdAsync(id, false);
30
32
  }
31
33
  get(id) {
32
34
  if (id === undefined || id === null)
33
35
  return null;
34
- if (this.isReferenceRelation && !this.storedItem)
36
+ const result = getRepositoryInternals(this.repository).getCachedById(id, this.isReferenceRelation);
37
+ if (this.isReferenceRelation && !this.storedItem) {
38
+ if (!this.allowNull && (this.id === 0 || this.id === ''))
39
+ return null;
35
40
  return undefined;
36
- return this.repository.getCachedById(id, this.isReferenceRelation);
41
+ }
42
+ return result;
37
43
  }
38
44
  storedItem;
39
45
  set(item) {
46
+ if (item === null &&
47
+ !this.allowNull &&
48
+ this.isReferenceRelation &&
49
+ (this.id == 0 || this.id == '')) {
50
+ this.storedItem = { item: null };
51
+ return;
52
+ }
40
53
  this.storedItem = undefined;
41
54
  if (item) {
42
55
  if (typeof item === 'string' || typeof item === 'number')
@@ -44,7 +57,7 @@ export class LookupColumn {
44
57
  else {
45
58
  let eo = getEntityRef(item, false);
46
59
  if (eo && !this.isReferenceRelation) {
47
- this.repository.addToCache(item);
60
+ getRepositoryInternals(this.repository).addToCache(item);
48
61
  this.id = eo.getId();
49
62
  }
50
63
  else {
@@ -61,9 +74,10 @@ export class LookupColumn {
61
74
  }
62
75
  }
63
76
  id;
64
- constructor(repository, isReferenceRelation) {
77
+ constructor(repository, isReferenceRelation, allowNull) {
65
78
  this.repository = repository;
66
79
  this.isReferenceRelation = isReferenceRelation;
80
+ this.allowNull = allowNull;
67
81
  }
68
82
  get item() {
69
83
  if (this.storedItem)
@@ -286,3 +286,5 @@ class transactionLiveQueryPublisher {
286
286
  }
287
287
  }
288
288
  }
289
+ //p2 - when value changes for field with error, clear error - so the user will feel comfortable
290
+ //y2 - require filter argument - and perform validation checks for it - site, id etc.. changelog, status changes etc...,
@@ -89,7 +89,10 @@ export class DataApi {
89
89
  databaseCustom: () => { },
90
90
  isGreaterOrEqualTo: () => { },
91
91
  isGreaterThan: () => { },
92
- isIn: () => { },
92
+ isIn: (col) => {
93
+ if (this.repository.metadata.idMetadata.isIdField(col))
94
+ hasId = true;
95
+ },
93
96
  isLessOrEqualTo: () => { },
94
97
  isLessThan: () => { },
95
98
  isNotNull: () => { },
@@ -1,5 +1,5 @@
1
1
  import type { Filter } from './filter/filter-interfaces';
2
- import type { EntityMetadata, OmitEB } from './remult3/remult3';
2
+ import type { EntityMetadata, MembersOnly } from './remult3/remult3';
3
3
  import { Sort } from './sort';
4
4
  export interface DataProvider {
5
5
  getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
@@ -33,7 +33,7 @@ export declare function extractSort(sort: any): Sort;
33
33
  export interface ErrorInfo<entityType = any> {
34
34
  message?: string;
35
35
  modelState?: {
36
- [Properties in keyof Partial<OmitEB<entityType>>]?: string;
36
+ [Properties in keyof Partial<MembersOnly<entityType>>]?: string;
37
37
  };
38
38
  stack?: string;
39
39
  exception?: any;
@@ -1,24 +1,3 @@
1
- import type { EntityDataProvider, EntityDataProviderFindOptions } from '../data-interfaces';
2
- import { type EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request';
3
- import { Filter } from '../filter/filter-interfaces';
4
- import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
5
- export declare class ArrayEntityDataProvider implements EntityDataProvider {
6
- private entity;
7
- static rawFilter(filter: CustomArrayFilter): EntityFilter<any>;
8
- private rows;
9
- constructor(entity: EntityMetadata, rows?: any[]);
10
- __names: EntityDbNamesBase;
11
- init(): Promise<EntityDbNamesBase>;
12
- private verifyThatRowHasAllNotNullColumns;
13
- count(where?: Filter): Promise<number>;
14
- find(options?: EntityDataProviderFindOptions): Promise<any[]>;
15
- translateFromJson(row: any, dbNames: EntityDbNamesBase): {};
16
- translateToJson(row: any, dbNames: EntityDbNamesBase): {};
17
- private idMatches;
18
- update(id: any, data: any): Promise<any>;
19
- delete(id: any): Promise<void>;
20
- insert(data: any): Promise<any>;
21
- }
22
1
  export type CustomArrayFilter = (item: any) => boolean;
23
2
  export interface CustomArrayFilterObject {
24
3
  arrayFilter: CustomArrayFilter;
@@ -1,6 +1,7 @@
1
1
  import { CompoundIdField } from '../CompoundIdField';
2
2
  import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
3
3
  import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
4
+ //@internal
4
5
  export class ArrayEntityDataProvider {
5
6
  entity;
6
7
  static rawFilter(filter) {
@@ -10,6 +11,7 @@ export class ArrayEntityDataProvider {
10
11
  },
11
12
  };
12
13
  }
14
+ //@internal
13
15
  rows;
14
16
  constructor(entity, rows) {
15
17
  this.entity = entity;
@@ -18,7 +20,9 @@ export class ArrayEntityDataProvider {
18
20
  else
19
21
  this.rows = rows;
20
22
  }
23
+ //@internal
21
24
  __names;
25
+ //@internal
22
26
  async init() {
23
27
  if (this.__names)
24
28
  return this.__names;
@@ -28,6 +32,7 @@ export class ArrayEntityDataProvider {
28
32
  }
29
33
  return this.__names;
30
34
  }
35
+ //@internal
31
36
  verifyThatRowHasAllNotNullColumns(r, names) {
32
37
  for (const f of this.entity.fields) {
33
38
  const key = names.$dbNameOf(f);
@@ -89,6 +94,7 @@ export class ArrayEntityDataProvider {
89
94
  });
90
95
  return [];
91
96
  }
97
+ //@internal
92
98
  translateFromJson(row, dbNames) {
93
99
  let result = {};
94
100
  for (const col of this.entity.fields) {
@@ -96,6 +102,7 @@ export class ArrayEntityDataProvider {
96
102
  }
97
103
  return result;
98
104
  }
105
+ //@internal
99
106
  translateToJson(row, dbNames) {
100
107
  let result = {};
101
108
  for (const col of this.entity.fields) {
@@ -104,6 +111,7 @@ export class ArrayEntityDataProvider {
104
111
  }
105
112
  return result;
106
113
  }
114
+ //@internal
107
115
  idMatches(id, names) {
108
116
  return (item) => {
109
117
  let x = new FilterConsumerBridgeToObject(item, names);
@@ -5,6 +5,7 @@ import { remult as defaultRemult } from '../remult-proxy';
5
5
  import { getRepository } from '../remult3/RepositoryImplementation';
6
6
  import { Sort } from '../sort';
7
7
  import { ValueConverters } from '../valueConverters';
8
+ import { getRepositoryInternals } from '../remult3/repository-internals';
8
9
  // @dynamic
9
10
  export class SqlDatabase {
10
11
  sql;
@@ -89,7 +90,7 @@ export class SqlDatabase {
89
90
  const r = getRepository(repo);
90
91
  var b = new FilterConsumerBridgeToSqlRequest(sqlCommand, await dbNamesOf(r.metadata));
91
92
  b._addWhere = false;
92
- await (await r.translateWhereToFilter(condition)).__applyToConsumer(b);
93
+ await (await getRepositoryInternals(r).translateWhereToFilter(condition)).__applyToConsumer(b);
93
94
  return await b.resolveWhere();
94
95
  }
95
96
  /**
@@ -1,6 +1,6 @@
1
1
  import type { Allowed, AllowedForInstance } from './context';
2
2
  import type { FieldMetadata } from './column-interfaces';
3
- import type { EntityFilter, EntityIdFields, EntityMetadata, EntityOrderBy, EntityRef, FieldsMetadata, LifeCycleEvent } 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, e: LifeCycleEvent<entityType>) => Promise<any> | any;
64
- /** will be called after the Entity was saved to the data source. */
65
- saved?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
66
- /** Will be called before an Entity is deleted. */
67
- deleting?: (row: entityType, e: LifeCycleEvent<entityType>) => Promise<any> | any;
68
- /** Will be called after an Entity is deleted */
69
- deleted?: (row: entityType, e: LifeCycleEvent<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,10 +115,10 @@ 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
123
  id?: EntityIdFields<entityType> | ((entity: FieldsMetadata<entityType>) => FieldMetadata | FieldMetadata[]);
93
124
  entityRefInit?: (ref: EntityRef<entityType>, row: entityType) => void;
package/esm/src/entity.js CHANGED
@@ -1,2 +1 @@
1
1
  export {};
2
- //[ ] make lazy only on field and not in Field Options
@@ -1,6 +1,6 @@
1
1
  import type { FieldMetadata } from '../column-interfaces';
2
2
  import type { EntityMetadataOverloads, RepositoryOverloads } from '../remult3/RepositoryImplementation';
3
- import type { EntityFilter, OmitEB } from '../remult3/remult3';
3
+ import type { EntityFilter, MembersOnly } from '../remult3/remult3';
4
4
  import type { SqlCommandWithParameters } from '../sql-command';
5
5
  import type { Filter, FilterConsumer } from './filter-interfaces';
6
6
  export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer {
@@ -45,6 +45,6 @@ export declare type EntityDbNamesBase = {
45
45
  toString(): string;
46
46
  };
47
47
  export declare type EntityDbNames<entityType> = {
48
- [Properties in keyof Required<OmitEB<entityType>>]: string;
48
+ [Properties in keyof Required<MembersOnly<entityType>>]: string;
49
49
  } & EntityDbNamesBase;
50
50
  export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType>): Promise<EntityDbNames<entityType>>;
@@ -208,6 +208,8 @@ class filterHelper {
208
208
  }
209
209
  isIn(val) {
210
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]));
211
213
  return new Filter((add) => add.isIn(this.metadata, val));
212
214
  }
213
215
  }
@@ -600,3 +602,5 @@ export function __updateEntityBasedOnWhere(entityDefs, where, r) {
600
602
  });
601
603
  }
602
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,7 +14,7 @@ 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
19
  listener(() => {
19
20
  return 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,14 +82,20 @@ 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
+ },
84
90
  relations: (args2) => self
85
91
  .remultFactory()
86
92
  .repo(...args)
87
93
  .relations(args2),
88
- validate: (a, b) => self
94
+ validate: (a, ...b) => self
89
95
  .remultFactory()
90
96
  .repo(...args)
91
- .validate(a, b),
97
+ //@ts-ignore
98
+ .validate(a, ...b),
92
99
  addEventListener: (...args2) => self
93
100
  .remultFactory()
94
101
  .repo(...args)
@@ -138,10 +145,6 @@ export class RemultProxy {
138
145
  .remultFactory()
139
146
  .repo(...args)
140
147
  .liveQuery(...args2),
141
- //@ts-ignore
142
- addToCache: (a) => self
143
- .remultFactory()
144
- .repo(...args).addToCache(a),
145
148
  get metadata() {
146
149
  return self.remultFactory().repo(...args).metadata;
147
150
  },
@@ -1,7 +1,6 @@
1
- import type { OmitEB } from './remult3';
2
1
  type Decorator<T = any> = (a: T, b: string, c?: any) => void;
3
2
  type Decorators<T> = T extends new (...args: any[]) => infer R ? {
4
- [K in keyof OmitEB<R>]?: Decorator;
3
+ [K in keyof R]?: Decorator;
5
4
  } : never;
6
5
  type StaticDecorators<T> = {
7
6
  [K in keyof T]?: Decorator;
@@ -1,31 +1,117 @@
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 } 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;
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>;
23
22
  }
24
23
  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>> & {
27
- fromEntityType?: ClassType<entityType>;
28
- }) | keyof toEntityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
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
+ * Fields.string()
40
+ * customerId?: string;
41
+ *
42
+ * @Relations.toOne(() => Customer, "customerId")
43
+ * customer?: Customer;
44
+ * ```
45
+ * ```
46
+ * Fields.string()
47
+ * customerId?: string;
48
+ *
49
+ * @Relations.toOne(() => Customer, {
50
+ * field: "customerId",
51
+ * defaultIncluded: true
52
+ * })
53
+ * customer?: Customer;
54
+ * ```
55
+ * ```
56
+ * Fields.string()
57
+ * customerId?: string;
58
+ *
59
+ * @Relations.toOne(() => Customer, {
60
+ * fields: {
61
+ * customerId: "id",
62
+ * },
63
+ * })
64
+ * customer?: Customer;
65
+ * ```
66
+ */
67
+ static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'> | RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<any, toEntityType>, c?: any) => void;
68
+ /**
69
+ * Define a toMany relation between entities, indicating a one-to-many relationship.
70
+ * This method allows you to establish a relationship where one entity can have multiple related entities.
71
+ *
72
+ * @param toEntityType A function that returns the target entity type.
73
+ * @param fieldInToEntity (Optional) The field in the target entity that represents the relation.
74
+ * Use this if you want to specify a custom field name for the relation.
75
+ * @returns A decorator function to apply the toMany relation to an entity field.
76
+ *
77
+ * Example usage:
78
+ * ```
79
+ * @Relations.toMany(() => Order)
80
+ * orders?: Order[];
81
+ *
82
+ * // or with a custom field name:
83
+ * @Relations.toMany(() => Order, "customerId")
84
+ * orders?: Order[];
85
+ * ```
86
+ */
87
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
88
+ /**
89
+ * Define a toMany relation between entities, indicating a one-to-many relationship.
90
+ * This method allows you to establish a relationship where one entity can have multiple related entities.
91
+ * You can also specify various options to customize the relation and control related data retrieval.
92
+ *
93
+ * @param toEntityType A function that returns the target entity type.
94
+ * @param options An object containing options for configuring the toMany relation.
95
+ * - field (Optional): The field in the target entity that represents the relation.
96
+ * Use this if you want to specify a custom field name for the relation.
97
+ * - findOptions (Optional): Customize the options for finding related entities.
98
+ * You can set limits, order, where conditions, and more.
99
+ * @returns A decorator function to apply the toMany relation to an entity field.
100
+ *
101
+ * Example usage:
102
+ * ```
103
+ * @Relations.toMany(() => Order, {
104
+ * field: "customerOrders",
105
+ * findOptions: {
106
+ * limit: 10,
107
+ * orderBy: { amount: "desc" },
108
+ * where: { completed: true },
109
+ * },
110
+ * })
111
+ * orders?: Order[];
112
+ * ```
113
+ */
114
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
29
115
  }
30
116
  /**Decorates fields that should be used as fields.
31
117
  * for more info see: [Field Types](https://remult.dev/docs/field-types.html)