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

@@ -50,7 +50,7 @@
"axios": "1.6.2",
"buffer": "6.0.3",
"cookie-es": "1.0.0",
"dioc": "1.0.1",
"dioc": "3.0.1",
"esprima": "4.0.1",
"events": "3.3.0",
"fp-ts": "2.16.1",

View File

@@ -32,6 +32,7 @@ declare module 'vue' {
AppSpotlightEntryRESTHistory: typeof import('./components/app/spotlight/entry/RESTHistory.vue')['default']
AppSpotlightEntryRESTRequest: typeof import('./components/app/spotlight/entry/RESTRequest.vue')['default']
AppSpotlightEntryRESTTeamRequestEntry: typeof import('./components/app/spotlight/entry/RESTTeamRequestEntry.vue')['default']
AppSpotlightSearch: typeof import('./components/app/SpotlightSearch.vue')['default']
AppSupport: typeof import('./components/app/Support.vue')['default']
Collections: typeof import('./components/collections/index.vue')['default']
CollectionsAdd: typeof import('./components/collections/Add.vue')['default']

View File

@@ -201,7 +201,7 @@ export class TeamSearchService extends Service {
expandingCollections: Ref<string[]> = ref([])
expandedCollections: Ref<string[]> = ref([])
// FUTURE-TODO: ideally this should return the search results / formatted results instead of directly manipulating the result set
// TODO: ideally this should return the search results / formatted results instead of directly manipulating the result set
// eg: do the spotlight formatting in the spotlight searcher and not here
searchTeams = async (query: string, teamID: string) => {
if (!query.length) {

View File

@@ -1,5 +1,5 @@
import { HoppModule } from "."
import { Container, Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { diocPlugin } from "dioc/vue"
import { DebugService } from "~/services/debug.service"
import { platform } from "~/platform"
@@ -22,7 +22,7 @@ if (import.meta.env.DEV) {
* services. Please use `useService` if within components or try to convert your
* legacy subsystem into a service if possible.
*/
export function getService<T extends typeof Service<any> & { ID: string }>(
export function getService<T extends ServiceClassInstance<any>>(
service: T
): InstanceType<T> {
return serviceContainer.bind(service)
@@ -30,11 +30,10 @@ export function getService<T extends typeof Service<any> & { ID: string }>(
export default <HoppModule>{
onVueAppInit(app) {
// TODO: look into this
// @ts-expect-error Something weird with Vue versions
app.use(diocPlugin, {
container: serviceContainer,
})
for (const service of platform.addedServices ?? []) {
serviceContainer.bind(service)
}

View File

@@ -8,14 +8,14 @@ import { AnalyticsPlatformDef } from "./analytics"
import { InterceptorsPlatformDef } from "./interceptors"
import { HoppModule } from "~/modules"
import { InspectorsPlatformDef } from "./inspectors"
import { Service } from "dioc"
import { ServiceClassInstance } from "dioc"
import { IOPlatformDef } from "./io"
import { SpotlightPlatformDef } from "./spotlight"
export type PlatformDef = {
ui?: UIPlatformDef
addedHoppModules?: HoppModule[]
addedServices?: Array<typeof Service<unknown> & { ID: string }>
addedServices?: Array<ServiceClassInstance<unknown>>
auth: AuthPlatformDef
analytics?: AnalyticsPlatformDef
io: IOPlatformDef

View File

@@ -1,4 +1,4 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { Inspector } from "~/services/inspection"
/**
@@ -8,8 +8,9 @@ export type PlatformInspectorsDef = {
// We are keeping this as the only mode for now
// So that if we choose to add other modes, we can do without breaking
type: "service"
service: typeof Service<unknown> & { ID: string } & {
new (): Service & Inspector
// TODO: I don't think this type is effective, we have to come up with a better impl
service: ServiceClassInstance<unknown> & {
new (c: Container): Inspector
}
}

View File

@@ -1,12 +1,13 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { Interceptor } from "~/services/interceptor.service"
export type PlatformInterceptorDef =
| { type: "standalone"; interceptor: Interceptor }
| {
type: "service"
service: typeof Service<unknown> & { ID: string } & {
new (): Service & Interceptor
// TODO: I don't think this type is effective, we have to come up with a better impl
service: ServiceClassInstance<unknown> & {
new (c: Container): Interceptor
}
}

View File

@@ -1,10 +1,10 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { SpotlightSearcher } from "~/services/spotlight"
export type SpotlightPlatformDef = {
additionalSearchers?: Array<
typeof Service<unknown> & { ID: string } & {
new (): Service & SpotlightSearcher
ServiceClassInstance<unknown> & {
new (c: Container): SpotlightSearcher
}
>
}

View File

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

View File

@@ -133,9 +133,7 @@ export class ExtensionInterceptorService
public selectable = { type: "selectable" as const }
constructor() {
super()
override onServiceInit() {
this.listenForExtensionStatus()
}

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(

View File

@@ -23,7 +23,7 @@
"@vueuse/core": "10.5.0",
"axios": "0.21.4",
"buffer": "6.0.3",
"dioc": "1.0.1",
"dioc": "3.0.1",
"environments.api": "link:@platform/environments/environments.api",
"event": "link:@tauri-apps/api/event",
"fp-ts": "2.16.1",
@@ -78,4 +78,4 @@
"vite-plugin-vue-layouts": "0.7.0",
"vue-tsc": "1.8.8"
}
}
}

View File

@@ -138,10 +138,6 @@ export class NativeInterceptorService extends Service implements Interceptor {
public cookieJarService = this.bind(CookieJarService)
constructor() {
super()
}
public runRequest(req: any) {
const processedReq = preProcessRequest(req)