Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] implement verbatim module syntax in tsconfig #3528

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/consistent-type-imports": "error",
"no-nested-ternary": "error",
"@vitest/expect-expect": [
"error",
Expand Down
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
5 changes: 3 additions & 2 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 type { RequiredScheduledEventArgs } from "./index.js";
import { createScheduledEvent } from "./index.js";
import axios from "axios";
import type { Mocked } from "vitest";

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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -46,7 +47,7 @@ const postToMetadataAPI = async (
body: ScheduledEvent,
): Promise<AxiosResponse<ScheduledEventResponse>> => {
try {
return await Axios.post(
return await axios.post(
process.env.HASURA_METADATA_URL!,
JSON.stringify(body),
{
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
5 changes: 3 additions & 2 deletions 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 All @@ -18,7 +19,7 @@ const postToSchemaAPI = async <T>(
query: SchemaAPIQuery,
): Promise<AxiosResponse<T>> => {
try {
return await Axios.post(
return await axios.post(
process.env.HASURA_SCHEMA_URL!,
JSON.stringify(query),
{
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 Expand Up @@ -70,7 +70,7 @@
if (template === "save")
returnValue.expiryDate = config.personalisation.expiryDate;
return returnValue;
} catch (error: any) {

Check warning on line 73 in api.planx.uk/lib/notify/index.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
const notifyError = error?.response?.data?.errors?.length
? JSON.stringify(error?.response?.data?.errors?.[0])
: error?.message;
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 Expand Up @@ -70,7 +67,7 @@
const uploadAndLabelFileTypes = uploadAndLabelNodes
.map(([_nodeId, node]: [string, Node]) => node.data?.fileTypes)
.flat();
return uploadAndLabelFileTypes?.map((file: any) => file?.fn as string);

Check warning on line 70 in api.planx.uk/modules/flows/validate/service/fileTypes.ts

View workflow job for this annotation

GitHub Actions / Run API Tests

Unexpected any. Specify a different type
};

export { validateFileTypes };
Loading
Loading