nats_wave 1.1.16 → 1.1.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70b9abe2ec70949d2ffd0b97d0d2e33688590d8d4bc5c01baa2a555cb0b355e4
4
- data.tar.gz: cbef4f7b640670744b71626606a0ad62de313012bfb524e7e406594ff0b31e9c
3
+ metadata.gz: 187d69a8b758d408457c45f096d66275cffc8ac56830aeac718265441a0a0d08
4
+ data.tar.gz: 0bd81d8ca8c0ec0ec5ac17b81e9cef8f005fc1307c8fdd42460c52cac4e27982
5
5
  SHA512:
6
- metadata.gz: 552e1c4272994c73ab29ed2c714aa7d9e776ef6cd81431a97da99af9609669815ad8af64651a12278154609033f1a1e82c37a9fa921ce400770a2228f56078bb
7
- data.tar.gz: 6c2f1a722122a2de176186b58835158764ff0ba4a5913c7d15e0b15b8b15feaba6b053fd12a97acc8d0699b3b2db7f701797679efe5322574e43c1b86b4cd6fd
6
+ metadata.gz: 86a91068caebdebe8bd5ae0d65ba4d08a76b627e9f51d628dfbc26ffd80cb14b667808213eb032752248626b3819db038d568c54e437336146973ffe303d6c7e
7
+ data.tar.gz: ed14c10b771818369ba40517fbf32aed83e3291919b17c9784648563ca3a7355510cc71654dd876721875e6f7068d44091b5ec15704bfa23bc3946acc9df5b6a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nats_wave (1.1.16)
4
+ nats_wave (1.1.18)
5
5
  activerecord (>= 6.1, < 8.0)
6
6
  activesupport (>= 6.1, < 8.0)
7
7
  concurrent-ruby (~> 1.1)
data/README.md CHANGED
@@ -174,7 +174,7 @@ rails console
174
174
  # This automatically publishes via nats_wave_publishes_to
175
175
  ```
176
176
 
177
- ## ⚙️ Configuration
177
+ ## ⚙️ Configuration
178
178
 
179
179
  ### Environment Variables
180
180
 
@@ -77,7 +77,7 @@ module NatsWave
77
77
  {
78
78
  service: @service_name,
79
79
  environment: ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'unknown',
80
- version: ENV['APP_VERSION'] || '1.1.16'
80
+ version: ENV['APP_VERSION'] || '1.1.18'
81
81
  }
82
82
  end
83
83
 
@@ -1014,7 +1014,8 @@ module NatsWave
1014
1014
  sync_strategy: options[:sync_strategy] || :upsert,
1015
1015
  custom_handler: custom_handler, # Renamed to be clear it's optional
1016
1016
  queue_group: options[:queue_group],
1017
- auto_sync: options[:auto_sync] != false # Default to true, can be disabled
1017
+ auto_sync: options[:auto_sync] != false, # Default to true, can be disabled
1018
+ only_mapped_fields: options[:only_mapped_fields] # ADD THIS LINE!
1018
1019
  }
1019
1020
 
1020
1021
  # Store the config
@@ -1037,7 +1038,7 @@ module NatsWave
1037
1038
 
1038
1039
  # Configure publishing with optional custom handler AND auto-publishing callbacks
1039
1040
  def nats_wave_publishes_to(*subjects, **options, &block)
1040
- NatsWave.logger.debug "⚙️#{self.name}: Setting up publishing to subjects: #{subjects.inspect}"
1041
+ NatsWave.logger.debug "⚙️ #{self.name}: Setting up publishing to subjects: #{subjects.inspect}"
1041
1042
 
1042
1043
  # Custom handler is now optional and runs AFTER default behavior
1043
1044
  custom_handler = options[:handler] || block
@@ -1062,7 +1063,7 @@ module NatsWave
1062
1063
  # Add ActiveRecord callbacks for auto-publishing (only once per model)
1063
1064
  setup_publishing_callbacks_once
1064
1065
 
1065
- NatsWave.logger.debug "⚙️#{self.name}: Registered publishing config for subjects: #{subjects}"
1066
+ NatsWave.logger.debug "⚙️ #{self.name}: Registered publishing config for subjects: #{subjects}"
1066
1067
  end
1067
1068
 
1068
1069
  # Get all subscription configurations
@@ -1075,31 +1076,49 @@ module NatsWave
1075
1076
  nats_wave_publishing_config
1076
1077
  end
1077
1078
 
1078
- # Process subscription data through field mappings and transformations (PUBLIC CLASS METHOD)
1079
1079
  def process_subscription_data(raw_data, config)
1080
1080
  processed_data = {}
1081
- field_mappings = config[:field_mappings]
1082
- transformations = config[:transformations]
1083
- skip_fields = config[:skip_fields]
1081
+ field_mappings = config[:field_mappings] || {}
1082
+ transformations = config[:transformations] || {}
1083
+ skip_fields = config[:skip_fields] || []
1084
+ only_mapped_fields = config[:only_mapped_fields]
1084
1085
 
1085
- raw_data.each do |field, value|
1086
- field_str = field.to_s
1087
- field_sym = field.to_sym
1088
-
1089
- # Skip if in skip_fields
1090
- next if skip_fields.include?(field_str) || skip_fields.include?(field_sym)
1086
+ # If only_mapped_fields is true, only process fields that have explicit mappings
1087
+ if only_mapped_fields && field_mappings.any?
1088
+ NatsWave.logger.debug "⚙️ Only processing mapped fields: #{field_mappings.keys}"
1091
1089
 
1092
- # Apply field mapping (external -> local)
1093
- mapped_field = field_mappings[field_str] ||
1094
- field_mappings[field_sym] ||
1095
- field
1096
-
1097
- # Apply transformation if any
1098
- transformed_value = apply_transformation(value, mapped_field, transformations, raw_data)
1099
-
1100
- processed_data[mapped_field.to_s] = transformed_value
1090
+ field_mappings.each do |external_field, local_field|
1091
+ external_field_str = external_field.to_s
1092
+
1093
+ # Skip if this field is in skip_fields
1094
+ next if skip_fields.include?(external_field_str) || skip_fields.include?(external_field.to_sym)
1095
+
1096
+ # Get the value from raw_data (using external field name)
1097
+ value = raw_data[external_field_str] || raw_data[external_field.to_sym]
1098
+
1099
+ # Apply transformation if any (use local field name for transformation lookup)
1100
+ transformed_value = apply_transformation(value, local_field, transformations, raw_data)
1101
+
1102
+ processed_data[local_field.to_s] = transformed_value
1103
+ end
1104
+ else
1105
+ raw_data.each do |field, value|
1106
+ field_str = field.to_s
1107
+ field_sym = field.to_sym
1108
+
1109
+ next if skip_fields.include?(field_str) || skip_fields.include?(field_sym)
1110
+
1111
+ mapped_field = field_mappings[field_str] ||
1112
+ field_mappings[field_sym] ||
1113
+ field
1114
+
1115
+ transformed_value = apply_transformation(value, mapped_field, transformations, raw_data)
1116
+
1117
+ processed_data[mapped_field.to_s] = transformed_value
1118
+ end
1101
1119
  end
1102
1120
 
1121
+ NatsWave.logger.debug "📨 Final processed subscription data keys: #{processed_data.keys}"
1103
1122
  processed_data
1104
1123
  end
1105
1124
 
@@ -1222,7 +1241,7 @@ module NatsWave
1222
1241
  after_commit :trigger_nats_wave_auto_publish_on_destroy, on: :destroy
1223
1242
 
1224
1243
  @nats_wave_callbacks_added = true
1225
- NatsWave.logger.debug "⚙️#{self.name}: Added publishing callbacks"
1244
+ NatsWave.logger.debug "⚙️ #{self.name}: Added publishing callbacks"
1226
1245
  end
1227
1246
 
1228
1247
  # Create a subscription handler that processes data and calls custom handler AFTER auto-sync
@@ -1231,7 +1250,7 @@ module NatsWave
1231
1250
 
1232
1251
  lambda do |message|
1233
1252
  begin
1234
- NatsWave.logger.debug "⚙️Processing subscription message for #{model_class.name}"
1253
+ NatsWave.logger.debug "⚙️ Processing subscription message for #{model_class.name}"
1235
1254
 
1236
1255
  # Extract the raw data
1237
1256
  raw_data = message['data'] || {}
@@ -1250,7 +1269,7 @@ module NatsWave
1250
1269
  # Handle nested data structure
1251
1270
  if raw_data['data'].is_a?(Hash)
1252
1271
  raw_data = raw_data['data']
1253
- NatsWave.logger.debug "⚙️Using nested data structure"
1272
+ NatsWave.logger.debug "⚙️ Using nested data structure"
1254
1273
  end
1255
1274
 
1256
1275
  # Process the data through mappings and transformations
@@ -1258,13 +1277,13 @@ module NatsWave
1258
1277
 
1259
1278
  # Always perform auto-sync first (if enabled)
1260
1279
  if config[:auto_sync]
1261
- NatsWave.logger.debug "⚙️Performing auto-sync first"
1280
+ NatsWave.logger.debug "⚙️ Performing auto-sync first"
1262
1281
  model_class.perform_auto_sync(model_name, action, processed_data, config)
1263
1282
  end
1264
1283
 
1265
1284
  # Then call custom handler if provided (optional)
1266
1285
  if config[:custom_handler]
1267
- NatsWave.logger.debug "⚙️Calling custom subscription handler after auto-sync"
1286
+ NatsWave.logger.debug "⚙️ Calling custom subscription handler after auto-sync"
1268
1287
  config[:custom_handler].call(model_name, action, processed_data, message)
1269
1288
  end
1270
1289
 
@@ -1287,7 +1306,7 @@ module NatsWave
1287
1306
 
1288
1307
  # Check conditions (only for publishing)
1289
1308
  if config[:conditions].any? && !evaluate_conditions(config[:conditions])
1290
- NatsWave.logger.debug "⚙️Skipping publish - conditions not met"
1309
+ NatsWave.logger.debug "⚙️ Skipping publish - conditions not met"
1291
1310
  next
1292
1311
  end
1293
1312
 
@@ -1315,7 +1334,7 @@ module NatsWave
1315
1334
 
1316
1335
  # Then call custom handler if provided (optional)
1317
1336
  if config[:custom_handler]
1318
- NatsWave.logger.debug "⚙️Calling custom publishing handler after publishing"
1337
+ NatsWave.logger.debug "⚙️ Calling custom publishing handler after publishing"
1319
1338
  config[:custom_handler].call(self.class.name, action, processed_data, self)
1320
1339
  end
1321
1340
  end
@@ -18,7 +18,7 @@ module NatsWave
18
18
  def initialize(options = {})
19
19
  @nats_url = ENV['NATS_URL'] || "nats://localhost:4222"
20
20
  @service_name = ENV['NATS_SERVICE_NAME'] || "purplewave"
21
- @version = ENV['NATS_SERVICE_VERSION'] || "1.1.16"
21
+ @version = ENV['NATS_SERVICE_VERSION'] || "1.1.18"
22
22
  @instance_id = ENV['NATS_INSTANCE_ID'] || Socket.gethostname
23
23
  @database_url = ENV['NATS_DATABASE_URL'] || nil
24
24
  @connection_pool_size = (ENV['NATS_CONNECTION_POOL_SIZE'] || 10).to_i
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NatsWave
4
- VERSION = '1.1.16'
4
+ VERSION = '1.1.18'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nats_wave
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.16
4
+ version: 1.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Dabo