Skip to content

Commit

Permalink
feat: use type imports so we will be able to drop unnecessary runtime…
Browse files Browse the repository at this point in the history
… deps
  • Loading branch information
darkbasic committed Nov 22, 2023
1 parent ea13493 commit 7d51840
Show file tree
Hide file tree
Showing 142 changed files with 352 additions and 308 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ module.exports = {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
disallowTypeAnnotations: true,
fixStyle: 'inline-type-imports',
},
],
},
};
2 changes: 1 addition & 1 deletion examples/accounts-microservice/src/app-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fetch from 'node-fetch';
import { mergeTypeDefs } from '@graphql-tools/merge';
import { schemaFromExecutor } from '@graphql-tools/wrap';
import { stitchSchemas } from '@graphql-tools/stitch';
import { AsyncExecutor } from '@graphql-tools/utils';
import { type AsyncExecutor } from '@graphql-tools/utils';
import { OperationTypeNode, print } from 'graphql';
import {
authDirective,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'reflect-metadata';
import {
EmailCtor,
EmailCtorArgs as AccountsEmailCtorArgs,
type EmailCtor,
type EmailCtorArgs as AccountsEmailCtorArgs,
getEmailCtor,
} from '@accounts/mikro-orm';
import { Entity, Property } from '@mikro-orm/core';
import { User } from './user';
import { type User } from './user';

export type EmailCtorArgs = AccountsEmailCtorArgs<User> & {
fullName: string;
Expand Down
10 changes: 5 additions & 5 deletions examples/graphql-server-mikro-orm-postgres/src/entities/user.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'reflect-metadata';
import {
UserCtorArgs as AccountsUserCtorArgs,
Session,
Service,
UserCtor,
type UserCtorArgs as AccountsUserCtorArgs,
type Session,
type Service,
type UserCtor,
getUserCtor,
} from '@accounts/mikro-orm';
import { Entity, Property } from '@mikro-orm/core';
import { Email, EmailCtorArgs } from './email';
import { Email, type EmailCtorArgs } from './email';

type UserCtorArgs = AccountsUserCtorArgs & {
firstName: string;
Expand Down
3 changes: 2 additions & 1 deletion examples/graphql-server-typeorm-postgres/src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createConnection } from 'typeorm';
import { entities } from '@accounts/typeorm';

export const connect = (url = process.env.DATABASE_URL) => {
return createConnection({
type: 'postgres',
url,
entities: [...require('@accounts/typeorm').entities],
entities,
synchronize: true,
}).then((connection) => {
return connection;
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql-server-typescript-basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { createApplication } from 'graphql-modules';
import { createAccountsMongoModule } from '@accounts/module-mongo';
import { createHandler } from 'graphql-http/lib/use/http';
import http from 'http';
import { IContext } from '@accounts/types';
import { type IContext } from '@accounts/types';

void (async () => {
// Create database connection
Expand Down
6 changes: 3 additions & 3 deletions modules/module-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createModule, gql, Provider } from 'graphql-modules';
import { createModule, gql, type Provider } from 'graphql-modules';
import { mergeTypeDefs } from '@graphql-tools/merge';
import { User, IContext } from '@accounts/types';
import { type User, type IContext } from '@accounts/types';
import {
AccountsServer,
AccountsServerOptions,
type AccountsServerOptions,
AccountsCoreConfigToken,
DatabaseInterfaceUserToken,
DatabaseInterfaceSessionsToken,
Expand Down
2 changes: 1 addition & 1 deletion modules/module-core/src/resolvers/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountsServer } from '@accounts/server';
import { MutationResolvers } from '../models';
import { type MutationResolvers } from '../models';

export const Mutation: MutationResolvers = {
authenticate: async (_, args, ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion modules/module-core/src/resolvers/query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QueryResolvers } from '../models';
import { type QueryResolvers } from '../models';

export const Query: QueryResolvers = {
getUser: (_, __, context) => context.user || null,
Expand Down
2 changes: 1 addition & 1 deletion modules/module-core/src/utils/authenticated-directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticated } from './authenticated-resolver';
import { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils';
import { defaultFieldResolver, GraphQLSchema } from 'graphql';
import { defaultFieldResolver, type GraphQLSchema } from 'graphql';

export function authDirective(directiveName = 'auth') {
const typeDirectiveArgumentMaps: Record<string, any> = {};
Expand Down
12 changes: 6 additions & 6 deletions modules/module-core/src/utils/context-builder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import AccountsServer from '@accounts/server';
import { IncomingHttpHeaders, IncomingMessage } from 'http';
import { type IncomingHttpHeaders, type IncomingMessage } from 'http';
import { getClientIp } from 'request-ip';
import { IContext, User } from '@accounts/types';
import { Application } from 'graphql-modules';
import { Request as RequestGraphqlHttp, RequestHeaders } from 'graphql-http';
import { RequestContext } from 'graphql-http/lib/use/http';
import http from 'http';
import { type IContext, type User } from '@accounts/types';
import { type Application } from 'graphql-modules';
import { type Request as RequestGraphqlHttp, type RequestHeaders } from 'graphql-http';
import { type RequestContext } from 'graphql-http/lib/use/http';
import type http from 'http';

export type AccountsContextOptions<Ctx extends object> = {
createOperationController: Application['createOperationController'];
Expand Down
6 changes: 3 additions & 3 deletions modules/module-core/src/utils/schema-builder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GraphQLSchema } from 'graphql';
import { ApplicationConfig } from 'graphql-modules';
import { type GraphQLSchema } from 'graphql';
import { type ApplicationConfig } from 'graphql-modules';
import { authDirective } from './authenticated-directive';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { mergeResolvers, mergeTypeDefs } from '@graphql-tools/merge';
import { IResolvers, Maybe, TypeSource } from '@graphql-tools/utils';
import { type IResolvers, type Maybe, type TypeSource } from '@graphql-tools/utils';

export const buildSchema =
<TSource, TContext>({
Expand Down
2 changes: 1 addition & 1 deletion modules/module-magic-link/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AccountsMagicLink,
AccountsMagicLinkOptions,
type AccountsMagicLinkOptions,
AccountsMagicLinkConfigToken,
} from '@accounts/magic-link';
import { createModule } from 'graphql-modules';
Expand Down
2 changes: 1 addition & 1 deletion modules/module-magic-link/src/resolvers/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AccountsMagicLink, RequestMagicLinkEmailErrors } from '@accounts/magic-link';
import { AccountsServer, AccountsJsError } from '@accounts/server';
import { MutationResolvers } from '../models';
import { type MutationResolvers } from '../models';

export const Mutation: MutationResolvers = {
requestMagicLinkEmail: async (_, { email }, ctx) => {
Expand Down
19 changes: 12 additions & 7 deletions modules/module-mikro-orm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { createModule, gql, Provider, Scope } from 'graphql-modules';
import { createModule, gql, type Provider, Scope } from 'graphql-modules';
import { DatabaseInterfaceSessionsToken, DatabaseInterfaceUserToken } from '@accounts/server';
import {
AccountsMikroOrm,
Email,
Session,
Service,
type Email,
type Session,
type Service,
EmailToken,
IUser,
type IUser,
SessionToken,
ServiceToken,
UserToken,
} from '@accounts/mikro-orm';
import { Connection, Constructor, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { DatabaseType } from '@accounts/types';
import {
type Connection,
type Constructor,
EntityManager,
type IDatabaseDriver,
} from '@mikro-orm/core';
import { type DatabaseType } from '@accounts/types';

export * from './types';
export * from './utils';
Expand Down
6 changes: 3 additions & 3 deletions modules/module-mikro-orm/src/types/IContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IContext as AccountsContext } from '@accounts/types';
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { IUser } from '@accounts/mikro-orm';
import { type IContext as AccountsContext } from '@accounts/types';
import { type Connection, type EntityManager, type IDatabaseDriver } from '@mikro-orm/core';
import { type IUser } from '@accounts/mikro-orm';

export interface IContext<User extends IUser<any, any, any> = IUser<any, any, any>>
extends Omit<AccountsContext, 'user'> {
Expand Down
6 changes: 3 additions & 3 deletions modules/module-mikro-orm/src/utils/context-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IUser } from '@accounts/mikro-orm';
import { type IUser } from '@accounts/mikro-orm';
import { context as contextBase } from '@accounts/module-core';
import { Connection, EntityManager, IDatabaseDriver } from '@mikro-orm/core';
import { IContext } from '../types';
import { type Connection, type EntityManager, type IDatabaseDriver } from '@mikro-orm/core';
import { type IContext } from '../types';

export const context = async <
User extends IUser<any, any, any> = IUser<any, any, any>,
Expand Down
4 changes: 2 additions & 2 deletions modules/module-mongo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createModule, gql, Module, Provider } from 'graphql-modules';
import { createModule, gql, type Module, type Provider } from 'graphql-modules';
import { DatabaseInterfaceSessionsToken, DatabaseInterfaceUserToken } from '@accounts/server';
import { DatabaseType } from '@accounts/types';
import {
AccountsMongoConfigToken,
AccountsMongoOptions,
type AccountsMongoOptions,
Mongo,
MongoConnectionToken,
} from '@accounts/mongo';
Expand Down
4 changes: 2 additions & 2 deletions modules/module-password/__tests__/resolvers/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
SendResetPasswordEmailErrors,
SendVerificationEmailErrors,
} from '@accounts/password';
import { LoginResult } from '@accounts/types';
import { type LoginResult } from '@accounts/types';
import { Mutation } from '../../src/resolvers/mutation';
import { CreateUserInput } from '../../src';
import { type CreateUserInput } from '../../src';

describe('accounts-password resolvers mutation', () => {
const accountsServerMock = {
Expand Down
2 changes: 1 addition & 1 deletion modules/module-password/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Query } from './resolvers/query';
import { Mutation } from './resolvers/mutation';
import AccountsPassword, {
AccountsPasswordConfigToken,
AccountsPasswordOptions,
type AccountsPasswordOptions,
} from '@accounts/password';

export * from './models';
Expand Down
4 changes: 2 additions & 2 deletions modules/module-password/src/resolvers/mutation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CreateUserServicePassword } from '@accounts/types';
import { type CreateUserServicePassword } from '@accounts/types';
import {
AccountsPassword,
CreateUserErrors,
SendResetPasswordEmailErrors,
SendVerificationEmailErrors,
} from '@accounts/password';
import { AccountsServer, AccountsJsError } from '@accounts/server';
import { MutationResolvers } from '../models';
import { type MutationResolvers } from '../models';
import { GraphQLError } from 'graphql';

export const Mutation: MutationResolvers = {
Expand Down
2 changes: 1 addition & 1 deletion modules/module-password/src/resolvers/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLError } from 'graphql';
import { QueryResolvers } from '../models';
import { type QueryResolvers } from '../models';
import { AccountsPassword } from '@accounts/password';

export const Query: QueryResolvers = {
Expand Down
6 changes: 3 additions & 3 deletions modules/module-typeorm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createModule, gql, Provider } from 'graphql-modules';
import { createModule, gql, type Provider } from 'graphql-modules';
import { DatabaseInterfaceSessionsToken, DatabaseInterfaceUserToken } from '@accounts/server';
import {
AccountsTypeorm,
Expand All @@ -10,10 +10,10 @@ import {
UserEmail,
UserSession,
UserService,
AccountsTypeormOptions,
type AccountsTypeormOptions,
AccountsTypeORMConfigToken,
} from '@accounts/typeorm';
import { DatabaseType } from '@accounts/types';
import { type DatabaseType } from '@accounts/types';
import { Connection } from 'typeorm';

export interface AccountsTypeORMModuleConfig extends AccountsTypeormOptions {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"publish:canary": "yarn run publish -- --canary",
"test": "yarn run test:lint && yarn run compile && yarn run coverage",
"testonly": "lerna run testonly",
"fix": "eslint --fix '{packages,modules,examples}/*/{src,__tests__}/**/*.ts'",
"prettier": "prettier --write '**/*.{json,md,js,ts,jsx,tsx,yml}'",
"test:lint": "eslint 'packages/*/{src,__tests__}/**/*.ts'",
"test:examples": "lerna run test --scope=\"@examples/*\"",
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-link-accounts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApolloLink } from '@apollo/client/core';
import { type ApolloLink } from '@apollo/client/core';
import { setContext } from '@apollo/client/link/context';
import { AccountsClient } from '@accounts/client';
import { type AccountsClient } from '@accounts/client';

type AccountsClientFactory = () => AccountsClient | Promise<AccountsClient>;

Expand Down
4 changes: 2 additions & 2 deletions packages/client-magic-link/src/client-magic-link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountsClient } from '@accounts/client';
import { LoginResult, LoginUserMagicLinkService } from '@accounts/types';
import { type AccountsClient } from '@accounts/client';
import { type LoginResult, type LoginUserMagicLinkService } from '@accounts/types';

export class AccountsClientMagicLink {
private client: AccountsClient;
Expand Down
2 changes: 1 addition & 1 deletion packages/client-password/__tests__/client-password.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AccountsClientPassword } from '../src/client-password';
import { LoginResult, CreateUserResult } from '@accounts/types';
import { type LoginResult, type CreateUserResult } from '@accounts/types';

const mockCreateUserResult: CreateUserResult = {
userId: '123',
Expand Down
12 changes: 6 additions & 6 deletions packages/client-password/src/client-password.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AccountsClient } from '@accounts/client';
import { type AccountsClient } from '@accounts/client';
import {
LoginResult,
CreateUserServicePassword,
CreateUserResult,
LoginUserPasswordService,
type LoginResult,
type CreateUserServicePassword,
type CreateUserResult,
type LoginUserPasswordService,
} from '@accounts/types';
import { AccountsClientPasswordOptions } from './types';
import { type AccountsClientPasswordOptions } from './types';

export class AccountsClientPassword {
private client: AccountsClient;
Expand Down
11 changes: 8 additions & 3 deletions packages/client/src/accounts-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { LoginResult, Tokens, ImpersonationResult, User } from '@accounts/types';
import { TransportInterface } from './transport-interface';
import { TokenStorage, AccountsClientOptions } from './types';
import {
type LoginResult,
type Tokens,
type ImpersonationResult,
type User,
} from '@accounts/types';
import { type TransportInterface } from './transport-interface';
import { type TokenStorage, type AccountsClientOptions } from './types';
import { tokenStorageLocal } from './token-storage-local';
import { isTokenExpired } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/token-storage-local.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenStorage } from './types';
import { type TokenStorage } from './types';

export const tokenStorageLocal: TokenStorage = {
setItem(key: string, value: string): void {
Expand Down
14 changes: 7 additions & 7 deletions packages/client/src/transport-interface.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
LoginResult,
ImpersonationUserIdentity,
ImpersonationResult,
CreateUser,
User,
CreateUserResult,
type LoginResult,
type ImpersonationUserIdentity,
type ImpersonationResult,
type CreateUser,
type User,
type CreateUserResult,
} from '@accounts/types';
import { AccountsClient } from './accounts-client';
import { type AccountsClient } from './accounts-client';

export interface TransportInterface {
client: AccountsClient;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenStorage } from '.';
import { type TokenStorage } from '.';

export interface AccountsClientOptions {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/database-mikro-orm/src/entity/Email.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Reference, EntitySchema, ref } from '@mikro-orm/core';
import { IUser, UserCtor } from './User';
import { type Reference, EntitySchema, ref } from '@mikro-orm/core';
import { type IUser, type UserCtor } from './User';

export class Email<CustomUser extends IUser<any, any, any>> {
id!: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/database-mikro-orm/src/entity/Service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Reference, EntitySchema, ref } from '@mikro-orm/core';
import { IUser, UserCtor } from './User';
import { type Reference, EntitySchema, ref } from '@mikro-orm/core';
import { type IUser, type UserCtor } from './User';

export class Service<CustomUser extends IUser<any, any, any>> {
id!: number;
Expand Down
Loading

0 comments on commit 7d51840

Please sign in to comment.