remult 0.25.5-exp.4 → 0.25.5-exp.6

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.
@@ -1,5 +1,4 @@
1
1
  export {};
2
- //y1 - another toOne scenario - for a one to one relation, where the other table has my id in one of its fields.
3
2
  //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
4
3
  //y1 - talk about the parameter issue with backend methods
5
4
  //y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
@@ -80,3 +79,10 @@ remult.apiClient.url='localhost:3007/api
80
79
  //y2 - should enforce integer - currently we probably round / truncate it
81
80
  //p1 - adjust react tutorial to esm
82
81
  //p1 - write docs on with remult - and usage in init api
82
+ /*y1 - discuss sql stuff:
83
+ https://discord.com/channels/975754286384418847/975754286384418852/1198997156678357043
84
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-f94p6m?file=%2Fsrc%2Findex.ts%3A21%2C3-21%2C12&workspaceId=c0f7eccf-c151-423b-ac8e-0f0f3e1ad350
85
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-c2jhyc?file=%2Fsrc%2Findex.ts%3A37%2C50&workspaceId=7e9d0505-ea79-46f1-8973-50cadde4fa96
86
+
87
+
88
+ */
@@ -92,7 +92,7 @@ export class myServerAction extends Action {
92
92
  await doTransaction(remult, async () => {
93
93
  if (!remult.isAllowedForInstance(undefined, this.options.allowed))
94
94
  throw new ForbiddenError();
95
- info.args = await prepareReceivedArgs(this.types, info.args, remult, ds, res);
95
+ info.args = await prepareReceivedArgs(this.types(), info.args, remult, ds, res);
96
96
  try {
97
97
  result.data = await this.originalMethod(info.args);
98
98
  }
@@ -119,14 +119,20 @@ export function BackendMethod(options) {
119
119
  const originalMethod = descriptor ? descriptor.value : target;
120
120
  let result = originalMethod;
121
121
  checkTarget(target);
122
- if (target.prototype !== undefined) {
122
+ function getTypes() {
123
123
  var types = Reflect.getMetadata('design:paramtypes', target, key);
124
124
  if (options.paramTypes)
125
- types = options.paramTypes;
125
+ types =
126
+ typeof options.paramTypes === 'function'
127
+ ? options.paramTypes()
128
+ : options.paramTypes;
129
+ return types;
130
+ }
131
+ if (target.prototype !== undefined) {
126
132
  // if types are undefined - you've forgot to set: "emitDecoratorMetadata":true
127
- let serverAction = new myServerAction((options?.apiPrefix ? options.apiPrefix + '/' : '') + key, types, options, (args) => originalMethod.apply(undefined, args));
133
+ let serverAction = new myServerAction((options?.apiPrefix ? options.apiPrefix + '/' : '') + key, () => getTypes(), options, (args) => originalMethod.apply(undefined, args));
128
134
  serverAction.doWork = async (args, self, url, http) => {
129
- args = prepareArgsToSend(types, args);
135
+ args = prepareArgsToSend(getTypes(), args);
130
136
  if (options.blockUser === false) {
131
137
  return await remultStatic.actionInfo.runActionWithoutBlockingUI(async () => (await serverAction.run({ args }, url, http)).data);
132
138
  }
@@ -149,9 +155,6 @@ export function BackendMethod(options) {
149
155
  else
150
156
  return result;
151
157
  }
152
- var types = Reflect.getMetadata('design:paramtypes', target, key);
153
- if (options.paramTypes)
154
- types = options.paramTypes;
155
158
  let x = remultStatic.classHelpers.get(target.constructor);
156
159
  if (!x) {
157
160
  x = new ClassHelper();
@@ -175,7 +178,7 @@ export function BackendMethod(options) {
175
178
  let remult = req;
176
179
  let r;
177
180
  await doTransaction(remult, async () => {
178
- d.args = await prepareReceivedArgs(types, d.args, remult, remult.dataProvider, res);
181
+ d.args = await prepareReceivedArgs(getTypes(), d.args, remult, remult.dataProvider, res);
179
182
  if (remultStatic.allEntities.includes(constructor)) {
180
183
  let repo = remult.repo(constructor);
181
184
  let y;
@@ -246,7 +249,7 @@ export function BackendMethod(options) {
246
249
  }
247
250
  },
248
251
  doWork: async function (args, self, baseUrl, http) {
249
- args = prepareArgsToSend(types, args);
252
+ args = prepareArgsToSend(getTypes(), args);
250
253
  if (remultStatic.allEntities.includes(target.constructor)) {
251
254
  let defs = getEntityRef(self);
252
255
  await defs.__validateEntity();
package/internals.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { getRelationInfo, getRelationFieldInfo, RelationFieldInfo, RelationInfo, } from './src/remult3/relationInfoMember.js';
1
+ export { getRelationInfo, getRelationFieldInfo, RelationFieldInfo, RelationInfo, RelationFields, } from './src/remult3/relationInfoMember.js';
2
2
  export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation.js';
3
3
  export { getEntitySettings } from './src/remult3/getEntityRef.js';
4
4
  export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.25.5-exp.4",
3
+ "version": "0.25.5-exp.6",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //y1 - another toOne scenario - for a one to one relation, where the other table has my id in one of its fields.
4
3
  //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
5
4
  //y1 - talk about the parameter issue with backend methods
6
5
  //y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
@@ -81,3 +80,10 @@ remult.apiClient.url='localhost:3007/api
81
80
  //y2 - should enforce integer - currently we probably round / truncate it
82
81
  //p1 - adjust react tutorial to esm
83
82
  //p1 - write docs on with remult - and usage in init api
83
+ /*y1 - discuss sql stuff:
84
+ https://discord.com/channels/975754286384418847/975754286384418852/1198997156678357043
85
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-f94p6m?file=%2Fsrc%2Findex.ts%3A21%2C3-21%2C12&workspaceId=c0f7eccf-c151-423b-ac8e-0f0f3e1ad350
86
+ https://codesandbox.io/p/devbox/demo-sql-expression-forked-c2jhyc?file=%2Fsrc%2Findex.ts%3A37%2C50&workspaceId=7e9d0505-ea79-46f1-8973-50cadde4fa96
87
+
88
+
89
+ */
@@ -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,24 @@ 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) {
194
+ function getTypes() {
195
195
  var types = Reflect.getMetadata('design:paramtypes', target, key);
196
196
  if (options.paramTypes)
197
- types = options.paramTypes;
197
+ types =
198
+ typeof options.paramTypes === 'function'
199
+ ? options.paramTypes()
200
+ : options.paramTypes;
201
+ return types;
202
+ }
203
+ if (target.prototype !== undefined) {
198
204
  // 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); });
205
+ 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
206
  serverAction_1.doWork = function (args, self, url, http) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
201
207
  var _this = this;
202
208
  return tslib_1.__generator(this, function (_a) {
203
209
  switch (_a.label) {
204
210
  case 0:
205
- args = prepareArgsToSend(types, args);
211
+ args = prepareArgsToSend(getTypes(), args);
206
212
  if (!(options.blockUser === false)) return [3 /*break*/, 2];
207
213
  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
214
  switch (_a.label) {
@@ -243,9 +249,6 @@ function BackendMethod(options) {
243
249
  else
244
250
  return result;
245
251
  }
246
- var types = Reflect.getMetadata('design:paramtypes', target, key);
247
- if (options.paramTypes)
248
- types = options.paramTypes;
249
252
  var x = remult_static_js_1.remultStatic.classHelpers.get(target.constructor);
250
253
  if (!x) {
251
254
  x = new context_js_1.ClassHelper();
@@ -283,7 +286,7 @@ function BackendMethod(options) {
283
286
  switch (_e.label) {
284
287
  case 0:
285
288
  _a = d;
286
- return [4 /*yield*/, prepareReceivedArgs(types, d.args, remult_1, remult_1.dataProvider, res)];
289
+ return [4 /*yield*/, prepareReceivedArgs(getTypes(), d.args, remult_1, remult_1.dataProvider, res)];
287
290
  case 1:
288
291
  _a.args = _e.sent();
289
292
  if (!remult_static_js_1.remultStatic.allEntities.includes(constructor)) return [3 /*break*/, 13];
@@ -404,7 +407,7 @@ function BackendMethod(options) {
404
407
  return tslib_1.__generator(this, function (_h) {
405
408
  switch (_h.label) {
406
409
  case 0:
407
- args = prepareArgsToSend(types, args);
410
+ args = prepareArgsToSend(getTypes(), args);
408
411
  if (!remult_static_js_1.remultStatic.allEntities.includes(target.constructor)) return [3 /*break*/, 8];
409
412
  defs = (0, getEntityRef_js_1.getEntityRef)(self);
410
413
  return [4 /*yield*/, defs.__validateEntity()];