Skip to content

Commit

Permalink
[api] make type imports consistent and verbatimModuleSyntax compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
freemvmt committed Sep 12, 2024
1 parent 4d1eca8 commit 4ca288e
Show file tree
Hide file tree
Showing 132 changed files with 242 additions and 223 deletions.
2 changes: 1 addition & 1 deletion api.planx.uk/docs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Express } from "express";
import type { Express } from "express";
import swaggerJSDoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";

Expand Down
5 changes: 3 additions & 2 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { gql } from "graphql-request";
import capitalize from "lodash/capitalize.js";
import { Flow, Node } from "./types.js";
import { ComponentType, FlowGraph } from "@opensystemslab/planx-core/types";
import type { Flow, Node } from "./types.js";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";
import { $public, getClient } from "./client/index.js";

export interface FlowData {
Expand Down
7 changes: 4 additions & 3 deletions api.planx.uk/lib/hasura/metadata/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createScheduledEvent, RequiredScheduledEventArgs } from "./index.js";
import axios from "axios";
import type { Mocked } from "vitest";
import type { RequiredScheduledEventArgs } from "./index.js";
import { createScheduledEvent } from "./index.js";
import axios from "axios";

describe("Creation of scheduled event", () => {
vi.mock("axios", async (importOriginal) => {
const actualAxios = await importOriginal<typeof import("axios")>();
const actualAxios = await importOriginal<typeof axios>();
return {
default: {
...actualAxios,
Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/lib/hasura/metadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Axios, { AxiosResponse, isAxiosError } from "axios";
import type { AxiosResponse } from "axios";
import Axios, { isAxiosError } from "axios";

/**
* Body posted to Hasura Metadata API to create a scheduled event
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/lib/hasura/schema/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Mocked } from "vitest";

describe("runSQL", () => {
vi.mock("axios", async (importOriginal) => {
const actualAxios = await importOriginal<typeof import("axios")>();
const actualAxios = await importOriginal<typeof axios>();
return {
default: {
...actualAxios,
Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/lib/hasura/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Axios, { AxiosResponse, isAxiosError } from "axios";
import type { AxiosResponse } from "axios";
import Axios, { isAxiosError } from "axios";

export interface RunSQLArgs {
source: "default";
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/lib/notify/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendEmail } from "./index.js";
import { NotifyClient } from "notifications-node-client";
import { NotifyConfig } from "../../types.js";
import type { NotifyConfig } from "../../types.js";

vi.mock("notifications-node-client");

Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/lib/notify/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NotifyClient } from "notifications-node-client";
import { softDeleteSession } from "../../modules/saveAndReturn/service/utils.js";
import { NotifyConfig } from "../../types.js";
import type { NotifyConfig } from "../../types.js";
import { $api, $public } from "../../client/index.js";

const notifyClient = new NotifyClient(process.env.GOVUK_NOTIFY_API_KEY);
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/admin/session/csv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stringify } from "csv-stringify";
import { NextFunction, Request, Response } from "express";
import type { NextFunction, Request, Response } from "express";
import { $api } from "../../../client/index.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/admin/session/digitalPlanningData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextFunction, Request, Response } from "express";
import type { NextFunction, Request, Response } from "express";
import { $api } from "../../../client/index.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/admin/session/oneAppXML.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, Response, NextFunction } from "express";
import type { Request, Response, NextFunction } from "express";
import { $api } from "../../../client/index.js";

/**
Expand Down
11 changes: 8 additions & 3 deletions api.planx.uk/modules/admin/session/summary.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {
import type {
GovUKPayment,
PaymentRequest,
Session,
Team,
} from "@opensystemslab/planx-core/types";
import { NextFunction, Request, Response } from "express";
import type { NextFunction, Request, Response } from "express";
import { gql } from "graphql-request";

import { Breadcrumb, Flow, LowCalSession, Passport } from "../../../types.js";
import type {
Breadcrumb,
Flow,
LowCalSession,
Passport,
} from "../../../types.js";
import { $api } from "../../../client/index.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/admin/session/zip.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextFunction, Request, Response } from "express";
import type { NextFunction, Request, Response } from "express";
import { buildSubmissionExportZip } from "../../send/utils/exportZip.js";

/**
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/analytics/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { trackAnalyticsLogExit } from "./service.js";
import { ValidatedRequestHandler } from "../../shared/middleware/validate.js";
import type { ValidatedRequestHandler } from "../../shared/middleware/validate.js";

export const logAnalyticsSchema = z.object({
query: z.object({
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/auth/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CookieOptions, RequestHandler, Response } from "express";
import { Request } from "express-jwt";
import type { CookieOptions, RequestHandler, Response } from "express";
import type { Request } from "express-jwt";

export const failedLogin: RequestHandler = (_req, _res, next) =>
next({
Expand Down
10 changes: 5 additions & 5 deletions api.planx.uk/modules/auth/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import crypto from "crypto";
import assert from "assert";
import { ServerError } from "../../errors/index.js";
import { Template } from "../../lib/notify/index.js";
import type { Template } from "../../lib/notify/index.js";
import { expressjwt } from "express-jwt";
import { generators } from "openid-client";
import { Authenticator } from "passport";
import { RequestHandler } from "http-proxy-middleware";
import { Role } from "@opensystemslab/planx-core/types";
import type { Authenticator } from "passport";
import type { RequestHandler } from "http-proxy-middleware";
import type { Role } from "@opensystemslab/planx-core/types";
import { AsyncLocalStorage } from "async_hooks";
import { Request } from "express";
import type { Request } from "express";

export const userContext = new AsyncLocalStorage<{ user: Express.User }>();

Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/modules/auth/passport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Issuer } from "openid-client";
import passport, { type Authenticator } from "passport";
import type { Authenticator } from "passport";
import passport from "passport";

import { googleStrategy } from "./strategy/google.js";
import {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/auth/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jwt from "jsonwebtoken";
import { $api } from "../../client/index.js";
import { User, Role } from "@opensystemslab/planx-core/types";
import type { User, Role } from "@opensystemslab/planx-core/types";

export const buildJWT = async (email: string): Promise<string | undefined> => {
await checkUserCanAccessEnv(email, process.env.NODE_ENV);
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { uploadPrivateFile, uploadPublicFile } from "./service/uploadFile.js";
import { buildFilePath } from "./service/utils.js";
import { getFileFromS3 } from "./service/getFile.js";
import { z } from "zod";
import { ValidatedRequestHandler } from "../../shared/middleware/validate.js";
import type { ValidatedRequestHandler } from "../../shared/middleware/validate.js";
import { ServerError } from "../../errors/index.js";

assert(process.env.AWS_S3_BUCKET);
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/file.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import supertest from "supertest";
import { Mocked } from "vitest";
import type { Mocked } from "vitest";

import app from "../../server.js";
import { deleteFilesByURL } from "./service/deleteFile.js";
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/service/deleteFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeleteObjectsRequest } from "aws-sdk/clients/s3.js";
import type { DeleteObjectsRequest } from "aws-sdk/clients/s3.js";
import { getS3KeyFromURL, s3Factory } from "./utils.js";

export const deleteFilesByURL = async (
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/service/getFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import S3 from "aws-sdk/clients/s3.js";
import type S3 from "aws-sdk/clients/s3.js";
import { s3Factory } from "./utils.js";

export const getFileFromS3 = async (fileId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/file/service/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import S3 from "aws-sdk/clients/s3.js";
import type S3 from "aws-sdk/clients/s3.js";
import { customAlphabet } from "nanoid";
import mime from "mime";
import { s3Factory } from "./utils.js";
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/copyFlow/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { Flow } from "../../../types.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { Flow } from "../../../types.js";
import { ServerError } from "../../../errors/index.js";
import { copyFlow } from "./service.js";

Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/copyFlow/copyFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import supertest from "supertest";
import { queryMock } from "../../../tests/graphqlQueryMock.js";
import { authHeader } from "../../../tests/mockJWT.js";
import app from "../../../server.js";
import { Flow } from "../../../types.js";
import type { Flow } from "../../../types.js";
import { userContext } from "../../auth/middleware.js";

beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/copyFlowAsPortal/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { Flow } from "../../../types.js";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { Flow } from "../../../types.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { copyPortalAsFlow } from "./service.js";
import { ServerError } from "../../../errors/index.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import supertest from "supertest";
import { queryMock } from "../../../tests/graphqlQueryMock.js";
import { authHeader } from "../../../tests/mockJWT.js";
import app from "../../../server.js";
import { Flow } from "../../../types.js";
import type { Flow } from "../../../types.js";

beforeEach(() => {
queryMock.mockQuery({
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/copyFlowAsPortal/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getFlowData, getChildren, makeUniqueFlow } from "../../../helpers.js";
import { Flow } from "../../../types.js";
import type { Flow } from "../../../types.js";

/**
* Copies an internal portal and transforms it to be an independent flow
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/downloadSchema/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { stringify } from "csv-stringify";
import { getFlowSchema } from "./service.js";
import { ServerError } from "../../../errors/index.js";
Expand Down
6 changes: 3 additions & 3 deletions api.planx.uk/modules/flows/findReplace/controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Flow } from "../../../types.js";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { Flow } from "../../../types.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { z } from "zod";
import { ServerError } from "../../../errors/index.js";
import { findAndReplaceInFlow } from "./service.js";
import { FlowGraph } from "@opensystemslab/planx-core/types";
import type { FlowGraph } from "@opensystemslab/planx-core/types";

interface FindAndReplaceResponse {
message: string;
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/findReplace/findReplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import supertest from "supertest";
import { queryMock } from "../../../tests/graphqlQueryMock.js";
import { authHeader } from "../../../tests/mockJWT.js";
import app from "../../../server.js";
import { Flow } from "../../../types.js";
import type { Flow } from "../../../types.js";

const auth = authHeader({ role: "platformAdmin" });

Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/findReplace/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from "graphql-request";
import { getFlowData } from "../../../helpers.js";
import { $api } from "../../../client/index.js";
import { FlowGraph } from "@opensystemslab/planx-core/types";
import { Flow } from "../../../types.js";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import type { Flow } from "../../../types.js";

interface MatchResult {
matches: Flow["data"];
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/flattenFlow/controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FlowGraph } from "@opensystemslab/planx-core/types";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { z } from "zod";
import { ServerError } from "../../../errors/index.js";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { dataMerged } from "../../../helpers.js";

type FlattenFlowDataResponse = FlowGraph;
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/moveFlow/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { z } from "zod";
import { ServerError } from "../../../errors/index.js";
import { moveFlow } from "./service.js";
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/moveFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { gql } from "graphql-request";
import { Flow } from "../../../types.js";
import type { Flow } from "../../../types.js";
import { getClient } from "../../../client/index.js";
import { Team } from "@opensystemslab/planx-core/types";
import type { Team } from "@opensystemslab/planx-core/types";

export const moveFlow = async (flowId: string, teamSlug: string) => {
const $client = getClient();
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/publish/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from "@opensystemslab/planx-core/types";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { Node } from "@opensystemslab/planx-core/types";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { z } from "zod";
import { publishFlow } from "./service.js";
import { ServerError } from "../../../errors/index.js";
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/flows/publish/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as jsondiffpatch from "jsondiffpatch";
import { dataMerged, getMostRecentPublishedFlow } from "../../../helpers.js";
import { gql } from "graphql-request";
import { FlowGraph, Node } from "@opensystemslab/planx-core/types";
import type { FlowGraph, Node } from "@opensystemslab/planx-core/types";
import { userContext } from "../../auth/middleware.js";
import { getClient } from "../../../client/index.js";

Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/validate/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Node } from "@opensystemslab/planx-core/types";
import { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import type { Node } from "@opensystemslab/planx-core/types";
import type { ValidatedRequestHandler } from "../../../shared/middleware/validate.js";
import { z } from "zod";
import { validateAndDiffFlow } from "./service/index.js";
import { ServerError } from "../../../errors/index.js";
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/modules/flows/validate/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
import type {
ComponentType,
FlowGraph,
Node,
} from "@opensystemslab/planx-core/types";
import { Entry } from "type-fest";
import type { Entry } from "type-fest";

export const isComponentType = (
entry: Entry<FlowGraph>,
Expand Down
9 changes: 3 additions & 6 deletions api.planx.uk/modules/flows/validate/service/fileTypes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { getValidSchemaValues } from "@opensystemslab/planx-core";
import {
ComponentType,
FlowGraph,
Node,
} from "@opensystemslab/planx-core/types";
import type { FlowGraph, Node } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";
import countBy from "lodash/countBy.js";

import { isComponentType } from "../helpers.js";
import { FlowValidationResponse } from "./index.js";
import type { FlowValidationResponse } from "./index.js";

const validateFileTypes = (flowGraph: FlowGraph): FlowValidationResponse => {
// Get all passport variables set by FileUpload and/or FileUploadAndLabel
Expand Down
6 changes: 5 additions & 1 deletion api.planx.uk/modules/flows/validate/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ComponentType, Edges, Node } from "@opensystemslab/planx-core/types";
import type {
ComponentType,
Edges,
Node,
} from "@opensystemslab/planx-core/types";
import * as jsondiffpatch from "jsondiffpatch";

import { dataMerged, getMostRecentPublishedFlow } from "../../../../helpers.js";
Expand Down
5 changes: 3 additions & 2 deletions api.planx.uk/modules/flows/validate/service/inviteToPay.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ComponentType, FlowGraph } from "@opensystemslab/planx-core/types";
import type { FlowGraph } from "@opensystemslab/planx-core/types";
import { ComponentType } from "@opensystemslab/planx-core/types";

import {
hasComponentType,
isComponentType,
numberOfComponentType,
} from "../helpers.js";
import { FlowValidationResponse } from "./index.js";
import type { FlowValidationResponse } from "./index.js";

const validateInviteToPay = (flowGraph: FlowGraph): FlowValidationResponse => {
if (inviteToPayEnabled(flowGraph)) {
Expand Down
Loading

0 comments on commit 4ca288e

Please sign in to comment.