shared-types.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  16. * A type representing the type rather than instance of a class.
  17. */
  18. export interface Type<T> extends Function {
  19. // tslint:disable-next-line:callable-types
  20. new (...args: any[]): T;
  21. }
  22. /**
  23. * A type describing the shape of a paginated list response
  24. */
  25. export type PaginatedList<T> = {
  26. items: T[];
  27. totalItems: number;
  28. };
  29. /**
  30. * @description
  31. * An entity ID. Depending on the configured {@link EntityIdStrategy}, it will be either
  32. * a `string` or a `number`;
  33. *
  34. * @docsCategory common
  35. */
  36. export type ID = string | number;
  37. /**
  38. * @description
  39. * A data type for a custom field.
  40. *
  41. * @docsCategory custom-fields
  42. */
  43. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  44. /**
  45. * @description
  46. * Certain entities (those which implement {@link ConfigurableOperationDef}) allow arbitrary
  47. * configuration arguments to be specified which can then be set in the admin-ui and used in
  48. * the business logic of the app. These are the valid data types of such arguments.
  49. * The data type influences:
  50. *
  51. * 1. How the argument form field is rendered in the admin-ui
  52. * 2. The JavaScript type into which the value is coerced before being passed to the business logic.
  53. *
  54. * @docsCategory common
  55. * @docsPage Configurable Operations
  56. */
  57. export type ConfigArgType = 'string' | 'int' | 'float' | 'boolean' | 'datetime' | 'facetValueIds';
  58. export type ConfigArgSubset<T extends ConfigArgType> = T;
  59. export type CustomFieldsObject = { [key: string]: any };
  60. /**
  61. * This interface describes the shape of the JSON config file used by the Admin UI.
  62. */
  63. export interface AdminUiConfig {
  64. apiHost: string | 'auto';
  65. apiPort: number | 'auto';
  66. adminApiPath: string;
  67. }