diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2d12f67..4cd73cec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,8 +12,6 @@ jobs: - name: set up node uses: actions/setup-node@v4 - with: - node-version: 18.15 - name: Yarn Install and Cache uses: graasp/graasp-deploy/.github/actions/yarn-install-and-cache@v1 diff --git a/package.json b/package.json index 914ff020..c691d435 100644 --- a/package.json +++ b/package.json @@ -18,26 +18,16 @@ }, "exports": { ".": "./dist/index.js", - "./frontend": "./dist/frontend/index.js", "./package.json": "./package.json" }, - "typesVersions": { - "*": { - "frontend": [ - "dist/frontend/index.d.ts" - ] - } - }, "files": [ "dist" ], "dependencies": { "@aws-sdk/client-s3": "3.427.0", - "@fastify/secure-session": "6.1.0", "@graasp/etherpad-api": "2.1.1", "date-fns": "2.30.0", - "fastify": "4.18.0", - "immutable": "4.3.4", + "fastify": "4.24.3", "js-cookie": "3.0.5", "uuid": "9.0.1", "validator": "13.11.0" @@ -62,7 +52,7 @@ "@commitlint/config-conventional": "18.1.0", "@trivago/prettier-plugin-sort-imports": "4.2.1", "@types/eslint": "8.44.6", - "@types/jest": "29.5.6", + "@types/jest": "29.5.7", "@types/js-cookie": "3.0.5", "@types/jsdom": "21.1.4", "@types/uuid": "9.0.6", diff --git a/src/frontend/index.ts b/src/frontend/index.ts deleted file mode 100644 index 769f202c..00000000 --- a/src/frontend/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './types'; -export * from './ui'; -export * from './ws-client'; diff --git a/src/frontend/types.ts b/src/frontend/types.ts deleted file mode 100644 index 75c4433f..00000000 --- a/src/frontend/types.ts +++ /dev/null @@ -1,155 +0,0 @@ -import type { List, RecordOf } from 'immutable'; - -import type { - Action, - ActionData, - App, - AppAction, - AppData, - AppItemType, - AppSetting, - Category, - CategoryType, - ChatMention, - ChatMessage, - DiscriminatedItem, - DocumentItemType, - EmbeddedLinkItemType, - Etherpad, - EtherpadItemType, - ExportedChatMessage, - ExportedItemChat, - FolderItemType, - H5PItemType, - Invitation, - ItemCategory, - ItemFavorite, - ItemFlag, - ItemLike, - ItemLogin, - ItemLoginSchema, - ItemMembership, - ItemPublished, - ItemTag, - ItemValidationGroup, - ItemValidationReview, - LocalFileItemType, - MeiliSearchResults, - Member, - MemberExtra, - MemberStorage, - RecycledItemData, - S3FileItemType, - ShortcutItemType, -} from '@/index'; -import type { ResultOf } from '@/types'; - -/** - * Convenience type to convert nested objects to deeply immutable objects - */ -export type ImmutableCast = Type extends (infer U)[] - ? List> - : // eslint-disable-next-line @typescript-eslint/no-unused-vars - Type extends RecordOf | List | Date // add any type that you do not want to change - ? Type - : Type extends object - ? RecordOf<{ - [Property in keyof Type]: ImmutableCast; - }> - : Type; - -export type AppItemTypeRecord = ImmutableCast; -export type DocumentItemTypeRecord = ImmutableCast; -export type FolderItemTypeRecord = ImmutableCast; -export type H5PItemTypeRecord = ImmutableCast; -export type EmbeddedLinkItemTypeRecord = ImmutableCast; -export type LocalFileItemTypeRecord = ImmutableCast; -export type S3FileItemTypeRecord = ImmutableCast; -export type ShortcutItemTypeRecord = ImmutableCast; -export type EtherpadItemTypeRecord = ImmutableCast; - -export type ItemRecord = ImmutableCast; - -export type EtherpadRecord = ImmutableCast; - -export type MemberExtraRecord = ImmutableCast; - -export type MemberRecord = ImmutableCast; - -export type ItemMembershipRecord = ImmutableCast; - -export type ChatMentionRecord = ImmutableCast; - -/** - * A `CategoryRecord` represents a sort of "tag" for an item. For example: "Math", "Kindergarten" etc ... - */ -export type CategoryRecord = ImmutableCast; - -/** - * A `CategoryTypeRecord` represents a higher order grouping of `CategoryRecord`s like "discipline", "education level" or "language" - */ -export type CategoryTypeRecord = ImmutableCast; - -export type ChatMessageRecord = ImmutableCast; - -export type ItemChatRecord = ImmutableCast; - -export type ItemTagRecord = ImmutableCast; - -export type ItemFlagRecord = ImmutableCast; - -export type InvitationRecord = ImmutableCast; - -export type ItemCategoryRecord = ImmutableCast; - -export type ItemLoginRecord = ImmutableCast; - -export type ItemLoginSchemaRecord = ImmutableCast; - -export type ExportedChatMessageRecord = ImmutableCast; - -export type ExportedItemChatRecord = ImmutableCast; - -// a combined record from item-validation, item-validation-review, item-validation-process -export type FullValidation = { - id: string; - itemId: string; - reviewStatusId: string; - validationStatusId: string; - validationResult: string; - process: string; - createdAt: Date; -}; - -export type FullValidationRecord = ImmutableCast; - -export type ItemValidationAndReviewRecord = ImmutableCast; - -export type ItemValidationGroupRecord = ImmutableCast; - -export type ActionRecord = ImmutableCast; - -export type ActionDataRecord = ImmutableCast; - -export type Password = string; -export type NewInvitation = Pick & - Partial; - -export type ItemFavoriteRecord = ImmutableCast; - -export type ItemLikeRecord = ImmutableCast; - -export type AppRecord = ImmutableCast; -export type AppDataRecord = ImmutableCast; -export type AppActionRecord = ImmutableCast; -export type AppSettingRecord = ImmutableCast; - -export type ResultOfRecord = ImmutableCast>; - -export type ItemPublishedRecord = ImmutableCast; - -export type RecycledItemDataRecord = ImmutableCast; - -export type MeiliSearchResultsRecord = ImmutableCast; - -export type MemberStorageRecord = ImmutableCast; diff --git a/src/frontend/ui.ts b/src/frontend/ui.ts deleted file mode 100644 index 3fb45059..00000000 --- a/src/frontend/ui.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { ThumbnailSize } from '@/constants/ui'; - -export type ThumbnailSizeVariant = - `${(typeof ThumbnailSize)[keyof typeof ThumbnailSize]}`; diff --git a/src/services/action/interfaces.ts b/src/services/action/interfaces.ts index cb585d7d..c5d4e9e6 100644 --- a/src/services/action/interfaces.ts +++ b/src/services/action/interfaces.ts @@ -10,7 +10,7 @@ export interface Action { extra: { [key: string]: unknown }; // TODO: cannot import geoip geolocation?: unknown; - createdAt: Date; + createdAt: string; } export interface ActionData { diff --git a/src/services/app/interfaces/app.ts b/src/services/app/interfaces/app.ts index 6eec3ad1..1feb3e6f 100644 --- a/src/services/app/interfaces/app.ts +++ b/src/services/app/interfaces/app.ts @@ -13,6 +13,6 @@ export interface App { url: string; extra: AppExtra; publisher: Publisher; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } diff --git a/src/services/app/interfaces/appAction.ts b/src/services/app/interfaces/appAction.ts index 0f73249d..5da3d483 100644 --- a/src/services/app/interfaces/appAction.ts +++ b/src/services/app/interfaces/appAction.ts @@ -6,5 +6,5 @@ export type AppAction = { member: Member; type: string; data: object; - createdAt: Date; + createdAt: string; }; diff --git a/src/services/app/interfaces/appData.ts b/src/services/app/interfaces/appData.ts index 66f93363..741d8bb5 100644 --- a/src/services/app/interfaces/appData.ts +++ b/src/services/app/interfaces/appData.ts @@ -15,6 +15,6 @@ export type AppData = { type: string; visibility: `${AppDataVisibility}` | AppDataVisibility; data: T; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; diff --git a/src/services/app/interfaces/appSetting.ts b/src/services/app/interfaces/appSetting.ts index 0bf96bee..fc4fbc9e 100644 --- a/src/services/app/interfaces/appSetting.ts +++ b/src/services/app/interfaces/appSetting.ts @@ -8,6 +8,6 @@ export type AppSetting = { creator?: Member | null; name: string; data: T; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; diff --git a/src/services/app/interfaces/publisher.ts b/src/services/app/interfaces/publisher.ts index 9f15913b..a2fdc532 100644 --- a/src/services/app/interfaces/publisher.ts +++ b/src/services/app/interfaces/publisher.ts @@ -4,6 +4,6 @@ export interface Publisher { id: UUID; name: string; origins: string[]; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } diff --git a/src/services/categories/types.ts b/src/services/categories/types.ts index 0abe8308..f63cd5b2 100644 --- a/src/services/categories/types.ts +++ b/src/services/categories/types.ts @@ -23,6 +23,6 @@ export type ItemCategory = { id: UUID; item: DiscriminatedItem; category: Category; - createdAt: Date; + createdAt: string; creator: Member; }; diff --git a/src/services/chat/types.ts b/src/services/chat/types.ts index c47cb96a..53b877d5 100644 --- a/src/services/chat/types.ts +++ b/src/services/chat/types.ts @@ -8,19 +8,11 @@ export type ChatMessage = { id: UUID; item: DiscriminatedItem; creator: Member | null; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; body: string; }; -/** - * All messages linked to an item - */ -export type ItemChat = { - id: UUID; - messages: ChatMessage[]; -}; - // type of the exported chat message // contains the additional "creatorName" key with the plain text name of the user export type ExportedChatMessage = { @@ -28,16 +20,11 @@ export type ExportedChatMessage = { chatId: UUID; creator: Member | null; creatorName: string; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; body: string; }; -export type ExportedItemChat = { - id: UUID; - messages: ExportedChatMessage[]; -}; - /** * Type of the "body" prop when sending a new message */ @@ -66,8 +53,8 @@ export type ChatMention = { id: UUID; message: ChatMessage; member: Member; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; status: MentionStatus; }; diff --git a/src/services/etherpad/interfaces/service.ts b/src/services/etherpad/interfaces/service.ts index 1cc111d8..5b3a7694 100644 --- a/src/services/etherpad/interfaces/service.ts +++ b/src/services/etherpad/interfaces/service.ts @@ -9,7 +9,7 @@ export type EtherpadCookie = { options: { domain: string; path: string; - expires: Date; + expires: string; signed: boolean; httpOnly: boolean; }; diff --git a/src/services/flag/types.ts b/src/services/flag/types.ts index bf9547f9..83384a6e 100644 --- a/src/services/flag/types.ts +++ b/src/services/flag/types.ts @@ -6,7 +6,7 @@ export type ItemFlag = { type: `${FlagType}` | FlagType; item: DiscriminatedItem; creator: Member; - createdAt: Date; + createdAt: string; }; export enum FlagType { diff --git a/src/services/invitation/types.ts b/src/services/invitation/types.ts index 020df2ab..8a956bdb 100644 --- a/src/services/invitation/types.ts +++ b/src/services/invitation/types.ts @@ -8,6 +8,6 @@ export type Invitation = { name?: string; creator?: Member | null; item: DiscriminatedItem; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; diff --git a/src/services/item-favorite/types.ts b/src/services/item-favorite/types.ts index bb10f077..0eaeae54 100644 --- a/src/services/item-favorite/types.ts +++ b/src/services/item-favorite/types.ts @@ -4,5 +4,5 @@ import { UUID } from '@/types'; export type ItemFavorite = { id: UUID; item: DiscriminatedItem; - createdAt: Date; + createdAt: string; }; diff --git a/src/services/item-like/types.ts b/src/services/item-like/types.ts index e1074bed..a45c4e27 100644 --- a/src/services/item-like/types.ts +++ b/src/services/item-like/types.ts @@ -4,5 +4,5 @@ import { UUID } from '@/types'; export type ItemLike = { id: UUID; item: DiscriminatedItem; - createdAt: Date; + createdAt: string; }; diff --git a/src/services/item-login/types.ts b/src/services/item-login/types.ts index 6172f3a9..dd1e92b9 100644 --- a/src/services/item-login/types.ts +++ b/src/services/item-login/types.ts @@ -5,8 +5,8 @@ export interface ItemLoginSchema { id: UUID; item: DiscriminatedItem; type: `${ItemLoginSchemaType}` | ItemLoginSchemaType; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } export type ItemLogin = { @@ -14,6 +14,6 @@ export type ItemLogin = { member: Member; itemLoginSchema: ItemLoginSchema; password?: string; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; diff --git a/src/services/item-memberships/interfaces/item-membership.ts b/src/services/item-memberships/interfaces/item-membership.ts index a545d28c..68d32a17 100644 --- a/src/services/item-memberships/interfaces/item-membership.ts +++ b/src/services/item-memberships/interfaces/item-membership.ts @@ -7,6 +7,6 @@ export interface ItemMembership { item: DiscriminatedItem; permission: PermissionLevel; creator?: Member | null; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } diff --git a/src/services/item-published/types.ts b/src/services/item-published/types.ts index 276ebdc7..8f3eeb05 100644 --- a/src/services/item-published/types.ts +++ b/src/services/item-published/types.ts @@ -4,7 +4,7 @@ import { UUID } from '@/types'; export interface ItemPublished { id: UUID; creator?: Member; - createdAt: Date; + createdAt: string; item: DiscriminatedItem; totalViews: number; } diff --git a/src/services/item-recycled/types.ts b/src/services/item-recycled/types.ts index e7604c1c..5d4b298e 100644 --- a/src/services/item-recycled/types.ts +++ b/src/services/item-recycled/types.ts @@ -3,6 +3,6 @@ import { DiscriminatedItem, Member } from '../index'; export type RecycledItemData = { id: string; creator: Member; - createdAt: Date; + createdAt: string; item: DiscriminatedItem; }; diff --git a/src/services/item-tags/types.ts b/src/services/item-tags/types.ts index 2834ec6a..eef6c775 100644 --- a/src/services/item-tags/types.ts +++ b/src/services/item-tags/types.ts @@ -10,6 +10,6 @@ export type ItemTag = { id: UUID; item: DiscriminatedItem; type: `${ItemTagType}` | ItemTagType; - createdAt: Date; + createdAt: string; creator: Member; }; diff --git a/src/services/item-validation/types.ts b/src/services/item-validation/types.ts index 60d1da2a..b4a45457 100644 --- a/src/services/item-validation/types.ts +++ b/src/services/item-validation/types.ts @@ -26,14 +26,14 @@ export interface ItemValidation { status: `${ItemValidationStatus}` | ItemValidationStatus; result: string; itemValidationGroup: ItemValidationGroup; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } export interface ItemValidationGroup { id: string; item: DiscriminatedItem; - createdAt: Date; + createdAt: string; itemValidations: ItemValidation[]; } @@ -43,6 +43,6 @@ export interface ItemValidationReview { reviewer: Member | null; status: `${ItemValidationReviewStatus}` | ItemValidationReviewStatus; reason: string; - updatedAt: Date; - createdAt: Date; + updatedAt: string; + createdAt: string; } diff --git a/src/services/items/interfaces/item.ts b/src/services/items/interfaces/item.ts index ca7d4bb4..1021654a 100644 --- a/src/services/items/interfaces/item.ts +++ b/src/services/items/interfaces/item.ts @@ -20,8 +20,8 @@ export interface Item { path: string; settings: S; creator: Member | null; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; } export type AppItemType = { diff --git a/src/services/members/index.ts b/src/services/members/index.ts index 2c586449..2a110670 100644 --- a/src/services/members/index.ts +++ b/src/services/members/index.ts @@ -1,2 +1,3 @@ export * from './interfaces/member'; export * from './interfaces/storage'; +export * from './interfaces/password'; diff --git a/src/services/members/interfaces/member.ts b/src/services/members/interfaces/member.ts index 61804a8e..5f5fa7fc 100644 --- a/src/services/members/interfaces/member.ts +++ b/src/services/members/interfaces/member.ts @@ -22,6 +22,6 @@ export type Member = { export type CompleteMember = Member & { type: `${MemberType}` | MemberType; extra: MemberExtra; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; diff --git a/src/services/members/interfaces/password.ts b/src/services/members/interfaces/password.ts new file mode 100644 index 00000000..6da04253 --- /dev/null +++ b/src/services/members/interfaces/password.ts @@ -0,0 +1 @@ +export type Password = string; diff --git a/src/services/search/types.ts b/src/services/search/types.ts index 534a1f6b..88ca54cd 100644 --- a/src/services/search/types.ts +++ b/src/services/search/types.ts @@ -13,8 +13,8 @@ export type IndexItem = { content: string; isPublishedRoot: boolean; isHidden: boolean; - createdAt: Date; - updatedAt: Date; + createdAt: string; + updatedAt: string; }; export type IndexMember = { diff --git a/src/services/websockets/index.ts b/src/services/websockets/index.ts index 18645f6d..f9021fdc 100644 --- a/src/services/websockets/index.ts +++ b/src/services/websockets/index.ts @@ -3,6 +3,7 @@ import * as Errors from './errors'; import * as Requests from './interfaces/request'; export * from './interfaces/service'; +export * from './ws-client'; /** * Re-export types and utility classes within the Websocket namespace diff --git a/src/frontend/ws-client.ts b/src/services/websockets/ws-client.ts similarity index 100% rename from src/frontend/ws-client.ts rename to src/services/websockets/ws-client.ts diff --git a/src/utils/date.test.ts b/src/utils/date.test.ts index 5a946121..5dbe2eb4 100644 --- a/src/utils/date.test.ts +++ b/src/utils/date.test.ts @@ -3,12 +3,12 @@ import { formatDate, parseStringToDate } from './date'; describe('Date utils', () => { describe('formatDate', () => { it('format date to readable string', () => { - const result = formatDate(new Date('2021-03-16T16:00:50.968Z'), { + const result = formatDate('2021-03-16T16:00:50.968Z', { locale: 'en', }); // test contain without hour because it can be differnt in CI expect(result).toContain('Mar 16, 2021'); - const resultFr = formatDate(new Date('2021-03-16T16:00:50.968Z'), { + const resultFr = formatDate('2021-03-16T16:00:50.968Z', { locale: 'fr', }); // test contain without hour because it can be differnt in CI @@ -16,9 +16,11 @@ describe('Date utils', () => { }); it('format date to relative date', () => { - const result = formatDate(new Date(), { locale: 'en' }); + const result = formatDate(new Date().toISOString(), { locale: 'en' }); expect(result).toEqual('now'); - const resultFr = formatDate(new Date(), { locale: 'fr' }); + const resultFr = formatDate(new Date().toISOString(), { + locale: 'fr', + }); expect(resultFr).toEqual('maintenant'); }); @@ -28,12 +30,12 @@ describe('Date utils', () => { }); expect(result).toEqual('Unknown'); - const resultMalformattedDate = formatDate(new Date('some date'), { + const resultMalformattedDate = formatDate('some date', { locale: 'fr', }); expect(resultMalformattedDate).toEqual('Unknown'); - const resultCustomDefault = formatDate(new Date('some date'), { + const resultCustomDefault = formatDate('some date', { locale: 'fr', defaultValue: 'Default Date', }); diff --git a/src/utils/date.ts b/src/utils/date.ts index 10e72f9c..fef9d38b 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -31,7 +31,7 @@ const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/; export const formatDate = ( - datetime: Date | undefined, + datetime: string | undefined, args: { locale: string; defaultValue?: string }, ): string => { const { locale, defaultValue = 'Unknown' } = args; @@ -40,15 +40,15 @@ export const formatDate = ( } try { const now = new Date(); - + const date = new Date(datetime); // return human readable date if less than a month ago - if (differenceInDays(now, datetime) < 7) { - return intlFormatDistance(datetime, now, { locale }); + if (differenceInDays(now, date) < 7) { + return intlFormatDistance(date, now, { locale }); } // compute best intl date return intlFormat( - datetime, + date, { year: 'numeric', month: 'short', @@ -67,6 +67,10 @@ export const formatDate = ( const isIsoDateString = (value: string): value is TDateISO => Boolean(value && isoDateFormat.test(value)); +/** + * + * @deprecated we should not use this function anymore + */ export const parseStringToDate = (data: any): any => { if (!data) { return data; diff --git a/src/utils/extra.ts b/src/utils/extra.ts index f443ef10..0d1d2f45 100644 --- a/src/utils/extra.ts +++ b/src/utils/extra.ts @@ -15,59 +15,40 @@ import { LocalFileItemExtra, S3FileItemExtra, } from '../services'; -import { ImmutableCast } from '@/frontend/types'; -export const getFileExtra = < - U extends LocalFileItemExtra | ImmutableCast, ->( +export const getFileExtra = ( extra: U, ): U[typeof ItemType.LOCAL_FILE] => extra[ItemType.LOCAL_FILE]; -export const getFolderExtra = < - U extends FolderItemExtra | ImmutableCast, ->( +export const getFolderExtra = ( extra: U, ): U[typeof ItemType.FOLDER] => extra[ItemType.FOLDER]; -export const getShortcutExtra = < - U extends ShortcutItemExtra | ImmutableCast, ->( +export const getShortcutExtra = ( extra: U, ): U[typeof ItemType.SHORTCUT] => extra[ItemType.SHORTCUT]; -export const getEtherpadExtra = < - U extends EtherpadItemExtra | ImmutableCast, ->( +export const getEtherpadExtra = ( extra: U, ): U[typeof ItemType.ETHERPAD] => extra[ItemType.ETHERPAD]; -export const getS3FileExtra = < - U extends S3FileItemExtra | ImmutableCast, ->( +export const getS3FileExtra = ( extra: U, ): U[typeof ItemType.S3_FILE] => extra[ItemType.S3_FILE]; -export const getEmbeddedLinkExtra = < - U extends EmbeddedLinkItemExtra | ImmutableCast, ->( +export const getEmbeddedLinkExtra = ( extra: U, ): U[typeof ItemType.LINK] => extra[ItemType.LINK]; -export const getDocumentExtra = < - U extends DocumentItemExtra | ImmutableCast, ->( +export const getDocumentExtra = ( extra: U, ): U[typeof ItemType.DOCUMENT] => extra[ItemType.DOCUMENT]; -export const getAppExtra = < - U extends AppItemExtra | ImmutableCast, ->( +export const getAppExtra = ( extra: U, ): U[typeof ItemType.APP] => extra[ItemType.APP]; -export const getH5PExtra = < - U extends H5PItemExtra | ImmutableCast, ->( +export const getH5PExtra = ( extra: U, ): U[typeof ItemType.H5P] => extra[ItemType.H5P]; diff --git a/src/utils/immutable.test.ts b/src/utils/immutable.test.ts deleted file mode 100644 index 95f35f27..00000000 --- a/src/utils/immutable.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { convertJs } from './immutable'; - -describe('Immutable', () => { - describe('convertJS', () => { - it('Raw', () => { - const res1 = convertJs(undefined); - expect(res1).toBe(undefined); - const res2 = convertJs(null); - expect(res2).toBe(null); - const res3 = convertJs(1); - expect(res3).toBe(1); - const res4 = convertJs(false); - expect(res4).toBe(false); - const res5 = convertJs('string'); - expect(res5).toEqual('string'); - }); - - it('Objects', () => { - const val1 = { a: 'd', b: false }; - const res1 = convertJs(val1); - expect(res1.toJS()).toEqual(val1); - - // test deep conversion - const val2 = { a: 'd', b: false, c: { d: 'd', e: { f: true } } }; - const res2 = convertJs(val2); - expect(res2.toJS()).toEqual(val2); - expect(res2.c.toJS()).toEqual(val2.c); - expect(res2.toJS()).toEqual(val2); - expect(res2.c.e.toJS()).toEqual(val2.c.e); - - // test deep conversion with arrays - const val3 = { - a: 'd', - b: false, - c: [{ d: 'd', e: { f: true } }, { g: 'g' }], - }; - const res3 = convertJs(val3); - expect(res3.toJS()).toEqual(val3); - expect(res3.c.size).toEqual(2); - expect(res3.c.toJS()).toEqual(val3.c); - expect(res3.c.get(0).toJS()).toEqual(val3.c[0]); - }); - - it('Arrays', () => { - const val1 = [1, 2, 3, 4]; - const res1 = convertJs(val1); - expect(res1.toJS()).toEqual(val1); - expect(res1.get(0)).toEqual(val1[0]); - expect(res1.get(2)).toEqual(val1[2]); - - const val2 = [ - { a: 'd', b: false }, - { a: 'de', b: true }, - ]; - const res2 = convertJs(val2); - expect(res2.toJS()).toEqual(val2); - expect(res2.get(0).toJS()).toEqual(val2[0]); - expect(res2.get(1).toJS()).toEqual(val2[1]); - - const val3 = [ - { a: 'd', b: false }, - { d: 'd', e: { f: true } }, - ]; - const res3 = convertJs(val3); - expect(res3.toJS()).toEqual(val3); - expect(res3.get(0).toJS()).toEqual(val3[0]); - expect(res3.get(1).toJS()).toEqual(val3[1]); - expect(res3.get(1).e.toJS()).toEqual(val3[1].e); - }); - - it('Dates', () => { - const val1 = new Date(); - const res1 = convertJs(val1); - expect(res1).toEqual(val1); - - const val2 = [ - { a: 'd', b: new Date() }, - { a: 'de', b: true }, - ]; - const res2 = convertJs(val2); - expect(res2.toJS()).toEqual(val2); - expect(res2.get(0).toJS()).toEqual(val2[0]); - expect(res2.get(1).toJS()).toEqual(val2[1]); - }); - }); -}); diff --git a/src/utils/immutable.ts b/src/utils/immutable.ts deleted file mode 100644 index 75e9668d..00000000 --- a/src/utils/immutable.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Record, Seq } from 'immutable'; - -export function convertJs(data: T) { - if (typeof data !== 'object' || data === null) { - return data; - } - - if (Array.isArray(data) || data instanceof Map) { - return Seq(data).map(convertJs).toList(); - } - - if (data instanceof Date) { - return data; - } - - if (typeof data === 'object') { - const Factory = Record(data as unknown as object); - - return new Factory(Seq(data).map(convertJs)); - } - - throw new Error(`data type '${typeof data}' is not valid`); -} diff --git a/src/utils/index.ts b/src/utils/index.ts index ea10baa3..ddb5b3f4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -3,7 +3,6 @@ export * from './cookie'; export * from './date'; export * from './error'; export * from './extra'; -export * from './immutable'; export * from './item'; export * from './member'; export * from './navigation'; diff --git a/yarn.lock b/yarn.lock index ea6aabec..9bd73b72 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1487,16 +1487,6 @@ __metadata: languageName: node linkType: hard -"@fastify/cookie@npm:^8.0.0": - version: 8.3.0 - resolution: "@fastify/cookie@npm:8.3.0" - dependencies: - cookie: "npm:^0.5.0" - fastify-plugin: "npm:^4.0.0" - checksum: bfb637113a76e14bb2efda674183937897df0122c8033d2b8654cdf7e60de947ef13c72f3a0f4b2c56cdb4cf2e1a4f4a4d277eff3b05389320e05623e675e4a3 - languageName: node - linkType: hard - "@fastify/deepmerge@npm:^1.0.0": version: 1.3.0 resolution: "@fastify/deepmerge@npm:1.3.0" @@ -1504,10 +1494,10 @@ __metadata: languageName: node linkType: hard -"@fastify/error@npm:^3.2.0": - version: 3.2.1 - resolution: "@fastify/error@npm:3.2.1" - checksum: d6626cbefa9caf42cda5347323031a5bb5e8ca9a2952f99d44e395f8e85f18a16593c60dcf0788cb936902f29e93c702c3999b29daa23ad3b25e2d04fb3cb5ea +"@fastify/error@npm:^3.4.0": + version: 3.4.0 + resolution: "@fastify/error@npm:3.4.0" + checksum: 548216c10662a4c2f210c7c40f98195c530b646cf8d27ea35d18c0d513fe2f33b2ba2611a61619a1ec3163e8c0fefca05a671bc87a355df30476fee224bda3b3 languageName: node linkType: hard @@ -1520,19 +1510,6 @@ __metadata: languageName: node linkType: hard -"@fastify/secure-session@npm:6.1.0": - version: 6.1.0 - resolution: "@fastify/secure-session@npm:6.1.0" - dependencies: - "@fastify/cookie": "npm:^8.0.0" - fastify-plugin: "npm:^4.0.0" - sodium-native: "npm:^4.0.0" - bin: - secure-session: genkey.js - checksum: a3ecafae6559454ca01743a4280102017313097504f6025a741b231b9f2c22f001ec449123b52af8aa3a4dd2fd8ccb3f56a400f06fe823395df440a7fa7379f6 - languageName: node - linkType: hard - "@gar/promisify@npm:^1.0.1": version: 1.1.2 resolution: "@gar/promisify@npm:1.1.2" @@ -1560,11 +1537,10 @@ __metadata: "@aws-sdk/client-s3": "npm:3.427.0" "@commitlint/cli": "npm:18.2.0" "@commitlint/config-conventional": "npm:18.1.0" - "@fastify/secure-session": "npm:6.1.0" "@graasp/etherpad-api": "npm:2.1.1" "@trivago/prettier-plugin-sort-imports": "npm:4.2.1" "@types/eslint": "npm:8.44.6" - "@types/jest": "npm:29.5.6" + "@types/jest": "npm:29.5.7" "@types/js-cookie": "npm:3.0.5" "@types/jsdom": "npm:21.1.4" "@types/uuid": "npm:9.0.6" @@ -1574,9 +1550,8 @@ __metadata: date-fns: "npm:2.30.0" eslint: "npm:8.52.0" eslint-config-prettier: "npm:9.0.0" - fastify: "npm:4.18.0" + fastify: "npm:4.24.3" husky: "npm:8.0.3" - immutable: "npm:4.3.4" jest: "npm:29.7.0" js-cookie: "npm:3.0.5" jsdom: "npm:19.0.0" @@ -2833,13 +2808,13 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:29.5.6": - version: 29.5.6 - resolution: "@types/jest@npm:29.5.6" +"@types/jest@npm:29.5.7": + version: 29.5.7 + resolution: "@types/jest@npm:29.5.7" dependencies: expect: "npm:^29.0.0" pretty-format: "npm:^29.0.0" - checksum: 316463d2755677c42db5b6d5189794b8bbcf281c79f60cc936b5daa049cb2dc6339a6e343941b3c995ef29778c1c84b2a4f32f10a119ece418c47a3febfb2051 + checksum: 231c873f3d1ddac973b8f8f2ad7760677d941d85fb52d1c5dc4a311bafba4c2c1658a1040fd7054a51f4d1841f51c6ca4cabf70675ee4fa9e10fc5b8066e1de1 languageName: node linkType: hard @@ -4569,10 +4544,10 @@ __metadata: languageName: node linkType: hard -"fast-content-type-parse@npm:^1.0.0": - version: 1.0.0 - resolution: "fast-content-type-parse@npm:1.0.0" - checksum: 4267249a0d4b26de4c39eb41cfc891bd9f295008e42cc7368129a74ff8b316adc0b4999bb5cd8ee7569031663832edf77c2298bf3ab275bda093ee207bfa3a99 +"fast-content-type-parse@npm:^1.1.0": + version: 1.1.0 + resolution: "fast-content-type-parse@npm:1.1.0" + checksum: 882bf990fa5d64be1825ce183818db43900ece0d7ef184cb9409bae8ed1001acbe536a657b1496382cb3e308e71ab39cc399bbdae70cba1745eecaeca4e55384 languageName: node linkType: hard @@ -4624,6 +4599,21 @@ __metadata: languageName: node linkType: hard +"fast-json-stringify@npm:^5.8.0": + version: 5.9.0 + resolution: "fast-json-stringify@npm:5.9.0" + dependencies: + "@fastify/deepmerge": "npm:^1.0.0" + ajv: "npm:^8.10.0" + ajv-formats: "npm:^2.1.1" + fast-deep-equal: "npm:^3.1.3" + fast-uri: "npm:^2.1.0" + json-schema-ref-resolver: "npm:^1.0.1" + rfdc: "npm:^1.2.0" + checksum: 25f41158e15c7b49cf62ac9020a33baeb0bad4d6146c8fbdf693272f657fb858c18b8aac5836e595d6eafe6ab1f6e0fa08278c9668af9e4bcc689b25afb8862f + languageName: node + linkType: hard + "fast-levenshtein@npm:^2.0.6, fast-levenshtein@npm:~2.0.6": version: 2.0.6 resolution: "fast-levenshtein@npm:2.0.6" @@ -4665,34 +4655,27 @@ __metadata: languageName: node linkType: hard -"fastify-plugin@npm:^4.0.0": - version: 4.5.0 - resolution: "fastify-plugin@npm:4.5.0" - checksum: 81a63886e038fffb5427df5104c53b0f5d8ad89e59a451110cf591a81372ead1986df59d95bd897d9bd742f78e20eb3ff50bda0115382e6359ed1616883b9a01 - languageName: node - linkType: hard - -"fastify@npm:4.18.0": - version: 4.18.0 - resolution: "fastify@npm:4.18.0" +"fastify@npm:4.24.3": + version: 4.24.3 + resolution: "fastify@npm:4.24.3" dependencies: "@fastify/ajv-compiler": "npm:^3.5.0" - "@fastify/error": "npm:^3.2.0" + "@fastify/error": "npm:^3.4.0" "@fastify/fast-json-stringify-compiler": "npm:^4.3.0" abstract-logging: "npm:^2.0.1" avvio: "npm:^8.2.1" - fast-content-type-parse: "npm:^1.0.0" - fast-json-stringify: "npm:^5.7.0" - find-my-way: "npm:^7.6.0" - light-my-request: "npm:^5.9.1" - pino: "npm:^8.12.0" + fast-content-type-parse: "npm:^1.1.0" + fast-json-stringify: "npm:^5.8.0" + find-my-way: "npm:^7.7.0" + light-my-request: "npm:^5.11.0" + pino: "npm:^8.16.0" process-warning: "npm:^2.2.0" proxy-addr: "npm:^2.0.7" rfdc: "npm:^1.3.0" - secure-json-parse: "npm:^2.5.0" - semver: "npm:^7.5.0" - tiny-lru: "npm:^11.0.1" - checksum: 9a8b7e17fc337a5ddd0145e47b054d20ba7f1b7f62f21e5a015047ad770fe0149b8fbb0b9b5582eda045facef74a6120a6e8aa431ad06b5c9d73cecef8289aeb + secure-json-parse: "npm:^2.7.0" + semver: "npm:^7.5.4" + toad-cache: "npm:^3.3.0" + checksum: 36018767b25cde307942f52172eedfc7c1ce186162222334e19caa607e3d29fe3de04cff2c08f21096d45fa4b071cd58a319392a6dbb5b5dbdf8230b38405c3e languageName: node linkType: hard @@ -4732,14 +4715,14 @@ __metadata: languageName: node linkType: hard -"find-my-way@npm:^7.6.0": - version: 7.6.1 - resolution: "find-my-way@npm:7.6.1" +"find-my-way@npm:^7.7.0": + version: 7.7.0 + resolution: "find-my-way@npm:7.7.0" dependencies: fast-deep-equal: "npm:^3.1.3" fast-querystring: "npm:^1.0.0" safe-regex2: "npm:^2.0.0" - checksum: 7ed4d716fd284f5399cf597a4dffb47a487c44e30f4f6b89614d57e4833dd79de9b5d13b1ee565a018dba418ae95af7aee3b93bcec29bc2f0847e2c29cb2bb57 + checksum: 6b4fef5f3a21a73c5428337a02ce2f90af055e3fade6f57f3444a76d7f58a43891aba26597014ff02f9fd9071abfdd32b92ff2435aadaf96dd2316920c456f6e languageName: node linkType: hard @@ -5201,13 +5184,6 @@ __metadata: languageName: node linkType: hard -"immutable@npm:4.3.4": - version: 4.3.4 - resolution: "immutable@npm:4.3.4" - checksum: c15b9f0fa7b3c9315725cb00704fddad59f0e668a7379c39b9a528a8386140ee9effb015ae51a5b423e05c59d15fc0b38c970db6964ad6b3e05d0761db68441f - languageName: node - linkType: hard - "import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1": version: 3.3.0 resolution: "import-fresh@npm:3.3.0" @@ -6091,6 +6067,15 @@ __metadata: languageName: node linkType: hard +"json-schema-ref-resolver@npm:^1.0.1": + version: 1.0.1 + resolution: "json-schema-ref-resolver@npm:1.0.1" + dependencies: + fast-deep-equal: "npm:^3.1.3" + checksum: aa89d88108c0109ae35b913c89c132fb50c00f3b99fc8a8309b524b9e3a6a77414f19a6a35a1253871462984cbabc74279ebbd9bf103c6629fb7b37c9fb59bcf + languageName: node + linkType: hard + "json-schema-traverse@npm:^0.4.1": version: 0.4.1 resolution: "json-schema-traverse@npm:0.4.1" @@ -6182,14 +6167,14 @@ __metadata: languageName: node linkType: hard -"light-my-request@npm:^5.9.1": - version: 5.10.0 - resolution: "light-my-request@npm:5.10.0" +"light-my-request@npm:^5.11.0": + version: 5.11.0 + resolution: "light-my-request@npm:5.11.0" dependencies: cookie: "npm:^0.5.0" process-warning: "npm:^2.0.0" set-cookie-parser: "npm:^2.4.1" - checksum: 8135809e8c8263a2af542c510206767e39a302f728f7a4cf762179cb39fd58cb390c0a3f2a3f4fd852828cf3e208a4f2ff2d4c842b354d68e23bb04d60c03a70 + checksum: ad5512b5216f2095409b54daf901f714f76004e4c8acdaa1ec3aa2ffde7ddf11ac249f02a87344d766bbad59eb2732acfe3ee5bb7e8ad5fc71057ef0d4d3be25 languageName: node linkType: hard @@ -6613,17 +6598,6 @@ __metadata: languageName: node linkType: hard -"node-gyp-build@npm:^4.6.0": - version: 4.6.0 - resolution: "node-gyp-build@npm:4.6.0" - bin: - node-gyp-build: bin.js - node-gyp-build-optional: optional.js - node-gyp-build-test: build-test.js - checksum: 147add65942acd3cf641d11d9becd030128c7298a5b4aec4ebf3ad4afcc3d0298ad2562afba3e7b2bf70160c5e2e82235e3bc043ff9c52dc68bdd36c856764fe - languageName: node - linkType: hard - "node-gyp@npm:latest": version: 8.4.1 resolution: "node-gyp@npm:8.4.1" @@ -6926,13 +6900,13 @@ __metadata: languageName: node linkType: hard -"pino-abstract-transport@npm:v1.0.0": - version: 1.0.0 - resolution: "pino-abstract-transport@npm:1.0.0" +"pino-abstract-transport@npm:v1.1.0": + version: 1.1.0 + resolution: "pino-abstract-transport@npm:1.1.0" dependencies: readable-stream: "npm:^4.0.0" split2: "npm:^4.0.0" - checksum: c7a68e4f77f47565d39fdc33ba23f388ad2594b26a12ccce3060fef833cd7803db73a0c6e4fa7129616f22eb762119ed6107450e0f8ca1e3745d4993017725f7 + checksum: 6e9b9d5a2c0a37f91ecaf224d335daae1ae682b1c79a05b06ef9e0f0a5d289f8e597992217efc857796dae6f1067e9b4882f95c6228ff433ddc153532cae8aca languageName: node linkType: hard @@ -6943,24 +6917,24 @@ __metadata: languageName: node linkType: hard -"pino@npm:^8.12.0": - version: 8.14.1 - resolution: "pino@npm:8.14.1" +"pino@npm:^8.16.0": + version: 8.16.1 + resolution: "pino@npm:8.16.1" dependencies: atomic-sleep: "npm:^1.0.0" fast-redact: "npm:^3.1.1" on-exit-leak-free: "npm:^2.1.0" - pino-abstract-transport: "npm:v1.0.0" + pino-abstract-transport: "npm:v1.1.0" pino-std-serializers: "npm:^6.0.0" process-warning: "npm:^2.0.0" quick-format-unescaped: "npm:^4.0.3" real-require: "npm:^0.2.0" safe-stable-stringify: "npm:^2.3.1" - sonic-boom: "npm:^3.1.0" + sonic-boom: "npm:^3.7.0" thread-stream: "npm:^2.0.0" bin: pino: bin.js - checksum: 0903238577141814b7bcab0278e0a249078e6cf8198630c9bb7a0dfba555ea303660632ea289d9bd721d8b964939adbfe90fd5a39dee7a6c9f967c0c5e3df8ae + checksum: 06ea391095e895f1f94adda231fb51565e2935a9cad87e6559b7e074a6dadc8bd279367dbe119b1649774480a53c97214f32daa4c14b21a853d50c60a4c28976 languageName: node linkType: hard @@ -7425,7 +7399,7 @@ __metadata: languageName: node linkType: hard -"secure-json-parse@npm:^2.5.0": +"secure-json-parse@npm:^2.7.0": version: 2.7.0 resolution: "secure-json-parse@npm:2.7.0" checksum: f57eb6a44a38a3eeaf3548228585d769d788f59007454214fab9ed7f01fbf2e0f1929111da6db28cf0bcc1a2e89db5219a59e83eeaec3a54e413a0197ce879e4 @@ -7481,17 +7455,6 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.5.0": - version: 7.5.2 - resolution: "semver@npm:7.5.2" - dependencies: - lru-cache: "npm:^6.0.0" - bin: - semver: bin/semver.js - checksum: d151207ab762a8067f6302076edc04e5b8da2362eb9e3f21c2567ceadfd415064936d215b4aae7791da118c230649d29089be979ffa49c5b56a6bcf82147efdd - languageName: node - linkType: hard - "set-blocking@npm:^2.0.0": version: 2.0.0 resolution: "set-blocking@npm:2.0.0" @@ -7585,22 +7548,12 @@ __metadata: languageName: node linkType: hard -"sodium-native@npm:^4.0.0": - version: 4.0.4 - resolution: "sodium-native@npm:4.0.4" - dependencies: - node-gyp: "npm:latest" - node-gyp-build: "npm:^4.6.0" - checksum: 3d2e960fb1b699167406161772e72afd7b5567601a769fbf8a9b688a866d60cd4268ce41b8642474e39c5e41b562460bc27101bf7923769e5b9a1d5ba5a0c942 - languageName: node - linkType: hard - -"sonic-boom@npm:^3.1.0": - version: 3.3.0 - resolution: "sonic-boom@npm:3.3.0" +"sonic-boom@npm:^3.7.0": + version: 3.7.0 + resolution: "sonic-boom@npm:3.7.0" dependencies: atomic-sleep: "npm:^1.0.0" - checksum: c5d387d9e35726a60afe5b5c54317db2428158ecaf3769fb16418e50d2a47176cbd800bf664a410dc0aab0792b421d394ce6edaf63b796ac3c7986f01933cddd + checksum: 57a3d560efb77f4576db111168ee2649c99e7869fda6ce0ec2a4e5458832d290ba58d74b073ddb5827d9a30f96d23cff79157993d919e1a6d5f28d8b6391c7f0 languageName: node linkType: hard @@ -7898,13 +7851,6 @@ __metadata: languageName: node linkType: hard -"tiny-lru@npm:^11.0.1": - version: 11.0.1 - resolution: "tiny-lru@npm:11.0.1" - checksum: f1b4c61dcf822747daafc2ec9f6de6722b7c8f028532d89a878315d0c82001fd9c9386916b6af96ee754ed327d3136ba7b55d319ffc1b4c108a34fdd923fd13b - languageName: node - linkType: hard - "tmpl@npm:1.0.5": version: 1.0.5 resolution: "tmpl@npm:1.0.5" @@ -7928,6 +7874,13 @@ __metadata: languageName: node linkType: hard +"toad-cache@npm:^3.3.0": + version: 3.3.0 + resolution: "toad-cache@npm:3.3.0" + checksum: df2e7fef3991e238197796d3ddd548e1a6b8cb569de8ee053949dcebb689a5ffdbaf2c2642c035768c00d114eb5d4db96925247cc9ccec9d88a6e6d58c95c76a + languageName: node + linkType: hard + "toidentifier@npm:1.0.1": version: 1.0.1 resolution: "toidentifier@npm:1.0.1"