فهرست منبع

WIP refactor types

Yuki Takei 2 سال پیش
والد
کامیت
9fb41afd0d

+ 1 - 0
apps/app/src/interfaces/apiv3/index.ts

@@ -0,0 +1 @@
+export * from './page';

+ 43 - 0
apps/app/src/interfaces/apiv3/page.ts

@@ -0,0 +1,43 @@
+import type {
+  IGrantedGroup, IPageHasId, IRevisionHasId, ITag, PageGrant,
+} from '@growi/core';
+
+export type IApiv3PageCreateParams = {
+  path?: string,
+  parentPath?: string,
+  optionalParentPath?: string,
+
+  body?: string,
+  pageTags?: string[],
+
+  grant?: PageGrant,
+  grantUserGroupIds?: IGrantedGroup[],
+  overwriteScopesOfDescendants?: boolean,
+
+  isSlackEnabled?: boolean,
+  slackChannels?: string,
+};
+
+export type IApiv3PageCreateResponse = {
+  page: IPageHasId,
+  tags: ITag[],
+  revision: IRevisionHasId,
+};
+
+export type IApiv3PageUpdateParams = {
+  pageId: string,
+  revisionId: string,
+  body: string,
+
+  grant?: PageGrant,
+  userRelatedGrantUserGroupIds?: IGrantedGroup[],
+  overwriteScopesOfDescendants?: boolean,
+
+  isSlackEnabled?: boolean,
+  slackChannels?: string,
+};
+
+export type IApiv3PageUpdateResponse = {
+  page: IPageHasId,
+  revision: IRevisionHasId,
+};

+ 0 - 34
apps/app/src/interfaces/page-operation.ts

@@ -1,7 +1,3 @@
-import type {
-  IGrantedGroup, IPageHasId, IRevisionHasId, ITag, PageGrant,
-} from '@growi/core';
-
 export const PageActionType = {
   Create: 'Create',
   Update: 'Update',
@@ -30,33 +26,3 @@ export type IPageOperationProcessData = {
 export type IPageOperationProcessInfo = {
   [pageId: string]: IPageOperationProcessData,
 }
-
-export type OptionsToSave = {
-  isSlackEnabled: boolean;
-  slackChannels: string;
-  grant: PageGrant;
-  // userRelatedGrantUserGroupIds?: IGrantedGroup[];
-  // isSyncRevisionToHackmd?: boolean;
-};
-
-export type IApiv3PageCreateParams = {
-  path?: string,
-  parentPath?: string,
-  optionalParentPath?: string,
-
-  body?: string,
-  pageTags?: string[],
-
-  grant?: PageGrant,
-  grantUserGroupIds?: IGrantedGroup[],
-  overwriteScopesOfDescendants?: boolean,
-
-  isSlackEnabled?: boolean,
-  slackChannels?: string,
-};
-
-export type IApiv3PageCreateResponse = {
-  page: IPageHasId,
-  tags: ITag[],
-  revision: IRevisionHasId,
-};

+ 18 - 1
apps/app/src/interfaces/page.ts

@@ -1,4 +1,6 @@
-import type { GroupType, IPageHasId, Nullable } from '@growi/core';
+import type {
+  GroupType, IGrantedGroup, IPageHasId, Nullable, PageGrant,
+} from '@growi/core';
 
 import type { IPageOperationProcessData } from './page-operation';
 
@@ -29,3 +31,18 @@ export type IDeleteManyPageApiv3Result = {
   isRecursively: Nullable<true>,
   isCompletely: Nullable<true>,
 };
+
+export type IOptionsForUpdate = {
+  grant?: PageGrant,
+  userRelatedGrantUserGroupIds?: IGrantedGroup[],
+  // isSyncRevisionToHackmd?: boolean,
+  overwriteScopesOfDescendants?: boolean,
+};
+
+export type IOptionsForCreate = {
+  // format?: string,
+  grantUserGroupIds?: IGrantedGroup[],
+  grant?: PageGrant,
+  overwriteScopesOfDescendants?: boolean,
+  isSynchronously?: boolean,
+};

+ 0 - 43
apps/app/src/server/models/interfaces/page-operation.ts

@@ -1,43 +0,0 @@
-import { PageGrant, type IGrantedGroup } from '@growi/core';
-
-import { ObjectIdLike } from '../../interfaces/mongoose-utils';
-
-export type IPageForResuming = {
-  _id: ObjectIdLike,
-  path: string,
-  isEmpty: boolean,
-  parent?: ObjectIdLike,
-  grant?: number,
-  grantedUsers?: ObjectIdLike[],
-  grantedGroups: IGrantedGroup[],
-  descendantCount: number,
-  status?: number,
-  revision?: ObjectIdLike,
-  lastUpdateUser?: ObjectIdLike,
-  creator?: ObjectIdLike,
-};
-
-export type IUserForResuming = {
-  _id: ObjectIdLike,
-};
-
-export type IOptionsForUpdate = {
-  grant?: PageGrant,
-  userRelatedGrantUserGroupIds?: IGrantedGroup[],
-  isSyncRevisionToHackmd?: boolean,
-  overwriteScopesOfDescendants?: boolean,
-};
-
-export type IOptionsForCreate = {
-  format?: string,
-  grantUserGroupIds?: IGrantedGroup[],
-  grant?: PageGrant,
-  overwriteScopesOfDescendants?: boolean,
-  isSynchronously?: boolean,
-};
-
-export type IOptionsForResuming = {
-  updateMetadata?: boolean,
-  createRedirectPage?: boolean,
-  prevDescendantCount?: number,
-} & IOptionsForUpdate & IOptionsForCreate;

+ 34 - 6
apps/app/src/server/models/page-operation.ts

@@ -1,17 +1,18 @@
+import type { IGrantedGroup } from '@growi/core';
 import { GroupType } from '@growi/core';
 import { addSeconds } from 'date-fns';
+import type {
+  Model, Document, QueryOptions, FilterQuery,
+} from 'mongoose';
 import mongoose, {
-  Schema, Model, Document, QueryOptions, FilterQuery,
+  Schema,
 } from 'mongoose';
 
+import type { IOptionsForCreate, IOptionsForUpdate } from '~/interfaces/page';
 import { PageActionType, PageActionStage } from '~/interfaces/page-operation';
-import {
-  IPageForResuming, IUserForResuming, IOptionsForResuming,
-} from '~/server/models/interfaces/page-operation';
-
 
 import loggerFactory from '../../utils/logger';
-import { ObjectIdLike } from '../interfaces/mongoose-utils';
+import type { ObjectIdLike } from '../interfaces/mongoose-utils';
 import { getOrCreateModel } from '../util/mongoose-utils';
 
 const TIME_TO_ADD_SEC = 10;
@@ -20,6 +21,33 @@ const logger = loggerFactory('growi:models:page-operation');
 
 const ObjectId = mongoose.Schema.Types.ObjectId;
 
+
+type IPageForResuming = {
+  _id: ObjectIdLike,
+  path: string,
+  isEmpty: boolean,
+  parent?: ObjectIdLike,
+  grant?: number,
+  grantedUsers?: ObjectIdLike[],
+  grantedGroups: IGrantedGroup[],
+  descendantCount: number,
+  status?: number,
+  revision?: ObjectIdLike,
+  lastUpdateUser?: ObjectIdLike,
+  creator?: ObjectIdLike,
+};
+
+type IUserForResuming = {
+  _id: ObjectIdLike,
+};
+
+type IOptionsForResuming = {
+  updateMetadata?: boolean,
+  createRedirectPage?: boolean,
+  prevDescendantCount?: number,
+} & IOptionsForUpdate & IOptionsForCreate;
+
+
 /*
  * Main Schema
  */

+ 4 - 19
apps/app/src/server/routes/apiv3/page/create-page.ts

@@ -1,6 +1,5 @@
 import type {
-  IGrantedGroup,
-  IPage, IUser, IUserHasId, PageGrant,
+  IPage, IUser, IUserHasId,
 } from '@growi/core';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { isCreatablePage, isUserPage } from '@growi/core/dist/utils/page-path-utils';
@@ -11,13 +10,14 @@ import { body } from 'express-validator';
 import mongoose from 'mongoose';
 
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
+import type { IApiv3PageCreateParams } from '~/interfaces/apiv3';
 import { subscribeRuleNames } from '~/interfaces/in-app-notification';
+import type { IOptionsForCreate } from '~/interfaces/page';
 import type Crowi from '~/server/crowi';
 import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
 import {
   GlobalNotificationSettingEvent, serializePageSecurely, serializeRevisionSecurely,
 } from '~/server/models';
-import type { IOptionsForCreate } from '~/server/models/interfaces/page-operation';
 import type { PageDocument, PageModel } from '~/server/models/page';
 import PageTagRelation from '~/server/models/page-tag-relation';
 import { configManager } from '~/server/service/config-manager';
@@ -76,21 +76,7 @@ async function determinePath(parentPath?: string, path?: string, optionalParentP
 }
 
 
-type ReqBody = {
-  path?: string,
-  parentPath?: string,
-  optionalParentPath?: string,
-
-  body?: string,
-  pageTags?: string[],
-
-  grant?: PageGrant,
-  grantUserGroupIds?: IGrantedGroup[],
-  overwriteScopesOfDescendants?: boolean,
-
-  isSlackEnabled?: boolean,
-  slackChannels?: any,
-}
+type ReqBody = IApiv3PageCreateParams
 
 interface CreatePageRequest extends Request<undefined, ApiV3Response, ReqBody> {
   user: IUserHasId,
@@ -121,7 +107,6 @@ export const createPageHandlersFactory: CreatePageHandlersFactory = (crowi) => {
     body('pageTags').optional().isArray().withMessage('pageTags must be array'),
     body('isSlackEnabled').optional().isBoolean().withMessage('isSlackEnabled must be boolean'),
     body('slackChannels').optional().isString().withMessage('slackChannels must be string'),
-    // body('shouldGeneratePath').optional().isBoolean().withMessage('shouldGeneratePath is must be boolean or undefined'),
   ];
 
 

+ 1 - 1
apps/app/src/server/service/page/index.ts

@@ -21,6 +21,7 @@ import { Comment } from '~/features/comment/server';
 import ExternalUserGroupRelation from '~/features/external-user-group/server/models/external-user-group-relation';
 import { SupportedAction } from '~/interfaces/activity';
 import { V5ConversionErrCode } from '~/interfaces/errors/v5-conversion-error';
+import type { IOptionsForCreate, IOptionsForUpdate } from '~/interfaces/page';
 import type { IPageDeleteConfigValueToProcessValidation } from '~/interfaces/page-delete-config';
 import {
   PageDeleteConfigValue, PageSingleDeleteCompConfigValue,
@@ -42,7 +43,6 @@ import { prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
 import type { ObjectIdLike } from '../../interfaces/mongoose-utils';
 import { Attachment } from '../../models';
 import { PathAlreadyExistsError } from '../../models/errors';
-import type { IOptionsForCreate, IOptionsForUpdate } from '../../models/interfaces/page-operation';
 import type { PageOperationDocument } from '../../models/page-operation';
 import PageOperation from '../../models/page-operation';
 import PageRedirect from '../../models/page-redirect';

+ 1 - 1
apps/app/src/server/service/page/page-service.ts

@@ -3,9 +3,9 @@ import type EventEmitter from 'events';
 import type { IPageInfo, IPageInfoForEntity, IUser } from '@growi/core';
 import type { ObjectId } from 'mongoose';
 
+import type { IOptionsForCreate } from '~/interfaces/page';
 import type { PopulatedGrantedGroup } from '~/interfaces/page-grant';
 import type { ObjectIdLike } from '~/server/interfaces/mongoose-utils';
-import type { IOptionsForCreate } from '~/server/models/interfaces/page-operation';
 import type { PageDocument } from '~/server/models/page';
 
 export interface IPageService {