jw-automator 3.0.0 → 3.1.0

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/CHANGELOG.md CHANGED
File without changes
package/README.md CHANGED
@@ -257,6 +257,15 @@ automator.updateActionByID(1, {
257
257
  });
258
258
  ```
259
259
 
260
+ #### `updateActionByName(name, updates)`
261
+ Update all actions with the given name. Returns the number of actions updated.
262
+
263
+ ```js
264
+ automator.updateActionByName('My Action', {
265
+ payload: { newData: 'newValue' }
266
+ });
267
+ ```
268
+
260
269
  #### `removeActionByID(id)`
261
270
  Remove an action by ID.
262
271
 
@@ -156,7 +156,7 @@ setTimeout(() => tick(), wait);
156
156
  - Event emission
157
157
 
158
158
  **Key APIs**:
159
- - Action management: `addAction`, `updateActionByID`, `removeActionByID`, etc.
159
+ - Action management: `addAction`, `updateActionByID`, `updateActionByName`, `removeActionByID`, etc.
160
160
  - Function registration: `addFunction`, `removeFunction`
161
161
  - Introspection: `getActions`, `describeAction`, `getActionsInRange`
162
162
  - Lifecycle: `start`, `stop`
package/docs/MIGRATION.md CHANGED
@@ -136,6 +136,10 @@ automator.updateActionByID(id, {
136
136
  name: 'New Name',
137
137
  repeat: { type: 'hour', interval: 2 }
138
138
  });
139
+
140
+ automator.updateActionByName('Old Name', {
141
+ name: 'New Name'
142
+ });
139
143
  ```
140
144
 
141
145
  ---
@@ -269,10 +269,16 @@ const id = automator.addAction({
269
269
  ### Update
270
270
 
271
271
  ```javascript
272
+ // By ID
272
273
  automator.updateActionByID(id, {
273
274
  name: 'Updated Task',
274
275
  repeat: { type: 'hour', interval: 2 }
275
276
  });
277
+
278
+ // By name
279
+ automator.updateActionByName('My Task', {
280
+ payload: { updated: true }
281
+ });
276
282
  ```
277
283
 
278
284
  ### Remove
File without changes
File without changes
File without changes
package/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jw-automator",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "A resilient, local-time, 1-second precision automation scheduler for Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
package/src/Automator.js CHANGED
@@ -159,6 +159,53 @@ class Automator {
159
159
  }
160
160
  }
161
161
 
162
+ /**
163
+ * Update actions by name
164
+ */
165
+ updateActionByName(name, updates) {
166
+ const state = this.host.getState();
167
+ const toUpdate = state.actions.filter(a => a.name === name);
168
+
169
+ if (toUpdate.length === 0) {
170
+ // For consistency with removeActionByName, we could throw an error.
171
+ // However, it might be more convenient to simply return 0.
172
+ // Let's return 0 for now.
173
+ return 0;
174
+ }
175
+
176
+ const allowedUpdates = ['cmd', 'payload', 'date', 'unBuffered', 'repeat', 'count'];
177
+
178
+ for (const action of toUpdate) {
179
+ for (const key of allowedUpdates) {
180
+ if (key in updates) {
181
+ if (key === 'date' && updates[key]) {
182
+ action[key] = new Date(updates[key]);
183
+ } else if (key === 'repeat' && updates[key]) {
184
+ action[key] = { ...action.repeat, ...updates[key] };
185
+ if (!action[key].dstPolicy) {
186
+ action[key].dstPolicy = 'once';
187
+ }
188
+ } else {
189
+ action[key] = updates[key];
190
+ }
191
+ }
192
+ }
193
+
194
+ this._emit('update', {
195
+ type: 'update',
196
+ operation: 'update',
197
+ actionId: action.id,
198
+ action: { ...action }
199
+ });
200
+ }
201
+
202
+ if (this.options.autoSave) {
203
+ this._saveState();
204
+ }
205
+
206
+ return toUpdate.length;
207
+ }
208
+
162
209
  /**
163
210
  * Remove action by ID
164
211
  */
File without changes
File without changes
File without changes
File without changes
File without changes