From 1a9d4f2dd09394f62214a8467176a96cbc013f95 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:31:33 +0100 Subject: [PATCH] Removed unused exports --- src/blocks/sectionBlock.ts | 2 +- src/collections/Folders/Folders.ts | 9 +- .../Folders/endpoints/getBySlugEndpoint.ts | 3 +- src/endpoints/createGetByEndpoint.ts | 2 +- src/endpoints/createStrapiImportEndpoint.ts | 12 +- src/types/collections.ts | 202 ++++++++++-------- src/types/strapi.ts | 4 - src/utils/asserts.ts | 12 -- src/utils/localApi.ts | 11 - src/utils/string.ts | 6 +- 10 files changed, 127 insertions(+), 136 deletions(-) diff --git a/src/blocks/sectionBlock.ts b/src/blocks/sectionBlock.ts index 2d7ecab..f8cbcdc 100644 --- a/src/blocks/sectionBlock.ts +++ b/src/blocks/sectionBlock.ts @@ -26,7 +26,7 @@ const generateRecursiveSectionBlock = (depth = 1, maxDepth = 5): Block => ({ blocks: [ ...(depth < maxDepth ? [generateRecursiveSectionBlock(depth + 1, maxDepth)] : []), transcriptBlock, - breakBlock + breakBlock, ], }), }, diff --git a/src/collections/Folders/Folders.ts b/src/collections/Folders/Folders.ts index 510e513..99c1a48 100644 --- a/src/collections/Folders/Folders.ts +++ b/src/collections/Folders/Folders.ts @@ -28,7 +28,14 @@ export const Folders = buildCollectionConfig({ admin: { useAsTitle: fields.slug, group: CollectionGroups.Collections, - defaultColumns: [fields.slug, fields.translations, fields.parentFolders, fields.sections, fields.files, fields.icon], + defaultColumns: [ + fields.slug, + fields.translations, + fields.parentFolders, + fields.sections, + fields.files, + fields.icon, + ], description: "Folders provide a way to structure our content. A folder can contain subfolders and/or files.", preview: ({ slug }) => `https://v3.accords-library.com/en/folders/${slug}`, diff --git a/src/collections/Folders/endpoints/getBySlugEndpoint.ts b/src/collections/Folders/endpoints/getBySlugEndpoint.ts index 3ae7f8a..6b5ef1e 100644 --- a/src/collections/Folders/endpoints/getBySlugEndpoint.ts +++ b/src/collections/Folders/endpoints/getBySlugEndpoint.ts @@ -19,8 +19,7 @@ export const getBySlugEndpoint = createGetByEndpoint( ? { type: "single", subfolders: - sections[0]?.subfolders?.filter(isPayloadType).map(convertFolderToPreview) ?? - [], + sections[0]?.subfolders?.filter(isPayloadType).map(convertFolderToPreview) ?? [], } : { type: "multiple", diff --git a/src/endpoints/createGetByEndpoint.ts b/src/endpoints/createGetByEndpoint.ts index d2cc941..f6bb698 100644 --- a/src/endpoints/createGetByEndpoint.ts +++ b/src/endpoints/createGetByEndpoint.ts @@ -5,7 +5,7 @@ export const createGetByEndpoint = Promise | R, - depth?: number, + depth?: number ): CollectionEndpoint => ({ path: `/${attribute}/:${attribute}`, method: "get", diff --git a/src/endpoints/createStrapiImportEndpoint.ts b/src/endpoints/createStrapiImportEndpoint.ts index 7696e2e..58ebe2c 100644 --- a/src/endpoints/createStrapiImportEndpoint.ts +++ b/src/endpoints/createStrapiImportEndpoint.ts @@ -4,10 +4,7 @@ import { Recorder } from "../types/collections"; import { CollectionEndpoint } from "../types/payload"; import { isDefined } from "../utils/asserts"; -export const getAllStrapiEntries = async ( - collectionSlug: string, - params: Object -): Promise => { +const getAllStrapiEntries = async (collectionSlug: string, params: Object): Promise => { let page = 1; let totalPage = 1; const result: any[] = []; @@ -39,14 +36,11 @@ type Params = { path?: string; collection: keyof GeneratedTypes["collections"]; import?: (strapiObject: S, user: any) => Promise; - convert?: ( - strapiObject: S, - user: any - ) => any; + convert?: (strapiObject: S, user: any) => any; }; }; -export const importStrapiEntries = async ({ +const importStrapiEntries = async ({ strapi: strapiParams, payload: payloadParams, user, diff --git a/src/types/collections.ts b/src/types/collections.ts index cbe4c28..56ea429 100644 --- a/src/types/collections.ts +++ b/src/types/collections.ts @@ -20,8 +20,8 @@ export type RecorderBiographies = version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -46,26 +46,25 @@ export interface Config { pages: Page; collectibles: Collectible; folders: Folder; - 'chronology-items': ChronologyItem; - 'chronology-eras': ChronologyEra; + "chronology-events": ChronologyEvent; notes: Note; images: Image; - 'background-images': BackgroundImage; - 'recorders-thumbnails': RecordersThumbnail; + "background-images": BackgroundImage; + "recorders-thumbnails": RecordersThumbnail; videos: Video; - 'videos-channels': VideosChannel; + "videos-channels": VideosChannel; tags: Tag; - 'tags-groups': TagsGroup; + "tags-groups": TagsGroup; recorders: Recorder; languages: Language; currencies: Currency; wordings: Wording; - 'generic-contents': GenericContent; - 'payload-preferences': PayloadPreference; - 'payload-migrations': PayloadMigration; + "generic-contents": GenericContent; + "payload-preferences": PayloadPreference; + "payload-migrations": PayloadMigration; }; globals: { - 'home-folders': HomeFolder; + "home-folders": HomeFolder; }; } /** @@ -75,7 +74,7 @@ export interface Config { export interface Page { id: string; slug: string; - type: 'Content' | 'Post' | 'Generic'; + type: "Content" | "Post" | "Generic"; thumbnail?: string | Image | null; backgroundImage?: string | BackgroundImage | null; tags?: (string | Tag)[] | null; @@ -93,8 +92,8 @@ export interface Page { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -108,8 +107,8 @@ export interface Page { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -126,7 +125,7 @@ export interface Page { updatedBy: string | Recorder; updatedAt: string; createdAt: string; - _status?: ('draft' | 'published') | null; + _status?: ("draft" | "published") | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -237,7 +236,7 @@ export interface Recorder { avatar?: string | RecordersThumbnail | null; languages?: (string | Language)[] | null; biographies?: RecorderBiographies; - role?: ('Admin' | 'Recorder' | 'Api')[] | null; + role?: ("Admin" | "Recorder" | "Api")[] | null; anonymize: boolean; email: string; resetPasswordToken?: string | null; @@ -301,8 +300,8 @@ export interface Folder { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -327,11 +326,11 @@ export interface Folder { files?: | ( | { - relationTo: 'collectibles'; + relationTo: "collectibles"; value: string | Collectible; } | { - relationTo: 'pages'; + relationTo: "pages"; value: string | Page; } )[] @@ -347,7 +346,7 @@ export interface Collectible { id: string; slug: string; thumbnail?: string | Image | null; - nature: 'Physical' | 'Digital'; + nature: "Physical" | "Digital"; languages?: (string | Language)[] | null; tags?: (string | Tag)[] | null; translations: { @@ -362,8 +361,8 @@ export interface Collectible { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -455,8 +454,8 @@ export interface Collectible { pageInfoEnabled?: boolean | null; pageInfo?: { pageCount: number; - bindingType?: ('Paperback' | 'Hardcover') | null; - pageOrder?: ('Left to right' | 'Right to left') | null; + bindingType?: ("Paperback" | "Hardcover") | null; + pageOrder?: ("Left to right" | "Right to left") | null; }; folders?: (string | Folder)[] | null; parentItems?: (string | Collectible)[] | null; @@ -465,11 +464,11 @@ export interface Collectible { | { content: | { - relationTo: 'pages'; + relationTo: "pages"; value: string | Page; } | { - relationTo: 'generic-contents'; + relationTo: "generic-contents"; value: string | GenericContent; }; range?: @@ -479,14 +478,14 @@ export interface Collectible { end: number; id?: string | null; blockName?: string | null; - blockType: 'pageRange'; + blockType: "pageRange"; } | { start: string; end: string; id?: string | null; blockName?: string | null; - blockType: 'timeRange'; + blockType: "timeRange"; } | { translations?: @@ -499,8 +498,8 @@ export interface Collectible { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -512,7 +511,7 @@ export interface Collectible { | null; id?: string | null; blockName?: string | null; - blockType: 'other'; + blockType: "other"; } )[] | null; @@ -522,7 +521,7 @@ export interface Collectible { updatedBy: string | Recorder; updatedAt: string; createdAt: string; - _status?: ('draft' | 'published') | null; + _status?: ("draft" | "published") | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -548,9 +547,9 @@ export interface GenericContent { } /** * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "chronology-items". + * via the `definition` "chronology-events". */ -export interface ChronologyItem { +export interface ChronologyEvent { id: string; name?: string | null; date: { @@ -559,6 +558,7 @@ export interface ChronologyItem { day?: number | null; }; events: { + sources?: (UrlBlock | CollectibleBlock | PageBlock)[] | null; translations: { language: string | Language; sourceLanguage: string | Language; @@ -570,8 +570,8 @@ export interface ChronologyItem { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -585,8 +585,8 @@ export interface ChronologyItem { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -603,42 +603,63 @@ export interface ChronologyItem { updatedBy: string | Recorder; updatedAt: string; createdAt: string; - _status?: ('draft' | 'published') | null; + _status?: ("draft" | "published") | null; } /** * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "chronology-eras". + * via the `definition` "UrlBlock". */ -export interface ChronologyEra { - id: string; - slug: string; - startingYear: number; - endingYear: number; - translations?: - | { - language: string | Language; - title: string; - description?: { - root: { - children: { - type: string; - version: number; - [k: string]: unknown; +export interface UrlBlock { + url: string; + id?: string | null; + blockName?: string | null; + blockType: "urlBlock"; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "CollectibleBlock". + */ +export interface CollectibleBlock { + collectible: string | Collectible; + range?: + | ( + | { + page: number; + id?: string | null; + blockName?: string | null; + blockType: "page"; + } + | { + timestamp: string; + id?: string | null; + blockName?: string | null; + blockType: "timestamp"; + } + | { + translations: { + language: string | Language; + note: string; + id?: string | null; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; - indent: number; - type: string; - version: number; - }; - [k: string]: unknown; - } | null; - id?: string | null; - }[] + id?: string | null; + blockName?: string | null; + blockType: "other"; + } + )[] | null; - events?: (string | ChronologyItem)[] | null; - updatedAt: string; - createdAt: string; + id?: string | null; + blockName?: string | null; + blockType: "collectibleBlock"; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "PageBlock". + */ +export interface PageBlock { + page: string | Page; + id?: string | null; + blockName?: string | null; + blockType: "pageBlock"; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -653,8 +674,8 @@ export interface Note { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -672,7 +693,7 @@ export interface Video { id: string; uid: string; gone: boolean; - source: 'YouTube' | 'NicoNico' | 'Tumblr'; + source: "YouTube" | "NicoNico" | "Tumblr"; title: string; description?: string | null; likes?: number | null; @@ -708,7 +729,7 @@ export interface Wording { export interface PayloadPreference { id: string; user: { - relationTo: 'recorders'; + relationTo: "recorders"; value: string | Recorder; }; key?: string | null; @@ -764,15 +785,15 @@ export interface LineBlock { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; }; [k: string]: unknown; }; - blockType: 'lineBlock'; + blockType: "lineBlock"; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -786,15 +807,15 @@ export interface CueBlock { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; }; [k: string]: unknown; }; - blockType: 'cueBlock'; + blockType: "cueBlock"; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -804,17 +825,17 @@ export interface TranscriptBlock { lines: (LineBlock | CueBlock)[]; id?: string | null; blockName?: string | null; - blockType: 'transcriptBlock'; + blockType: "transcriptBlock"; } /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "BreakBlock". */ export interface BreakBlock { - type: 'Scene break' | 'Empty space' | 'Solid line' | 'Dotted line'; + type: "Scene break" | "Empty space" | "Solid line" | "Dotted line"; id?: string | null; blockName?: string | null; - blockType: 'breakBlock'; + blockType: "breakBlock"; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -828,8 +849,8 @@ export interface SectionBlock { version: number; [k: string]: unknown; }[]; - direction: ('ltr' | 'rtl') | null; - format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | ''; + direction: ("ltr" | "rtl") | null; + format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; type: string; version: number; @@ -838,10 +859,9 @@ export interface SectionBlock { }; id?: string | null; blockName?: string | null; - blockType: 'sectionBlock'; + blockType: "sectionBlock"; } - -declare module 'payload' { +declare module "payload" { export interface GeneratedTypes extends Config {} -} \ No newline at end of file +} diff --git a/src/types/strapi.ts b/src/types/strapi.ts index 8dbec52..4752cd8 100644 --- a/src/types/strapi.ts +++ b/src/types/strapi.ts @@ -2,10 +2,6 @@ export type StrapiLanguage = { data?: { attributes: { code: string } }; }; -export type StrapiRecorders = { - data?: { attributes: { username: string } }[]; -}; - export type StrapiImage = { data?: { attributes: { diff --git a/src/utils/asserts.ts b/src/utils/asserts.ts index e05821a..63697ff 100644 --- a/src/utils/asserts.ts +++ b/src/utils/asserts.ts @@ -12,15 +12,6 @@ export const isNotEmpty = (value: string | null | undefined): value is string => export const isEmpty = (value: string | null | undefined): value is string => isUndefined(value) || value.trim().length === 0; -type Span = [number, number]; -const hasNoIntersection = (a: Span, b: Span): boolean => { - const [aStart, aEnd] = a; - const [bStart, bEnd] = b; - return aEnd < bStart || aStart > bEnd; -}; - -export const hasIntersection = (a: Span, b: Span): boolean => !hasNoIntersection(a, b); - export const hasDuplicates = (list: T[]): boolean => list.length !== new Set(list).size; export const isValidPayloadImage = ( @@ -46,9 +37,6 @@ export const isValidPayloadImage = ( return true; }; -export const isString = (value: string | T): value is string => - typeof value === "string"; - export const isPayloadType = (value: string | T): value is T => typeof value === "object"; diff --git a/src/utils/localApi.ts b/src/utils/localApi.ts index 7b9293f..15a8aeb 100644 --- a/src/utils/localApi.ts +++ b/src/utils/localApi.ts @@ -1,18 +1,7 @@ import payload, { GeneratedTypes } from "payload"; -import { Collections } from "../constants"; import { StrapiImage } from "../types/strapi"; import { isDefined } from "./asserts"; -export const findRecorder = async (name: string): Promise => { - const recorder = await payload.find({ - collection: Collections.Recorders, - where: { username: { equals: name } }, - depth: 0, - }); - if (!recorder.docs[0]) throw new Error(`Recorder ${name} wasn't found`); - return recorder.docs[0].id; -}; - type UploadStrapiImage = { image: StrapiImage; collection: keyof GeneratedTypes["collections"]; diff --git a/src/utils/string.ts b/src/utils/string.ts index ad1c8b4..07b6ef9 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -14,7 +14,7 @@ export const capitalize = (string: string): string => { return [firstLetter.toUpperCase(), ...otherLetters].join(""); }; -export const formatToCamelCase = (name: string): string => +const formatToCamelCase = (name: string): string => name .toLowerCase() .split(/[ \_-]/g) @@ -23,9 +23,7 @@ export const formatToCamelCase = (name: string): string => export const formatToPascalCase = (name: string): string => capitalize(formatToCamelCase(name)); -export const plainTextToLexical = ( - text: string -): RichTextContent => ({ +export const plainTextToLexical = (text: string): RichTextContent => ({ root: { type: "root", format: "",