dsh-autorestart 0.3.5 → 0.5.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/README.md +208 -4
- package/client.js +2764 -82
- package/cordis.patch.yml +19 -0
- package/docs/README.zh.md +122 -7
- package/index.js +1318 -72
- package/lib/checkpoint.js +38 -0
- package/lib/sleep.js +828 -0
- package/locale/en.json +113 -0
- package/locale/zh.json +113 -0
- package/package.json +1 -1
package/lib/checkpoint.js
CHANGED
|
@@ -105,6 +105,7 @@ const TOP_LEVEL_KEYS = new Set([
|
|
|
105
105
|
'sessions',
|
|
106
106
|
'parkedGoals',
|
|
107
107
|
'disarmedGoals',
|
|
108
|
+
'seenFeatureVersions',
|
|
108
109
|
'updatedAt',
|
|
109
110
|
]);
|
|
110
111
|
|
|
@@ -172,6 +173,7 @@ export function createEmptyState(now = Date.now()) {
|
|
|
172
173
|
phase: 'idle',
|
|
173
174
|
restart: null,
|
|
174
175
|
sessions: {},
|
|
176
|
+
seenFeatureVersions: {},
|
|
175
177
|
updatedAt: now,
|
|
176
178
|
};
|
|
177
179
|
}
|
|
@@ -277,6 +279,33 @@ function normalizeDisarmedGoals(raw) {
|
|
|
277
279
|
return { disarmedGoals, changed };
|
|
278
280
|
}
|
|
279
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Normalize the record of the feature announcements the user has already seen.
|
|
284
|
+
*
|
|
285
|
+
* The shape is `{ [feature]: version }`: the id of the feature and the version
|
|
286
|
+
* of the plugin that announced it. A record whose version is not a string is
|
|
287
|
+
* dropped — an unreadable record must never hide an announcement for ever,
|
|
288
|
+
* so a broken entry makes the announcement show up again instead.
|
|
289
|
+
*
|
|
290
|
+
* @param {unknown} raw
|
|
291
|
+
* @returns {{ seenFeatureVersions: Record<string, string>, changed: boolean }}
|
|
292
|
+
*/
|
|
293
|
+
function normalizeSeenFeatureVersions(raw) {
|
|
294
|
+
if (!isObject(raw)) {
|
|
295
|
+
return { seenFeatureVersions: {}, changed: raw !== null && raw !== undefined };
|
|
296
|
+
}
|
|
297
|
+
const seenFeatureVersions = {};
|
|
298
|
+
let changed = false;
|
|
299
|
+
for (const [feature, version] of Object.entries(raw)) {
|
|
300
|
+
if (typeof version !== 'string' || version === '') {
|
|
301
|
+
changed = true;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
seenFeatureVersions[feature] = version;
|
|
305
|
+
}
|
|
306
|
+
return { seenFeatureVersions, changed };
|
|
307
|
+
}
|
|
308
|
+
|
|
280
309
|
/**
|
|
281
310
|
* Normalize the handoff record of a session: `{ handedOffTo, handoffAt, carriedChars }`.
|
|
282
311
|
* A missing record stays `null`; a corrupt one is dropped instead of being thrown on.
|
|
@@ -536,6 +565,15 @@ export function normalizeState(raw, now = Date.now()) {
|
|
|
536
565
|
if (disarmed.changed) repaired = true;
|
|
537
566
|
}
|
|
538
567
|
|
|
568
|
+
// The record of the feature announcements the user has already seen. It
|
|
569
|
+
// survives a restart of the Host: an announcement that was shown once must
|
|
570
|
+
// not come back with the next boot.
|
|
571
|
+
if (raw.seenFeatureVersions != null) {
|
|
572
|
+
const seen = normalizeSeenFeatureVersions(raw.seenFeatureVersions);
|
|
573
|
+
state.seenFeatureVersions = seen.seenFeatureVersions;
|
|
574
|
+
if (seen.changed) repaired = true;
|
|
575
|
+
}
|
|
576
|
+
|
|
539
577
|
return { state, repaired };
|
|
540
578
|
}
|
|
541
579
|
|