[WIP] Refactor to NPM workspaces (#104)

This commit is contained in:
Gregory Schier
2024-09-22 21:27:10 -07:00
committed by GitHub
parent 93633875ac
commit 101b6284d6
176 changed files with 1983 additions and 1249 deletions

View File

@@ -1,6 +1,6 @@
import { useUpdateAnyGrpcRequest } from '../hooks/useUpdateAnyGrpcRequest';
import { useUpdateAnyHttpRequest } from '../hooks/useUpdateAnyHttpRequest';
import type { GrpcRequest, HttpRequest } from '@yaakapp/api';
import type { GrpcRequest, HttpRequest } from '@yaakapp-internal/models';
import { Input } from './core/Input';
import { VStack } from './core/Stacks';

View File

@@ -1,6 +1,6 @@
import { useUpdateAnyGrpcRequest } from '../hooks/useUpdateAnyGrpcRequest';
import { useUpdateAnyHttpRequest } from '../hooks/useUpdateAnyHttpRequest';
import type { GrpcRequest, HttpRequest } from '@yaakapp/api';
import type { GrpcRequest, HttpRequest } from '@yaakapp-internal/models';
import { Input } from './core/Input';
import { VStack } from './core/Stacks';

View File

@@ -1,6 +1,6 @@
import mime from 'mime';
import { useKeyValue } from '../hooks/useKeyValue';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import { Banner } from './core/Banner';
import { Button } from './core/Button';
import { InlineCode } from './core/InlineCode';

View File

@@ -1,4 +1,4 @@
import type { Cookie } from '@yaakapp/api';
import type { Cookie } from '@yaakapp-internal/models';
import { useCookieJars } from '../hooks/useCookieJars';
import { useUpdateCookieJar } from '../hooks/useUpdateCookieJar';
import { cookieDomain } from '../lib/model_util';

View File

@@ -9,7 +9,7 @@ import { useKeyValue } from '../hooks/useKeyValue';
import { usePrompt } from '../hooks/usePrompt';
import { useUpdateEnvironment } from '../hooks/useUpdateEnvironment';
import { useUpdateWorkspace } from '../hooks/useUpdateWorkspace';
import type { Environment, Workspace } from '@yaakapp/api';
import type { Environment, Workspace } from '@yaakapp-internal/models';
import { Button } from './core/Button';
import { ContextMenu } from './core/Dropdown';
import type {

View File

@@ -1,7 +1,7 @@
import { save } from '@tauri-apps/plugin-dialog';
import { useCallback, useMemo, useState } from 'react';
import slugify from 'slugify';
import type { Workspace } from '@yaakapp/api';
import type { Workspace } from '@yaakapp-internal/models';
import { count } from '../lib/pluralize';
import { invokeCmd } from '../lib/tauri';
import { Button } from './core/Button';

View File

@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import type { Pair, PairEditorProps } from './core/PairEditor';
import { PairEditor } from './core/PairEditor';

View File

@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import type { Pair, PairEditorProps } from './core/PairEditor';
import { PairOrBulkEditor } from './core/PairOrBulkEditor';

View File

@@ -1,6 +1,6 @@
import { useQueryClient } from '@tanstack/react-query';
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
import type { Model } from '@yaakapp/api';
import type { AnyModel } from '@yaakapp-internal/models';
import { useSetAtom } from 'jotai';
import { useEffect } from 'react';
import { useEnsureActiveCookieJar, useMigrateActiveCookieJarId } from '../hooks/useActiveCookieJar';
@@ -62,7 +62,7 @@ export function GlobalHooks() {
const { wasUpdatedExternally } = useRequestUpdateKey(null);
interface ModelPayload {
model: Model;
model: AnyModel;
windowLabel: string;
}
@@ -94,7 +94,7 @@ export function GlobalHooks() {
wasUpdatedExternally(model.id);
}
const pushToFront = (['http_response', 'grpc_connection'] as Model['model'][]).includes(
const pushToFront = (['http_response', 'grpc_connection'] as AnyModel['model'][]).includes(
model.model,
);
@@ -197,7 +197,7 @@ export function GlobalHooks() {
return null;
}
function updateModelList<T extends Model>(model: T, pushToFront: boolean) {
function updateModelList<T extends AnyModel>(model: T, pushToFront: boolean) {
return (current: T[]): T[] => {
const index = current.findIndex((v) => modelsEq(v, model)) ?? -1;
if (index >= 0) {
@@ -212,7 +212,7 @@ function removeById<T extends { id: string }>(model: T) {
return (entries: T[] | undefined) => entries?.filter((e) => e.id !== model.id) ?? [];
}
const shouldIgnoreModel = (payload: Model, windowLabel: string) => {
const shouldIgnoreModel = (payload: AnyModel, windowLabel: string) => {
if (windowLabel === getCurrentWebviewWindow().label) {
// Never ignore same-window updates
return false;

View File

@@ -2,7 +2,7 @@ import type { EditorView } from 'codemirror';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useIntrospectGraphQL } from '../hooks/useIntrospectGraphQL';
import { tryFormatJson } from '../lib/formatters';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import { Button } from './core/Button';
import type { EditorProps } from './core/Editor';
import { Editor, formatGraphQL } from './core/Editor';

View File

@@ -5,7 +5,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { useGrpcEvents } from '../hooks/useGrpcEvents';
import { usePinnedGrpcConnection } from '../hooks/usePinnedGrpcConnection';
import { useStateWithDeps } from '../hooks/useStateWithDeps';
import type { GrpcEvent, GrpcRequest } from '@yaakapp/api';
import type { GrpcEvent, GrpcRequest } from '@yaakapp-internal/models';
import { isResponseLoading } from '../lib/model_util';
import { Banner } from './core/Banner';
import { Button } from './core/Button';

View File

@@ -6,7 +6,7 @@ import { createGlobalState } from 'react-use';
import type { ReflectResponseService } from '../hooks/useGrpc';
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
import { useUpdateAnyGrpcRequest } from '../hooks/useUpdateAnyGrpcRequest';
import type { GrpcMetadataEntry, GrpcRequest } from '@yaakapp/api';
import type { GrpcMetadataEntry, GrpcRequest } from '@yaakapp-internal/models';
import { AUTH_TYPE_BASIC, AUTH_TYPE_BEARER, AUTH_TYPE_NONE } from '../lib/model_util';
import { BasicAuth } from './BasicAuth';
import { BearerAuth } from './BearerAuth';

View File

@@ -15,7 +15,7 @@ import { useEffect, useMemo, useRef } from 'react';
import { useAlert } from '../hooks/useAlert';
import type { ReflectResponseService } from '../hooks/useGrpc';
import { tryFormatJson } from '../lib/formatters';
import type { GrpcRequest } from '@yaakapp/api';
import type { GrpcRequest } from '@yaakapp-internal/models';
import { count } from '../lib/pluralize';
import { Button } from './core/Button';
import type { EditorProps } from './core/Editor';

View File

@@ -3,7 +3,7 @@ import { connections } from '../lib/data/connections';
import { encodings } from '../lib/data/encodings';
import { headerNames } from '../lib/data/headerNames';
import { mimeTypes } from '../lib/data/mimetypes';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import type { GenericCompletionConfig } from './core/Editor/genericCompletion';
import type { PairEditorProps } from './core/PairEditor';
import { PairOrBulkEditor } from './core/PairOrBulkEditor';

View File

@@ -1,6 +1,6 @@
import type { CSSProperties } from 'react';
import React from 'react';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import { SplitLayout } from './core/SplitLayout';
import { RequestPane } from './RequestPane';
import { ResponsePane } from './ResponsePane';

View File

@@ -1,4 +1,4 @@
import type { GrpcRequest, HttpRequest } from '@yaakapp/api';
import type { GrpcRequest, HttpRequest } from '@yaakapp-internal/models';
import React, { useState } from 'react';
import { useAppRoutes } from '../hooks/useAppRoutes';
import { useUpdateAnyGrpcRequest } from '../hooks/useUpdateAnyGrpcRequest';

View File

@@ -2,7 +2,7 @@ import { useState } from 'react';
import { useOpenWorkspace } from '../hooks/useOpenWorkspace';
import { useSettings } from '../hooks/useSettings';
import { useUpdateSettings } from '../hooks/useUpdateSettings';
import type { Workspace } from '@yaakapp/api';
import type { Workspace } from '@yaakapp-internal/models';
import { Button } from './core/Button';
import { Checkbox } from './core/Checkbox';
import { Icon } from './core/Icon';

View File

@@ -1,7 +1,7 @@
import { formatDistanceToNowStrict } from 'date-fns';
import { useDeleteGrpcConnection } from '../hooks/useDeleteGrpcConnection';
import { useDeleteGrpcConnections } from '../hooks/useDeleteGrpcConnections';
import type { GrpcConnection } from '@yaakapp/api';
import type { GrpcConnection } from '@yaakapp-internal/models';
import { count } from '../lib/pluralize';
import { Dropdown } from './core/Dropdown';
import { Icon } from './core/Icon';

View File

@@ -1,4 +1,4 @@
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { useCopyHttpResponse } from '../hooks/useCopyHttpResponse';
import { useDeleteHttpResponse } from '../hooks/useDeleteHttpResponse';
import { useDeleteHttpResponses } from '../hooks/useDeleteHttpResponses';

View File

@@ -1,4 +1,4 @@
import type { HttpRequest, HttpRequestHeader, HttpUrlParameter } from '@yaakapp/api';
import type { HttpRequest, HttpRequestHeader, HttpUrlParameter } from '@yaakapp-internal/models';
import classNames from 'classnames';
import type { CSSProperties } from 'react';
import React, { memo, useCallback, useMemo, useState } from 'react';

View File

@@ -1,4 +1,4 @@
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { KeyValueRow, KeyValueRows } from './core/KeyValueRow';
interface Props {

View File

@@ -1,5 +1,5 @@
import { open } from '@tauri-apps/plugin-shell';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { IconButton } from './core/IconButton';
import { KeyValueRow, KeyValueRows } from './core/KeyValueRow';

View File

@@ -1,4 +1,4 @@
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import classNames from 'classnames';
import type { CSSProperties } from 'react';
import { memo, useCallback, useMemo } from 'react';

View File

@@ -1,4 +1,4 @@
import type { Plugin } from '@yaakapp/api';
import type { Plugin } from '@yaakapp-internal/models';
import { open } from '@tauri-apps/plugin-shell';
import React from 'react';
import { useInstallPlugin } from '../../hooks/useInstallPlugin';

View File

@@ -1,4 +1,10 @@
import type { Folder, GrpcRequest, HttpRequest, Model, Workspace } from '@yaakapp/api';
import type {
AnyModel,
Folder,
GrpcRequest,
HttpRequest,
Workspace,
} from '@yaakapp-internal/models';
import classNames from 'classnames';
import type { ReactNode } from 'react';
import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
@@ -575,7 +581,7 @@ type SidebarItemProps = {
itemId: string;
itemName: string;
itemFallbackName: string;
itemModel: Model['model'];
itemModel: AnyModel['model'];
itemPrefix: ReactNode;
useProminentStyles?: boolean;
selected: boolean;

View File

@@ -5,10 +5,9 @@ import type {
TemplateFunctionHttpRequestArg,
TemplateFunctionSelectArg,
TemplateFunctionTextArg,
} from '@yaakapp/api';
} from '@yaakapp-internal/plugin';
import type { FnArg, Tokens } from '@yaakapp-internal/template';
import { useCallback, useMemo, useState } from 'react';
import type { FnArg } from '../gen/FnArg';
import type { Tokens } from '../gen/Tokens';
import { useActiveRequest } from '../hooks/useActiveRequest';
import { useDebouncedValue } from '../hooks/useDebouncedValue';
import { useHttpRequests } from '../hooks/useHttpRequests';
@@ -62,8 +61,8 @@ export function TemplateFunctionDialog({ templateFunction, hide, initialTokens,
argValues[name] === NULL_ARG
? { type: 'null' }
: typeof argValues[name] === 'boolean'
? { type: 'bool', value: argValues[name] === true }
: { type: 'str', text: String(argValues[name] ?? '') },
? { type: 'bool', value: argValues[name] === true }
: { type: 'str', text: String(argValues[name] ?? '') },
}));
return {

View File

@@ -1,5 +1,5 @@
import type { Tokens } from '@yaakapp-internal/template';
import { useCallback, useMemo, useState } from 'react';
import type { Tokens } from '../gen/Tokens';
import { useActiveEnvironmentVariables } from '../hooks/useActiveEnvironmentVariables';
import { useRenderTemplate } from '../hooks/useRenderTemplate';
import { useTemplateTokensToString } from '../hooks/useTemplateTokensToString';

View File

@@ -1,7 +1,7 @@
import type { ShowToastRequest } from '@yaakapp-internal/plugin';
import { AnimatePresence } from 'framer-motion';
import type { ReactNode } from 'react';
import React, { createContext, useContext, useMemo, useRef, useState } from 'react';
import type { ShowToastRequest } from '@yaakapp/api';
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
import { generateId } from '../lib/generateId';
import type { ToastProps } from './core/Toast';

View File

@@ -3,7 +3,7 @@ import type { EditorView } from 'codemirror';
import type { FormEvent, ReactNode } from 'react';
import { memo, useRef, useState } from 'react';
import { useHotKey } from '../hooks/useHotKey';
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import type { IconProps } from './core/Icon';
import { IconButton } from './core/IconButton';
import type { InputProps } from './core/Input';

View File

@@ -1,4 +1,4 @@
import type { HttpRequest } from '@yaakapp/api';
import type { HttpRequest } from '@yaakapp-internal/models';
import { useRequestEditor, useRequestEditorEvent } from '../hooks/useRequestEditor';
import type { PairEditorRef } from './core/PairEditor';
import { PairOrBulkEditor } from './core/PairOrBulkEditor';

View File

@@ -2,7 +2,8 @@ import { defaultKeymap } from '@codemirror/commands';
import { forceParsing } from '@codemirror/language';
import { Compartment, EditorState, type Extension } from '@codemirror/state';
import { keymap, placeholder as placeholderExt, tooltips } from '@codemirror/view';
import type { EnvironmentVariable, TemplateFunction } from '@yaakapp/api';
import type { EnvironmentVariable } from '@yaakapp-internal/models';
import type { TemplateFunction } from '@yaakapp-internal/plugin';
import classNames from 'classnames';
import { EditorView } from 'codemirror';
import type { MutableRefObject, ReactNode } from 'react';

View File

@@ -31,7 +31,8 @@ import {
rectangularSelection,
} from '@codemirror/view';
import { tags as t } from '@lezer/highlight';
import type { EnvironmentVariable, TemplateFunction } from '@yaakapp/api';
import type { EnvironmentVariable } from '@yaakapp-internal/models';
import type { TemplateFunction } from '@yaakapp-internal/plugin';
import { graphql } from 'cm6-graphql';
import { EditorView } from 'codemirror';
import type { EditorProps } from './index';

View File

@@ -1,7 +1,8 @@
import type { LanguageSupport } from '@codemirror/language';
import { LRLanguage } from '@codemirror/language';
import { parseMixed } from '@lezer/common';
import type { EnvironmentVariable, TemplateFunction } from '@yaakapp/api';
import type { EnvironmentVariable } from '@yaakapp-internal/models';
import type { TemplateFunction } from '@yaakapp-internal/plugin';
import type { GenericCompletionConfig } from '../genericCompletion';
import { genericCompletion } from '../genericCompletion';
import { textLanguageName } from '../text/extension';

View File

@@ -1,5 +1,5 @@
import classNames from 'classnames';
import type { GrpcRequest, HttpRequest } from '@yaakapp/api';
import type { GrpcRequest, HttpRequest } from '@yaakapp-internal/models';
interface Props {
request: HttpRequest | GrpcRequest;
@@ -34,8 +34,8 @@ export function HttpMethodTag({ shortNames, request, className }: Props) {
request.model === 'http_request' && request.bodyType === 'graphql'
? 'GQL'
: request.model === 'grpc_request'
? 'GRPC'
: request.method;
? 'GRPC'
: request.method;
const m = method.toLowerCase();
const methodMap: Record<string, string> = shortNames ? shortMethodMap : longMethodMap;

View File

@@ -1,5 +1,5 @@
import classNames from 'classnames';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: Pick<HttpResponse, 'status' | 'statusReason' | 'error'>;

View File

@@ -1,4 +1,4 @@
import type { ShowToastRequest } from '@yaakapp/api';
import type { ShowToastRequest } from '@yaakapp-internal/plugin';
import classNames from 'classnames';
import { motion } from 'framer-motion';
import type { ReactNode } from 'react';

View File

@@ -1,6 +1,6 @@
import { convertFileSrc } from '@tauri-apps/api/core';
import React from 'react';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: HttpResponse;

View File

@@ -1,5 +1,5 @@
import { useSaveResponse } from '../../hooks/useSaveResponse';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { getContentTypeHeader } from '../../lib/model_util';
import { Banner } from '../core/Banner';
import { Button } from '../core/Button';

View File

@@ -2,7 +2,7 @@ import classNames from 'classnames';
import Papa from 'papaparse';
import { useMemo } from 'react';
import { useResponseBodyText } from '../../hooks/useResponseBodyText';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: HttpResponse;

View File

@@ -1,4 +1,4 @@
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { useContentTypeFromHeaders } from '../../hooks/useContentTypeFromHeaders';
import { useResponseBodyText } from '../../hooks/useResponseBodyText';
import { isJSON, languageFromContentType } from '../../lib/contentType';

View File

@@ -1,7 +1,7 @@
import { convertFileSrc } from '@tauri-apps/api/core';
import classNames from 'classnames';
import { useState } from 'react';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: HttpResponse;

View File

@@ -1,6 +1,6 @@
import classNames from 'classnames';
import { useResponseBodyText } from '../../hooks/useResponseBodyText';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import { JsonAttributeTree } from '../core/JsonAttributeTree';
interface Props {

View File

@@ -6,7 +6,7 @@ import type { PDFDocumentProxy } from 'pdfjs-dist';
import React, { useRef, useState } from 'react';
import { Document, Page } from 'react-pdf';
import { useDebouncedState } from '../../hooks/useDebouncedState';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import './PdfViewer.css';
interface Props {

View File

@@ -1,4 +1,4 @@
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
import classNames from 'classnames';
import type { ReactNode } from 'react';
import { useCallback, useMemo } from 'react';
@@ -161,8 +161,8 @@ export function TextViewer({ response, pretty, className }: Props) {
pretty && language === 'json'
? tryFormatJson(rawBody.data)
: pretty && (language === 'xml' || language === 'html')
? tryFormatXml(rawBody.data)
: rawBody.data;
? tryFormatXml(rawBody.data)
: rawBody.data;
let body;
if (isSearching && filterText?.length > 0) {

View File

@@ -1,6 +1,6 @@
import { convertFileSrc } from '@tauri-apps/api/core';
import React from 'react';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: HttpResponse;

View File

@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { useResponseBodyText } from '../../hooks/useResponseBodyText';
import type { HttpResponse } from '@yaakapp/api';
import type { HttpResponse } from '@yaakapp-internal/models';
interface Props {
response: HttpResponse;