-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SY-1367: Allow Silencing of Version Update Notification (#879)
- Loading branch information
Showing
16 changed files
with
207 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
import { migrate } from "@synnaxlabs/x"; | ||
|
||
import * as v0 from "@/version/migrations/v0"; | ||
import * as v1 from "@/version/migrations/v1"; | ||
|
||
export type SliceState = v1.SliceState; | ||
export type AnySliceState = v0.SliceState | v1.SliceState; | ||
export const ZERO_SLICE_STATE = v1.ZERO_SLICE_STATE; | ||
|
||
export const SLICE_MIGRATIONS: migrate.Migrations = {}; | ||
|
||
// Because the v0 state had a key called version, the usual migration pattern from X | ||
// does not work. Instead, we need to check if the state is a v0 state, manually convert | ||
// it to a v1 state, and then run the internal migrator. | ||
|
||
const internalMigrator = migrate.migrator<AnySliceState, SliceState>({ | ||
name: "version.slice", | ||
migrations: SLICE_MIGRATIONS, | ||
def: ZERO_SLICE_STATE, | ||
}); | ||
|
||
const v0StrictSliceStateZ = v0.sliceStateZ.strict(); | ||
|
||
export const migrateSlice: (v: AnySliceState) => SliceState = (v) => { | ||
const state = v0StrictSliceStateZ.safeParse(v).success ? v1.migrate(v) : v; | ||
return internalMigrator(state); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in | ||
// the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business | ||
// Source License, use of this software will be governed by the Apache License, | ||
// Version 2.0, included in the file licenses/APL.txt. | ||
|
||
import { describe, expect, it } from "vitest"; | ||
|
||
import { migrateSlice, ZERO_SLICE_STATE } from "@/version/migrations"; | ||
import * as v0 from "@/version/migrations/v0"; | ||
import * as v1 from "@/version/migrations/v1"; | ||
|
||
describe("migrations", () => { | ||
describe("slice", () => { | ||
const STATES = [v0.ZERO_SLICE_STATE, v1.ZERO_SLICE_STATE]; | ||
STATES.forEach((state) => | ||
it(`should migrate slice from ${state.version} to latest`, () => { | ||
const migrated = migrateSlice(state); | ||
expect(migrated).toEqual(ZERO_SLICE_STATE); | ||
}), | ||
); | ||
}); | ||
describe("slice with a version", () => { | ||
const consoleVersion = "0.27.0"; | ||
const V0_STATE: v0.SliceState = { | ||
version: consoleVersion, | ||
}; | ||
const V1_STATE: v1.SliceState = { | ||
version: "1.0.0", | ||
consoleVersion, | ||
updateNotificationsSilenced: false, | ||
}; | ||
it(`should migrate slice from ${V0_STATE.version} to latest`, () => { | ||
const migrated = migrateSlice(V0_STATE); | ||
console.log(migrated); | ||
expect(migrated).toEqual(migrateSlice(V1_STATE)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
import { z } from "zod"; | ||
|
||
export const sliceStateZ = z.object({ | ||
version: z.string(), | ||
}); | ||
|
||
export type SliceState = z.infer<typeof sliceStateZ>; | ||
|
||
export const ZERO_SLICE_STATE: SliceState = { | ||
version: "0.0.0", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2024 Synnax Labs, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License included in the file | ||
// licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with the Business Source | ||
// License, use of this software will be governed by the Apache License, Version 2.0, | ||
// included in the file licenses/APL.txt. | ||
|
||
import { z } from "zod"; | ||
|
||
import * as v0 from "@/version/migrations/v0"; | ||
|
||
export const sliceStateZ = z.object({ | ||
version: z.literal("1.0.0"), | ||
consoleVersion: z.string(), | ||
updateNotificationsSilenced: z.boolean(), | ||
}); | ||
export type SliceState = z.infer<typeof sliceStateZ>; | ||
|
||
export const ZERO_SLICE_STATE: SliceState = { | ||
version: "1.0.0", | ||
consoleVersion: "0.0.0", | ||
updateNotificationsSilenced: false, | ||
}; | ||
|
||
export const migrate: (state: v0.SliceState) => SliceState = (state) => ({ | ||
version: "1.0.0", | ||
consoleVersion: state.version, | ||
updateNotificationsSilenced: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.