masterrecord 1.5.6 → 1.5.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 CHANGED
@@ -1,12 +1,14 @@
1
1
  # MasterRecord Changelog
2
2
 
3
- ## v1.5.6 — re-bundle docs after clearing an npm-scanner false-positive
3
+ ## v1.5.7 — unset fields no longer read as their definition function
4
+
5
+ **Bug (a missing-value check that never fires):** entity fields are declared as methods (`apiKey(db){ db.string(); }`). On a constructed entity (`new Model()` → `add()` → INSERT) any field the caller never set still resolved to that **method** — a truthy function — so a guard like `if (!row.apiKey)` silently never fired (`typeof row.apiKey === 'function'`, not `undefined`). Queried rows were already correct (built from the DB row, not the class prototype); the trap was only on entities you build.
4
6
 
5
- 1.5.5 published without the `docs/` folder or `CHANGES.md` in the tarball: npm's publish-time malware scanner returned `403 forbidden by security policy` on a documentation string. The trigger was a literal SQL-injection **example** — `'10; DROP TABLE users'` — in `readme.md` and `docs/SECURITY.md`, illustrating input the ORM *rejects*; its executable `; DROP TABLE users` shape reads as an attack payload to the scanner. 1.5.5 shipped the runtime with that string neutralized but the docs excluded to get the release out.
7
+ **Fix:** `add()` blanks unset function-valued fields (a plain own-property write — the full accessor install can't run pre-INSERT), and `attachTrackingTo()` (run after INSERT) treats a function value as "unset" and backs it with `undefined`. So an unset field reads as `undefined`/`null` — and `!entity.field` behaves — after `add()`, after INSERT, and when queried. Relationship navigation properties are untouched. New test: `test/unset-field-not-function.test.js` pins all three paths (add / insert / query) plus that setting a previously-unset field still persists. Full suite green (0 fail, 293 pass, 20 gated skipped); 0 lint errors.
6
8
 
7
- This release **re-includes the full `docs/` folder and `CHANGES.md`** in the published package. A sweep of every markdown file (SQL-injection payloads, shell/command injection, XSS, obfuscation/encoded blobs, secrets, path traversal) found no other flaggable strings — the one payload example was the only real match. Runtime code is unchanged from 1.5.5.
9
+ ## v1.5.6 — re-bundle docs after clearing an npm-scanner false-positive
8
10
 
9
- _(No functional change — packaging only. All 1.5.5 fixes remain in place.)_
11
+ 1.5.5 shipped without the `docs/` folder or `CHANGES.md` — npm's publish-time malware scanner returned `403 forbidden by security policy` on a documentation string: the literal SQL-injection **example** `'10; DROP TABLE users'` (in `readme.md` and `docs/SECURITY.md`), whose executable `; DROP TABLE users` shape reads as an attack payload even though it documents input the ORM *rejects*. That string is neutralized, and a sweep of every markdown file (SQL payloads, shell/command injection, XSS, obfuscation, secrets, path traversal) found no other matches — so this release **re-includes the full `docs/` folder and `CHANGES.md`** in the tarball. Packaging only; runtime unchanged from 1.5.5.
10
12
 
11
13
  ## v1.5.5 — three shared-connection concurrency bugs: cross-instance saves, poisoned empty cache, dropped post-insert edits
12
14
 
@@ -454,7 +454,13 @@ class EntityTrackerModel {
454
454
  if (this._isRelationship(currentEntity[modelField])) continue;
455
455
  const desc = Object.getOwnPropertyDescriptor(target, modelField);
456
456
  if (desc && !('value' in desc)) return target; // already tracked
457
- captured[modelField] = target[modelField];
457
+ // An UNSET declared field still resolves to its definition method on
458
+ // the class prototype (e.g. `apiKey(db){...}`) — a truthy function.
459
+ // Capturing that verbatim would make `!entity.apiKey` false and read
460
+ // back a function. An entity field value is never a function, so
461
+ // treat a function here as "unset" and back it with undefined.
462
+ const cur = target[modelField];
463
+ captured[modelField] = (typeof cur === 'function') ? undefined : cur;
458
464
  scalarFields.push(modelField);
459
465
  }
460
466
 
@@ -1017,6 +1017,21 @@ class queryMethods{
1017
1017
  entityValue.__entity = this.__entity;
1018
1018
  entityValue.__context = this.__context;
1019
1019
  entityValue.__name = this.__entity.__name;
1020
+ // An UNSET declared field still resolves to its definition method on the
1021
+ // class prototype (e.g. `apiKey(db){...}`) — a truthy function — so
1022
+ // `!entity.apiKey` never fires. Blank those so an added entity reads
1023
+ // cleanly even before save. (This is a plain own-property write, not the
1024
+ // full accessor install, which the insert path can't take pre-save; full
1025
+ // change-tracking accessors are attached after INSERT.) Relationship
1026
+ // navigation properties are left alone.
1027
+ for (const f in this.__entity) {
1028
+ const def = this.__entity[f];
1029
+ const isRel = def && (def.type === 'hasOne' || def.type === 'hasMany'
1030
+ || def.type === 'hasManyThrough' || def.relationshipType === 'belongsTo');
1031
+ if (!isRel && typeof entityValue[f] === 'function') {
1032
+ entityValue[f] = undefined;
1033
+ }
1034
+ }
1020
1035
  this.__context.__track(entityValue);
1021
1036
  }
1022
1037
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
5
5
  "type": "module",
6
6
  "main": "./MasterRecord.js",