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 +0 -0
- package/README.md +9 -0
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/MIGRATION.md +4 -0
- package/docs/QUICKSTART.md +6 -0
- package/examples/basic-example.js +0 -0
- package/examples/hello-world.js +0 -0
- package/examples/iot-sensor-example.js +0 -0
- package/index.js +0 -0
- package/package.json +1 -1
- package/src/Automator.js +47 -0
- package/src/core/CoreEngine.js +0 -0
- package/src/core/RecurrenceEngine.js +0 -0
- package/src/host/SchedulerHost.js +0 -0
- package/src/storage/FileStorage.js +0 -0
- package/src/storage/MemoryStorage.js +0 -0
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
|
|
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -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
package/docs/QUICKSTART.md
CHANGED
|
@@ -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
|
package/examples/hello-world.js
CHANGED
|
File without changes
|
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
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
|
*/
|
package/src/core/CoreEngine.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|