diff --git a/.firebaserc b/.firebaserc deleted file mode 100644 index 2d1217a..0000000 --- a/.firebaserc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "projects": { - "default": "kysely-playground" - } -} diff --git a/.github/workflows/deploy-preview.yml b/.github/workflows/deploy-preview.yml index 489a102..be760a2 100644 --- a/.github/workflows/deploy-preview.yml +++ b/.github/workflows/deploy-preview.yml @@ -19,10 +19,3 @@ jobs: env: VITE_BRANCH: ${{ github.ref_name }} VITE_PREVIEW: 1 - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: "${{ secrets.GITHUB_TOKEN }}" - firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_KYSELY_PLAYGROUND }}" - channelId: preview - expires: 7d - projectId: kysely-playground diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 50ce02e..95d608f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,9 +18,3 @@ jobs: - run: npm run build env: VITE_BRANCH: ${{ github.ref_name }} - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: '${{ secrets.GITHUB_TOKEN }}' - firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_KYSELY_PLAYGROUND }}' - channelId: live - projectId: kysely-playground diff --git a/.gitignore b/.gitignore index 1ba7d45..017d3be 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,4 @@ dist-ssr *.sln *.sw? -.firebase/* stats.html diff --git a/firebase.json b/firebase.json deleted file mode 100644 index 2c33c29..0000000 --- a/firebase.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "hosting": { - "public": "dist", - "ignore": [ - "firebase.json", - "**/.*", - "**/node_modules/**" - ], - "rewrites": [ - { - "source": "**", - "destination": "/index.html" - } - ] - } -} diff --git a/package-lock.json b/package-lock.json index 2ec142c..c9a7276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,6 @@ "": { "name": "kysely-playground", "dependencies": { - "firebase-firestore-lite": "^1.0.3", "highlight.js": "^11.9.0", "lz-string": "^1.5.0", "monaco-editor": "^0.50.0-dev-20240525", @@ -2274,11 +2273,6 @@ "node": "^12.20 || >= 14.13" } }, - "node_modules/firebase-firestore-lite": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/firebase-firestore-lite/-/firebase-firestore-lite-1.0.3.tgz", - "integrity": "sha512-mc24fSlOJMUVpMmOETxRuFVjeMOO919r7uZlc3z+Hw5wjtCB9G5JXzg3PLGBxFB0KkT7jD7DjXIjpzxklEiC0Q==" - }, "node_modules/foreground-child": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", diff --git a/package.json b/package.json index cdde908..a3e4527 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "test": "vitest" }, "dependencies": { - "firebase-firestore-lite": "^1.0.3", "highlight.js": "^11.9.0", "lz-string": "^1.5.0", "monaco-editor": "^0.50.0-dev-20240525", diff --git a/src/bootstrap.ts b/src/bootstrap.ts index ca1c417..8d228af 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -3,7 +3,6 @@ import { EditorController } from "./controllers/editor-controller"; import { ElementController } from "./controllers/element-controller"; import { CssUtils } from "./lib/utility/css-utils"; import { StateManager } from "./lib/state/state-manager"; -import { FirestoreStateRepository } from "./lib/state/firestore-state-repository"; import { SelectController } from "./controllers/select-controller"; import { KyselyManager } from "./lib/kysely/kysely-manager"; import { State } from "./lib/state/state"; @@ -24,7 +23,6 @@ import { DEBUG, SETTING_KEYS } from "./lib/constants"; import { SettingsUtils } from "./lib/utility/settings-utils"; import { PanelContainerController } from "./controllers/panel-container-controller"; import { DomUtils } from "./lib/utility/dom-utils"; -import { GtagUtils } from "./lib/utility/gtag-utils"; import { AsyncUtils } from "./lib/utility/async-utils.js"; const lazy = null as unknown; @@ -73,7 +71,7 @@ async function init() { D.resultController = new ResultController(e`result`); setupResultController(); - D.stateManager = new StateManager(new FirestoreStateRepository()); + D.stateManager = new StateManager(); D.versionController = new SelectController(e`version`); D.dialectController = new SelectController(e`dialect`); D.switchThemeController = new ElementController(e`switch-theme`); @@ -122,7 +120,6 @@ async function setup() { setupMobileModeController(); setLoading(false); setupOpenInNewTabController(); - setupGtag(); } function setLoading(v: boolean) { @@ -193,8 +190,7 @@ async function setupMoreController() { const actionKey = DomUtils.isMac() ? "Cmd" : "Ctrl"; D.morePopupController.appendHint("To share a playground, press 'Save'"); - D.morePopupController.appendButton("Save", `${actionKey}-S`, save.bind(null, false)); - D.morePopupController.appendButton("Save and shorten link", `${actionKey}-Shift-S`, save.bind(null, true)); + D.morePopupController.appendButton("Save", `${actionKey}-S`, save.bind(null)); D.morePopupController.appendButton("Toggle type-editor", `F2`, toggleTypeEditor); D.morePopupController.appendText(" "); @@ -259,7 +255,6 @@ function setupResultController() { if (e.message && e.message.trim().startsWith("ResizeObserver")) { return; } - GtagUtils.event("exception", { description: e, fatal: true }); D.resultController.appendMessage( "error", `ERROR: There is an unexpected error. Checkout the developer console.`, @@ -270,7 +265,6 @@ function setupResultController() { D.resultController.clear(); D.resultController.appendMessage("info", "Loading..."); D.resultController.onClickCode = (v) => { - GtagUtils.event("click_result_code"); copyText(v, "Code copied"); }; } @@ -313,7 +307,6 @@ function setupSwitchThemeController() { function toggleTypeEditor() { const hidden = D.panel0.isHidden(); - GtagUtils.event("toggle_type_editor", { on: !hidden }); D.panel0.setHidden(!hidden); if (hidden) { D.panelContainerController.resetSizes(); @@ -424,19 +417,17 @@ function setupHotKeys() { if (DomUtils.hasSearchParam("nohotkey")) { return; } - HotkeyUtils.register(["ctrl"], "s", save.bind(null, false)); - HotkeyUtils.register(["ctrl", "shift"], "s", save.bind(null, true)); + HotkeyUtils.register(["ctrl"], "s", save.bind(null)); HotkeyUtils.register([], "f1", D.morePopupController.toggle.bind(D.morePopupController)); HotkeyUtils.register([], "f2", toggleTypeEditor); } -async function save(shorten: boolean) { - GtagUtils.event("save", { shorten }); +async function save() { await useLoading(async () => { if (SettingsUtils.get("save:format-before-save")) { await formatEditors(); } - await D.stateManager.save(makeState(), shorten); + await D.stateManager.save(makeState()); if (SettingsUtils.get("save:copy-url-after-save")) { await ClipboardUtils.writeText(window.location.toString()); ToastUtils.show("info", "URL copied"); @@ -445,7 +436,6 @@ async function save(shorten: boolean) { } async function formatEditors() { - GtagUtils.event("format"); await useLoading(async () => { try { const printWidth = SettingsUtils.get("ts-format:wider-width") ? 100 : 70; @@ -488,7 +478,6 @@ function makeState(): State { } async function reloadState(s: State) { - await D.stateManager.save(s, false); window.location.reload(); } @@ -516,11 +505,3 @@ async function copyText(v: string, msg: string) { ToastUtils.show("error", e.message ?? e.toString()); } } - -function setupGtag() { - const params = { dialect: D.state.dialect, version: D.state.kysely?.name } as any; - if (DEBUG) { - params.debug_mode = true; - } - GtagUtils.init(params); -} diff --git a/src/lib/constants.ts b/src/lib/constants.ts index bdd6102..3a9e386 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -17,9 +17,6 @@ export const GITHUB_MINIFIED_KYSELY_MAIN_BRANCH = "main"; export const GITHUB_API_MINIFIED_KYSELY_MAIN_REFS = `https://api.github.com/repos/${GITHUB_MINIFIED_KYSELY_OWNER}/${GITHUB_MINIFIED_KYSELY_REPO}/git/refs/heads/${GITHUB_MINIFIED_KYSELY_MAIN_BRANCH}`; -export const FIRESTORE_PROJECT_ID = "kysely-playground"; -export const FIRESTORE_COLLECTION_FRAGMENTS = "states"; - export const CSS_MIN_WIDE_WIDTH = 650; export const CSS_MIN_DESKTOP_WIDTH = 500; diff --git a/src/lib/state/firestore-state-repository.ts b/src/lib/state/firestore-state-repository.ts deleted file mode 100644 index a665a40..0000000 --- a/src/lib/state/firestore-state-repository.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { Database, Reference } from "firebase-firestore-lite"; -import { FIRESTORE_COLLECTION_FRAGMENTS, FIRESTORE_PROJECT_ID } from "../constants"; -import { logger } from "../utility/logger"; -import Transform from "firebase-firestore-lite/dist/Transform"; - -export class FirestoreStateRepository { - private readonly states: Reference; - constructor() { - const db = new Database({ projectId: FIRESTORE_PROJECT_ID }); - this.states = db.ref(FIRESTORE_COLLECTION_FRAGMENTS); - } - - async add(data: string): Promise { - let tryCount = 0; - while (tryCount < 16) { - try { - tryCount += 1; - const document = this.states.child(randomId(4 + tryCount)); - await document.set({ data, createdAt: new Transform("serverTimestamp") }, { exists: false }); - return document.id; - } catch (e: any) { - if (e.status === "ALREADY_EXISTS") { - logger.warn("firestore document confict", "try:", tryCount); - continue; - } - throw e; - } - } - throw new FirestoreError(`UNREACHABLE. ${tryCount}`); - } - - async get(id: string): Promise { - const document = await this.states.child(id).get(); - const data = document.data as string; - if (!data) { - throw new FirestoreError(`document has no data. id=${id}`); - } - return data; - } -} - -class FirestoreError extends Error {} - -// firestore document id - -const validChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" as const; - -function randomId(size: number) { - const b = crypto.getRandomValues(new Uint8Array(size)); - return Array.from(b) - .map((b) => validChars[b % validChars.length]) - .join(""); -} diff --git a/src/lib/state/state-manager.ts b/src/lib/state/state-manager.ts index 3a6dc51..2282962 100644 --- a/src/lib/state/state-manager.ts +++ b/src/lib/state/state-manager.ts @@ -3,23 +3,17 @@ import { logger } from "../utility/logger"; import { StringUtils } from "../utility/string-utils"; import { ValidateUtils } from "../utility/validate-utils"; import { State } from "./state"; -import { FirestoreStateRepository } from "./firestore-state-repository"; export class StateManager { - constructor(private readonly firestoreStateRepository: FirestoreStateRepository) {} + constructor() {} /** * Encode the state and update url. */ - async save(state: State, shorten: boolean) { + async save(state: State) { validate(state); logger.debug("encode state"); const encoded = await lzEncode(JSON.stringify(state)); - if (shorten) { - const id = await this.firestoreStateRepository.add(encoded); - window.history.replaceState(null, "", window.location.origin + "/" + id + window.location.search); - return; - } const header: FragmentHeader = "c"; window.history.replaceState(null, "", window.location.origin + window.location.search); window.location.hash = header + encoded; @@ -69,9 +63,10 @@ export class StateManager { } private async loadPath(path: string) { + logger.debug(`load path ${path}`); const id = path; - logger.debug(`get firestore state by id ${id}`); - return JSON.parse(await lzDecode(await this.firestoreStateRepository.get(id))); + logger.debug(`get state by id ${id}`); + return JSON.parse(await lzDecode(id)); } } diff --git a/src/lib/utility/gtag-utils.ts b/src/lib/utility/gtag-utils.ts deleted file mode 100644 index 77a6f9c..0000000 --- a/src/lib/utility/gtag-utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -export class GtagUtils { - static init(params: any) { - const w = window as any; - w.dataLayer = w.dataLayer || []; - w.gtag = function () { - w.dataLayer.push(arguments); - }; - w.gtag("js", new Date()); - w.gtag("config", "G-G1QNWZ9NSP", { ...params }); - } - - static event(name: string, params: any = {}) { - // @ts-ignore - window.gtag("event", name, params); - } -}