@aws-amplify/api-graphql 0.0.0-unstable-1ca644b-20260128091132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/GraphQLAPI.js +66 -0
  3. package/dist/cjs/GraphQLAPI.js.map +1 -0
  4. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +117 -0
  5. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +1 -0
  6. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +96 -0
  7. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
  8. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +113 -0
  9. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +1 -0
  10. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +99 -0
  11. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +1 -0
  12. package/dist/cjs/Providers/AWSWebSocketProvider/index.js +693 -0
  13. package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +1 -0
  14. package/dist/cjs/Providers/constants.js +149 -0
  15. package/dist/cjs/Providers/constants.js.map +1 -0
  16. package/dist/cjs/index.js +18 -0
  17. package/dist/cjs/index.js.map +1 -0
  18. package/dist/cjs/internals/InternalGraphQLAPI.js +269 -0
  19. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -0
  20. package/dist/cjs/internals/events/appsyncRequest.js +96 -0
  21. package/dist/cjs/internals/events/appsyncRequest.js.map +1 -0
  22. package/dist/cjs/internals/events/index.js +142 -0
  23. package/dist/cjs/internals/events/index.js.map +1 -0
  24. package/dist/cjs/internals/events/types.js +6 -0
  25. package/dist/cjs/internals/events/types.js.map +1 -0
  26. package/dist/cjs/internals/events/utils.js +57 -0
  27. package/dist/cjs/internals/events/utils.js.map +1 -0
  28. package/dist/cjs/internals/generateClient.js +86 -0
  29. package/dist/cjs/internals/generateClient.js.map +1 -0
  30. package/dist/cjs/internals/graphqlAuth.js +63 -0
  31. package/dist/cjs/internals/graphqlAuth.js.map +1 -0
  32. package/dist/cjs/internals/graphqlRequest.js +19 -0
  33. package/dist/cjs/internals/graphqlRequest.js.map +1 -0
  34. package/dist/cjs/internals/index.js +16 -0
  35. package/dist/cjs/internals/index.js.map +1 -0
  36. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +48 -0
  37. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -0
  38. package/dist/cjs/internals/server/index.js +9 -0
  39. package/dist/cjs/internals/server/index.js.map +1 -0
  40. package/dist/cjs/internals/types.js +4 -0
  41. package/dist/cjs/internals/types.js.map +1 -0
  42. package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js +10 -0
  43. package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -0
  44. package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js +10 -0
  45. package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -0
  46. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +14 -0
  47. package/dist/cjs/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -0
  48. package/dist/cjs/internals/v6.js +155 -0
  49. package/dist/cjs/internals/v6.js.map +1 -0
  50. package/dist/cjs/server/generateClient.js +42 -0
  51. package/dist/cjs/server/generateClient.js.map +1 -0
  52. package/dist/cjs/server/index.js +9 -0
  53. package/dist/cjs/server/index.js.map +1 -0
  54. package/dist/cjs/types/PubSub.js +49 -0
  55. package/dist/cjs/types/PubSub.js.map +1 -0
  56. package/dist/cjs/types/index.js +34 -0
  57. package/dist/cjs/types/index.js.map +1 -0
  58. package/dist/cjs/utils/ConnectionStateMonitor.js +134 -0
  59. package/dist/cjs/utils/ConnectionStateMonitor.js.map +1 -0
  60. package/dist/cjs/utils/ReachabilityMonitor/index.js +10 -0
  61. package/dist/cjs/utils/ReachabilityMonitor/index.js.map +1 -0
  62. package/dist/cjs/utils/ReachabilityMonitor/index.native.js +12 -0
  63. package/dist/cjs/utils/ReachabilityMonitor/index.native.js.map +1 -0
  64. package/dist/cjs/utils/ReconnectionMonitor.js +71 -0
  65. package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -0
  66. package/dist/cjs/utils/errors/GraphQLApiError.js +21 -0
  67. package/dist/cjs/utils/errors/GraphQLApiError.js.map +1 -0
  68. package/dist/cjs/utils/errors/assertValidationError.js +18 -0
  69. package/dist/cjs/utils/errors/assertValidationError.js.map +1 -0
  70. package/dist/cjs/utils/errors/constants.js +47 -0
  71. package/dist/cjs/utils/errors/constants.js.map +1 -0
  72. package/dist/cjs/utils/errors/createGraphQLResultWithError.js +15 -0
  73. package/dist/cjs/utils/errors/createGraphQLResultWithError.js.map +1 -0
  74. package/dist/cjs/utils/errors/index.js +16 -0
  75. package/dist/cjs/utils/errors/index.js.map +1 -0
  76. package/dist/cjs/utils/errors/repackageAuthError.js +38 -0
  77. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -0
  78. package/dist/cjs/utils/errors/validation.js +28 -0
  79. package/dist/cjs/utils/errors/validation.js.map +1 -0
  80. package/dist/cjs/utils/index.js +11 -0
  81. package/dist/cjs/utils/index.js.map +1 -0
  82. package/dist/cjs/utils/resolveConfig.js +32 -0
  83. package/dist/cjs/utils/resolveConfig.js.map +1 -0
  84. package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
  85. package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
  86. package/dist/esm/GraphQLAPI.d.ts +37 -0
  87. package/dist/esm/GraphQLAPI.mjs +63 -0
  88. package/dist/esm/GraphQLAPI.mjs.map +1 -0
  89. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +49 -0
  90. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +115 -0
  91. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +1 -0
  92. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +47 -0
  93. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +94 -0
  94. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -0
  95. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +21 -0
  96. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +107 -0
  97. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +1 -0
  98. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +8 -0
  99. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +97 -0
  100. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +1 -0
  101. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +99 -0
  102. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +691 -0
  103. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -0
  104. package/dist/esm/Providers/constants.d.ts +135 -0
  105. package/dist/esm/Providers/constants.mjs +147 -0
  106. package/dist/esm/Providers/constants.mjs.map +1 -0
  107. package/dist/esm/index.d.ts +6 -0
  108. package/dist/esm/index.mjs +7 -0
  109. package/dist/esm/index.mjs.map +1 -0
  110. package/dist/esm/internals/InternalGraphQLAPI.d.ts +45 -0
  111. package/dist/esm/internals/InternalGraphQLAPI.mjs +270 -0
  112. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -0
  113. package/dist/esm/internals/events/appsyncRequest.d.ts +14 -0
  114. package/dist/esm/internals/events/appsyncRequest.mjs +96 -0
  115. package/dist/esm/internals/events/appsyncRequest.mjs.map +1 -0
  116. package/dist/esm/internals/events/index.d.ts +58 -0
  117. package/dist/esm/internals/events/index.mjs +139 -0
  118. package/dist/esm/internals/events/index.mjs.map +1 -0
  119. package/dist/esm/internals/events/types.d.ts +93 -0
  120. package/dist/esm/internals/events/types.mjs +2 -0
  121. package/dist/esm/internals/events/types.mjs.map +1 -0
  122. package/dist/esm/internals/events/utils.d.ts +16 -0
  123. package/dist/esm/internals/events/utils.mjs +53 -0
  124. package/dist/esm/internals/events/utils.mjs.map +1 -0
  125. package/dist/esm/internals/generateClient.d.ts +12 -0
  126. package/dist/esm/internals/generateClient.mjs +85 -0
  127. package/dist/esm/internals/generateClient.mjs.map +1 -0
  128. package/dist/esm/internals/graphqlAuth.d.ts +3 -0
  129. package/dist/esm/internals/graphqlAuth.mjs +64 -0
  130. package/dist/esm/internals/graphqlAuth.mjs.map +1 -0
  131. package/dist/esm/internals/graphqlRequest.d.ts +3 -0
  132. package/dist/esm/internals/graphqlRequest.mjs +18 -0
  133. package/dist/esm/internals/graphqlRequest.mjs.map +1 -0
  134. package/dist/esm/internals/index.d.ts +4 -0
  135. package/dist/esm/internals/index.mjs +4 -0
  136. package/dist/esm/internals/index.mjs.map +1 -0
  137. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +13 -0
  138. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +61 -0
  139. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -0
  140. package/dist/esm/internals/server/index.d.ts +1 -0
  141. package/dist/esm/internals/server/index.mjs +2 -0
  142. package/dist/esm/internals/server/index.mjs.map +1 -0
  143. package/dist/esm/internals/types.d.ts +34 -0
  144. package/dist/esm/internals/types.mjs +2 -0
  145. package/dist/esm/internals/types.mjs.map +1 -0
  146. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts +2 -0
  147. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs +8 -0
  148. package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -0
  149. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts +8 -0
  150. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs +8 -0
  151. package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -0
  152. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.d.ts +2 -0
  153. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs +12 -0
  154. package/dist/esm/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -0
  155. package/dist/esm/internals/v6.d.ts +100 -0
  156. package/dist/esm/internals/v6.mjs +152 -0
  157. package/dist/esm/internals/v6.mjs.map +1 -0
  158. package/dist/esm/server/generateClient.d.ts +21 -0
  159. package/dist/esm/server/generateClient.mjs +41 -0
  160. package/dist/esm/server/generateClient.mjs.map +1 -0
  161. package/dist/esm/server/index.d.ts +1 -0
  162. package/dist/esm/server/index.mjs +2 -0
  163. package/dist/esm/server/index.mjs.map +1 -0
  164. package/dist/esm/types/PubSub.d.ts +27 -0
  165. package/dist/esm/types/PubSub.mjs +47 -0
  166. package/dist/esm/types/PubSub.mjs.map +1 -0
  167. package/dist/esm/types/index.d.ts +369 -0
  168. package/dist/esm/types/index.mjs +30 -0
  169. package/dist/esm/types/index.mjs.map +1 -0
  170. package/dist/esm/utils/ConnectionStateMonitor.d.ts +69 -0
  171. package/dist/esm/utils/ConnectionStateMonitor.mjs +132 -0
  172. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -0
  173. package/dist/esm/utils/ReachabilityMonitor/index.d.ts +1 -0
  174. package/dist/esm/utils/ReachabilityMonitor/index.mjs +8 -0
  175. package/dist/esm/utils/ReachabilityMonitor/index.mjs.map +1 -0
  176. package/dist/esm/utils/ReachabilityMonitor/index.native.d.ts +1 -0
  177. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs +9 -0
  178. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -0
  179. package/dist/esm/utils/ReconnectionMonitor.d.ts +29 -0
  180. package/dist/esm/utils/ReconnectionMonitor.mjs +69 -0
  181. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -0
  182. package/dist/esm/utils/errors/GraphQLApiError.d.ts +7 -0
  183. package/dist/esm/utils/errors/GraphQLApiError.mjs +19 -0
  184. package/dist/esm/utils/errors/GraphQLApiError.mjs.map +1 -0
  185. package/dist/esm/utils/errors/assertValidationError.d.ts +5 -0
  186. package/dist/esm/utils/errors/assertValidationError.mjs +17 -0
  187. package/dist/esm/utils/errors/assertValidationError.mjs.map +1 -0
  188. package/dist/esm/utils/errors/constants.d.ts +7 -0
  189. package/dist/esm/utils/errors/constants.mjs +46 -0
  190. package/dist/esm/utils/errors/constants.mjs.map +1 -0
  191. package/dist/esm/utils/errors/createGraphQLResultWithError.d.ts +2 -0
  192. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs +13 -0
  193. package/dist/esm/utils/errors/createGraphQLResultWithError.mjs.map +1 -0
  194. package/dist/esm/utils/errors/index.d.ts +4 -0
  195. package/dist/esm/utils/errors/index.mjs +5 -0
  196. package/dist/esm/utils/errors/index.mjs.map +1 -0
  197. package/dist/esm/utils/errors/repackageAuthError.d.ts +7 -0
  198. package/dist/esm/utils/errors/repackageAuthError.mjs +36 -0
  199. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -0
  200. package/dist/esm/utils/errors/validation.d.ts +7 -0
  201. package/dist/esm/utils/errors/validation.mjs +26 -0
  202. package/dist/esm/utils/errors/validation.mjs.map +1 -0
  203. package/dist/esm/utils/index.d.ts +2 -0
  204. package/dist/esm/utils/index.mjs +3 -0
  205. package/dist/esm/utils/index.mjs.map +1 -0
  206. package/dist/esm/utils/resolveConfig.d.ts +12 -0
  207. package/dist/esm/utils/resolveConfig.mjs +33 -0
  208. package/dist/esm/utils/resolveConfig.mjs.map +1 -0
  209. package/dist/esm/utils/resolveLibraryOptions.d.ts +11 -0
  210. package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
  211. package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
  212. package/internals/package.json +8 -0
  213. package/internals/server/package.json +8 -0
  214. package/package.json +99 -0
  215. package/server/package.json +7 -0
  216. package/src/GraphQLAPI.ts +97 -0
  217. package/src/Providers/AWSAppSyncEventsProvider/index.ts +218 -0
  218. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +185 -0
  219. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +152 -0
  220. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +146 -0
  221. package/src/Providers/AWSWebSocketProvider/index.ts +1028 -0
  222. package/src/Providers/constants.ts +154 -0
  223. package/src/index.ts +12 -0
  224. package/src/internals/InternalGraphQLAPI.ts +424 -0
  225. package/src/internals/events/appsyncRequest.ts +169 -0
  226. package/src/internals/events/index.ts +199 -0
  227. package/src/internals/events/types.ts +109 -0
  228. package/src/internals/events/utils.ts +77 -0
  229. package/src/internals/generateClient.ts +120 -0
  230. package/src/internals/graphqlAuth.ts +87 -0
  231. package/src/internals/graphqlRequest.ts +30 -0
  232. package/src/internals/index.ts +10 -0
  233. package/src/internals/server/generateClientWithAmplifyInstance.ts +73 -0
  234. package/src/internals/server/index.ts +4 -0
  235. package/src/internals/types.ts +42 -0
  236. package/src/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.ts +10 -0
  237. package/src/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.ts +13 -0
  238. package/src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts +15 -0
  239. package/src/internals/v6.ts +189 -0
  240. package/src/server/generateClient.ts +68 -0
  241. package/src/server/index.ts +4 -0
  242. package/src/types/PubSub.ts +57 -0
  243. package/src/types/index.ts +524 -0
  244. package/src/utils/ConnectionStateMonitor.ts +195 -0
  245. package/src/utils/ReachabilityMonitor/index.native.ts +7 -0
  246. package/src/utils/ReachabilityMonitor/index.ts +5 -0
  247. package/src/utils/ReconnectionMonitor.ts +77 -0
  248. package/src/utils/errors/GraphQLApiError.ts +21 -0
  249. package/src/utils/errors/assertValidationError.ts +19 -0
  250. package/src/utils/errors/constants.ts +56 -0
  251. package/src/utils/errors/createGraphQLResultWithError.ts +15 -0
  252. package/src/utils/errors/index.ts +7 -0
  253. package/src/utils/errors/repackageAuthError.ts +43 -0
  254. package/src/utils/errors/validation.ts +26 -0
  255. package/src/utils/index.ts +5 -0
  256. package/src/utils/resolveConfig.ts +46 -0
  257. package/src/utils/resolveLibraryOptions.ts +14 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/internals/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = exports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nvar InternalGraphQLAPI_1 = require(\"./InternalGraphQLAPI\");\nObject.defineProperty(exports, \"InternalGraphQLAPI\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPI; } });\nObject.defineProperty(exports, \"InternalGraphQLAPIClass\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPIClass; } });\nvar v6_1 = require(\"./v6\");\nObject.defineProperty(exports, \"graphql\", { enumerable: true, get: function () { return v6_1.graphql; } });\nObject.defineProperty(exports, \"cancel\", { enumerable: true, get: function () { return v6_1.cancel; } });\nObject.defineProperty(exports, \"isCancelError\", { enumerable: true, get: function () { return v6_1.isCancelError; } });\nvar generateClient_1 = require(\"./generateClient\");\nObject.defineProperty(exports, \"generateClient\", { enumerable: true, get: function () { return generateClient_1.generateClient; } });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,MAAM,G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AC,CAAC,EAAE,CAAC;;"}
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateClientWithAmplifyInstance = generateClientWithAmplifyInstance;
7
+ const runtime_1 = require("@aws-amplify/data-schema/runtime");
8
+ const types_1 = require("../../types");
9
+ const isApiGraphQLProviderConfig_1 = require("../utils/runtimeTypeGuards/isApiGraphQLProviderConfig");
10
+ const __1 = require("..");
11
+ /**
12
+ * @private
13
+ *
14
+ * Used internally by `adapter-nextjs` package.
15
+ *
16
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
17
+ * compatible context object for config and auth fetching.
18
+ *
19
+ * @param params
20
+ * @returns
21
+ */
22
+ function generateClientWithAmplifyInstance(params) {
23
+ const client = {
24
+ [types_1.__amplify]: params.amplify,
25
+ [types_1.__authMode]: params.authMode,
26
+ [types_1.__authToken]: params.authToken,
27
+ [types_1.__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
28
+ [types_1.__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
29
+ [types_1.__headers]: params.headers,
30
+ graphql: __1.graphql,
31
+ cancel: __1.cancel,
32
+ isCancelError: __1.isCancelError,
33
+ };
34
+ const apiGraphqlConfig = params.config?.API?.GraphQL;
35
+ if (client[types_1.__endpoint]) {
36
+ if (!client[types_1.__authMode]) {
37
+ throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');
38
+ }
39
+ if (client[types_1.__authMode] === 'apiKey' && !client[types_1.__apiKey]) {
40
+ throw new Error("generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.");
41
+ }
42
+ }
43
+ if (!client[types_1.__endpoint] && (0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphqlConfig)) {
44
+ (0, runtime_1.addSchemaToClientWithInstance)(client, params, types_1.getInternals);
45
+ }
46
+ return client;
47
+ }
48
+ //# sourceMappingURL=generateClientWithAmplifyInstance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClientWithAmplifyInstance.js","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClientWithAmplifyInstance = generateClientWithAmplifyInstance;\nconst runtime_1 = require(\"@aws-amplify/data-schema/runtime\");\nconst types_1 = require(\"../../types\");\nconst isApiGraphQLProviderConfig_1 = require(\"../utils/runtimeTypeGuards/isApiGraphQLProviderConfig\");\nconst __1 = require(\"..\");\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nfunction generateClientWithAmplifyInstance(params) {\n const client = {\n [types_1.__amplify]: params.amplify,\n [types_1.__authMode]: params.authMode,\n [types_1.__authToken]: params.authToken,\n [types_1.__apiKey]: 'apiKey' in params ? params.apiKey : undefined,\n [types_1.__endpoint]: 'endpoint' in params ? params.endpoint : undefined,\n [types_1.__headers]: params.headers,\n graphql: __1.graphql,\n cancel: __1.cancel,\n isCancelError: __1.isCancelError,\n };\n const apiGraphqlConfig = params.config?.API?.GraphQL;\n if (client[types_1.__endpoint]) {\n if (!client[types_1.__authMode]) {\n throw new Error('generateClient() requires an explicit `authMode` when `endpoint` is provided.');\n }\n if (client[types_1.__authMode] === 'apiKey' && !client[types_1.__apiKey]) {\n throw new Error(\"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.\");\n }\n }\n if (!client[types_1.__endpoint] && (0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphqlConfig)) {\n (0, runtime_1.addSchemaToClientWithInstance)(client, params, types_1.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AACpC,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;AACzC,YAAY,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC;AAC5G,QAAQ;AACR,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;AAClF,YAAY,MAAM,IAAI,KAAK,CAAC,uGAAuG,CAAC;AACpI,QAAQ;AACR,IAAI;AACJ,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,4BAA4B,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,EAAE;AAC/G,QAAQ,IAAI,SAAS,CAAC,6BAA6B,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC;AAC1F,IAAI;AACJ,IAAI,OAAO,MAAM;AACjB;;"}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateClientWithAmplifyInstance = void 0;
7
+ var generateClientWithAmplifyInstance_1 = require("./generateClientWithAmplifyInstance");
8
+ Object.defineProperty(exports, "generateClientWithAmplifyInstance", { enumerable: true, get: function () { return generateClientWithAmplifyInstance_1.generateClientWithAmplifyInstance; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/internals/server/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClientWithAmplifyInstance = void 0;\nvar generateClientWithAmplifyInstance_1 = require(\"./generateClientWithAmplifyInstance\");\nObject.defineProperty(exports, \"generateClientWithAmplifyInstance\", { enumerable: true, get: function () { return generateClientWithAmplifyInstance_1.generateClientWithAmplifyInstance; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,iCAAiC,GAAG,MAAM;AAClD,IAAI,mCAAmC,GAAG,OAAO,CAAC,qCAAqC,CAAC;AACxF,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mCAAmC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,mCAAmC,CAAC,iCAAiC,CAAC,CAAC,CAAC,EAAE,CAAC;;"}
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../../src/internals/types.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isApiGraphQLConfig = isApiGraphQLConfig;
7
+ function isApiGraphQLConfig(apiGraphQLConfig) {
8
+ return apiGraphQLConfig !== undefined;
9
+ }
10
+ //# sourceMappingURL=isApiGraphQLProviderConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isApiGraphQLProviderConfig.js","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isApiGraphQLConfig = isApiGraphQLConfig;\nfunction isApiGraphQLConfig(apiGraphQLConfig) {\n return apiGraphQLConfig !== undefined;\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;AAC/C,SAAS,kBAAkB,CAAC,gBAAgB,EAAE;AAC9C,IAAI,OAAO,gBAAgB,KAAK,SAAS;AACzC;;"}
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isConfigureEventWithResourceConfig = isConfigureEventWithResourceConfig;
7
+ function isConfigureEventWithResourceConfig(payload) {
8
+ return payload.event === 'configure';
9
+ }
10
+ //# sourceMappingURL=isConfigureEventWithResourceConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isConfigureEventWithResourceConfig.js","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isConfigureEventWithResourceConfig = isConfigureEventWithResourceConfig;\nfunction isConfigureEventWithResourceConfig(payload) {\n return payload.event === 'configure';\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,kCAAkC,GAAG,kCAAkC;AAC/E,SAAS,kCAAkC,CAAC,OAAO,EAAE;AACrD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,WAAW;AACxC;;"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isGraphQLResponseWithErrors = isGraphQLResponseWithErrors;
7
+ function isGraphQLResponseWithErrors(response) {
8
+ if (!response) {
9
+ return false;
10
+ }
11
+ const r = response;
12
+ return Array.isArray(r.errors) && r.errors.length > 0;
13
+ }
14
+ //# sourceMappingURL=isGraphQLResponseWithErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isGraphQLResponseWithErrors.js","sources":["../../../../../src/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isGraphQLResponseWithErrors = isGraphQLResponseWithErrors;\nfunction isGraphQLResponseWithErrors(response) {\n if (!response) {\n return false;\n }\n const r = response;\n return Array.isArray(r.errors) && r.errors.length > 0;\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,2BAA2B,GAAG,2BAA2B;AACjE,SAAS,2BAA2B,CAAC,QAAQ,EAAE;AAC/C,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,OAAO,KAAK;AACpB,IAAI;AACJ,IAAI,MAAM,CAAC,GAAG,QAAQ;AACtB,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;AACzD;;"}
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.graphql = graphql;
5
+ exports.cancel = cancel;
6
+ exports.isCancelError = isCancelError;
7
+ const GraphQLAPI_1 = require("../GraphQLAPI");
8
+ const types_1 = require("../types");
9
+ /**
10
+ * Invokes graphql operations against a graphql service, providing correct input and
11
+ * output types if Amplify-generated graphql from a recent version of the CLI/codegen
12
+ * are used *or* correct typing is provided via the type argument.
13
+ *
14
+ * Amplify-generated "branded" graphql queries will look similar to this:
15
+ *
16
+ * ```ts
17
+ * //
18
+ * // |-- branding
19
+ * // v
20
+ * export const getModel = `...` as GeneratedQuery<
21
+ * GetModelQueryVariables,
22
+ * GetModelQuery
23
+ * >;
24
+ * ```
25
+ *
26
+ * If this branding is not in your generated graphql, update to a newer version of
27
+ * CLI/codegen and regenerate your graphql using `amplify codegen`.
28
+ *
29
+ * ## Using Amplify-generated graphql
30
+ *
31
+ * ```ts
32
+ * import * as queries from './graphql/queries';
33
+ *
34
+ * //
35
+ * // |-- correctly typed graphql response containing a Widget
36
+ * // v
37
+ * const queryResult = await graphql({
38
+ * query: queries.getWidget,
39
+ * variables: {
40
+ * id: "abc", // <-- type hinted/enforced
41
+ * },
42
+ * });
43
+ *
44
+ * //
45
+ * // |-- a correctly typed Widget
46
+ * // v
47
+ * const fetchedWidget = queryResult.data?.getWidget!;
48
+ * ```
49
+ *
50
+ * ## Custom input + result types
51
+ *
52
+ * To provide input types (`variables`) and result types:
53
+ *
54
+ * ```ts
55
+ * type GetById_NameOnly = {
56
+ * variables: {
57
+ * id: string
58
+ * },
59
+ * result: Promise<{
60
+ * data: { getWidget: { name: string } }
61
+ * }>
62
+ * }
63
+ *
64
+ * //
65
+ * // |-- type is GetById_NameOnly["result"]
66
+ * // v
67
+ * const result = graphql<GetById_NameOnly>({
68
+ * query: "...",
69
+ * variables: { id: "abc" } // <-- type of GetById_NameOnly["variables"]
70
+ * });
71
+ * ```
72
+ *
73
+ * ## Custom result type only
74
+ *
75
+ * To specify result types only, use a type that is *not* in the `{variables, result}` shape:
76
+ *
77
+ * ```ts
78
+ * type MyResultType = Promise<{
79
+ * data: {
80
+ * getWidget: { name: string }
81
+ * }
82
+ * }>
83
+ *
84
+ * //
85
+ * // |-- type is MyResultType
86
+ * // v
87
+ * const result = graphql<MyResultType>({query: "..."});
88
+ * ```
89
+ *
90
+ * @param options
91
+ * @param additionalHeaders
92
+ */
93
+ function graphql(options, additionalHeaders) {
94
+ // inject client-level auth
95
+ const internals = (0, types_1.getInternals)(this);
96
+ /**
97
+ * The custom `endpoint` specific to the client
98
+ */
99
+ const clientEndpoint = internals.endpoint;
100
+ /**
101
+ * The `authMode` specific to the client.
102
+ */
103
+ const clientAuthMode = internals.authMode;
104
+ /**
105
+ * The `apiKey` specific to the client.
106
+ */
107
+ const clientApiKey = internals.apiKey;
108
+ /**
109
+ * The most specific `authMode` wins. Setting an `endpoint` value without also
110
+ * setting an `authMode` value is invalid. This helps to prevent customers apps
111
+ * from unexpectedly sending auth details to endpoints the auth details do not
112
+ * belong to.
113
+ *
114
+ * This is especially pronounced for `apiKey`. When both an `endpoint` *and*
115
+ * `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required
116
+ * to prevent inadvertent sending of an API's `apiKey` to an endpoint is does
117
+ * not belong to.
118
+ */
119
+ options.authMode = options.authMode || clientAuthMode;
120
+ options.apiKey = options.apiKey ?? clientApiKey;
121
+ options.authToken = options.authToken || internals.authToken;
122
+ if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {
123
+ throw new Error("graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.");
124
+ }
125
+ const headers = additionalHeaders || internals.headers;
126
+ /**
127
+ * The correctness of these typings depends on correct string branding or overrides.
128
+ * Neither of these can actually be validated at runtime. Hence, we don't perform
129
+ * any validation or type-guarding here.
130
+ */
131
+ const result = GraphQLAPI_1.GraphQLAPI.graphql(
132
+ // TODO: move V6Client back into this package?
133
+ internals.amplify, {
134
+ ...options,
135
+ endpoint: clientEndpoint,
136
+ }, headers);
137
+ return result;
138
+ }
139
+ /**
140
+ * Cancels an inflight request. Only applicable for graphql queries and mutations
141
+ * @param {any} request - request to cancel
142
+ * @returns - A boolean indicating if the request was cancelled
143
+ */
144
+ function cancel(promise, message) {
145
+ return GraphQLAPI_1.GraphQLAPI.cancel(promise, message);
146
+ }
147
+ /**
148
+ * Checks to see if an error thrown is from an api request cancellation
149
+ * @param {any} error - Any error
150
+ * @returns - A boolean indicating if the error was from an api request cancellation
151
+ */
152
+ function isCancelError(error) {
153
+ return GraphQLAPI_1.GraphQLAPI.isCancelError(error);
154
+ }
155
+ //# sourceMappingURL=v6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v6.js","sources":["../../../src/internals/v6.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.graphql = graphql;\nexports.cancel = cancel;\nexports.isCancelError = isCancelError;\nconst GraphQLAPI_1 = require(\"../GraphQLAPI\");\nconst types_1 = require(\"../types\");\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nfunction graphql(options, additionalHeaders) {\n // inject client-level auth\n const internals = (0, types_1.getInternals)(this);\n /**\n * The custom `endpoint` specific to the client\n */\n const clientEndpoint = internals.endpoint;\n /**\n * The `authMode` specific to the client.\n */\n const clientAuthMode = internals.authMode;\n /**\n * The `apiKey` specific to the client.\n */\n const clientApiKey = internals.apiKey;\n /**\n * The most specific `authMode` wins. Setting an `endpoint` value without also\n * setting an `authMode` value is invalid. This helps to prevent customers apps\n * from unexpectedly sending auth details to endpoints the auth details do not\n * belong to.\n *\n * This is especially pronounced for `apiKey`. When both an `endpoint` *and*\n * `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required\n * to prevent inadvertent sending of an API's `apiKey` to an endpoint is does\n * not belong to.\n */\n options.authMode = options.authMode || clientAuthMode;\n options.apiKey = options.apiKey ?? clientApiKey;\n options.authToken = options.authToken || internals.authToken;\n if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {\n throw new Error(\"graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.\");\n }\n const headers = additionalHeaders || internals.headers;\n /**\n * The correctness of these typings depends on correct string branding or overrides.\n * Neither of these can actually be validated at runtime. Hence, we don't perform\n * any validation or type-guarding here.\n */\n const result = GraphQLAPI_1.GraphQLAPI.graphql(\n // TODO: move V6Client back into this package?\n internals.amplify, {\n ...options,\n endpoint: clientEndpoint,\n }, headers);\n return result;\n}\n/**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\nfunction cancel(promise, message) {\n return GraphQLAPI_1.GraphQLAPI.cancel(promise, message);\n}\n/**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @returns - A boolean indicating if the error was from an api request cancellation\n */\nfunction isCancelError(error) {\n return GraphQLAPI_1.GraphQLAPI.isCancelError(error);\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,OAAO,GAAG,OAAO;AACzB,OAAO,CAAC,MAAM,GAAG,MAAM;AACvB,OAAO,CAAC,aAAa,GAAG,aAAa;AACrC,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;AAC7C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE;AAC7C;AACA,I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,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC;AACvD;;"}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateClient = generateClient;
7
+ const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
8
+ const server_1 = require("../internals/server");
9
+ const types_1 = require("../types");
10
+ /**
11
+ * Generates an GraphQL API client that works with Amplify server context.
12
+ *
13
+ * @example
14
+ * import config from './amplifyconfiguration.json';
15
+ * import { listPosts } from './graphql/queries';
16
+ *
17
+ * const client = generateServerClient({ config });
18
+ *
19
+ * const result = await runWithAmplifyServerContext({
20
+ * nextServerContext: { request, response },
21
+ * operation: (contextSpec) => client.graphql(contextSpec, {
22
+ * query: listPosts,
23
+ * }),
24
+ * });
25
+ */
26
+ function generateClient(options) {
27
+ // passing `null` instance because each (future model) method must retrieve a valid instance
28
+ // from server context
29
+ const client = (0, server_1.generateClientWithAmplifyInstance)({
30
+ amplify: null,
31
+ ...options,
32
+ });
33
+ // TODO: improve this and the next type
34
+ const prevGraphql = client.graphql;
35
+ const wrappedGraphql = (contextSpec, innerOptions, additionalHeaders) => {
36
+ const amplifyInstance = (0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify;
37
+ return prevGraphql.call({ [types_1.__amplify]: amplifyInstance }, innerOptions, additionalHeaders);
38
+ };
39
+ client.graphql = wrappedGraphql;
40
+ return client;
41
+ }
42
+ //# sourceMappingURL=generateClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClient.js","sources":["../../../src/server/generateClient.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = generateClient;\nconst adapter_core_1 = require(\"@aws-amplify/core/internals/adapter-core\");\nconst server_1 = require(\"../internals/server\");\nconst types_1 = require(\"../types\");\n/**\n * Generates an GraphQL API client that works with Amplify server context.\n *\n * @example\n * import config from './amplifyconfiguration.json';\n * import { listPosts } from './graphql/queries';\n *\n * const client = generateServerClient({ config });\n *\n * const result = await runWithAmplifyServerContext({\n * nextServerContext: { request, response },\n * operation: (contextSpec) => client.graphql(contextSpec, {\n * query: listPosts,\n * }),\n * });\n */\nfunction generateClient(options) {\n // passing `null` instance because each (future model) method must retrieve a valid instance\n // from server context\n const client = (0, server_1.generateClientWithAmplifyInstance)({\n amplify: null,\n ...options,\n });\n // TODO: improve this and the next type\n const prevGraphql = client.graphql;\n const wrappedGraphql = (contextSpec, innerOptions, additionalHeaders) => {\n const amplifyInstance = (0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify;\n return prevGraphql.call({ [types_1.__amplify]: amplifyInstance }, innerOptions, additionalHeaders);\n };\n client.graphql = wrappedGraphql;\n return client;\n}\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,cAAc,GAAG,cAAc;AACvC,MAAM,cAAc,GAAG,OAAO,CAAC,0CAA0C,CAAC;AAC1E,MAAM,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,cAAc,CAAC,OAAO,EAAE;AACjC;AACA;AACA,IAAI,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,iCAAiC,EAAE;AACnE,QAAQ,OAAO,EAAE,IAAI;AACrB,QAAQ,GAAG,OAAO;AAClB,KAAK,CAAC;AACN;AACA,IAAI,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO;AACtC,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,iBAAiB,KAAK;AAC7E,QAAQ,MAAM,eAAe,GAAG,IAAI,cAAc,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAC,OAAO;AAChG,QAAQ,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,GAAG,eAAe,EAAE,EAAE,YAAY,EAAE,iBAAiB,CAAC;AAC1G,IAAI,CAAC;AACL,IAAI,MAAM,CAAC,OAAO,GAAG,cAAc;AACnC,IAAI,OAAO,MAAM;AACjB;;"}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateClient = void 0;
7
+ var generateClient_1 = require("./generateClient");
8
+ Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return generateClient_1.generateClient; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/server/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\nvar generateClient_1 = require(\"./generateClient\");\nObject.defineProperty(exports, \"generateClient\", { enumerable: true, get: function () { return generateClient_1.generateClient; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,cAAc,GAAG,MAAM;AAC/B,IAAI,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAClD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;;"}
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ConnectionState = exports.CONTROL_MSG = void 0;
5
+ var CONTROL_MSG;
6
+ (function (CONTROL_MSG) {
7
+ CONTROL_MSG["CONNECTION_CLOSED"] = "Connection closed";
8
+ CONTROL_MSG["CONNECTION_FAILED"] = "Connection failed";
9
+ CONTROL_MSG["REALTIME_SUBSCRIPTION_INIT_ERROR"] = "AppSync Realtime subscription init error";
10
+ CONTROL_MSG["SUBSCRIPTION_ACK"] = "Subscription ack";
11
+ CONTROL_MSG["TIMEOUT_DISCONNECT"] = "Timeout disconnect";
12
+ })(CONTROL_MSG || (exports.CONTROL_MSG = CONTROL_MSG = {}));
13
+ /** @enum {string} */
14
+ var ConnectionState;
15
+ (function (ConnectionState) {
16
+ /*
17
+ * The connection is alive and healthy
18
+ */
19
+ ConnectionState["Connected"] = "Connected";
20
+ /*
21
+ * The connection is alive, but the connection is offline
22
+ */
23
+ ConnectionState["ConnectedPendingNetwork"] = "ConnectedPendingNetwork";
24
+ /*
25
+ * The connection has been disconnected while in use
26
+ */
27
+ ConnectionState["ConnectionDisrupted"] = "ConnectionDisrupted";
28
+ /*
29
+ * The connection has been disconnected and the network is offline
30
+ */
31
+ ConnectionState["ConnectionDisruptedPendingNetwork"] = "ConnectionDisruptedPendingNetwork";
32
+ /*
33
+ * The connection is in the process of connecting
34
+ */
35
+ ConnectionState["Connecting"] = "Connecting";
36
+ /*
37
+ * The connection is not in use and is being disconnected
38
+ */
39
+ ConnectionState["ConnectedPendingDisconnect"] = "ConnectedPendingDisconnect";
40
+ /*
41
+ * The connection is not in use and has been disconnected
42
+ */
43
+ ConnectionState["Disconnected"] = "Disconnected";
44
+ /*
45
+ * The connection is alive, but a keep alive message has been missed
46
+ */
47
+ ConnectionState["ConnectedPendingKeepAlive"] = "ConnectedPendingKeepAlive";
48
+ })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
49
+ //# sourceMappingURL=PubSub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PubSub.js","sources":["../../../src/types/PubSub.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ConnectionState = exports.CONTROL_MSG = void 0;\nvar CONTROL_MSG;\n(function (CONTROL_MSG) {\n CONTROL_MSG[\"CONNECTION_CLOSED\"] = \"Connection closed\";\n CONTROL_MSG[\"CONNECTION_FAILED\"] = \"Connection failed\";\n CONTROL_MSG[\"REALTIME_SUBSCRIPTION_INIT_ERROR\"] = \"AppSync Realtime subscription init error\";\n CONTROL_MSG[\"SUBSCRIPTION_ACK\"] = \"Subscription ack\";\n CONTROL_MSG[\"TIMEOUT_DISCONNECT\"] = \"Timeout disconnect\";\n})(CONTROL_MSG || (exports.CONTROL_MSG = CONTROL_MSG = {}));\n/** @enum {string} */\nvar ConnectionState;\n(function (ConnectionState) {\n /*\n * The connection is alive and healthy\n */\n ConnectionState[\"Connected\"] = \"Connected\";\n /*\n * The connection is alive, but the connection is offline\n */\n ConnectionState[\"ConnectedPendingNetwork\"] = \"ConnectedPendingNetwork\";\n /*\n * The connection has been disconnected while in use\n */\n ConnectionState[\"ConnectionDisrupted\"] = \"ConnectionDisrupted\";\n /*\n * The connection has been disconnected and the network is offline\n */\n ConnectionState[\"ConnectionDisruptedPendingNetwork\"] = \"ConnectionDisruptedPendingNetwork\";\n /*\n * The connection is in the process of connecting\n */\n ConnectionState[\"Connecting\"] = \"Connecting\";\n /*\n * The connection is not in use and is being disconnected\n */\n ConnectionState[\"ConnectedPendingDisconnect\"] = \"ConnectedPendingDisconnect\";\n /*\n * The connection is not in use and has been disconnected\n */\n ConnectionState[\"Disconnected\"] = \"Disconnected\";\n /*\n * The connection is alive, but a keep alive message has been missed\n */\n ConnectionState[\"ConnectedPendingKeepAlive\"] = \"ConnectedPendingKeepAlive\";\n})(ConnectionState || (exports.ConnectionState = ConnectionState = {}));\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,WAAW,GAAG,MAAM;AACtD,IAAI,WAAW;AACf,CAAC,UAAU,WAAW,EAAE;AACxB,IAAI,WAAW,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;AAC1D,IAAI,WAAW,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;AAC1D,IAAI,WAAW,CAAC,kCAAkC,CAAC,GAAG,0CAA0C;AAChG,IAAI,WAAW,CAAC,kBAAkB,CAAC,GAAG,kBAAkB;AACxD,IAAI,WAAW,CAAC,oBAAoB,CAAC,GAAG,oBAAoB;AAC5D,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,GAAG,WAAW,GAAG,EAAE,CAAC,CAAC;AAC3D;AACA,IAAI,eAAe;AACnB,CAAC,UAAU,eAAe,EAAE;AAC5B;AACA;AACA;AACA,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;AAC9C;AACA;AACA;AACA,IAAI,eAAe,CAAC,yBAAyB,CAAC,GAAG,yBAAyB;AAC1E;AACA;AACA;AACA,IAAI,eAAe,CAAC,qBAAqB,CAAC,GAAG,qBAAqB;AAClE;AACA;AACA;AACA,IAAI,eAAe,CAAC,mCAAmC,CAAC,GAAG,mCAAmC;AAC9F;AACA;AACA;AACA,IAAI,eAAe,CAAC,YAAY,CAAC,GAAG,YAAY;AAChD;AACA;AACA;AACA,IAAI,eAAe,CAAC,4BAA4B,CAAC,GAAG,4BAA4B;AAChF;AACA;AACA;AACA,IAAI,eAAe,CAAC,cAAc,CAAC,GAAG,cAAc;AACpD;AACA;AACA;AACA,IAAI,eAAe,CAAC,2BAA2B,CAAC,GAAG,2BAA2B;AAC9E,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,eAAe,GAAG,eAAe,GAAG,EAAE,CAAC,CAAC;;"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.__endpoint = exports.__headers = exports.__apiKey = exports.__authToken = exports.__authMode = exports.__amplify = exports.GraphQLAuthError = exports.ConnectionState = exports.CONTROL_MSG = void 0;
5
+ exports.getInternals = getInternals;
6
+ var PubSub_1 = require("./PubSub");
7
+ Object.defineProperty(exports, "CONTROL_MSG", { enumerable: true, get: function () { return PubSub_1.CONTROL_MSG; } });
8
+ Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return PubSub_1.ConnectionState; } });
9
+ var GraphQLAuthError;
10
+ (function (GraphQLAuthError) {
11
+ GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
12
+ GraphQLAuthError["NO_CURRENT_USER"] = "No current user";
13
+ GraphQLAuthError["NO_CREDENTIALS"] = "No credentials";
14
+ GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
15
+ GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
16
+ })(GraphQLAuthError || (exports.GraphQLAuthError = GraphQLAuthError = {}));
17
+ exports.__amplify = Symbol('amplify');
18
+ exports.__authMode = Symbol('authMode');
19
+ exports.__authToken = Symbol('authToken');
20
+ exports.__apiKey = Symbol('apiKey');
21
+ exports.__headers = Symbol('headers');
22
+ exports.__endpoint = Symbol('endpoint');
23
+ function getInternals(client) {
24
+ const c = client;
25
+ return {
26
+ amplify: c[exports.__amplify],
27
+ apiKey: c[exports.__apiKey],
28
+ authMode: c[exports.__authMode],
29
+ authToken: c[exports.__authToken],
30
+ endpoint: c[exports.__endpoint],
31
+ headers: c[exports.__headers],
32
+ };
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/types/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.__endpoint = exports.__headers = exports.__apiKey = exports.__authToken = exports.__authMode = exports.__amplify = exports.GraphQLAuthError = exports.ConnectionState = exports.CONTROL_MSG = void 0;\nexports.getInternals = getInternals;\nvar PubSub_1 = require(\"./PubSub\");\nObject.defineProperty(exports, \"CONTROL_MSG\", { enumerable: true, get: function () { return PubSub_1.CONTROL_MSG; } });\nObject.defineProperty(exports, \"ConnectionState\", { enumerable: true, get: function () { return PubSub_1.ConnectionState; } });\nvar GraphQLAuthError;\n(function (GraphQLAuthError) {\n GraphQLAuthError[\"NO_API_KEY\"] = \"No api-key configured\";\n GraphQLAuthError[\"NO_CURRENT_USER\"] = \"No current user\";\n GraphQLAuthError[\"NO_CREDENTIALS\"] = \"No credentials\";\n GraphQLAuthError[\"NO_FEDERATED_JWT\"] = \"No federated jwt\";\n GraphQLAuthError[\"NO_AUTH_TOKEN\"] = \"No auth token specified\";\n})(GraphQLAuthError || (exports.GraphQLAuthError = GraphQLAuthError = {}));\nexports.__amplify = Symbol('amplify');\nexports.__authMode = Symbol('authMode');\nexports.__authToken = Symbol('authToken');\nexports.__apiKey = Symbol('apiKey');\nexports.__headers = Symbol('headers');\nexports.__endpoint = Symbol('endpoint');\nfunction getInternals(client) {\n const c = client;\n return {\n amplify: c[exports.__amplify],\n apiKey: c[exports.__apiKey],\n authMode: c[exports.__authMode],\n authToken: c[exports.__authToken],\n endpoint: c[exports.__endpoint],\n headers: c[exports.__headers],\n };\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,gBAAgB,GAAG,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC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AI,MAAM,CAAC,GAAG,MAAM;AACpB,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;AACrC,QAAQ,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;AACnC,QAAQ,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;AACvC,QAAQ,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;AACzC,QAAQ,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;AACvC,QAAQ,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;AACrC,KAAK;AACL;;"}
@@ -0,0 +1,134 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConnectionStateMonitor = exports.CONNECTION_CHANGE = void 0;
7
+ const rxjs_1 = require("rxjs");
8
+ const PubSub_1 = require("../types/PubSub");
9
+ const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
10
+ exports.CONNECTION_CHANGE = {
11
+ KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
12
+ KEEP_ALIVE: { keepAliveState: 'healthy' },
13
+ CONNECTION_ESTABLISHED: { connectionState: 'connected' },
14
+ CONNECTION_FAILED: {
15
+ intendedConnectionState: 'disconnected',
16
+ connectionState: 'disconnected',
17
+ },
18
+ CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
19
+ OPENING_CONNECTION: {
20
+ intendedConnectionState: 'connected',
21
+ connectionState: 'connecting',
22
+ },
23
+ CLOSED: { connectionState: 'disconnected' },
24
+ ONLINE: { networkState: 'connected' },
25
+ OFFLINE: { networkState: 'disconnected' },
26
+ };
27
+ class ConnectionStateMonitor {
28
+ constructor() {
29
+ this._networkMonitoringSubscription = undefined;
30
+ this._linkedConnectionState = {
31
+ networkState: 'connected',
32
+ connectionState: 'disconnected',
33
+ intendedConnectionState: 'disconnected',
34
+ keepAliveState: 'healthy',
35
+ };
36
+ // Attempt to update the state with the current actual network state
37
+ this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
38
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
39
+ this._initialNetworkStateSubscription?.unsubscribe();
40
+ });
41
+ this._linkedConnectionStateObservable =
42
+ new rxjs_1.Observable(connectionStateObserver => {
43
+ connectionStateObserver.next(this._linkedConnectionState);
44
+ this._linkedConnectionStateObserver = connectionStateObserver;
45
+ });
46
+ }
47
+ /**
48
+ * Turn network state monitoring on if it isn't on already
49
+ */
50
+ enableNetworkMonitoring() {
51
+ // If no initial network state was discovered, stop trying
52
+ this._initialNetworkStateSubscription?.unsubscribe();
53
+ // Maintain the network state based on the reachability monitor
54
+ if (this._networkMonitoringSubscription === undefined) {
55
+ this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
56
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
57
+ });
58
+ }
59
+ }
60
+ /**
61
+ * Turn network state monitoring off if it isn't off already
62
+ */
63
+ disableNetworkMonitoring() {
64
+ this._networkMonitoringSubscription?.unsubscribe();
65
+ this._networkMonitoringSubscription = undefined;
66
+ }
67
+ /**
68
+ * Get the observable that allows us to monitor the connection state
69
+ *
70
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
71
+ */
72
+ get connectionStateObservable() {
73
+ let previous;
74
+ // The linked state aggregates state changes to any of the network, connection,
75
+ // intendedConnection and keepAliveHealth. Some states will change these independent
76
+ // states without changing the overall connection state.
77
+ // After translating from linked states to ConnectionState, then remove any duplicates
78
+ return this._linkedConnectionStateObservable
79
+ .pipe((0, rxjs_1.map)(value => {
80
+ return this.connectionStatesTranslator(value);
81
+ }))
82
+ .pipe((0, rxjs_1.filter)(current => {
83
+ const toInclude = current !== previous;
84
+ previous = current;
85
+ return toInclude;
86
+ }));
87
+ }
88
+ /*
89
+ * Updates local connection state and emits the full state to the observer.
90
+ */
91
+ record(statusUpdates) {
92
+ // Maintain the network monitor
93
+ if (statusUpdates.intendedConnectionState === 'connected') {
94
+ this.enableNetworkMonitoring();
95
+ }
96
+ else if (statusUpdates.intendedConnectionState === 'disconnected') {
97
+ this.disableNetworkMonitoring();
98
+ }
99
+ // Maintain the socket state
100
+ const newSocketStatus = {
101
+ ...this._linkedConnectionState,
102
+ ...statusUpdates,
103
+ };
104
+ this._linkedConnectionState = { ...newSocketStatus };
105
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
106
+ }
107
+ /*
108
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
109
+ */
110
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
111
+ if (connectionState === 'connected' && networkState === 'disconnected')
112
+ return PubSub_1.ConnectionState.ConnectedPendingNetwork;
113
+ if (connectionState === 'connected' &&
114
+ intendedConnectionState === 'disconnected')
115
+ return PubSub_1.ConnectionState.ConnectedPendingDisconnect;
116
+ if (connectionState === 'disconnected' &&
117
+ intendedConnectionState === 'connected' &&
118
+ networkState === 'disconnected')
119
+ return PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork;
120
+ if (connectionState === 'disconnected' &&
121
+ intendedConnectionState === 'connected')
122
+ return PubSub_1.ConnectionState.ConnectionDisrupted;
123
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy')
124
+ return PubSub_1.ConnectionState.ConnectedPendingKeepAlive;
125
+ // All remaining states directly correspond to the connection state
126
+ if (connectionState === 'connecting')
127
+ return PubSub_1.ConnectionState.Connecting;
128
+ if (connectionState === 'disconnected')
129
+ return PubSub_1.ConnectionState.Disconnected;
130
+ return PubSub_1.ConnectionState.Connected;
131
+ }
132
+ }
133
+ exports.ConnectionStateMonitor = ConnectionStateMonitor;
134
+ //# sourceMappingURL=ConnectionStateMonitor.js.map