Add pocketbase types

This commit is contained in:
2025-06-15 18:09:13 +02:00
parent ec663fba55
commit 6ba59430db
8 changed files with 218 additions and 46 deletions

View File

@@ -1,8 +1,7 @@
import { Card, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Zap, Shield, Coins, HelpCircle } from "lucide-react";
import { Signature } from "@/lib/types";
import { SigviewRecord as Signature } from "@/lib/pbtypes";
interface SignatureCardProps {
signature: Signature;

View File

@@ -1,6 +1,6 @@
import { Badge } from "@/components/ui/badge";
import { Zap, Shield, Coins, HelpCircle, Clock, AlertTriangle, Skull } from "lucide-react";
import { Signature } from "@/lib/types";
import { SigviewRecord as Signature } from "@/lib/pbtypes";
interface SignatureListItemProps {
signature: Signature;
@@ -86,7 +86,7 @@ export const SignatureListItem = ({ signature }: SignatureListItemProps) => {
{/* Signature Name and ID */}
<div className="flex-1 min-w-[200px]">
<div className="flex items-center gap-2">
<span className="font-mono text-sm text-slate-400 min-w-[60px]">{signature.id}</span>
<span className="font-mono text-sm text-slate-400 min-w-[60px]">{signature.identifier}</span>
<h3 className="text-white font-medium flex items-center gap-2">
{signature.signame || "Unnamed Signature"}
{signature.dangerous && (
@@ -96,7 +96,6 @@ export const SignatureListItem = ({ signature }: SignatureListItemProps) => {
)}
</h3>
</div>
<div className="text-xs text-slate-400 font-mono ml-[60px]">{signature.identifier}</div>
</div>
{/* Dates */}

View File

@@ -7,11 +7,7 @@ import { Button } from "@/components/ui/button";
import { RefreshCw, AlertCircle, Radar } from "lucide-react";
import { SignatureListItem } from "@/components/SignatureListItem";
import { toast } from "@/hooks/use-toast";
import { Signature } from "@/lib/types";
interface ApiResponse {
items: Signature[];
}
import pb from "@/lib/pocketbase";
interface SystemTrackerProps {
system: string;
@@ -27,19 +23,7 @@ export const SystemTracker = ({ system }: SystemTrackerProps) => {
queryKey: ['signatures', system],
queryFn: async () => {
if (!system) return null;
const encodedSystem = encodeURIComponent(system);
const url = `https://evebase.site.quack-lab.dev/api/collections/sigview/records?filter=(system%3D'${encodedSystem}')`;
console.log('Fetching signatures for system:', system);
console.log('API URL:', url);
const response = await fetch(url);
if (!response.ok) {
throw new Error('Failed to fetch signatures');
}
const data: ApiResponse = await response.json();
return data;
return pb.collection('sigview').getFullList({ batch: 1000, filter: `(system='${system}')` });
},
enabled: !!system,
refetchInterval: 5000, // Poll every 5 seconds
@@ -53,7 +37,7 @@ export const SystemTracker = ({ system }: SystemTrackerProps) => {
});
};
const signatures = signaturesData?.items || [];
const signatures = signaturesData || [];
const isLoading = signaturesLoading;
// Sort signatures by date (newest first) and prioritize unknown types

202
src/lib/pbtypes.ts Normal file
View File

@@ -0,0 +1,202 @@
/**
* This file was @generated using pocketbase-typegen
*/
import type PocketBase from 'pocketbase'
import type { RecordService } from 'pocketbase'
export enum Collections {
Authorigins = "_authOrigins",
Externalauths = "_externalAuths",
Mfas = "_mfas",
Otps = "_otps",
Superusers = "_superusers",
Regionview = "regionview",
Signature = "signature",
Sigview = "sigview",
System = "system",
WormholeSystems = "wormholeSystems",
}
// Alias types for improved usability
export type IsoDateString = string
export type RecordIdString = string
export type HTMLString = string
type ExpandType<T> = unknown extends T
? T extends unknown
? { expand?: unknown }
: { expand: T }
: { expand: T }
// System fields
export type BaseSystemFields<T = unknown> = {
id: RecordIdString
collectionId: string
collectionName: Collections
} & ExpandType<T>
export type AuthSystemFields<T = unknown> = {
email: string
emailVisibility: boolean
username: string
verified: boolean
} & BaseSystemFields<T>
// Record types for each collection
export type AuthoriginsRecord = {
collectionRef: string
created?: IsoDateString
fingerprint: string
id: string
recordRef: string
updated?: IsoDateString
}
export type ExternalauthsRecord = {
collectionRef: string
created?: IsoDateString
id: string
provider: string
providerId: string
recordRef: string
updated?: IsoDateString
}
export type MfasRecord = {
collectionRef: string
created?: IsoDateString
id: string
method: string
recordRef: string
updated?: IsoDateString
}
export type OtpsRecord = {
collectionRef: string
created?: IsoDateString
id: string
password: string
recordRef: string
sentTo?: string
updated?: IsoDateString
}
export type SuperusersRecord = {
created?: IsoDateString
email: string
emailVisibility?: boolean
id: string
password: string
tokenKey: string
updated?: IsoDateString
verified?: boolean
}
export type RegionviewRecord = {
id: string
sigcount?: number
sysname: string
sysregion: string
}
export type SignatureRecord = {
created?: IsoDateString
dangerous?: boolean
id: string
identifier: string
name?: string
scanned?: string
system: RecordIdString
type?: string
updated?: IsoDateString
}
export type SigviewRecord = {
created?: IsoDateString
dangerous?: boolean
id: string
identifier: string
scanned?: string
signame?: string
sysid?: RecordIdString
system: string
type?: string
updated?: IsoDateString
}
export type SystemRecord = {
connectedTo?: string
created?: IsoDateString
id: string
name: string
region: string
updated?: IsoDateString
}
export type WormholeSystemsRecord = {
connectedSystems?: string
created?: IsoDateString
id: string
solarSystemName: string
updated?: IsoDateString
x: number
y: number
}
// Response types include system fields and match responses from the PocketBase API
export type AuthoriginsResponse<Texpand = unknown> = Required<AuthoriginsRecord> & BaseSystemFields<Texpand>
export type ExternalauthsResponse<Texpand = unknown> = Required<ExternalauthsRecord> & BaseSystemFields<Texpand>
export type MfasResponse<Texpand = unknown> = Required<MfasRecord> & BaseSystemFields<Texpand>
export type OtpsResponse<Texpand = unknown> = Required<OtpsRecord> & BaseSystemFields<Texpand>
export type SuperusersResponse<Texpand = unknown> = Required<SuperusersRecord> & AuthSystemFields<Texpand>
export type RegionviewResponse<Texpand = unknown> = Required<RegionviewRecord> & BaseSystemFields<Texpand>
export type SignatureResponse<Texpand = unknown> = Required<SignatureRecord> & BaseSystemFields<Texpand>
export type SigviewResponse<Texpand = unknown> = Required<SigviewRecord> & BaseSystemFields<Texpand>
export type SystemResponse<Texpand = unknown> = Required<SystemRecord> & BaseSystemFields<Texpand>
export type WormholeSystemsResponse<Texpand = unknown> = Required<WormholeSystemsRecord> & BaseSystemFields<Texpand>
// Types containing all Records and Responses, useful for creating typing helper functions
export type CollectionRecords = {
_authOrigins: AuthoriginsRecord
_externalAuths: ExternalauthsRecord
_mfas: MfasRecord
_otps: OtpsRecord
_superusers: SuperusersRecord
regionview: RegionviewRecord
signature: SignatureRecord
sigview: SigviewRecord
system: SystemRecord
wormholeSystems: WormholeSystemsRecord
}
export type CollectionResponses = {
_authOrigins: AuthoriginsResponse
_externalAuths: ExternalauthsResponse
_mfas: MfasResponse
_otps: OtpsResponse
_superusers: SuperusersResponse
regionview: RegionviewResponse
signature: SignatureResponse
sigview: SigviewResponse
system: SystemResponse
wormholeSystems: WormholeSystemsResponse
}
// Type for usage with type asserted PocketBase instance
// https://github.com/pocketbase/js-sdk#specify-typescript-definitions
export type TypedPocketBase = PocketBase & {
collection(idOrName: '_authOrigins'): RecordService<AuthoriginsResponse>
collection(idOrName: '_externalAuths'): RecordService<ExternalauthsResponse>
collection(idOrName: '_mfas'): RecordService<MfasResponse>
collection(idOrName: '_otps'): RecordService<OtpsResponse>
collection(idOrName: '_superusers'): RecordService<SuperusersResponse>
collection(idOrName: 'regionview'): RecordService<RegionviewResponse>
collection(idOrName: 'signature'): RecordService<SignatureResponse>
collection(idOrName: 'sigview'): RecordService<SigviewResponse>
collection(idOrName: 'system'): RecordService<SystemResponse>
collection(idOrName: 'wormholeSystems'): RecordService<WormholeSystemsResponse>
}

View File

@@ -1,6 +1,6 @@
import PocketBase from 'pocketbase';
import { TypedPocketBase } from './pbtypes';
const pb = new PocketBase('https://evebase.site.quack-lab.dev');
const pb = new PocketBase('https://evebase.site.quack-lab.dev') as TypedPocketBase;
export default pb;

View File

@@ -27,16 +27,3 @@ export interface Connection {
to: Position;
color?: string;
}
export interface Signature {
id?: string;
identifier: string;
signame: string;
sysid: string;
system: string;
type: string;
updated?: string;
created?: string;
dangerous?: boolean;
scanned?: string;
}

View File

@@ -10,7 +10,7 @@ import { Header } from "@/components/Header";
import { parseSignature, parseScannedPercentage } from "@/utils/signatureParser";
import { getSystemId } from "@/utils/systemApi";
import pb from "@/lib/pocketbase";
import { Signature } from "@/lib/types";
import { SigviewRecord as Signature } from "@/lib/pbtypes";
export const SystemView = () => {
const { system, region } = useParams();
@@ -27,7 +27,7 @@ export const SystemView = () => {
try {
// Check if signature already exists
const existingRecords = await pb.collection('signature').getList(1, 1, {
filter: `identifier='${signature.identifier}' && system='${signature.system}'`
filter: `(id='${signature.id}' && system='${signature.system}')`
});
const newScannedPercentage = parseScannedPercentage(signature.scanned);
@@ -84,7 +84,7 @@ export const SystemView = () => {
try {
const systemId = await getSystemId(system);
const lines = pastedText.trim().split('\n').filter(line => line.trim());
const parsedSignatures: Signature[] = [];
const parsedSignatures: Omit<Signature, 'id'>[] = [];
// Parse all signatures
for (const line of lines) {
@@ -93,7 +93,8 @@ export const SystemView = () => {
parsedSignatures.push({
...parsed,
system: systemId,
sysid: systemId
sysid: systemId,
identifier: parsed.identifier
});
}
}
@@ -130,7 +131,7 @@ export const SystemView = () => {
// Save all new/updated signatures
for (const signature of parsedSignatures) {
await saveSignature(signature);
await saveSignature(signature as Signature);
}
// Invalidate queries to refresh the data

View File

@@ -1,6 +1,6 @@
import { Signature } from "@/lib/types";
import { SigviewRecord as Signature } from "@/lib/pbtypes";
export const parseSignature = (text: string): Omit<Signature, 'system' | 'sysid'> | null => {
export const parseSignature = (text: string): Omit<Signature, 'system' | 'id' | 'sysid'> | null => {
const parts = text.split('\t');
if (parts.length < 4) return null;