remult 0.25.7-exp.0 → 0.25.7-exp.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.
@@ -80,6 +80,9 @@ class PostgresBridgeToSQLCommand {
80
80
  }
81
81
  values = [];
82
82
  addParameterAndReturnSqlToken(val) {
83
+ return this.param(val);
84
+ }
85
+ param(val) {
83
86
  if (Array.isArray(val))
84
87
  val = JSON.stringify(val);
85
88
  this.values.push(val);
@@ -65,9 +65,9 @@ export class PostgresSchemaBuilder {
65
65
  }
66
66
  const where = [];
67
67
  if (schema) {
68
- where.push(`table_schema=${cmd.addParameterAndReturnSqlToken(this.removeQuotes(schema))}`);
68
+ where.push(`table_schema=${cmd.param(this.removeQuotes(schema))}`);
69
69
  }
70
- where.push(`table_name=${cmd.addParameterAndReturnSqlToken(this.removeQuotes(table))}`);
70
+ where.push(`table_name=${cmd.param(this.removeQuotes(table))}`);
71
71
  return where.join(' AND ');
72
72
  }
73
73
  schemaAndName(e) {
@@ -162,7 +162,7 @@ CREATE table ${this.schemaAndName(e)} (${result}\r\n)`;
162
162
  const colName = e.$dbNameOf(c(entity));
163
163
  if ((await cmd.execute(`SELECT 1 FROM information_schema.columns WHERE ` +
164
164
  `${this.whereTableAndSchema(cmd, e)} ` +
165
- `AND column_name=${cmd.addParameterAndReturnSqlToken(colName.toLocaleLowerCase())}`)).rows.length == 0) {
165
+ `AND column_name=${cmd.param(colName.toLocaleLowerCase())}`)).rows.length == 0) {
166
166
  let sql = `ALTER table ${this.schemaAndName(e)} ` +
167
167
  `ADD column ${postgresColumnSyntax(c(entity), colName)}`;
168
168
  if (PostgresSchemaBuilder.logToConsole)
@@ -92,6 +92,9 @@ class SqlJsCommand {
92
92
  return new SqlJsSqlResult((await this.db).exec(sql, this.values));
93
93
  }
94
94
  addParameterAndReturnSqlToken(val) {
95
+ return this.param(val);
96
+ }
97
+ param(val) {
95
98
  if (val instanceof Date)
96
99
  val = val.valueOf();
97
100
  const key = ':' + ++this.i;
@@ -58,7 +58,10 @@ export class SqlDatabase {
58
58
  createCommand: () => {
59
59
  let c = x.createCommand();
60
60
  return {
61
- addParameterAndReturnSqlToken: (x) => c.addParameterAndReturnSqlToken(x),
61
+ addParameterAndReturnSqlToken: (val) => {
62
+ return c.param(val);
63
+ },
64
+ param: (x) => c.param(x),
62
65
  execute: async (sql) => {
63
66
  if (completed)
64
67
  throw "can't run a command after the transaction was completed";
@@ -139,7 +142,10 @@ class LogSQLCommand {
139
142
  }
140
143
  args = {};
141
144
  addParameterAndReturnSqlToken(val) {
142
- let r = this.origin.addParameterAndReturnSqlToken(val);
145
+ return this.param(val);
146
+ }
147
+ param(val, name) {
148
+ let r = this.origin.param(val);
143
149
  this.args[r] = val;
144
150
  return r;
145
151
  }
@@ -321,8 +327,7 @@ class ActualSQLServerDataProvider {
321
327
  added = true;
322
328
  else
323
329
  statement += ', ';
324
- statement +=
325
- e.$dbNameOf(x) + ' = ' + r.addParameterAndReturnSqlToken(v);
330
+ statement += e.$dbNameOf(x) + ' = ' + r.param(v);
326
331
  }
327
332
  }
328
333
  }
@@ -364,7 +369,7 @@ class ActualSQLServerDataProvider {
364
369
  vals += ', ';
365
370
  }
366
371
  cols += e.$dbNameOf(x);
367
- vals += r.addParameterAndReturnSqlToken(v);
372
+ vals += r.param(v);
368
373
  }
369
374
  }
370
375
  }
@@ -382,6 +387,9 @@ class myDummySQLCommand {
382
387
  throw new Error('Method not implemented.');
383
388
  }
384
389
  addParameterAndReturnSqlToken(val) {
390
+ return this.param(val);
391
+ }
392
+ param(val) {
385
393
  if (val === null)
386
394
  return 'null';
387
395
  if (val instanceof Date)
@@ -410,7 +418,7 @@ async function bulkInsert(array, db) {
410
418
  sql += items
411
419
  .map((row) => '(' +
412
420
  row.$.toArray()
413
- .map((f) => c.addParameterAndReturnSqlToken(f.metadata.valueConverter.toDb(f.value)))
421
+ .map((f) => c.param(f.metadata.valueConverter.toDb(f.value)))
414
422
  .join(', ') +
415
423
  ')')
416
424
  .join(',');
@@ -101,6 +101,9 @@ class WebSqlBridgeToSQLCommand {
101
101
  }
102
102
  values = [];
103
103
  addParameterAndReturnSqlToken(val) {
104
+ return this.param(val);
105
+ }
106
+ param(val) {
104
107
  this.values.push(val);
105
108
  return '~' + this.values.length + '~';
106
109
  }
@@ -61,7 +61,7 @@ export class FilterConsumerBridgeToSqlRequest {
61
61
  this.addToWhere(this.nameProvider.$dbNameOf(col) +
62
62
  ' in (' +
63
63
  val
64
- .map((x) => this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(x)))
64
+ .map((x) => this.r.param(col.valueConverter.toDb(x)))
65
65
  .join(',') +
66
66
  ')');
67
67
  else
@@ -110,7 +110,7 @@ export class FilterConsumerBridgeToSqlRequest {
110
110
  ' ' +
111
111
  operator +
112
112
  ' ' +
113
- this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(val));
113
+ this.r.param(col.valueConverter.toDb(val));
114
114
  this.addToWhere(x);
115
115
  })());
116
116
  }
@@ -141,10 +141,15 @@ export class CustomSqlFilterBuilder {
141
141
  this.r = r;
142
142
  }
143
143
  sql = '';
144
- addParameterAndReturnSqlToken(val, field) {
145
- if (field)
144
+ /** @deprecated @deprecated use `param` instead*/
145
+ addParameterAndReturnSqlToken(val) {
146
+ return this.param(val);
147
+ }
148
+ param(val, field) {
149
+ if (typeof field === 'object' && field.valueConverter.toDb) {
146
150
  val = field.valueConverter.toDb(val);
147
- return this.r.addParameterAndReturnSqlToken(val);
151
+ }
152
+ return this.r.param(val);
148
153
  }
149
154
  async filterToRaw(repo, condition) {
150
155
  return SqlDatabase.filterToRaw(repo, condition, this);
@@ -39,6 +39,12 @@ export class RepositoryImplementation {
39
39
  dataProvider;
40
40
  _info;
41
41
  defaultFindOptions;
42
+ notFoundError(id) {
43
+ return {
44
+ message: `id ${id} not found in entity ${this.metadata.key}`,
45
+ httpStatusCode: 404,
46
+ };
47
+ }
42
48
  [getInternalKey]() {
43
49
  return this;
44
50
  }
@@ -191,8 +197,9 @@ export class RepositoryImplementation {
191
197
  return this.edp.delete(item);
192
198
  else {
193
199
  let ref2 = await this.findId(item);
194
- if (ref2)
195
- return await getEntityRef(ref2).delete();
200
+ if (!ref2)
201
+ throw this.notFoundError(item);
202
+ return await getEntityRef(ref2).delete();
196
203
  }
197
204
  let ref2 = this.getRefForExistingRow(item, undefined);
198
205
  if (!this.dataProvider.isProxy)
@@ -269,7 +276,7 @@ export class RepositoryImplementation {
269
276
  else {
270
277
  const r = await ref.reload();
271
278
  if (!r)
272
- throw new Error('Not Found');
279
+ throw this.notFoundError(ref.id);
273
280
  for (const key in entity) {
274
281
  if (Object.prototype.hasOwnProperty.call(entity, key)) {
275
282
  let f = ref.fields[key];
@@ -1147,7 +1154,11 @@ export class rowHelperImplementation extends rowHelperBase {
1147
1154
  this.__clearErrorsAndReportChanged();
1148
1155
  }
1149
1156
  async reload() {
1150
- await this.edp.find({ where: this.getIdFilter() }).then(async (newData) => {
1157
+ await this.edp
1158
+ .find({ where: await this.getIdFilter() })
1159
+ .then(async (newData) => {
1160
+ if (newData.length === 0)
1161
+ throw this.repository.notFoundError(this.id);
1151
1162
  await this.loadDataFrom(newData[0]);
1152
1163
  this.saveOriginalData();
1153
1164
  });
@@ -1232,7 +1243,7 @@ export class rowHelperImplementation extends rowHelperBase {
1232
1243
  if (!wasChanged)
1233
1244
  return this.instance;
1234
1245
  if (doNotSave) {
1235
- updatedRow = (await this.edp.find({ where: this.getIdFilter() }))[0];
1246
+ updatedRow = (await this.edp.find({ where: await this.getIdFilter() }))[0];
1236
1247
  }
1237
1248
  else {
1238
1249
  updatedRow = await this.edp.update(this.id, changesOnly);
@@ -1275,8 +1286,8 @@ export class rowHelperImplementation extends rowHelperBase {
1275
1286
  relations: self.repository.relations(self.instance),
1276
1287
  };
1277
1288
  }
1278
- getIdFilter() {
1279
- return Filter.fromEntityFilter(this.metadata, this.repository.metadata.idMetadata.getIdFilter(this.id));
1289
+ async getIdFilter() {
1290
+ return await this.repository.translateWhereToFilter(this.repository.metadata.idMetadata.getIdFilter(this.id));
1280
1291
  }
1281
1292
  async delete() {
1282
1293
  this.__clearErrorsAndReportChanged();
@@ -10,10 +10,12 @@ export {};
10
10
  #
11
11
 
12
12
  //y1 - getFields didn't work for kobi in the home component
13
- //p1 - JYC - change name of add parameter and .... to token - param
14
- //p1 - Hint names for sql parameters
13
+
14
+
15
15
  //p1 - add section to Fields doc, explaining field type in db
16
16
  /*p1 - JYC - Delete many, update many, insert many
17
+ //p1 - @jycouet regarding required - are you ok with leaving '' as not a good value? (0 will be a good value)
18
+
17
19
  - post + __action=delet
18
20
  */
19
21
  //p1 - JYC - there should be a required that says not null or undefined, but space, 0 etc... should be ok - NOAM- check if removing zero is good enough
@@ -21,6 +23,23 @@ export {};
21
23
  - soft delete
22
24
  - delete restrict (implicit, or user selected - and if so, how) (delete & update of id)
23
25
 
26
+ */
27
+ /*y1 currency.ts:10 Uncaught TypeError: Currency_1 is not a constructor
28
+
29
+ @ValueListFieldType()
30
+ export class Currency {
31
+ constructor(
32
+ public id: number,
33
+ public caption: string,
34
+ public symbol: string
35
+ ) {}
36
+ static shekel = new Currency(1, 'Shekel', '₪');
37
+ static dollar = new Currency(2, 'Dollar', '$');
38
+ static euro = new Currency(3, 'Euro', '€');
39
+ static pound = new Currency(4, 'Pound', '£');
40
+ static yen = new Currency(5, 'Yen', '¥');
41
+ }
42
+
24
43
  */
25
44
  //y1 - admin url!
26
45
  //y1 - consider sql expression gets a dbnames of it's own (that already has the "tableName" defined correctly) maybe also the filter translator
@@ -31,7 +50,8 @@ export {};
31
50
  //y1 - talk about the parameter issue with backend methods
32
51
  //y1 - select data provider per entity https://discord.com/channels/975754286384418847/976006081748807690/1201415305885397003
33
52
  //y1 - migrations
34
- //y2 - live query refresh of view on table update
53
+ //y1 - live query refresh of view on table update
54
+ //y1 - main vs master
35
55
  //y2 - livequery for findfirst (@JY)
36
56
  /*y2 -
37
57
  //y2 - allow api update only for new rows
@@ -1,5 +1,5 @@
1
1
  export class Validators {
2
- static required = createValidator(async (_, e) => e.value != null && e.value != undefined && e.value !== '' && e.value != 0, 'Should not be empty');
2
+ static required = createValidator(async (_, e) => e.value != null && e.value != undefined && e.value !== '', 'Should not be empty');
3
3
  static unique = createValidator(async (_, e) => {
4
4
  if (!e.entityRef)
5
5
  throw 'unique validation may only work on columns that are attached to an entity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.25.7-exp.0",
3
+ "version": "0.25.7-exp.1",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "homepage": "https://remult.dev",
6
6
  "repository": {
@@ -123,6 +123,9 @@ var PostgresBridgeToSQLCommand = /** @class */ (function () {
123
123
  this.values = [];
124
124
  }
125
125
  PostgresBridgeToSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
126
+ return this.param(val);
127
+ };
128
+ PostgresBridgeToSQLCommand.prototype.param = function (val) {
126
129
  if (Array.isArray(val))
127
130
  val = JSON.stringify(val);
128
131
  this.values.push(val);
@@ -82,9 +82,9 @@ var PostgresSchemaBuilder = /** @class */ (function () {
82
82
  }
83
83
  var where = [];
84
84
  if (schema) {
85
- where.push("table_schema=".concat(cmd.addParameterAndReturnSqlToken(this.removeQuotes(schema))));
85
+ where.push("table_schema=".concat(cmd.param(this.removeQuotes(schema))));
86
86
  }
87
- where.push("table_name=".concat(cmd.addParameterAndReturnSqlToken(this.removeQuotes(table))));
87
+ where.push("table_name=".concat(cmd.param(this.removeQuotes(table))));
88
88
  return where.join(' AND ');
89
89
  };
90
90
  PostgresSchemaBuilder.prototype.schemaAndName = function (e) {
@@ -290,7 +290,7 @@ var PostgresSchemaBuilder = /** @class */ (function () {
290
290
  colName = e.$dbNameOf(c(entity));
291
291
  return [4 /*yield*/, cmd.execute("SELECT 1 FROM information_schema.columns WHERE " +
292
292
  "".concat(this.whereTableAndSchema(cmd, e), " ") +
293
- "AND column_name=".concat(cmd.addParameterAndReturnSqlToken(colName.toLocaleLowerCase())))];
293
+ "AND column_name=".concat(cmd.param(colName.toLocaleLowerCase())))];
294
294
  case 3:
295
295
  if (!((_a.sent()).rows.length == 0)) return [3 /*break*/, 5];
296
296
  sql = "ALTER table ".concat(this.schemaAndName(e), " ") +
package/remult-sql-js.js CHANGED
@@ -183,6 +183,9 @@ var SqlJsCommand = /** @class */ (function () {
183
183
  });
184
184
  };
185
185
  SqlJsCommand.prototype.addParameterAndReturnSqlToken = function (val) {
186
+ return this.param(val);
187
+ };
188
+ SqlJsCommand.prototype.param = function (val) {
186
189
  if (val instanceof Date)
187
190
  val = val.valueOf();
188
191
  var key = ':' + ++this.i;
@@ -109,9 +109,10 @@ var SqlDatabase = /** @class */ (function () {
109
109
  createCommand: function () {
110
110
  var c = x.createCommand();
111
111
  return {
112
- addParameterAndReturnSqlToken: function (x) {
113
- return c.addParameterAndReturnSqlToken(x);
112
+ addParameterAndReturnSqlToken: function (val) {
113
+ return c.param(val);
114
114
  },
115
+ param: function (x) { return c.param(x); },
115
116
  execute: function (sql) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
116
117
  return tslib_1.__generator(this, function (_a) {
117
118
  if (completed)
@@ -217,7 +218,10 @@ var LogSQLCommand = /** @class */ (function () {
217
218
  this.args = {};
218
219
  }
219
220
  LogSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
220
- var r = this.origin.addParameterAndReturnSqlToken(val);
221
+ return this.param(val);
222
+ };
223
+ LogSQLCommand.prototype.param = function (val, name) {
224
+ var r = this.origin.param(val);
221
225
  this.args[r] = val;
222
226
  return r;
223
227
  };
@@ -490,8 +494,7 @@ var ActualSQLServerDataProvider = /** @class */ (function () {
490
494
  added = true;
491
495
  else
492
496
  statement += ', ';
493
- statement +=
494
- e.$dbNameOf(x) + ' = ' + r.addParameterAndReturnSqlToken(v);
497
+ statement += e.$dbNameOf(x) + ' = ' + r.param(v);
495
498
  }
496
499
  }
497
500
  }
@@ -572,7 +575,7 @@ var ActualSQLServerDataProvider = /** @class */ (function () {
572
575
  vals += ', ';
573
576
  }
574
577
  cols += e.$dbNameOf(x);
575
- vals += r.addParameterAndReturnSqlToken(v);
578
+ vals += r.param(v);
576
579
  }
577
580
  }
578
581
  }
@@ -607,6 +610,9 @@ var myDummySQLCommand = /** @class */ (function () {
607
610
  throw new Error('Method not implemented.');
608
611
  };
609
612
  myDummySQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
613
+ return this.param(val);
614
+ };
615
+ myDummySQLCommand.prototype.param = function (val) {
610
616
  if (val === null)
611
617
  return 'null';
612
618
  if (val instanceof Date)
@@ -651,9 +657,7 @@ function bulkInsert(array, db) {
651
657
  .map(function (row) {
652
658
  return '(' +
653
659
  row.$.toArray()
654
- .map(function (f) {
655
- return c.addParameterAndReturnSqlToken(f.metadata.valueConverter.toDb(f.value));
656
- })
660
+ .map(function (f) { return c.param(f.metadata.valueConverter.toDb(f.value)); })
657
661
  .join(', ') +
658
662
  ')';
659
663
  })
@@ -182,6 +182,9 @@ var WebSqlBridgeToSQLCommand = /** @class */ (function () {
182
182
  this.values = [];
183
183
  }
184
184
  WebSqlBridgeToSQLCommand.prototype.addParameterAndReturnSqlToken = function (val) {
185
+ return this.param(val);
186
+ };
187
+ WebSqlBridgeToSQLCommand.prototype.param = function (val) {
185
188
  this.values.push(val);
186
189
  return '~' + this.values.length + '~';
187
190
  };
@@ -36,7 +36,9 @@ export declare class CustomSqlFilterBuilder {
36
36
  private r;
37
37
  constructor(r: SqlCommandWithParameters);
38
38
  sql: string;
39
- addParameterAndReturnSqlToken<valueType>(val: valueType, field?: FieldMetadata<valueType>): string;
39
+ /** @deprecated @deprecated use `param` instead*/
40
+ addParameterAndReturnSqlToken(val: any): string;
41
+ param<valueType>(val: valueType, field?: FieldMetadata<valueType>): string;
40
42
  filterToRaw<entityType>(repo: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<string>;
41
43
  }
42
44
  export declare function isDbReadonly<entityType>(field: FieldMetadata, dbNames: EntityDbNames<entityType>): boolean;
@@ -135,9 +135,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
135
135
  this.addToWhere(this.nameProvider.$dbNameOf(col) +
136
136
  ' in (' +
137
137
  val
138
- .map(function (x) {
139
- return _this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(x));
140
- })
138
+ .map(function (x) { return _this.r.param(col.valueConverter.toDb(x)); })
141
139
  .join(',') +
142
140
  ')');
143
141
  else
@@ -199,7 +197,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
199
197
  ' ' +
200
198
  operator +
201
199
  ' ' +
202
- this.r.addParameterAndReturnSqlToken(col.valueConverter.toDb(val));
200
+ this.r.param(col.valueConverter.toDb(val));
203
201
  this.addToWhere(x);
204
202
  return [2 /*return*/];
205
203
  });
@@ -243,10 +241,15 @@ var CustomSqlFilterBuilder = /** @class */ (function () {
243
241
  this.r = r;
244
242
  this.sql = '';
245
243
  }
246
- CustomSqlFilterBuilder.prototype.addParameterAndReturnSqlToken = function (val, field) {
247
- if (field)
244
+ /** @deprecated @deprecated use `param` instead*/
245
+ CustomSqlFilterBuilder.prototype.addParameterAndReturnSqlToken = function (val) {
246
+ return this.param(val);
247
+ };
248
+ CustomSqlFilterBuilder.prototype.param = function (val, field) {
249
+ if (typeof field === 'object' && field.valueConverter.toDb) {
248
250
  val = field.valueConverter.toDb(val);
249
- return this.r.addParameterAndReturnSqlToken(val);
251
+ }
252
+ return this.r.param(val);
250
253
  };
251
254
  CustomSqlFilterBuilder.prototype.filterToRaw = function (repo, condition) {
252
255
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -17,6 +17,10 @@ export declare class RepositoryImplementation<entityType> implements Repository<
17
17
  private dataProvider;
18
18
  private _info;
19
19
  private defaultFindOptions?;
20
+ notFoundError(id: any): {
21
+ message: string;
22
+ httpStatusCode: number;
23
+ };
20
24
  [getInternalKey](): this;
21
25
  createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
22
26
  relations(item: entityType): RepositoryRelations<entityType>;
@@ -47,6 +47,12 @@ var RepositoryImplementation = /** @class */ (function () {
47
47
  this.idCache = new Map();
48
48
  this.cache = new Map();
49
49
  }
50
+ RepositoryImplementation.prototype.notFoundError = function (id) {
51
+ return {
52
+ message: "id ".concat(id, " not found in entity ").concat(this.metadata.key),
53
+ httpStatusCode: 404,
54
+ };
55
+ };
50
56
  RepositoryImplementation.prototype[repository_internals_js_1.getInternalKey] = function () {
51
57
  return this;
52
58
  };
@@ -253,7 +259,8 @@ var RepositoryImplementation = /** @class */ (function () {
253
259
  case 1: return [4 /*yield*/, this.findId(item)];
254
260
  case 2:
255
261
  ref2_1 = _a.sent();
256
- if (!ref2_1) return [3 /*break*/, 4];
262
+ if (!ref2_1)
263
+ throw this.notFoundError(item);
257
264
  return [4 /*yield*/, (0, getEntityRef_js_1.getEntityRef)(ref2_1).delete()];
258
265
  case 3: return [2 /*return*/, _a.sent()];
259
266
  case 4:
@@ -411,7 +418,7 @@ var RepositoryImplementation = /** @class */ (function () {
411
418
  case 5:
412
419
  r = _a.sent();
413
420
  if (!r)
414
- throw new Error('Not Found');
421
+ throw this.notFoundError(ref.id);
415
422
  for (key in entity) {
416
423
  if (Object.prototype.hasOwnProperty.call(entity, key)) {
417
424
  f = ref.fields[key];
@@ -1807,13 +1814,24 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1807
1814
  };
1808
1815
  rowHelperImplementation.prototype.reload = function () {
1809
1816
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1817
+ var _a, _b;
1818
+ var _c;
1810
1819
  var _this = this;
1811
- return tslib_1.__generator(this, function (_a) {
1812
- switch (_a.label) {
1813
- case 0: return [4 /*yield*/, this.edp.find({ where: this.getIdFilter() }).then(function (newData) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1820
+ return tslib_1.__generator(this, function (_d) {
1821
+ switch (_d.label) {
1822
+ case 0:
1823
+ _b = (_a = this.edp)
1824
+ .find;
1825
+ _c = {};
1826
+ return [4 /*yield*/, this.getIdFilter()];
1827
+ case 1: return [4 /*yield*/, _b.apply(_a, [(_c.where = _d.sent(), _c)])
1828
+ .then(function (newData) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1814
1829
  return tslib_1.__generator(this, function (_a) {
1815
1830
  switch (_a.label) {
1816
- case 0: return [4 /*yield*/, this.loadDataFrom(newData[0])];
1831
+ case 0:
1832
+ if (newData.length === 0)
1833
+ throw this.repository.notFoundError(this.id);
1834
+ return [4 /*yield*/, this.loadDataFrom(newData[0])];
1817
1835
  case 1:
1818
1836
  _a.sent();
1819
1837
  this.saveOriginalData();
@@ -1821,8 +1839,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1821
1839
  }
1822
1840
  });
1823
1841
  }); })];
1824
- case 1:
1825
- _a.sent();
1842
+ case 2:
1843
+ _d.sent();
1826
1844
  this._reportChangedToEntityAndFields();
1827
1845
  return [2 /*return*/, this.instance];
1828
1846
  }
@@ -1865,12 +1883,12 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1865
1883
  rowHelperImplementation.prototype.save = function (onlyTheseFieldsSentOnlyInTheCaseOfProxySaveWithPartialObject) {
1866
1884
  var _a;
1867
1885
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1868
- var doNotSave_1, e, _b, _c, col, e_29_1, d, ignoreKeys, _d, _e, field, f, updatedRow, isNew, changesOnly, wasChanged, key, element, _f, _g, listener, e_30_1, err_1;
1869
- var e_29, _h, e_31, _j, e_30, _k;
1870
- return tslib_1.__generator(this, function (_l) {
1871
- switch (_l.label) {
1886
+ var doNotSave_1, e, _b, _c, col, e_29_1, d, ignoreKeys, _d, _e, field, f, updatedRow, isNew, changesOnly, wasChanged, key, element, _f, _g, _h, _j, listener, e_30_1, err_1;
1887
+ var e_29, _k, e_31, _l, _m, e_30, _o;
1888
+ return tslib_1.__generator(this, function (_p) {
1889
+ switch (_p.label) {
1872
1890
  case 0:
1873
- _l.trys.push([0, , 35, 36]);
1891
+ _p.trys.push([0, , 36, 37]);
1874
1892
  if (this._saving)
1875
1893
  throw new Error('cannot save while entity is already saving');
1876
1894
  this._saving = true;
@@ -1883,36 +1901,36 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1883
1901
  return [4 /*yield*/, this.__validateEntity()];
1884
1902
  case 1:
1885
1903
  // no need
1886
- _l.sent();
1887
- _l.label = 2;
1904
+ _p.sent();
1905
+ _p.label = 2;
1888
1906
  case 2:
1889
1907
  doNotSave_1 = false;
1890
1908
  e = this.buildLifeCycleEvent(function () { return (doNotSave_1 = true); });
1891
1909
  if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 12];
1892
- _l.label = 3;
1910
+ _p.label = 3;
1893
1911
  case 3:
1894
- _l.trys.push([3, 8, 9, 10]);
1912
+ _p.trys.push([3, 8, 9, 10]);
1895
1913
  _b = tslib_1.__values(this.fields), _c = _b.next();
1896
- _l.label = 4;
1914
+ _p.label = 4;
1897
1915
  case 4:
1898
1916
  if (!!_c.done) return [3 /*break*/, 7];
1899
1917
  col = _c.value;
1900
1918
  if (!col.metadata.options.saving) return [3 /*break*/, 6];
1901
1919
  return [4 /*yield*/, col.metadata.options.saving(this.instance, col, e)];
1902
1920
  case 5:
1903
- _l.sent();
1904
- _l.label = 6;
1921
+ _p.sent();
1922
+ _p.label = 6;
1905
1923
  case 6:
1906
1924
  _c = _b.next();
1907
1925
  return [3 /*break*/, 4];
1908
1926
  case 7: return [3 /*break*/, 10];
1909
1927
  case 8:
1910
- e_29_1 = _l.sent();
1928
+ e_29_1 = _p.sent();
1911
1929
  e_29 = { error: e_29_1 };
1912
1930
  return [3 /*break*/, 10];
1913
1931
  case 9:
1914
1932
  try {
1915
- if (_c && !_c.done && (_h = _b.return)) _h.call(_b);
1933
+ if (_c && !_c.done && (_k = _b.return)) _k.call(_b);
1916
1934
  }
1917
1935
  finally { if (e_29) throw e_29.error; }
1918
1936
  return [7 /*endfinally*/];
@@ -1920,8 +1938,8 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1920
1938
  if (!this.info.entityInfo.saving) return [3 /*break*/, 12];
1921
1939
  return [4 /*yield*/, this.info.entityInfo.saving(this.instance, e)];
1922
1940
  case 11:
1923
- _l.sent();
1924
- _l.label = 12;
1941
+ _p.sent();
1942
+ _p.label = 12;
1925
1943
  case 12:
1926
1944
  this.__assertValidity();
1927
1945
  d = this.copyDataToObject(this.isNew());
@@ -1943,21 +1961,21 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1943
1961
  catch (e_31_1) { e_31 = { error: e_31_1 }; }
1944
1962
  finally {
1945
1963
  try {
1946
- if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
1964
+ if (_e && !_e.done && (_l = _d.return)) _l.call(_d);
1947
1965
  }
1948
1966
  finally { if (e_31) throw e_31.error; }
1949
1967
  }
1950
1968
  updatedRow = void 0;
1951
1969
  isNew = this.isNew();
1952
- _l.label = 13;
1970
+ _p.label = 13;
1953
1971
  case 13:
1954
- _l.trys.push([13, 32, , 34]);
1972
+ _p.trys.push([13, 33, , 35]);
1955
1973
  (_a = this._subscribers) === null || _a === void 0 ? void 0 : _a.reportChanged();
1956
1974
  if (!this.isNew()) return [3 /*break*/, 15];
1957
1975
  return [4 /*yield*/, this.edp.insert(d)];
1958
1976
  case 14:
1959
- updatedRow = _l.sent();
1960
- return [3 /*break*/, 19];
1977
+ updatedRow = _p.sent();
1978
+ return [3 /*break*/, 20];
1961
1979
  case 15:
1962
1980
  changesOnly = {};
1963
1981
  wasChanged = false;
@@ -1973,71 +1991,74 @@ var rowHelperImplementation = /** @class */ (function (_super) {
1973
1991
  }
1974
1992
  if (!wasChanged)
1975
1993
  return [2 /*return*/, this.instance];
1976
- if (!doNotSave_1) return [3 /*break*/, 17];
1977
- return [4 /*yield*/, this.edp.find({ where: this.getIdFilter() })];
1978
- case 16:
1979
- updatedRow = (_l.sent())[0];
1980
- return [3 /*break*/, 19];
1981
- case 17: return [4 /*yield*/, this.edp.update(this.id, changesOnly)];
1982
- case 18:
1983
- updatedRow = _l.sent();
1984
- _l.label = 19;
1985
- case 19: return [4 /*yield*/, this.loadDataFrom(updatedRow)];
1986
- case 20:
1987
- _l.sent();
1988
- if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 30];
1989
- if (!this.info.entityInfo.saved) return [3 /*break*/, 22];
1990
- return [4 /*yield*/, this.info.entityInfo.saved(this.instance, e)];
1994
+ if (!doNotSave_1) return [3 /*break*/, 18];
1995
+ _g = (_f = this.edp).find;
1996
+ _m = {};
1997
+ return [4 /*yield*/, this.getIdFilter()];
1998
+ case 16: return [4 /*yield*/, _g.apply(_f, [(_m.where = _p.sent(), _m)])];
1999
+ case 17:
2000
+ updatedRow = (_p.sent())[0];
2001
+ return [3 /*break*/, 20];
2002
+ case 18: return [4 /*yield*/, this.edp.update(this.id, changesOnly)];
2003
+ case 19:
2004
+ updatedRow = _p.sent();
2005
+ _p.label = 20;
2006
+ case 20: return [4 /*yield*/, this.loadDataFrom(updatedRow)];
1991
2007
  case 21:
1992
- _l.sent();
1993
- _l.label = 22;
2008
+ _p.sent();
2009
+ if (!!this.remult.dataProvider.isProxy) return [3 /*break*/, 31];
2010
+ if (!this.info.entityInfo.saved) return [3 /*break*/, 23];
2011
+ return [4 /*yield*/, this.info.entityInfo.saved(this.instance, e)];
1994
2012
  case 22:
1995
- if (!this.repository.listeners) return [3 /*break*/, 30];
1996
- _l.label = 23;
2013
+ _p.sent();
2014
+ _p.label = 23;
1997
2015
  case 23:
1998
- _l.trys.push([23, 28, 29, 30]);
1999
- _f = tslib_1.__values(this.repository.listeners.filter(function (x) { return x.saved; })), _g = _f.next();
2000
- _l.label = 24;
2016
+ if (!this.repository.listeners) return [3 /*break*/, 31];
2017
+ _p.label = 24;
2001
2018
  case 24:
2002
- if (!!_g.done) return [3 /*break*/, 27];
2003
- listener = _g.value;
2004
- return [4 /*yield*/, listener.saved(this.instance, isNew)];
2019
+ _p.trys.push([24, 29, 30, 31]);
2020
+ _h = tslib_1.__values(this.repository.listeners.filter(function (x) { return x.saved; })), _j = _h.next();
2021
+ _p.label = 25;
2005
2022
  case 25:
2006
- _l.sent();
2007
- _l.label = 26;
2023
+ if (!!_j.done) return [3 /*break*/, 28];
2024
+ listener = _j.value;
2025
+ return [4 /*yield*/, listener.saved(this.instance, isNew)];
2008
2026
  case 26:
2009
- _g = _f.next();
2010
- return [3 /*break*/, 24];
2011
- case 27: return [3 /*break*/, 30];
2012
- case 28:
2013
- e_30_1 = _l.sent();
2014
- e_30 = { error: e_30_1 };
2015
- return [3 /*break*/, 30];
2027
+ _p.sent();
2028
+ _p.label = 27;
2029
+ case 27:
2030
+ _j = _h.next();
2031
+ return [3 /*break*/, 25];
2032
+ case 28: return [3 /*break*/, 31];
2016
2033
  case 29:
2034
+ e_30_1 = _p.sent();
2035
+ e_30 = { error: e_30_1 };
2036
+ return [3 /*break*/, 31];
2037
+ case 30:
2017
2038
  try {
2018
- if (_g && !_g.done && (_k = _f.return)) _k.call(_f);
2039
+ if (_j && !_j.done && (_o = _h.return)) _o.call(_h);
2019
2040
  }
2020
2041
  finally { if (e_30) throw e_30.error; }
2021
2042
  return [7 /*endfinally*/];
2022
- case 30: return [4 /*yield*/, this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }])];
2023
- case 31:
2024
- _l.sent();
2043
+ case 31: return [4 /*yield*/, this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }])];
2044
+ case 32:
2045
+ _p.sent();
2025
2046
  this.saveOriginalData();
2026
2047
  this._isNew = false;
2027
2048
  return [2 /*return*/, this.instance];
2028
- case 32:
2029
- err_1 = _l.sent();
2030
- return [4 /*yield*/, this.catchSaveErrors(err_1)];
2031
2049
  case 33:
2032
- _l.sent();
2033
- return [3 /*break*/, 34];
2034
- case 34: return [3 /*break*/, 36];
2035
- case 35:
2050
+ err_1 = _p.sent();
2051
+ return [4 /*yield*/, this.catchSaveErrors(err_1)];
2052
+ case 34:
2053
+ _p.sent();
2054
+ return [3 /*break*/, 35];
2055
+ case 35: return [3 /*break*/, 37];
2056
+ case 36:
2036
2057
  this.isLoading = false;
2037
2058
  this._reportChangedToEntityAndFields();
2038
2059
  this._saving = false;
2039
2060
  return [7 /*endfinally*/];
2040
- case 36: return [2 /*return*/];
2061
+ case 37: return [2 /*return*/];
2041
2062
  }
2042
2063
  });
2043
2064
  });
@@ -2057,7 +2078,14 @@ var rowHelperImplementation = /** @class */ (function (_super) {
2057
2078
  };
2058
2079
  };
2059
2080
  rowHelperImplementation.prototype.getIdFilter = function () {
2060
- return filter_interfaces_js_1.Filter.fromEntityFilter(this.metadata, this.repository.metadata.idMetadata.getIdFilter(this.id));
2081
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
2082
+ return tslib_1.__generator(this, function (_a) {
2083
+ switch (_a.label) {
2084
+ case 0: return [4 /*yield*/, this.repository.translateWhereToFilter(this.repository.metadata.idMetadata.getIdFilter(this.id))];
2085
+ case 1: return [2 /*return*/, _a.sent()];
2086
+ }
2087
+ });
2088
+ });
2061
2089
  };
2062
2090
  rowHelperImplementation.prototype.delete = function () {
2063
2091
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -11,10 +11,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
11
  #
12
12
 
13
13
  //y1 - getFields didn't work for kobi in the home component
14
- //p1 - JYC - change name of add parameter and .... to token - param
15
- //p1 - Hint names for sql parameters
14
+
15
+
16
16
  //p1 - add section to Fields doc, explaining field type in db
17
17
  /*p1 - JYC - Delete many, update many, insert many
18
+ //p1 - @jycouet regarding required - are you ok with leaving '' as not a good value? (0 will be a good value)
19
+
18
20
  - post + __action=delet
19
21
  */
20
22
  //p1 - JYC - there should be a required that says not null or undefined, but space, 0 etc... should be ok - NOAM- check if removing zero is good enough
@@ -22,6 +24,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
24
  - soft delete
23
25
  - delete restrict (implicit, or user selected - and if so, how) (delete & update of id)
24
26
 
27
+ */
28
+ /*y1 currency.ts:10 Uncaught TypeError: Currency_1 is not a constructor
29
+
30
+ @ValueListFieldType()
31
+ export class Currency {
32
+ constructor(
33
+ public id: number,
34
+ public caption: string,
35
+ public symbol: string
36
+ ) {}
37
+ static shekel = new Currency(1, 'Shekel', '₪');
38
+ static dollar = new Currency(2, 'Dollar', '$');
39
+ static euro = new Currency(3, 'Euro', '€');
40
+ static pound = new Currency(4, 'Pound', '£');
41
+ static yen = new Currency(5, 'Yen', '¥');
42
+ }
43
+
25
44
  */
26
45
  //y1 - admin url!
27
46
  //y1 - consider sql expression gets a dbnames of it's own (that already has the "tableName" defined correctly) maybe also the filter translator
@@ -32,7 +51,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
51
  //y1 - talk about the parameter issue with backend methods
33
52
  //y1 - select data provider per entity https://discord.com/channels/975754286384418847/976006081748807690/1201415305885397003
34
53
  //y1 - migrations
35
- //y2 - live query refresh of view on table update
54
+ //y1 - live query refresh of view on table update
55
+ //y1 - main vs master
36
56
  //y2 - livequery for findfirst (@JY)
37
57
  /*y2 -
38
58
  //y2 - allow api update only for new rows
@@ -16,7 +16,9 @@ export interface SqlCommand extends SqlCommandWithParameters {
16
16
  execute(sql: string): Promise<SqlResult>;
17
17
  }
18
18
  export interface SqlCommandWithParameters {
19
+ /** @deprecated @deprecated use `param` instead*/
19
20
  addParameterAndReturnSqlToken(val: any): string;
21
+ param(val: any): string;
20
22
  }
21
23
  export interface SqlResult {
22
24
  rows: any[];
package/src/validators.js CHANGED
@@ -8,7 +8,7 @@ var Validators = /** @class */ (function () {
8
8
  var _a;
9
9
  _a = Validators;
10
10
  Validators.required = createValidator(function (_, e) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(_a, function (_b) {
11
- return [2 /*return*/, e.value != null && e.value != undefined && e.value !== '' && e.value != 0];
11
+ return [2 /*return*/, e.value != null && e.value != undefined && e.value !== ''];
12
12
  }); }); }, 'Should not be empty');
13
13
  Validators.unique = createValidator(function (_, e) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
14
14
  var _b;