backend-plus 2.5.2-betha.14 → 2.5.2-betha.16
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 +3 -0
- package/lib/backend-plus.d.ts +3 -2
- package/lib/backend-plus.js +50 -40
- package/package.json +2 -2
package/for-client/my-tables.js
CHANGED
|
@@ -2203,6 +2203,9 @@ myOwn.specialDefaultValue={
|
|
|
2203
2203
|
return belowDepot.row[fieldName]?belowDepot.row[fieldName]+1:(
|
|
2204
2204
|
aboveDepot.row[fieldName]?aboveDepot.row[fieldName]-1:1
|
|
2205
2205
|
);
|
|
2206
|
+
},
|
|
2207
|
+
current_user: function specialDefaultValueCurrentUser(){
|
|
2208
|
+
return my.config.username;
|
|
2206
2209
|
}
|
|
2207
2210
|
}
|
|
2208
2211
|
|
package/lib/backend-plus.d.ts
CHANGED
|
@@ -188,6 +188,7 @@ export type FieldDefinition = EditableDbDefinition & {
|
|
|
188
188
|
dbNullable?:boolean /* dbNullable === false is not nullabla at DB level, but not at CLIENT LEVEL */
|
|
189
189
|
defaultValue?:any
|
|
190
190
|
defaultDbValue?:PgKnownDbValues|string
|
|
191
|
+
specialDefaultValue?:string /* keyof myOwn.specialDefaultValues and/or keyof AppBackend.prototype.specialSqlDefaultExpressions */
|
|
191
192
|
clientSide?:string /* keyof: myOwn.clientSides */
|
|
192
193
|
isName?:boolean|'known' /* is a name but it is a well known name (because the user uses it to thier code or because the code is enugh expresive)
|
|
193
194
|
isPk?:number /* internal: pos in the primaryKey array */
|
|
@@ -204,7 +205,6 @@ export type FieldDefinition = EditableDbDefinition & {
|
|
|
204
205
|
references?:string /* table name */
|
|
205
206
|
referencesField?:string
|
|
206
207
|
aggregate?:'avg'|'sum'|'count'|'min'|'max'|'countTrue' /* keyof myOwn.TableAggregates */
|
|
207
|
-
specialDefaultValue?:string /* keyof myOwn.specialDefaultValues
|
|
208
208
|
defaultForOtherFields?:boolean /* the field that stores the "other fields" of a flexible imported table */
|
|
209
209
|
specialValueWhenInsert?:string
|
|
210
210
|
exportMetadata?:ExportMetadataDefinition
|
|
@@ -548,6 +548,7 @@ export class AppBackend{
|
|
|
548
548
|
dbUserNameExpr:string
|
|
549
549
|
dbUserRolExpr:string
|
|
550
550
|
specialValueWhenInsert:{[k:string]:(context:ProcedureContext, defField:FieldDefinition, parameters:object)=>any}
|
|
551
|
+
specialSqlDefaultExpressions:Record<string, string>
|
|
551
552
|
clearCaches():void
|
|
552
553
|
start(opts?: StartOptions):Promise<void>
|
|
553
554
|
getTables():TableItemDef[]
|
|
@@ -586,7 +587,7 @@ export class AppBackend{
|
|
|
586
587
|
messages:Record<LangId,Record<string, string>>
|
|
587
588
|
}
|
|
588
589
|
shutdownCallbackListAdd(param:{message:string, fun:()=>Promise<void>}):void
|
|
589
|
-
shutdownBackend():Promise<void>
|
|
590
|
+
shutdownBackend(opts?:{skipTurnOff?:boolean, onlyTurnOff?:boolean}):Promise<void>
|
|
590
591
|
setLog(opts:{until:string, results?:boolean}):void
|
|
591
592
|
getDataDumpTransformations(rawData:string):Promise<{rawData:string, prepareTransformationSql:string[], endTransformationSql:string[]}>
|
|
592
593
|
}
|
package/lib/backend-plus.js
CHANGED
|
@@ -643,33 +643,42 @@ AppBackend.prototype.start = function start(opts){
|
|
|
643
643
|
// @ts-ignore : only for testing */
|
|
644
644
|
this.getMainApp = function getMainApp(){ return mainApp; };
|
|
645
645
|
}
|
|
646
|
-
this.shutdownBackend = async function shutdownBackend(){
|
|
647
|
-
|
|
648
|
-
var
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
646
|
+
this.shutdownBackend = async function shutdownBackend(opts){
|
|
647
|
+
var shootingDown = opts == null || !opts.onlyTurnOff;
|
|
648
|
+
var turningOff = opts == null || !opts.skipTurnOff;
|
|
649
|
+
if(!shootingDown){
|
|
650
|
+
console.log('shooting down:');
|
|
651
|
+
var waitFor = [
|
|
652
|
+
new Promise(function(resolve,reject){
|
|
653
|
+
console.log('*','express server');
|
|
654
|
+
be.server.close(/** @param {Error} err */function(err){
|
|
655
|
+
if(err){
|
|
656
|
+
console.log('*', err)
|
|
657
|
+
reject(err);
|
|
658
|
+
}else{
|
|
659
|
+
console.log('*','express server done!')
|
|
660
|
+
resolve();
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}),
|
|
664
|
+
...(be.shutdownCallbackList.map(x => (async function(){
|
|
665
|
+
console.log('shut:', x.message)
|
|
666
|
+
await x.fun()
|
|
667
|
+
console.log('done:', x.message)
|
|
668
|
+
})())),
|
|
669
|
+
];
|
|
670
|
+
console.log('*', 'waiting for all')
|
|
671
|
+
await Promise.all(waitFor);
|
|
672
|
+
console.log('*', 'all done')
|
|
673
|
+
mainApp = null;
|
|
674
|
+
}
|
|
675
|
+
if(turningOff){
|
|
676
|
+
console.log('turning off:');
|
|
677
|
+
await pg.shutdown();
|
|
678
|
+
console.log('pg shutdown done!');
|
|
679
|
+
console.log('* logWhy',logWhy)
|
|
680
|
+
logWhy && logWhy();
|
|
681
|
+
}
|
|
673
682
|
};
|
|
674
683
|
return Promise.resolve().then(function(){
|
|
675
684
|
var configList=be.configList();
|
|
@@ -802,7 +811,7 @@ AppBackend.prototype.start = function start(opts){
|
|
|
802
811
|
}
|
|
803
812
|
}).then(function(client){
|
|
804
813
|
if(username){
|
|
805
|
-
return client.query(`
|
|
814
|
+
return client.query(`CALL set_app_user(${be.db.quoteLiteral(username)})`).execute().then(function(){
|
|
806
815
|
return client;
|
|
807
816
|
});
|
|
808
817
|
}else{
|
|
@@ -1008,12 +1017,6 @@ AppBackend.prototype.start = function start(opts){
|
|
|
1008
1017
|
mainApp.loginPlusManager.closeManager();
|
|
1009
1018
|
}
|
|
1010
1019
|
});
|
|
1011
|
-
be.shutdownCallbackListAdd({
|
|
1012
|
-
message:'pg',
|
|
1013
|
-
fun:function(){
|
|
1014
|
-
pg.shutdown();
|
|
1015
|
-
}
|
|
1016
|
-
});
|
|
1017
1020
|
mainApp.loginPlusManager.setValidatorStrategy(
|
|
1018
1021
|
function(req, username, password, done) {
|
|
1019
1022
|
var client;
|
|
@@ -1022,7 +1025,7 @@ AppBackend.prototype.start = function start(opts){
|
|
|
1022
1025
|
}
|
|
1023
1026
|
be.getDbClient(req).then(function(cli){
|
|
1024
1027
|
client = cli;
|
|
1025
|
-
return client.query("
|
|
1028
|
+
return client.query("CALL set_app_user('!login')").execute();
|
|
1026
1029
|
}).then(function(){
|
|
1027
1030
|
var infoFieldList=be.config.login.infoFieldList||(be.config.login.rolFieldName?[be.config.login.userFieldName,be.config.login.rolFieldName]:[be.config.login.userFieldName]);
|
|
1028
1031
|
return client.query(
|
|
@@ -1237,6 +1240,10 @@ AppBackend.prototype.specialValueWhenInsert = {
|
|
|
1237
1240
|
}
|
|
1238
1241
|
}
|
|
1239
1242
|
|
|
1243
|
+
AppBackend.prototype.specialSqlDefaultExpressions = {
|
|
1244
|
+
'current_user': 'get_app_user()',
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1240
1247
|
AppBackend.prototype.checkDatabaseStructure = async function checkDatabaseStructure(client){
|
|
1241
1248
|
var be=this;
|
|
1242
1249
|
var result = await client.query(`select setting from pg_settings where name='server_version';`).fetchUniqueValue();
|
|
@@ -2681,8 +2688,12 @@ AppBackend.prototype.dumpDbTableFields = function dumpDbTableFields(tableDef, op
|
|
|
2681
2688
|
fields.push(
|
|
2682
2689
|
' '+db.quoteIdent(fieldDef.name)+
|
|
2683
2690
|
' '+(fieldDef.dataLength?(fieldType=='text'?'varchar':fieldType)+'('+fieldDef.dataLength+')':fieldType)+
|
|
2684
|
-
(fieldDef.
|
|
2685
|
-
|
|
2691
|
+
( be.specialSqlDefaultExpressions[fieldDef.defaultDbValue] != null ? ' default ' + be.specialSqlDefaultExpressions[fieldDef.defaultDbValue]
|
|
2692
|
+
: fieldDef.defaultDbValue != null ? ' default ' + fieldDef.defaultDbValue
|
|
2693
|
+
: be.specialSqlDefaultExpressions[fieldDef.specialDefaultValue] != null ? ' default ' + be.specialSqlDefaultExpressions[fieldDef.specialDefaultValue]
|
|
2694
|
+
: fieldDef.defaultValue != null ? ' default ' + db.quoteLiteral(fieldDef.defaultValue)
|
|
2695
|
+
: ''
|
|
2696
|
+
) +
|
|
2686
2697
|
(be.isGeneratedSequence(fieldDef.sequence)?' generated always as identity':'')+
|
|
2687
2698
|
(fieldDef.generatedAs!=null?` generated always as (${fieldDef.generatedAs}) stored`:'')
|
|
2688
2699
|
);
|
|
@@ -2972,8 +2983,8 @@ AppBackend.prototype.dumpDbSchemaPartial = async function dumpDbSchemaPartial(pa
|
|
|
2972
2983
|
}
|
|
2973
2984
|
}
|
|
2974
2985
|
lines.push(`
|
|
2975
|
-
create or replace
|
|
2976
|
-
security definer
|
|
2986
|
+
create or replace procedure set_app_user(p_user text)
|
|
2987
|
+
security definer language plpgsql
|
|
2977
2988
|
as
|
|
2978
2989
|
$body$
|
|
2979
2990
|
declare
|
|
@@ -3000,7 +3011,6 @@ begin
|
|
|
3000
3011
|
set backend_plus._mode = normal;
|
|
3001
3012
|
end if;
|
|
3002
3013
|
perform set_config('backend_plus._user', p_user, false);
|
|
3003
|
-
return p_user;
|
|
3004
3014
|
end;
|
|
3005
3015
|
$body$;
|
|
3006
3016
|
|
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.5.2-betha.
|
|
4
|
+
"version": "2.5.2-betha.16",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/backend-plus",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"sinon": "^21.0.0",
|
|
107
107
|
"supertest": "^7.1.4",
|
|
108
108
|
"types.d.ts": "~0.6.22",
|
|
109
|
-
"typescript": "^5.
|
|
109
|
+
"typescript": "^5.9.2",
|
|
110
110
|
"why-is-node-running": "^3.2.2"
|
|
111
111
|
},
|
|
112
112
|
"engines": {
|