Skip to content

Commit

Permalink
refactor(next-drupal): make type imports explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Oct 18, 2023
1 parent ce466e4 commit d0e83a6
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 61 deletions.
2 changes: 1 addition & 1 deletion packages/next-drupal-query/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import deepmerge from "deepmerge"
import { DrupalJsonApiParams } from "drupal-jsonapi-params"
import { GetServerSidePropsContext, GetStaticPathsContext } from "next"
import type { GetServerSidePropsContext, GetStaticPathsContext } from "next"
import type { RequireAllOrNone, ConditionalKeys } from "type-fest"

// Note: some generic are explicitly not typed here to force definition.
Expand Down
47 changes: 23 additions & 24 deletions packages/next-drupal/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
import Jsona from "jsona"
import { stringify } from "qs"
import { JsonApiErrors } from "./jsonapi-errors"
import { logger as defaultLogger } from "./logger"
import type {
GetStaticPathsContext,
GetStaticPathsResult,
GetStaticPropsContext,
NextApiRequest,
NextApiResponse,
} from "next"
import { stringify } from "qs"
import Jsona from "jsona"

import type {
JsonApiResource,
Locale,
AccessToken,
JsonApiResponse,
JsonApiWithLocaleOptions,
JsonApiParams,
DrupalTranslatedPath,
BaseUrl,
DrupalClientAuthAccessToken,
DrupalClientAuthClientIdSecret,
DrupalClientAuthUsernamePassword,
DrupalClientOptions,
DrupalFile,
DrupalMenuLinkContent,
DrupalTranslatedPath,
DrupalView,
FetchOptions,
DrupalClientOptions,
BaseUrl,
JsonApiWithAuthOptions,
PathPrefix,
JsonApiCreateFileResourceBody,
JsonApiCreateResourceBody,
JsonApiParams,
JsonApiResource,
JsonApiResourceWithPath,
JsonApiResponse,
JsonApiUpdateResourceBody,
JsonApiWithAuthOptions,
JsonApiWithCacheOptions,
JsonApiWithLocaleOptions,
Locale,
PathAlias,
PathPrefix,
PreviewOptions,
JsonApiWithCacheOptions,
JsonApiCreateResourceBody,
JsonApiUpdateResourceBody,
DrupalClientAuthUsernamePassword,
DrupalClientAuthAccessToken,
DrupalClientAuthClientIdSecret,
JsonApiCreateFileResourceBody,
DrupalView,
DrupalFile,
} from "./types"
import { logger as defaultLogger } from "./logger"
import { JsonApiErrors } from "./jsonapi-errors"

const DEFAULT_API_PREFIX = "/jsonapi"
const DEFAULT_FRONT_PAGE = "/home"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/src/get-access-token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cache } from "./get-cache"
import { AccessToken } from "./types"
import type { AccessToken } from "./types"

const CACHE_KEY = "NEXT_DRUPAL_ACCESS_TOKEN"

Expand Down
4 changes: 2 additions & 2 deletions packages/next-drupal/src/get-menu.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
import { buildHeaders, buildUrl, deserialize } from "./utils"
import type {
AccessToken,
DrupalMenuLinkContent,
JsonApiWithLocaleOptions,
} from "./types"
import { buildHeaders, buildUrl, deserialize } from "./utils"

export async function getMenu<T extends DrupalMenuLinkContent>(
name: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/next-drupal/src/get-paths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetStaticPathsContext, GetStaticPathsResult } from "next"
import { getResourceCollection } from "./get-resource-collection"
import { AccessToken, JsonApiParams, Locale } from "./types"
import type { GetStaticPathsContext, GetStaticPathsResult } from "next"
import type { AccessToken, JsonApiParams, Locale } from "./types"

export async function getPathsFromContext(
types: string | string[],
Expand Down
14 changes: 7 additions & 7 deletions packages/next-drupal/src/get-resource-collection.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { GetStaticPropsContext } from "next"
import {
AccessToken,
JsonApiParams,
JsonApiWithLocaleOptions,
JsonApiResource,
} from "./types"
import {
buildHeaders,
buildUrl,
deserialize,
getJsonApiPathForResourceType,
} from "./utils"
import type { GetStaticPropsContext } from "next"
import type {
AccessToken,
JsonApiParams,
JsonApiResource,
JsonApiWithLocaleOptions,
} from "./types"

export async function getResourceCollection<T = JsonApiResource[]>(
type: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/next-drupal/src/get-resource-type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetStaticPropsContext } from "next"
import { translatePathFromContext } from "./translate-path"
import { AccessToken } from "./types"
import type { GetStaticPropsContext } from "next"
import type { AccessToken } from "./types"

export async function getResourceTypeFromContext(
context: GetStaticPropsContext,
Expand Down
14 changes: 7 additions & 7 deletions packages/next-drupal/src/get-resource.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { GetStaticPropsContext } from "next"
import { stringify } from "qs"
import {
AccessToken,
JsonApiParams,
JsonApiWithLocaleOptions,
JsonApiResource,
} from "./types"
import {
buildHeaders,
buildUrl,
deserialize,
getJsonApiPathForResourceType,
getPathFromContext,
} from "./utils"
import type { GetStaticPropsContext } from "next"
import type {
AccessToken,
JsonApiParams,
JsonApiResource,
JsonApiWithLocaleOptions,
} from "./types"

export async function getResourceFromContext<T extends JsonApiResource>(
type: string,
Expand Down
8 changes: 6 additions & 2 deletions packages/next-drupal/src/get-search-index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { GetStaticPropsContext } from "next"
import { AccessToken, JsonApiResource, JsonApiWithLocaleOptions } from "./types"
import { buildHeaders, buildUrl, deserialize } from "./utils"
import type { GetStaticPropsContext } from "next"
import type {
AccessToken,
JsonApiResource,
JsonApiWithLocaleOptions,
} from "./types"

export async function getSearchIndex<T = JsonApiResource[]>(
name: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/src/get-view.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccessToken, JsonApiWithLocaleOptions } from "./types"
import { buildHeaders, buildUrl, deserialize } from "./utils"
import type { AccessToken, JsonApiWithLocaleOptions } from "./types"

export async function getView<T>(
name: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/src/jsonapi-errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonApiError } from "./types"
import type { JsonApiError } from "./types"

export class JsonApiErrors extends Error {
errors: JsonApiError[] | string
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from "."
import type { Logger } from "./types"

// Default logger. Uses console.
export const logger: Logger = {
Expand Down
4 changes: 2 additions & 2 deletions packages/next-drupal/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next"
import { getResourceByPath } from "./get-resource"
import { JsonApiWithLocaleOptions } from "./types"
import type { NextApiRequest, NextApiResponse } from "next"
import type { JsonApiWithLocaleOptions } from "./types"

interface PreviewOptions {
errorMessages?: {
Expand Down
4 changes: 2 additions & 2 deletions packages/next-drupal/src/translate-path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GetStaticPropsContext } from "next"
import { AccessToken, DrupalTranslatedPath } from "./types"
import { buildHeaders, buildUrl, getPathFromContext } from "./utils"
import type { GetStaticPropsContext } from "next"
import type { AccessToken, DrupalTranslatedPath } from "./types"

export async function translatePath(
path: string,
Expand Down
5 changes: 2 additions & 3 deletions packages/next-drupal/src/use-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from "react"
import { useRouter } from "next/router"

import * as React from "react"
import { getMenu } from "./get-menu"
import { DrupalMenuLinkContent } from "./types"
import type { DrupalMenuLinkContent } from "./types"

export function useMenu<T extends DrupalMenuLinkContent>(
name: string
Expand Down
6 changes: 3 additions & 3 deletions packages/next-drupal/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GetStaticPropsContext } from "next"
import Jsona from "jsona"
import { getAccessToken } from "./get-access-token"
import { AccessToken, Locale } from "./types"
import { stringify } from "qs"
import { getAccessToken } from "./get-access-token"
import type { GetStaticPropsContext } from "next"
import type { AccessToken, Locale } from "./types"

const JSONAPI_PREFIX = process.env.DRUPAL_JSONAPI_PREFIX || "/jsonapi"

Expand Down

0 comments on commit d0e83a6

Please sign in to comment.