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
package/CHANGES.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # MasterRecord Changelog
2
2
 
3
+ ## v1.1.6 — lint-driven bug fixes + ESLint tooling
4
+
5
+ Set up ESLint (flat config, eslint 9 + `globals.node`) with a `lint`/`lint:check` script and ran it across the codebase. Beyond the mechanical `var`→`const`/`let` autofix (safe; full test suite still green), the lint surfaced several genuine bugs, now fixed:
6
+
7
+ - **CLI rollback-to-target was broken.** The migration rollback handler in `Migrations/cli.js` referenced `contextAbs` without ever defining it (every other handler does `const contextAbs = path.resolve(snapDir, contextSnapshot.contextLocation)`), so the command threw `ReferenceError` the moment it tried to load the context. Added the missing resolution.
8
+ - **SQLite multi-field UPDATE could drop SET clauses.** `SQLLiteEngine` had two `case "belongsTo"` blocks in the UPDATE builder (a duplicate-case). The one that won **overwrote** the accumulated `argument` instead of appending — so an UPDATE touching a `belongsTo` field plus other fields would lose the other `SET` assignments. Fixed to append and removed the dead duplicate.
9
+ - **`migrations.js` dead/broken branches.** `template()` had `if (item.old === null)` / `if (item.new === null)` blocks referencing an undefined `column`; old/new are always `{}` or an object (never `null`), so they never ran — removed.
10
+ - **`MasterValidator` (mastercontroller sibling pattern)** — n/a here; see mastercontroller 2.0.6.
11
+ - Removed unreachable `break` statements after `return` in `migrationMySQLQuery.boolType`, a no-op self-assignment in `SQLLiteEngine`, and wrapped an intentional assignment-in-condition in `queryScript` to satisfy `no-cond-assign`.
12
+
13
+ Runtime behavior is unchanged except where noted (the bug fixes). Test suite: green (same single pre-existing `count-no-from-audit` failure as prior releases).
14
+
15
+ > Note: a number of non-functional stylistic lint findings remain (legacy `var`/`no-redeclare`-heavy internals). These are being addressed separately to avoid risky mechanical rewrites of engine paths that aren't covered by the local (SQLite-only) test run.
16
+
17
+ ## v1.1.5 — clean npm tarball: add a `files` allowlist
18
+
19
+ The package had no `files` field, so `npm publish` swept the whole working tree. The 1.1.4 tarball shipped `.claude/settings.local.json` (a local editor-settings file that should never have been published), all 20 `test/*.test.js` files, test fixtures, and the eslint/prettier configs — none of which belong in a consumed package.
20
+
21
+ - Added a `files` allowlist: top-level `*.js`, `Cache/`, `Entity/`, `QueryLanguage/`, `Migrations/` runtime modules, `docs/`, `CHANGES.md`, `LICENSE` (npm always also includes `readme.md` and `package.json`). `bin` (`Migrations/cli.js`) still ships.
22
+ - Excluded `**/*.test.js` (including the colocated `Migrations/pathUtils.test.js`) and the dev configs via `files` negation patterns.
23
+ - Added `.claude/` to `.gitignore`.
24
+
25
+ Result: tarball dropped from publishing ~65 files to 42 — runtime code + docs only. No source/API changes; runtime behavior is identical to 1.1.4.
26
+
3
27
  ## v1.1.4 — re-publish: include the entityTrackerModel.js fix that 1.1.3 missed
4
28
 
5
29
  v1.1.3's commit dropped one of the two files it was supposed to ship — the `Entity/entityTrackerModel.js` change. macOS's case-insensitive filesystem combined with git's case-sensitive index: the file is tracked as `Entity/EntityTrackerModel.js` (capital E), the disk had `entityTrackerModel.js` (lowercase e), and `git add Entity/entityTrackerModel.js` silently no-op'd against the capital-E tracked path.
@@ -9,10 +9,10 @@ class EntityModelBuilder {
9
9
  if(model.name === undefined){
10
10
  throw "dbset model declaired incorrectly. Check you dbset models for code errors."
11
11
  }
12
- var mod = new model(); //create new instance of Entity Model
13
- var obj = {};
14
- var methodNamesArray = Object.getOwnPropertyNames( mod.__proto__ );
15
- var constructorIndex = methodNamesArray.indexOf("constructor");
12
+ const mod = new model(); //create new instance of Entity Model
13
+ const obj = {};
14
+ const methodNamesArray = Object.getOwnPropertyNames( mod.__proto__ );
15
+ const constructorIndex = methodNamesArray.indexOf("constructor");
16
16
  // remove contructor method
17
17
  if (constructorIndex > -1) {
18
18
  methodNamesArray.splice(constructorIndex, 1);
@@ -22,7 +22,7 @@ class EntityModelBuilder {
22
22
  const lifecycleHooks = ['beforeSave', 'afterSave', 'beforeDelete', 'afterDelete'];
23
23
 
24
24
  // loop through all method names in the entity model
25
- for (var i = 0; i < methodNamesArray.length; i++) {
25
+ for (let i = 0; i < methodNamesArray.length; i++) {
26
26
  const methodName = methodNamesArray[i];
27
27
 
28
28
  // Skip lifecycle hooks - they should not be called during entity construction
@@ -37,7 +37,7 @@ class EntityModelBuilder {
37
37
  continue;
38
38
  }
39
39
 
40
- let MDB = new modelDB(model.name); // create a new instance of entity Model class
40
+ const MDB = new modelDB(model.name); // create a new instance of entity Model class
41
41
  mod[methodName](MDB);
42
42
  this.cleanNull(MDB.obj); // remove objects that are null or undefined
43
43
  if(Object.keys(MDB.obj).length === 0){
@@ -61,7 +61,7 @@ class EntityModelBuilder {
61
61
  }
62
62
 
63
63
  static cleanNull(obj) {
64
- for (var propName in obj) {
64
+ for (const propName in obj) {
65
65
  if (obj[propName] === null) {
66
66
  delete obj[propName];
67
67
  }
@@ -10,8 +10,8 @@ class EntityTrackerModel {
10
10
 
11
11
  // start tracking model
12
12
  build(dataModel, currentEntity, context){
13
- var $that = this;
14
- var modelClass = this.buildObject(); // build entity with models
13
+ const $that = this;
14
+ const modelClass = this.buildObject(); // build entity with models
15
15
  modelClass.__proto__ = {};
16
16
  const modelFields = Object.entries(dataModel); /// return array of objects
17
17
 
@@ -63,7 +63,7 @@ class EntityTrackerModel {
63
63
  if (fieldDef && fieldDef.validators && Array.isArray(fieldDef.validators)) {
64
64
  for (const validator of fieldDef.validators) {
65
65
  let isValid = true;
66
- let errorMsg = validator.message;
66
+ const errorMsg = validator.message;
67
67
 
68
68
  switch (validator.type) {
69
69
  case 'required':
@@ -420,7 +420,7 @@ class EntityTrackerModel {
420
420
  }
421
421
 
422
422
  buildRelationshipModels(modelClass, currentEntity, currentModel){
423
- var $that = this;
423
+ const $that = this;
424
424
  // loop though current entity and add only relationship models to this list
425
425
  const entityFields = Object.entries(currentEntity);
426
426
  for (const [entityField, entityFieldValue] of entityFields) { // loop through entity values
@@ -438,9 +438,9 @@ class EntityTrackerModel {
438
438
  this["__proto__"]["_" + entityField] = value;
439
439
  },
440
440
  get : function(){
441
- var ent = tools.findEntity(entityField, this.__context);
441
+ let ent = tools.findEntity(entityField, this.__context);
442
442
  if(!ent){
443
- var parentEntity = tools.findEntity(this.__name, this.__context);
443
+ const parentEntity = tools.findEntity(this.__name, this.__context);
444
444
  if(parentEntity){
445
445
  ent = tools.findEntity(parentEntity.__entity[entityField].foreignTable, this.__context);
446
446
  if(!ent){
@@ -457,12 +457,12 @@ class EntityTrackerModel {
457
457
  if(currentEntity[entityField].lazyLoading){
458
458
  // TODO: UPDATE THIS CODE TO USE SOMETHING ELSE - THIS WILL NOT WORK WHEN USING DIFFERENT DATABASES BECAUSE THIS IS USING SQLITE CODE.
459
459
 
460
- var name = currentEntity[entityField].foreignKey;
460
+ const name = currentEntity[entityField].foreignKey;
461
461
  var priKey = tools.getPrimaryKeyObject(ent.__entity);
462
462
 
463
463
  //var idValue = currentEntity[entityField].foreignKey;
464
- var currentValue = this.__proto__[`_${name}`];
465
- var val = this["__proto__"]["_"+entityField];
464
+ const currentValue = this.__proto__[`_${name}`];
465
+ const val = this["__proto__"]["_"+entityField];
466
466
  var modelValue = null;
467
467
  if(!val){
468
468
  modelValue = ent.where(`r => r.${priKey} == ${ currentValue }`).single();
@@ -484,17 +484,17 @@ class EntityTrackerModel {
484
484
  if(currentEntity[entityField].lazyLoading){
485
485
  var priKey = tools.getPrimaryKeyObject(this.__entity);
486
486
  var entityName = currentEntity[entityField].foreignTable === undefined ? entityField : currentEntity[entityField].foreignTable;
487
- var tableName = "";
487
+ let tableName = "";
488
488
  if(entityName){
489
489
  switch(currentEntity[entityField].type){
490
490
  // TODO: move the SQL generation part to the SQL builder so that we can later on use many diffrent types of SQL databases.
491
491
  case "hasManyThrough" :
492
492
  try{
493
- var joiningEntity = this.__context[tools.capitalize(entityName)];
494
- var entityFieldJoinName = currentEntity[entityField].foreignTable === undefined? entityField : currentEntity[entityField].foreignTable;
495
- var thirdEntity = this.__context[tools.capitalize(entityFieldJoinName)];
496
- var firstJoiningID = joiningEntity.__entity[this.__entity.__name].foreignTable;
497
- var secondJoiningID = Object.values(joiningEntity.__entity).find(e => e.foreignTable === ent.__name);
493
+ const joiningEntity = this.__context[tools.capitalize(entityName)];
494
+ const entityFieldJoinName = currentEntity[entityField].foreignTable === undefined? entityField : currentEntity[entityField].foreignTable;
495
+ const thirdEntity = this.__context[tools.capitalize(entityFieldJoinName)];
496
+ const firstJoiningID = joiningEntity.__entity[this.__entity.__name].foreignTable;
497
+ const secondJoiningID = Object.values(joiningEntity.__entity).find(e => e.foreignTable === ent.__name);
498
498
  if(firstJoiningID && secondJoiningID )
499
499
  {
500
500
  var modelValue = ent.include(`p => p.${entityFieldJoinName}.select(j => j.${joiningEntity.__entity[this.__entity.__name].foreignKey})`).include(`p =>p.${this.__entity.__name}`).where(`r =>r.${this.__entity.__name}.${priKey} = ${this[priKey]}`).toList();