From 3c06c95f396b6e911076bc3291d5855ed01b5caa Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Sun, 26 Apr 2026 20:18:30 -0700 Subject: cleanup and ready for launch --- source/library/state/session-io.ts | 116 +++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 57 deletions(-) (limited to 'source/library/state/session-io.ts') diff --git a/source/library/state/session-io.ts b/source/library/state/session-io.ts index a5e2ea9..f2491ba 100644 --- a/source/library/state/session-io.ts +++ b/source/library/state/session-io.ts @@ -9,59 +9,14 @@ import type { Tab } from "./session.svelte.ts"; const MAX_STRING_BYTES = 1024 * 1024; const MAX_TABS = 50; -function isObject(value: unknown): value is Record { - return typeof value === "object" && value !== null && !Array.isArray(value); -} - -function stringTooLong(value: string): boolean { - return value.length > MAX_STRING_BYTES; -} - -function validateTab(raw: unknown, index: number): TabExport | string { - if (!isObject(raw)) - return `tabs[${index}]: not an object`; - - if (typeof raw.headers !== "string") - return `tabs[${index}].headers: not a string`; - - if (typeof raw.query !== "string") - return `tabs[${index}].query: not a string`; - - if (typeof raw.title !== "string") - return `tabs[${index}].title: not a string`; - - if (typeof raw.variables !== "string") - return `tabs[${index}].variables: not a string`; - - if (raw.operationName !== null && typeof raw.operationName !== "string") - return `tabs[${index}].operationName: not a string or null`; - - if (stringTooLong(raw.headers)) - return `tabs[${index}].headers: exceeds 1 MB`; - - if (stringTooLong(raw.query)) - return `tabs[${index}].query: exceeds 1 MB`; - - if (stringTooLong(raw.title)) - return `tabs[${index}].title: exceeds 1 MB`; - - if (stringTooLong(raw.variables)) - return `tabs[${index}].variables: exceeds 1 MB`; - - if (typeof raw.operationName === "string" && stringTooLong(raw.operationName)) - return `tabs[${index}].operationName: exceeds 1 MB`; - - return { - headers: raw.headers, - operationName: raw.operationName, - query: raw.query, - title: raw.title, - variables: raw.variables - }; -} - /*** EXPORT ------------------------------------------- ***/ +export type ImportResult = { + added: number; + errors: string[]; + skipped: number; +}; + export type TabExport = { headers: string; operationName: string | null; @@ -76,12 +31,6 @@ export type SessionExport = { version: 1; }; -export type ImportResult = { - added: number; - errors: string[]; - skipped: number; -}; - export function tabToExport(tab: Tab): TabExport { return { headers: tab.headers, @@ -125,3 +74,56 @@ export function validateSessionExport(data: unknown): SessionExport | { error: s version: 1 }; } + +/*** HELPER ------------------------------------------- ***/ + +function isObject(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} + +function stringTooLong(value: string): boolean { + return value.length > MAX_STRING_BYTES; +} + +function validateTab(raw: unknown, index: number): TabExport | string { + if (!isObject(raw)) + return `tabs[${index}]: not an object`; + + if (typeof raw.headers !== "string") + return `tabs[${index}].headers: not a string`; + + if (typeof raw.query !== "string") + return `tabs[${index}].query: not a string`; + + if (typeof raw.title !== "string") + return `tabs[${index}].title: not a string`; + + if (typeof raw.variables !== "string") + return `tabs[${index}].variables: not a string`; + + if (raw.operationName !== null && typeof raw.operationName !== "string") + return `tabs[${index}].operationName: not a string or null`; + + if (stringTooLong(raw.headers)) + return `tabs[${index}].headers: exceeds 1 MB`; + + if (stringTooLong(raw.query)) + return `tabs[${index}].query: exceeds 1 MB`; + + if (stringTooLong(raw.title)) + return `tabs[${index}].title: exceeds 1 MB`; + + if (stringTooLong(raw.variables)) + return `tabs[${index}].variables: exceeds 1 MB`; + + if (typeof raw.operationName === "string" && stringTooLong(raw.operationName)) + return `tabs[${index}].operationName: exceeds 1 MB`; + + return { + headers: raw.headers, + operationName: raw.operationName, + query: raw.query, + title: raw.title, + variables: raw.variables + }; +} -- cgit v1.2.3