remult 0.22.7-exp.1 → 0.22.8-exp.0

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.
package/esm/src/column.js CHANGED
@@ -14,6 +14,8 @@ export class LookupColumn {
14
14
  repository;
15
15
  id;
16
16
  toJson() {
17
+ if (!this.storedItem)
18
+ return undefined;
17
19
  if (this.item === null)
18
20
  return null;
19
21
  return this.repository.toJson(this.item);
@@ -23,7 +23,7 @@ export class DataApi {
23
23
  async httpPost(res, req, body, serializeContext) {
24
24
  const action = req?.get('__action');
25
25
  if (action?.startsWith(liveQueryAction))
26
- return this.liveQuery(res, req, undefined, serializeContext, action.substring(liveQueryAction.length));
26
+ return this.liveQuery(res, req, body, serializeContext, action.substring(liveQueryAction.length));
27
27
  switch (action) {
28
28
  case 'get':
29
29
  return this.getArray(res, req, body);
@@ -377,12 +377,15 @@ export function buildFilterFromRequestParameters(entity, filterInfo) {
377
377
  let val = filterInfo.get('OR');
378
378
  if (val) {
379
379
  const array = separateArrayFromInnerArray(val);
380
- where.push({
381
- $and: array.map((v) => ({
382
- $or: v.map((x) => buildFilterFromRequestParameters(entity, {
383
- get: (key) => x[key],
384
- })),
380
+ const or = array.map((v) => ({
381
+ $or: v.map((x) => buildFilterFromRequestParameters(entity, {
382
+ get: (key) => x[key],
385
383
  })),
384
+ }));
385
+ if (or.length == 1)
386
+ return or[0];
387
+ where.push({
388
+ $and: or,
386
389
  });
387
390
  }
388
391
  for (const key in entity.entityType) {
@@ -405,6 +408,8 @@ export function buildFilterFromRequestParameters(entity, filterInfo) {
405
408
  }
406
409
  }
407
410
  }
411
+ if (where.length == 1)
412
+ return where[0];
408
413
  return { $and: where };
409
414
  function separateArrayFromInnerArray(val) {
410
415
  if (!Array.isArray(val))
@@ -874,7 +874,15 @@ export class rowHelperImplementation extends rowHelperBase {
874
874
  }
875
875
  metadata;
876
876
  getId() {
877
- return this.info.idMetadata.getId(this.instance);
877
+ const getVal = (y) => {
878
+ let z = this.lookups.get(y.key);
879
+ if (z)
880
+ return z.id;
881
+ return this.instance[y.key];
882
+ };
883
+ if (this.metadata.idMetadata.field instanceof CompoundIdField)
884
+ return this.metadata.idMetadata.field.fields.map(getVal).join(',');
885
+ return getVal(this.metadata.idMetadata.field);
878
886
  }
879
887
  saveMoreOriginalData() {
880
888
  this.originalId = this.getId();
@@ -1513,6 +1521,9 @@ class EntityFullInfo {
1513
1521
  }
1514
1522
  idMetadata = {
1515
1523
  getId: (item) => {
1524
+ const ref = getEntityRef(item, false);
1525
+ if (ref)
1526
+ return ref.getId();
1516
1527
  if (this.idMetadata.field instanceof CompoundIdField)
1517
1528
  return this.idMetadata.field.getId(item);
1518
1529
  else
@@ -5,6 +5,7 @@ import type { FieldMetadata } from '../column-interfaces';
5
5
  import type { EntityOptions } from '../entity';
6
6
  import type { LiveQueryChange, SubscriptionListener, Unsubscribe } from '../live-query/SubscriptionChannel';
7
7
  import type { SortSegment } from '../sort';
8
+ import type { EntityBase } from './RepositoryImplementation';
8
9
  export interface EntityRef<entityType> extends Subscribable {
9
10
  hasErrors(): boolean;
10
11
  undoChanges(): any;
@@ -153,7 +154,7 @@ export interface EntityMetadata<entityType = any> {
153
154
  /** Metadata for the Entity's id */
154
155
  readonly idMetadata: IdMetadata<entityType>;
155
156
  }
156
- export declare type OmitEB<T> = Omit<T, keyof import('./RepositoryImplementation').EntityBase>;
157
+ export declare type OmitEB<T> = Omit<T, keyof EntityBase>;
157
158
  export declare type idType<entityType> = entityType extends {
158
159
  id?: number;
159
160
  } ? number : entityType extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.22.7-exp.1",
3
+ "version": "0.22.8-exp.0",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
package/src/column.js CHANGED
@@ -21,6 +21,8 @@ var LookupColumn = /** @class */ (function () {
21
21
  this.id = id;
22
22
  }
23
23
  LookupColumn.prototype.toJson = function () {
24
+ if (!this.storedItem)
25
+ return undefined;
24
26
  if (this.item === null)
25
27
  return null;
26
28
  return this.repository.toJson(this.item);
package/src/data-api.js CHANGED
@@ -30,7 +30,7 @@ var DataApi = /** @class */ (function () {
30
30
  case 0:
31
31
  action = req === null || req === void 0 ? void 0 : req.get('__action');
32
32
  if (action === null || action === void 0 ? void 0 : action.startsWith(rest_data_provider_1.liveQueryAction))
33
- return [2 /*return*/, this.liveQuery(res, req, undefined, serializeContext, action.substring(rest_data_provider_1.liveQueryAction.length))];
33
+ return [2 /*return*/, this.liveQuery(res, req, body, serializeContext, action.substring(rest_data_provider_1.liveQueryAction.length))];
34
34
  _a = action;
35
35
  switch (_a) {
36
36
  case 'get': return [3 /*break*/, 1];
@@ -497,14 +497,17 @@ function buildFilterFromRequestParameters(entity, filterInfo) {
497
497
  var val = filterInfo.get('OR');
498
498
  if (val) {
499
499
  var array = separateArrayFromInnerArray(val);
500
+ var or = array.map(function (v) { return ({
501
+ $or: v.map(function (x) {
502
+ return buildFilterFromRequestParameters(entity, {
503
+ get: function (key) { return x[key]; },
504
+ });
505
+ }),
506
+ }); });
507
+ if (or.length == 1)
508
+ return or[0];
500
509
  where.push({
501
- $and: array.map(function (v) { return ({
502
- $or: v.map(function (x) {
503
- return buildFilterFromRequestParameters(entity, {
504
- get: function (key) { return x[key]; },
505
- });
506
- }),
507
- }); }),
510
+ $and: or,
508
511
  });
509
512
  }
510
513
  var _loop_2 = function (key) {
@@ -531,6 +534,8 @@ function buildFilterFromRequestParameters(entity, filterInfo) {
531
534
  for (var key in entity.entityType) {
532
535
  _loop_2(key);
533
536
  }
537
+ if (where.length == 1)
538
+ return where[0];
534
539
  return { $and: where };
535
540
  function separateArrayFromInnerArray(val) {
536
541
  var e_4, _a;
@@ -1436,7 +1436,16 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1436
1436
  configurable: true
1437
1437
  });
1438
1438
  rowHelperImplementation.prototype.getId = function () {
1439
- return this.info.idMetadata.getId(this.instance);
1439
+ var _this = this;
1440
+ var getVal = function (y) {
1441
+ var z = _this.lookups.get(y.key);
1442
+ if (z)
1443
+ return z.id;
1444
+ return _this.instance[y.key];
1445
+ };
1446
+ if (this.metadata.idMetadata.field instanceof CompoundIdField_1.CompoundIdField)
1447
+ return this.metadata.idMetadata.field.fields.map(getVal).join(',');
1448
+ return getVal(this.metadata.idMetadata.field);
1440
1449
  };
1441
1450
  rowHelperImplementation.prototype.saveMoreOriginalData = function () {
1442
1451
  this.originalId = this.getId();
@@ -2413,6 +2422,9 @@ var EntityFullInfo = /** @class */ (function () {
2413
2422
  this.key = key;
2414
2423
  this.idMetadata = {
2415
2424
  getId: function (item) {
2425
+ var ref = (0, getEntityRef_1.getEntityRef)(item, false);
2426
+ if (ref)
2427
+ return ref.getId();
2416
2428
  if (_this.idMetadata.field instanceof CompoundIdField_1.CompoundIdField)
2417
2429
  return _this.idMetadata.field.getId(item);
2418
2430
  else
@@ -5,6 +5,7 @@ import type { FieldMetadata } from '../column-interfaces';
5
5
  import type { EntityOptions } from '../entity';
6
6
  import type { LiveQueryChange, SubscriptionListener, Unsubscribe } from '../live-query/SubscriptionChannel';
7
7
  import type { SortSegment } from '../sort';
8
+ import type { EntityBase } from './RepositoryImplementation';
8
9
  export interface EntityRef<entityType> extends Subscribable {
9
10
  hasErrors(): boolean;
10
11
  undoChanges(): any;
@@ -153,7 +154,7 @@ export interface EntityMetadata<entityType = any> {
153
154
  /** Metadata for the Entity's id */
154
155
  readonly idMetadata: IdMetadata<entityType>;
155
156
  }
156
- export declare type OmitEB<T> = Omit<T, keyof import('./RepositoryImplementation').EntityBase>;
157
+ export declare type OmitEB<T> = Omit<T, keyof EntityBase>;
157
158
  export declare type idType<entityType> = entityType extends {
158
159
  id?: number;
159
160
  } ? number : entityType extends {