shared-types.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. * See [Extending the Admin UI](/docs/developer-guide/plugins/extending-the-admin-ui/) for
  90. * detailed instructions.
  91. *
  92. * @docsCategory AdminUiPlugin
  93. */
  94. export interface AdminUiExtension {
  95. /**
  96. * @description
  97. * An optional ID for the extension module. Only used internally for generating
  98. * import paths to your module. If not specified, a unique hash will be used as the id.
  99. */
  100. id?: string;
  101. /**
  102. * @description
  103. * The path to the directory containing the extension module(s). The entire contents of this directory
  104. * will be copied into the Admin UI app, including all TypeScript source files, html templates,
  105. * scss style sheets etc.
  106. */
  107. extensionPath: string;
  108. /**
  109. * @description
  110. * One or more Angular modules which extend the default Admin UI.
  111. */
  112. ngModules: AdminUiExtensionModule[];
  113. }
  114. /**
  115. * @description
  116. * Configuration defining a single NgModule with which to extend the Admin UI.
  117. *
  118. * @docsCategory AdminUiPlugin
  119. */
  120. export interface AdminUiExtensionModule {
  121. /**
  122. * @description
  123. * Lazy modules are lazy-loaded at the `/extensions/` route and should be used for
  124. * modules which define new views for the Admin UI.
  125. *
  126. * Shared modules are directly imported into the main AppModule of the Admin UI
  127. * and should be used to declare custom form components and define custom
  128. * navigation items.
  129. */
  130. type: 'shared' | 'lazy';
  131. /**
  132. * @description
  133. * The name of the file containing the extension module class.
  134. */
  135. ngModuleFileName: string;
  136. /**
  137. * @description
  138. * The name of the extension module class.
  139. */
  140. ngModuleName: string;
  141. }