diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-26 20:18:30 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-26 20:18:30 -0700 |
| commit | 3c06c95f396b6e911076bc3291d5855ed01b5caa (patch) | |
| tree | 17cd218339c52fbeee93d931303b04a3ff294f8b /source/library/state/session.svelte.ts | |
| parent | f059d97ab7f6d74d61139ac698cb871be7cb632e (diff) | |
| download | graphiql-3c06c95f396b6e911076bc3291d5855ed01b5caa.tar.gz graphiql-3c06c95f396b6e911076bc3291d5855ed01b5caa.zip | |
cleanup and ready for launch
Diffstat (limited to 'source/library/state/session.svelte.ts')
| -rw-r--r-- | source/library/state/session.svelte.ts | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/source/library/state/session.svelte.ts b/source/library/state/session.svelte.ts index 76777e5..f84bb17 100644 --- a/source/library/state/session.svelte.ts +++ b/source/library/state/session.svelte.ts @@ -3,29 +3,26 @@ /*** UTILITY ------------------------------------------ ***/ -import type { Fetcher, FetcherResult } from "../fetcher/types.ts"; import { format } from "../graphql/format.ts"; + import { deriveTitle, parseOperations, type OperationInfo } from "../graphql/operations.ts"; + import { tabToExport, type ImportResult, type SessionExport, type TabExport } from "./session-io.ts"; + +import type { Fetcher, FetcherResult } from "../fetcher/types.ts"; import type { Storage } from "./storage.ts"; const STORAGE_KEY = "session"; -function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T> { - return typeof value === "object" && - value !== null && - typeof (value as AsyncIterable<T>)[Symbol.asyncIterator] === "function"; -} - type Snapshot = { activeId: string; tabs: Tab[]; @@ -72,7 +69,6 @@ export class SessionStore { activeId = $state<string>(""); tabs = $state<Tab[]>([]); active = $derived(this.tabs.find((t) => t.id === this.activeId)); - #storage: Storage; constructor(storage: Storage) { @@ -106,6 +102,7 @@ export class SessionStore { if (this.tabs.length === 1) { const fresh = this.#blank(); + this.tabs = [fresh]; this.activeId = fresh.id; @@ -154,8 +151,8 @@ export class SessionStore { } importTabs(data: SessionExport, opts: { mode: "append" | "replace" }): ImportResult { - const errors: string[] = []; const capped = data.tabs.slice(0, 50); + const errors: string[] = []; const skipped = data.tabs.length - capped.length; if (opts.mode === "replace") { @@ -181,7 +178,11 @@ export class SessionStore { if (capped.length > 0) this.activeId = this.tabs[this.tabs.length - 1].id; - return { added: capped.length, errors, skipped }; + return { + added: capped.length, + errors, + skipped + }; } nextTab() { @@ -249,8 +250,8 @@ export class SessionStore { tab.timing = { endMs: startMs, firstByteMs: startMs, startMs }; try { - const variables = tab.variables.trim() ? JSON.parse(tab.variables) : {}; const headers = tab.headers.trim() ? JSON.parse(tab.headers) : {}; + const variables = tab.variables.trim() ? JSON.parse(tab.variables) : {}; const result = await fetcher({ headers, @@ -312,13 +313,16 @@ export class SessionStore { } const firstByteMs = performance.now(); + tab.timing = { ...tab.timing, firstByteMs }; tab.result = JSON.stringify(result, null, 2); tab.timing = { ...tab.timing, endMs: performance.now() }; + return true; } catch(err) { tab.result = JSON.stringify({ error: String(err) }, null, 2); tab.timing = { ...tab.timing, endMs: performance.now() }; + return false; } } @@ -431,3 +435,11 @@ export class SessionStore { }; } } + +/*** HELPER ------------------------------------------- ***/ + +function isAsyncIterable<T>(value: unknown): value is AsyncIterable<T> { + return typeof value === "object" && + value !== null && + typeof (value as AsyncIterable<T>)[Symbol.asyncIterator] === "function"; +} |