remult 3.4.1 → 3.5.0-next.1

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 (68) hide show
  1. package/esm/internals.js +1 -0
  2. package/esm/postgres/postgres-data-provider.js +4 -5
  3. package/esm/remult-duckdb.js +4 -0
  4. package/esm/remult-knex/index.js +41 -9
  5. package/esm/remult-mongo.js +27 -9
  6. package/esm/remult-sqlite-core.js +4 -1
  7. package/esm/server/remult-api-server.js +1 -1
  8. package/esm/src/buildRestDataProvider.js +4 -2
  9. package/esm/src/data-api.js +2 -2
  10. package/esm/src/data-interfaces.js +2 -1
  11. package/esm/src/data-providers/array-entity-data-provider.js +5 -0
  12. package/esm/src/data-providers/rest-data-provider-using-fetch.js +2 -2
  13. package/esm/src/data-providers/retry.js +11 -6
  14. package/esm/src/data-providers/sql-database.js +41 -31
  15. package/esm/src/filter/entityDbName.js +6 -10
  16. package/esm/src/filter/fieldDbName.js +8 -14
  17. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +4 -4
  18. package/esm/src/filter/sqlExpressionInProgress.js +14 -0
  19. package/esm/src/live-query/SubscriptionChannel.js +13 -8
  20. package/esm/src/remult-static.js +1 -0
  21. package/esm/src/remult3/Fields.js +14 -14
  22. package/esm/src/remult3/QueryResultImpl.js +2 -0
  23. package/esm/src/remult3/RepositoryImplementation.js +47 -33
  24. package/esm/src/sort.js +18 -0
  25. package/index.d.ts +1 -1
  26. package/internals.d.ts +1 -0
  27. package/internals.js +3 -1
  28. package/package.json +41 -1
  29. package/postgres/postgres-data-provider.d.ts +2 -3
  30. package/postgres/postgres-data-provider.js +4 -4
  31. package/remult-duckdb.d.ts +2 -0
  32. package/remult-duckdb.js +4 -0
  33. package/remult-knex/index.d.ts +2 -0
  34. package/remult-knex/index.js +127 -80
  35. package/remult-mongo.js +29 -8
  36. package/remult-sqlite-core.d.ts +2 -1
  37. package/remult-sqlite-core.js +4 -0
  38. package/server/remult-api-server.d.ts +12 -1
  39. package/server/remult-api-server.js +1 -1
  40. package/src/buildRestDataProvider.js +3 -1
  41. package/src/column-interfaces.d.ts +5 -1
  42. package/src/data-api.js +2 -2
  43. package/src/data-interfaces.d.ts +0 -1
  44. package/src/data-interfaces.js +3 -0
  45. package/src/data-providers/array-entity-data-provider.js +5 -0
  46. package/src/data-providers/rest-data-provider-using-fetch.js +1 -1
  47. package/src/data-providers/retry.d.ts +4 -1
  48. package/src/data-providers/retry.js +26 -16
  49. package/src/data-providers/sql-database.d.ts +7 -3
  50. package/src/data-providers/sql-database.js +100 -84
  51. package/src/filter/entityDbName.d.ts +1 -1
  52. package/src/filter/entityDbName.js +14 -16
  53. package/src/filter/fieldDbName.js +19 -25
  54. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +1 -1
  55. package/src/filter/filter-consumer-bridge-to-sql-request.js +7 -5
  56. package/src/filter/sqlExpressionInProgress.d.ts +2 -0
  57. package/src/filter/sqlExpressionInProgress.js +27 -0
  58. package/src/live-query/SubscriptionChannel.js +16 -10
  59. package/src/remult-static.d.ts +2 -0
  60. package/src/remult-static.js +1 -0
  61. package/src/remult3/Fields.d.ts +5 -3
  62. package/src/remult3/Fields.js +24 -13
  63. package/src/remult3/QueryResultImpl.js +2 -0
  64. package/src/remult3/RepositoryImplementation.js +284 -272
  65. package/src/remult3/remult3.d.ts +6 -1
  66. package/src/sort.d.ts +19 -0
  67. package/src/sort.js +20 -1
  68. package/src/sql-command.d.ts +2 -1
@@ -64,12 +64,6 @@ var LiveQuerySubscriber = /** @class */ (function () {
64
64
  var _this = this;
65
65
  what(function (reducer) {
66
66
  _this.defaultQueryState = reducer(_this.defaultQueryState);
67
- if (changes.find(function (c) { return c.type === 'add' || c.type === 'replace'; })) {
68
- if (_this.query.options.orderBy) {
69
- var o_1 = sort_js_1.Sort.translateOrderByToSort(_this.repo.metadata, _this.query.options.orderBy);
70
- _this.defaultQueryState.sort(function (a, b) { return o_1.compare(a, b); });
71
- }
72
- }
73
67
  });
74
68
  var _loop_1 = function (l) {
75
69
  what(function (reducer) {
@@ -138,8 +132,10 @@ var LiveQuerySubscriber = /** @class */ (function () {
138
132
  element.data.item = loadedItems[index];
139
133
  }
140
134
  this.forListeners(function (listener) {
141
- listener(function (items) {
142
- var e_2, _a;
135
+ listener(function (items, _a) {
136
+ var e_2, _b;
137
+ var _c;
138
+ var _d = _a === void 0 ? {} : _a, _e = _d.pos, pos = _e === void 0 ? 'auto' : _e;
143
139
  if (!items)
144
140
  items = [];
145
141
  var _loop_2 = function (message) {
@@ -160,7 +156,10 @@ var LiveQuerySubscriber = /** @class */ (function () {
160
156
  return _this.repo.metadata.idMetadata.getId(x) !==
161
157
  _this.repo.metadata.idMetadata.getId(message.data.item);
162
158
  });
163
- items.push(message.data.item);
159
+ if (pos === 'first')
160
+ items.unshift(message.data.item);
161
+ else
162
+ items.push(message.data.item);
164
163
  break;
165
164
  case 'remove':
166
165
  items = items.filter(function (x) {
@@ -178,10 +177,17 @@ var LiveQuerySubscriber = /** @class */ (function () {
178
177
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
179
178
  finally {
180
179
  try {
181
- if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
180
+ if (data_1_1 && !data_1_1.done && (_b = data_1.return)) _b.call(data_1);
182
181
  }
183
182
  finally { if (e_2) throw e_2.error; }
184
183
  }
184
+ var orderBy = (_c = _this.query.options.orderBy) !== null && _c !== void 0 ? _c : _this.repo.metadata.options.defaultOrderBy;
185
+ if (pos === 'auto' &&
186
+ orderBy &&
187
+ data.some(function (m) { return m.type === 'add' || m.type === 'replace'; })) {
188
+ var o_1 = sort_js_1.Sort.translateOrderByToSort(_this.repo.metadata, orderBy);
189
+ items.sort(function (a, b) { return o_1.compare(a, b); });
190
+ }
185
191
  return items;
186
192
  });
187
193
  }, data);
@@ -2,6 +2,7 @@ import type { ClassType } from '../classType.js';
2
2
  import type { ClassHelper, Remult, RemultAsyncLocalStorage } from './context.js';
3
3
  import type { DataProvider } from './data-interfaces.js';
4
4
  import type { columnInfo } from './remult3/columnInfo.js';
5
+ import type { NullSort } from './sort.js';
5
6
  export declare const remultStatic: {
6
7
  defaultRemultFactory: () => Remult;
7
8
  remultFactory: () => Remult;
@@ -21,6 +22,7 @@ export declare const remultStatic: {
21
22
  };
22
23
  fieldOptionsEnricher: any;
23
24
  labelTransformer: any;
25
+ nullSort: typeof NullSort;
24
26
  defaultIdFactory: () => string;
25
27
  defaultDataProvider: () => Promise<DataProvider | undefined>;
26
28
  };
@@ -25,6 +25,7 @@ var x = {
25
25
  },
26
26
  fieldOptionsEnricher: undefined,
27
27
  labelTransformer: undefined,
28
+ nullSort: undefined,
28
29
  defaultIdFactory: undefined,
29
30
  defaultDataProvider: function () {
30
31
  return undefined;
@@ -2,6 +2,10 @@ import type { ClassType } from '../../classType.js';
2
2
  import type { FieldOptions } from '../column-interfaces.js';
3
3
  import type { Remult } from '../context.js';
4
4
  import type { FindOptions, RelationOptions, ClassFieldDecorator, ClassFieldDecoratorContextStub } from './remult3.js';
5
+ export type IdFieldOptions<entityType = unknown> = FieldOptions<entityType, string> & {
6
+ /** Generates the id for a new row. Defaults to `Fields.defaultIdFactory`. */
7
+ idFactory?: () => string;
8
+ };
5
9
  export declare class Fields {
6
10
  /**
7
11
  * Stored as a JSON.stringify - to store as json use Fields.json
@@ -71,9 +75,7 @@ export declare class Fields {
71
75
  * }
72
76
  * ```
73
77
  */
74
- static id<entityType = unknown>(options?: FieldOptions<entityType, string> & {
75
- idFactory?: () => string;
76
- }): ClassFieldDecorator<entityType, string | undefined>;
78
+ static id<entityType = unknown>(...options: (IdFieldOptions<entityType> | ((options: IdFieldOptions<entityType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
77
79
  /**
78
80
  * Defines a field that can hold a value from a specified set of string literals.
79
81
  * @param {() => readonly valueType[]} optionalValues - A function that returns an array of allowed string literals.
@@ -106,6 +106,8 @@ var Fields = /** @class */ (function () {
106
106
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Date; },
107
107
  {
108
108
  allowApiUpdate: false,
109
+ // Set on every insert, so never NULL.
110
+ allowNull: false,
109
111
  saving: function (_, ref, _a) {
110
112
  var isNew = _a.isNew;
111
113
  if (isNew)
@@ -121,6 +123,8 @@ var Fields = /** @class */ (function () {
121
123
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Date; },
122
124
  {
123
125
  allowApiUpdate: false,
126
+ // Set on every save, so never NULL.
127
+ allowNull: false,
124
128
  saving: function (_, ref) {
125
129
  ref.value = new Date();
126
130
  },
@@ -132,7 +136,7 @@ var Fields = /** @class */ (function () {
132
136
  for (var _i = 0; _i < arguments.length; _i++) {
133
137
  options[_i] = arguments[_i];
134
138
  }
135
- return Fields.id(tslib_1.__assign({ idFactory: function () { return crypto.randomUUID(); } }, options));
139
+ return Fields.id.apply(Fields, tslib_1.__spreadArray([{ idFactory: function () { return crypto.randomUUID(); } }], tslib_1.__read(options), false));
136
140
  };
137
141
  Object.defineProperty(Fields, "defaultIdFactory", {
138
142
  /**
@@ -197,18 +201,25 @@ var Fields = /** @class */ (function () {
197
201
  * }
198
202
  * ```
199
203
  */
200
- Fields.id = function (options) {
201
- return Field(function () { return String; }, tslib_1.__assign({ allowApiUpdate: false, defaultValue: function () {
202
- var _a;
203
- var idFactory = (_a = options === null || options === void 0 ? void 0 : options.idFactory) !== null && _a !== void 0 ? _a : Fields.defaultIdFactory;
204
- return idFactory();
205
- }, saving: function (_, r) {
206
- var _a;
207
- if (!r.value) {
208
- var idFactory = (_a = options === null || options === void 0 ? void 0 : options.idFactory) !== null && _a !== void 0 ? _a : Fields.defaultIdFactory;
209
- r.value = idFactory();
210
- }
211
- } }, options));
204
+ Fields.id = function () {
205
+ var options = [];
206
+ for (var _i = 0; _i < arguments.length; _i++) {
207
+ options[_i] = arguments[_i];
208
+ }
209
+ // Read once the options are merged, so a later option or a function option can set it.
210
+ var idFactory;
211
+ var newId = function () { return (idFactory !== null && idFactory !== void 0 ? idFactory : Fields.defaultIdFactory)(); };
212
+ return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([function () { return String; },
213
+ {
214
+ allowApiUpdate: false,
215
+ defaultValue: newId,
216
+ saving: function (_, r) {
217
+ if (!r.value)
218
+ r.value = newId();
219
+ },
220
+ }], tslib_1.__read(options), false), [function (o) {
221
+ idFactory = o.idFactory;
222
+ }], false));
212
223
  };
213
224
  /**
214
225
  * Defines a field that can hold a value from a specified set of string literals.
@@ -29,6 +29,7 @@ var QueryResultImpl = /** @class */ (function () {
29
29
  page: page,
30
30
  load: this.options.load,
31
31
  include: this.options.include,
32
+ args: this.options.args,
32
33
  })];
33
34
  });
34
35
  });
@@ -115,6 +116,7 @@ var QueryResultImpl = /** @class */ (function () {
115
116
  limit: this.options.pageSize,
116
117
  load: this.options.load,
117
118
  include: this.options.include,
119
+ args: this.options.args,
118
120
  };
119
121
  getItems = function () { return _this.repo.find(options); };
120
122
  if (this._aggregates === undefined &&