remult 2.7.27 → 2.7.29

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.
@@ -20,67 +20,73 @@ export function buildEntityInfo(options) {
20
20
  for (const x of metadata.fields.toArray()) {
21
21
  if (!x.includedInApi(undefined))
22
22
  continue;
23
- let relation;
24
- let valFieldKey = x.key;
25
- const info = getRelationFieldInfo(x);
26
- if (info) {
27
- const relInfo = info.getFields();
28
- const relRepo = options.remult.repo(info.toEntity);
29
- const where = typeof info.options.findOptions === 'object' &&
30
- info.options.findOptions.where
31
- ? Filter.entityFilterToJson(relRepo.metadata, info.options.findOptions.where)
32
- : undefined;
33
- const idField = relRepo.metadata.idMetadata.field.key;
34
- if (info.type === 'reference' || info.type === 'toOne') {
35
- if (info.type == 'toOne') {
36
- for (const key in relInfo.fields) {
37
- if (Object.prototype.hasOwnProperty.call(relInfo.fields, key)) {
38
- const element = relInfo.fields[key];
39
- valFieldKey = element;
23
+ try {
24
+ let relation;
25
+ let valFieldKey = x.key;
26
+ const info = getRelationFieldInfo(x);
27
+ if (info) {
28
+ const relInfo = info.getFields();
29
+ const relRepo = options.remult.repo(info.toEntity);
30
+ const where = typeof info.options.findOptions === 'object' &&
31
+ info.options.findOptions.where
32
+ ? Filter.entityFilterToJson(relRepo.metadata, info.options.findOptions.where)
33
+ : undefined;
34
+ const idField = relRepo.metadata.idMetadata.field.key;
35
+ if (info.type === 'reference' || info.type === 'toOne') {
36
+ if (info.type == 'toOne') {
37
+ for (const key in relInfo.fields) {
38
+ if (Object.prototype.hasOwnProperty.call(relInfo.fields, key)) {
39
+ const element = relInfo.fields[key];
40
+ valFieldKey = element;
41
+ }
40
42
  }
41
43
  }
44
+ if (relRepo.metadata.apiReadAllowed) {
45
+ relation = {
46
+ ...relInfo,
47
+ where,
48
+ entityKey: relRepo.metadata.key,
49
+ idField,
50
+ captionField: relRepo.metadata.fields
51
+ .toArray()
52
+ .find((x) => x.key != idField && x.valueType == String)?.key,
53
+ };
54
+ }
42
55
  }
43
- if (relRepo.metadata.apiReadAllowed) {
44
- relation = {
45
- ...relInfo,
46
- where,
47
- entityKey: relRepo.metadata.key,
48
- idField,
49
- captionField: relRepo.metadata.fields
50
- .toArray()
51
- .find((x) => x.key != idField && x.valueType == String)?.key,
52
- };
53
- }
54
- }
55
- else if (info.type === 'toMany') {
56
- if (relRepo.metadata.apiReadAllowed) {
57
- relations.push({
58
- ...relInfo,
59
- where,
60
- entityKey: relRepo.metadata.key,
61
- });
56
+ else if (info.type === 'toMany') {
57
+ if (relRepo.metadata.apiReadAllowed) {
58
+ relations.push({
59
+ ...relInfo,
60
+ where,
61
+ entityKey: relRepo.metadata.key,
62
+ });
63
+ }
64
+ continue;
62
65
  }
63
- continue;
64
66
  }
67
+ fields.push({
68
+ key: x.key,
69
+ readOnly: !x.apiUpdateAllowed(),
70
+ values: getValueList(x),
71
+ valFieldKey,
72
+ caption: x.caption,
73
+ relationToOne: relation,
74
+ inputType: x.inputType,
75
+ type: x.valueConverter.fieldTypeInDb == 'json'
76
+ ? 'json'
77
+ : x.valueType === Number
78
+ ? 'number'
79
+ : x.valueType === Boolean
80
+ ? 'boolean'
81
+ : x.valueType === Date
82
+ ? 'date'
83
+ : 'string',
84
+ });
85
+ }
86
+ catch (error) {
87
+ console.error(`[remult-admin] Error with ${metadata.key}.${x.key} field.`);
88
+ console.error(`[remult-admin]`, error);
65
89
  }
66
- fields.push({
67
- key: x.key,
68
- readOnly: !x.apiUpdateAllowed(),
69
- values: getValueList(x),
70
- valFieldKey,
71
- caption: x.caption,
72
- relationToOne: relation,
73
- inputType: x.inputType,
74
- type: x.valueConverter.fieldTypeInDb == 'json'
75
- ? 'json'
76
- : x.valueType === Number
77
- ? 'number'
78
- : x.valueType === Boolean
79
- ? 'boolean'
80
- : x.valueType === Date
81
- ? 'date'
82
- : 'string',
83
- });
84
90
  }
85
91
  if (metadata.apiReadAllowed) {
86
92
  entities.push({
@@ -8,6 +8,8 @@
8
8
  * @see [Active Record & EntityBase](https://remult.dev/docs/active-record)
9
9
  */
10
10
  export function getEntityRef(entity, throwException = true) {
11
+ if (entity === undefined)
12
+ throw new Error('entity is undefined');
11
13
  let x = entity[entityMember];
12
14
  if (!x && throwException)
13
15
  throw new Error('item ' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "2.7.27",
3
+ "version": "2.7.29",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -296,7 +296,7 @@ var SqliteCoreDataProvider = /** @class */ (function () {
296
296
  'create table if not exists ' + e.$entityName + ' (' + result + '\r\n)',
297
297
  ];
298
298
  if (entity.idMetadata.fields.length > 1) {
299
- sql.push("create unique index ".concat(this.wrapIdentifier(entity.dbName + '_primary_key'), " on ").concat(e.$entityName, " (").concat(entity.idMetadata.fields
299
+ sql.push("create unique index if not exists ".concat(this.wrapIdentifier(entity.dbName + '_primary_key'), " on ").concat(e.$entityName, " (").concat(entity.idMetadata.fields
300
300
  .map(function (x) { return e.$dbNameOf(x); })
301
301
  .join(','), ")"));
302
302
  }