Source: client/composite-client.js

  1. /*
  2. * Copyright 2023, TeamDev. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Redistribution and use in source and/or binary forms, with or without
  11. * modification, must retain the above copyright notice and the following
  12. * disclaimer.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  18. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  20. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. "use strict";
  27. import {Client} from "./client";
  28. /**
  29. * A {@link Client} that delegates requests to case-specific client implementations.
  30. *
  31. * @see QueryingClient
  32. * @see SubscribingClient
  33. * @see CommandingClient
  34. */
  35. export class CompositeClient extends Client {
  36. constructor(querying, subscribing, commanding) {
  37. super();
  38. /**
  39. * @type QueryingClient
  40. *
  41. * @private
  42. */
  43. this._querying = querying;
  44. /**
  45. * @type SubscribingClient
  46. *
  47. * @private
  48. */
  49. this._subscribing = subscribing;
  50. /**
  51. * @type CommandingClient
  52. *
  53. * @private
  54. */
  55. this._commanding = commanding;
  56. }
  57. /**
  58. * @override
  59. */
  60. select(entityType) {
  61. return this._querying.select(entityType, this);
  62. }
  63. /**
  64. * @override
  65. */
  66. read(query) {
  67. return this._querying.read(query);
  68. }
  69. /**
  70. * @override
  71. */
  72. newQuery() {
  73. return this._querying.newQuery();
  74. }
  75. /**
  76. * @override
  77. */
  78. subscribeTo(entityType) {
  79. return this._subscribing.subscribeTo(entityType, this);
  80. }
  81. /**
  82. * @override
  83. */
  84. cancelAllSubscriptions() {
  85. this._subscribing.cancelAllSubscriptions();
  86. }
  87. /**
  88. * @override
  89. */
  90. subscribeToEvent(eventType) {
  91. return this._subscribing.subscribeToEvent(eventType, this);
  92. }
  93. /**
  94. * @override
  95. */
  96. subscribe(topic) {
  97. return this._subscribing.subscribe(topic)
  98. }
  99. /**
  100. * @override
  101. */
  102. subscribeToEvents(topic) {
  103. return this._subscribing.subscribeToEvents(topic);
  104. }
  105. /**
  106. * @override
  107. */
  108. newTopic() {
  109. return this._subscribing.newTopic();
  110. }
  111. /**
  112. * @override
  113. */
  114. command(commandMessage) {
  115. return this._commanding.command(commandMessage, this);
  116. }
  117. /**
  118. * @override
  119. */
  120. post(command, onAck) {
  121. this._commanding.post(command, onAck);
  122. }
  123. }