shared-types.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. new (...args: any[]): T;
  20. }
  21. /**
  22. * A type describing the shape of a paginated list response
  23. */
  24. export type PaginatedList<T> = {
  25. items: T[];
  26. totalItems: number;
  27. };
  28. /**
  29. * @description
  30. * An entity ID. Depending on the configured {@link EntityIdStrategy}, it will be either
  31. * a `string` or a `number`;
  32. *
  33. * @docsCategory entities
  34. * @docsWeight 0
  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. * Configures a custom field on an entity in the {@link CustomFields} config object.
  47. *
  48. * @docsCategory custom-fields
  49. */
  50. export interface CustomFieldConfig {
  51. name: string;
  52. type: CustomFieldType;
  53. }
  54. /**
  55. * @description
  56. * The certain entities can have additional fields added to them by defining an array of {@link CustomFieldConfig}
  57. * objects on against the corresponding key.
  58. *
  59. * @docsCategory custom-fields
  60. */
  61. export interface CustomFields {
  62. Address?: CustomFieldConfig[];
  63. Customer?: CustomFieldConfig[];
  64. Facet?: CustomFieldConfig[];
  65. FacetValue?: CustomFieldConfig[];
  66. GlobalSettings?: CustomFieldConfig[];
  67. Product?: CustomFieldConfig[];
  68. ProductCategory?: CustomFieldConfig[];
  69. ProductOption?: CustomFieldConfig[];
  70. ProductOptionGroup?: CustomFieldConfig[];
  71. ProductVariant?: CustomFieldConfig[];
  72. User?: CustomFieldConfig[];
  73. }
  74. /**
  75. * This interface should be implemented by any entity which can be extended
  76. * with custom fields.
  77. */
  78. export interface HasCustomFields {
  79. customFields: CustomFieldsObject;
  80. }
  81. export type MayHaveCustomFields = Partial<HasCustomFields>;
  82. export type CustomFieldsObject = { [key: string]: any; };