Skip to content

Commit

Permalink
feat: move types to @graasp/sdk/frontend (#203)
Browse files Browse the repository at this point in the history
feat: add `useExportItemChat` hook
chore(hooks): remove git checkout hook performing yarn install
fix(types): improve `useItem` query return type
fix: deprecate exported types, use types from sdk instead
fix(types): in infinite query
fix(types): `useEtherpad` type
fix(types): `useItemThumbnail` hook return type
  • Loading branch information
spaenleh authored Feb 16, 2023
1 parent e3ff175 commit c9be56d
Show file tree
Hide file tree
Showing 85 changed files with 4,278 additions and 3,750 deletions.
48 changes: 34 additions & 14 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"legacyDecorators": true,
"jsx": true
}
},
"extends": [
"airbnb",
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"prettier",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["import", "jsx-a11y", "react", "react-hooks"],
"plugins": [
"import",
"jsx-a11y",
"react",
"react-hooks",
"@typescript-eslint"
],
"ignorePatterns": ["dist"],
"env": {
"browser": true,
Expand All @@ -18,8 +32,21 @@
"cy": true,
"Cypress": true
},
"parser": "@typescript-eslint/parser",
"settings": {
"react": {
"version": "17"
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
}
}
},
"rules": {
"import/export": "off",
"no-underscore-dangle": [
"error",
{
Expand Down Expand Up @@ -66,24 +93,17 @@
"tsx": "never"
}
],
"import/no-unresolved": [2, { "ignore": ["^react$"] }],
"import/no-extraneous-dependencies": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
4 changes: 0 additions & 4 deletions .husky/post-checkout

This file was deleted.

785 changes: 0 additions & 785 deletions .yarn/releases/yarn-3.2.0.cjs

This file was deleted.

873 changes: 873 additions & 0 deletions .yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.2.0.cjs
yarnPath: .yarn/releases/yarn-3.4.1.cjs
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react-dom": "17.0.2",
"react-query": "3.34.16",
"react-scripts": "5.0.0",
"typescript": "4.7.2"
"typescript": "4.9.5"
},
"devDependencies": {
"@babel/plugin-syntax-object-rest-spread": "7.8.3"
Expand Down
55 changes: 30 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"Alexandre Chau"
],
"dependencies": {
"@graasp/sdk": "0.2.0",
"@graasp/translations": "1.1.0",
"@graasp/sdk": "0.4.1",
"@graasp/translations": "1.4.0",
"axios": "0.27.2",
"crypto-js": "4.1.1",
"http-status-codes": "2.2.0",
"immutable": "4.0.0",
"qs": "6.10.3",
"react-query": "3.34.19",
"uuid": "8.3.2"
"immutable": "4.2.4",
"qs": "6.11.0",
"react-query": "3.39.3",
"uuid": "9.0.0"
},
"devDependencies": {
"@babel/core": "7.17.10",
Expand All @@ -48,33 +48,34 @@
"@types/qs": "6.9.7",
"@types/react": "17.0.44",
"@types/react-dom": "17.0.16",
"@types/react-query": "1.2.9",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.22.0",
"@typescript-eslint/parser": "5.22.0",
"@types/uuid": "9.0.0",
"@typescript-eslint/eslint-plugin": "5.51.0",
"@typescript-eslint/parser": "5.51.0",
"babel-jest": "27.5.1",
"env-cmd": "10.1.0",
"eslint": "8.11.0",
"eslint": "8.33.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react": "7.29.4",
"eslint-plugin-react-hooks": "4.3.0",
"husky": "7.0.4",
"eslint-config-prettier": "8.6.0",
"eslint-import-resolver-typescript": "3.5.3",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"husky": "8.0.3",
"jest": "28.1.0",
"jest-environment-jsdom": "28.1.0",
"jest-immutable-matchers": "3.0.0",
"js-cookie": "3.0.1",
"microbundle-crl": "0.13.11",
"mock-socket": "9.1.2",
"nock": "13.2.4",
"prettier": "2.6.0",
"mock-socket": "9.1.5",
"nock": "13.3.0",
"prettier": "2.8.4",
"react-test-renderer": "17.0.2",
"standard-version": "9.3.2",
"standard-version": "9.5.0",
"ts-jest": "28.0.4",
"ts-node": "10.8.0",
"typescript": "4.7.2",
"wait-on": "6.0.1"
"typescript": "4.9.5",
"wait-on": "7.0.1"
},
"peerDependencies": {
"react": "^17.0.0"
Expand All @@ -101,7 +102,9 @@
"deploy": "gh-pages -d example/build",
"release": "standard-version",
"lint": "eslint .",
"post-commit": "git status"
"post-commit": "git status",
"type-check": "tsc --noEmit",
"check": "yarn prettier:check && yarn type-check && yarn lint"
},
"eslintConfig": {
"extends": "react-app"
Expand All @@ -122,8 +125,10 @@
]
},
"resolutions": {
"typescript": "4.9.5",
"rollup-plugin-typescript2": "0.34.1",
"postcss": "7.0.36",
"nth-check": "2.0.1"
},
"packageManager": "yarn@3.2.0"
"packageManager": "yarn@3.4.1"
}
5 changes: 4 additions & 1 deletion src/api/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ActionData, QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';
import { ActionData } from '@graasp/sdk/frontend';

import { QueryClientConfig } from '../types';
import configureAxios from './axios';
import { buildExportActions, buildGetActions } from './routes';

Expand Down
5 changes: 4 additions & 1 deletion src/api/apps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { App, QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';
import { App } from '@graasp/sdk/frontend';

import { QueryClientConfig } from '../types';
import configureAxios, {
fallbackToPublic,
verifyAuthentication,
Expand Down
4 changes: 3 additions & 1 deletion src/api/category.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Category, ItemCategory, QueryClientConfig, UUID } from '../types';
import { Category, ItemCategory, UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, {
fallbackToPublic,
verifyAuthentication,
Expand Down
54 changes: 30 additions & 24 deletions src/api/chat.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import {
ChatMessage,
PartialChatMessage,
PartialNewChatMessage,
QueryClientConfig,
UUID,
} from '../types';
import { ChatMessage, ExportedChatMessage, ItemChat, UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, {
fallbackToPublic,
verifyAuthentication,
} from './axios';
import {
buildClearItemChatRoute,
buildDeleteItemChatMessageRoute,
buildExportItemChatRoute,
buildGetItemChatRoute,
buildGetPublicItemChatRoute,
buildPatchItemChatMessageRoute,
Expand All @@ -20,16 +17,30 @@ import {

const axios = configureAxios();

export const getItemChat = async (id: UUID, { API_HOST }: QueryClientConfig) =>
export const getItemChat = async (
id: UUID,
{ API_HOST }: QueryClientConfig,
): Promise<ItemChat> =>
fallbackToPublic(
() => axios.get(`${API_HOST}/${buildGetItemChatRoute(id)}`),
() => axios.get(`${API_HOST}/${buildGetPublicItemChatRoute(id)}`),
);

export const exportItemChat = async (
id: UUID,
{ API_HOST }: QueryClientConfig,
): Promise<ExportedChatMessage> =>
verifyAuthentication(
(): Promise<ExportedChatMessage> =>
axios
.get(`${API_HOST}/${buildExportItemChatRoute(id)}`)
.then(({ data }) => data),
);

export const postItemChatMessage = async (
{ chatId, body }: PartialNewChatMessage,
{ chatId, body }: Pick<ChatMessage, 'chatId' | 'body'>,
{ API_HOST }: QueryClientConfig,
) =>
): Promise<ChatMessage> =>
verifyAuthentication(
(): Promise<ChatMessage> =>
axios
Expand All @@ -40,38 +51,33 @@ export const postItemChatMessage = async (
);

export const patchItemChatMessage = async (
{ chatId, messageId, body }: PartialChatMessage,
{ chatId, id, body }: Pick<ChatMessage, 'chatId' | 'id' | 'body'>,
{ API_HOST }: QueryClientConfig,
) =>
): Promise<ChatMessage> =>
verifyAuthentication(
(): Promise<ChatMessage> =>
axios
.patch(
`${API_HOST}/${buildPatchItemChatMessageRoute(chatId, messageId)}`,
{
body,
},
)
.patch(`${API_HOST}/${buildPatchItemChatMessageRoute(chatId, id)}`, {
body,
})
.then(({ data }) => data),
);

export const deleteItemChatMessage = async (
{ chatId, messageId }: PartialChatMessage,
{ chatId, id }: Pick<ChatMessage, 'chatId' | 'id'>,
{ API_HOST }: QueryClientConfig,
) =>
): Promise<ChatMessage> =>
verifyAuthentication(
(): Promise<ChatMessage> =>
axios
.delete(
`${API_HOST}/${buildDeleteItemChatMessageRoute(chatId, messageId)}`,
)
.delete(`${API_HOST}/${buildDeleteItemChatMessageRoute(chatId, id)}`)
.then(({ data }) => data),
);

export const clearItemChat = async (
id: UUID,
{ API_HOST }: QueryClientConfig,
) =>
): Promise<void> =>
verifyAuthentication(() =>
axios
.delete(`${API_HOST}/${buildClearItemChatRoute(id)}`)
Expand Down
5 changes: 4 additions & 1 deletion src/api/invitation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Invitation, NewInvitation, QueryClientConfig, UUID } from '../types';
import { Invitation, UUID } from '@graasp/sdk';
import { NewInvitation } from '@graasp/sdk/frontend';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import {
buildDeleteInvitationRoute,
Expand Down
4 changes: 2 additions & 2 deletions src/api/item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Item } from '@graasp/sdk';
import { Item, UUID } from '@graasp/sdk';

import { DEFAULT_THUMBNAIL_SIZES } from '../config/constants';
import { QueryClientConfig, UUID } from '../types';
import { QueryClientConfig } from '../types';
import { getParentsIdsFromPath } from '../utils/item';
import configureAxios, {
fallbackToPublic,
Expand Down
4 changes: 3 additions & 1 deletion src/api/itemExport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { fallbackToPublic } from './axios';
import { buildExportItemRoute, buildExportPublicItemRoute } from './routes';

Expand Down
4 changes: 3 additions & 1 deletion src/api/itemFlag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import { GET_FLAGS_ROUTE, buildPostItemFlagRoute } from './routes';

Expand Down
4 changes: 3 additions & 1 deletion src/api/itemLike.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import {
buildDeleteItemLikeRoute,
Expand Down
4 changes: 3 additions & 1 deletion src/api/itemLogin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import {
buildGetItemLoginRoute,
Expand Down
4 changes: 3 additions & 1 deletion src/api/itemPublish.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import { buildItemPublishRoute } from './routes';

Expand Down
4 changes: 3 additions & 1 deletion src/api/itemTag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { QueryClientConfig, UUID } from '../types';
import { UUID } from '@graasp/sdk';

import { QueryClientConfig } from '../types';
import configureAxios, { verifyAuthentication } from './axios';
import {
GET_TAGS_ROUTE,
Expand Down
Loading

0 comments on commit c9be56d

Please sign in to comment.