page.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. isContainerFluid: boolean,
  30. deleteUser: Ref<IUser>,
  31. deletedAt: Date,
  32. }
  33. export const PageGrant = {
  34. GRANT_PUBLIC: 1,
  35. GRANT_RESTRICTED: 2,
  36. GRANT_SPECIFIED: 3, // DEPRECATED
  37. GRANT_OWNER: 4,
  38. GRANT_USER_GROUP: 5,
  39. };
  40. export type PageGrant = typeof PageGrant[keyof typeof PageGrant];
  41. export type IPageHasId = IPage & HasObjectId;
  42. export type IPageForItem = Partial<IPageHasId & {isTarget?: boolean}>;
  43. export type IPageInfo = {
  44. isV5Compatible: boolean,
  45. isEmpty: boolean,
  46. isMovable: boolean,
  47. isDeletable: boolean,
  48. isAbleToDeleteCompletely: boolean,
  49. isRevertible: boolean,
  50. isContainerFluid?: boolean,
  51. }
  52. export type IPageInfoForEntity = IPageInfo & {
  53. bookmarkCount?: number,
  54. sumOfLikers?: number,
  55. likerIds?: string[],
  56. sumOfSeenUsers?: number,
  57. seenUserIds?: string[],
  58. }
  59. export type IPageInfoForOperation = IPageInfoForEntity & {
  60. isBookmarked?: boolean,
  61. isLiked?: boolean,
  62. subscriptionStatus?: SubscriptionStatusType,
  63. }
  64. export type IPageInfoForListing = IPageInfoForEntity & HasRevisionShortbody;
  65. export type IPageInfoAll = IPageInfo | IPageInfoForEntity | IPageInfoForOperation | IPageInfoForListing;
  66. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  67. export const isIPageInfoForEntity = (pageInfo: any | undefined): pageInfo is IPageInfoForEntity => {
  68. return pageInfo != null && ('isEmpty' in pageInfo) && pageInfo.isEmpty === false;
  69. };
  70. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  71. export const isIPageInfoForOperation = (pageInfo: any | undefined): pageInfo is IPageInfoForOperation => {
  72. return pageInfo != null
  73. && isIPageInfoForEntity(pageInfo)
  74. && ('isBookmarked' in pageInfo || 'isLiked' in pageInfo || 'subscriptionStatus' in pageInfo || 'isContainerFluid' in pageInfo);
  75. };
  76. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  77. export const isIPageInfoForListing = (pageInfo: any | undefined): pageInfo is IPageInfoForListing => {
  78. return pageInfo != null
  79. && isIPageInfoForEntity(pageInfo)
  80. && 'revisionShortBody' in pageInfo;
  81. };
  82. // export type IPageInfoTypeResolver<T extends IPageInfo> =
  83. // T extends HasRevisionShortbody ? IPageInfoForListing :
  84. // T extends { isBookmarked?: boolean } | { isLiked?: boolean } | { subscriptionStatus?: SubscriptionStatusType } ? IPageInfoForOperation :
  85. // T extends { bookmarkCount: number } ? IPageInfoForEntity :
  86. // T extends { isEmpty: number } ? IPageInfo :
  87. // T;
  88. /**
  89. * Union Distribution
  90. * @param pageInfo
  91. * @returns
  92. */
  93. // export const resolvePageInfo = <T extends IPageInfo>(pageInfo: T | undefined): IPageInfoTypeResolver<T> => {
  94. // return <IPageInfoTypeResolver<T>>pageInfo;
  95. // };
  96. export type IDataWithMeta<D = unknown, M = unknown> = {
  97. data: D,
  98. meta?: M,
  99. }
  100. export type IPageWithMeta<M = IPageInfoAll> = IDataWithMeta<IPageHasId, M>;
  101. export type IPageToDeleteWithMeta = IDataWithMeta<HasObjectId & (IPage | { path: string, revision: string }), IPageInfoForEntity | unknown>;
  102. export type IPageToRenameWithMeta = IPageToDeleteWithMeta;
  103. export type IPageGrantData = {
  104. grant: number,
  105. grantedGroup?: {
  106. id: string,
  107. name: string
  108. }
  109. }
  110. export type IDeleteSinglePageApiv1Result = {
  111. ok: boolean
  112. path: string,
  113. isRecursively: Nullable<true>,
  114. isCompletely: Nullable<true>,
  115. };
  116. export type IDeleteManyPageApiv3Result = {
  117. paths: string[],
  118. isRecursively: Nullable<true>,
  119. isCompletely: Nullable<true>,
  120. };