interfaces.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. /**
  4. * A generic interface for change emitter payloads.
  5. */
  6. export interface IChangedArgs<T> {
  7. /**
  8. * The name of the changed attribute.
  9. */
  10. name: string;
  11. /**
  12. * The old value of the changed attribute.
  13. */
  14. oldValue: T;
  15. /**
  16. * The new value of the changed attribute.
  17. */
  18. newValue: T;
  19. }
  20. /**
  21. * The description of a general purpose data connector.
  22. *
  23. * @typeparam T - The basic entity response type a service's connector.
  24. *
  25. * @typeparam U - The basic entity request type, which is conventionally the
  26. * same as the response type but may be different if a service's implementation
  27. * requires input data to be different from output responses. Defaults to `T`.
  28. *
  29. * @typeparam V - The basic token applied to a request, conventionally a string
  30. * ID or filter, but may be set to a different type when an implementation
  31. * requires it. Defaults to `string`.
  32. */
  33. export interface IDataConnector<T, U = T, V = string> {
  34. /**
  35. * Retrieve an item from the data connector.
  36. *
  37. * @param id - The identifier used to retrieve an item.
  38. *
  39. * @returns A promise that bears a data payload if available.
  40. *
  41. * #### Notes
  42. * The promise returned by this method may be rejected if an error occurs in
  43. * retrieving the data. Nonexistence of an `id` resolves with `undefined`.
  44. */
  45. fetch(id: V): Promise<T | undefined>;
  46. /**
  47. * Retrieve the list of items available from the data connector.
  48. *
  49. * @param query - The optional query filter to apply to the connector request.
  50. *
  51. * @returns A promise that bears a list of `values` and an associated list of
  52. * fetch `ids`.
  53. *
  54. * #### Notes
  55. * The promise returned by this method may be rejected if an error occurs in
  56. * retrieving the data. The two lists will always be the same size. If there
  57. * is no data, this method will succeed with empty `ids` and `values`.
  58. */
  59. list(query?: any): Promise<{ ids: V[]; values: T[] }>;
  60. /**
  61. * Remove a value using the data connector.
  62. *
  63. * @param id - The identifier for the data being removed.
  64. *
  65. * @returns A promise that is rejected if remove fails and succeeds otherwise.
  66. *
  67. * #### Notes
  68. * This promise may resolve with a back-end response or `undefined`.
  69. * Existence of resolved content in the promise is not prescribed and must be
  70. * tested for. For example, some back-ends may return a copy of the item of
  71. * type `T` being removed while others may return no content.
  72. */
  73. remove(id: V): Promise<any>;
  74. /**
  75. * Save a value using the data connector.
  76. *
  77. * @param id - The identifier for the data being saved.
  78. *
  79. * @param value - The data being saved.
  80. *
  81. * @returns A promise that is rejected if saving fails and succeeds otherwise.
  82. *
  83. * #### Notes
  84. * This promise may resolve with a back-end response or `undefined`.
  85. * Existence of resolved content in the promise is not prescribed and must be
  86. * tested for. For example, some back-ends may return a copy of the item of
  87. * type `T` being saved while others may return no content.
  88. */
  89. save(id: V, value: U): Promise<any>;
  90. }