page.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. isRevertible: boolean,
  40. }
  41. export type IPageInfoForEntity = IPageInfo & {
  42. bookmarkCount?: number,
  43. sumOfLikers?: number,
  44. likerIds?: string[],
  45. sumOfSeenUsers?: number,
  46. seenUserIds?: string[],
  47. }
  48. export type IPageInfoForOperation = IPageInfoForEntity & {
  49. isBookmarked?: boolean,
  50. isLiked?: boolean,
  51. subscriptionStatus?: SubscriptionStatusType,
  52. }
  53. export type IPageInfoForListing = IPageInfoForEntity & HasRevisionShortbody;
  54. export type IPageInfoAll = IPageInfo | IPageInfoForEntity | IPageInfoForOperation | IPageInfoForListing;
  55. export const isIPageInfoForEntity = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForEntity => {
  56. return pageInfo != null && !pageInfo.isEmpty;
  57. };
  58. export const isIPageInfoForOperation = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForOperation => {
  59. return pageInfo != null
  60. && isIPageInfoForEntity(pageInfo)
  61. && ('isBookmarked' in pageInfo || 'isLiked' in pageInfo || 'subscriptionStatus' in pageInfo);
  62. };
  63. export const isIPageInfoForListing = (pageInfo: IPageInfoAll | undefined): pageInfo is IPageInfoForListing => {
  64. return pageInfo != null
  65. && isIPageInfoForEntity(pageInfo)
  66. && 'revisionShortBody' in pageInfo;
  67. };
  68. // export type IPageInfoTypeResolver<T extends IPageInfo> =
  69. // T extends HasRevisionShortbody ? IPageInfoForListing :
  70. // T extends { isBookmarked?: boolean } | { isLiked?: boolean } | { subscriptionStatus?: SubscriptionStatusType } ? IPageInfoForOperation :
  71. // T extends { bookmarkCount: number } ? IPageInfoForEntity :
  72. // T extends { isEmpty: number } ? IPageInfo :
  73. // T;
  74. /**
  75. * Union Distribution
  76. * @param pageInfo
  77. * @returns
  78. */
  79. // export const resolvePageInfo = <T extends IPageInfo>(pageInfo: T | undefined): IPageInfoTypeResolver<T> => {
  80. // return <IPageInfoTypeResolver<T>>pageInfo;
  81. // };
  82. export type IPageWithMeta<M = IPageInfoAll> = {
  83. pageData: IPageHasId,
  84. pageMeta?: M,
  85. };
  86. export type IDeleteSinglePageApiv1Result = {
  87. ok: boolean
  88. path: string,
  89. isRecursively: Nullable<true>,
  90. isCompletely: Nullable<true>,
  91. };
  92. export type IDeleteManyPageApiv3Result = {
  93. paths: string[],
  94. isRecursively: Nullable<true>,
  95. isCompletely: Nullable<true>,
  96. };