page.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. isV5Compatible: boolean,
  36. isEmpty: boolean,
  37. isMovable: boolean,
  38. isDeletable: boolean,
  39. isAbleToDeleteCompletely: boolean,
  40. isRevertible: boolean,
  41. }
  42. export type IPageInfoForEntity = IPageInfo & {
  43. bookmarkCount?: number,
  44. sumOfLikers?: number,
  45. likerIds?: string[],
  46. sumOfSeenUsers?: number,
  47. seenUserIds?: string[],
  48. }
  49. export type IPageInfoForOperation = IPageInfoForEntity & {
  50. isBookmarked?: boolean,
  51. isLiked?: boolean,
  52. subscriptionStatus?: SubscriptionStatusType,
  53. }
  54. export type IPageInfoForListing = IPageInfoForEntity & HasRevisionShortbody;
  55. export type IPageInfoAll = IPageInfo | IPageInfoForEntity | IPageInfoForOperation | IPageInfoForListing;
  56. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  57. export const isIPageInfoForEntity = (pageInfo: any | undefined): pageInfo is IPageInfoForEntity => {
  58. return pageInfo != null && ('isEmpty' in pageInfo) && pageInfo.isEmpty === false;
  59. };
  60. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  61. export const isIPageInfoForOperation = (pageInfo: any | undefined): pageInfo is IPageInfoForOperation => {
  62. return pageInfo != null
  63. && isIPageInfoForEntity(pageInfo)
  64. && ('isBookmarked' in pageInfo || 'isLiked' in pageInfo || 'subscriptionStatus' in pageInfo);
  65. };
  66. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  67. export const isIPageInfoForListing = (pageInfo: any | undefined): pageInfo is IPageInfoForListing => {
  68. return pageInfo != null
  69. && isIPageInfoForEntity(pageInfo)
  70. && 'revisionShortBody' in pageInfo;
  71. };
  72. // export type IPageInfoTypeResolver<T extends IPageInfo> =
  73. // T extends HasRevisionShortbody ? IPageInfoForListing :
  74. // T extends { isBookmarked?: boolean } | { isLiked?: boolean } | { subscriptionStatus?: SubscriptionStatusType } ? IPageInfoForOperation :
  75. // T extends { bookmarkCount: number } ? IPageInfoForEntity :
  76. // T extends { isEmpty: number } ? IPageInfo :
  77. // T;
  78. /**
  79. * Union Distribution
  80. * @param pageInfo
  81. * @returns
  82. */
  83. // export const resolvePageInfo = <T extends IPageInfo>(pageInfo: T | undefined): IPageInfoTypeResolver<T> => {
  84. // return <IPageInfoTypeResolver<T>>pageInfo;
  85. // };
  86. export type IDataWithMeta<D = unknown, M = unknown> = {
  87. data: D,
  88. meta?: M,
  89. }
  90. export type IPageWithMeta<M = IPageInfoAll> = IDataWithMeta<IPageHasId, M>;
  91. export type IPageToDeleteWithMeta = IDataWithMeta<HasObjectId & (IPage | { path: string, revision: string }), IPageInfoForEntity | unknown>;
  92. export type IPageToRenameWithMeta = IPageToDeleteWithMeta;
  93. export type IDeleteSinglePageApiv1Result = {
  94. ok: boolean
  95. path: string,
  96. isRecursively: Nullable<true>,
  97. isCompletely: Nullable<true>,
  98. };
  99. export type IDeleteManyPageApiv3Result = {
  100. paths: string[],
  101. isRecursively: Nullable<true>,
  102. isCompletely: Nullable<true>,
  103. };