@ordewell/core 0.13.4 → 0.14.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/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +31 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -616,8 +616,8 @@ declare class HttpWebFetcher implements IWebFetcher {
|
|
|
616
616
|
|
|
617
617
|
/**
|
|
618
618
|
* The daily version check (ADR-0048): one ping a day that counts installs
|
|
619
|
-
* under an install ID replaced every 30 days, and may answer with
|
|
620
|
-
* version, which the state file keeps until an answer
|
|
619
|
+
* under an install ID replaced every 30 days, and may answer with the latest
|
|
620
|
+
* version, which the state file keeps until an answer names a newer one.
|
|
621
621
|
*/
|
|
622
622
|
declare const VERSION_CHECK_URL = "https://ordewell.ai/api/v1/ping";
|
|
623
623
|
declare const VERSION_CHECK_NOTICE: string;
|
|
@@ -659,15 +659,16 @@ interface VersionCheckOptions {
|
|
|
659
659
|
interface VersionCheck {
|
|
660
660
|
/** Settles once no ping is in flight. Never rejects. */
|
|
661
661
|
settled(): Promise<void>;
|
|
662
|
-
/** Stops the
|
|
662
|
+
/** Stops the hourly re-check; nothing is named after it, not even an answer already on its way. */
|
|
663
663
|
stop(): void;
|
|
664
664
|
}
|
|
665
665
|
/**
|
|
666
666
|
* Starts the check for this process: the one-time notice on the first start
|
|
667
667
|
* on a machine; otherwise the update line for a newer version an earlier
|
|
668
|
-
* answer named, a ping if a day has passed since the last one
|
|
669
|
-
*
|
|
670
|
-
*
|
|
668
|
+
* answer named, and a ping if a day has passed since the last one. Both are
|
|
669
|
+
* asked again every hour on an unref'd timer for as long as the process lives,
|
|
670
|
+
* so a version another process on the machine learned is named here too.
|
|
671
|
+
* Never throws and never waits on the network.
|
|
671
672
|
*/
|
|
672
673
|
declare function startVersionCheck(options: VersionCheckOptions): VersionCheck;
|
|
673
674
|
|
package/dist/index.d.ts
CHANGED
|
@@ -616,8 +616,8 @@ declare class HttpWebFetcher implements IWebFetcher {
|
|
|
616
616
|
|
|
617
617
|
/**
|
|
618
618
|
* The daily version check (ADR-0048): one ping a day that counts installs
|
|
619
|
-
* under an install ID replaced every 30 days, and may answer with
|
|
620
|
-
* version, which the state file keeps until an answer
|
|
619
|
+
* under an install ID replaced every 30 days, and may answer with the latest
|
|
620
|
+
* version, which the state file keeps until an answer names a newer one.
|
|
621
621
|
*/
|
|
622
622
|
declare const VERSION_CHECK_URL = "https://ordewell.ai/api/v1/ping";
|
|
623
623
|
declare const VERSION_CHECK_NOTICE: string;
|
|
@@ -659,15 +659,16 @@ interface VersionCheckOptions {
|
|
|
659
659
|
interface VersionCheck {
|
|
660
660
|
/** Settles once no ping is in flight. Never rejects. */
|
|
661
661
|
settled(): Promise<void>;
|
|
662
|
-
/** Stops the
|
|
662
|
+
/** Stops the hourly re-check; nothing is named after it, not even an answer already on its way. */
|
|
663
663
|
stop(): void;
|
|
664
664
|
}
|
|
665
665
|
/**
|
|
666
666
|
* Starts the check for this process: the one-time notice on the first start
|
|
667
667
|
* on a machine; otherwise the update line for a newer version an earlier
|
|
668
|
-
* answer named, a ping if a day has passed since the last one
|
|
669
|
-
*
|
|
670
|
-
*
|
|
668
|
+
* answer named, and a ping if a day has passed since the last one. Both are
|
|
669
|
+
* asked again every hour on an unref'd timer for as long as the process lives,
|
|
670
|
+
* so a version another process on the machine learned is named here too.
|
|
671
|
+
* Never throws and never waits on the network.
|
|
671
672
|
*/
|
|
672
673
|
declare function startVersionCheck(options: VersionCheckOptions): VersionCheck;
|
|
673
674
|
|
package/dist/index.js
CHANGED
|
@@ -34041,13 +34041,12 @@ function compareVersions(a, b) {
|
|
|
34041
34041
|
return 0;
|
|
34042
34042
|
}
|
|
34043
34043
|
var isNewer = (latest, version) => (compareVersions(latest, version) ?? 0) > 0;
|
|
34044
|
-
async function readAnswer(response
|
|
34045
|
-
if (response.status === 204) return null;
|
|
34044
|
+
async function readAnswer(response) {
|
|
34046
34045
|
if (response.status !== 200) return void 0;
|
|
34047
34046
|
const body2 = JSON.parse(await response.text());
|
|
34048
34047
|
if (!body2 || typeof body2 !== "object") return void 0;
|
|
34049
34048
|
const { latest } = body2;
|
|
34050
|
-
return typeof latest === "string" &&
|
|
34049
|
+
return typeof latest === "string" && SEMVER.test(latest) ? latest : void 0;
|
|
34051
34050
|
}
|
|
34052
34051
|
var truthy = (value) => /^(1|true|yes)$/i.test(value?.trim() ?? "");
|
|
34053
34052
|
var OFF = { settled: async () => {
|
|
@@ -34061,6 +34060,7 @@ function startVersionCheck(options) {
|
|
|
34061
34060
|
const file = (0, import_path3.join)(options.stateDir ?? globalDataDir(), STATE_FILE);
|
|
34062
34061
|
let inFlight = Promise.resolve();
|
|
34063
34062
|
let pinging = false;
|
|
34063
|
+
let stopped2 = false;
|
|
34064
34064
|
let named3;
|
|
34065
34065
|
const lessThanADayAgo = (at) => {
|
|
34066
34066
|
if (!at) return false;
|
|
@@ -34068,7 +34068,7 @@ function startVersionCheck(options) {
|
|
|
34068
34068
|
return since >= 0 && since < DAY_MS;
|
|
34069
34069
|
};
|
|
34070
34070
|
const showUpdate = (latest) => {
|
|
34071
|
-
if (!options.onUpdate || latest === named3) return;
|
|
34071
|
+
if (stopped2 || !options.onUpdate || latest === named3 || !isNewer(latest, options.version)) return;
|
|
34072
34072
|
if (options.updateLine === "daily") {
|
|
34073
34073
|
const state2 = readState(file);
|
|
34074
34074
|
if (lessThanADayAgo(state2.updateShownAt) || !writeState(file, { ...state2, updateShownAt: new Date(now2()).toISOString() })) return;
|
|
@@ -34082,27 +34082,28 @@ function startVersionCheck(options) {
|
|
|
34082
34082
|
const ping = async (version, installId) => {
|
|
34083
34083
|
const query = new URLSearchParams({ v: version, id: installId });
|
|
34084
34084
|
const abort = new AbortController();
|
|
34085
|
-
const
|
|
34086
|
-
|
|
34085
|
+
const timer = setTimeout(() => abort.abort(), TIMEOUT_MS);
|
|
34086
|
+
timer.unref?.();
|
|
34087
34087
|
try {
|
|
34088
34088
|
const response = await fetchImpl(`${VERSION_CHECK_URL}?${query}`, {
|
|
34089
34089
|
method: "GET",
|
|
34090
34090
|
signal: abort.signal,
|
|
34091
34091
|
redirect: "manual"
|
|
34092
34092
|
});
|
|
34093
|
-
const latest = await readAnswer(response
|
|
34093
|
+
const latest = await readAnswer(response);
|
|
34094
34094
|
if (latest === void 0) return;
|
|
34095
34095
|
const state2 = readState(file);
|
|
34096
|
-
|
|
34097
|
-
|
|
34098
|
-
|
|
34099
|
-
if (latest) showUpdate(latest);
|
|
34096
|
+
if (state2.latest && isNewer(state2.latest, latest)) return;
|
|
34097
|
+
writeState(file, { ...state2, latest, latestAt: new Date(now2()).toISOString() });
|
|
34098
|
+
showUpdate(latest);
|
|
34100
34099
|
} finally {
|
|
34101
|
-
clearTimeout(
|
|
34100
|
+
clearTimeout(timer);
|
|
34102
34101
|
}
|
|
34103
34102
|
};
|
|
34104
|
-
const check2 = () => {
|
|
34105
|
-
|
|
34103
|
+
const check2 = (mayPing) => {
|
|
34104
|
+
const remembered = readState(file).latest;
|
|
34105
|
+
if (remembered) showUpdate(remembered);
|
|
34106
|
+
if (!mayPing || pinging) return;
|
|
34106
34107
|
const state2 = readState(file);
|
|
34107
34108
|
if (!state2.installId) return;
|
|
34108
34109
|
if (lessThanADayAgo(state2.lastCheckAt)) return;
|
|
@@ -34113,6 +34114,17 @@ function startVersionCheck(options) {
|
|
|
34113
34114
|
pinging = false;
|
|
34114
34115
|
});
|
|
34115
34116
|
};
|
|
34117
|
+
const recheckEveryHour = (mayPing) => {
|
|
34118
|
+
const timer = setInterval(() => check2(mayPing), RECHECK_MS);
|
|
34119
|
+
timer.unref?.();
|
|
34120
|
+
return {
|
|
34121
|
+
settled: () => inFlight,
|
|
34122
|
+
stop: () => {
|
|
34123
|
+
stopped2 = true;
|
|
34124
|
+
clearInterval(timer);
|
|
34125
|
+
}
|
|
34126
|
+
};
|
|
34127
|
+
};
|
|
34116
34128
|
const state = rotateInstallId(file, readState(file), now2());
|
|
34117
34129
|
if (!state.noticeShownAt || !state.installId) {
|
|
34118
34130
|
const installId = state.installId ?? (0, import_crypto3.randomUUID)();
|
|
@@ -34122,17 +34134,15 @@ function startVersionCheck(options) {
|
|
|
34122
34134
|
installIdAt: state.installId && state.installIdAt ? state.installIdAt : new Date(now2()).toISOString(),
|
|
34123
34135
|
noticeShownAt: new Date(now2()).toISOString()
|
|
34124
34136
|
});
|
|
34137
|
+
if (!recorded3) return OFF;
|
|
34125
34138
|
try {
|
|
34126
|
-
|
|
34139
|
+
options.onNotice(VERSION_CHECK_NOTICE);
|
|
34127
34140
|
} catch {
|
|
34128
34141
|
}
|
|
34129
|
-
return
|
|
34142
|
+
return recheckEveryHour(false);
|
|
34130
34143
|
}
|
|
34131
|
-
|
|
34132
|
-
|
|
34133
|
-
const timer = setInterval(check2, RECHECK_MS);
|
|
34134
|
-
timer.unref?.();
|
|
34135
|
-
return { settled: () => inFlight, stop: () => clearInterval(timer) };
|
|
34144
|
+
check2(true);
|
|
34145
|
+
return recheckEveryHour(true);
|
|
34136
34146
|
}
|
|
34137
34147
|
|
|
34138
34148
|
// src/index.ts
|