mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 09:30:01 +08:00
fix(core): version guard (#15226)
fix #15225 #### PR Dependency Tree * **PR #15226** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved self-hosted server version validation. * Correctly supports compatible beta and release-candidate versions. * Rejects outdated pre-release versions consistently. * Provides the appropriate unsupported-version guidance when compatibility requirements are not met. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -9,13 +9,17 @@ import {
|
||||
describe('server config version guard', () => {
|
||||
test('accepts supported server versions', () => {
|
||||
expect(() => assertSupportedServerVersion('0.27.0')).not.toThrow();
|
||||
expect(() => assertSupportedServerVersion('0.27.0-beta.5')).not.toThrow();
|
||||
expect(() => assertSupportedServerVersion('0.27.0-rc.1')).not.toThrow();
|
||||
expect(() => assertSupportedServerVersion('0.28.0')).not.toThrow();
|
||||
});
|
||||
|
||||
test('rejects old server versions', () => {
|
||||
expect(() => assertSupportedServerVersion('0.26.9')).toThrow(
|
||||
UserFriendlyError
|
||||
);
|
||||
for (const version of ['0.26.9', '0.26.9-beta.5']) {
|
||||
expect(() => assertSupportedServerVersion(version)).toThrow(
|
||||
UserFriendlyError
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('rejects missing or invalid server versions', () => {
|
||||
|
||||
@@ -47,16 +47,18 @@ export function createUnsupportedServerVersionError(version?: string | null) {
|
||||
});
|
||||
}
|
||||
|
||||
export function assertSupportedServerVersion(version?: string | null) {
|
||||
if (!version) {
|
||||
throw createUnsupportedServerVersionError(version);
|
||||
}
|
||||
export function isSupportedServerVersion(version?: string | null) {
|
||||
const normalized = version && semver.valid(version, { loose: true });
|
||||
return (
|
||||
!!normalized &&
|
||||
semver.gte(normalized, `${MIN_SUPPORTED_SERVER_VERSION}-0`, {
|
||||
loose: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const normalized = semver.valid(version, { loose: true });
|
||||
if (
|
||||
!normalized ||
|
||||
semver.lt(normalized, MIN_SUPPORTED_SERVER_VERSION, { loose: true })
|
||||
) {
|
||||
export function assertSupportedServerVersion(version?: string | null) {
|
||||
if (!isSupportedServerVersion(version)) {
|
||||
throw createUnsupportedServerVersionError(version);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user