shared-types.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // tslint:disable:no-shadowed-variable
  2. /**
  3. * A recursive implementation of the Partial<T> type.
  4. * Source: https://stackoverflow.com/a/49936686/772859
  5. */
  6. export type DeepPartial<T> = {
  7. [P in keyof T]?: T[P] extends Array<infer U>
  8. ? Array<DeepPartial<U>>
  9. : T[P] extends ReadonlyArray<infer U>
  10. ? ReadonlyArray<DeepPartial<U>>
  11. : DeepPartial<T[P]>
  12. };
  13. // tslint:enable:no-shadowed-variable
  14. // tslint:disable:ban-types
  15. /**
  16. * A type representing the type rather than instance of a class.
  17. */
  18. export type Type<T> = {
  19. new (...args: any[]): T;
  20. } & Function;
  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. * An entity ID
  30. */
  31. export type ID = string | number;
  32. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  33. export interface CustomFieldConfig {
  34. name: string;
  35. type: CustomFieldType;
  36. }
  37. export interface CustomFields {
  38. Address?: CustomFieldConfig[];
  39. Customer?: CustomFieldConfig[];
  40. Facet?: CustomFieldConfig[];
  41. FacetValue?: CustomFieldConfig[];
  42. Product?: CustomFieldConfig[];
  43. ProductOption?: CustomFieldConfig[];
  44. ProductOptionGroup?: CustomFieldConfig[];
  45. ProductVariant?: CustomFieldConfig[];
  46. User?: CustomFieldConfig[];
  47. }
  48. /**
  49. * This interface should be implemented by any entity which can be extended
  50. * with custom fields.
  51. */
  52. export interface HasCustomFields {
  53. customFields: CustomFieldsObject;
  54. }
  55. export type MayHaveCustomFields = Partial<HasCustomFields>;
  56. export type CustomFieldsObject = { [key: string]: any; };