backend-plus 2.0.0-rc.17 → 2.0.0-rc.19
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/for-client/my-tables.js +13 -17
- package/for-client/my-websqldb.d.ts +0 -1
- package/lib/backend-plus.d.ts +10 -7
- package/lib/procedures-table.js +37 -13
- package/package.json +9 -9
package/for-client/my-tables.js
CHANGED
|
@@ -183,20 +183,15 @@ myOwn.i18n.messages.es=changing(myOwn.i18n.messages.es, {
|
|
|
183
183
|
/** @param {string} text */
|
|
184
184
|
function regex4search(text){
|
|
185
185
|
return new RegExp(
|
|
186
|
-
text.trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
186
|
+
text.toString().trim().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
187
187
|
// .replace(/"/g,"\\b")
|
|
188
188
|
.replace(/[ñÑ]/g,'(?:gn|nn?i?|[ñÑ])')
|
|
189
|
-
.replace(/[cCçÇ]/g,'[
|
|
190
|
-
.replace(/[
|
|
191
|
-
.replace(/[
|
|
192
|
-
.replace(/[
|
|
193
|
-
.replace(/[
|
|
194
|
-
.replace(/[
|
|
195
|
-
.replace(/a/gi,'[AáÁàÀäÄãÃ]')
|
|
196
|
-
.replace(/e/gi,'[EéÉèÈëË]')
|
|
197
|
-
.replace(/i/gi,'[IíÍìÌïÏ]')
|
|
198
|
-
.replace(/o/gi,'[OóÓòÒöÖõÕ]')
|
|
199
|
-
.replace(/u/gi,'[UúÚùÙüÜ]')
|
|
189
|
+
.replace(/[cCçÇ]/g,'[cCçÇ]')
|
|
190
|
+
.replace(/[AáÁàÀäÄãÃ]/gi,'[AáÁàÀäÄãÃ]')
|
|
191
|
+
.replace(/[EéÉèÈëË]/gi,'[EéÉèÈëË]')
|
|
192
|
+
.replace(/[IíÍìÌïÏ]/gi,'[IíÍìÌïÏ]')
|
|
193
|
+
.replace(/[OóÓòÒöÖõÕ]/gi,'[OóÓòÒöÖõÕ]')
|
|
194
|
+
.replace(/[UúÚùÙüÜ]/gi,'[UúÚùÙüÜ]')
|
|
200
195
|
// .replace(/\s+/g,'.*\\s+.*') mas estricto, exige el espacio
|
|
201
196
|
.replace(/\s+/g,'.*')
|
|
202
197
|
, 'i');
|
|
@@ -212,9 +207,9 @@ myOwn.comparatorParameterNull={
|
|
|
212
207
|
'!=\u2205':true,
|
|
213
208
|
}
|
|
214
209
|
myOwn.comparator={
|
|
215
|
-
'=':function(valueToCheck,condition){return valueToCheck
|
|
216
|
-
'~':function(valueToCheck,condition){return condition==null ||
|
|
217
|
-
'!~':function(valueToCheck,condition){return condition==null ||
|
|
210
|
+
'=':function(valueToCheck,condition){return sameValue(valueToCheck,condition);},
|
|
211
|
+
'~': function(valueToCheck,condition){return condition==null || condition instanceof Date ? Math.abs(condition-valueToCheck) <= 1000*60*60*24 : regex4search(condition).test(valueToCheck);},
|
|
212
|
+
'!~':function(valueToCheck,condition){return condition==null || condition instanceof Date ? Math.abs(condition-valueToCheck) > 1000*60*60*24 :!regex4search(condition).test(valueToCheck);},
|
|
218
213
|
'/R/i':function(valueToCheck,condition){return condition==null || RegExp(condition,'i').test(valueToCheck);},
|
|
219
214
|
'\u2205':function(valueToCheck,condition){return valueToCheck == null;},//\u2205 = conjunto vacío
|
|
220
215
|
'!=\u2205':function(valueToCheck,condition){return valueToCheck != null;},//\u2205 = conjunto vacío
|
|
@@ -1005,7 +1000,7 @@ myOwn.DataColumnGrid.prototype.thFilter = function thFilter(depot, iColumn){
|
|
|
1005
1000
|
var grid = this.grid;
|
|
1006
1001
|
var fieldDef = this.fieldDef;
|
|
1007
1002
|
var fieldName=fieldDef.name;
|
|
1008
|
-
depot.rowSymbols[fieldDef.name]=depot.rowSymbols[fieldDef.name]||'~';
|
|
1003
|
+
depot.rowSymbols[fieldDef.name]=depot.rowSymbols[fieldDef.name]||(fieldDef.typeName == 'text' ? '~' : '=');
|
|
1009
1004
|
var filterImage=my.path.img+my.comparator.traductor[depot.rowSymbols[fieldDef.name]]+'.png';
|
|
1010
1005
|
var th=html.td(this.cellAttributes({class:"autoFilter", "typed-controls-direct-input":true},{skipMandatory:true})).create();
|
|
1011
1006
|
var symbolFilter=th;
|
|
@@ -2253,7 +2248,8 @@ myOwn.TableGrid.prototype.createRowInsertElements = function createRowInsertElem
|
|
|
2253
2248
|
}
|
|
2254
2249
|
var depotForInsert = grid.createDepotFromRow({$allow:{delete:true, update:true}}, 'new');
|
|
2255
2250
|
grid.connector.fixedFields.forEach(function(pair){
|
|
2256
|
-
|
|
2251
|
+
var fieldDef = grid.def.field[pair.fieldName];
|
|
2252
|
+
if(!pair.range && (fieldDef.inTable !== false || fieldDef.isPk && pair.value !=null)){
|
|
2257
2253
|
depotForInsert.row[pair.fieldName] = pair.value;
|
|
2258
2254
|
depotForInsert.rowPendingForUpdate[pair.fieldName] = pair.value;
|
|
2259
2255
|
}
|
package/lib/backend-plus.d.ts
CHANGED
|
@@ -257,16 +257,17 @@ export type TableDefinition = EditableDbDefinition & {
|
|
|
257
257
|
tableName?:string
|
|
258
258
|
schema?:string
|
|
259
259
|
title?:string
|
|
260
|
-
fields:FieldDefinition[]
|
|
261
|
-
primaryKey:string[]
|
|
262
|
-
refrescable?: boolean
|
|
260
|
+
fields:FieldDefinition[]
|
|
261
|
+
primaryKey:string[]
|
|
262
|
+
refrescable?: boolean
|
|
263
263
|
sql?:{
|
|
264
|
+
primaryKey4Delete?:string[]
|
|
264
265
|
isTable?:boolean
|
|
265
266
|
from?:string
|
|
266
267
|
where?:string
|
|
267
268
|
postCreateSqls?:string
|
|
268
|
-
skipEnance?: boolean
|
|
269
|
-
isReferable?: boolean
|
|
269
|
+
skipEnance?: boolean
|
|
270
|
+
isReferable?: boolean
|
|
270
271
|
logicalDeletes?:{
|
|
271
272
|
fieldName:string
|
|
272
273
|
valueToDelete:string
|
|
@@ -275,11 +276,12 @@ export type TableDefinition = EditableDbDefinition & {
|
|
|
275
276
|
fieldName:string
|
|
276
277
|
}
|
|
277
278
|
tableName?:string
|
|
279
|
+
tableName4Delete?:string
|
|
278
280
|
fields?:{
|
|
279
281
|
[k:string]:{
|
|
280
282
|
expr:string
|
|
281
283
|
}
|
|
282
|
-
}
|
|
284
|
+
}
|
|
283
285
|
orderBy?:string[]
|
|
284
286
|
viewBody?:string
|
|
285
287
|
insertIfNotUpdate?:boolean
|
|
@@ -293,6 +295,7 @@ export type TableDefinition = EditableDbDefinition & {
|
|
|
293
295
|
join?:string
|
|
294
296
|
constraintsDeferred?:boolean
|
|
295
297
|
otherTableDefs?:OtherTableDefs
|
|
298
|
+
setExpectedPkValues?:boolean
|
|
296
299
|
}
|
|
297
300
|
foreignKeys?:ForeignKey[]
|
|
298
301
|
softForeignKeys?:ForeignKey[]
|
|
@@ -318,7 +321,7 @@ export type TableDefinition = EditableDbDefinition & {
|
|
|
318
321
|
specialValidator?:string
|
|
319
322
|
saveAfter?:boolean
|
|
320
323
|
selfRefresh?:boolean
|
|
321
|
-
filterColumns?:{column:string, operator:string, value:any}[]
|
|
324
|
+
filterColumns?:{column:string, operator:string, value:any}[]
|
|
322
325
|
gridAlias?:string /* front-end css my-table = gridAlias */
|
|
323
326
|
}
|
|
324
327
|
export interface DetailTable { table?: string, fields: FieldsForConnectDetailTable, abr: string, label?: string, refreshParent?:boolean, refreshFromParent?:boolean, wScreen?:string, condition?:string }
|
package/lib/procedures-table.js
CHANGED
|
@@ -201,7 +201,7 @@ ProcedureTables = [
|
|
|
201
201
|
tables:{},
|
|
202
202
|
tableNames:{}
|
|
203
203
|
};
|
|
204
|
-
var expectedMainPrimaryKeyValues=parameters.primaryKeyValues;
|
|
204
|
+
var expectedMainPrimaryKeyValues = parameters.primaryKeyValues;
|
|
205
205
|
/** @type { TableUpdater } */
|
|
206
206
|
// @ts-expect-error parece no asignada pero al menos un nombre hay en el ciclo y por lo tanto va a tener valor
|
|
207
207
|
var updateTarget = {}
|
|
@@ -257,6 +257,7 @@ ProcedureTables = [
|
|
|
257
257
|
});
|
|
258
258
|
var result;
|
|
259
259
|
var mainResult;
|
|
260
|
+
var initialUpdatesLength = updates.length;
|
|
260
261
|
while(updates.length){
|
|
261
262
|
var {fieldNames, values, defTable, main} = notnull(updates.shift());
|
|
262
263
|
var values4Insert = values.slice(0);
|
|
@@ -272,7 +273,7 @@ ProcedureTables = [
|
|
|
272
273
|
values4Insert[i] = value;
|
|
273
274
|
}
|
|
274
275
|
}
|
|
275
|
-
if(defField.generatedAs){
|
|
276
|
+
if(defField.generatedAs || defField.inTable === false){
|
|
276
277
|
var i = fieldNames4Insert.indexOf(defField.name);
|
|
277
278
|
if(i!==-1){
|
|
278
279
|
fieldNames4Insert.splice(i,1);
|
|
@@ -284,10 +285,11 @@ ProcedureTables = [
|
|
|
284
285
|
var primaryKeyValues=[]
|
|
285
286
|
var primaryKeyValuesForUpdate=[]
|
|
286
287
|
var primaryKeyValueObject={};
|
|
288
|
+
var fieldNames4InsertWithoutPkAddings = fieldNames4Insert.slice(0);
|
|
287
289
|
defTable.primaryKey.forEach(function(name,i){
|
|
288
290
|
var value = main?parameters.primaryKeyValues[i]:coalesce(parameters.newRow[name],parameters.oldRow[name],undefined);
|
|
291
|
+
var defField = defTable.field[name];
|
|
289
292
|
if(value===undefined){
|
|
290
|
-
var defField = defTable.field[name];
|
|
291
293
|
value = defTable.prefilledField && name in defTable.prefilledField ? defTable.prefilledField[name] : (
|
|
292
294
|
'defaultValue' in defField?defField.defaultValue:(
|
|
293
295
|
'specialDefaultValue' in defField?new Error("my.specialDefaultValue[defField.specialDefaultValue](name, {row:{}}, {row:previousRow})"):undefined
|
|
@@ -304,13 +306,16 @@ ProcedureTables = [
|
|
|
304
306
|
}else{
|
|
305
307
|
primaryKeyValuesForUpdate[i]=value;
|
|
306
308
|
}
|
|
307
|
-
if(!fieldNames4Insert.includes(name) && value != null){
|
|
309
|
+
if(!fieldNames4Insert.includes(name) && value != null && defField.inTable !== false){
|
|
308
310
|
fieldNames4Insert.push(name);
|
|
309
311
|
values4Insert.push(value);
|
|
310
312
|
}
|
|
311
313
|
});
|
|
312
|
-
if(main){
|
|
313
|
-
expectedMainPrimaryKeyValues=primaryKeyValues;
|
|
314
|
+
if (main) {
|
|
315
|
+
expectedMainPrimaryKeyValues = primaryKeyValues;
|
|
316
|
+
} else if (defTable.sql.setExpectedPkValues) {
|
|
317
|
+
expectedMainPrimaryKeyValues = primaryKeyValues.slice(0);
|
|
318
|
+
while (expectedMainPrimaryKeyValues.length < mainDefTable.primaryKey.length) expectedMainPrimaryKeyValues.push(null);
|
|
314
319
|
}
|
|
315
320
|
var returningClausule='';
|
|
316
321
|
if(opts && opts.forImport){
|
|
@@ -331,7 +336,9 @@ ProcedureTables = [
|
|
|
331
336
|
return result;
|
|
332
337
|
}
|
|
333
338
|
var sql;
|
|
334
|
-
if(defTable &&
|
|
339
|
+
if (defTable?.sql?.isTable === false && initialUpdatesLength > 1 && fieldNames4InsertWithoutPkAddings.length == 0) {
|
|
340
|
+
// New feature. Ignore attempts to save to non tables when pseudo tables save in others
|
|
341
|
+
} else if(defTable && parameters.status=='new'){
|
|
335
342
|
result = await insertFun();
|
|
336
343
|
}else if(defTable && primaryKeyValues.length==defTable.primaryKey.length){
|
|
337
344
|
var values4Update = [];
|
|
@@ -400,6 +407,12 @@ ProcedureTables = [
|
|
|
400
407
|
var rowFrom = parameters.status!='new' && !plainUpdate.values.length?
|
|
401
408
|
likeAr.toPlainObject(mainDefTable.primaryKey,expectedMainPrimaryKeyValues):
|
|
402
409
|
(mainResult||result).row;
|
|
410
|
+
for (var fieldname of mainDefTable.primaryKey) {
|
|
411
|
+
if (rowFrom[fieldname] == null) {
|
|
412
|
+
var newValue = parameters.newRow[fieldname] ?? parameters.oldRow[fieldname];
|
|
413
|
+
if (newValue != null) rowFrom[fieldname] = newValue
|
|
414
|
+
}
|
|
415
|
+
}
|
|
403
416
|
result = await be.queryValuesOfUniqueRow(context, mainDefTable, rowFrom);
|
|
404
417
|
}
|
|
405
418
|
return {command:insertOrUpdate, row:result.row};
|
|
@@ -417,16 +430,26 @@ ProcedureTables = [
|
|
|
417
430
|
if(!defTable.allow.delete){
|
|
418
431
|
throw changing(new Error("Deletes not allowed"),{status:403});
|
|
419
432
|
}
|
|
420
|
-
|
|
421
|
-
|
|
433
|
+
if (defTable.primaryKey4Delete) {
|
|
434
|
+
console.log("DEPRECATED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! defTable.primaryKey4Delete", defTable.name);
|
|
435
|
+
}
|
|
436
|
+
var primaryKeyFields = defTable.primaryKey4Delete ?? defTable.sql.primaryKey4Delete ?? defTable.primaryKey;
|
|
437
|
+
var primaryKeyValues = [];
|
|
438
|
+
var tableName4Delete = defTable.sql.tableName4Delete ?? defTable.sql.tableName;
|
|
439
|
+
for (var fieldName of primaryKeyFields) {
|
|
440
|
+
var pos = defTable.primaryKey.indexOf(fieldName);
|
|
441
|
+
if (pos > -1) {
|
|
442
|
+
primaryKeyValues.push(parameters.primaryKeyValues[pos]);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
422
445
|
if(defTable && primaryKeyValues.length==primaryKeyFields.length){
|
|
423
446
|
var sqlDelete;
|
|
424
447
|
if(defTable.sql.logicalDeletes){
|
|
425
|
-
sqlDelete="UPDATE "+be.db.quoteIdent(
|
|
448
|
+
sqlDelete="UPDATE "+be.db.quoteIdent(tableName4Delete)+
|
|
426
449
|
" SET "+be.db.quoteIdent(defTable.sql.logicalDeletes.fieldName)+
|
|
427
450
|
" = "+be.db.quoteNullable(defTable.sql.logicalDeletes.valueToDelete);
|
|
428
451
|
}else{
|
|
429
|
-
sqlDelete="DELETE FROM "+be.db.quoteIdent(
|
|
452
|
+
sqlDelete="DELETE FROM "+be.db.quoteIdent(tableName4Delete);
|
|
430
453
|
}
|
|
431
454
|
sqlDelete+=" WHERE "+primaryKeyFields.map(function(fieldName, i){
|
|
432
455
|
return be.db.quoteIdent(fieldName)+" = $"+(i+1);
|
|
@@ -453,6 +476,7 @@ ProcedureTables = [
|
|
|
453
476
|
context.informProgress({message:be.messages.server.deleting})
|
|
454
477
|
var be=context.be;
|
|
455
478
|
var defTable=be.tableStructures[parameters.table](context);
|
|
479
|
+
var tableName4Delete = defTable.sql.tableName4Delete ?? defTable.sql.tableName;
|
|
456
480
|
if(!defTable.allow.delete && !defTable.allow.deleteAll){
|
|
457
481
|
throw changing(new Error("Deletes not allowed"),{status:403});
|
|
458
482
|
}
|
|
@@ -480,7 +504,7 @@ ProcedureTables = [
|
|
|
480
504
|
}
|
|
481
505
|
});
|
|
482
506
|
return context.client.query(
|
|
483
|
-
"DELETE FROM "+be.db.quoteIdent(
|
|
507
|
+
"DELETE FROM "+be.db.quoteIdent(tableName4Delete)+
|
|
484
508
|
" WHERE "+whereParts.join(" AND ")+" RETURNING 1",
|
|
485
509
|
dataParams
|
|
486
510
|
).fetchUniqueRow().then(function(){
|
|
@@ -490,7 +514,7 @@ ProcedureTables = [
|
|
|
490
514
|
};
|
|
491
515
|
var result = await Promise.all(parameters.rowsToDelete.map(deleteOneRow)).then(function(){
|
|
492
516
|
return context.client.query(
|
|
493
|
-
"SELECT count(*) remaining_record_count FROM "+be.db.quoteIdent(
|
|
517
|
+
"SELECT count(*) remaining_record_count FROM "+be.db.quoteIdent(tableName4Delete)
|
|
494
518
|
).fetchUniqueRow().then(function(result){
|
|
495
519
|
context.informProgress({lengthComputable:true, loaded:deleteCounter, total:parameters.rowsToDelete.length, force:true});
|
|
496
520
|
return result.row;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-plus",
|
|
3
3
|
"description": "Backend for the anti Pareto rule",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.19",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/backend-plus",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@upgraded/locate-path": "^6.0.0-alfa.1",
|
|
33
33
|
"ajax-best-promise": "^0.4.2",
|
|
34
34
|
"backend-skins": "^0.1.15",
|
|
35
|
-
"best-globals": "^1.1.
|
|
35
|
+
"best-globals": "^1.1.6",
|
|
36
36
|
"big.js": "^6.2.1",
|
|
37
37
|
"body-parser": "^1.20.2",
|
|
38
38
|
"cast-error": "^0.1.1",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"mini-tools": "^1.12.1",
|
|
56
56
|
"moment": "^2.30.1",
|
|
57
57
|
"multiparty": "^4.2.3",
|
|
58
|
-
"nodemailer": "^6.9.
|
|
58
|
+
"nodemailer": "^6.9.14",
|
|
59
59
|
"numeral": "^2.0.6",
|
|
60
60
|
"pg-promise-strict": "^1.4.0",
|
|
61
61
|
"pikaday": "^1.8.2",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"@types/express-useragent": "^1.0.5",
|
|
81
81
|
"@types/fs-extra": "^11.0.4",
|
|
82
82
|
"@types/js-yaml": "^4.0.9",
|
|
83
|
-
"@types/mocha": "^10.0.
|
|
83
|
+
"@types/mocha": "^10.0.7",
|
|
84
84
|
"@types/multiparty": "~0.0.36",
|
|
85
|
-
"@types/node": "^20.14.
|
|
85
|
+
"@types/node": "^20.14.9",
|
|
86
86
|
"@types/nodemailer": "^6.4.15",
|
|
87
87
|
"@types/numeral": "~2.0.5",
|
|
88
88
|
"@types/session-file-store": "^1.2.5",
|
|
@@ -97,13 +97,13 @@
|
|
|
97
97
|
"karma-ie-launcher": "^1.0.0",
|
|
98
98
|
"karma-mocha": "^2.0.1",
|
|
99
99
|
"kill-9": "~0.4.3",
|
|
100
|
-
"mocha": "^10.
|
|
101
|
-
"nyc": "^
|
|
102
|
-
"puppeteer": "^22.
|
|
100
|
+
"mocha": "^10.5.2",
|
|
101
|
+
"nyc": "^17.0.0",
|
|
102
|
+
"puppeteer": "^22.12.1",
|
|
103
103
|
"sinon": "^18.0.0",
|
|
104
104
|
"supertest": "^7.0.0",
|
|
105
105
|
"types.d.ts": "~0.6.21",
|
|
106
|
-
"typescript": "^5.
|
|
106
|
+
"typescript": "^5.5.2",
|
|
107
107
|
"why-is-node-running": "^2.2.2"
|
|
108
108
|
},
|
|
109
109
|
"engines": {
|