Skip to content

Commit

Permalink
enable eslint and fix problems (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev authored Oct 5, 2023
1 parent 99f4b2f commit b104bc4
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 57 deletions.
6 changes: 4 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.eslintrc.js
**/*.json
**/*.json
**/lib-esm/**
tsconfig.json
tsconfig.base.json
40 changes: 40 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
// "plugin:jsdoc/recommended-typescript-error",
"prettier"
],
"parser": "@typescript-eslint/parser",
"root": true,
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": ["./packages/*/tsconfig.json"]
},
"plugins": [
"@typescript-eslint",
// "jsdoc",
"import"
],
"ignorePatterns": ["**/lib-esm/**/*.js", "**/*.d.ts"],
"rules": {
"no-duplicate-imports": "error",
"no-tabs": "error",
"import/no-extraneous-dependencies": "error",
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
}
}
4 changes: 2 additions & 2 deletions .github/actions/node-and-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ inputs:
runs:
using: 'composite'
steps:
- name: Setup Node.js 16
- name: Setup Node.js 18
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 https://github.com/actions/setup-node/commit/64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
with:
node-version: 16
node-version: 18
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/callable-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: workflow_call

jobs:
unit_test:
name: Unit Tests
name: Lint & Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -15,4 +15,4 @@ jobs:
uses: ./amplify-api-next/.github/actions/node-and-build
- name: Run tests
working-directory: ./amplify-api-next
run: npm run test
run: npm run lint && npm run test
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ bin
lib
docs
tsconfig.tsbuildinfo
**/*.js
**/*.json
**/*.js
4 changes: 2 additions & 2 deletions packages/amplify-api-next-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
}
},
"scripts": {
"lint": "eslint \"**/*.ts*\"",
"build": "npm run build:esm",
"build:esm": "npm run clean && tsc -p ./tsconfig.json",
"build:esm:watch": "npm run build:esm --watch",
"clean": "rimraf lib-esm tsconfig.tsbuildinfo",
"test": "echo \"No tests\"",
"clean": "rimraf lib-esm tsconfig.tsbuildinfo"
"lint": "eslint ."
},
"devDependencies": {
"typescript": "^5.1.6"
Expand Down
10 changes: 5 additions & 5 deletions packages/amplify-api-next-types/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export declare const __modelMeta__: unique symbol;
export type ExtractModelMeta<T extends Record<any, any>> =
T[typeof __modelMeta__];

type Prettify<T> = T extends () => {}
type Prettify<T> = T extends () => any
? () => ReturnType<T>
: T extends object
? { [P in keyof T]: Prettify<T[P]> }
Expand Down Expand Up @@ -50,7 +50,7 @@ type MutationInput<
ModelMeta extends Record<any, any>,
Relationships = ModelMeta['relationships'],
> = {
[Prop in keyof Fields as Fields[Prop] extends () => {}
[Prop in keyof Fields as Fields[Prop] extends () => any
? never
: Prop]: Fields[Prop];
} & {
Expand All @@ -60,7 +60,7 @@ type MutationInput<
type ArrElementOrElement<ArrType> =
ArrType extends readonly (infer ElementType)[] ? ElementType : ArrType;

type FlatSchema<T, FlattenArray = true> = T extends () => {}
type FlatSchema<T, FlattenArray = true> = T extends () => any
? FlattenArray extends true
? ArrElementOrElement<Awaited<ReturnType<T>>>
: Awaited<ReturnType<T>>
Expand All @@ -69,7 +69,7 @@ type FlatSchema<T, FlattenArray = true> = T extends () => {}
: T;

type FlattenKeys<
T extends Record<string, unknown> = {},
T extends Record<string, unknown> = Record<string, unknown>,
Key = keyof T,
> = Key extends string
? T[Key] extends Record<string, unknown>
Expand Down Expand Up @@ -101,7 +101,7 @@ export type ModelTypes<
): Promise<T[K]>;
list<SS extends FlattenKeys<Flat[K]>[] = never[]>(options?: {
// TODO: strongly type filter
filter?: {};
filter?: object;
selectionSet?: SS;
}): Promise<Array<Joined<T[K], SS>>>;

Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-api-next-types/src/client/index.v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export type ExtractModelMeta<T extends Record<any, any>> =
T[typeof __modelMeta__];

export type ModelTypes<
T extends Record<any, any> = never,
ModelMeta extends Record<any, any> = any,
_T extends Record<any, any> = never,
_ModelMeta extends Record<any, any> = any,
> = any;
8 changes: 8 additions & 0 deletions packages/amplify-api-next/__tests__/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
// needed for testing
"@typescript-eslint/no-unused-vars": "off",
// needed for @ts-expect-error
"@typescript-eslint/ban-ts-comment": "off"
}
}
2 changes: 1 addition & 1 deletion packages/amplify-api-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build": "npm run clean && tsc -p ./tsconfig.json",
"clean": "rimraf lib-esm tsconfig.tsbuildinfo",
"test": "jest __tests__",
"lint": "eslint \"**/*.ts*\""
"lint": "eslint ."
},
"dependencies": {
"@aws-amplify/amplify-api-next-types-alpha": "*"
Expand Down
19 changes: 6 additions & 13 deletions packages/amplify-api-next/src/Authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ export const Operations = [
] as const;
export type Operation = (typeof Operations)[number];

// type ImpliedFields<Fields extends string> = Record<
// Fields,
// any
// >;

type Shape = Record<string, any>;

export type Authorization<
AuthField extends string | undefined,
AuthFieldPlurality extends boolean,
Expand All @@ -96,9 +89,9 @@ export type Authorization<
};
};

export type OwnerField = {};
export type OwnerField = object;

type BuilderMethods<T extends {}> = {
type BuilderMethods<T extends object> = {
[K in keyof T as T[K] extends (...args: any) => any ? K : never]: T[K];
};

Expand All @@ -109,7 +102,7 @@ type BuilderMethods<T extends {}> = {
* @param without The field to prune.
* @returns The pruned object.
*/
function omit<T extends {}, O extends string>(
function omit<T extends object, O extends string>(
original: T,
without: O,
): Omit<T, O> {
Expand Down Expand Up @@ -173,7 +166,7 @@ function validateProvider(
function authData<
Field extends string | undefined = 'owner',
isMulti extends boolean = false,
Builders extends {} = {},
Builders extends object = object,
>(
defaults: Partial<Authorization<Field, isMulti>[typeof __data]>,
builderMethods: Builders,
Expand Down Expand Up @@ -345,8 +338,8 @@ export type ImpliedAuthField<T extends Authorization<any, any>> =
? isMulti extends true
? { [K in Field]?: string[] }
: { [K in Field]?: string }
: {}
: {};
: object
: object;

/**
* Turns the type from a list of `Authorization` rules like this:
Expand Down
8 changes: 4 additions & 4 deletions packages/amplify-api-next/src/ClientSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type ModelImpliedAuthFields<Schema extends ModelSchema<any>> = {
>
? ImpliedAuthFields<Model['authorization'][number]> &
ImpliedAuthFieldsFromFields<Model>
: {};
: object;
};

type ImpliedAuthFieldsFromFields<T> = UnionToIntersection<
Expand All @@ -132,9 +132,9 @@ type ImpliedAuthFieldsFromFields<T> = UnionToIntersection<
| ModelRelationalField<any, any, any, infer Auth>
? Auth extends Authorization<any, any>
? ImpliedAuthFields<Auth>
: {}
: {}
: {}
: object
: object
: object
>;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-api-next/src/ModelField.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Authorization, __data } from './Authorization';
import { Authorization } from './Authorization';

/**
* Used to "attach" auth types to ModelField without exposing them on the builder.
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-api-next/src/ModelType.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ModelField, InternalField, fields } from './ModelField';
import { ModelField, InternalField } from './ModelField';
import type {
ModelRelationalField,
InternalRelationalField,
} from './ModelRelationalField';
import { Authorization, ImpliedAuthFields } from './Authorization';
import { Authorization } from './Authorization';
import type { SetTypeSubArg } from './util';

type ModelFields = Record<
Expand Down
19 changes: 3 additions & 16 deletions packages/amplify-api-next/src/SchemaProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type {
ModelSchema,
ModelSchemaType,
InternalSchema,
ModelSchemaParamShape,
} from './ModelSchema';
import type { ModelField, InternalField } from './ModelField';
import type { InternalSchema } from './ModelSchema';
import { type ModelField, type InternalField, fields } from './ModelField';
import type { InternalRelationalField } from './ModelRelationalField';
import type { ModelType, InternalModel } from './ModelType';
import { fields } from './ModelField';
import { Authorization, __data } from './Authorization';
import { DerivedApiDefinition } from './types';

Expand Down Expand Up @@ -85,14 +79,7 @@ function scalarFieldToGql(fieldDef: ScalarFieldDef, identifier?: string[]) {
}

function modelFieldToGql(fieldDef: ModelFieldDef) {
const {
type,
relatedModel,
array,
valueOptional,
arrayOptional,
connectionName,
} = fieldDef;
const { type, relatedModel, array, connectionName } = fieldDef;

let field = relatedModel;

Expand Down
10 changes: 7 additions & 3 deletions packages/amplify-api-next/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type SetTypeSubArg<T, SetKey extends keyof T, Val> = {
[Property in keyof T]: SetKey extends Property ? Val : T[Property];
};

export type Prettify<T> = T extends () => {}
export type Prettify<T> = T extends () => any
? () => ReturnType<T>
: T extends object
? { [P in keyof T]: Prettify<T[P]> }
Expand Down Expand Up @@ -44,7 +44,11 @@ export type UnionToIntersection<U> = (
* @example
* ExcludeEmpty<{a: 1} | {} | {b: 2}> => {a: 1} | {b: 2}
*/
export type ExcludeEmpty<U> = U extends U ? ({} extends U ? never : U) : never;
export type ExcludeEmpty<U> = U extends U
? object extends U
? never
: U
: never;

export type Expect<T extends true> = T;
export type ExpectTrue<T extends true> = T;
Expand All @@ -63,6 +67,6 @@ export type NotAny<T> = true extends IsAny<T> ? false : true;

export type Debug<T> = { [K in keyof T]: T[K] };

export type ObjectIsNonEmpty<T extends {}> = keyof T extends never
export type ObjectIsNonEmpty<T extends object> = keyof T extends never
? false
: true;

0 comments on commit b104bc4

Please sign in to comment.