Przeglądaj źródła

configure biome for app/server/events, app/server/interfaces

Futa Arai 5 miesięcy temu
rodzic
commit
ae5a97d56c

+ 2 - 2
apps/app/src/server/events/bookmark.js

@@ -9,7 +9,7 @@ function BookmarkEvent(crowi) {
 }
 util.inherits(BookmarkEvent, events.EventEmitter);
 
-BookmarkEvent.prototype.onCreate = function(bookmark) {};
-BookmarkEvent.prototype.onDelete = function(bookmark) {};
+BookmarkEvent.prototype.onCreate = (bookmark) => {};
+BookmarkEvent.prototype.onDelete = (bookmark) => {};
 
 module.exports = BookmarkEvent;

+ 4 - 4
apps/app/src/server/events/page.js

@@ -13,16 +13,16 @@ function PageEvent(crowi) {
 }
 util.inherits(PageEvent, events.EventEmitter);
 
-PageEvent.prototype.onCreate = function(page, user) {
+PageEvent.prototype.onCreate = (page, user) => {
   logger.debug('onCreate event fired');
 };
-PageEvent.prototype.onUpdate = function(page, user) {
+PageEvent.prototype.onUpdate = (page, user) => {
   logger.debug('onUpdate event fired');
 };
-PageEvent.prototype.onCreateMany = function(pages, user) {
+PageEvent.prototype.onCreateMany = (pages, user) => {
   logger.debug('onCreateMany event fired');
 };
-PageEvent.prototype.onAddSeenUsers = function(pages, user) {
+PageEvent.prototype.onAddSeenUsers = (pages, user) => {
   logger.debug('onAddSeenUsers event fired');
 };
 module.exports = PageEvent;

+ 1 - 1
apps/app/src/server/events/tag.js

@@ -9,6 +9,6 @@ function TagEvent(crowi) {
 }
 util.inherits(TagEvent, events.EventEmitter);
 
-TagEvent.prototype.onUpdate = function(tag) { };
+TagEvent.prototype.onUpdate = (tag) => {};
 
 module.exports = TagEvent;

+ 19 - 11
apps/app/src/server/events/user.ts

@@ -1,7 +1,6 @@
-import EventEmitter from 'events';
-
 import { getIdStringForRef, type IUserHasId } from '@growi/core';
 import { pagePathUtils } from '@growi/core/dist/utils';
+import EventEmitter from 'events';
 import type { HydratedDocument } from 'mongoose';
 import mongoose from 'mongoose';
 
@@ -13,7 +12,6 @@ import { deleteCompletelyUserHomeBySystem } from '../service/page/delete-complet
 const logger = loggerFactory('growi:events:user');
 
 class UserEvent extends EventEmitter {
-
   crowi: any;
 
   // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -23,14 +21,26 @@ class UserEvent extends EventEmitter {
   }
 
   async onActivated(user: IUserHasId): Promise<void> {
-    const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>('Page');
+    const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>(
+      'Page',
+    );
     const userHomepagePath = pagePathUtils.userHomepagePath(user);
 
     try {
-      let page: HydratedDocument<PageDocument> | null = await Page.findByPath(userHomepagePath, true);
-
-      if (page != null && page.creator != null && getIdStringForRef(page.creator) !== user._id.toString()) {
-        await deleteCompletelyUserHomeBySystem(userHomepagePath, this.crowi.pageService);
+      let page: HydratedDocument<PageDocument> | null = await Page.findByPath(
+        userHomepagePath,
+        true,
+      );
+
+      if (
+        page != null &&
+        page.creator != null &&
+        getIdStringForRef(page.creator) !== user._id.toString()
+      ) {
+        await deleteCompletelyUserHomeBySystem(
+          userHomepagePath,
+          this.crowi.pageService,
+        );
         page = null;
       }
 
@@ -40,12 +50,10 @@ class UserEvent extends EventEmitter {
         await this.crowi.pageService.create(userHomepagePath, body, user, {});
         logger.debug('User page created', page);
       }
-    }
-    catch (err) {
+    } catch (err) {
       logger.error('Failed to create user page', err);
     }
   }
-
 }
 
 export default UserEvent;

+ 8 - 8
apps/app/src/server/interfaces/attachment.ts

@@ -5,12 +5,12 @@ export const AttachmentType = {
   PAGE_BULK_EXPORT: 'PAGE_BULK_EXPORT',
 } as const;
 
-export type AttachmentType = typeof AttachmentType[keyof typeof AttachmentType];
-
+export type AttachmentType =
+  (typeof AttachmentType)[keyof typeof AttachmentType];
 
 export type ExpressHttpHeader<Field = string> = {
-  field: Field,
-  value: string | string[]
+  field: Field;
+  value: string | string[];
 };
 
 export type IContentHeaders = {
@@ -18,18 +18,18 @@ export type IContentHeaders = {
   contentLength?: ExpressHttpHeader<'Content-Length'>;
   contentSecurityPolicy?: ExpressHttpHeader<'Content-Security-Policy'>;
   contentDisposition?: ExpressHttpHeader<'Content-Disposition'>;
-}
+};
 
 export type RespondOptions = {
-  download?: boolean,
-}
+  download?: boolean;
+};
 
 export const ResponseMode = {
   RELAY: 'relay',
   REDIRECT: 'redirect',
   DELEGATE: 'delegate',
 } as const;
-export type ResponseMode = typeof ResponseMode[keyof typeof ResponseMode];
+export type ResponseMode = (typeof ResponseMode)[keyof typeof ResponseMode];
 
 export const FilePathOnStoragePrefix = {
   attachment: 'attachment',

+ 54 - 26
apps/app/src/server/interfaces/search.ts

@@ -2,49 +2,77 @@
 import type { SearchDelegatorName } from '~/interfaces/named-query';
 import type { ISearchResult } from '~/interfaces/search';
 
-
 export type QueryTerms = {
-  match: string[],
-  not_match: string[],
-  phrase: string[],
-  not_phrase: string[],
-  prefix: string[],
-  not_prefix: string[],
-  tag: string[],
-  not_tag: string[],
-}
+  match: string[];
+  not_match: string[];
+  phrase: string[];
+  not_phrase: string[];
+  prefix: string[];
+  not_prefix: string[];
+  tag: string[];
+  not_tag: string[];
+};
 
-export type ParsedQuery = { queryString: string, terms: QueryTerms, delegatorName?: string }
+export type ParsedQuery = {
+  queryString: string;
+  terms: QueryTerms;
+  delegatorName?: string;
+};
 
 export interface SearchQueryParser {
-  parseSearchQuery(queryString: string, nqName: string | null): Promise<ParsedQuery>
+  parseSearchQuery(
+    queryString: string,
+    nqName: string | null,
+  ): Promise<ParsedQuery>;
 }
 
 export interface SearchResolver {
-  resolve(parsedQuery: ParsedQuery): Promise<[SearchDelegator, SearchableData | null]>
+  resolve(
+    parsedQuery: ParsedQuery,
+  ): Promise<[SearchDelegator, SearchableData | null]>;
 }
 
-export interface SearchDelegator<T = unknown, KEY extends AllTermsKey = AllTermsKey, QTERMS = QueryTerms> {
-  name?: SearchDelegatorName
-  search(data: SearchableData | null, user, userGroups, option): Promise<ISearchResult<T>>
-  isTermsNormalized(terms: Partial<QueryTerms>): terms is Partial<QTERMS>,
-  validateTerms(terms: QueryTerms): UnavailableTermsKey<KEY>[],
+export interface SearchDelegator<
+  T = unknown,
+  KEY extends AllTermsKey = AllTermsKey,
+  QTERMS = QueryTerms,
+> {
+  name?: SearchDelegatorName;
+  search(
+    data: SearchableData | null,
+    user,
+    userGroups,
+    option,
+  ): Promise<ISearchResult<T>>;
+  isTermsNormalized(terms: Partial<QueryTerms>): terms is Partial<QTERMS>;
+  validateTerms(terms: QueryTerms): UnavailableTermsKey<KEY>[];
 }
 
 export type SearchableData<T = Partial<QueryTerms>> = {
-  queryString: string
-  terms: T
-}
+  queryString: string;
+  terms: T;
+};
 
 export type UpdateOrInsertPagesOpts = {
-  shouldEmitProgress?: boolean
-  invokeGarbageCollection?: boolean
-}
+  shouldEmitProgress?: boolean;
+  invokeGarbageCollection?: boolean;
+};
 
 // Terms Key types
 export type AllTermsKey = keyof QueryTerms;
-export type UnavailableTermsKey<K extends AllTermsKey> = Exclude<AllTermsKey, K>;
-export type ESTermsKey = 'match' | 'not_match' | 'phrase' | 'not_phrase' | 'prefix' | 'not_prefix' | 'tag' | 'not_tag';
+export type UnavailableTermsKey<K extends AllTermsKey> = Exclude<
+  AllTermsKey,
+  K
+>;
+export type ESTermsKey =
+  | 'match'
+  | 'not_match'
+  | 'phrase'
+  | 'not_phrase'
+  | 'prefix'
+  | 'not_prefix'
+  | 'tag'
+  | 'not_tag';
 export type MongoTermsKey = 'match' | 'not_match' | 'prefix' | 'not_prefix';
 
 // Query Terms types

+ 1 - 1
apps/app/src/server/interfaces/slack-integration/events.ts

@@ -1 +1 @@
-export type EventActionsPermission = Map<string, boolean | string[]>
+export type EventActionsPermission = Map<string, boolean | string[]>;

+ 20 - 20
apps/app/src/server/interfaces/slack-integration/link-shared-unfurl.ts

@@ -1,32 +1,32 @@
 export type PrivateData = {
-  isPublic: false,
-  isPermalink: boolean,
-  id: string,
-  path: string,
-}
+  isPublic: false;
+  isPermalink: boolean;
+  id: string;
+  path: string;
+};
 
 export type PublicData = {
-  isPublic: true,
-  isPermalink: boolean,
-  id: string,
-  path: string,
-  pageBody: string,
-  updatedAt: Date,
-  commentCount: number,
-}
+  isPublic: true;
+  isPermalink: boolean;
+  id: string;
+  path: string;
+  pageBody: string;
+  updatedAt: Date;
+  commentCount: number;
+};
 
 export type DataForUnfurl = PrivateData | PublicData;
 
 export type UnfurlEventLink = {
-  url: string,
-  domain: string,
-}
+  url: string;
+  domain: string;
+};
 
 export type UnfurlRequestEvent = {
-  channel: string,
+  channel: string;
 
   // eslint-disable-next-line camelcase
-  message_ts: string,
+  message_ts: string;
 
-  links: UnfurlEventLink[],
-}
+  links: UnfurlEventLink[];
+};

+ 0 - 2
biome.json

@@ -30,8 +30,6 @@
       "!apps/app/playwright",
       "!apps/app/src/client",
       "!apps/app/src/features/openai",
-      "!apps/app/src/server/events",
-      "!apps/app/src/server/interfaces",
       "!apps/app/src/server/middlewares",
       "!apps/app/src/server/models",
       "!apps/app/src/server/routes",