velocious 1.0.705 → 1.0.706

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.705",
6
+ "version": "1.0.706",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -420,14 +420,18 @@ function modelParamKey(modelClass) {
420
420
  * Table detection and relationship registration happen lazily on first usage.
421
421
  * Called synchronously from Model.audited() at module-load time.
422
422
  * @param {AuditedModelClass} modelClass - Model class to audit.
423
+ * @param {{except?: string[]}} [options] - Audit options: `except` lists attribute names never written to the audit trail (e.g. high-frequency telemetry columns).
423
424
  * @returns {void}
424
425
  */
425
- function registerAuditing(modelClass) {
426
+ function registerAuditing(modelClass, options = {}) {
426
427
  if (Object.prototype.hasOwnProperty.call(modelClass, "_auditLifecycleCallbacksRegistered") && modelClass._auditLifecycleCallbacksRegistered) {
427
428
  return
428
429
  }
429
430
 
430
- modelClass._auditLifecycleCallbacksRegistered = true
431
+ const auditableModelClass = /** @type {AuditedModelClass & {_auditExcludedAttributes?: Set<string>}} */ (modelClass)
432
+
433
+ auditableModelClass._auditLifecycleCallbacksRegistered = true
434
+ auditableModelClass._auditExcludedAttributes = new Set(options.except || [])
431
435
  registerAuditRelationship(modelClass)
432
436
  modelClass.beforeCreate("captureCreateAuditChanges")
433
437
  modelClass.afterCreate("createCreateAudit")
@@ -801,10 +805,18 @@ function auditChangesForCurrentChanges(record) {
801
805
  const changes = record.changes()
802
806
  /** @type {AuditChanges} */
803
807
  const auditedChanges = {}
804
- const columnNameToAttributeName = record.getModelClass().getColumnNameToAttributeNameMap()
808
+ const modelClass = /** @type {AuditedModelClass & {_auditExcludedAttributes?: Set<string>}} */ (record.getModelClass())
809
+ const columnNameToAttributeName = modelClass.getColumnNameToAttributeNameMap()
810
+ const excludedAttributes = modelClass._auditExcludedAttributes
805
811
 
806
812
  for (const [attributeName, change] of Object.entries(changes)) {
807
- auditedChanges[columnNameToAttributeName[attributeName] || attributeName] = change[1]
813
+ const auditedAttributeName = columnNameToAttributeName[attributeName] || attributeName
814
+
815
+ if (excludedAttributes && (excludedAttributes.has(auditedAttributeName) || excludedAttributes.has(attributeName))) {
816
+ continue
817
+ }
818
+
819
+ auditedChanges[auditedAttributeName] = change[1]
808
820
  }
809
821
 
810
822
  return auditedChanges
@@ -734,10 +734,11 @@ class VelociousDatabaseRecord {
734
734
 
735
735
  /**
736
736
  * Enables automatic create/update/destroy auditing for this model.
737
+ * @param {{except?: string[]}} [options] - Audit options: `except` lists attribute names that must never be written to the audit trail. Use it for high-frequency telemetry columns (heartbeats, progress counters) whose write volume turns the audit table into a deadlock partner for the parent row.
737
738
  * @returns {void}
738
739
  */
739
- static audited() {
740
- registerAuditing(this)
740
+ static audited(options = {}) {
741
+ registerAuditing(this, options)
741
742
  }
742
743
 
743
744
  /**