backend-plus 2.7.0-beta.0 → 2.7.0-beta.2

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.
@@ -2266,7 +2266,9 @@ myOwn.TableGrid.prototype.createRowInsertElements = function createRowInsertElem
2266
2266
  }
2267
2267
  if(value!==null){
2268
2268
  depotForInsert.row[fieldDef.name] = value;
2269
- depotForInsert.rowPendingForUpdate[fieldDef.name] = value;
2269
+ if (fieldDef.inTable) {
2270
+ depotForInsert.rowPendingForUpdate[fieldDef.name] = value;
2271
+ }
2270
2272
  }
2271
2273
  });
2272
2274
  //TODO: mejorar la posición dentro del splice o concluir que no sirve el splice
@@ -1,5 +1,7 @@
1
1
  declare module "backend-plus"{
2
2
 
3
+ type RequireSome<T, K extends keyof T> = T & Required<Pick<T, K>>;
4
+
3
5
  import * as net from "net";
4
6
  import * as express from "express";
5
7
  import {Client} from "pg-promise-strict";
@@ -211,6 +213,7 @@ export interface FieldDefinition extends EditableDbDefinition {
211
213
  exportMetadata?:ExportMetadataDefinition
212
214
  description?:string
213
215
  dataLength?:number
216
+ dataDecimals?:number
214
217
  options?:(string|{option:string|number, label:string})[]
215
218
  inView?:boolean
216
219
  sortMethod?:string
@@ -226,6 +229,11 @@ export interface FieldDefinition extends EditableDbDefinition {
226
229
  sequence?: SequenceDefinition|SequenceMadMaxDefinition
227
230
  format?: string
228
231
  }
232
+ export type FieldDefinitionInternal = RequireSome<FieldDefinition, 'allow'> & {
233
+ isPk:number|null
234
+ tableName:string
235
+ table:string
236
+ }
229
237
  export interface EditableDbDefinition {
230
238
  editable?:boolean
231
239
  allow?:{
@@ -343,8 +351,14 @@ export type TableDefinition = EditableDbDefinition & {
343
351
  parameters?:ProcedureParameter[]
344
352
  }
345
353
  }
354
+ export type TableDefinitionInternal = RequireSome<TableDefinition,
355
+ 'allow'|'sql'
356
+ > & {
357
+ field:Record<string, FieldDefinitionInternal>
358
+ otherTableDefs:Record<string, TableDefinitionInternal>
359
+ }
346
360
  export interface DetailTable { table?: string, fields: FieldsForConnectDetailTable, abr: string, label?: string, refreshParent?:boolean, refreshFromParent?:boolean, wScreen?:string, condition?:string }
347
- export type TableDefinitionFunction = (context: ContextForDump, opts?:any) => TableDefinition;
361
+ export type TableDefinitionFunction = (context: ContextForDump, opts?:any) => TableDefinitionInternal;
348
362
  export type TableItemDef=string|{name:string, path?:string, tableGenerator?:(context:TableContext)=>TableDefinition}
349
363
  // {{name: string; path?:string; fileName?: string; source?: string; tableGenerator?:()=>void; title?:string; mixin?:any[]}} TableItem
350
364
  export interface TableDefinitions {
@@ -601,6 +615,8 @@ export class AppBackend{
601
615
  setLog(opts:{until:string, results?:boolean}):void
602
616
  getDataDumpTransformations(rawData:string):Promise<{rawData:string, prepareTransformationSql:string[], endTransformationSql:string[]}>
603
617
  activeSkinFiles: Set<string>
618
+ /****** internals: */
619
+ transformInput:<T>(fieldDefinition: FieldDefinitionInternal, value:T) => T
604
620
  }
605
621
 
606
622
  }
@@ -3036,7 +3036,9 @@ AppBackend.prototype.dumpDbTableFields = function dumpDbTableFields(tableDef, op
3036
3036
  }
3037
3037
  fields.push(
3038
3038
  ' '+db.quoteIdent(fieldDef.name)+
3039
- ' '+(fieldDef.dataLength?(fieldType=='text'?'varchar':fieldType)+'('+fieldDef.dataLength+')':fieldType)+
3039
+ ' '+(fieldDef.dataLength?(fieldType=='text'?'varchar':fieldType)+'('+fieldDef.dataLength+
3040
+ (fieldDef.dataDecimals?','+fieldDef.dataDecimals:'')
3041
+ +')':fieldType)+
3040
3042
  ( be.specialSqlDefaultExpressions[fieldDef.defaultDbValue] != null ? ' default ' + be.specialSqlDefaultExpressions[fieldDef.defaultDbValue]
3041
3043
  : fieldDef.defaultDbValue != null ? ' default ' + fieldDef.defaultDbValue
3042
3044
  : be.specialSqlDefaultExpressions[fieldDef.specialDefaultValue] != null ? ' default ' + be.specialSqlDefaultExpressions[fieldDef.specialDefaultValue]
@@ -13,6 +13,9 @@ const bestGlobals = require('best-globals');
13
13
 
14
14
  const PANIC_IMPORT = true;
15
15
 
16
+ /** @import { TableDefinitionInternal, ProcedureContext } from './in-backend-plus' */
17
+
18
+
16
19
  var ProcedureTables;
17
20
 
18
21
  /** @type {<T>(x:T)=>NonNullable<T>} */
@@ -21,6 +24,9 @@ var notnull = x =>{
21
24
  return x;
22
25
  };
23
26
 
27
+ /**
28
+ * @param {any} mmm
29
+ */
24
30
  function inlineLog(mmm){ console.log(mmm); return mmm; }
25
31
 
26
32
  ProcedureTables = [
@@ -189,9 +195,18 @@ ProcedureTables = [
189
195
  {name: 'oldRow'},
190
196
  {name: 'status', encoding:'plain'},
191
197
  ],
198
+ /**
199
+ *
200
+ * @param {ProcedureContext} context
201
+ * @param {*} parameters
202
+ * @param {*} files
203
+ * @param {*} opts
204
+ * @returns
205
+ */
192
206
  coreFunction:async function(context, parameters, files, opts){
193
207
  var be=context.be;
194
208
  var mainDefTable=be.tableStructures[parameters.table](context);
209
+ /** @type {'insert'|'update'} */
195
210
  var action=parameters.status=='new'?'insert':'update';
196
211
  if(!mainDefTable.allow[action] && (!opts || !opts.forImport)){
197
212
  throw changing(new Error(action+" not allowed"),{status:403});
@@ -254,6 +269,7 @@ ProcedureTables = [
254
269
  var updates = updatesOthers.filter(u => !u.defTable.saveAfter)
255
270
  .concat(plainUpdate.values.length?[changing({defTable:mainDefTable,main:true},plainUpdate)]:[])
256
271
  .concat(updatesOthers.filter(u => u.defTable.saveAfter));
272
+ /** @type {Record<string, any>} */
257
273
  var globalPrimaryKeyValue={}
258
274
  mainDefTable.primaryKey.forEach(function(name,i){
259
275
  globalPrimaryKeyValue[name]=parameters.primaryKeyValues[i];
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.7.0-beta.0",
4
+ "version": "2.7.0-beta.2",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/backend-plus",
@@ -52,7 +52,7 @@
52
52
  "json4all": "^1.4.4",
53
53
  "lazy-some": "^0.1.0",
54
54
  "like-ar": "^0.5.3",
55
- "login-plus": "^1.8.1",
55
+ "login-plus": "^1.9.0-beta.1",
56
56
  "memorystore": "^1.6.8",
57
57
  "mini-tools": "^1.13.7",
58
58
  "moment": "^2.30.1",
@@ -118,7 +118,8 @@
118
118
  "test-ui": "(npm run prepublish || echo \"continue w/error\") && mocha --reporter spec --single-run --bail test/test-*.js",
119
119
  "test-karma": "(npm run prepublish || echo \"continue w/error\") && mocha --reporter spec --bail test/test-k*.js",
120
120
  "test-why": "node --expose-internals ./node_modules/mocha/bin/_mocha --reporter spec --bail test/test*.js",
121
- "test-ci": "(npm run prepublish || echo \"continue w/error\") && mocha --reporter spec --bail test/test*.js",
121
+ "test-ci": "npm test",
122
+ "test-cov": "(npm run prepublish || echo \"continue w/error\") && mocha --reporter spec --bail test/test*.js",
122
123
  "test-good": "mocha --reporter spec --bail --check-leaks test/test*.js",
123
124
  "example-pu": "node test/puppeteer/first-step.js",
124
125
  "test-pu": "node ./test/download_puppeteer && mocha --reporter spec --bail --check-leaks --globals cptable --globals QUOTE --globals __core-js_shared__ test/test-pu.js",