Added prettier script to standardize formatting

This commit is contained in:
DrMint 2024-07-21 10:00:36 +02:00
parent 806543a487
commit a50cee7636
13 changed files with 163 additions and 147 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -8,10 +8,7 @@ type AnalyticsBody = Record<string, unknown> & {
export class AnalyticsSDK { export class AnalyticsSDK {
constructor(private readonly apiURL: string) {} constructor(private readonly apiURL: string) {}
trackRequest( trackRequest(request: Request, { clientAddress, locale, responseStatus }: TrackRequestParams) {
request: Request,
{ clientAddress, locale, responseStatus }: TrackRequestParams
) {
const userAgent = request.headers.get("User-Agent"); const userAgent = request.headers.get("User-Agent");
const acceptLanguage = request.headers.get("Accept-Language"); const acceptLanguage = request.headers.get("Accept-Language");
const { method, url: stringUrl, referrer } = request; const { method, url: stringUrl, referrer } = request;

View File

@ -6,11 +6,7 @@ export class MeilisearchSDK {
private readonly bearer: string private readonly bearer: string
) {} ) {}
async search({ async search({ q, page, types }: SearchRequest): Promise<SearchResponse<MeiliDocument>> {
q,
page,
types,
}: SearchRequest): Promise<SearchResponse<MeiliDocument>> {
const filter: string[] = []; const filter: string[] = [];
if (types) { if (types) {

View File

@ -49,7 +49,6 @@ export type MeiliDocumentRequest =
type: Collections.ChronologyEvents; type: Collections.ChronologyEvents;
}; };
export type MeiliDocument = MeiliDocumentRequest & { export type MeiliDocument = MeiliDocumentRequest & {
docId: string; docId: string;
distinctId: string; distinctId: string;

31
package-lock.json generated Normal file
View File

@ -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"
}
}
}
}

13
package.json Normal file
View File

@ -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"
}
}

View File

@ -3,45 +3,45 @@ import type { RichTextContent } from "./rich-text";
export interface TranscriptBlock extends GenericBlock { export interface TranscriptBlock extends GenericBlock {
lines: (LineBlock | CueBlock)[]; lines: (LineBlock | CueBlock)[];
blockType: "transcriptBlock"; blockType: "transcriptBlock";
} }
export interface BreakBlock extends GenericBlock { export interface BreakBlock extends GenericBlock {
type: "Scene break" | "Empty space" | "Solid line" | "Dotted line"; type: "Scene break" | "Empty space" | "Solid line" | "Dotted line";
blockType: "breakBlock"; blockType: "breakBlock";
} }
export interface SectionBlock extends GenericBlock { export interface SectionBlock extends GenericBlock {
content: RichTextContent; content: RichTextContent;
blockType: "sectionBlock"; blockType: "sectionBlock";
} }
export interface CueBlock extends GenericBlock { export interface CueBlock extends GenericBlock {
content: RichTextContent; content: RichTextContent;
blockType: "cueBlock"; blockType: "cueBlock";
} }
export interface LineBlock extends GenericBlock { export interface LineBlock extends GenericBlock {
content: RichTextContent; content: RichTextContent;
blockType: "lineBlock"; blockType: "lineBlock";
} }
export interface GenericBlock { export interface GenericBlock {
id?: string | null; id?: string | null;
blockName?: string | null; blockName?: string | null;
blockType: string; blockType: string;
} }
export const isBlockTranscriptBlock = (block: GenericBlock): block is TranscriptBlock => export const isBlockTranscriptBlock = (block: GenericBlock): block is TranscriptBlock =>
block.blockType === "transcriptBlock"; block.blockType === "transcriptBlock";
export const isBlockBreakBlock = (block: GenericBlock): block is BreakBlock => export const isBlockBreakBlock = (block: GenericBlock): block is BreakBlock =>
block.blockType === "breakBlock"; block.blockType === "breakBlock";
export const isBlockSectionBlock = (block: GenericBlock): block is SectionBlock => export const isBlockSectionBlock = (block: GenericBlock): block is SectionBlock =>
block.blockType === "sectionBlock"; block.blockType === "sectionBlock";
export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => export const isBlockCueBlock = (block: GenericBlock): block is CueBlock =>
block.blockType === "cueBlock"; block.blockType === "cueBlock";
export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => export const isBlockLineBlock = (block: GenericBlock): block is LineBlock =>
block.blockType === "lineBlock"; block.blockType === "lineBlock";

View File

@ -22,17 +22,12 @@ const formatList = (node: RichTextListNode) => {
const formatBlock = (node: RichTextBlockNode) => { const formatBlock = (node: RichTextBlockNode) => {
if (isBlockNodeSectionBlock(node)) { if (isBlockNodeSectionBlock(node)) {
return ( return `\n\n${node.fields.blockName}\n` + formatRichTextContentToString(node.fields.content);
`\n\n${node.fields.blockName}\n` +
formatRichTextContentToString(node.fields.content)
);
} else if (isBlockNodeTranscriptBlock(node)) { } else if (isBlockNodeTranscriptBlock(node)) {
return node.fields.lines return node.fields.lines
.map((block) => { .map((block) => {
if (isBlockLineBlock(block)) { if (isBlockLineBlock(block)) {
return `${block.blockName} | ${formatRichTextContentToString( return `${block.blockName} | ${formatRichTextContentToString(block.content)}`;
block.content
)}`;
} else if (isBlockCueBlock(block)) { } else if (isBlockCueBlock(block)) {
return formatRichTextContentToString(block.content); return formatRichTextContentToString(block.content);
} }
@ -71,9 +66,8 @@ const formatNode = (node: RichTextNode): string => {
return ""; return "";
}; };
export const formatRichTextContentToString = ( export const formatRichTextContentToString = (content: RichTextContent): string =>
content: RichTextContent content.root.children.map(formatNode).join("\n\n");
): string => content.root.children.map(formatNode).join("\n\n");
export const formatInlineTitle = ({ export const formatInlineTitle = ({
pretitle, pretitle,

View File

@ -138,50 +138,40 @@ export interface RichTextBreakBlock extends RichTextBlockNode {
anchorHash: string; anchorHash: string;
} }
export const isNodeParagraphNode = ( export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode =>
node: RichTextNode node.type === "paragraph";
): node is RichTextParagraphNode => node.type === "paragraph";
export const isNodeUploadNode = ( export const isNodeUploadNode = (node: RichTextNode): node is RichTextUploadNode =>
node: RichTextNode node.type === "upload";
): node is RichTextUploadNode => node.type === "upload";
export const isUploadNodeImageNode = ( export const isUploadNodeImageNode = (node: RichTextUploadNode): node is RichTextUploadImageNode =>
node: RichTextUploadNode node.relationTo === Collections.Images;
): node is RichTextUploadImageNode => node.relationTo === Collections.Images;
export const isUploadNodeVideoNode = ( export const isUploadNodeVideoNode = (node: RichTextUploadNode): node is RichTextUploadVideoNode =>
node: RichTextUploadNode node.relationTo === Collections.Videos;
): node is RichTextUploadVideoNode => node.relationTo === Collections.Videos;
export const isUploadNodeAudioNode = ( export const isUploadNodeAudioNode = (node: RichTextUploadNode): node is RichTextUploadAudioNode =>
node: RichTextUploadNode node.relationTo === Collections.Audios;
): node is RichTextUploadAudioNode => node.relationTo === Collections.Audios;
export const isNodeListNode = (node: RichTextNode): node is RichTextListNode => export const isNodeListNode = (node: RichTextNode): node is RichTextListNode =>
node.type === "list"; node.type === "list";
export const isListNodeNumberListNode = ( export const isListNodeNumberListNode = (node: RichTextListNode): node is RichTextListNumberNode =>
node: RichTextListNode node.listType === "number";
): node is RichTextListNumberNode => node.listType === "number";
export const isListNodeBulletListNode = ( export const isListNodeBulletListNode = (node: RichTextListNode): node is RichTextListBulletNode =>
node: RichTextListNode node.listType === "bullet";
): node is RichTextListBulletNode => node.listType === "bullet";
export const isListNodeCheckListNode = ( export const isListNodeCheckListNode = (node: RichTextListNode): node is RichTextListCheckNode =>
node: RichTextListNode node.listType === "check";
): node is RichTextListCheckNode => node.listType === "check";
export const isNodeLinebreakNode = ( export const isNodeLinebreakNode = (node: RichTextNode): node is RichTextLinebreakNode =>
node: RichTextNode node.type === "linebreak";
): node is RichTextLinebreakNode => node.type === "linebreak";
export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode => export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode =>
node.type === "text"; node.type === "text";
export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => node.type === "tab";
node.type === "tab";
export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode => export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode =>
node.type === "link"; node.type === "link";
@ -190,22 +180,18 @@ export const isLinkNodeInternalLinkNode = (
node: RichTextLinkNode node: RichTextLinkNode
): node is RichTextLinkInternalNode => node.fields.linkType === "internal"; ): node is RichTextLinkInternalNode => node.fields.linkType === "internal";
export const isLinkNodeCustomLinkNode = ( export const isLinkNodeCustomLinkNode = (node: RichTextLinkNode): node is RichTextLinkCustomNode =>
node: RichTextLinkNode node.fields.linkType === "custom";
): node is RichTextLinkCustomNode => node.fields.linkType === "custom";
export const isNodeBlockNode = ( export const isNodeBlockNode = (node: RichTextNode): node is RichTextBlockNode =>
node: RichTextNode node.type === "block";
): node is RichTextBlockNode => node.type === "block";
export const isBlockNodeSectionBlock = ( export const isBlockNodeSectionBlock = (node: RichTextBlockNode): node is RichTextSectionBlock =>
node: RichTextBlockNode node.fields.blockType === "sectionBlock";
): node is RichTextSectionBlock => node.fields.blockType === "sectionBlock";
export const isBlockNodeTranscriptBlock = ( export const isBlockNodeTranscriptBlock = (
node: RichTextBlockNode node: RichTextBlockNode
): node is RichTextTranscriptBlock => isBlockTranscriptBlock(node.fields); ): node is RichTextTranscriptBlock => isBlockTranscriptBlock(node.fields);
export const isBlockNodeBreakBlock = ( export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock =>
node: RichTextBlockNode isBlockBreakBlock(node.fields);
): node is RichTextBreakBlock => isBlockBreakBlock(node.fields);

View File

@ -28,10 +28,8 @@ export const getSDKEndpoint = {
getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`,
getWordingsEndpoint: () => `/${Collections.Wordings}/all`, getWordingsEndpoint: () => `/${Collections.Wordings}/all`,
getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`,
getCollectibleEndpoint: (slug: string) => getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`,
`/${Collections.Collectibles}/slug/${slug}`, getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`,
getCollectibleScansEndpoint: (slug: string) =>
`/${Collections.Collectibles}/slug/${slug}/scans`,
getCollectibleScanPageEndpoint: (slug: string, index: string) => getCollectibleScanPageEndpoint: (slug: string, index: string) =>
`/${Collections.Collectibles}/slug/${slug}/scans/${index}`, `/${Collections.Collectibles}/slug/${slug}/scans/${index}`,
getCollectibleGalleryEndpoint: (slug: string) => getCollectibleGalleryEndpoint: (slug: string) =>
@ -39,8 +37,7 @@ export const getSDKEndpoint = {
getCollectibleGalleryImageEndpoint: (slug: string, index: string) => getCollectibleGalleryImageEndpoint: (slug: string, index: string) =>
`/${Collections.Collectibles}/slug/${slug}/gallery/${index}`, `/${Collections.Collectibles}/slug/${slug}/gallery/${index}`,
getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`, getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`,
getChronologyEventByIDEndpoint: (id: string) => getChronologyEventByIDEndpoint: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`,
`/${Collections.ChronologyEvents}/id/${id}`,
getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`, getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`,
getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`, getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`,
getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`, getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`,
@ -117,9 +114,7 @@ export class PayloadSDK {
const result = await fetch(`${this.apiURL}${endpoint}`, { const result = await fetch(`${this.apiURL}${endpoint}`, {
headers: { headers: {
Authorization: `JWT ${ Authorization: `JWT ${this.tokenCache?.get() ?? (await this.refreshToken())}`,
this.tokenCache?.get() ?? (await this.refreshToken())
}`,
}, },
}); });
this.logResponse(result); this.logResponse(result);
@ -151,50 +146,34 @@ export class PayloadSDK {
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> { async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
return await this.request(getSDKEndpoint.getPageEndpoint(slug)); return await this.request(getSDKEndpoint.getPageEndpoint(slug));
} }
async getCollectible( async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
slug: string
): Promise<PayloadSDKResponse<EndpointCollectible>> {
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug));
} }
async getCollectibleScans( async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
} }
async getCollectibleScanPage( async getCollectibleScanPage(
slug: string, slug: string,
index: string index: string
): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> { ): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> {
return await this.request( return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index));
getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)
);
} }
async getCollectibleGallery( async getCollectibleGallery(
slug: string slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> { ): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> {
return await this.request( return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug));
getSDKEndpoint.getCollectibleGalleryEndpoint(slug)
);
} }
async getCollectibleGalleryImage( async getCollectibleGalleryImage(
slug: string, slug: string,
index: string index: string
): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> { ): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> {
return await this.request( return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index));
getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)
);
} }
async getChronologyEvents(): Promise< async getChronologyEvents(): Promise<PayloadSDKResponse<EndpointChronologyEvent[]>> {
PayloadSDKResponse<EndpointChronologyEvent[]>
> {
return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); return await this.request(getSDKEndpoint.getChronologyEventsEndpoint());
} }
async getChronologyEventByID( async getChronologyEventByID(id: string): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
id: string return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id));
): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
return await this.request(
getSDKEndpoint.getChronologyEventByIDEndpoint(id)
);
} }
async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> { async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> {
return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); return await this.request(getSDKEndpoint.getImageByIDEndpoint(id));
@ -208,9 +187,7 @@ export class PayloadSDK {
async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> { async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> {
return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); return await this.request(getSDKEndpoint.getFileByIDEndpoint(id));
} }
async getRecorderByID( async getRecorderByID(id: string): Promise<PayloadSDKResponse<EndpointRecorder>> {
id: string
): Promise<PayloadSDKResponse<EndpointRecorder>> {
return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id));
} }
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> { async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {

View File

@ -5,4 +5,4 @@ export type AfterOperationWebHookMessage = {
id?: string; id?: string;
addedDependantIds: string[]; addedDependantIds: string[];
urls: string[]; urls: string[];
}; };

22
prettier.config.js Normal file
View File

@ -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,
};