page.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { Ref, Nullable } from './common';
  2. import { IUser } from './user';
  3. import { IRevision, HasRevisionShortbody } from './revision';
  4. import { ITag } from './tag';
  5. import { HasObjectId } from './has-object-id';
  6. import { SubscriptionStatusType } from './subscription';
  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: number,
  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 type IPageHasId = IPage & HasObjectId;
  33. export type IPageForItem = Partial<IPageHasId & {isTarget?: boolean}>;
  34. export type IPageInfo = {
  35. isEmpty: boolean,
  36. isMovable: boolean,
  37. isDeletable: boolean,
  38. isAbleToDeleteCompletely: boolean,
  39. }
  40. export type IPageInfoForEntity = IPageInfo & {
  41. bookmarkCount?: number,
  42. sumOfLikers?: number,
  43. likerIds?: string[],
  44. sumOfSeenUsers?: number,
  45. seenUserIds?: string[],
  46. }
  47. export type IPageInfoForOperation = IPageInfoForEntity & {
  48. isBookmarked?: boolean,
  49. isLiked?: boolean,
  50. subscriptionStatus?: SubscriptionStatusType,
  51. }
  52. export type IPageInfoForListing = IPageInfoForEntity & HasRevisionShortbody;
  53. export type IPageInfoAll = IPageInfo | IPageInfoForEntity | IPageInfoForOperation | IPageInfoForListing;
  54. export const isIPageInfoForEntity = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForEntity => {
  55. return pageInfo != null && !pageInfo.isEmpty;
  56. };
  57. export const isIPageInfoForOperation = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForOperation => {
  58. return pageInfo != null
  59. && isIPageInfoForEntity(pageInfo)
  60. && ('isBookmarked' in pageInfo || 'isLiked' in pageInfo || 'subscriptionStatus' in pageInfo);
  61. };
  62. export const isIPageInfoForListing = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForListing => {
  63. return pageInfo != null
  64. && isIPageInfoForEntity(pageInfo)
  65. && 'revisionShortBody' in pageInfo;
  66. };
  67. // export type IPageInfoTypeResolver<T extends IPageInfo> =
  68. // T extends HasRevisionShortbody ? IPageInfoForListing :
  69. // T extends { isBookmarked?: boolean } | { isLiked?: boolean } | { subscriptionStatus?: SubscriptionStatusType } ? IPageInfoForOperation :
  70. // T extends { bookmarkCount: number } ? IPageInfoForEntity :
  71. // T extends { isEmpty: number } ? IPageInfo :
  72. // T;
  73. /**
  74. * Union Distribution
  75. * @param pageInfo
  76. * @returns
  77. */
  78. // export const resolvePageInfo = <T extends IPageInfo>(pageInfo: T | undefined): IPageInfoTypeResolver<T> => {
  79. // return <IPageInfoTypeResolver<T>>pageInfo;
  80. // };
  81. export type IPageWithMeta<M = IPageInfoAll> = {
  82. pageData: IPageHasId,
  83. pageMeta?: M,
  84. };
  85. export type IDeleteSinglePageApiv1Result = {
  86. ok: boolean
  87. path: string,
  88. isRecursively: Nullable<true>,
  89. isCompletely: Nullable<true>,
  90. };
  91. export type IDeleteManyPageApiv3Result = {
  92. paths: string[],
  93. isRecursively: Nullable<true>,
  94. isCompletely: Nullable<true>,
  95. };