masterrecord 1.22.0 → 1.22.1

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,5 +1,10 @@
1
1
  # MasterRecord Changelog
2
2
 
3
+ ## v1.22.1 — boolean columns materialize as booleans on read (fix)
4
+
5
+ - **Fix:** `db.boolean()` columns are now materialized as real `true`/`false` when rows are read (`toList()/find()/single()/first()`, tracked or `asNoTracking()`), matching EF Core value conversion. SQLite stores booleans as INTEGER `0/1` and MySQL as `TINYINT(1)`/`BIT(1)`, so an entity read back exposed `1`/`0` (an API echoed `{ published: true }` after the insert but `{ published: 1 }` after a later read/update). `null` is preserved; other types are untouched; a custom `transform()` still wins. Implemented as `FieldTransformer.materialize(value, fieldDef)`, applied on the single row→entity path.
6
+ - Found validating the `master new` scaffold end to end. New test: `test/boolean-materialization.test.js`.
7
+
3
8
  ## v1.22.0 — owned / complex types as JSON (EF Core `OwnsOne(...).ToJson()` / `ComplexProperty`)
4
9
 
5
10
  - **`db.owned(Address)`** stores the value as JSON in one column and **hydrates it into the class on read**; **`db.owned()`** for plain objects/arrays. Serialization is automatic (a custom `transform()` still wins).
@@ -134,6 +134,30 @@ class FieldTransformer {
134
134
  }
135
135
  }
136
136
 
137
+ /**
138
+ * Built-in materialization of a raw column value into its declared JS type
139
+ * (EF Core value conversion on read). SQLite stores booleans as INTEGER 0/1
140
+ * and MySQL as TINYINT(1), so `db.boolean()` columns come back as numbers
141
+ * unless converted here; Postgres already returns true/false. Other types
142
+ * pass through unchanged; null/undefined are preserved.
143
+ *
144
+ * @param {*} value - Raw value from the database row
145
+ * @param {Object} fieldDef - Field definition ({ type, ... })
146
+ * @returns {*} Value in its application type
147
+ */
148
+ static materialize(value, fieldDef) {
149
+ if (value === null || value === undefined || !fieldDef) return value;
150
+ const type = fieldDef.type;
151
+ if (type === 'boolean' || type === 'bool') {
152
+ if (typeof value === 'boolean') return value;
153
+ if (value === 1 || value === '1' || value === 'true' || value === 'TRUE') return true;
154
+ if (value === 0 || value === '0' || value === 'false' || value === 'FALSE') return false;
155
+ if (typeof value === 'bigint') return value !== 0n;
156
+ if (Buffer.isBuffer(value) && value.length === 1) return value[0] !== 0; // MySQL BIT(1)
157
+ }
158
+ return value;
159
+ }
160
+
137
161
  /**
138
162
  * Transform a value from database storage to application format
139
163
  * Executes the fromDatabase transformer if defined
@@ -146,9 +170,9 @@ class FieldTransformer {
146
170
  * @throws {Error} If transformation fails
147
171
  */
148
172
  static fromDatabase(value, fieldDef, entityName, fieldName) {
149
- // No transformer - return original value
173
+ // No transformer - apply the built-in type materialization only
150
174
  if (!this.hasTransformer(fieldDef)) {
151
- return value;
175
+ return this.materialize(value, fieldDef);
152
176
  }
153
177
 
154
178
  const transformer = fieldDef.transform;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masterrecord",
3
- "version": "1.22.0",
3
+ "version": "1.22.1",
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",