From a50cee76369f4313fc6c667c3f5af58834f8b223 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sun, 21 Jul 2024 10:00:36 +0200 Subject: [PATCH] Added prettier script to standardize formatting --- .gitignore | 1 + analytics/sdk.ts | 5 +-- meilisearch/constants.ts | 2 +- meilisearch/sdk.ts | 6 +-- meilisearch/types.ts | 1 - package-lock.json | 31 ++++++++++++++ package.json | 13 ++++++ payload/blocks.ts | 88 ++++++++++++++++++++-------------------- payload/format.ts | 14 ++----- payload/rich-text.ts | 68 ++++++++++++------------------- payload/sdk.ts | 49 ++++++---------------- payload/webhooks.ts | 10 ++--- prettier.config.js | 22 ++++++++++ 13 files changed, 163 insertions(+), 147 deletions(-) create mode 100644 .gitignore create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 prettier.config.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/analytics/sdk.ts b/analytics/sdk.ts index dc58385..2682eca 100644 --- a/analytics/sdk.ts +++ b/analytics/sdk.ts @@ -8,10 +8,7 @@ type AnalyticsBody = Record & { export class AnalyticsSDK { constructor(private readonly apiURL: string) {} - trackRequest( - request: Request, - { clientAddress, locale, responseStatus }: TrackRequestParams - ) { + trackRequest(request: Request, { clientAddress, locale, responseStatus }: TrackRequestParams) { const userAgent = request.headers.get("User-Agent"); const acceptLanguage = request.headers.get("Accept-Language"); const { method, url: stringUrl, referrer } = request; diff --git a/meilisearch/constants.ts b/meilisearch/constants.ts index 2ac5471..d7f98c7 100644 --- a/meilisearch/constants.ts +++ b/meilisearch/constants.ts @@ -1,3 +1,3 @@ export enum MeiliIndexes { DOCUMENT = "DOCUMENT", -} \ No newline at end of file +} diff --git a/meilisearch/sdk.ts b/meilisearch/sdk.ts index 5a5e63d..ab26928 100644 --- a/meilisearch/sdk.ts +++ b/meilisearch/sdk.ts @@ -6,11 +6,7 @@ export class MeilisearchSDK { private readonly bearer: string ) {} - async search({ - q, - page, - types, - }: SearchRequest): Promise> { + async search({ q, page, types }: SearchRequest): Promise> { const filter: string[] = []; if (types) { diff --git a/meilisearch/types.ts b/meilisearch/types.ts index cf6585f..631f5b2 100644 --- a/meilisearch/types.ts +++ b/meilisearch/types.ts @@ -49,7 +49,6 @@ export type MeiliDocumentRequest = type: Collections.ChronologyEvents; }; - export type MeiliDocument = MeiliDocumentRequest & { docId: string; distinctId: string; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..aa96539 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,31 @@ +{ + "name": "shared-library", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "shared-library", + "version": "1.0.0", + "license": "MIT", + "devDependencies": { + "prettier": "3.3.3" + } + }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b6b2cd1 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "shared-library", + "version": "1.0.0", + "description": "", + "scripts": { + "prettier": "prettier --list-different --end-of-line auto --write ." + }, + "author": "", + "license": "MIT", + "devDependencies": { + "prettier": "3.3.3" + } +} diff --git a/payload/blocks.ts b/payload/blocks.ts index 9dc2d0d..7a920dc 100644 --- a/payload/blocks.ts +++ b/payload/blocks.ts @@ -1,47 +1,47 @@ import type { RichTextContent } from "./rich-text"; export interface TranscriptBlock extends GenericBlock { - lines: (LineBlock | CueBlock)[]; - blockType: "transcriptBlock"; - } - - export interface BreakBlock extends GenericBlock { - type: "Scene break" | "Empty space" | "Solid line" | "Dotted line"; - blockType: "breakBlock"; - } - - export interface SectionBlock extends GenericBlock { - content: RichTextContent; - blockType: "sectionBlock"; - } - - export interface CueBlock extends GenericBlock { - content: RichTextContent; - blockType: "cueBlock"; - } - - export interface LineBlock extends GenericBlock { - content: RichTextContent; - blockType: "lineBlock"; - } - - export interface GenericBlock { - id?: string | null; - blockName?: string | null; - blockType: string; - } - - export const isBlockTranscriptBlock = (block: GenericBlock): block is TranscriptBlock => - block.blockType === "transcriptBlock"; - - export const isBlockBreakBlock = (block: GenericBlock): block is BreakBlock => - block.blockType === "breakBlock"; - - export const isBlockSectionBlock = (block: GenericBlock): block is SectionBlock => - block.blockType === "sectionBlock"; - - export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => - block.blockType === "cueBlock"; - - export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => - block.blockType === "lineBlock"; \ No newline at end of file + lines: (LineBlock | CueBlock)[]; + blockType: "transcriptBlock"; +} + +export interface BreakBlock extends GenericBlock { + type: "Scene break" | "Empty space" | "Solid line" | "Dotted line"; + blockType: "breakBlock"; +} + +export interface SectionBlock extends GenericBlock { + content: RichTextContent; + blockType: "sectionBlock"; +} + +export interface CueBlock extends GenericBlock { + content: RichTextContent; + blockType: "cueBlock"; +} + +export interface LineBlock extends GenericBlock { + content: RichTextContent; + blockType: "lineBlock"; +} + +export interface GenericBlock { + id?: string | null; + blockName?: string | null; + blockType: string; +} + +export const isBlockTranscriptBlock = (block: GenericBlock): block is TranscriptBlock => + block.blockType === "transcriptBlock"; + +export const isBlockBreakBlock = (block: GenericBlock): block is BreakBlock => + block.blockType === "breakBlock"; + +export const isBlockSectionBlock = (block: GenericBlock): block is SectionBlock => + block.blockType === "sectionBlock"; + +export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => + block.blockType === "cueBlock"; + +export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => + block.blockType === "lineBlock"; diff --git a/payload/format.ts b/payload/format.ts index b3810fe..bde1edc 100644 --- a/payload/format.ts +++ b/payload/format.ts @@ -22,17 +22,12 @@ const formatList = (node: RichTextListNode) => { const formatBlock = (node: RichTextBlockNode) => { if (isBlockNodeSectionBlock(node)) { - return ( - `\n\n${node.fields.blockName}\n` + - formatRichTextContentToString(node.fields.content) - ); + return `\n\n${node.fields.blockName}\n` + formatRichTextContentToString(node.fields.content); } else if (isBlockNodeTranscriptBlock(node)) { return node.fields.lines .map((block) => { if (isBlockLineBlock(block)) { - return `${block.blockName} | ${formatRichTextContentToString( - block.content - )}`; + return `${block.blockName} | ${formatRichTextContentToString(block.content)}`; } else if (isBlockCueBlock(block)) { return formatRichTextContentToString(block.content); } @@ -71,9 +66,8 @@ const formatNode = (node: RichTextNode): string => { return ""; }; -export const formatRichTextContentToString = ( - content: RichTextContent -): string => content.root.children.map(formatNode).join("\n\n"); +export const formatRichTextContentToString = (content: RichTextContent): string => + content.root.children.map(formatNode).join("\n\n"); export const formatInlineTitle = ({ pretitle, diff --git a/payload/rich-text.ts b/payload/rich-text.ts index f32db98..f7c82a1 100644 --- a/payload/rich-text.ts +++ b/payload/rich-text.ts @@ -138,50 +138,40 @@ export interface RichTextBreakBlock extends RichTextBlockNode { anchorHash: string; } -export const isNodeParagraphNode = ( - node: RichTextNode -): node is RichTextParagraphNode => node.type === "paragraph"; +export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode => + node.type === "paragraph"; -export const isNodeUploadNode = ( - node: RichTextNode -): node is RichTextUploadNode => node.type === "upload"; +export const isNodeUploadNode = (node: RichTextNode): node is RichTextUploadNode => + node.type === "upload"; -export const isUploadNodeImageNode = ( - node: RichTextUploadNode -): node is RichTextUploadImageNode => node.relationTo === Collections.Images; +export const isUploadNodeImageNode = (node: RichTextUploadNode): node is RichTextUploadImageNode => + node.relationTo === Collections.Images; -export const isUploadNodeVideoNode = ( - node: RichTextUploadNode -): node is RichTextUploadVideoNode => node.relationTo === Collections.Videos; +export const isUploadNodeVideoNode = (node: RichTextUploadNode): node is RichTextUploadVideoNode => + node.relationTo === Collections.Videos; -export const isUploadNodeAudioNode = ( - node: RichTextUploadNode -): node is RichTextUploadAudioNode => node.relationTo === Collections.Audios; +export const isUploadNodeAudioNode = (node: RichTextUploadNode): node is RichTextUploadAudioNode => + node.relationTo === Collections.Audios; export const isNodeListNode = (node: RichTextNode): node is RichTextListNode => node.type === "list"; -export const isListNodeNumberListNode = ( - node: RichTextListNode -): node is RichTextListNumberNode => node.listType === "number"; +export const isListNodeNumberListNode = (node: RichTextListNode): node is RichTextListNumberNode => + node.listType === "number"; -export const isListNodeBulletListNode = ( - node: RichTextListNode -): node is RichTextListBulletNode => node.listType === "bullet"; +export const isListNodeBulletListNode = (node: RichTextListNode): node is RichTextListBulletNode => + node.listType === "bullet"; -export const isListNodeCheckListNode = ( - node: RichTextListNode -): node is RichTextListCheckNode => node.listType === "check"; +export const isListNodeCheckListNode = (node: RichTextListNode): node is RichTextListCheckNode => + node.listType === "check"; -export const isNodeLinebreakNode = ( - node: RichTextNode -): node is RichTextLinebreakNode => node.type === "linebreak"; +export const isNodeLinebreakNode = (node: RichTextNode): node is RichTextLinebreakNode => + node.type === "linebreak"; export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode => node.type === "text"; -export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => - node.type === "tab"; +export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => node.type === "tab"; export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode => node.type === "link"; @@ -190,22 +180,18 @@ export const isLinkNodeInternalLinkNode = ( node: RichTextLinkNode ): node is RichTextLinkInternalNode => node.fields.linkType === "internal"; -export const isLinkNodeCustomLinkNode = ( - node: RichTextLinkNode -): node is RichTextLinkCustomNode => node.fields.linkType === "custom"; +export const isLinkNodeCustomLinkNode = (node: RichTextLinkNode): node is RichTextLinkCustomNode => + node.fields.linkType === "custom"; -export const isNodeBlockNode = ( - node: RichTextNode -): node is RichTextBlockNode => node.type === "block"; +export const isNodeBlockNode = (node: RichTextNode): node is RichTextBlockNode => + node.type === "block"; -export const isBlockNodeSectionBlock = ( - node: RichTextBlockNode -): node is RichTextSectionBlock => node.fields.blockType === "sectionBlock"; +export const isBlockNodeSectionBlock = (node: RichTextBlockNode): node is RichTextSectionBlock => + node.fields.blockType === "sectionBlock"; export const isBlockNodeTranscriptBlock = ( node: RichTextBlockNode ): node is RichTextTranscriptBlock => isBlockTranscriptBlock(node.fields); -export const isBlockNodeBreakBlock = ( - node: RichTextBlockNode -): node is RichTextBreakBlock => isBlockBreakBlock(node.fields); +export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock => + isBlockBreakBlock(node.fields); diff --git a/payload/sdk.ts b/payload/sdk.ts index c40ea6e..b154366 100644 --- a/payload/sdk.ts +++ b/payload/sdk.ts @@ -28,10 +28,8 @@ export const getSDKEndpoint = { getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, getWordingsEndpoint: () => `/${Collections.Wordings}/all`, getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, - getCollectibleEndpoint: (slug: string) => - `/${Collections.Collectibles}/slug/${slug}`, - getCollectibleScansEndpoint: (slug: string) => - `/${Collections.Collectibles}/slug/${slug}/scans`, + getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, + getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, getCollectibleScanPageEndpoint: (slug: string, index: string) => `/${Collections.Collectibles}/slug/${slug}/scans/${index}`, getCollectibleGalleryEndpoint: (slug: string) => @@ -39,8 +37,7 @@ export const getSDKEndpoint = { getCollectibleGalleryImageEndpoint: (slug: string, index: string) => `/${Collections.Collectibles}/slug/${slug}/gallery/${index}`, getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`, - getChronologyEventByIDEndpoint: (id: string) => - `/${Collections.ChronologyEvents}/id/${id}`, + getChronologyEventByIDEndpoint: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`, getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`, getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`, getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`, @@ -117,9 +114,7 @@ export class PayloadSDK { const result = await fetch(`${this.apiURL}${endpoint}`, { headers: { - Authorization: `JWT ${ - this.tokenCache?.get() ?? (await this.refreshToken()) - }`, + Authorization: `JWT ${this.tokenCache?.get() ?? (await this.refreshToken())}`, }, }); this.logResponse(result); @@ -151,50 +146,34 @@ export class PayloadSDK { async getPage(slug: string): Promise> { return await this.request(getSDKEndpoint.getPageEndpoint(slug)); } - async getCollectible( - slug: string - ): Promise> { + async getCollectible(slug: string): Promise> { return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); } - async getCollectibleScans( - slug: string - ): Promise> { + async getCollectibleScans(slug: string): Promise> { return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); } async getCollectibleScanPage( slug: string, index: string ): Promise> { - return await this.request( - getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index) - ); + return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)); } async getCollectibleGallery( slug: string ): Promise> { - return await this.request( - getSDKEndpoint.getCollectibleGalleryEndpoint(slug) - ); + return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug)); } async getCollectibleGalleryImage( slug: string, index: string ): Promise> { - return await this.request( - getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index) - ); + return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)); } - async getChronologyEvents(): Promise< - PayloadSDKResponse - > { + async getChronologyEvents(): Promise> { return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); } - async getChronologyEventByID( - id: string - ): Promise> { - return await this.request( - getSDKEndpoint.getChronologyEventByIDEndpoint(id) - ); + async getChronologyEventByID(id: string): Promise> { + return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id)); } async getImageByID(id: string): Promise> { return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); @@ -208,9 +187,7 @@ export class PayloadSDK { async getFileByID(id: string): Promise> { return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); } - async getRecorderByID( - id: string - ): Promise> { + async getRecorderByID(id: string): Promise> { return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); } async getAllSdkUrls(): Promise> { diff --git a/payload/webhooks.ts b/payload/webhooks.ts index fc24bc8..e9b8151 100644 --- a/payload/webhooks.ts +++ b/payload/webhooks.ts @@ -1,8 +1,8 @@ import type { Collections } from "./constants"; export type AfterOperationWebHookMessage = { - collection: Collections; - id?: string; - addedDependantIds: string[]; - urls: string[]; - }; \ No newline at end of file + collection: Collections; + id?: string; + addedDependantIds: string[]; + urls: string[]; +}; diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..1dc757e --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,22 @@ +/** @type {import("prettier").Options} */ +module.exports = { + printWidth: 100, + tabWidth: 2, + useTabs: false, + semi: true, + singleQuote: false, + quoteProps: "as-needed", + jsxSingleQuote: false, + trailingComma: "es5", + bracketSpacing: true, + bracketSameLine: true, + arrowParens: "always", + rangeStart: 0, + rangeEnd: Infinity, + requirePragma: false, + insertPragma: false, + proseWrap: "preserve", + htmlWhitespaceSensitivity: "ignore", + endOfLine: "lf", + singleAttributePerLine: false, +};