page.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Ref, Nullable } from './common';
  2. import { HasObjectId } from './has-object-id';
  3. import { IPageActionType } from './page-operation';
  4. import { IRevision, HasRevisionShortbody } from './revision';
  5. import { SubscriptionStatusType } from './subscription';
  6. import { ITag } from './tag';
  7. import { IUser } from './user';
  8. export interface IPage {
  9. path: string,
  10. status: string,
  11. revision: Ref<IRevision>,
  12. tags: Ref<ITag>[],
  13. creator: Ref<IUser>,
  14. createdAt: Date,
  15. updatedAt: Date,
  16. seenUsers: Ref<IUser>[],
  17. parent: Ref<IPage> | null,
  18. descendantCount: number,
  19. isEmpty: boolean,
  20. grant: number,
  21. grantedUsers: Ref<IUser>[],
  22. grantedGroup: Ref<any>,
  23. lastUpdateUser: Ref<IUser>,
  24. liker: Ref<IUser>[],
  25. commentCount: number
  26. slackChannels: string,
  27. pageIdOnHackmd: string,
  28. revisionHackmdSynced: Ref<IRevision>,
  29. hasDraftOnHackmd: boolean,
  30. deleteUser: Ref<IUser>,
  31. deletedAt: Date,
  32. }
  33. export type IPageHasId = IPage & HasObjectId;
  34. export type IPageOperationProcessInfo = Partial<Record<IPageActionType, {isProcessing: boolean}>>
  35. export type IPageForItem = Partial<IPageHasId & {isTarget?: boolean}>;
  36. export type IPageInfo = {
  37. isV5Compatible: boolean,
  38. isEmpty: boolean,
  39. isMovable: boolean,
  40. isDeletable: boolean,
  41. isAbleToDeleteCompletely: boolean,
  42. isRevertible: boolean,
  43. }
  44. export type IPageInfoForEntity = IPageInfo & {
  45. bookmarkCount?: number,
  46. sumOfLikers?: number,
  47. likerIds?: string[],
  48. sumOfSeenUsers?: number,
  49. seenUserIds?: string[],
  50. }
  51. export type IPageInfoForOperation = IPageInfoForEntity & {
  52. isBookmarked?: boolean,
  53. isLiked?: boolean,
  54. subscriptionStatus?: SubscriptionStatusType,
  55. }
  56. export type IPageInfoForListing = IPageInfoForEntity & HasRevisionShortbody;
  57. export type IPageInfoAll = IPageInfo | IPageInfoForEntity | IPageInfoForOperation | IPageInfoForListing;
  58. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  59. export const isIPageInfoForEntity = (pageInfo: any | undefined): pageInfo is IPageInfoForEntity => {
  60. return pageInfo != null && ('isEmpty' in pageInfo) && pageInfo.isEmpty === false;
  61. };
  62. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  63. export const isIPageInfoForOperation = (pageInfo: any | undefined): pageInfo is IPageInfoForOperation => {
  64. return pageInfo != null
  65. && isIPageInfoForEntity(pageInfo)
  66. && ('isBookmarked' in pageInfo || 'isLiked' in pageInfo || 'subscriptionStatus' in pageInfo);
  67. };
  68. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  69. export const isIPageInfoForListing = (pageInfo: any | undefined): pageInfo is IPageInfoForListing => {
  70. return pageInfo != null
  71. && isIPageInfoForEntity(pageInfo)
  72. && 'revisionShortBody' in pageInfo;
  73. };
  74. // export type IPageInfoTypeResolver<T extends IPageInfo> =
  75. // T extends HasRevisionShortbody ? IPageInfoForListing :
  76. // T extends { isBookmarked?: boolean } | { isLiked?: boolean } | { subscriptionStatus?: SubscriptionStatusType } ? IPageInfoForOperation :
  77. // T extends { bookmarkCount: number } ? IPageInfoForEntity :
  78. // T extends { isEmpty: number } ? IPageInfo :
  79. // T;
  80. /**
  81. * Union Distribution
  82. * @param pageInfo
  83. * @returns
  84. */
  85. // export const resolvePageInfo = <T extends IPageInfo>(pageInfo: T | undefined): IPageInfoTypeResolver<T> => {
  86. // return <IPageInfoTypeResolver<T>>pageInfo;
  87. // };
  88. export type IDataWithMeta<D = unknown, M = unknown> = {
  89. data: D,
  90. meta?: M,
  91. }
  92. export type IPageWithMeta<M = IPageInfoAll> = IDataWithMeta<IPageHasId, M>;
  93. export type IPageToDeleteWithMeta = IDataWithMeta<HasObjectId & (IPage | { path: string, revision: string }), IPageInfoForEntity | unknown>;
  94. export type IPageToRenameWithMeta = IPageToDeleteWithMeta;
  95. export type IDeleteSinglePageApiv1Result = {
  96. ok: boolean
  97. path: string,
  98. isRecursively: Nullable<true>,
  99. isCompletely: Nullable<true>,
  100. };
  101. export type IDeleteManyPageApiv3Result = {
  102. paths: string[],
  103. isRecursively: Nullable<true>,
  104. isCompletely: Nullable<true>,
  105. };