From 1d88253aecd4a84b0ea699ed123ffae5601b66e6 Mon Sep 17 00:00:00 2001 From: Kim Lan Phan Hoang Date: Wed, 6 Nov 2024 14:49:56 +0100 Subject: [PATCH] feat!: rename tags to item visibilities (#694) * feat: rename tags to item visibilities * refactor: fix typo --- src/index.ts | 4 +- src/item/factory.test.ts | 44 ++++++++++------- src/item/factory.ts | 47 ++++++++++--------- src/item/packedItem.ts | 6 +-- .../itemVisibility.factory.ts} | 8 ++-- .../itemVisibility.ts} | 6 +-- 6 files changed, 64 insertions(+), 51 deletions(-) rename src/{itemTag/itemTag.factory.ts => itemVisibility/itemVisibility.factory.ts} (66%) rename src/{itemTag/itemTag.ts => itemVisibility/itemVisibility.ts} (68%) diff --git a/src/index.ts b/src/index.ts index 24f0277b..8ef34a04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -213,9 +213,9 @@ export * from './itemRecycled/itemRecycled.js'; export * from './itemRecycled/itemRecycled.factory.js'; /** - * Item Tag + * Item Visibility */ -export * from './itemTag/itemTag.js'; +export * from './itemVisibility/itemVisibility.js'; /** * Item Validation diff --git a/src/item/factory.test.ts b/src/item/factory.test.ts index 7fe6972a..b3605d81 100644 --- a/src/item/factory.test.ts +++ b/src/item/factory.test.ts @@ -6,7 +6,7 @@ import { PackedFolderItemFactory, } from './folderItem/folderItem.factory.js'; import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js'; -import { ItemTagType } from '@/itemTag/itemTag.js'; +import { ItemVisibilityType } from '@/itemVisibility/itemVisibility.js'; describe('Base Item Factory', () => { it('Returns correct path for id', () => { @@ -70,46 +70,56 @@ describe('Packed Item Factory', () => { expect(info.hidden).toBeUndefined(); expect(info.public).toBeUndefined(); }); - it('Returns correct packed info with given hidden tag', () => { + it('Returns correct packed info with given hidden visibility', () => { const item = FolderItemFactory(); - const hiddenTag = { type: ItemTagType.Hidden, item }; + const hiddenVisibility = { item }; - const info = PackedInformationFactory({ hiddenTag: hiddenTag }, item); + const info = PackedInformationFactory( + { hiddenVisibility: hiddenVisibility }, + item, + ); expect(info.permission).toEqual(PermissionLevel.Admin); - expect(info.hidden).toEqual(expect.objectContaining(hiddenTag)); + expect(info.hidden).toEqual(expect.objectContaining(hiddenVisibility)); + expect(info.hidden!.type).toEqual(ItemVisibilityType.Hidden); expect(info.public).toBeUndefined(); }); - it('Returns correct packed info inheriting parent hidden tag', () => { + it('Returns correct packed info inheriting parent hidden visibility', () => { const parent = FolderItemFactory(); - const hiddenTag = { type: ItemTagType.Hidden, item: parent }; + const hiddenVisibility = { type: ItemVisibilityType.Hidden, item: parent }; const parentItem = PackedFolderItemFactory(parent, { - hiddenTag: hiddenTag, + hiddenVisibility: hiddenVisibility, }); const item = FolderItemFactory({ parentItem }); const info = PackedInformationFactory({}, item, parentItem); expect(info.permission).toEqual(PermissionLevel.Admin); - expect(info.hidden).toEqual(expect.objectContaining(hiddenTag)); + expect(info.hidden).toEqual(expect.objectContaining(hiddenVisibility)); + expect(info.hidden!.type).toEqual(ItemVisibilityType.Hidden); expect(info.public).toBeUndefined(); }); - it('Returns correct packed info with given public tag', () => { + it('Returns correct packed info with given public visibility', () => { const item = FolderItemFactory(); - const publicTag = { type: ItemTagType.Public, item }; + const publicVisibility = { item }; - const info = PackedInformationFactory({ publicTag: publicTag }, item); + const info = PackedInformationFactory( + { publicVisibility: publicVisibility }, + item, + ); expect(info.permission).toEqual(PermissionLevel.Admin); - expect(info.public).toEqual(expect.objectContaining(publicTag)); + expect(info.public).toEqual(expect.objectContaining(publicVisibility)); + expect(info.public!.type).toEqual(ItemVisibilityType.Public); expect(info.hidden).toBeUndefined(); }); - it('Returns correct packed info inheriting parent public tag', () => { + it('Returns correct packed info inheriting parent public visibility', () => { const parent = FolderItemFactory(); - const publicTag = { type: ItemTagType.Public, item: parent }; + const publicVisibility = { type: ItemVisibilityType.Public, item: parent }; const parentItem = PackedFolderItemFactory(parent, { - publicTag: publicTag, + publicVisibility: publicVisibility, }); const item = FolderItemFactory({ parentItem }); const info = PackedInformationFactory({}, item, parentItem); expect(info.permission).toEqual(PermissionLevel.Admin); - expect(info.public).toEqual(expect.objectContaining(publicTag)); + expect(info.public).toEqual(expect.objectContaining(publicVisibility)); + expect(info.public!.type).toEqual(ItemVisibilityType.Public); expect(info.hidden).toBeUndefined(); }); }); diff --git a/src/item/factory.ts b/src/item/factory.ts index 16d748a4..24b364bb 100644 --- a/src/item/factory.ts +++ b/src/item/factory.ts @@ -4,8 +4,11 @@ import { buildPathFromIds } from './itemUtils.js'; import { PackedInformation, PackedItem } from './packedItem.js'; import { CCLicenseAdaptions } from '@/enums/ccLicenses.js'; import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js'; -import { ItemTagFactory } from '@/itemTag/itemTag.factory.js'; -import { ItemTag, ItemTagType } from '@/itemTag/itemTag.js'; +import { ItemVisibilityFactory } from '@/itemVisibility/itemVisibility.factory.js'; +import { + ItemVisibility, + ItemVisibilityType, +} from '@/itemVisibility/itemVisibility.js'; import { faker } from '@faker-js/faker'; export type ItemFactoryOutputType = Pick< @@ -79,44 +82,44 @@ export const PartialItemFactory = ( export type PackedInformationFactoryInput = { permission?: PermissionLevel | null; - hiddenTag?: Partial; - publicTag?: Partial; + hiddenVisibility?: Partial; + publicVisibility?: Partial; }; export const PackedInformationFactory = ( { permission = PermissionLevel.Admin, - hiddenTag, - publicTag, + hiddenVisibility, + publicVisibility, }: PackedInformationFactoryInput, item: DiscriminatedItem, parentItem: Partial> = {}, ): PackedInformation => { - // use parent tag if exists - let hiddenItemTag = parentItem.hidden; - // use given hidden tag - if (hiddenTag) { - hiddenItemTag = ItemTagFactory({ - type: ItemTagType.Hidden, + // use parent visibility if exists + let hiddenItemVisibility = parentItem.hidden; + // use given hidden visibility + if (hiddenVisibility) { + hiddenItemVisibility = ItemVisibilityFactory({ + type: ItemVisibilityType.Hidden, item, - ...hiddenTag, + ...hiddenVisibility, }); } - // use parent tag if exists - let publicItemTag = parentItem.public; - // use given hidden tag - if (publicTag) { - publicItemTag = ItemTagFactory({ - type: ItemTagType.Hidden, + // use parent visibility if exists + let publicItemVisibility = parentItem.public; + // use given hidden visibility + if (publicVisibility) { + publicItemVisibility = ItemVisibilityFactory({ + type: ItemVisibilityType.Public, item, - ...publicTag, + ...publicVisibility, }); } return { permission, - ...(hiddenItemTag ? { hidden: hiddenItemTag } : {}), - ...(publicItemTag ? { public: publicItemTag } : {}), + ...(hiddenItemVisibility ? { hidden: hiddenItemVisibility } : {}), + ...(publicItemVisibility ? { public: publicItemVisibility } : {}), }; }; diff --git a/src/item/packedItem.ts b/src/item/packedItem.ts index 5b79342c..766f4cb0 100644 --- a/src/item/packedItem.ts +++ b/src/item/packedItem.ts @@ -2,12 +2,12 @@ import { ItemMembership } from '../itemMembership/itemMembership.js'; import { DiscriminatedItem } from './item.js'; import { ItemSettings } from './itemSettings.js'; import { ThumbnailsBySize } from '@/enums/thumbnailSizes.js'; -import { ItemTag } from '@/itemTag/itemTag.js'; +import { ItemVisibility } from '@/itemVisibility/itemVisibility.js'; export type PackedInformation = { permission: ItemMembership['permission'] | null; - hidden?: ItemTag; - public?: ItemTag; + hidden?: ItemVisibility; + public?: ItemVisibility; thumbnails?: ThumbnailsBySize; }; diff --git a/src/itemTag/itemTag.factory.ts b/src/itemVisibility/itemVisibility.factory.ts similarity index 66% rename from src/itemTag/itemTag.factory.ts rename to src/itemVisibility/itemVisibility.factory.ts index 0231d7b1..7c2149bd 100644 --- a/src/itemTag/itemTag.factory.ts +++ b/src/itemVisibility/itemVisibility.factory.ts @@ -1,11 +1,11 @@ -import { ItemTag } from './itemTag.js'; +import { ItemVisibility } from './itemVisibility.js'; import { FolderItemFactory } from '@/item/folderItem/folderItem.factory.js'; import { MemberFactory } from '@/member/factory.js'; import { faker } from '@faker-js/faker'; -export const ItemTagFactory = ( - it: Partial & Pick, -): ItemTag => ({ +export const ItemVisibilityFactory = ( + it: Partial & Pick, +): ItemVisibility => ({ id: it.id ?? faker.string.uuid(), createdAt: faker.date.anytime().toISOString(), item: it.item ?? FolderItemFactory(), diff --git a/src/itemTag/itemTag.ts b/src/itemVisibility/itemVisibility.ts similarity index 68% rename from src/itemTag/itemTag.ts rename to src/itemVisibility/itemVisibility.ts index a4efbd59..cf1b417a 100644 --- a/src/itemTag/itemTag.ts +++ b/src/itemVisibility/itemVisibility.ts @@ -2,15 +2,15 @@ import { DiscriminatedItem } from '@/item/item.js'; import { Member } from '@/member/member.js'; import { UUID } from '@/types.js'; -export enum ItemTagType { +export enum ItemVisibilityType { Public = 'public', Hidden = 'hidden', } -export type ItemTag = { +export type ItemVisibility = { id: UUID; item: DiscriminatedItem; - type: `${ItemTagType}` | ItemTagType; + type: `${ItemVisibilityType}` | ItemVisibilityType; createdAt: string; creator: Member; };