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.
- package/CHANGES.md +26 -0
- package/Cache/RedisQueryCache.js +1 -1
- package/Entity/entityModelBuilder.js +8 -8
- package/Entity/entityTrackerModel.js +19 -19
- package/Migrations/cli.js +127 -123
- package/Migrations/migrationMySQLQuery.js +21 -27
- package/Migrations/migrationPostgresQuery.js +16 -16
- package/Migrations/migrationSQLiteQuery.js +14 -15
- package/Migrations/migrationTemplate.js +6 -6
- package/Migrations/migrations.js +66 -70
- package/Migrations/schema.js +3 -3
- package/QueryLanguage/queryMethods.js +27 -28
- package/QueryLanguage/queryScript.js +35 -37
- package/SQLLiteEngine.js +122 -123
- package/Tools.js +23 -23
- package/context.js +4 -5
- package/deleteManager.js +0 -1
- package/insertManager.js +1 -1
- package/mySQLEngine.js +16 -10
- package/package.json +9 -2
- package/postgresEngine.js +25 -18
- package/postgresSyncConnect.js +2 -2
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# MasterRecord Changelog
|
|
2
2
|
|
|
3
|
+
## v1.1.7 — clear remaining safe lint errors (0 errors)
|
|
4
|
+
|
|
5
|
+
Follow-up to 1.1.6. ESLint now reports **0 errors** (192 `no-var`/`no-redeclare` warnings remain, intentionally deferred — see below). No runtime behavior changes; full test suite green (same single pre-existing `count-no-from-audit` failure).
|
|
6
|
+
|
|
7
|
+
- **`no-prototype-builtins` (9):** `obj.hasOwnProperty(k)` → `Object.prototype.hasOwnProperty.call(obj, k)`.
|
|
8
|
+
- **`no-case-declarations` (23):** wrapped `switch`-`case` bodies that declare `const`/`let` in blocks (SQLite/MySQL/Postgres engines).
|
|
9
|
+
- **`no-unused-vars` (61):** removed genuinely-unused imports/locals (verified safe — e.g. an unused `PostgresEngine` import in `context.js`, which builds the PG engine via `PostgresClient`/`__postgresInit`, and an unused `tools` import in `deleteManager.js`), prefixed unused params/catch bindings with `_`.
|
|
10
|
+
- **`eqeqeq` (12):** switched the rule to `'smart'` (permits the `x == null` null-or-undefined idiom) and converted the lambda-DSL string comparisons in `queryScript` to `===`.
|
|
11
|
+
- **`prefer-const` (2):** in `queryScript`.
|
|
12
|
+
|
|
13
|
+
**Deferred (now `warn`, not `error`):** `no-var` (123) and `no-redeclare` (69). These live in legacy var-heavy engine internals; mechanically converting them across the MySQL/Postgres code paths — which the local test run (SQLite only) does not exercise — risks silent regressions. Tracked for a dedicated, individually-verified pass.
|
|
14
|
+
|
|
15
|
+
## v1.1.6 — lint-driven bug fixes + ESLint tooling
|
|
16
|
+
|
|
17
|
+
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:
|
|
18
|
+
|
|
19
|
+
- **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.
|
|
20
|
+
- **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.
|
|
21
|
+
- **`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.
|
|
22
|
+
- **`MasterValidator` (mastercontroller sibling pattern)** — n/a here; see mastercontroller 2.0.6.
|
|
23
|
+
- 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`.
|
|
24
|
+
|
|
25
|
+
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).
|
|
26
|
+
|
|
27
|
+
> 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.
|
|
28
|
+
|
|
3
29
|
## v1.1.5 — clean npm tarball: add a `files` allowlist
|
|
4
30
|
|
|
5
31
|
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.
|
package/Cache/RedisQueryCache.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 (
|
|
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
|
-
|
|
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 (
|
|
64
|
+
for (const propName in obj) {
|
|
65
65
|
if (obj[propName] === null) {
|
|
66
66
|
delete obj[propName];
|
|
67
67
|
}
|
|
@@ -73,7 +73,7 @@ class EntityModelBuilder {
|
|
|
73
73
|
throw new Error(`compositeIndexes must be an array`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
return indexes.map((index,
|
|
76
|
+
return indexes.map((index, _i) => {
|
|
77
77
|
// Simple array: ['col1', 'col2'] -> auto-generate name
|
|
78
78
|
if (Array.isArray(index)) {
|
|
79
79
|
const colNames = index.join('_');
|
|
@@ -10,8 +10,8 @@ class EntityTrackerModel {
|
|
|
10
10
|
|
|
11
11
|
// start tracking model
|
|
12
12
|
build(dataModel, currentEntity, context){
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
66
|
+
const errorMsg = validator.message;
|
|
67
67
|
|
|
68
68
|
switch (validator.type) {
|
|
69
69
|
case 'required':
|
|
@@ -222,7 +222,7 @@ class EntityTrackerModel {
|
|
|
222
222
|
// This is the FASTEST method - direct access to plain data storage
|
|
223
223
|
if (this._values && typeof this._values === 'object') {
|
|
224
224
|
for (const key in this._values) {
|
|
225
|
-
if (
|
|
225
|
+
if (Object.prototype.hasOwnProperty.call(this._values, key)) {
|
|
226
226
|
plain[key] = this._values[key];
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -240,7 +240,7 @@ class EntityTrackerModel {
|
|
|
240
240
|
if (!isRelationship) {
|
|
241
241
|
try {
|
|
242
242
|
plain[fieldName] = this[fieldName];
|
|
243
|
-
} catch (
|
|
243
|
+
} catch (_e) {
|
|
244
244
|
// Skip fields that throw errors when accessed
|
|
245
245
|
}
|
|
246
246
|
}
|
|
@@ -275,7 +275,7 @@ class EntityTrackerModel {
|
|
|
275
275
|
_visited: visited
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
|
-
} catch (
|
|
278
|
+
} catch (_e) {
|
|
279
279
|
// Skip relationships that throw errors when accessed
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -420,10 +420,10 @@ class EntityTrackerModel {
|
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
buildRelationshipModels(modelClass, currentEntity, currentModel){
|
|
423
|
-
|
|
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
|
-
for (const [entityField,
|
|
426
|
+
for (const [entityField, _entityFieldValue] of entityFields) { // loop through entity values
|
|
427
427
|
|
|
428
428
|
if($that._isRelationship(currentEntity[entityField])){
|
|
429
429
|
|
|
@@ -438,9 +438,9 @@ class EntityTrackerModel {
|
|
|
438
438
|
this["__proto__"]["_" + entityField] = value;
|
|
439
439
|
},
|
|
440
440
|
get : function(){
|
|
441
|
-
|
|
441
|
+
let ent = tools.findEntity(entityField, this.__context);
|
|
442
442
|
if(!ent){
|
|
443
|
-
|
|
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
|
-
|
|
460
|
+
const name = currentEntity[entityField].foreignKey;
|
|
461
461
|
var priKey = tools.getPrimaryKeyObject(ent.__entity);
|
|
462
462
|
|
|
463
463
|
//var idValue = currentEntity[entityField].foreignKey;
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
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
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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();
|