remult 0.25.5-exp.2 → 0.25.5-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 (46) hide show
  1. package/esm/graphql.js +87 -64
  2. package/esm/index.js +1 -0
  3. package/esm/package.json +1 -1
  4. package/esm/remult-fastify.js +3 -0
  5. package/esm/remult-hapi.js +3 -0
  6. package/esm/remult-knex/index.js +22 -5
  7. package/esm/remult-next.js +8 -0
  8. package/esm/remult-nuxt.js +3 -0
  9. package/esm/remult-sveltekit.js +63 -42
  10. package/esm/server/expressBridge.js +25 -0
  11. package/esm/server/get-remult-admin-html.js +3 -0
  12. package/esm/server/remult-admin.js +92 -0
  13. package/esm/src/remult-static.js +2 -1
  14. package/esm/src/remult3/Fields.js +7 -1
  15. package/esm/src/remult3/RepositoryImplementation.js +9 -5
  16. package/esm/src/remult3/remult3.js +47 -12
  17. package/esm/src/server-action.js +16 -11
  18. package/esm/src/sort.js +1 -1
  19. package/graphql.js +154 -99
  20. package/index.d.ts +1 -0
  21. package/index.js +3 -1
  22. package/internals.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/remult-fastify.js +3 -0
  25. package/remult-hapi.js +3 -0
  26. package/remult-knex/index.js +73 -49
  27. package/remult-next.js +8 -0
  28. package/remult-nuxt.js +3 -0
  29. package/remult-sveltekit.d.ts +5 -1
  30. package/remult-sveltekit.js +85 -56
  31. package/server/expressBridge.d.ts +8 -0
  32. package/server/expressBridge.js +39 -0
  33. package/server/get-remult-admin-html.d.ts +1 -0
  34. package/server/get-remult-admin-html.js +7 -0
  35. package/server/remult-admin.d.ts +36 -0
  36. package/server/remult-admin.js +121 -0
  37. package/src/remult-static.js +2 -1
  38. package/src/remult3/Fields.d.ts +1 -0
  39. package/src/remult3/Fields.js +7 -1
  40. package/src/remult3/RepositoryImplementation.d.ts +9 -2
  41. package/src/remult3/RepositoryImplementation.js +9 -5
  42. package/src/remult3/remult3.js +47 -12
  43. package/src/remult3/repository-internals.d.ts +6 -0
  44. package/src/server-action.d.ts +2 -2
  45. package/src/server-action.js +16 -11
  46. package/src/sort.js +1 -1
@@ -0,0 +1,36 @@
1
+ import { type RelationFields } from '../src/remult3/relationInfoMember.js';
2
+ import type { ClassType } from '../classType.js';
3
+ import type { Remult } from '../src/context.js';
4
+ export interface EntityUIInfo {
5
+ key: string;
6
+ caption: string;
7
+ fields: FieldUIInfo[];
8
+ ids: Record<string, true>;
9
+ relations: EntityRelationToManyInfo[];
10
+ }
11
+ export interface EntityRelationToManyInfo extends RelationFields {
12
+ entityKey: string;
13
+ where?: any;
14
+ }
15
+ export interface FieldUIInfo {
16
+ key: string;
17
+ valFieldKey: string;
18
+ caption: string;
19
+ type: 'json' | 'string' | 'number' | 'boolean';
20
+ relationToOne?: FieldRelationToOneInfo;
21
+ }
22
+ export interface FieldRelationToOneInfo extends RelationFields {
23
+ entityKey: string;
24
+ idField: string;
25
+ captionField: string;
26
+ where?: any;
27
+ }
28
+ export interface AdminOptions extends DisplayOptions {
29
+ entities: ClassType<any>[];
30
+ remult: Remult;
31
+ }
32
+ export interface DisplayOptions {
33
+ baseUrl?: string;
34
+ }
35
+ export default function remultAdminHtml(options: AdminOptions): string;
36
+ export declare function buildEntityInfo(options: AdminOptions): EntityUIInfo[];
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildEntityInfo = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var CompoundIdField_js_1 = require("../src/CompoundIdField.js");
6
+ var relationInfoMember_js_1 = require("../src/remult3/relationInfoMember.js");
7
+ var filter_interfaces_js_1 = require("../src/filter/filter-interfaces.js");
8
+ var get_remult_admin_html_js_1 = require("./get-remult-admin-html.js");
9
+ function remultAdminHtml(options) {
10
+ var optionsFromServer = tslib_1.__assign({}, options);
11
+ //@ts-ignore
12
+ delete optionsFromServer.entities;
13
+ delete optionsFromServer.remult;
14
+ return (0, get_remult_admin_html_js_1.getHtml)().replace('<!--PLACE_HERE-->', "<script >const entities = ".concat(JSON.stringify(buildEntityInfo(options)), "\n const optionsFromServer = ").concat(JSON.stringify(optionsFromServer), "\n </script>"));
15
+ }
16
+ exports.default = remultAdminHtml;
17
+ function buildEntityInfo(options) {
18
+ var e_1, _a, e_2, _b, e_3, _c;
19
+ var _d;
20
+ var entities = [];
21
+ try {
22
+ for (var _e = tslib_1.__values(options.entities.map(function (e) { return options.remult.repo(e).metadata; })), _f = _e.next(); !_f.done; _f = _e.next()) {
23
+ var metadata = _f.value;
24
+ var fields = [];
25
+ var relations = [];
26
+ var ids = {};
27
+ if (metadata.idMetadata.field instanceof CompoundIdField_js_1.CompoundIdField) {
28
+ try {
29
+ for (var _g = (e_2 = void 0, tslib_1.__values(metadata.idMetadata.field.fields)), _h = _g.next(); !_h.done; _h = _g.next()) {
30
+ var field = _h.value;
31
+ ids[field.key] = true;
32
+ }
33
+ }
34
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
35
+ finally {
36
+ try {
37
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
38
+ }
39
+ finally { if (e_2) throw e_2.error; }
40
+ }
41
+ }
42
+ else
43
+ ids[metadata.idMetadata.field.key] = true;
44
+ var _loop_1 = function (x) {
45
+ if (!x.includedInApi(undefined))
46
+ return "continue";
47
+ var relation = void 0;
48
+ var valFieldKey = x.key;
49
+ var info = (0, relationInfoMember_js_1.getRelationFieldInfo)(x);
50
+ if (info) {
51
+ var relInfo = info.getFields();
52
+ var relRepo = options.remult.repo(info.toEntity);
53
+ var where = typeof info.options.findOptions === 'object' &&
54
+ info.options.findOptions.where
55
+ ? filter_interfaces_js_1.Filter.entityFilterToJson(relRepo.metadata, info.options.findOptions.where)
56
+ : undefined;
57
+ var idField_1 = relRepo.metadata.idMetadata.field.key;
58
+ if (info.type === 'reference' || info.type === 'toOne') {
59
+ if (info.type == 'toOne') {
60
+ for (var key in relInfo.fields) {
61
+ if (Object.prototype.hasOwnProperty.call(relInfo.fields, key)) {
62
+ var element = relInfo.fields[key];
63
+ valFieldKey = element;
64
+ }
65
+ }
66
+ }
67
+ relation = tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key, idField: idField_1, captionField: (_d = relRepo.metadata.fields
68
+ .toArray()
69
+ .find(function (x) { return x.key != idField_1 && x.valueType == String; })) === null || _d === void 0 ? void 0 : _d.key });
70
+ }
71
+ else if (info.type === 'toMany') {
72
+ relations.push(tslib_1.__assign(tslib_1.__assign({}, relInfo), { where: where, entityKey: relRepo.metadata.key }));
73
+ return "continue";
74
+ }
75
+ }
76
+ fields.push({
77
+ key: x.key,
78
+ valFieldKey: valFieldKey,
79
+ caption: x.caption,
80
+ relationToOne: relation,
81
+ type: x.valueConverter.fieldTypeInDb == 'json'
82
+ ? 'json'
83
+ : x.valueType === Number
84
+ ? 'number'
85
+ : x.valueType === Boolean
86
+ ? 'boolean'
87
+ : 'string',
88
+ });
89
+ };
90
+ try {
91
+ for (var _j = (e_3 = void 0, tslib_1.__values(metadata.fields.toArray())), _k = _j.next(); !_k.done; _k = _j.next()) {
92
+ var x = _k.value;
93
+ _loop_1(x);
94
+ }
95
+ }
96
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
97
+ finally {
98
+ try {
99
+ if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
100
+ }
101
+ finally { if (e_3) throw e_3.error; }
102
+ }
103
+ entities.push({
104
+ key: metadata.key,
105
+ caption: metadata.caption,
106
+ ids: ids,
107
+ fields: fields,
108
+ relations: relations,
109
+ });
110
+ }
111
+ }
112
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
113
+ finally {
114
+ try {
115
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
116
+ }
117
+ finally { if (e_1) throw e_1.error; }
118
+ }
119
+ return entities;
120
+ }
121
+ exports.buildEntityInfo = buildEntityInfo;
@@ -22,7 +22,8 @@ var x = {
22
22
  },
23
23
  captionTransformer: undefined,
24
24
  };
25
- if (process.env['IGNORE_GLOBAL_REMULT_IN_TESTS'] ||
25
+ if ((typeof process !== 'undefined' &&
26
+ process.env['IGNORE_GLOBAL_REMULT_IN_TESTS']) ||
26
27
  typeof globalThis[remultStaticKey] === 'undefined') {
27
28
  globalThis[remultStaticKey] = x;
28
29
  }
@@ -129,5 +129,6 @@ export declare class Relations {
129
129
  export declare function Field<entityType = any, valueType = any>(valueType: (() => valueType extends number ? Number : valueType extends string ? String : valueType extends boolean ? Boolean : 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;
130
130
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
131
131
  maxLength?: number;
132
+ minLength?: number;
132
133
  }
133
134
  export declare function checkTarget(target: any): void;
@@ -254,6 +254,9 @@ function Field(valueType) {
254
254
  if (r.maxLength) {
255
255
  r.validate = addValidator(r.validate, validators_js_1.Validators.maxLength(r.maxLength));
256
256
  }
257
+ if (r.minLength) {
258
+ r.validate = addValidator(r.validate, validators_js_1.Validators.minLength(r.minLength));
259
+ }
257
260
  if (!r.valueType && valueType) {
258
261
  r.valueType = valueType();
259
262
  }
@@ -264,7 +267,10 @@ function Field(valueType) {
264
267
  r.dbName = r.key;
265
268
  var type = r.valueType;
266
269
  if (!type) {
267
- type = Reflect.getMetadata('design:type', target, key);
270
+ type =
271
+ typeof Reflect.getMetadata == 'function'
272
+ ? Reflect.getMetadata('design:type', target, key)
273
+ : [];
268
274
  r.valueType = type;
269
275
  }
270
276
  if (!r.target)
@@ -3,14 +3,15 @@ import { LookupColumn } from '../column.js';
3
3
  import type { FieldMetadata, FieldOptions, ValueConverter, ValueListItem } from '../column-interfaces.js';
4
4
  import { Remult } from '../context.js';
5
5
  import type { EntityOptions } from '../entity.js';
6
+ import { Filter } from '../filter/filter-interfaces.js';
6
7
  import type { ControllerRef, ControllerRefForControllerBase, EntityFilter, EntityMetadata, EntityOrderBy, EntityRef, EntityRefForEntityBase, FieldRef, FieldsMetadata, FieldsRef, FieldsRefForEntityBase, FindFirstOptions, FindFirstOptionsBase, FindOptions, IdMetadata, LiveQuery, LoadOptions, MembersOnly, QueryOptions, QueryResult, Repository, RepositoryRelations, Subscribable } from './remult3.js';
7
8
  import type { RefSubscriber } from './remult3.js';
8
9
  import type { entityEventListener } from '../__EntityValueProvider.js';
9
10
  import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo } from '../data-interfaces.js';
10
11
  import type { Unsubscribe } from '../live-query/SubscriptionChannel.js';
11
12
  import { RelationLoader } from './relation-loader.js';
12
- import { getInternalKey } from './repository-internals.js';
13
- export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
13
+ import { type RepositoryInternal, getInternalKey } from './repository-internals.js';
14
+ export declare class RepositoryImplementation<entityType> implements Repository<entityType>, RepositoryInternal<entityType> {
14
15
  private entity;
15
16
  remult: Remult;
16
17
  private dataProvider;
@@ -19,6 +20,11 @@ export declare class RepositoryImplementation<entityType> implements Repository<
19
20
  [getInternalKey](): this;
20
21
  createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
21
22
  relations(item: entityType): RepositoryRelations<entityType>;
23
+ getFocusedRelationRepo(field: FieldMetadata, item: entityType): {
24
+ toRepo: RepositoryImplementation<any>;
25
+ returnNull: boolean;
26
+ returnUndefined: boolean;
27
+ };
22
28
  private __edp;
23
29
  private get edp();
24
30
  constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider, _info: EntityFullInfo<entityType>, defaultFindOptions?: FindOptions<entityType>);
@@ -67,6 +73,7 @@ export declare class RepositoryImplementation<entityType> implements Repository<
67
73
  create(item?: Partial<MembersOnly<entityType>>): entityType;
68
74
  fixTypes(item: any): Promise<any>;
69
75
  findId(id: any, options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
76
+ translateWhereToFilter(where: EntityFilter<entityType>): Promise<Filter>;
70
77
  }
71
78
  export type EntityOptionsFactory = (remult: Remult) => EntityOptions;
72
79
  export declare function createOldEntity<T>(entity: ClassType<T>, remult: Remult): EntityFullInfo<T>;
@@ -127,9 +127,7 @@ var RepositoryImplementation = /** @class */ (function () {
127
127
  var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
128
128
  if (!rel)
129
129
  throw Error(key + ' is not a relation');
130
- var repo = rel.toRepo;
131
- var _a = _this.findOptionsBasedOnRelation(rel, field, undefined, item, repo), findOptions = _a.findOptions, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
132
- var toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
130
+ var _a = _this.getFocusedRelationRepo(field, item), toRepo = _a.toRepo, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
133
131
  if (rel.type === 'toMany')
134
132
  return toRepo;
135
133
  else
@@ -145,6 +143,13 @@ var RepositoryImplementation = /** @class */ (function () {
145
143
  },
146
144
  });
147
145
  };
146
+ RepositoryImplementation.prototype.getFocusedRelationRepo = function (field, item) {
147
+ var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
148
+ var repo = rel.toRepo;
149
+ var _a = this.findOptionsBasedOnRelation(rel, field, undefined, item, repo), findOptions = _a.findOptions, returnNull = _a.returnNull, returnUndefined = _a.returnUndefined;
150
+ var toRepo = new RepositoryImplementation(repo.entity, repo.remult, repo.dataProvider, repo._info, findOptions);
151
+ return { toRepo: toRepo, returnNull: returnNull, returnUndefined: returnUndefined };
152
+ };
148
153
  Object.defineProperty(RepositoryImplementation.prototype, "edp", {
149
154
  get: function () {
150
155
  return this.__edp
@@ -1133,7 +1138,6 @@ var RepositoryImplementation = /** @class */ (function () {
1133
1138
  throw new Error('id can be either number or string, but got: ' + typeof id);
1134
1139
  return this.findFirst({}, tslib_1.__assign(tslib_1.__assign({}, options), { where: this.metadata.idMetadata.getIdFilter(id) }), true);
1135
1140
  };
1136
- /* @internal*/
1137
1141
  RepositoryImplementation.prototype.translateWhereToFilter = function (where) {
1138
1142
  var _a, _b;
1139
1143
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -2929,7 +2933,7 @@ var EntityFullInfo = /** @class */ (function () {
2929
2933
  else
2930
2934
  this.idMetadata.field = r_2;
2931
2935
  }
2932
- else {
2936
+ if (!this.idMetadata.field) {
2933
2937
  if (this.fields['id'])
2934
2938
  this.idMetadata.field = this.fields['id'];
2935
2939
  else
@@ -1,30 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*y1 - workshop
4
+
5
+ * Experiment with doing this with version control - so the students can follow changes
6
+ * Prepare stackblitz
7
+
8
+
9
+ # influencer:
10
+ * review react summit
11
+ #
12
+
13
+ //y1 - admin url!
3
14
  //y1 - number default storage in knex is decimal and it by default has 8,2 - meaning only 999,999 - I think it should be way bigger than that. in firefly we do at least 18 - https://discord.com/channels/975754286384418847/1195162533447876658
15
+ //y1 - talk about the parameter issue with backend methods
4
16
  //y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
17
+ //y1 - I think that the tests you've setup cover next app router - I added to the setup, but not sure where else
18
+ //y1 - select data provider per entity https://discord.com/channels/975754286384418847/976006081748807690/1201415305885397003
19
+
20
+
21
+ //p1 - Small thing, I get SvelteKitError: Not found: /vite.svg
22
+ //p1 - understand the to many relation for the admin, based on the to one
23
+ //p1 - relation from order details to order gave a compound id info - and it is not true - same for the relation to product
24
+ //p1 - live query with include
25
+ //p1 - new row when there are relations, looks funny (see product)
26
+ //p1 - the + row in the bottom should extend to the full width
27
+ //p1 - adjust angular tutorial starter kit for latest angular (as is in tutorial)
28
+
29
+ /*y2 -
30
+ @Fields.string<Category>({
31
+ allowApiUpdate: (c) => getEntityRef(c).isNew(),
32
+ })
33
+ Description = ""*/
5
34
  //y2 - from the crm-demo(https://crm-demo.up.railway.app/deals), after editing a deal: - _updateEntityBasedOnApi
6
35
  //y2 - Backend methods are transactions, it's not intuitive and maybe should be optional / opt in
7
36
  //y2 - how to run a transaction as a user
8
- //p1 - enum column
9
- //p1 - I think there should be a way to throw a forbidden exception
10
- //p1 - Write some ctrl g
37
+ //p2 - enum column
38
+ //p2 - I think there should be a way to throw a forbidden exception
11
39
  //y2 - get backend methods to work when specifying types for date, and entities as poco's
12
40
  //y2 - required
13
41
  //y2 - reconsider validators
14
42
  //y2 - message for invalid value
15
43
  //y2 - message for relation that is missing
16
- //p1 - more column types
44
+ //p2 - more column types
17
45
  //p2 - processError in remult express
18
46
  //p2 - allow find options preprocessor for api calls, to use for authorization
19
- //p1 - write doc about controlling updates of rows...
47
+ //p2 - write doc about controlling updates of rows...
20
48
  //p1 - need a way to extract the fields from the relation - for generating relation based sql
21
49
  //p1 - when doing this, work on graphql relation with fields not just field
22
- //p1 - add docs for apply changes
23
- //p1 - when subscribe is forbidden - the query still runs after the renew process
24
- //p1 - 'update tasks set where id = $1
50
+ //p2 - add docs for apply changes
51
+ //p2 - when subscribe is forbidden - the query still runs after the renew process
52
+ //p2 - 'update tasks set where id = $1
25
53
  //y2 - consider multi tenancies
26
54
  //y2 - allow api read to also support instance and filter. - problem with promise
27
- //p1 - doc this:
55
+ //p2 - doc this:
28
56
  /**
29
57
  * //p2 - doc this
30
58
  remult.apiClient.httpClient = (
@@ -47,12 +75,12 @@ remult.apiClient.url='localhost:3007/api
47
75
  */
48
76
  //p1 - remult-admin doesn't handle primary key that has compound column
49
77
  //p1 - remult-admin didn't show a update for a table with a uniqua that is numeric
50
- //p1 - crm demo graphql error
51
- //p1 - fix multiple instances of remult: the defaultRemult and async local hook - and columnsOfType - all can be tests with a vite project loading `remult-admin`
52
78
  //p1 -check if checouknt doesn't respect allow read (I think)
79
+ //p1 - when a tasks table exists in a different schema - we get many errors
53
80
  //p1 - allow api update only for new rows
54
81
  //p1 - getFields didn't work for kobi in the home component
55
- //p1 - https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
82
+ //p1 - add to docs https://codesandbox.io/p/devbox/demo-sql-expression-wqvj4g
83
+ //y1 - talk about export api is not possible in +server - how did we face that in others, and how do we doc it
56
84
  //p2 - document validators
57
85
  //p2 - and validators to reference
58
86
  //y2 - discuss a default date formatter
@@ -82,3 +110,10 @@ remult.apiClient.url='localhost:3007/api
82
110
  //y2 - should enforce integer - currently we probably round / truncate it
83
111
  //p1 - adjust react tutorial to esm
84
112
  //p1 - write docs on with remult - and usage in init api
113
+ /*y1 - discuss sql stuff:
114
+ https://discord.com/channels/975754286384418847/975754286384418852/1198997156678357043
115
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-f94p6m?file=%2Fsrc%2Findex.ts%3A21%2C3-21%2C12&workspaceId=c0f7eccf-c151-423b-ac8e-0f0f3e1ad350
116
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-c2jhyc?file=%2Fsrc%2Findex.ts%3A37%2C50&workspaceId=7e9d0505-ea79-46f1-8973-50cadde4fa96
117
+
118
+
119
+ */
@@ -1,3 +1,4 @@
1
+ import type { FieldMetadata } from '../column-interfaces.js';
1
2
  import type { EntityDataProviderFindOptions } from '../data-interfaces.js';
2
3
  import type { Filter } from '../filter/filter-interfaces.js';
3
4
  import type { EntityFilter, EntityOrderBy, FindOptions, LoadOptions, Repository } from './remult3.js';
@@ -9,6 +10,11 @@ export interface RepositoryInternal<entityType> {
9
10
  getCachedById(id: any, doNotLoadIfNotFound: boolean): entityType;
10
11
  getCachedByIdAsync(id: any, doNotLoadIfNotFound: boolean): Promise<entityType>;
11
12
  addToCache(item: entityType): any;
13
+ getFocusedRelationRepo(field: FieldMetadata, item: any): {
14
+ toRepo: Repository<any>;
15
+ returnNull: boolean;
16
+ returnUndefined: boolean;
17
+ };
12
18
  }
13
19
  export declare function getRepositoryInternals<entityType>(repo: Repository<entityType>): RepositoryInternal<entityType>;
14
20
  export declare const getInternalKey: unique symbol;
@@ -28,7 +28,7 @@ export declare class myServerAction extends Action<inArgs, result> {
28
28
  private types;
29
29
  private options;
30
30
  originalMethod: (args: any[]) => any;
31
- constructor(name: string, types: any[], options: BackendMethodOptions<any>, originalMethod: (args: any[]) => any);
31
+ constructor(name: string, types: () => any[], options: BackendMethodOptions<any>, originalMethod: (args: any[]) => any);
32
32
  protected execute(info: inArgs, remult: Remult, res: DataApiResponse): Promise<result>;
33
33
  }
34
34
  export interface BackendMethodOptions<type> {
@@ -43,7 +43,7 @@ export interface BackendMethodOptions<type> {
43
43
  queue?: boolean;
44
44
  /** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
45
45
  blockUser?: boolean;
46
- paramTypes?: any[];
46
+ paramTypes?: any[] | (() => any[]);
47
47
  }
48
48
  export declare function Controller(key: string): (target: any, context?: any) => any;
49
49
  export interface ClassMethodDecoratorContextStub<This = unknown, Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any> {
@@ -145,7 +145,7 @@ var myServerAction = /** @class */ (function (_super) {
145
145
  if (!remult.isAllowedForInstance(undefined, this.options.allowed))
146
146
  throw new ForbiddenError();
147
147
  _a = info;
148
- return [4 /*yield*/, prepareReceivedArgs(this.types, info.args, remult, ds, res)];
148
+ return [4 /*yield*/, prepareReceivedArgs(this.types(), info.args, remult, ds, res)];
149
149
  case 1:
150
150
  _a.args = _c.sent();
151
151
  _c.label = 2;
@@ -191,18 +191,26 @@ function BackendMethod(options) {
191
191
  var originalMethod = descriptor ? descriptor.value : target;
192
192
  var result = originalMethod;
193
193
  (0, Fields_js_1.checkTarget)(target);
194
- if (target.prototype !== undefined) {
195
- var types = Reflect.getMetadata('design:paramtypes', target, key);
194
+ function getTypes() {
195
+ var types = typeof Reflect.getMetadata == 'function'
196
+ ? Reflect.getMetadata('design:paramtypes', target, key)
197
+ : [];
196
198
  if (options.paramTypes)
197
- types = options.paramTypes;
199
+ types =
200
+ typeof options.paramTypes === 'function'
201
+ ? options.paramTypes()
202
+ : options.paramTypes;
203
+ return types;
204
+ }
205
+ if (target.prototype !== undefined) {
198
206
  // if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
199
- var serverAction_1 = new myServerAction(((options === null || options === void 0 ? void 0 : options.apiPrefix) ? options.apiPrefix + '/' : '') + key, types, options, function (args) { return originalMethod.apply(undefined, args); });
207
+ var serverAction_1 = new myServerAction(((options === null || options === void 0 ? void 0 : options.apiPrefix) ? options.apiPrefix + '/' : '') + key, function () { return getTypes(); }, options, function (args) { return originalMethod.apply(undefined, args); });
200
208
  serverAction_1.doWork = function (args, self, url, http) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
201
209
  var _this = this;
202
210
  return tslib_1.__generator(this, function (_a) {
203
211
  switch (_a.label) {
204
212
  case 0:
205
- args = prepareArgsToSend(types, args);
213
+ args = prepareArgsToSend(getTypes(), args);
206
214
  if (!(options.blockUser === false)) return [3 /*break*/, 2];
207
215
  return [4 /*yield*/, remult_static_js_1.remultStatic.actionInfo.runActionWithoutBlockingUI(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
208
216
  switch (_a.label) {
@@ -243,9 +251,6 @@ function BackendMethod(options) {
243
251
  else
244
252
  return result;
245
253
  }
246
- var types = Reflect.getMetadata('design:paramtypes', target, key);
247
- if (options.paramTypes)
248
- types = options.paramTypes;
249
254
  var x = remult_static_js_1.remultStatic.classHelpers.get(target.constructor);
250
255
  if (!x) {
251
256
  x = new context_js_1.ClassHelper();
@@ -283,7 +288,7 @@ function BackendMethod(options) {
283
288
  switch (_e.label) {
284
289
  case 0:
285
290
  _a = d;
286
- return [4 /*yield*/, prepareReceivedArgs(types, d.args, remult_1, remult_1.dataProvider, res)];
291
+ return [4 /*yield*/, prepareReceivedArgs(getTypes(), d.args, remult_1, remult_1.dataProvider, res)];
287
292
  case 1:
288
293
  _a.args = _e.sent();
289
294
  if (!remult_static_js_1.remultStatic.allEntities.includes(constructor)) return [3 /*break*/, 13];
@@ -404,7 +409,7 @@ function BackendMethod(options) {
404
409
  return tslib_1.__generator(this, function (_h) {
405
410
  switch (_h.label) {
406
411
  case 0:
407
- args = prepareArgsToSend(types, args);
412
+ args = prepareArgsToSend(getTypes(), args);
408
413
  if (!remult_static_js_1.remultStatic.allEntities.includes(target.constructor)) return [3 /*break*/, 8];
409
414
  defs = (0, getEntityRef_js_1.getEntityRef)(self);
410
415
  return [4 /*yield*/, defs.__validateEntity()];
package/src/sort.js CHANGED
@@ -92,8 +92,8 @@ var Sort = /** @class */ (function () {
92
92
  };
93
93
  if (field) {
94
94
  var rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(field);
95
- var op = field.options; //p1 - fix
96
95
  if ((rel === null || rel === void 0 ? void 0 : rel.type) === 'toOne') {
96
+ var op = rel.options;
97
97
  if (typeof op.field === 'string') {
98
98
  addSegment(entityDefs.fields.find(op.field));
99
99
  }