Switch to BiomeJS (#306)

This commit is contained in:
Gregory Schier
2025-11-23 08:38:13 -08:00
committed by GitHub
parent 2bac610efe
commit ec3e2e16a9
332 changed files with 3007 additions and 4097 deletions

View File

@@ -16,28 +16,30 @@ export function convertId(id: string): string {
export function deleteUndefinedAttrs<T>(obj: T): T {
if (Array.isArray(obj) && obj != null) {
return obj.map(deleteUndefinedAttrs) as T;
} else if (typeof obj === 'object' && obj != null) {
}
if (typeof obj === 'object' && obj != null) {
return Object.fromEntries(
Object.entries(obj)
.filter(([, v]) => v !== undefined)
.map(([k, v]) => [k, deleteUndefinedAttrs(v)]),
) as T;
} else {
return obj;
}
return obj;
}
/** Recursively render all nested object properties */
export function convertTemplateSyntax<T>(obj: T): T {
if (typeof obj === 'string') {
// biome-ignore lint/suspicious/noTemplateCurlyInString: Yaak template syntax
return obj.replaceAll(/{{\s*(_\.)?([^}]+)\s*}}/g, '${[$2]}') as T;
} else if (Array.isArray(obj) && obj != null) {
}
if (Array.isArray(obj) && obj != null) {
return obj.map(convertTemplateSyntax) as T;
} else if (typeof obj === 'object' && obj != null) {
}
if (typeof obj === 'object' && obj != null) {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => [k, convertTemplateSyntax(v)]),
) as T;
} else {
return obj;
}
return obj;
}

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { PartialImportResources } from '@yaakapp/api';
import { convertId, convertTemplateSyntax, isJSObject } from './common';
// biome-ignore lint/suspicious/noExplicitAny: none
export function convertInsomniaV4(parsed: any) {
if (!Array.isArray(parsed.resources)) return null;
@@ -16,6 +16,7 @@ export function convertInsomniaV4(parsed: any) {
// Import workspaces
const workspacesToImport = parsed.resources.filter(
// biome-ignore lint/suspicious/noExplicitAny: none
(r: any) => isJSObject(r) && r._type === 'workspace',
);
for (const w of workspacesToImport) {
@@ -28,13 +29,16 @@ export function convertInsomniaV4(parsed: any) {
description: w.description || undefined,
});
const environmentsToImport = parsed.resources.filter(
// biome-ignore lint/suspicious/noExplicitAny: none
(r: any) => isJSObject(r) && r._type === 'environment',
);
resources.environments.push(
// biome-ignore lint/suspicious/noExplicitAny: none
...environmentsToImport.map((r: any) => importEnvironment(r, w._id)),
);
const nextFolder = (parentId: string) => {
// biome-ignore lint/suspicious/noExplicitAny: none
const children = parsed.resources.filter((r: any) => r.parentId === parentId);
for (const child of children) {
if (!isJSObject(child)) continue;
@@ -63,6 +67,7 @@ export function convertInsomniaV4(parsed: any) {
return { resources: convertTemplateSyntax(resources) };
}
// biome-ignore lint/suspicious/noExplicitAny: none
function importHttpRequest(r: any, workspaceId: string): PartialImportResources['httpRequests'][0] {
let bodyType: string | null = null;
let body = {};
@@ -72,6 +77,7 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
} else if (r.body?.mimeType === 'application/x-www-form-urlencoded') {
bodyType = 'application/x-www-form-urlencoded';
body = {
// biome-ignore lint/suspicious/noExplicitAny: none
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -81,6 +87,7 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
} else if (r.body?.mimeType === 'multipart/form-data') {
bodyType = 'multipart/form-data';
body = {
// biome-ignore lint/suspicious/noExplicitAny: none
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -122,6 +129,7 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
name: r.name,
description: r.description || undefined,
url: r.url,
// biome-ignore lint/suspicious/noExplicitAny: none
urlParameters: (r.parameters ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -133,16 +141,20 @@ function importHttpRequest(r: any, workspaceId: string): PartialImportResources[
authenticationType,
method: r.method,
headers: (r.headers ?? [])
// biome-ignore lint/suspicious/noExplicitAny: none
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? '',
value: h.value ?? '',
}))
// biome-ignore lint/suspicious/noExplicitAny: none
.filter(({ name, value }: any) => name !== '' || value !== ''),
};
}
// biome-ignore lint/suspicious/noExplicitAny: none
function importGrpcRequest(r: any, workspaceId: string): PartialImportResources['grpcRequests'][0] {
// biome-ignore lint/suspicious/noExplicitAny: none
const parts = r.protoMethodName.split('/').filter((p: any) => p !== '');
const service = parts[0] ?? null;
const method = parts[1] ?? null;
@@ -162,15 +174,18 @@ function importGrpcRequest(r: any, workspaceId: string): PartialImportResources[
method,
message: r.body?.text ?? '',
metadata: (r.metadata ?? [])
// biome-ignore lint/suspicious/noExplicitAny: none
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? '',
value: h.value ?? '',
}))
// biome-ignore lint/suspicious/noExplicitAny: none
.filter(({ name, value }: any) => name !== '' || value !== ''),
};
}
// biome-ignore lint/suspicious/noExplicitAny: none
function importFolder(f: any, workspaceId: string): PartialImportResources['folders'][0] {
return {
id: convertId(f._id),
@@ -185,11 +200,12 @@ function importFolder(f: any, workspaceId: string): PartialImportResources['fold
}
function importEnvironment(
// biome-ignore lint/suspicious/noExplicitAny: none
e: any,
workspaceId: string,
isParent?: boolean,
isParentOg?: boolean,
): PartialImportResources['environments'][0] {
isParent ??= e.parentId === workspaceId;
const isParent = isParentOg ?? e.parentId === workspaceId;
return {
id: convertId(e._id),
createdAt: e.created ? new Date(e.created).toISOString().replace('Z', '') : undefined,

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { PartialImportResources } from '@yaakapp/api';
import { convertId, convertTemplateSyntax, isJSObject } from './common';
// biome-ignore lint/suspicious/noExplicitAny: none
export function convertInsomniaV5(parsed: any) {
// Assert parsed is object
if (parsed == null || typeof parsed !== 'object') {
@@ -22,6 +22,7 @@ export function convertInsomniaV5(parsed: any) {
};
// Import workspaces
// biome-ignore lint/suspicious/noExplicitAny: none
const meta = ('meta' in parsed ? parsed.meta : {}) as Record<string, any>;
resources.workspaces.push({
id: convertId(meta.id ?? 'collection'),
@@ -37,10 +38,12 @@ export function convertInsomniaV5(parsed: any) {
// Import environments
resources.environments.push(
importEnvironment(parsed.environments, meta.id, true),
// biome-ignore lint/suspicious/noExplicitAny: none
...(parsed.environments.subEnvironments ?? []).map((r: any) => importEnvironment(r, meta.id)),
);
// Import folders
// biome-ignore lint/suspicious/noExplicitAny: none
const nextFolder = (children: any[], parentId: string) => {
for (const child of children ?? []) {
if (!isJSObject(child)) continue;
@@ -73,6 +76,7 @@ export function convertInsomniaV5(parsed: any) {
}
function importHttpRequest(
// biome-ignore lint/suspicious/noExplicitAny: none
r: any,
workspaceId: string,
parentId: string,
@@ -90,6 +94,7 @@ function importHttpRequest(
} else if (r.body?.mimeType === 'application/x-www-form-urlencoded') {
bodyType = 'application/x-www-form-urlencoded';
body = {
// biome-ignore lint/suspicious/noExplicitAny: none
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -99,6 +104,7 @@ function importHttpRequest(
} else if (r.body?.mimeType === 'multipart/form-data') {
bodyType = 'multipart/form-data';
body = {
// biome-ignore lint/suspicious/noExplicitAny: none
form: (r.body.params ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -125,6 +131,7 @@ function importHttpRequest(
name: r.name,
description: r.meta?.description || undefined,
url: r.url,
// biome-ignore lint/suspicious/noExplicitAny: none
urlParameters: (r.parameters ?? []).map((p: any) => ({
enabled: !p.disabled,
name: p.name ?? '',
@@ -139,6 +146,7 @@ function importHttpRequest(
}
function importGrpcRequest(
// biome-ignore lint/suspicious/noExplicitAny: none
r: any,
workspaceId: string,
parentId: string,
@@ -148,6 +156,7 @@ function importGrpcRequest(
const updated = r.meta?.modified ?? r.updated;
const sortKey = r.meta?.sortKey ?? r.sortKey;
// biome-ignore lint/suspicious/noExplicitAny: none
const parts = r.protoMethodName.split('/').filter((p: any) => p !== '');
const service = parts[0] ?? null;
const method = parts[1] ?? null;
@@ -167,16 +176,19 @@ function importGrpcRequest(
method,
message: r.body?.text ?? '',
metadata: (r.metadata ?? [])
// biome-ignore lint/suspicious/noExplicitAny: none
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? '',
value: h.value ?? '',
}))
// biome-ignore lint/suspicious/noExplicitAny: none
.filter(({ name, value }: any) => name !== '' || value !== ''),
};
}
function importWebsocketRequest(
// biome-ignore lint/suspicious/noExplicitAny: none
r: any,
workspaceId: string,
parentId: string,
@@ -203,17 +215,21 @@ function importWebsocketRequest(
};
}
// biome-ignore lint/suspicious/noExplicitAny: none
function importHeaders(obj: any) {
const headers = (obj.headers ?? [])
// biome-ignore lint/suspicious/noExplicitAny: none
.map((h: any) => ({
enabled: !h.disabled,
name: h.name ?? '',
value: h.value ?? '',
}))
// biome-ignore lint/suspicious/noExplicitAny: none
.filter(({ name, value }: any) => name !== '' || value !== '');
return { headers } as const;
}
// biome-ignore lint/suspicious/noExplicitAny: none
function importAuthentication(obj: any) {
let authenticationType: string | null = null;
let authentication = {};
@@ -234,6 +250,7 @@ function importAuthentication(obj: any) {
}
function importFolder(
// biome-ignore lint/suspicious/noExplicitAny: none
f: any,
workspaceId: string,
parentId: string,
@@ -249,7 +266,7 @@ function importFolder(
let environment: PartialImportResources['environments'][0] | null = null;
if (Object.keys(f.environment ?? {}).length > 0) {
environment = {
id: convertId(id + 'folder'),
id: convertId(`${id}folder`),
createdAt: created ? new Date(created).toISOString().replace('Z', '') : undefined,
updatedAt: updated ? new Date(updated).toISOString().replace('Z', '') : undefined,
workspaceId: convertId(workspaceId),
@@ -285,6 +302,7 @@ function importFolder(
}
function importEnvironment(
// biome-ignore lint/suspicious/noExplicitAny: none
e: any,
workspaceId: string,
isParent?: boolean,