insomnia/packages/insomnia-app/app/models/helpers/is-model.ts
Dimitri Mitropoulos 5f4c19da35
[TypeScript] Phase 1 & 2 (#3370)
Co-authored-by: Opender Singh <opender.singh@konghq.com>
2021-05-12 18:35:00 +12:00

56 lines
1.6 KiB
TypeScript

import type { BaseModel } from '../index';
import {
grpcRequest,
request,
requestGroup,
protoFile,
protoDirectory,
workspace,
} from '../index';
import type { Workspace } from '../workspace';
import { WorkspaceScopeKeys } from '../../models/workspace';
import { ProtoDirectory } from '../proto-directory';
import { ProtoFile } from '../proto-file';
import { RequestGroup } from '../request-group';
import { Request } from '../request';
import { GrpcRequest } from '../grpc-request';
export const isGrpcRequestId = (id: string | null) => (
id?.startsWith(`${grpcRequest.prefix}_`)
);
// TODO: Invalid until we can ensure all requests are prefixed by the id correctly INS-341
// export const isRequestId = (id: string) => id.startsWith(`${request.prefix}_`);
export const isGrpcRequest = (obj: Pick<BaseModel, 'type'>): obj is GrpcRequest => (
obj.type === grpcRequest.type
);
export const isRequest = (obj: Pick<BaseModel, 'type'>): obj is Request => (
obj.type === request.type
);
export const isRequestGroup = (obj: Pick<BaseModel, 'type'>): obj is RequestGroup => (
obj.type === requestGroup.type
);
export const isProtoFile = (obj: Pick<BaseModel, 'type'>): obj is ProtoFile => (
obj.type === protoFile.type
);
export const isProtoDirectory = (obj: Pick<BaseModel, 'type'>): obj is ProtoDirectory => (
obj.type === protoDirectory.type
);
export const isWorkspace = (obj: Pick<BaseModel, 'type'>): obj is Workspace => (
obj.type === workspace.type
);
export const isDesign = (obj: Partial<Workspace>) => (
obj.scope === WorkspaceScopeKeys.design
);
export const isCollection = (obj: Workspace) => (
obj.scope === WorkspaceScopeKeys.collection
);