Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update to dioc v3 #4009

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/hoppscotch-common/package.json
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/hoppscotch-common/src/components.d.ts
Expand Up @@ -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']
Expand Down
Expand Up @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions packages/hoppscotch-common/src/modules/dioc.ts
@@ -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"
Expand All @@ -22,19 +22,18 @@ 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)
}

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)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hoppscotch-common/src/platform/index.ts
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions packages/hoppscotch-common/src/platform/inspectors.ts
@@ -1,4 +1,4 @@
import { Service } from "dioc"
import { Container, ServiceClassInstance } from "dioc"
import { Inspector } from "~/services/inspection"

/**
Expand All @@ -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
}
}

Expand Down
7 changes: 4 additions & 3 deletions packages/hoppscotch-common/src/platform/interceptors.ts
@@ -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
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hoppscotch-common/src/platform/spotlight.ts
@@ -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
}
>
}
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -133,9 +133,7 @@ export class ExtensionInterceptorService

public selectable = { type: "selectable" as const }

constructor() {
super()

override onServiceInit() {
this.listenForExtensionStatus()
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions packages/hoppscotch-common/src/services/debug.service.ts
Expand Up @@ -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()
Expand Down
Expand Up @@ -107,9 +107,7 @@ export class InspectionService extends Service {

private readonly restTab = this.bind(RESTTabService)

constructor() {
super()

override onServiceInit() {
this.initializeListeners()
}

Expand Down
Expand Up @@ -53,9 +53,7 @@ export class EnvironmentInspectorService extends Service implements Inspector {
}
)[0]

constructor() {
super()

override onServiceInit() {
this.inspection.registerInspector(this)
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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)
}

Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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 = () => {
Expand Down
Expand Up @@ -89,10 +89,6 @@ export class PersistenceService extends Service {

public hoppLocalConfigStorage: StorageLike = localStorage

constructor() {
super()
}

private showErrorToast(localStorageKey: string) {
const toast = useToast()
toast.error(
Expand Down
Expand Up @@ -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
Expand Down