masterrecord 1.1.4 → 1.1.6

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.
Files changed (41) hide show
  1. package/CHANGES.md +24 -0
  2. package/Entity/entityModelBuilder.js +7 -7
  3. package/Entity/entityTrackerModel.js +15 -15
  4. package/Migrations/cli.js +126 -121
  5. package/Migrations/migrationMySQLQuery.js +21 -27
  6. package/Migrations/migrationPostgresQuery.js +16 -16
  7. package/Migrations/migrationSQLiteQuery.js +14 -14
  8. package/Migrations/migrations.js +41 -45
  9. package/Migrations/schema.js +3 -3
  10. package/QueryLanguage/queryMethods.js +26 -26
  11. package/QueryLanguage/queryScript.js +28 -28
  12. package/SQLLiteEngine.js +116 -118
  13. package/Tools.js +19 -19
  14. package/context.js +1 -1
  15. package/mySQLEngine.js +3 -3
  16. package/package.json +22 -2
  17. package/postgresEngine.js +6 -6
  18. package/.claude/settings.local.json +0 -10
  19. package/Migrations/pathUtils.test.js +0 -37
  20. package/eslint.config.js +0 -40
  21. package/prettier.config.js +0 -22
  22. package/test/belongs-to-fk-setter.test.js +0 -154
  23. package/test/belongs-to-fk-type.test.js +0 -253
  24. package/test/broad-audit.test.js +0 -256
  25. package/test/context-errors.test.js +0 -43
  26. package/test/count-chained-where.test.js +0 -136
  27. package/test/count-no-from-audit.test.js +0 -124
  28. package/test/ctx-dollar-placeholder.test.js +0 -142
  29. package/test/drop-column-idempotent.test.js +0 -181
  30. package/test/edge-cases-audit.test.js +0 -180
  31. package/test/esm-imports.test.js +0 -110
  32. package/test/full-text-search.test.js +0 -340
  33. package/test/migration-template.test.js +0 -47
  34. package/test/new-setter-large-string.test.js +0 -191
  35. package/test/pool-key.test.js +0 -43
  36. package/test/postgres-camelcase-quoting.test.js +0 -249
  37. package/test/query-builder-parity.test.js +0 -260
  38. package/test/setter-and-update-drop.test.js +0 -168
  39. package/test/sqlite-lifecycle.test.js +0 -76
  40. package/test/text-types.test.js +0 -167
  41. package/test/update-database-multi.test.js +0 -239
@@ -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,10 @@ 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
+ const $that = this;
605
+ for (const fieldName in this.__entity) {
606
606
  if(!fieldName.startsWith("__")){
607
- var field = this.__entity[fieldName];
607
+ const field = this.__entity[fieldName];
608
608
  // Skip navigational properties (relationships)
609
609
  if(!field.isNavigational && field.type !== "hasMany" && field.type !== "hasOne" && field.type !== "hasManyThrough"){
610
610
  (function(fname, fieldDef){
@@ -616,7 +616,7 @@ class queryMethods{
616
616
  if (fieldDef && fieldDef.validators && Array.isArray(fieldDef.validators)) {
617
617
  for (const validator of fieldDef.validators) {
618
618
  let isValid = true;
619
- let errorMsg = validator.message;
619
+ const errorMsg = validator.message;
620
620
 
621
621
  switch (validator.type) {
622
622
  case 'required':
@@ -989,7 +989,7 @@ class queryMethods{
989
989
 
990
990
  removeRange(entityValues){
991
991
  for (const property in entityValues) {
992
- var entityValue = entityValues[property];
992
+ const entityValue = entityValues[property];
993
993
  entityValue.__state = "delete";
994
994
  entityValue.__entity = this.__entity;
995
995
  entityValue.__context = this.__context;
@@ -117,10 +117,10 @@ class queryScript{
117
117
 
118
118
  buildScript(text, type, obj, entityName){
119
119
 
120
- var cachedExpr = {}; // this function will just get the high level
120
+ const cachedExpr = {}; // this function will just get the high level
121
121
 
122
122
  /// first we find all the groups in the query string
123
- var querySections = this.getFunctionsInQuery(text);
123
+ const querySections = this.getFunctionsInQuery(text);
124
124
 
125
125
  // remove spaces from query and get the Entity
126
126
  cachedExpr.entity = this.getEntity(text);
@@ -213,10 +213,10 @@ class queryScript{
213
213
  // `(p) => p.name == ...` — the previous regex only matched bare
214
214
  // identifiers and silently mis-parsed parens as the entity name,
215
215
  // 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]*(?:\})?)/);
216
+ const match = text.match(/^\s*(?:\(\s*([\w\d$_]+)[^)]*\)|([\w\d$_]+))\s*=>((?:\{\sreturn\s)?[\s\S]*(?:\})?)/);
217
217
  if(match){
218
218
  const entity = match[1] || match[2];
219
- let exprStr = match[3];
219
+ const exprStr = match[3];
220
220
  const fields = [];
221
221
 
222
222
  exprStr.replace(new RegExp(entity + "\\.([\\w_]+)", "g"), function (_, field) {
@@ -246,7 +246,7 @@ class queryScript{
246
246
 
247
247
  splitGroupsByLogicalOperators(text) {
248
248
  let parts = {}, tmp;
249
- var part = {query : text, name : "query"}
249
+ const part = {query : text, name : "query"}
250
250
 
251
251
  //tmp = this.splitByLogicalOperators(part.query, entityRegExp)
252
252
  tmp = this.extractInside(part.query, part.name);
@@ -299,7 +299,7 @@ class queryScript{
299
299
  }
300
300
 
301
301
  getParentField(text, funcName){
302
- var split = text.split(".");
302
+ const split = text.split(".");
303
303
  for (let i = 0; i < split.length; i++) {
304
304
 
305
305
  if(split[i].includes(funcName)){
@@ -322,18 +322,18 @@ class queryScript{
322
322
  describeExpressionPartsFunctions(cachedExpr, functions){
323
323
  cachedExpr.functions = [];
324
324
  if(functions.length > 0){
325
- for (let item in functions) {
325
+ for (const item in functions) {
326
326
 
327
- var part = functions[item];
328
- var partQuery = part.inside;
327
+ const part = functions[item];
328
+ const partQuery = part.inside;
329
329
  // get entity of inside function
330
- var entity = this.getEntity(partQuery);
330
+ const entity = this.getEntity(partQuery);
331
331
 
332
332
  part.entity = entity;
333
333
 
334
334
  // is the function name white listed
335
335
  if(this.isFunction(part.name)){
336
- var scriptInner = {
336
+ const scriptInner = {
337
337
  select : false,
338
338
  where: false,
339
339
  and : [],
@@ -408,23 +408,23 @@ class queryScript{
408
408
  describeExpressionParts(parts) {
409
409
  if(parts.query) {
410
410
  let match, fields, func, arg;
411
- var part = {};
411
+ const part = {};
412
412
  part.inside = parts.query.query;
413
413
  part.expressions = [];
414
- var partQuery = part.inside;
415
- var entity = this.getEntity(partQuery);
416
- var exprPartRegExp = this.OPERATORS_REGEX(entity);
414
+ const partQuery = part.inside;
415
+ const entity = this.getEntity(partQuery);
416
+ const exprPartRegExp = this.OPERATORS_REGEX(entity);
417
417
  // check if query contains an AND.
418
- var normalized = partQuery.replace(/\s+/g, ' ').trim();
419
- var splitByAnd = normalized.split(/\sand\s/);
418
+ const normalized = partQuery.replace(/\s+/g, ' ').trim();
419
+ const splitByAnd = normalized.split(/\sand\s/);
420
420
  let groupId = 0;
421
- for (let splitAnds in splitByAnd) {
422
- let token = splitByAnd[splitAnds];
421
+ for (const splitAnds in splitByAnd) {
422
+ const token = splitByAnd[splitAnds];
423
423
  // Split possible OR groups inside this AND segment
424
- let orParts = token.split(/\sor\s/);
424
+ const orParts = token.split(/\sor\s/);
425
425
  const hasOrGroup = orParts.length > 1;
426
- let currentGroup = hasOrGroup ? (++groupId) : null;
427
- for (let idx in orParts){
426
+ const currentGroup = hasOrGroup ? (++groupId) : null;
427
+ for (const idx in orParts){
428
428
  let segment = orParts[idx];
429
429
  // strip wrapping parentheses pairs repeatedly
430
430
  segment = segment.trim();
@@ -438,7 +438,7 @@ class queryScript{
438
438
  isNegated = true;
439
439
  segment = segment.replace(/^\s*!+\s*/, '');
440
440
  }
441
- if (match = segment.match(exprPartRegExp)) {
441
+ if ((match = segment.match(exprPartRegExp))) {
442
442
  fields = match[1].split(".");
443
443
  func = (match[2] ? fields[fields.length - 1] : (match[3] || "exists"));
444
444
  if (func == "==" || func == "===") {
@@ -486,13 +486,13 @@ class queryScript{
486
486
  return m[1] || m[2];
487
487
  }
488
488
  // Fallback to previous behavior: first non-space char
489
- var clean = str.replace(/\s/g, '');
489
+ const clean = str.replace(/\s/g, '');
490
490
  return clean.substring(0, 1);
491
491
  }
492
492
 
493
493
  isMapped(name, maps){
494
- for (let item in maps) {
495
- var map = maps[item];
494
+ for (const item in maps) {
495
+ const map = maps[item];
496
496
  if(tools.capitalizeFirstLetter(name) === map.name){
497
497
  return true
498
498
  }
@@ -525,8 +525,8 @@ class queryScript{
525
525
  }
526
526
 
527
527
  isFunction(func){
528
- var funcList = [ "include", "like", "any"]
529
- for(var i =0; i < funcList.length; i++){
528
+ const funcList = [ "include", "like", "any"]
529
+ for(let i =0; i < funcList.length; i++){
530
530
  if(funcList[i] === func){
531
531
  return true
532
532
  }