shared-types.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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]?: null | (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. /**
  15. * A type representing the type rather than instance of a class.
  16. */
  17. export interface Type<T> extends Function { new (...args: any[]): T; }
  18. /**
  19. * A type describing the shape of a paginated list response
  20. */
  21. export type PaginatedList<T> = {
  22. items: T[];
  23. totalItems: number;
  24. };
  25. /**
  26. * An entity ID
  27. */
  28. export type ID = string | number;
  29. export type CustomFieldType = 'string' | 'localeString' | 'int' | 'float' | 'boolean' | 'datetime';
  30. export interface CustomFieldConfig {
  31. name: string;
  32. type: CustomFieldType;
  33. }
  34. export interface CustomFields {
  35. Address?: CustomFieldConfig[];
  36. Customer?: CustomFieldConfig[];
  37. Facet?: CustomFieldConfig[];
  38. FacetValue?: CustomFieldConfig[];
  39. Product?: CustomFieldConfig[];
  40. ProductOption?: CustomFieldConfig[];
  41. ProductOptionGroup?: CustomFieldConfig[];
  42. ProductVariant?: CustomFieldConfig[];
  43. User?: CustomFieldConfig[];
  44. }
  45. /**
  46. * This interface should be implemented by any entity which can be extended
  47. * with custom fields.
  48. */
  49. export interface HasCustomFields {
  50. customFields: CustomFieldsObject;
  51. }
  52. export type MayHaveCustomFields = Partial<HasCustomFields>;
  53. export type CustomFieldsObject = { [key: string]: any; };