shared-types.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // tslint:disable:no-shadowed-variable
  2. // prettier-ignore
  3. /**
  4. * A recursive implementation of the Partial<T> type.
  5. * Source: https://stackoverflow.com/a/49936686/772859
  6. */
  7. export type DeepPartial<T> = {
  8. [P in keyof T]?: null | (T[P] extends Array<infer U>
  9. ? Array<DeepPartial<U>>
  10. : T[P] extends ReadonlyArray<infer U>
  11. ? ReadonlyArray<DeepPartial<U>>
  12. : DeepPartial<T[P]>)
  13. };
  14. // tslint:enable:no-shadowed-variable
  15. // tslint:disable:ban-types
  16. /**
  17. * A recursive implementation of Required<T>.
  18. * Source: https://github.com/microsoft/TypeScript/issues/15012#issuecomment-365453623
  19. */
  20. export type DeepRequired<T, U extends object | undefined = undefined> = T extends object
  21. ? {
  22. [P in keyof T]-?: NonNullable<T[P]> extends NonNullable<U | Function | Type<any>>
  23. ? NonNullable<T[P]>
  24. : DeepRequired<NonNullable<T[P]>, U>;
  25. }
  26. : T;
  27. // tslint:enable:ban-types
  28. /**
  29. * A type representing the type rather than instance of a class.
  30. */
  31. export interface Type<T> extends Function {
  32. // tslint:disable-next-line:callable-types
  33. new (...args: any[]): T;
  34. }
  35. /**
  36. * A type describing the shape of a paginated list response
  37. */
  38. export type PaginatedList<T> = {
  39. items: T[];
  40. totalItems: number;
  41. };
  42. /**
  43. * @description
  44. * An entity ID. Depending on the configured {@link EntityIdStrategy}, it will be either
  45. * a `string` or a `number`;
  46. *
  47. * @docsCategory common
  48. */
  49. export type ID = string | number;
  50. /**
  51. * @description
  52. * A data type for a custom field.
  53. *
  54. * @docsCategory custom-fields
  55. */
  56. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  57. /**
  58. * @description
  59. * Certain entities (those which implement {@link ConfigurableOperationDef}) allow arbitrary
  60. * configuration arguments to be specified which can then be set in the admin-ui and used in
  61. * the business logic of the app. These are the valid data types of such arguments.
  62. * The data type influences:
  63. *
  64. * 1. How the argument form field is rendered in the admin-ui
  65. * 2. The JavaScript type into which the value is coerced before being passed to the business logic.
  66. *
  67. * @docsCategory common
  68. * @docsPage Configurable Operations
  69. */
  70. export type ConfigArgType = 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'facetValueIds';
  71. export type ConfigArgSubset<T extends ConfigArgType> = T;
  72. export type CustomFieldsObject = { [key: string]: any };
  73. /**
  74. * This interface describes the shape of the JSON config file used by the Admin UI.
  75. */
  76. export interface AdminUiConfig {
  77. apiHost: string | 'auto';
  78. apiPort: number | 'auto';
  79. adminApiPath: string;
  80. tokenMethod: 'cookie' | 'bearer';
  81. authTokenHeaderKey: string;
  82. }
  83. /**
  84. * @description
  85. * Defines extensions to the Admin UI application by specifying additional
  86. * Angular [NgModules](https://angular.io/guide/ngmodules) which are compiled
  87. * into the application.
  88. *
  89. * @docsCategory AdminUiPlugin
  90. */
  91. export interface AdminUiExtension {
  92. id?: string;
  93. type: 'shared' | 'lazy';
  94. ngModulePath: string;
  95. ngModuleFileName: string;
  96. ngModuleName: string;
  97. }