shared-types.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * 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; };