growi-app-info.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import type * as os from 'node:os';
  2. import type { GrowiDeploymentType, GrowiServiceType } from '../consts/system';
  3. export const GrowiWikiType = { open: 'open', closed: 'closed' } as const;
  4. type GrowiWikiType = (typeof GrowiWikiType)[keyof typeof GrowiWikiType];
  5. // Info options for additionalInfo selection
  6. export interface GrowiInfoOptions {
  7. includeAttachmentInfo?: boolean;
  8. includeInstalledInfo?: boolean;
  9. includeUserCountInfo?: boolean;
  10. includePageCountInfo?: boolean;
  11. // Future extensions can be added here
  12. }
  13. interface IGrowiOSInfo {
  14. type?: ReturnType<typeof os.type>;
  15. platform?: ReturnType<typeof os.platform>;
  16. arch?: ReturnType<typeof os.arch>;
  17. totalmem?: ReturnType<typeof os.totalmem>;
  18. }
  19. interface IAdditionalAttachmentInfo {
  20. attachmentType: string;
  21. activeExternalAccountTypes: string[];
  22. }
  23. interface IAdditionalInstalledAtInfo {
  24. installedAt: Date;
  25. installedAtByOldestUser: Date | null;
  26. }
  27. interface IAdditionalUserCountInfo {
  28. currentUsersCount: number;
  29. currentActiveUsersCount: number;
  30. }
  31. interface IAdditionalPageCountInfo {
  32. currentPagesCount: number;
  33. }
  34. export interface IGrowiAdditionalInfo
  35. extends IAdditionalInstalledAtInfo,
  36. IAdditionalUserCountInfo,
  37. IAdditionalPageCountInfo,
  38. IAdditionalAttachmentInfo {}
  39. // Type mapping for flexible options
  40. export type IGrowiAdditionalInfoByOptions<T extends GrowiInfoOptions> =
  41. (T['includeAttachmentInfo'] extends true
  42. ? IAdditionalAttachmentInfo
  43. : Record<string, never>) &
  44. (T['includeInstalledInfo'] extends true
  45. ? IAdditionalInstalledAtInfo
  46. : Record<string, never>) &
  47. (T['includeUserCountInfo'] extends true
  48. ? IAdditionalUserCountInfo
  49. : Record<string, never>) &
  50. (T['includePageCountInfo'] extends true
  51. ? IAdditionalPageCountInfo
  52. : Record<string, never>);
  53. // Helper type to check if any option is enabled
  54. export type HasAnyOption<T extends GrowiInfoOptions> =
  55. T['includeAttachmentInfo'] extends true
  56. ? true
  57. : T['includeInstalledInfo'] extends true
  58. ? true
  59. : T['includeUserCountInfo'] extends true
  60. ? true
  61. : T['includePageCountInfo'] extends true
  62. ? true
  63. : false;
  64. // Final result type based on options
  65. export type IGrowiAdditionalInfoResult<T extends GrowiInfoOptions> =
  66. HasAnyOption<T> extends true ? IGrowiAdditionalInfoByOptions<T> : undefined;
  67. export interface IGrowiInfo<A extends object | undefined = undefined> {
  68. serviceInstanceId: string;
  69. appSiteUrl: string;
  70. osInfo: IGrowiOSInfo;
  71. version: string;
  72. type: GrowiServiceType;
  73. wikiType: GrowiWikiType;
  74. deploymentType: GrowiDeploymentType;
  75. additionalInfo?: A;
  76. }