Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
chore: move collections sync system to platform (#2940)
Akash K7e1b26c6a9c6
diff --git a/packages/hoppscotch-common/src/helpers/fb/index.ts b/packages/hoppscotch-common/src/helpers/fb/index.tsindex 1e8af88d7..9b82c20f5 100644--- a/packages/hoppscotch-common/src/helpers/fb/index.ts+++ b/packages/hoppscotch-common/src/helpers/fb/index.ts@@ -1,7 +1,6 @@import { initializeApp } from "firebase/app"import { platform } from "~/platform"import { initAnalytics } from "./analytics"-import { initCollections } from "./collections"import { initHistory } from "./history"import { initSettings } from "./settings"@@ -25,7 +24,7 @@ export function initializeFirebase() {platform.auth.performAuthInit()initSettings()- initCollections()+ platform.sync.collections.initCollectionsSync()initHistory()platform.sync.environments.initEnvironmentsSync()initAnalytics()diff --git a/packages/hoppscotch-common/src/platform/collections.ts b/packages/hoppscotch-common/src/platform/collections.tsnew file mode 100644index 000000000..107ba4af6--- /dev/null+++ b/packages/hoppscotch-common/src/platform/collections.ts@@ -0,0 +1,3 @@+export type CollectionsPlatformDef = {+ initCollectionsSync: () => void+}diff --git a/packages/hoppscotch-common/src/platform/index.ts b/packages/hoppscotch-common/src/platform/index.tsindex 5a0203dc7..5845f4065 100644--- a/packages/hoppscotch-common/src/platform/index.ts+++ b/packages/hoppscotch-common/src/platform/index.ts@@ -1,12 +1,14 @@import { AuthPlatformDef } from "./auth"import { UIPlatformDef } from "./ui"import { EnvironmentsPlatformDef } from "./environments"+import { CollectionsPlatformDef } from "./collections"export type PlatformDef = {ui?: UIPlatformDefauth: AuthPlatformDefsync: {environments: EnvironmentsPlatformDef+ collections: CollectionsPlatformDef}}diff --git a/packages/hoppscotch-web/package.json b/packages/hoppscotch-web/package.jsonindex 06607c0f8..a5a1835e9 100644--- a/packages/hoppscotch-web/package.json+++ b/packages/hoppscotch-web/package.json@@ -28,7 +28,8 @@"stream-browserify": "^3.0.0","util": "^0.12.4","vue": "^3.2.41",- "workbox-window": "^6.5.4"+ "workbox-window": "^6.5.4",+ "@hoppscotch/data": "workspace:^0.4.4"},"devDependencies": {"@intlify/vite-plugin-vue-i18n": "^6.0.1",diff --git a/packages/hoppscotch-common/src/helpers/fb/collections.ts b/packages/hoppscotch-web/src/collections.tssimilarity index 86%rename from packages/hoppscotch-common/src/helpers/fb/collections.tsrename to packages/hoppscotch-web/src/collections.tsindex 8f8cff180..d20412fd6 100644--- a/packages/hoppscotch-common/src/helpers/fb/collections.ts+++ b/packages/hoppscotch-web/src/collections.ts@@ -9,14 +9,22 @@ import {translateToNewRESTCollection,translateToNewGQLCollection,} from "@hoppscotch/data"-import { platform } from "~/platform"++import { def as platformAuth } from "./firebase/auth"+import {restCollections$,graphqlCollections$,setRESTCollections,setGraphqlCollections,-} from "~/newstore/collections"-import { getSettingSubject, settingsStore } from "~/newstore/settings"+} from "@hoppscotch/common/newstore/collections"++import {+ getSettingSubject,+ settingsStore,+} from "@hoppscotch/common/newstore/settings"++import { CollectionsPlatformDef } from "@hoppscotch/common/platform/collections"type CollectionFlags = "collectionsGraphql" | "collections"@@ -40,11 +48,8 @@ let loadedRESTCollections = false*/let loadedGraphqlCollections = false-export async function writeCollections(- collection: any[],- flag: CollectionFlags-) {- const currentUser = platform.auth.getCurrentUser()+async function writeCollections(collection: any[], flag: CollectionFlags) {+ const currentUser = platformAuth.getCurrentUser()if (currentUser === null)throw new Error("User not logged in to write collections")@@ -68,11 +73,11 @@ export async function writeCollections(}}-export function initCollections() {- const currentUser$ = platform.auth.getCurrentUserStream()+function initCollectionsSync() {+ const currentUser$ = platformAuth.getCurrentUserStream()const restCollSub = restCollections$.subscribe((collections) => {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (loadedRESTCollections &&@@ -84,7 +89,7 @@ export function initCollections() {})const gqlCollSub = graphqlCollections$.subscribe((collections) => {- const currentUser = platform.auth.getCurrentUser()+ const currentUser = platformAuth.getCurrentUser()if (loadedGraphqlCollections &&@@ -177,8 +182,12 @@ export function initCollections() {gqlCollSub.unsubscribe()currentUserSub.unsubscribe()- initCollections()+ initCollectionsSync()}})}++export const def: CollectionsPlatformDef = {+ initCollectionsSync,+}diff --git a/packages/hoppscotch-web/src/main.ts b/packages/hoppscotch-web/src/main.tsindex 5945e25ac..e223e6493 100644--- a/packages/hoppscotch-web/src/main.ts+++ b/packages/hoppscotch-web/src/main.ts@@ -1,10 +1,12 @@import { createHoppApp } from "@hoppscotch/common"import { def as authDef } from "./firebase/auth"import { def as envDef } from "./environments"+import { def as collectionsDef } from "./collections"createHoppApp("#app", {auth: authDef,sync: {environments: envDef,+ collections: collectionsDef,},})diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 70e7cd0c0..85be2f416 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -345,7 +345,7 @@ importers:vite-plugin-inspect: [email protected]vite-plugin-pages: 0.26.0_vnheu5mvzzbfbuhqo4shkhdheivite-plugin-pages-sitemap: 1.4.0- vite-plugin-pwa: 0.13.1_bg4cnt4dy3xq3a47wkujd6ryzq+ vite-plugin-pwa: [email protected]vite-plugin-vue-layouts: 0.7.0_oewzdqozxqnqgsrjzmwikx34vivite-plugin-windicss: [email protected]vue-tsc: [email protected]@@ -551,6 +551,7 @@ importers:packages/hoppscotch-web:specifiers:'@hoppscotch/common': workspace:^+ '@hoppscotch/data': workspace:^0.4.4'@hoppscotch/ui': workspace:^'@intlify/vite-plugin-vue-i18n': ^6.0.1'@rushstack/eslint-patch': ^1.1.4@@ -588,6 +589,7 @@ importers:workbox-window: ^6.5.4dependencies:'@hoppscotch/common': link:../hoppscotch-common+ '@hoppscotch/data': link:../hoppscotch-data'@hoppscotch/ui': link:../hoppscotch-uibuffer: 6.0.3firebase: 9.8.4@@ -618,7 +620,7 @@ importers:vite-plugin-inspect: [email protected]vite-plugin-pages: [email protected]vite-plugin-pages-sitemap: 1.4.0- vite-plugin-pwa: 0.13.1_3kw35epztoiwny7qtfesjexvtu+ vite-plugin-pwa: [email protected]vite-plugin-static-copy: [email protected]vite-plugin-vue-layouts: [email protected][email protected]vite-plugin-windicss: [email protected]@@ -5723,7 +5725,7 @@ packages:dev: true/after/0.8.2:- resolution: {integrity: sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=}+ resolution: {integrity: sha512-QbJ0NTQ/I9DI3uSJA4cbexiwQeRAfjPScqIbSjUDd9TOrcg6pTkdgziesOqxBMBzit8vFCTwrP27t13vFOORRA==}dev: false/agent-base/6.0.2:@@ -6080,7 +6082,7 @@ packages:resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}/base64-arraybuffer/0.1.4:- resolution: {integrity: sha1-mBjHngWbE1X5fgQooBfIOOkLqBI=}+ resolution: {integrity: sha512-a1eIFi4R9ySrbiMuyTGx5e92uRH5tQY6kArNcFaKBUleIoLjdjBg7Zxm3Mqm3Kmkf27HLR/1fnxX9q8GQ7Iavg==}engines: {node: '>= 0.6.0'}dev: false@@ -6542,7 +6544,7 @@ packages:dev: true/component-bind/1.0.0:- resolution: {integrity: sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=}+ resolution: {integrity: sha512-WZveuKPeKAG9qY+FkYDeADzdHyTYdIboXS59ixDeRJL5ZhxpqUnxSOwop4FQjMsiYm3/Or8cegVbpAHNA7pHxw==}dev: false/component-emitter/1.3.0:@@ -6550,7 +6552,7 @@ packages:dev: false/component-inherit/0.0.3:- resolution: {integrity: sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=}+ resolution: {integrity: sha512-w+LhYREhatpVqTESyGFg3NlP6Iu0kEKUHETY9GoZP/pQyW4mHFZuFWRUCIqVPZ36ueVLtoOEZaAqbCF2RDndaA==}dev: false/concat-map/0.0.1:@@ -8954,7 +8956,7 @@ packages:dev: false/has-cors/1.1.0:- resolution: {integrity: sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=}+ resolution: {integrity: sha512-g5VNKdkFuUuVCP9gYfDJHjK2nqdQJ7aDLTnycnc2+RvsOQbuLdF5pm7vuE5J76SEBIQjs4kQY/BWq74JUmjbXA==}dev: false/has-flag/3.0.0:@@ -9258,7 +9260,7 @@ packages:engines: {node: '>=8'}/indexof/0.0.1:- resolution: {integrity: sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=}+ resolution: {integrity: sha512-i0G7hLJ1z0DE8dsqJa2rycj9dBmNKgXBvotXtZYXakU9oivfB9Uj2ZBC27qqef2U58/ZLwalxa1X/RDCdkHtVg==}dev: false/inflight/1.0.6:@@ -12953,7 +12955,7 @@ packages:dev: true/to-array/0.1.4:- resolution: {integrity: sha1-F+bBH3PdTz10zaek/zI46a2b+JA=}+ resolution: {integrity: sha512-LhVdShQD/4Mk4zXNroIQZJC+Ap3zgLcDuwEdcmLv9CCO73NWockQDwyUnW/m8VX/EElfL6FcYx7EeutN4HJA6A==}dev: false/to-fast-properties/2.0.0:@@ -14023,29 +14025,10 @@ packages:- supports-colordev: true- /vite-plugin-pwa/0.13.1_3kw35epztoiwny7qtfesjexvtu:+ /vite-plugin-pwa/[email protected]:resolution: {integrity: sha512-NR3dIa+o2hzlzo4lF4Gu0cYvoMjSw2DdRc6Epw1yjmCqWaGuN86WK9JqZie4arNlE1ZuWT3CLiMdiX5wcmmUmg==}peerDependencies:vite: ^3.1.0- workbox-window: ^6.5.4- dependencies:- debug: 4.3.4- fast-glob: 3.2.11- pretty-bytes: 6.0.0- rollup: 2.79.1- vite: 3.2.4- workbox-build: 6.5.4- workbox-window: 6.5.4- transitivePeerDependencies:- - '@types/babel__core'- - supports-color- dev: true-- /vite-plugin-pwa/0.13.1_bg4cnt4dy3xq3a47wkujd6ryzq:- resolution: {integrity: sha512-NR3dIa+o2hzlzo4lF4Gu0cYvoMjSw2DdRc6Epw1yjmCqWaGuN86WK9JqZie4arNlE1ZuWT3CLiMdiX5wcmmUmg==}- peerDependencies:- vite: ^3.1.0- workbox-window: ^6.5.4dependencies:debug: 4.3.4fast-glob: 3.2.11@@ -14063,7 +14046,6 @@ packages:resolution: {integrity: sha512-NR3dIa+o2hzlzo4lF4Gu0cYvoMjSw2DdRc6Epw1yjmCqWaGuN86WK9JqZie4arNlE1ZuWT3CLiMdiX5wcmmUmg==}peerDependencies:vite: ^3.1.0- workbox-window: ^6.5.4dependencies:debug: 4.3.4fast-glob: 3.2.11@@ -14071,6 +14053,7 @@ packages:rollup: 2.79.1vite: [email protected]workbox-build: 6.5.4+ workbox-window: 6.5.4transitivePeerDependencies:- '@types/babel__core'- supports-color@@ -15099,7 +15082,7 @@ packages:dev: false/yeast/0.1.2:- resolution: {integrity: sha1-AI4G2AlDIMNy28L47XagymyKxBk=}+ resolution: {integrity: sha512-8HFIh676uyGYP6wP13R/j6OJ/1HwJ46snpvzE7aHAN3Ryqh2yX6Xox2B4CUmTwwOIzlG3Bs7ocsP5dZH/R1Qbg==}dev: false/yn/3.1.1: