shared-types.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ProductCategory?: CustomFieldConfig[];
  44. ProductOption?: CustomFieldConfig[];
  45. ProductOptionGroup?: CustomFieldConfig[];
  46. ProductVariant?: CustomFieldConfig[];
  47. User?: CustomFieldConfig[];
  48. }
  49. /**
  50. * This interface should be implemented by any entity which can be extended
  51. * with custom fields.
  52. */
  53. export interface HasCustomFields {
  54. customFields: CustomFieldsObject;
  55. }
  56. export type MayHaveCustomFields = Partial<HasCustomFields>;
  57. export type CustomFieldsObject = { [key: string]: any; };