remult 0.27.5-next.1 → 0.27.7

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,51 +1,37 @@
1
1
  export const flags = {
2
2
  error500RetryCount: 4,
3
3
  };
4
- //y1 - Hacker News for the tutorial?
4
+ //p1 - add transactional option to backend method
5
+ //p1 - add parameter all to deleteMany, and updateMany
6
+ //p1 filter.apply ApiPreFilter
7
+ //p1 - min, max, avg, sum, countDistinct - noam come up with an api
8
+ /*p1 - add id and use uuid by default, but allow changes with Fields.id.defaultIdProvider NO but defaultProvider yes???
9
+ //p1 - replace uuid with crypto.randomUUID and allow custom fallback NO
10
+ //p1 - Add example for luid
11
+ //p1 - add example for nanoid
12
+ //p1 - explain the benefits of changing the default provider for testing in docs.
13
+ */
14
+ //p1 - consider upsert (where,set)
15
+ //p1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
16
+ //p2 - add some kind of options handler that will help with translation etc... like in hagai - something that runs at the stage where options are being built
5
17
  /*y1 - https://github.com/remult/remult/discussions/438
6
18
  - https://github.com/remult/remult/blob/query-argumets/projects/tests/dbs/test-sql-database.spec.ts#L100-L128
7
- //p2 - allow preprocess to replace filter values - for example replace $contains on a specific field, with specific other sql - useful for full text search and other scenarios
8
19
  //y1 - consider sql expression gets a dbnames of it's own (that already has the "tableName" defined correctly) maybe also the filter translator
20
+ //p2 - allow preprocess to replace filter values - for example replace $contains on a specific field, with specific other sql - useful for full text search and other scenarios
9
21
  //y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
10
22
  */
11
- //y1 - add parameter all to deleteMany, and updateMany
12
- //p1 - fix query docs to also explain how it can be used for infinite scroll and pagination.
13
- //p1 - when like doesn't have a string - don't send it to the db
14
- //y1 - 'test expression columns without aliases'
15
- //y1 - live query update waits for last
16
- //p1 - add luid - it's cool for order by. - NO
17
- //p1 - replace uuid with crypto.randomUUID and allow custom fallback NO
18
- //p1 - add nanoid - NO
19
- //p1 - add id and use luid by default, but allow changes with Fields.id.defaultIdProvider NO but defaultProvider yes
20
- /*p1
21
- * field, fieldType ,ValueListFieldType, - return optional parameter for decorators
22
- * options to remultExpress tc... should be mandatory
23
- * return value converter to previous typing
24
- * add breaking change notification about findOne and findFirst and findId
25
- */
26
- //p1 - fix query docs to also explain how it can be used for infinite scroll and pagination.
27
- //y1 - 'test expression columns without aliases'
28
- //y1 - ts issue with fields - when a field is optional, it's $ is also optional and thats a problem
23
+ //p2 - fix query docs to also explain how it can be used for infinite scroll and pagination.
24
+ //p2 - when like doesn't have a string - don't send it to the db
29
25
  //p1 - vite 5.3 supports ts5 decorators - check and adapt.
30
- //p1 - see if I can fix the no alias problem in selects
31
- //p1 - add luid - it's cool for order by.
32
- //p1 - replace uuid with crypto.randomUUID and allow custom fallback
33
- //p1 - add nanoid
34
- //p1 - add id and use luid by default, but allow changes with Fields.id.defaultIdProvider
35
- //p1 - explain the benefits of changing the default provider for testing in docs.
26
+ //p1 - tutorial about controller - and mutable controller
27
+ //p1 - docs abount subscription channel
28
+ //p1 - Consider enforcing serial operations on JSON database to prevent data loss
36
29
  //p1 - fix sqlite to support alter table when adding a column with ensure schema = on
37
- //p1 - fix app custom filters example for multiple filters.
38
- //p1 - add not!!!!
39
30
  //p1 - add LifecycleEvent to documentation
40
- //p1 - Fix hagai and starter project to latest ts
41
31
  //p1 - fix chaining of saving and saved in multiple entity options args
42
32
  //p1 - review starter and examples and separate remult * auth from the routes
43
- //p1 - min, max, avg, sum
44
- //p1 - consider upsert (where,set)
45
33
  //y1 - live query with count #436
46
34
  //y1 TODO - In the esm version of our tutorial - the imports are automatically .ts and not .js in react and not in vue
47
- //y1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
48
- //y1 TODO - readonly key: keyof MembersOnly<entityType> & string
49
35
  //y1 TODO - fix remult admin not to load the html into memory until used
50
36
  //y2 - talk about insert / update / delete with relations
51
37
  /*
@@ -63,15 +49,10 @@ const result = await repo.batch(x=>({
63
49
  }))
64
50
  */
65
51
  //y1 - wait a second to close stream -see pr
66
- //p1 - Consider enforcing serial operations on JSON database to prevent data loss
67
52
  //p1 - prepare the createEntity discussion
68
- //p1 - return error on connection error
69
53
  //p1 - article on displayValue including it's definition for entities that is used in relations
70
54
  //p1 - article auth.js with express - played with it, requires type="module" and a few more configurations - https://github.com/noam-honig/express-auth
71
- //y2 - currently for string fields we default for 255 in knex (which is their default) why not just use text (varchar max) - and only use exact length when one is provided?
72
55
  //p2 - create foreign key constraints in user code - https://codesandbox.io/p/devbox/fk-validator-tdshcs
73
- //p2 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
74
- //y2 - fix validators cache
75
56
  //y2 - should we validate relations
76
57
  //y1 - dependency of live query tables live query refresh of view on table update
77
58
  //p1 - see why mongo tests do not run anymore
@@ -91,7 +72,6 @@ const result = await repo.batch(x=>({
91
72
  - delete restrict (implicit, or user selected - and if so, how) (delete & update of id)
92
73
 
93
74
  */
94
- //y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
95
75
  //y1 - talk about the parameter issue with backend methods
96
76
  //y2 - livequery for findfirst (@JY)
97
77
  /*y2 -
@@ -108,7 +88,6 @@ const result = await repo.batch(x=>({
108
88
  //y2 - Fix problem with promise all in sql expression recurssion - when using PromiseAll in row relation loading, some sql expressions appear is recursion call even if they are not
109
89
  //p2 - when subscribe is forbidden - the query still runs after the renew process
110
90
  //p2 - 'update tasks set where id = $1
111
- //p2 - type metadata.key - to keyof entity - based on cwis input
112
91
  //y2 - remove __dirname from tutorials
113
92
  //p2 - when value changes for field with error, clear error - so the user will feel comfortable
114
93
  //p2 - allowApiUpdate should be false for include in api false
@@ -89,7 +89,7 @@ export class myServerAction extends Action {
89
89
  async execute(info, remult, res) {
90
90
  let result = { data: {} };
91
91
  let ds = remult.dataProvider;
92
- await doTransaction(remult, async () => {
92
+ await decideTransaction(remult, this.options, async () => {
93
93
  if (!remult.isAllowedForInstance(undefined, this.options.allowed))
94
94
  throw new ForbiddenError();
95
95
  info.args = await prepareReceivedArgs(this.types(), info.args, remult, ds, res);
@@ -112,7 +112,24 @@ export function Controller(key) {
112
112
  return target;
113
113
  };
114
114
  }
115
- /** Indicates that the decorated methods runs on the backend. See: [Backend Methods](https://remult.dev/docs/backendMethods.html) */
115
+ /**
116
+ * Decorator indicating that the decorated method runs on the backend.
117
+ * It allows the method to be invoked from the frontend while ensuring that the execution happens on the server side.
118
+ * By default, the method runs within a database transaction, meaning it will either complete entirely or fail without making any partial changes.
119
+ * This behavior can be controlled using the `transactional` option in the `BackendMethodOptions`.
120
+ *
121
+ * For more details, see: [Backend Methods](https://remult.dev/docs/backendMethods.html).
122
+ *
123
+ * @param options - Configuration options for the backend method, including permissions, routing, and transactional behavior.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * @BackendMethod({ allowed: true })
128
+ * async someBackendMethod() {
129
+ * // method logic here
130
+ * }
131
+ * ```
132
+ */
116
133
  export function BackendMethod(options) {
117
134
  return (target, context, descriptor) => {
118
135
  const key = typeof context === 'string' ? context : context.name.toString();
@@ -181,7 +198,7 @@ export function BackendMethod(options) {
181
198
  try {
182
199
  let remult = req;
183
200
  let r;
184
- await doTransaction(remult, async () => {
201
+ await decideTransaction(remult, options, async () => {
185
202
  d.args = await prepareReceivedArgs(getTypes(), d.args, remult, remult.dataProvider, res);
186
203
  if (remultStatic.allEntities.includes(constructor)) {
187
204
  let repo = remult.repo(constructor);
@@ -406,3 +423,10 @@ export async function prepareReceivedArgs(types, args, remult, ds, res) {
406
423
  return args;
407
424
  }
408
425
  export const classBackendMethodsArray = Symbol.for('classBackendMethodsArray');
426
+ //
427
+ async function decideTransaction(remult, options, what) {
428
+ if (options.transactional === undefined || options.transactional === true)
429
+ return await doTransaction(remult, what);
430
+ else
431
+ await what(remult.dataProvider);
432
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.27.5-next.1",
3
+ "version": "0.27.7",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -4,51 +4,37 @@ exports.flags = void 0;
4
4
  exports.flags = {
5
5
  error500RetryCount: 4,
6
6
  };
7
- //y1 - Hacker News for the tutorial?
7
+ //p1 - add transactional option to backend method
8
+ //p1 - add parameter all to deleteMany, and updateMany
9
+ //p1 filter.apply ApiPreFilter
10
+ //p1 - min, max, avg, sum, countDistinct - noam come up with an api
11
+ /*p1 - add id and use uuid by default, but allow changes with Fields.id.defaultIdProvider NO but defaultProvider yes???
12
+ //p1 - replace uuid with crypto.randomUUID and allow custom fallback NO
13
+ //p1 - Add example for luid
14
+ //p1 - add example for nanoid
15
+ //p1 - explain the benefits of changing the default provider for testing in docs.
16
+ */
17
+ //p1 - consider upsert (where,set)
18
+ //p1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
19
+ //p2 - add some kind of options handler that will help with translation etc... like in hagai - something that runs at the stage where options are being built
8
20
  /*y1 - https://github.com/remult/remult/discussions/438
9
21
  - https://github.com/remult/remult/blob/query-argumets/projects/tests/dbs/test-sql-database.spec.ts#L100-L128
10
- //p2 - allow preprocess to replace filter values - for example replace $contains on a specific field, with specific other sql - useful for full text search and other scenarios
11
22
  //y1 - consider sql expression gets a dbnames of it's own (that already has the "tableName" defined correctly) maybe also the filter translator
23
+ //p2 - allow preprocess to replace filter values - for example replace $contains on a specific field, with specific other sql - useful for full text search and other scenarios
12
24
  //y2 - soft-delete-discussion https://discord.com/channels/975754286384418847/1230386433093533698/1230386433093533698
13
25
  */
14
- //y1 - add parameter all to deleteMany, and updateMany
15
- //p1 - fix query docs to also explain how it can be used for infinite scroll and pagination.
16
- //p1 - when like doesn't have a string - don't send it to the db
17
- //y1 - 'test expression columns without aliases'
18
- //y1 - live query update waits for last
19
- //p1 - add luid - it's cool for order by. - NO
20
- //p1 - replace uuid with crypto.randomUUID and allow custom fallback NO
21
- //p1 - add nanoid - NO
22
- //p1 - add id and use luid by default, but allow changes with Fields.id.defaultIdProvider NO but defaultProvider yes
23
- /*p1
24
- * field, fieldType ,ValueListFieldType, - return optional parameter for decorators
25
- * options to remultExpress tc... should be mandatory
26
- * return value converter to previous typing
27
- * add breaking change notification about findOne and findFirst and findId
28
- */
29
- //p1 - fix query docs to also explain how it can be used for infinite scroll and pagination.
30
- //y1 - 'test expression columns without aliases'
31
- //y1 - ts issue with fields - when a field is optional, it's $ is also optional and thats a problem
26
+ //p2 - fix query docs to also explain how it can be used for infinite scroll and pagination.
27
+ //p2 - when like doesn't have a string - don't send it to the db
32
28
  //p1 - vite 5.3 supports ts5 decorators - check and adapt.
33
- //p1 - see if I can fix the no alias problem in selects
34
- //p1 - add luid - it's cool for order by.
35
- //p1 - replace uuid with crypto.randomUUID and allow custom fallback
36
- //p1 - add nanoid
37
- //p1 - add id and use luid by default, but allow changes with Fields.id.defaultIdProvider
38
- //p1 - explain the benefits of changing the default provider for testing in docs.
29
+ //p1 - tutorial about controller - and mutable controller
30
+ //p1 - docs abount subscription channel
31
+ //p1 - Consider enforcing serial operations on JSON database to prevent data loss
39
32
  //p1 - fix sqlite to support alter table when adding a column with ensure schema = on
40
- //p1 - fix app custom filters example for multiple filters.
41
- //p1 - add not!!!!
42
33
  //p1 - add LifecycleEvent to documentation
43
- //p1 - Fix hagai and starter project to latest ts
44
34
  //p1 - fix chaining of saving and saved in multiple entity options args
45
35
  //p1 - review starter and examples and separate remult * auth from the routes
46
- //p1 - min, max, avg, sum
47
- //p1 - consider upsert (where,set)
48
36
  //y1 - live query with count #436
49
37
  //y1 TODO - In the esm version of our tutorial - the imports are automatically .ts and not .js in react and not in vue
50
- //y1 TODO - consider id to also support keyof (id:['company','index']) - had problem with | (keyof Partial<entityType>)[] & `entity`
51
- //y1 TODO - readonly key: keyof MembersOnly<entityType> & string
52
38
  //y1 TODO - fix remult admin not to load the html into memory until used
53
39
  //y2 - talk about insert / update / delete with relations
54
40
  /*
@@ -66,15 +52,10 @@ const result = await repo.batch(x=>({
66
52
  }))
67
53
  */
68
54
  //y1 - wait a second to close stream -see pr
69
- //p1 - Consider enforcing serial operations on JSON database to prevent data loss
70
55
  //p1 - prepare the createEntity discussion
71
- //p1 - return error on connection error
72
56
  //p1 - article on displayValue including it's definition for entities that is used in relations
73
57
  //p1 - article auth.js with express - played with it, requires type="module" and a few more configurations - https://github.com/noam-honig/express-auth
74
- //y2 - currently for string fields we default for 255 in knex (which is their default) why not just use text (varchar max) - and only use exact length when one is provided?
75
58
  //p2 - create foreign key constraints in user code - https://codesandbox.io/p/devbox/fk-validator-tdshcs
76
- //p2 - admin url1 - pocketbase use /_ for the admin //{allowed?:Allowed,url?:string} also checkout the admin* as it should probably be something else and didn't work in hono
77
- //y2 - fix validators cache
78
59
  //y2 - should we validate relations
79
60
  //y1 - dependency of live query tables live query refresh of view on table update
80
61
  //p1 - see why mongo tests do not run anymore
@@ -94,7 +75,6 @@ const result = await repo.batch(x=>({
94
75
  - delete restrict (implicit, or user selected - and if so, how) (delete & update of id)
95
76
 
96
77
  */
97
- //y1 - tried to upgrade vitest, nuxt tests are failing with loading uuid - sounds familiar?
98
78
  //y1 - talk about the parameter issue with backend methods
99
79
  //y2 - livequery for findfirst (@JY)
100
80
  /*y2 -
@@ -111,7 +91,6 @@ const result = await repo.batch(x=>({
111
91
  //y2 - Fix problem with promise all in sql expression recurssion - when using PromiseAll in row relation loading, some sql expressions appear is recursion call even if they are not
112
92
  //p2 - when subscribe is forbidden - the query still runs after the renew process
113
93
  //p2 - 'update tasks set where id = $1
114
- //p2 - type metadata.key - to keyof entity - based on cwis input
115
94
  //y2 - remove __dirname from tutorials
116
95
  //p2 - when value changes for field with error, clear error - so the user will feel comfortable
117
96
  //p2 - allowApiUpdate should be false for include in api false
@@ -39,6 +39,13 @@ export interface BackendMethodOptions<type> {
39
39
  * {allowed:true, apiPrefix:'someFolder/'}
40
40
  */
41
41
  apiPrefix?: string;
42
+ /**
43
+ * Controls whether this `BackendMethod` runs within a database transaction. If set to `true`, the method will either complete entirely or fail without making any partial changes. If set to `false`, the method will not be transactional and may result in partial changes if it fails.
44
+ * @default true
45
+ * @example
46
+ * {allowed: true, transactional: false}
47
+ */
48
+ transactional?: boolean;
42
49
  /** EXPERIMENTAL: Determines if this method should be queued for later execution */
43
50
  queue?: boolean;
44
51
  /** EXPERIMENTAL: Determines if the user should be blocked while this `BackendMethod` is running*/
@@ -53,7 +60,24 @@ export interface ClassMethodDecoratorContextStub<This = unknown, Value extends (
53
60
  has(object: This): boolean;
54
61
  };
55
62
  }
56
- /** Indicates that the decorated methods runs on the backend. See: [Backend Methods](https://remult.dev/docs/backendMethods.html) */
63
+ /**
64
+ * Decorator indicating that the decorated method runs on the backend.
65
+ * It allows the method to be invoked from the frontend while ensuring that the execution happens on the server side.
66
+ * By default, the method runs within a database transaction, meaning it will either complete entirely or fail without making any partial changes.
67
+ * This behavior can be controlled using the `transactional` option in the `BackendMethodOptions`.
68
+ *
69
+ * For more details, see: [Backend Methods](https://remult.dev/docs/backendMethods.html).
70
+ *
71
+ * @param options - Configuration options for the backend method, including permissions, routing, and transactional behavior.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * @BackendMethod({ allowed: true })
76
+ * async someBackendMethod() {
77
+ * // method logic here
78
+ * }
79
+ * ```
80
+ */
57
81
  export declare function BackendMethod<type = unknown>(options: BackendMethodOptions<type>): (target: any, context: ClassMethodDecoratorContextStub<type> | string, descriptor?: any) => any;
58
82
  export interface jobWasQueuedResult {
59
83
  queuedJobId?: string;
@@ -143,7 +143,7 @@ var myServerAction = /** @class */ (function (_super) {
143
143
  case 0:
144
144
  result = { data: {} };
145
145
  ds = remult.dataProvider;
146
- return [4 /*yield*/, (0, context_js_1.doTransaction)(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
146
+ return [4 /*yield*/, decideTransaction(remult, this.options, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
147
147
  var _a, _b, err_2;
148
148
  return tslib_1.__generator(this, function (_c) {
149
149
  switch (_c.label) {
@@ -188,7 +188,24 @@ function Controller(key) {
188
188
  return target;
189
189
  };
190
190
  }
191
- /** Indicates that the decorated methods runs on the backend. See: [Backend Methods](https://remult.dev/docs/backendMethods.html) */
191
+ /**
192
+ * Decorator indicating that the decorated method runs on the backend.
193
+ * It allows the method to be invoked from the frontend while ensuring that the execution happens on the server side.
194
+ * By default, the method runs within a database transaction, meaning it will either complete entirely or fail without making any partial changes.
195
+ * This behavior can be controlled using the `transactional` option in the `BackendMethodOptions`.
196
+ *
197
+ * For more details, see: [Backend Methods](https://remult.dev/docs/backendMethods.html).
198
+ *
199
+ * @param options - Configuration options for the backend method, including permissions, routing, and transactional behavior.
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * @BackendMethod({ allowed: true })
204
+ * async someBackendMethod() {
205
+ * // method logic here
206
+ * }
207
+ * ```
208
+ */
192
209
  function BackendMethod(options) {
193
210
  var _this = this;
194
211
  return function (target, context, descriptor) {
@@ -289,7 +306,7 @@ function BackendMethod(options) {
289
306
  case 1:
290
307
  _a.trys.push([1, 3, , 4]);
291
308
  remult_1 = req;
292
- return [4 /*yield*/, (0, context_js_1.doTransaction)(remult_1, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
309
+ return [4 /*yield*/, decideTransaction(remult_1, options, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
293
310
  var _a, repo, y, rowInfo, rowHelper, rows, defs, err_4, y, controllerRef, err_5;
294
311
  var _b, _c, _d;
295
312
  var _e;
@@ -645,3 +662,21 @@ function prepareReceivedArgs(types, args, remult, ds, res) {
645
662
  });
646
663
  }
647
664
  exports.classBackendMethodsArray = Symbol.for('classBackendMethodsArray');
665
+ //
666
+ function decideTransaction(remult, options, what) {
667
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
668
+ return tslib_1.__generator(this, function (_a) {
669
+ switch (_a.label) {
670
+ case 0:
671
+ if (!(options.transactional === undefined || options.transactional === true)) return [3 /*break*/, 2];
672
+ return [4 /*yield*/, (0, context_js_1.doTransaction)(remult, what)];
673
+ case 1: return [2 /*return*/, _a.sent()];
674
+ case 2: return [4 /*yield*/, what(remult.dataProvider)];
675
+ case 3:
676
+ _a.sent();
677
+ _a.label = 4;
678
+ case 4: return [2 /*return*/];
679
+ }
680
+ });
681
+ });
682
+ }