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 {
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;

View File

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

View File

@ -49,7 +49,6 @@ export type MeiliDocumentRequest =
type: Collections.ChronologyEvents;
};
export type MeiliDocument = MeiliDocumentRequest & {
docId: 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

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

View File

@ -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);

View File

@ -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<PayloadSDKResponse<EndpointPage>> {
return await this.request(getSDKEndpoint.getPageEndpoint(slug));
}
async getCollectible(
slug: string
): Promise<PayloadSDKResponse<EndpointCollectible>> {
async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug));
}
async getCollectibleScans(
slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
}
async getCollectibleScanPage(
slug: string,
index: string
): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> {
return await this.request(
getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)
);
return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index));
}
async getCollectibleGallery(
slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> {
return await this.request(
getSDKEndpoint.getCollectibleGalleryEndpoint(slug)
);
return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug));
}
async getCollectibleGalleryImage(
slug: string,
index: string
): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> {
return await this.request(
getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)
);
return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index));
}
async getChronologyEvents(): Promise<
PayloadSDKResponse<EndpointChronologyEvent[]>
> {
async getChronologyEvents(): Promise<PayloadSDKResponse<EndpointChronologyEvent[]>> {
return await this.request(getSDKEndpoint.getChronologyEventsEndpoint());
}
async getChronologyEventByID(
id: string
): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
return await this.request(
getSDKEndpoint.getChronologyEventByIDEndpoint(id)
);
async getChronologyEventByID(id: string): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id));
}
async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> {
return await this.request(getSDKEndpoint.getImageByIDEndpoint(id));
@ -208,9 +187,7 @@ export class PayloadSDK {
async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> {
return await this.request(getSDKEndpoint.getFileByIDEndpoint(id));
}
async getRecorderByID(
id: string
): Promise<PayloadSDKResponse<EndpointRecorder>> {
async getRecorderByID(id: string): Promise<PayloadSDKResponse<EndpointRecorder>> {
return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id));
}
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {

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