masterrecord 1.1.7 → 1.1.8
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 +16 -0
- package/Entity/entityTrackerModel.js +25 -0
- package/QueryLanguage/queryMethods.js +15 -0
- package/package.json +1 -1
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# MasterRecord Changelog
|
|
2
2
|
|
|
3
|
+
## v1.1.8 — entity internals/methods are non-enumerable (fixes spread/JSON data loss)
|
|
4
|
+
|
|
5
|
+
**Bug:** entity instances exposed their internals (`__entity`, `__context`, `__ID`, `__dirtyFields`, `__state`, `__name`) and helper methods (`toJSON`, `toObject`, `save`, `delete`, `reload`, `clone`) as **enumerable** own properties (attached by object literal / plain assignment). So spreading or `Object.assign`-ing an entity:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
const w = await ctx.Workspace.where(x => x.id == $$, id).single();
|
|
9
|
+
const out = { ...w, role: 'owner' };
|
|
10
|
+
JSON.stringify(out); // before: {"id":28,"name":"..."} — `role` silently dropped
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Two failure modes: (1) the **copied `toJSON`** ran on the plain object and rebuilt output from the original columns only, silently discarding any key the caller added; (2) `__context` (the whole DB context) leaked into the copy and could make `JSON.stringify` throw on its circular structure. `Object.keys(entity)` also returned methods + internals.
|
|
14
|
+
|
|
15
|
+
**Fix:** internals and helper/hook methods are now defined non-enumerable in both entity-construction paths — `Entity/entityTrackerModel.build()` (queried entities) and `QueryLanguage/queryMethods.new()` (new entities). Column accessors stay enumerable (and the FTS `__rank` column too). `{ ...entity, extra }` now serializes correctly and `Object.keys(entity)` returns only columns.
|
|
16
|
+
|
|
17
|
+
**Engine coverage:** the fix is in shared, engine-agnostic hydration code — all entities (SQLite, MySQL, Postgres) are built through the same `build()` / `new()`. (Regression test runs on SQLite; the code path is identical for the other engines.)
|
|
18
|
+
|
|
3
19
|
## v1.1.7 — clear remaining safe lint errors (0 errors)
|
|
4
20
|
|
|
5
21
|
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).
|
|
@@ -392,6 +392,31 @@ class EntityTrackerModel {
|
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
// Make internal metadata (`__*`) and helper/hook methods
|
|
396
|
+
// non-enumerable. They are attached by plain assignment / object
|
|
397
|
+
// literal above, which makes them enumerable own properties — so
|
|
398
|
+
// `{ ...entity }` / `Object.assign({}, entity)` would copy them.
|
|
399
|
+
// Two concrete bugs that causes:
|
|
400
|
+
// 1. The copied `toJSON` runs on the spread object and rebuilds
|
|
401
|
+
// output from the original columns only, silently dropping any
|
|
402
|
+
// key the caller added (`{ ...w, role }` serialized without
|
|
403
|
+
// `role`).
|
|
404
|
+
// 2. `__context` (the whole DB context) leaks into the spread and
|
|
405
|
+
// makes `JSON.stringify` throw on its circular structure.
|
|
406
|
+
// Column accessors are defined with `enumerable: true` and stay
|
|
407
|
+
// enumerable; relationship getters are already non-enumerable.
|
|
408
|
+
for (const key of Object.keys(modelClass)) {
|
|
409
|
+
const desc = Object.getOwnPropertyDescriptor(modelClass, key);
|
|
410
|
+
// Only touch DATA properties (internals + methods). Skip accessor
|
|
411
|
+
// properties — those are the column getters (defined enumerable +
|
|
412
|
+
// non-configurable, so redefining them throws), including the FTS
|
|
413
|
+
// `__rank` column, which should stay enumerable/serializable.
|
|
414
|
+
if (!desc || !('value' in desc)) continue;
|
|
415
|
+
if (key.startsWith('__') || typeof desc.value === 'function') {
|
|
416
|
+
Object.defineProperty(modelClass, key, { enumerable: false });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
395
420
|
return modelClass;
|
|
396
421
|
}
|
|
397
422
|
|
|
@@ -968,6 +968,21 @@ class queryMethods{
|
|
|
968
968
|
}
|
|
969
969
|
}
|
|
970
970
|
|
|
971
|
+
// Make internal metadata (`__*`) and helper/hook methods
|
|
972
|
+
// non-enumerable so that `{ ...entity }` / `Object.assign` copy only
|
|
973
|
+
// column values — see the matching note in entityTrackerModel.build().
|
|
974
|
+
// Without this, the copied `toJSON` silently drops caller-added keys
|
|
975
|
+
// on serialize and `__context` leaks (circular JSON).
|
|
976
|
+
for (const key of Object.keys(newEntity)) {
|
|
977
|
+
const desc = Object.getOwnPropertyDescriptor(newEntity, key);
|
|
978
|
+
// Only DATA properties (internals + methods); skip accessor
|
|
979
|
+
// (column) getters, which are non-configurable.
|
|
980
|
+
if (!desc || !('value' in desc)) continue;
|
|
981
|
+
if (key.startsWith('__') || typeof desc.value === 'function') {
|
|
982
|
+
Object.defineProperty(newEntity, key, { enumerable: false });
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
|
|
971
986
|
return newEntity;
|
|
972
987
|
}
|
|
973
988
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masterrecord",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
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",
|