masterrecord 1.1.5 → 1.1.7

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.
@@ -538,9 +538,9 @@ class schema{
538
538
  if(this.fullTable){
539
539
  if(this.context.isSQLite){
540
540
  var queryBuilder = new sqliteQuery();
541
- var tableSchema = (this._tableObj && this._tableObj[table.tableName]) || this.fullTable.new;
542
- var queryObj = queryBuilder.alterColumn(tableSchema, table);
543
- for (var key in queryObj) {
541
+ const tableSchema = (this._tableObj && this._tableObj[table.tableName]) || this.fullTable.new;
542
+ const queryObj = queryBuilder.alterColumn(tableSchema, table);
543
+ for (const key in queryObj) {
544
544
  var query = queryObj[key];
545
545
  await this.context._execute(query);
546
546
  }
@@ -15,10 +15,10 @@ class queryMethods{
15
15
 
16
16
  // build a single entity
17
17
  __singleEntityBuilder(dataModel){
18
- var $that = this;
18
+ const $that = this;
19
19
  if(dataModel){
20
- var ent = new entityTrackerModel();
21
- var mod = ent.build(dataModel, $that.__entity, $that.__context);
20
+ const ent = new entityTrackerModel();
21
+ const mod = ent.build(dataModel, $that.__entity, $that.__context);
22
22
  mod.__state = "track";
23
23
  $that.__context.__track(mod);
24
24
  return mod;
@@ -29,8 +29,8 @@ class queryMethods{
29
29
 
30
30
  // build multiple entities
31
31
  __multipleEntityBuilder(entityValue){
32
- var $that = this;
33
- var listArray = [];
32
+ const $that = this;
33
+ const listArray = [];
34
34
  if(entityValue){
35
35
  for(let i = 0; i < entityValue.length; i++){
36
36
  listArray.push($that.__singleEntityBuilder(entityValue[i]));
@@ -61,28 +61,28 @@ class queryMethods{
61
61
  }
62
62
 
63
63
  ______orderByCount(query, ...args){
64
- var str = query.toString();
64
+ let str = query.toString();
65
65
  str = this.__validateAndCollectParameters(str, args, 'orderByCount');
66
66
  this.__queryObject.orderByCount(str, this.__entity.__name);
67
67
  return this;
68
68
  }
69
69
 
70
70
  ______orderByCountDescending(query, ...args){
71
- var str = query.toString();
71
+ let str = query.toString();
72
72
  str = this.__validateAndCollectParameters(str, args, 'orderByCountDescending');
73
73
  this.__queryObject.orderByCountDesc(str, this.__entity.__name);
74
74
  return this;
75
75
  }
76
76
 
77
77
  orderBy(query, ...args){
78
- var str = query.toString();
78
+ let str = query.toString();
79
79
  str = this.__validateAndCollectParameters(str, args, 'orderBy');
80
80
  this.__queryObject.orderBy(str, this.__entity.__name);
81
81
  return this;
82
82
  }
83
83
 
84
84
  orderByDescending(query, ...args){
85
- var str = query.toString();
85
+ let str = query.toString();
86
86
  str = this.__validateAndCollectParameters(str, args, 'orderByDescending');
87
87
  this.__queryObject.orderByDesc(str, this.__entity.__name);
88
88
  return this;
@@ -112,9 +112,9 @@ class queryMethods{
112
112
 
113
113
  /* WHERE and AND work together its a way to add to the WHERE CLAUSE DYNAMICALLY */
114
114
  and(query, ...args){
115
- var str = query.toString();
115
+ let str = query.toString();
116
116
  // Transform .includes() syntax to .any() syntax
117
- var transformResult = this.__transformIncludes(str, args);
117
+ const transformResult = this.__transformIncludes(str, args);
118
118
  str = transformResult.query;
119
119
  args = transformResult.args;
120
120
  str = this.__validateAndCollectParameters(str, args, 'and');
@@ -123,9 +123,9 @@ class queryMethods{
123
123
  }
124
124
 
125
125
  where(query, ...args){
126
- var str = query.toString();
126
+ let str = query.toString();
127
127
  // Transform .includes() syntax to .any() syntax
128
- var transformResult = this.__transformIncludes(str, args);
128
+ const transformResult = this.__transformIncludes(str, args);
129
129
  str = transformResult.query;
130
130
  args = transformResult.args;
131
131
  str = this.__validateAndCollectParameters(str, args, 'where');
@@ -136,7 +136,7 @@ class queryMethods{
136
136
  // when you dont want to use lazy loading and want it called at that moment
137
137
  //Eagerly loading
138
138
  include(query, ...args){
139
- var str = query.toString();
139
+ let str = query.toString();
140
140
  str = this.__validateAndCollectParameters(str, args, 'include');
141
141
  this.__queryObject.include(str, this.__entity.__name);
142
142
  return this;
@@ -144,7 +144,7 @@ class queryMethods{
144
144
 
145
145
  // only takes a array of selected items
146
146
  select(query, ...args){
147
- var str = query.toString();
147
+ let str = query.toString();
148
148
  str = this.__validateAndCollectParameters(str, args, 'select');
149
149
  this.__queryObject.select(str, this.__entity.__name);
150
150
  return this;
@@ -213,7 +213,7 @@ class queryMethods{
213
213
 
214
214
  async count(query, ...args){
215
215
  if(query){
216
- var str = query.toString();
216
+ let str = query.toString();
217
217
  str = this.__validateAndCollectParameters(str, args, 'count');
218
218
  this.__queryObject.count(str, this.__entity.__name);
219
219
  }
@@ -386,8 +386,8 @@ class queryMethods{
386
386
 
387
387
  // Replace $$ with ? placeholders and collect parameter values
388
388
  if(args){
389
- for(let argument in args){
390
- var item = args[argument];
389
+ for(const argument in args){
390
+ const item = args[argument];
391
391
  if(typeof item === 'undefined'){
392
392
  const msg = `Query argument error in ${methodName}: placeholder value at index ${argument} is undefined.`;
393
393
  console.error(msg);
@@ -504,7 +504,7 @@ class queryMethods{
504
504
 
505
505
  // Cache miss - execute query
506
506
  await this.__context._ensureReady();
507
- var result = null;
507
+ let result = null;
508
508
  if(this.__context.isSQLite){
509
509
  var entityValue = await this.__context._SQLEngine.get(this.__queryObject.script, this.__entity, this.__context);
510
510
  result = this.__singleEntityBuilder(entityValue);
@@ -557,7 +557,7 @@ class queryMethods{
557
557
 
558
558
  // Cache miss - execute query
559
559
  await this.__context._ensureReady();
560
- var result = [];
560
+ let result = [];
561
561
  if(this.__context.isSQLite){
562
562
  var entityValue = await this.__context._SQLEngine.all(this.__queryObject.script, this.__entity, this.__context);
563
563
  result = this.__multipleEntityBuilder(entityValue);
@@ -590,7 +590,7 @@ class queryMethods{
590
590
  // Creates a new empty entity instance ready for insertion
591
591
  // Returns an object with property setters that track changes
592
592
  new(){
593
- var newEntity = {
593
+ const newEntity = {
594
594
  __ID : Math.floor((Math.random() * 100000) + 1),
595
595
  __dirtyFields : [],
596
596
  __state : "insert",
@@ -601,10 +601,9 @@ class queryMethods{
601
601
  };
602
602
 
603
603
  // Set up property setters for all entity fields
604
- var $that = this;
605
- for (var fieldName in this.__entity) {
604
+ for (const fieldName in this.__entity) {
606
605
  if(!fieldName.startsWith("__")){
607
- var field = this.__entity[fieldName];
606
+ const field = this.__entity[fieldName];
608
607
  // Skip navigational properties (relationships)
609
608
  if(!field.isNavigational && field.type !== "hasMany" && field.type !== "hasOne" && field.type !== "hasManyThrough"){
610
609
  (function(fname, fieldDef){
@@ -616,7 +615,7 @@ class queryMethods{
616
615
  if (fieldDef && fieldDef.validators && Array.isArray(fieldDef.validators)) {
617
616
  for (const validator of fieldDef.validators) {
618
617
  let isValid = true;
619
- let errorMsg = validator.message;
618
+ const errorMsg = validator.message;
620
619
 
621
620
  switch (validator.type) {
622
621
  case 'required':
@@ -802,7 +801,7 @@ class queryMethods{
802
801
  if (!isRelationship) {
803
802
  try {
804
803
  plain[fieldName] = this[fieldName];
805
- } catch (e) {
804
+ } catch (_e) {
806
805
  // Skip fields that throw errors when accessed
807
806
  }
808
807
  }
@@ -836,7 +835,7 @@ class queryMethods{
836
835
  _visited: visited
837
836
  });
838
837
  }
839
- } catch (e) {
838
+ } catch (_e) {
840
839
  // Skip relationships that throw errors when accessed
841
840
  }
842
841
  }
@@ -989,7 +988,7 @@ class queryMethods{
989
988
 
990
989
  removeRange(entityValues){
991
990
  for (const property in entityValues) {
992
- var entityValue = entityValues[property];
991
+ const entityValue = entityValues[property];
993
992
  entityValue.__state = "delete";
994
993
  entityValue.__entity = this.__entity;
995
994
  entityValue.__context = this.__context;
@@ -3,8 +3,6 @@
3
3
  import tools from '../Tools.js';
4
4
  import QueryParameters from './queryParameters.js';
5
5
 
6
- const LOG_OPERATORS_REGEX = /(\|\|)|(&&)/;
7
-
8
6
  // Escape special regex characters so user-supplied names can be safely
9
7
  // interpolated into RegExp constructors (prevents "Unmatched ')'" etc.)
10
8
  function escapeRegExp(str) {
@@ -117,10 +115,10 @@ class queryScript{
117
115
 
118
116
  buildScript(text, type, obj, entityName){
119
117
 
120
- var cachedExpr = {}; // this function will just get the high level
118
+ const cachedExpr = {}; // this function will just get the high level
121
119
 
122
120
  /// first we find all the groups in the query string
123
- var querySections = this.getFunctionsInQuery(text);
121
+ const querySections = this.getFunctionsInQuery(text);
124
122
 
125
123
  // remove spaces from query and get the Entity
126
124
  cachedExpr.entity = this.getEntity(text);
@@ -213,10 +211,10 @@ class queryScript{
213
211
  // `(p) => p.name == ...` — the previous regex only matched bare
214
212
  // identifiers and silently mis-parsed parens as the entity name,
215
213
  // producing SQL like `SELECT (.id, (.name FROM Plugin AS (`.
216
- var match = text.match(/^\s*(?:\(\s*([\w\d$_]+)[^)]*\)|([\w\d$_]+))\s*=>((?:\{\sreturn\s)?[\s\S]*(?:\})?)/);
214
+ const match = text.match(/^\s*(?:\(\s*([\w\d$_]+)[^)]*\)|([\w\d$_]+))\s*=>((?:\{\sreturn\s)?[\s\S]*(?:\})?)/);
217
215
  if(match){
218
216
  const entity = match[1] || match[2];
219
- let exprStr = match[3];
217
+ const exprStr = match[3];
220
218
  const fields = [];
221
219
 
222
220
  exprStr.replace(new RegExp(entity + "\\.([\\w_]+)", "g"), function (_, field) {
@@ -245,11 +243,11 @@ class queryScript{
245
243
 
246
244
 
247
245
  splitGroupsByLogicalOperators(text) {
248
- let parts = {}, tmp;
249
- var part = {query : text, name : "query"}
246
+ const parts = {};
247
+ const part = {query : text, name : "query"}
250
248
 
251
249
  //tmp = this.splitByLogicalOperators(part.query, entityRegExp)
252
- tmp = this.extractInside(part.query, part.name);
250
+ const tmp = this.extractInside(part.query, part.name);
253
251
  if(tmp){
254
252
  part.inside = tmp;
255
253
  parts[part.name] = part;
@@ -299,7 +297,7 @@ class queryScript{
299
297
  }
300
298
 
301
299
  getParentField(text, funcName){
302
- var split = text.split(".");
300
+ const split = text.split(".");
303
301
  for (let i = 0; i < split.length; i++) {
304
302
 
305
303
  if(split[i].includes(funcName)){
@@ -322,18 +320,18 @@ class queryScript{
322
320
  describeExpressionPartsFunctions(cachedExpr, functions){
323
321
  cachedExpr.functions = [];
324
322
  if(functions.length > 0){
325
- for (let item in functions) {
323
+ for (const item in functions) {
326
324
 
327
- var part = functions[item];
328
- var partQuery = part.inside;
325
+ const part = functions[item];
326
+ const partQuery = part.inside;
329
327
  // get entity of inside function
330
- var entity = this.getEntity(partQuery);
328
+ const entity = this.getEntity(partQuery);
331
329
 
332
330
  part.entity = entity;
333
331
 
334
332
  // is the function name white listed
335
333
  if(this.isFunction(part.name)){
336
- var scriptInner = {
334
+ const scriptInner = {
337
335
  select : false,
338
336
  where: false,
339
337
  and : [],
@@ -408,23 +406,23 @@ class queryScript{
408
406
  describeExpressionParts(parts) {
409
407
  if(parts.query) {
410
408
  let match, fields, func, arg;
411
- var part = {};
409
+ const part = {};
412
410
  part.inside = parts.query.query;
413
411
  part.expressions = [];
414
- var partQuery = part.inside;
415
- var entity = this.getEntity(partQuery);
416
- var exprPartRegExp = this.OPERATORS_REGEX(entity);
412
+ const partQuery = part.inside;
413
+ const entity = this.getEntity(partQuery);
414
+ const exprPartRegExp = this.OPERATORS_REGEX(entity);
417
415
  // check if query contains an AND.
418
- var normalized = partQuery.replace(/\s+/g, ' ').trim();
419
- var splitByAnd = normalized.split(/\sand\s/);
416
+ const normalized = partQuery.replace(/\s+/g, ' ').trim();
417
+ const splitByAnd = normalized.split(/\sand\s/);
420
418
  let groupId = 0;
421
- for (let splitAnds in splitByAnd) {
422
- let token = splitByAnd[splitAnds];
419
+ for (const splitAnds in splitByAnd) {
420
+ const token = splitByAnd[splitAnds];
423
421
  // Split possible OR groups inside this AND segment
424
- let orParts = token.split(/\sor\s/);
422
+ const orParts = token.split(/\sor\s/);
425
423
  const hasOrGroup = orParts.length > 1;
426
- let currentGroup = hasOrGroup ? (++groupId) : null;
427
- for (let idx in orParts){
424
+ const currentGroup = hasOrGroup ? (++groupId) : null;
425
+ for (const idx in orParts){
428
426
  let segment = orParts[idx];
429
427
  // strip wrapping parentheses pairs repeatedly
430
428
  segment = segment.trim();
@@ -438,20 +436,20 @@ class queryScript{
438
436
  isNegated = true;
439
437
  segment = segment.replace(/^\s*!+\s*/, '');
440
438
  }
441
- if (match = segment.match(exprPartRegExp)) {
439
+ if ((match = segment.match(exprPartRegExp))) {
442
440
  fields = match[1].split(".");
443
441
  func = (match[2] ? fields[fields.length - 1] : (match[3] || "exists"));
444
- if (func == "==" || func == "===") {
442
+ if (func === "==" || func === "===") {
445
443
  func = "=";
446
444
  }
447
- else if (func == "!==") {
445
+ else if (func === "!==") {
448
446
  func = "!=";
449
447
  }
450
448
  arg = match[2] || match[4];
451
- if (arg == "true" || arg == "false") {
452
- arg = arg == "true";
449
+ if (arg === "true" || arg === "false") {
450
+ arg = arg === "true";
453
451
  }
454
- else if (arg && arg.charAt(0) == arg.charAt(arg.length - 1) && (arg.charAt(0) == "'" || arg.charAt(0) == '"')) {
452
+ else if (arg && arg.charAt(0) === arg.charAt(arg.length - 1) && (arg.charAt(0) === "'" || arg.charAt(0) === '"')) {
455
453
  arg = arg.slice(1, -1);
456
454
  }
457
455
  part.entity = entity;
@@ -486,13 +484,13 @@ class queryScript{
486
484
  return m[1] || m[2];
487
485
  }
488
486
  // Fallback to previous behavior: first non-space char
489
- var clean = str.replace(/\s/g, '');
487
+ const clean = str.replace(/\s/g, '');
490
488
  return clean.substring(0, 1);
491
489
  }
492
490
 
493
491
  isMapped(name, maps){
494
- for (let item in maps) {
495
- var map = maps[item];
492
+ for (const item in maps) {
493
+ const map = maps[item];
496
494
  if(tools.capitalizeFirstLetter(name) === map.name){
497
495
  return true
498
496
  }
@@ -525,8 +523,8 @@ class queryScript{
525
523
  }
526
524
 
527
525
  isFunction(func){
528
- var funcList = [ "include", "like", "any"]
529
- for(var i =0; i < funcList.length; i++){
526
+ const funcList = [ "include", "like", "any"]
527
+ for(let i =0; i < funcList.length; i++){
530
528
  if(funcList[i] === func){
531
529
  return true
532
530
  }