You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.4 KiB

  1. package database
  2. import (
  3. "github.com/matrix-org/go-neb/api"
  4. "github.com/matrix-org/go-neb/types"
  5. "maunium.net/go/mautrix/id"
  6. )
  7. // Storer is the interface which needs to be conformed to in order to persist Go-NEB data
  8. type Storer interface {
  9. StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error)
  10. LoadMatrixClientConfigs() (configs []api.ClientConfig, err error)
  11. LoadMatrixClientConfig(userID id.UserID) (config api.ClientConfig, err error)
  12. UpdateNextBatch(userID id.UserID, nextBatch string) (err error)
  13. LoadNextBatch(userID id.UserID) (nextBatch string, err error)
  14. LoadService(serviceID string) (service types.Service, err error)
  15. DeleteService(serviceID string) (err error)
  16. LoadServicesForUser(serviceUserID id.UserID) (services []types.Service, err error)
  17. LoadServicesByType(serviceType string) (services []types.Service, err error)
  18. StoreService(service types.Service) (oldService types.Service, err error)
  19. LoadAuthRealm(realmID string) (realm types.AuthRealm, err error)
  20. LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error)
  21. StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error)
  22. StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error)
  23. LoadAuthSessionByUser(realmID string, userID id.UserID) (session types.AuthSession, err error)
  24. LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error)
  25. RemoveAuthSession(realmID string, userID id.UserID) error
  26. LoadBotOptions(userID id.UserID, roomID id.RoomID) (opts types.BotOptions, err error)
  27. StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error)
  28. InsertFromConfig(cfg *api.ConfigFile) error
  29. }
  30. // NopStorage nops every store API call. This is intended to be embedded into derived structs
  31. // in tests
  32. type NopStorage struct{}
  33. // StoreMatrixClientConfig NOP
  34. func (s *NopStorage) StoreMatrixClientConfig(config api.ClientConfig) (oldConfig api.ClientConfig, err error) {
  35. return api.ClientConfig{}, nil
  36. }
  37. // LoadMatrixClientConfigs NOP
  38. func (s *NopStorage) LoadMatrixClientConfigs() (configs []api.ClientConfig, err error) {
  39. return
  40. }
  41. // LoadMatrixClientConfig NOP
  42. func (s *NopStorage) LoadMatrixClientConfig(userID id.UserID) (config api.ClientConfig, err error) {
  43. return
  44. }
  45. // UpdateNextBatch NOP
  46. func (s *NopStorage) UpdateNextBatch(userID id.UserID, nextBatch string) (err error) {
  47. return
  48. }
  49. // LoadNextBatch NOP
  50. func (s *NopStorage) LoadNextBatch(userID id.UserID) (nextBatch string, err error) {
  51. return
  52. }
  53. // LoadService NOP
  54. func (s *NopStorage) LoadService(serviceID string) (service types.Service, err error) {
  55. return
  56. }
  57. // DeleteService NOP
  58. func (s *NopStorage) DeleteService(serviceID string) (err error) {
  59. return
  60. }
  61. // LoadServicesForUser NOP
  62. func (s *NopStorage) LoadServicesForUser(serviceUserID id.UserID) (services []types.Service, err error) {
  63. return
  64. }
  65. // LoadServicesByType NOP
  66. func (s *NopStorage) LoadServicesByType(serviceType string) (services []types.Service, err error) {
  67. return
  68. }
  69. // StoreService NOP
  70. func (s *NopStorage) StoreService(service types.Service) (oldService types.Service, err error) {
  71. return
  72. }
  73. // LoadAuthRealm NOP
  74. func (s *NopStorage) LoadAuthRealm(realmID string) (realm types.AuthRealm, err error) {
  75. return
  76. }
  77. // LoadAuthRealmsByType NOP
  78. func (s *NopStorage) LoadAuthRealmsByType(realmType string) (realms []types.AuthRealm, err error) {
  79. return
  80. }
  81. // StoreAuthRealm NOP
  82. func (s *NopStorage) StoreAuthRealm(realm types.AuthRealm) (old types.AuthRealm, err error) {
  83. return
  84. }
  85. // StoreAuthSession NOP
  86. func (s *NopStorage) StoreAuthSession(session types.AuthSession) (old types.AuthSession, err error) {
  87. return
  88. }
  89. // LoadAuthSessionByUser NOP
  90. func (s *NopStorage) LoadAuthSessionByUser(realmID string, userID id.UserID) (session types.AuthSession, err error) {
  91. return
  92. }
  93. // LoadAuthSessionByID NOP
  94. func (s *NopStorage) LoadAuthSessionByID(realmID, sessionID string) (session types.AuthSession, err error) {
  95. return
  96. }
  97. // RemoveAuthSession NOP
  98. func (s *NopStorage) RemoveAuthSession(realmID string, userID id.UserID) error {
  99. return nil
  100. }
  101. // LoadBotOptions NOP
  102. func (s *NopStorage) LoadBotOptions(userID id.UserID, roomID id.RoomID) (opts types.BotOptions, err error) {
  103. return
  104. }
  105. // StoreBotOptions NOP
  106. func (s *NopStorage) StoreBotOptions(opts types.BotOptions) (oldOpts types.BotOptions, err error) {
  107. return
  108. }
  109. // InsertFromConfig NOP
  110. func (s *NopStorage) InsertFromConfig(cfg *api.ConfigFile) error {
  111. return nil
  112. }