refactor: update to dioc v3 (#4009)

Co-authored-by: jamesgeorge007 <jamesgeorge998001@gmail.com>
This commit is contained in:
Andrew Bastin
2024-04-29 19:06:18 +05:30
committed by GitHub
parent f89561da54
commit be57255bf7
46 changed files with 173 additions and 170 deletions

View File

@@ -24,9 +24,7 @@ export class EnvironmentMenuService extends Service implements ContextMenu {
private readonly contextMenu = this.bind(ContextMenuService)
constructor() {
super()
override onServiceInit() {
this.contextMenu.registerMenu(this)
}

View File

@@ -41,9 +41,7 @@ export class ParameterMenuService extends Service implements ContextMenu {
private readonly contextMenu = this.bind(ContextMenuService)
constructor() {
super()
override onServiceInit() {
this.contextMenu.registerMenu(this)
}

View File

@@ -39,9 +39,7 @@ export class URLMenuService extends Service implements ContextMenu {
private readonly contextMenu = this.bind(ContextMenuService)
private readonly restTab = this.bind(RESTTabService)
constructor() {
super()
override onServiceInit() {
this.contextMenu.registerMenu(this)
}

View File

@@ -20,10 +20,6 @@ export class CookieJarService extends Service {
*/
public cookieJar = ref(new Map<string, string[]>())
constructor() {
super()
}
public parseSetCookieString(setCookieString: string) {
return setCookieParse(setCookieString)
}

View File

@@ -14,9 +14,7 @@ import { Service } from "dioc"
export class DebugService extends Service {
public static readonly ID = "DEBUG_SERVICE"
constructor() {
super()
override onServiceInit() {
console.log("DebugService is initialized...")
const container = this.getContainer()

View File

@@ -107,9 +107,7 @@ export class InspectionService extends Service {
private readonly restTab = this.bind(RESTTabService)
constructor() {
super()
override onServiceInit() {
this.initializeListeners()
}

View File

@@ -53,9 +53,7 @@ export class EnvironmentInspectorService extends Service implements Inspector {
}
)[0]
constructor() {
super()
override onServiceInit() {
this.inspection.registerInspector(this)
}

View File

@@ -22,9 +22,7 @@ export class HeaderInspectorService extends Service implements Inspector {
private readonly inspection = this.bind(InspectionService)
private readonly interceptorService = this.bind(InterceptorService)
constructor() {
super()
override onServiceInit() {
this.inspection.registerInspector(this)
}

View File

@@ -23,9 +23,7 @@ export class ResponseInspectorService extends Service implements Inspector {
private readonly inspection = this.bind(InspectionService)
constructor() {
super()
override onServiceInit() {
this.inspection.registerInspector(this)
}

View File

@@ -178,9 +178,7 @@ export class InterceptorService extends Service {
return this.interceptors.get(this.currentInterceptorID.value)
})
constructor() {
super()
override onServiceInit() {
// If the current interceptor is unselectable, select the first selectable one, else null
watch([() => this.interceptors, this.currentInterceptorID], () => {
if (!this.currentInterceptorID.value) return

View File

@@ -109,10 +109,6 @@ export class OauthAuthService extends Service {
public static readonly ID = "OAUTH_AUTH_SERVICE"
static redirectURI = `${window.location.origin}/oauth`
constructor() {
super()
}
}
export const generateRandomString = () => {

View File

@@ -89,10 +89,6 @@ export class PersistenceService extends Service {
public hoppLocalConfigStorage: StorageLike = localStorage
constructor() {
super()
}
private showErrorToast(localStorageKey: string) {
const toast = useToast()
toast.error(

View File

@@ -27,10 +27,6 @@ export class SecretEnvironmentService extends Service {
*/
public secretEnvironments = reactive(new Map<string, SecretVariable[]>())
constructor() {
super()
}
/**
* Add a new secret environment.
* @param id ID of the environment

View File

@@ -6,6 +6,7 @@ import {
import { nextTick, reactive, ref } from "vue"
import { SpotlightSearcherResult } from "../../.."
import { TestContainer } from "dioc/testing"
import { Container } from "dioc"
async function flushPromises() {
return await new Promise((r) => setTimeout(r))
@@ -32,12 +33,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}
@@ -94,12 +98,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}
@@ -159,12 +166,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}
@@ -224,12 +234,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}
@@ -285,12 +298,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}
@@ -354,12 +370,15 @@ describe("StaticSpotlightSearcherService", () => {
},
})
constructor() {
super({
// TODO: dioc > v3 does not recommend using constructors, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternate"],
fieldWeights: {},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
}

View File

@@ -1,4 +1,4 @@
import { Service } from "dioc"
import { Container, Service } from "dioc"
import {
type SpotlightSearcher,
type SpotlightSearcherResult,
@@ -67,8 +67,12 @@ export abstract class StaticSpotlightSearcherService<
private _documents: Record<string, Doc> = {}
constructor(private opts: StaticSpotlightSearcherOptions<Doc>) {
super()
// TODO: This pattern is no longer recommended in dioc > 3, move to something else
constructor(
c: Container,
private opts: StaticSpotlightSearcherOptions<Doc>
) {
super(c)
this.minisearch = new MiniSearch({
fields: opts.searchFields as string[],

View File

@@ -50,9 +50,7 @@ export class CollectionsSpotlightSearcherService
private readonly spotlight = this.bind(SpotlightService)
private readonly workspaceService = this.bind(WorkspaceService)
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -26,7 +26,7 @@ import IconEdit from "~icons/lucide/edit"
import IconLayers from "~icons/lucide/layers"
import IconTrash2 from "~icons/lucide/trash-2"
import { Service } from "dioc"
import { Container, Service } from "dioc"
import * as TE from "fp-ts/TaskEither"
import { pipe } from "fp-ts/function"
import { cloneDeep } from "lodash-es"
@@ -164,15 +164,18 @@ export class EnvironmentsSpotlightSearcherService extends StaticSpotlightSearche
},
})
constructor() {
super({
// TODO: This pattern is no longer recommended in dioc > 3, move to something else
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}
@@ -277,9 +280,7 @@ export class SwitchEnvSpotlightSearcherService
private readonly workspaceService = this.bind(WorkspaceService)
private teamEnvironmentList: TeamEnvironment[] = []
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -15,6 +15,7 @@ import IconBook from "~icons/lucide/book"
import IconLifeBuoy from "~icons/lucide/life-buoy"
import IconZap from "~icons/lucide/zap"
import { platform } from "~/platform"
import { Container } from "dioc"
type Doc = {
text: string | string[]
@@ -89,15 +90,18 @@ export class GeneralSpotlightSearcherService extends StaticSpotlightSearcherServ
},
})
constructor() {
super({
// TODO: This is not recommended as of dioc > 3. Move to onServiceInit instead
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -66,9 +66,7 @@ export class HistorySpotlightSearcherService
}
)[0]
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -31,9 +31,7 @@ export class InterceptorSpotlightSearcherService
private readonly spotlight = this.bind(SpotlightService)
private interceptorService = this.bind(InterceptorService)
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -8,6 +8,7 @@ import {
} from "./base/static.searcher"
import IconShare from "~icons/lucide/share"
import { Container } from "dioc"
type Doc = {
text: string
@@ -39,15 +40,18 @@ export class MiscellaneousSpotlightSearcherService extends StaticSpotlightSearch
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -8,6 +8,7 @@ import {
} from "./base/static.searcher"
import IconArrowRight from "~icons/lucide/arrow-right"
import { Container } from "dioc"
type Doc = {
text: string
@@ -61,15 +62,18 @@ export class NavigationSpotlightSearcherService extends StaticSpotlightSearcherS
private docKeys = Object.keys(this.documents)
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, use onServiceInit instead
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -20,6 +20,7 @@ import IconRotateCCW from "~icons/lucide/rotate-ccw"
import IconSave from "~icons/lucide/save"
import { GQLOptionTabs } from "~/components/graphql/RequestOptions.vue"
import { RESTTabService } from "~/services/tab/rest"
import { Container } from "dioc"
type Doc = {
text: string | string[]
@@ -224,15 +225,18 @@ export class RequestSpotlightSearcherService extends StaticSpotlightSearcherServ
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, use onServiceInit instead
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -9,6 +9,7 @@ import {
import IconDownload from "~icons/lucide/download"
import IconCopy from "~icons/lucide/copy"
import { Container } from "dioc"
type Doc = {
text: string
@@ -56,15 +57,18 @@ export class ResponseSpotlightSearcherService extends StaticSpotlightSearcherSer
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -15,6 +15,7 @@ import IconMonitor from "~icons/lucide/monitor"
import IconMoon from "~icons/lucide/moon"
import IconSun from "~icons/lucide/sun"
import IconCheckCircle from "~icons/lucide/check-circle"
import { Container } from "dioc"
type Doc = {
text: string | string[]
@@ -100,15 +101,18 @@ export class SettingsSpotlightSearcherService extends StaticSpotlightSearcherSer
},
})
constructor() {
super({
// TODO: Constuctors are no longer recommended as of dioc > 3, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -14,6 +14,7 @@ import IconXSquare from "~icons/lucide/x-square"
import { invokeAction } from "~/helpers/actions"
import { RESTTabService } from "~/services/tab/rest"
import { GQLTabService } from "~/services/tab/graphql"
import { Container } from "dioc"
type Doc = {
text: string | string[]
@@ -89,15 +90,18 @@ export class TabSpotlightSearcherService extends StaticSpotlightSearcherService<
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, use onServiceInit instead
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -39,9 +39,7 @@ export class TeamsSpotlightSearcherService
private readonly tabs = this.bind(RESTTabService)
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -9,6 +9,7 @@ import { useStreamStatic } from "~/composables/stream"
import IconLogin from "~icons/lucide/log-in"
import IconLogOut from "~icons/lucide/log-out"
import { activeActions$, invokeAction } from "~/helpers/actions"
import { Container } from "dioc"
type Doc = {
text: string
@@ -59,15 +60,18 @@ export class UserSpotlightSearcherService extends StaticSpotlightSearcherService
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit(): void {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}

View File

@@ -21,7 +21,7 @@ import {
StaticSpotlightSearcherService,
} from "./base/static.searcher"
import { Service } from "dioc"
import { Container, Service } from "dioc"
import * as E from "fp-ts/Either"
import MiniSearch from "minisearch"
import IconCheckCircle from "~/components/app/spotlight/entry/IconSelected.vue"
@@ -102,15 +102,18 @@ export class WorkspaceSpotlightSearcherService extends StaticSpotlightSearcherSe
},
})
constructor() {
super({
// TODO: Constructors are no longer recommended as of dioc > 3, move to onServiceInit
constructor(c: Container) {
super(c, {
searchFields: ["text", "alternates"],
fieldWeights: {
text: 2,
alternates: 1,
},
})
}
override onServiceInit() {
this.setDocuments(this.documents)
this.spotlight.registerSearcher(this)
}
@@ -166,9 +169,7 @@ export class SwitchWorkspaceSpotlightSearcherService
private readonly spotlight = this.bind(SpotlightService)
private readonly workspaceService = this.bind(WorkspaceService)
constructor() {
super()
override onServiceInit() {
this.spotlight.registerSearcher(this)
}

View File

@@ -6,9 +6,7 @@ import { reactive } from "vue"
class MockTabService extends TabService<{ request: string }> {
public static readonly ID = "MOCK_TAB_SERVICE"
constructor() {
super()
override onServiceInit() {
this.tabMap = reactive(
new Map([
[

View File

@@ -7,9 +7,7 @@ import { computed } from "vue"
export class GQLTabService extends TabService<HoppGQLDocument> {
public static readonly ID = "GQL_TAB_SERVICE"
constructor() {
super()
override onServiceInit() {
this.tabMap.set("test", {
id: "test",
document: {

View File

@@ -7,9 +7,7 @@ import { TabService } from "./tab"
export class RESTTabService extends TabService<HoppRESTDocument> {
public static readonly ID = "REST_TAB_SERVICE"
constructor() {
super()
override onServiceInit() {
this.tabMap.set("test", {
id: "test",
document: {

View File

@@ -48,8 +48,7 @@ export class WorkspaceService extends Service<WorkspaceServiceEvent> {
-1
)
constructor() {
super()
override onServiceInit() {
// Dispose the managed team list adapter when the user logs out
// and initialize it when the user logs in
watch(