page.ts 4.0 KB

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