remult 0.22.8 → 0.22.9-exp.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 (67) hide show
  1. package/esm/index.d.ts +4 -3
  2. package/esm/index.js +3 -1
  3. package/esm/internals.d.ts +6 -0
  4. package/esm/internals.js +5 -0
  5. package/esm/live-query/data-provider-live-query-storage.js +2 -1
  6. package/esm/server/expressBridge.d.ts +1 -1
  7. package/esm/server/expressBridge.js +2 -1
  8. package/esm/src/column.d.ts +3 -2
  9. package/esm/src/column.js +6 -5
  10. package/esm/src/context.js +2 -2
  11. package/esm/src/data-providers/array-entity-data-provider.d.ts +5 -2
  12. package/esm/src/data-providers/array-entity-data-provider.js +63 -46
  13. package/esm/src/data-providers/rest-data-provider.d.ts +1 -1
  14. package/esm/src/data-providers/rest-data-provider.js +51 -7
  15. package/esm/src/remult3/Fields.d.ts +46 -0
  16. package/esm/src/remult3/Fields.js +199 -0
  17. package/esm/src/remult3/IdEntity.d.ts +4 -0
  18. package/esm/src/remult3/IdEntity.js +10 -0
  19. package/esm/src/remult3/RepositoryImplementation.d.ts +11 -48
  20. package/esm/src/remult3/RepositoryImplementation.js +201 -193
  21. package/esm/src/remult3/columnInfo.d.ts +6 -0
  22. package/esm/src/remult3/columnInfo.js +1 -0
  23. package/esm/src/remult3/relation-loader-types.d.ts +7 -0
  24. package/esm/src/remult3/relation-loader-types.js +1 -0
  25. package/esm/src/remult3/relation-loader.d.ts +40 -0
  26. package/esm/src/remult3/relation-loader.js +139 -0
  27. package/esm/src/remult3/relationInfoMember.d.ts +4 -0
  28. package/esm/src/remult3/relationInfoMember.js +4 -0
  29. package/esm/src/remult3/remult3.d.ts +30 -1
  30. package/esm/src/remult3/remult3.js +4 -0
  31. package/esm/src/server-action.js +2 -1
  32. package/esm/src/sort.d.ts +1 -1
  33. package/esm/src/sort.js +5 -3
  34. package/index.d.ts +4 -3
  35. package/index.js +6 -4
  36. package/internals.d.ts +6 -0
  37. package/internals.js +13 -0
  38. package/live-query/data-provider-live-query-storage.js +5 -4
  39. package/package.json +6 -14
  40. package/server/expressBridge.d.ts +1 -1
  41. package/server/expressBridge.js +11 -10
  42. package/src/column.d.ts +3 -2
  43. package/src/column.js +4 -4
  44. package/src/context.js +1 -1
  45. package/src/data-providers/array-entity-data-provider.d.ts +5 -2
  46. package/src/data-providers/array-entity-data-provider.js +192 -134
  47. package/src/data-providers/rest-data-provider.d.ts +1 -1
  48. package/src/data-providers/rest-data-provider.js +45 -4
  49. package/src/remult3/Fields.d.ts +46 -0
  50. package/src/remult3/Fields.js +259 -0
  51. package/src/remult3/IdEntity.d.ts +4 -0
  52. package/src/remult3/IdEntity.js +18 -0
  53. package/src/remult3/RepositoryImplementation.d.ts +11 -48
  54. package/src/remult3/RepositoryImplementation.js +422 -415
  55. package/src/remult3/columnInfo.d.ts +6 -0
  56. package/src/remult3/columnInfo.js +2 -0
  57. package/src/remult3/relation-loader-types.d.ts +7 -0
  58. package/src/remult3/relation-loader-types.js +2 -0
  59. package/src/remult3/relation-loader.d.ts +40 -0
  60. package/src/remult3/relation-loader.js +216 -0
  61. package/src/remult3/relationInfoMember.d.ts +4 -0
  62. package/src/remult3/relationInfoMember.js +8 -0
  63. package/src/remult3/remult3.d.ts +30 -1
  64. package/src/remult3/remult3.js +4 -0
  65. package/src/server-action.js +2 -1
  66. package/src/sort.d.ts +1 -1
  67. package/src/sort.js +5 -3
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, } from './src/remult3/remult3';
2
- export { Field, Fields, IdEntity, EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
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';
2
+ export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
3
3
  export { Entity } from './src/remult3/entity';
4
4
  export { getEntityRef } from './src/remult3/getEntityRef';
5
- export { StringFieldOptions } from './src/remult3/RepositoryImplementation';
5
+ export { Field, Fields, StringFieldOptions } from './src/remult3/Fields';
6
+ export { IdEntity } from './src/remult3/IdEntity';
6
7
  export { describeClass } from './src/remult3/DecoratorReplacer';
7
8
  export { EntityOptions } from './src/entity';
8
9
  export { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo, RestDataProviderHttpProvider, } from './src/data-interfaces';
package/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
- export { Field, Fields, IdEntity, EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
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';
5
+ export { IdEntity } from './src/remult3/IdEntity';
4
6
  export { describeClass } from './src/remult3/DecoratorReplacer';
5
7
  export { RestDataProvider } from './src/data-providers/rest-data-provider'; //V
6
8
  export { InMemoryDataProvider } from './src/data-providers/in-memory-database'; //V
@@ -0,0 +1,6 @@
1
+ export { getRelationInfo } from './src/remult3/relationInfoMember';
2
+ export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
3
+ export { getEntitySettings } from './src/remult3/getEntityRef';
4
+ export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
5
+ export { actionInfo } from './src/server-action-info';
6
+ export { RelationInfo } from './src/remult3/remult3';
@@ -0,0 +1,5 @@
1
+ export { getRelationInfo } from './src/remult3/relationInfoMember';
2
+ export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
3
+ export { getEntitySettings } from './src/remult3/getEntityRef';
4
+ export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
5
+ export { actionInfo } from './src/server-action-info';
@@ -1,7 +1,8 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { initDataProvider } from '../server/initDataProvider';
3
3
  import { allEntities, Remult } from '../src/context';
4
- import { EntityBase, Fields } from '../src/remult3/RepositoryImplementation';
4
+ import { EntityBase } from '../src/remult3/RepositoryImplementation';
5
+ import { Fields } from '../src/remult3/Fields';
5
6
  import { Entity } from '../src/remult3/entity';
6
7
  export class DataProviderLiveQueryStorage {
7
8
  repo;
@@ -3,7 +3,7 @@ import type { UserInfo } from '../src/context';
3
3
  import { Remult } from '../src/context';
4
4
  import type { DataProvider } from '../src/data-interfaces';
5
5
  import type { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
6
- import { IdEntity } from '../src/remult3/RepositoryImplementation';
6
+ import { IdEntity } from '../src/remult3/IdEntity';
7
7
  import type { Repository } from '../src/remult3/remult3';
8
8
  import type { queuedJobInfoResponse } from '../src/server-action';
9
9
  export interface RemultServerOptions<RequestType> {
@@ -4,7 +4,8 @@ import { Remult, RemultAsyncLocalStorage, allEntities } from '../src/context';
4
4
  import { DataApi, serializeError } from '../src/data-api';
5
5
  import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel';
6
6
  import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer';
7
- import { Fields, IdEntity } from '../src/remult3/RepositoryImplementation';
7
+ import { IdEntity } from '../src/remult3/IdEntity';
8
+ import { Fields } from '../src/remult3/Fields';
8
9
  import { Entity } from '../src/remult3/entity';
9
10
  import { getEntityKey } from '../src/remult3/getEntityRef';
10
11
  import { Action, classBackendMethodsArray } from '../src/server-action';
@@ -3,7 +3,7 @@ import type { RepositoryImplementation } from './remult3/RepositoryImplementatio
3
3
  export declare function makeTitle(name: string): string;
4
4
  export declare class LookupColumn<T> {
5
5
  private repository;
6
- id: idType<T>;
6
+ private isManyToOneRelation;
7
7
  toJson(): any;
8
8
  setId(val: any): void;
9
9
  waitLoadOf(id: any): Promise<T>;
@@ -12,7 +12,8 @@ export declare class LookupColumn<T> {
12
12
  item: T;
13
13
  };
14
14
  set(item: T): void;
15
- constructor(repository: RepositoryImplementation<T>, id: idType<T>);
15
+ id: idType<T>;
16
+ constructor(repository: RepositoryImplementation<T>, isManyToOneRelation: any);
16
17
  get item(): T;
17
18
  waitLoad(): Promise<T>;
18
19
  }
package/esm/src/column.js CHANGED
@@ -12,7 +12,7 @@ export function makeTitle(name) {
12
12
  }
13
13
  export class LookupColumn {
14
14
  repository;
15
- id;
15
+ isManyToOneRelation;
16
16
  toJson() {
17
17
  if (!this.storedItem)
18
18
  return undefined;
@@ -28,12 +28,12 @@ export class LookupColumn {
28
28
  waitLoadOf(id) {
29
29
  if (id === undefined || id === null)
30
30
  return null;
31
- return this.repository.getCachedByIdAsync(id);
31
+ return this.repository.getCachedByIdAsync(id, false);
32
32
  }
33
33
  get(id) {
34
34
  if (id === undefined || id === null)
35
35
  return null;
36
- return this.repository.getCachedById(id);
36
+ return this.repository.getCachedById(id, this.isManyToOneRelation);
37
37
  }
38
38
  storedItem;
39
39
  set(item) {
@@ -60,9 +60,10 @@ export class LookupColumn {
60
60
  this.id = undefined;
61
61
  }
62
62
  }
63
- constructor(repository, id) {
63
+ id;
64
+ constructor(repository, isManyToOneRelation) {
64
65
  this.repository = repository;
65
- this.id = id;
66
+ this.isManyToOneRelation = isManyToOneRelation;
66
67
  }
67
68
  get item() {
68
69
  if (this.storedItem)
@@ -2,7 +2,7 @@ import { RestDataProvider } from './data-providers/rest-data-provider';
2
2
  import { LiveQueryClient } from './live-query/LiveQueryClient';
3
3
  import { SseSubscriptionClient } from './live-query/SseSubscriptionClient';
4
4
  import { RemultProxy, remult } from './remult-proxy';
5
- import { RepositoryImplementation } from './remult3/RepositoryImplementation';
5
+ import { RepositoryImplementation, createOldEntity, } from './remult3/RepositoryImplementation';
6
6
  import { actionInfo, serverActionField } from './server-action-info';
7
7
  import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider';
8
8
  export class RemultAsyncLocalStorage {
@@ -57,7 +57,7 @@ export class Remult {
57
57
  this.repCache.set(dataProvider, (dpCache = new Map()));
58
58
  let r = dpCache.get(entity);
59
59
  if (!r) {
60
- dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider)));
60
+ dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider, createOldEntity(entity, this))));
61
61
  }
62
62
  return r;
63
63
  }
@@ -1,4 +1,5 @@
1
1
  import type { EntityDataProvider, EntityDataProviderFindOptions } from '../data-interfaces';
2
+ import { type EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request';
2
3
  import { Filter } from '../filter/filter-interfaces';
3
4
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
4
5
  export declare class ArrayEntityDataProvider implements EntityDataProvider {
@@ -6,11 +7,13 @@ export declare class ArrayEntityDataProvider implements EntityDataProvider {
6
7
  private rows?;
7
8
  static rawFilter(filter: CustomArrayFilter): EntityFilter<any>;
8
9
  constructor(entity: EntityMetadata, rows?: any[]);
10
+ __names: EntityDbNamesBase;
11
+ init(): Promise<EntityDbNamesBase>;
9
12
  private verifyThatRowHasAllNotNullColumns;
10
13
  count(where?: Filter): Promise<number>;
11
14
  find(options?: EntityDataProviderFindOptions): Promise<any[]>;
12
- translateFromJson(row: any): {};
13
- translateToJson(row: any): {};
15
+ translateFromJson(row: any, dbNames: EntityDbNamesBase): {};
16
+ translateToJson(row: any, dbNames: EntityDbNamesBase): {};
14
17
  private idMatches;
15
18
  update(id: any, data: any): Promise<any>;
16
19
  delete(id: any): Promise<void>;
@@ -1,4 +1,5 @@
1
1
  import { CompoundIdField } from '../CompoundIdField';
2
+ import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
2
3
  import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
3
4
  export class ArrayEntityDataProvider {
4
5
  entity;
@@ -16,16 +17,24 @@ export class ArrayEntityDataProvider {
16
17
  if (!rows)
17
18
  rows = [];
18
19
  else {
19
- for (const r of rows) {
20
- this.verifyThatRowHasAllNotNullColumns(r);
21
- }
22
20
  }
23
21
  }
24
- verifyThatRowHasAllNotNullColumns(r) {
22
+ __names;
23
+ async init() {
24
+ if (this.__names)
25
+ return this.__names;
26
+ this.__names = await dbNamesOf(this.entity);
27
+ for (const r of this.rows) {
28
+ this.verifyThatRowHasAllNotNullColumns(r, this.__names);
29
+ }
30
+ return this.__names;
31
+ }
32
+ verifyThatRowHasAllNotNullColumns(r, names) {
25
33
  for (const f of this.entity.fields) {
34
+ const key = names.$dbNameOf(f);
26
35
  if (!f.isServerExpression)
27
36
  if (!f.allowNull) {
28
- if (r[f.key] === undefined || r[f.key] === null) {
37
+ if (r[key] === undefined || r[key] === null) {
29
38
  let val = undefined;
30
39
  if (f.valueType === Boolean)
31
40
  val = false;
@@ -33,22 +42,23 @@ export class ArrayEntityDataProvider {
33
42
  val = 0;
34
43
  else if (f.valueType === String)
35
44
  val = '';
36
- r[f.key] = val;
45
+ r[key] = val;
37
46
  }
38
47
  }
39
- else if (r[f.key] === undefined)
40
- r[f.key] = null;
48
+ else if (r[key] === undefined)
49
+ r[key] = null;
41
50
  }
42
51
  }
43
52
  async count(where) {
44
53
  let rows = this.rows;
54
+ const names = await this.init();
45
55
  let j = 0;
46
56
  for (let i = 0; i < rows.length; i++) {
47
57
  if (!where) {
48
58
  j++;
49
59
  }
50
60
  else {
51
- let x = new FilterConsumerBridgeToObject(rows[i]);
61
+ let x = new FilterConsumerBridgeToObject(rows[i], names);
52
62
  where.__applyToConsumer(x);
53
63
  if (x.ok)
54
64
  j++;
@@ -58,70 +68,74 @@ export class ArrayEntityDataProvider {
58
68
  }
59
69
  async find(options) {
60
70
  let rows = this.rows;
71
+ const dbNames = await this.init();
61
72
  if (options) {
62
73
  if (options.where) {
63
74
  rows = rows.filter((i) => {
64
- let x = new FilterConsumerBridgeToObject(i);
75
+ let x = new FilterConsumerBridgeToObject(i, dbNames);
65
76
  options.where.__applyToConsumer(x);
66
77
  return x.ok;
67
78
  });
68
79
  }
69
80
  if (options.orderBy) {
70
81
  rows = rows.sort((a, b) => {
71
- return options.orderBy.compare(a, b);
82
+ return options.orderBy.compare(a, b, dbNames.$dbNameOf);
72
83
  });
73
84
  }
74
85
  rows = pageArray(rows, options);
75
86
  }
76
87
  if (rows)
77
88
  return rows.map((i) => {
78
- return this.translateFromJson(i);
89
+ return this.translateFromJson(i, dbNames);
79
90
  });
80
91
  }
81
- translateFromJson(row) {
92
+ translateFromJson(row, dbNames) {
82
93
  let result = {};
83
94
  for (const col of this.entity.fields) {
84
- result[col.key] = col.valueConverter.fromJson(row[col.key]);
95
+ result[col.key] = col.valueConverter.fromJson(row[dbNames.$dbNameOf(col)]);
85
96
  }
86
97
  return result;
87
98
  }
88
- translateToJson(row) {
99
+ translateToJson(row, dbNames) {
89
100
  let result = {};
90
101
  for (const col of this.entity.fields) {
91
- result[col.key] = col.valueConverter.toJson(row[col.key]);
102
+ if (!isDbReadonly(col, dbNames))
103
+ result[dbNames.$dbNameOf(col)] = col.valueConverter.toJson(row[col.key]);
92
104
  }
93
105
  return result;
94
106
  }
95
- idMatches(id) {
107
+ idMatches(id, names) {
96
108
  return (item) => {
97
- let x = new FilterConsumerBridgeToObject(item);
109
+ let x = new FilterConsumerBridgeToObject(item, names);
98
110
  Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(x);
99
111
  return x.ok;
100
112
  };
101
113
  }
102
- update(id, data) {
103
- let idMatches = this.idMatches(id);
114
+ async update(id, data) {
115
+ const names = await this.init();
116
+ let idMatches = this.idMatches(id, names);
104
117
  let keys = Object.keys(data);
105
118
  for (let i = 0; i < this.rows.length; i++) {
106
119
  let r = this.rows[i];
107
120
  if (idMatches(r)) {
108
121
  let newR = { ...r };
109
122
  for (const f of this.entity.fields) {
110
- if (!f.dbReadOnly && !f.isServerExpression) {
123
+ if (!isDbReadonly(f, names)) {
111
124
  if (keys.includes(f.key)) {
112
- newR[f.key] = f.valueConverter.toJson(data[f.key]);
125
+ newR[names.$dbNameOf(f)] = f.valueConverter.toJson(data[f.key]);
113
126
  }
114
127
  }
115
128
  }
116
- this.verifyThatRowHasAllNotNullColumns(newR);
129
+ this.verifyThatRowHasAllNotNullColumns(newR, names);
117
130
  this.rows[i] = newR;
118
- return Promise.resolve(this.translateFromJson(this.rows[i]));
131
+ return Promise.resolve(this.translateFromJson(this.rows[i], names));
119
132
  }
120
133
  }
121
134
  throw new Error("couldn't find id to update: " + id);
122
135
  }
123
- delete(id) {
124
- let idMatches = this.idMatches(id);
136
+ async delete(id) {
137
+ const names = await this.init();
138
+ let idMatches = this.idMatches(id, names);
125
139
  for (let i = 0; i < this.rows.length; i++) {
126
140
  if (idMatches(this.rows[i])) {
127
141
  this.rows.splice(i, 1);
@@ -131,25 +145,26 @@ export class ArrayEntityDataProvider {
131
145
  throw new Error("couldn't find id to delete: " + id);
132
146
  }
133
147
  async insert(data) {
148
+ const names = await this.init();
149
+ let j = this.translateToJson(data, names);
134
150
  let idf = this.entity.idMetadata.field;
135
151
  if (!(idf instanceof CompoundIdField)) {
136
152
  if (idf.options.valueConverter?.fieldTypeInDb === 'autoincrement') {
137
- data[idf.key] = 1;
153
+ j[idf.key] = 1;
138
154
  for (const row of this.rows) {
139
- if (row[idf.key] >= data[idf.key])
140
- data[idf.key] = row[idf.key] + 1;
155
+ if (row[idf.key] >= j[idf.key])
156
+ j[idf.key] = row[idf.key] + 1;
141
157
  }
142
158
  }
143
- if (data[idf.key])
159
+ if (j[idf.key])
144
160
  this.rows.forEach((i) => {
145
- if (data[idf.key] == i[idf.key])
161
+ if (j[idf.key] == i[idf.key])
146
162
  throw Error('id already exists');
147
163
  });
148
164
  }
149
- let j = this.translateToJson(data);
150
- this.verifyThatRowHasAllNotNullColumns(j);
165
+ this.verifyThatRowHasAllNotNullColumns(j, names);
151
166
  this.rows.push(j);
152
- return Promise.resolve(this.translateFromJson(j));
167
+ return Promise.resolve(this.translateFromJson(j, names));
153
168
  }
154
169
  }
155
170
  function pageArray(rows, options) {
@@ -172,9 +187,11 @@ function pageArray(rows, options) {
172
187
  }
173
188
  class FilterConsumerBridgeToObject {
174
189
  row;
190
+ dbNames;
175
191
  ok = true;
176
- constructor(row) {
192
+ constructor(row, dbNames) {
177
193
  this.row = row;
194
+ this.dbNames = dbNames;
178
195
  }
179
196
  databaseCustom(databaseCustom) {
180
197
  if (databaseCustom && databaseCustom.arrayFilter) {
@@ -187,7 +204,7 @@ class FilterConsumerBridgeToObject {
187
204
  }
188
205
  or(orElements) {
189
206
  for (const element of orElements) {
190
- let filter = new FilterConsumerBridgeToObject(this.row);
207
+ let filter = new FilterConsumerBridgeToObject(this.row, this.dbNames);
191
208
  element.__applyToConsumer(filter);
192
209
  if (filter.ok) {
193
210
  return;
@@ -196,47 +213,47 @@ class FilterConsumerBridgeToObject {
196
213
  this.ok = false;
197
214
  }
198
215
  isNull(col) {
199
- if (this.row[col.key] != null)
216
+ if (this.row[this.dbNames.$dbNameOf(col)] != null)
200
217
  this.ok = false;
201
218
  }
202
219
  isNotNull(col) {
203
- if (this.row[col.key] == null)
220
+ if (this.row[this.dbNames.$dbNameOf(col)] == null)
204
221
  this.ok = false;
205
222
  }
206
223
  isIn(col, val) {
207
224
  for (const v of val) {
208
- if (this.row[col.key] == col.valueConverter.toJson(v)) {
225
+ if (this.row[this.dbNames.$dbNameOf(col)] == col.valueConverter.toJson(v)) {
209
226
  return;
210
227
  }
211
228
  }
212
229
  this.ok = false;
213
230
  }
214
231
  isEqualTo(col, val) {
215
- if (this.row[col.key] != col.valueConverter.toJson(val))
232
+ if (this.row[this.dbNames.$dbNameOf(col)] != col.valueConverter.toJson(val))
216
233
  this.ok = false;
217
234
  }
218
235
  isDifferentFrom(col, val) {
219
- if (this.row[col.key] == col.valueConverter.toJson(val))
236
+ if (this.row[this.dbNames.$dbNameOf(col)] == col.valueConverter.toJson(val))
220
237
  this.ok = false;
221
238
  }
222
239
  isGreaterOrEqualTo(col, val) {
223
- if (this.row[col.key] < col.valueConverter.toJson(val))
240
+ if (this.row[this.dbNames.$dbNameOf(col)] < col.valueConverter.toJson(val))
224
241
  this.ok = false;
225
242
  }
226
243
  isGreaterThan(col, val) {
227
- if (this.row[col.key] <= col.valueConverter.toJson(val))
244
+ if (this.row[this.dbNames.$dbNameOf(col)] <= col.valueConverter.toJson(val))
228
245
  this.ok = false;
229
246
  }
230
247
  isLessOrEqualTo(col, val) {
231
- if (this.row[col.key] > col.valueConverter.toJson(val))
248
+ if (this.row[this.dbNames.$dbNameOf(col)] > col.valueConverter.toJson(val))
232
249
  this.ok = false;
233
250
  }
234
251
  isLessThan(col, val) {
235
- if (this.row[col.key] >= col.valueConverter.toJson(val))
252
+ if (this.row[this.dbNames.$dbNameOf(col)] >= col.valueConverter.toJson(val))
236
253
  this.ok = false;
237
254
  }
238
255
  containsCaseInsensitive(col, val) {
239
- let v = this.row[col.key];
256
+ let v = this.row[this.dbNames.$dbNameOf(col)];
240
257
  if (!v) {
241
258
  this.ok = false;
242
259
  return;
@@ -1,6 +1,6 @@
1
1
  import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, RestDataProviderHttpProvider } from '../data-interfaces';
2
2
  import { UrlBuilder } from '../../urlBuilder';
3
- import type { ApiClient } from '../context';
3
+ import { type ApiClient } from '../context';
4
4
  import { Filter } from '../filter/filter-interfaces';
5
5
  import type { EntityMetadata } from '../remult3/remult3';
6
6
  export declare class RestDataProvider implements DataProvider {
@@ -1,7 +1,9 @@
1
1
  import { UrlBuilder } from '../../urlBuilder';
2
2
  import { buildRestDataProvider, retry } from '../buildRestDataProvider';
3
+ import { Remult } from '../context';
3
4
  import { customUrlToken, Filter } from '../filter/filter-interfaces';
4
5
  import { actionInfo } from '../server-action-info';
6
+ import { getRelationInfo } from '../remult3/relationInfoMember';
5
7
  export class RestDataProvider {
6
8
  apiProvider;
7
9
  constructor(apiProvider) {
@@ -24,22 +26,64 @@ export class RestDataProvider {
24
26
  }
25
27
  //@internal
26
28
  export function findOptionsToJson(options, meta) {
27
- const r = {
28
- ...options,
29
- where: Filter.entityFilterToJson(meta, options.where),
30
- };
29
+ if (options.include) {
30
+ let newInclude = {};
31
+ for (const key in options.include) {
32
+ if (Object.prototype.hasOwnProperty.call(options.include, key)) {
33
+ let element = options.include[key];
34
+ if (typeof element === 'object') {
35
+ const rel = getRelationInfo(meta.fields.find(key).options);
36
+ if (rel) {
37
+ element = findOptionsToJson(element, new Remult().repo(rel.toType()).metadata);
38
+ }
39
+ }
40
+ newInclude[key] = element;
41
+ }
42
+ }
43
+ options = { ...options, include: newInclude };
44
+ }
45
+ if (options.where)
46
+ options = {
47
+ ...options,
48
+ where: Filter.entityFilterToJson(meta, options.where),
49
+ };
31
50
  if (options.load)
32
- r.load = options.load(meta.fields).map((y) => y.key);
33
- return r;
51
+ options = {
52
+ ...options,
53
+ load: options.load(meta.fields).map((y) => y.key),
54
+ };
55
+ return options;
34
56
  }
35
57
  //@internal
36
58
  export function findOptionsFromJson(json, meta) {
37
59
  let r = {};
38
- for (const key of ['limit', 'page', 'where', 'orderBy']) {
60
+ for (const key of [
61
+ 'limit',
62
+ 'page',
63
+ 'where',
64
+ 'orderBy',
65
+ 'include',
66
+ ]) {
39
67
  if (json[key] !== undefined) {
40
68
  if (key === 'where') {
41
69
  r[key] = Filter.entityFilterFromJson(meta, json.where);
42
70
  }
71
+ else if (key === 'include') {
72
+ let newInclude = { ...json[key] };
73
+ for (const key in newInclude) {
74
+ if (Object.prototype.hasOwnProperty.call(newInclude, key)) {
75
+ let element = newInclude[key];
76
+ if (typeof element === 'object') {
77
+ const rel = getRelationInfo(meta.fields.find(key).options);
78
+ if (rel) {
79
+ element = findOptionsFromJson(element, new Remult().repo(rel.toType()).metadata);
80
+ }
81
+ }
82
+ newInclude[key] = element;
83
+ }
84
+ }
85
+ r[key] = newInclude;
86
+ }
43
87
  else
44
88
  r[key] = json[key];
45
89
  }
@@ -0,0 +1,46 @@
1
+ import type { ClassType } from '../../classType';
2
+ import type { FieldOptions } from '../column-interfaces';
3
+ import type { Remult } from '../context';
4
+ import type { FindOptions, RelationOptions, RelationOptionsBase } from './remult3';
5
+ import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
6
+ export declare class Fields {
7
+ /**
8
+ * Stored as a JSON.stringify - to store as json use Fields.json
9
+ */
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;
28
+ }
29
+ /**Decorates fields that should be used as fields.
30
+ * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
31
+ *
32
+ * FieldOptions can be set in two ways:
33
+ * @example
34
+ * // as an object
35
+ * @Fields.string({ includeInApi:false })
36
+ * title='';
37
+ * @example
38
+ * // as an arrow function that receives `remult` as a parameter
39
+ * @Fields.string((options,remult) => options.includeInApi = true)
40
+ * title='';
41
+ */
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;
43
+ export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
44
+ maxLength?: number;
45
+ }
46
+ export declare function checkTarget(target: any): void;