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
@@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var uuid_1 = require("uuid");
6
6
  var sort_1 = require("../sort");
7
7
  var remult_proxy_1 = require("../remult-proxy");
8
+ var repository_internals_1 = require("../remult3/repository-internals");
8
9
  exports.streamUrl = 'stream';
9
10
  //@internal
10
11
  var LiveQuerySubscriber = /** @class */ (function () {
@@ -27,11 +28,11 @@ var LiveQuerySubscriber = /** @class */ (function () {
27
28
  var items;
28
29
  return tslib_1.__generator(this, function (_a) {
29
30
  switch (_a.label) {
30
- case 0: return [4 /*yield*/, this.repo.fromJsonArray(result, this.query.options)];
31
+ case 0: return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(this.repo).fromJsonArray(result, this.query.options)];
31
32
  case 1:
32
33
  items = _a.sent();
33
34
  this.forListeners(function (listener) {
34
- listener(function (x) {
35
+ listener(function () {
35
36
  return items;
36
37
  });
37
38
  }, this.allItemsMessage(items));
@@ -97,7 +98,7 @@ var LiveQuerySubscriber = /** @class */ (function () {
97
98
  var type = _a.type;
98
99
  return type == 'add' || type == 'replace';
99
100
  });
100
- return [4 /*yield*/, this.repo.fromJsonArray(x.map(function (m) { return m.data.item; }), this.query.options)];
101
+ return [4 /*yield*/, (0, repository_internals_1.getRepositoryInternals)(this.repo).fromJsonArray(x.map(function (m) { return m.data.item; }), this.query.options)];
101
102
  case 1:
102
103
  loadedItems = _a.sent();
103
104
  for (index = 0; index < x.length; index++) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.remult = exports.RemultProxy = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var repository_internals_1 = require("./remult3/repository-internals");
5
6
  var defaultRemult;
6
7
  function defaultFactory() {
7
8
  if (!defaultRemult) {
@@ -18,6 +19,7 @@ var RemultProxy = /** @class */ (function () {
18
19
  this.repoCache = new Map();
19
20
  //@ts-ignore
20
21
  this.repo = function () {
22
+ var _a;
21
23
  var args = [];
22
24
  for (var _i = 0; _i < arguments.length; _i++) {
23
25
  args[_i] = arguments[_i];
@@ -30,18 +32,31 @@ var RemultProxy = /** @class */ (function () {
30
32
  var result = entityCache.get(args[1]);
31
33
  if (result)
32
34
  return result;
33
- result = {
34
- get fields() {
35
+ result = (_a = {
36
+ get fields() {
37
+ var _a;
38
+ return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata.fields;
39
+ }
40
+ },
41
+ _a[repository_internals_1.getInternalKey] = function () {
35
42
  var _a;
36
- return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata.fields;
43
+ return (_a = self
44
+ .remultFactory())
45
+ .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_1.getInternalKey]();
37
46
  },
38
- validate: function (a, b) {
47
+ _a.relations = function (args2) {
48
+ var _a;
49
+ return (_a = self
50
+ .remultFactory())
51
+ .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).relations(args2);
52
+ },
53
+ _a.validate = function (a, b) {
39
54
  var _a;
40
55
  return (_a = self
41
56
  .remultFactory())
42
57
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).validate(a, b);
43
58
  },
44
- addEventListener: function () {
59
+ _a.addEventListener = function () {
45
60
  var _a, _b;
46
61
  var args2 = [];
47
62
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -52,7 +67,7 @@ var RemultProxy = /** @class */ (function () {
52
67
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
53
68
  .addEventListener.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
54
69
  },
55
- count: function () {
70
+ _a.count = function () {
56
71
  var _a, _b;
57
72
  var args2 = [];
58
73
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -63,7 +78,7 @@ var RemultProxy = /** @class */ (function () {
63
78
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
64
79
  .count.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
65
80
  },
66
- create: function () {
81
+ _a.create = function () {
67
82
  var _a, _b;
68
83
  var args2 = [];
69
84
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -74,13 +89,13 @@ var RemultProxy = /** @class */ (function () {
74
89
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
75
90
  .create.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
76
91
  },
77
- delete: function (args2) {
92
+ _a.delete = function (args2) {
78
93
  var _a;
79
94
  return (_a = self
80
95
  .remultFactory())
81
96
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).delete(args2);
82
97
  },
83
- find: function () {
98
+ _a.find = function () {
84
99
  var _a, _b;
85
100
  var args2 = [];
86
101
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -91,7 +106,7 @@ var RemultProxy = /** @class */ (function () {
91
106
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
92
107
  .find.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
93
108
  },
94
- findFirst: function () {
109
+ _a.findFirst = function () {
95
110
  var _a, _b;
96
111
  var args2 = [];
97
112
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -102,26 +117,26 @@ var RemultProxy = /** @class */ (function () {
102
117
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
103
118
  .findFirst.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
104
119
  },
105
- findId: function (a, b) {
120
+ _a.findId = function (a, b) {
106
121
  var _a;
107
122
  return (_a = self
108
123
  .remultFactory())
109
124
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).findId(a, b);
110
125
  },
111
126
  //@ts-ignore
112
- toJson: function (json) {
127
+ _a.toJson = function (json) {
113
128
  var _a;
114
129
  return (_a = self
115
130
  .remultFactory())
116
131
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).toJson(json);
117
132
  },
118
- fromJson: function (item, isNew) {
133
+ _a.fromJson = function (item, isNew) {
119
134
  var _a;
120
135
  return (_a = self
121
136
  .remultFactory())
122
137
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).fromJson(item, isNew);
123
138
  },
124
- getEntityRef: function () {
139
+ _a.getEntityRef = function () {
125
140
  var _a, _b;
126
141
  var args2 = [];
127
142
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -132,13 +147,13 @@ var RemultProxy = /** @class */ (function () {
132
147
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
133
148
  .getEntityRef.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
134
149
  },
135
- insert: function (args2) {
150
+ _a.insert = function (args2) {
136
151
  var _a;
137
152
  return (_a = self
138
153
  .remultFactory())
139
154
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).insert(args2);
140
155
  },
141
- liveQuery: function () {
156
+ _a.liveQuery = function () {
142
157
  var _a, _b;
143
158
  var args2 = [];
144
159
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -149,16 +164,15 @@ var RemultProxy = /** @class */ (function () {
149
164
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
150
165
  .liveQuery.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
151
166
  },
152
- //@ts-ignore
153
- addToCache: function (a) {
154
- var _a;
155
- return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).addToCache(a);
156
- },
157
- get metadata() {
158
- var _a;
159
- return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata;
160
- },
161
- query: function () {
167
+ Object.defineProperty(_a, "metadata", {
168
+ get: function () {
169
+ var _a;
170
+ return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).metadata;
171
+ },
172
+ enumerable: false,
173
+ configurable: true
174
+ }),
175
+ _a.query = function () {
162
176
  var _a, _b;
163
177
  var args2 = [];
164
178
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -169,19 +183,19 @@ var RemultProxy = /** @class */ (function () {
169
183
  .repo.apply(_b, tslib_1.__spreadArray([], tslib_1.__read(args), false)))
170
184
  .query.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args2), false));
171
185
  },
172
- save: function (args2) {
186
+ _a.save = function (args2) {
173
187
  var _a;
174
188
  return (_a = self
175
189
  .remultFactory())
176
190
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).save(args2);
177
191
  },
178
- update: function (a, b) {
192
+ _a.update = function (a, b) {
179
193
  var _a;
180
194
  return (_a = self
181
195
  .remultFactory())
182
196
  .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false)).update(a, b);
183
197
  },
184
- };
198
+ _a);
185
199
  entityCache.set(args[1], result);
186
200
  return result;
187
201
  };
@@ -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
  }
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTarget = exports.Field = exports.Fields = void 0;
3
+ exports.checkTarget = exports.Field = exports.Relations = exports.Fields = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var cuid2_1 = require("@paralleldrive/cuid2");
6
6
  var uuid_1 = require("uuid");
7
7
  var valueConverters_1 = require("../valueConverters");
8
- var getEntityRef_1 = require("./getEntityRef");
9
8
  var RepositoryImplementation_1 = require("./RepositoryImplementation");
10
9
  var relationInfoMember_1 = require("./relationInfoMember");
11
10
  var Fields = /** @class */ (function () {
@@ -87,8 +86,9 @@ var Fields = /** @class */ (function () {
87
86
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Date; },
88
87
  {
89
88
  allowApiUpdate: false,
90
- saving: function (_, ref) {
91
- if ((0, getEntityRef_1.getEntityRef)(_).isNew())
89
+ saving: function (_, _a, ref) {
90
+ var isNew = _a.isNew;
91
+ if (isNew)
92
92
  ref.value = new Date();
93
93
  },
94
94
  }], tslib_1.__read(options), false));
@@ -101,7 +101,7 @@ var Fields = /** @class */ (function () {
101
101
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Date; },
102
102
  {
103
103
  allowApiUpdate: false,
104
- saving: function (_, ref) {
104
+ saving: function (_, _1, ref) {
105
105
  ref.value = new Date();
106
106
  },
107
107
  }], tslib_1.__read(options), false));
@@ -115,7 +115,7 @@ var Fields = /** @class */ (function () {
115
115
  {
116
116
  allowApiUpdate: false,
117
117
  defaultValue: function () { return (0, uuid_1.v4)(); },
118
- saving: function (_, r) {
118
+ saving: function (_, _1, r) {
119
119
  if (!r.value)
120
120
  r.value = (0, uuid_1.v4)();
121
121
  },
@@ -130,7 +130,7 @@ var Fields = /** @class */ (function () {
130
130
  {
131
131
  allowApiUpdate: false,
132
132
  defaultValue: function () { return (0, cuid2_1.createId)(); },
133
- saving: function (_, r) {
133
+ saving: function (_, _1, r) {
134
134
  if (!r.value)
135
135
  r.value = (0, cuid2_1.createId)();
136
136
  },
@@ -150,45 +150,45 @@ var Fields = /** @class */ (function () {
150
150
  }
151
151
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Boolean; }], tslib_1.__read(options), false));
152
152
  };
153
- //[ ] docking the move from reference to one will not be fun,since the parameter order changes
154
- Fields.reference = function (toEntityType, options) {
155
- var _a;
156
- var op = (!options
157
- ? {}
158
- : options);
159
- return Field(toEntityType, tslib_1.__assign(tslib_1.__assign({}, op), (_a = {}, _a[relationInfoMember_1.relationInfoMember] = {
160
- //field,
161
- toType: toEntityType,
162
- type: 'reference',
163
- }, _a)));
164
- };
165
- Fields.many = function (toEntityType, options) {
166
- var _a;
153
+ return Fields;
154
+ }());
155
+ exports.Fields = Fields;
156
+ var Relations = /** @class */ (function () {
157
+ function Relations() {
158
+ }
159
+ Relations.toOne = function (toEntityType, options) {
160
+ var _a, _b;
167
161
  var op = (typeof options === 'string'
168
162
  ? { field: options }
169
- : options);
170
- return Field(function () { return undefined; }, tslib_1.__assign(tslib_1.__assign({}, op), (_a = { serverExpression: function () { return undefined; } }, _a[relationInfoMember_1.relationInfoMember] = {
163
+ : !options
164
+ ? {}
165
+ : options);
166
+ if (!op.field && !op.fields && !op.findOptions)
167
+ return Field(toEntityType, tslib_1.__assign(tslib_1.__assign({}, op), (_a = {}, _a[relationInfoMember_1.relationInfoMember] = {
168
+ //field,
169
+ toType: toEntityType,
170
+ type: 'reference',
171
+ }, _a)));
172
+ return Field(function () { return undefined; }, tslib_1.__assign(tslib_1.__assign({}, op), (_b = { serverExpression: function () { return undefined; } }, _b[relationInfoMember_1.relationInfoMember] = {
171
173
  //field,
172
174
  toType: toEntityType,
173
- type: 'toMany',
174
- }, _a)));
175
+ type: 'toOne',
176
+ }, _b)));
175
177
  };
176
- Fields.one = function (entity, toEntityType, options) {
178
+ Relations.toMany = function (toEntityType, options) {
177
179
  var _a;
178
180
  var op = (typeof options === 'string'
179
181
  ? { field: options }
180
- : !options
181
- ? {}
182
- : options);
182
+ : options);
183
183
  return Field(function () { return undefined; }, tslib_1.__assign(tslib_1.__assign({}, op), (_a = { serverExpression: function () { return undefined; } }, _a[relationInfoMember_1.relationInfoMember] = {
184
184
  //field,
185
185
  toType: toEntityType,
186
- type: 'toOne',
186
+ type: 'toMany',
187
187
  }, _a)));
188
188
  };
189
- return Fields;
189
+ return Relations;
190
190
  }());
191
- exports.Fields = Fields;
191
+ exports.Relations = Relations;
192
192
  /**Decorates fields that should be used as fields.
193
193
  * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
194
194
  *
@@ -10,12 +10,14 @@ import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, E
10
10
  import type { Unsubscribe } from '../live-query/SubscriptionChannel';
11
11
  import type { columnInfo } from './columnInfo';
12
12
  import { RelationLoader } from './relation-loader';
13
+ import { getInternalKey } from './repository-internals';
13
14
  export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
14
15
  private entity;
15
16
  remult: Remult;
16
17
  private dataProvider;
17
18
  private _info;
18
19
  private defaultFindOptions?;
20
+ [getInternalKey](): this;
19
21
  createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
20
22
  relations(item: entityType): RepositoryRelations<entityType>;
21
23
  private __edp;
@@ -50,10 +52,10 @@ export declare class RepositoryImplementation<entityType> implements Repository<
50
52
  save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
51
53
  save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
52
54
  liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
53
- rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<Awaited<entityType>[]>;
55
+ rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<entityType[]>;
54
56
  find(options: FindOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType[]>;
55
57
  buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
56
- fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<Awaited<entityType>[]>;
58
+ fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<entityType[]>;
57
59
  private loadManyToOneForManyRows;
58
60
  private mapRawDataToResult;
59
61
  toJson(item: entityType | entityType[] | Promise<entityType> | Promise<entityType[]>): any;
@@ -73,10 +75,11 @@ declare abstract class rowHelperBase<T> {
73
75
  protected columnsInfo: FieldOptions[];
74
76
  protected instance: T;
75
77
  protected remult: Remult;
78
+ protected isNewRow: boolean;
76
79
  _error: string;
77
80
  get error(): string;
78
81
  set error(val: string);
79
- constructor(columnsInfo: FieldOptions[], instance: T, remult: Remult);
82
+ constructor(columnsInfo: FieldOptions[], instance: T, remult: Remult, isNewRow: boolean);
80
83
  _subscribers: SubscribableImp;
81
84
  subscribe(listener: RefSubscriber): Unsubscribe;
82
85
  _isLoading: boolean;
@@ -103,7 +106,7 @@ declare abstract class rowHelperBase<T> {
103
106
  __validateEntity(): Promise<void>;
104
107
  __performColumnAndEntityValidations(): Promise<void>;
105
108
  toApiJson(includeRelatedEntities?: boolean): any;
106
- _updateEntityBasedOnApi(body: any): Promise<void>;
109
+ _updateEntityBasedOnApi(body: any, ignoreApiAllowed?: boolean): Promise<void>;
107
110
  }
108
111
  export declare class rowHelperImplementation<T> extends rowHelperBase<T> implements EntityRef<T> {
109
112
  private info;
@@ -111,6 +114,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
111
114
  private edp;
112
115
  private _isNew;
113
116
  constructor(info: EntityFullInfo<T>, instance: T, repository: RepositoryImplementation<T>, edp: EntityDataProvider, remult: Remult, _isNew: boolean);
117
+ get relations(): RepositoryRelations<T>;
114
118
  get apiUpdateAllowed(): boolean;
115
119
  get apiDeleteAllowed(): boolean;
116
120
  get apiInsertAllowed(): boolean;
@@ -125,6 +129,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
125
129
  get fields(): FieldsRef<T>;
126
130
  private _saving;
127
131
  save(onlyTheseFieldsSentOnlyInTheCaseOfProxySaveWithPartialObject?: string[]): Promise<T>;
132
+ private buildLifeCycleEvent;
128
133
  private getIdFilter;
129
134
  delete(): Promise<void>;
130
135
  loadDataFrom(data: any, loadItems?: FieldMetadata[]): Promise<void>;
@@ -185,7 +190,7 @@ export declare class columnDefsImpl implements FieldMetadata {
185
190
  constructor(settings: FieldOptions, entityDefs: EntityFullInfo<any>, remult: Remult);
186
191
  apiUpdateAllowed(item?: any): boolean;
187
192
  displayValue(item: any): string;
188
- get includedInApi(): boolean;
193
+ includedInApi(item?: any): boolean;
189
194
  toInput(value: any, inputType?: string): string;
190
195
  fromInput(inputValue: string, inputType?: string): any;
191
196
  getDbName(): Promise<string>;
@@ -250,17 +255,6 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
250
255
  export declare function getValueList<T>(field: FieldRef<T>): T[];
251
256
  export declare function getValueList<T>(field: FieldMetadata<T>): T[];
252
257
  export declare function getValueList<T>(type: ClassType<T>): T[];
253
- export interface ClassFieldDecoratorContextStub<entityType, valueType> {
254
- readonly access: {
255
- set(object: entityType, value: valueType): void;
256
- };
257
- readonly name: string;
258
- }
259
- export interface ClassDecoratorContextStub<Class extends new (...args: any) => any = new (...args: any) => any> {
260
- readonly kind: 'class';
261
- readonly name: string | undefined;
262
- addInitializer(initializer: (this: Class) => void): void;
263
- }
264
258
  export declare const storableMember: unique symbol;
265
259
  export declare function buildOptions<entityType = any, valueType = any>(options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[], remult: Remult): FieldOptions<entityType, valueType>;
266
260
  export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;