@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,369 @@
1
+ import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
2
+ import { BaseClient, ClientExtensions, ClientExtensionsSSRCookies, ClientExtensionsSSRRequest, ClientInternals, CustomHeaders, ModelSortDirection } from '@aws-amplify/data-schema/runtime';
3
+ import { DocumentNode, GraphQLError, Source } from 'graphql';
4
+ import { Observable } from 'rxjs';
5
+ import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
6
+ import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
7
+ import { CommonPublicClientOptions } from '../internals/types';
8
+ export { OperationTypeNode } from 'graphql';
9
+ export { CONTROL_MSG, ConnectionState } from './PubSub';
10
+ export { SelectionSet } from '@aws-amplify/data-schema/runtime';
11
+ export type { CommonPublicClientOptions };
12
+ /**
13
+ * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
14
+ */
15
+ export interface GraphQLOptions {
16
+ query: string | DocumentNode;
17
+ endpoint?: string;
18
+ variables?: Record<string, DocumentType>;
19
+ authMode?: GraphQLAuthMode;
20
+ authToken?: string;
21
+ apiKey?: string;
22
+ /**
23
+ * @deprecated This property should not be used
24
+ */
25
+ userAgentSuffix?: string;
26
+ }
27
+ export interface GraphQLResult<T = object | null> {
28
+ data: T;
29
+ errors?: GraphQLError[];
30
+ extensions?: Record<string, any>;
31
+ }
32
+ declare const queryType: unique symbol;
33
+ export type GraphQLQuery<T> = T & {
34
+ readonly [queryType]: 'query';
35
+ };
36
+ export type GraphQLSubscription<T> = T & {
37
+ readonly [queryType]: 'subscription';
38
+ };
39
+ /**
40
+ * Accepts a code generated model type and returns a supertype that
41
+ * can accept return values from the relevant graphql operations.
42
+ *
43
+ * For example:
44
+ *
45
+ * ```typescript
46
+ * import { GraphQLReturnType } from 'aws-amplify/api';
47
+ * import { MyModel } from './API';
48
+ * import { getMyModel } from './graphql/queries';
49
+ *
50
+ * const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
51
+ * setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)
52
+ * ```
53
+ *
54
+ * Trying to assign the result of a `getMyModel` operation directly to a
55
+ * `MyModel` variables won't necessarily work, because normally-required related
56
+ * models might not be part of the selection set.
57
+ *
58
+ * This util simply makes related model properties optional recursively.
59
+ */
60
+ export type GraphQLReturnType<T> = T extends Record<string, unknown> ? {
61
+ [K in keyof T]?: GraphQLReturnType<T[K]>;
62
+ } : T;
63
+ /**
64
+ * Describes a paged list result from AppSync, which can either
65
+ * live at the top query or property (e.g., related model) level.
66
+ */
67
+ interface PagedList<T, TYPENAME> {
68
+ __typename: TYPENAME;
69
+ nextToken?: string | null | undefined;
70
+ items: T[];
71
+ }
72
+ /**
73
+ * Recursively looks through a result type and removes nulls and
74
+ * and undefined from `PagedList` types.
75
+ *
76
+ * Although a graphql response might contain empty values in an
77
+ * array, this will only be the case when we also have errors,
78
+ * which will then be *thrown*.
79
+ */
80
+ type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends Record<string, unknown> ? {
81
+ [K in keyof T]: WithListsFixed<T[K]>;
82
+ } : T;
83
+ /**
84
+ * Returns an updated response type to always return a value.
85
+ */
86
+ type NeverEmpty<T> = {
87
+ [K in keyof T]-?: Exclude<WithListsFixed<T[K]>, undefined | null>;
88
+ };
89
+ /**
90
+ * Replaces all list result types in a query result with types to exclude
91
+ * nulls and undefined from list member unions.
92
+ *
93
+ * If empty members are present, there will also be errors present,
94
+ * and the response will instead be *thrown*.
95
+ */
96
+ type FixedQueryResult<T> = Exclude<T[keyof T], null | undefined> extends PagedList<any, any> ? {
97
+ [K in keyof T]-?: WithListsFixed<Exclude<T[K], null | undefined>>;
98
+ } : T;
99
+ /**
100
+ * The return value from a `graphql({query})` call when `query` is a subscription.
101
+ *
102
+ * ```ts
103
+ * // |-- You are here
104
+ * // v
105
+ * const subResult: GraphqlSubscriptionResult<T> = client.graphql({
106
+ * query: onCreateWidget
107
+ * });
108
+ *
109
+ * const sub = subResult.subscribe({
110
+ * //
111
+ * // |-- You are here
112
+ * // v
113
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
114
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
115
+ * }
116
+ * })
117
+ * ```
118
+ */
119
+ export type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage<T>>;
120
+ /**
121
+ * The shape of messages passed to `next()` from a graphql subscription. E.g.,
122
+ *
123
+ * ```ts
124
+ * const sub = client.graphql({
125
+ * query: onCreateWidget,
126
+ * }).subscribe({
127
+ * //
128
+ * // |-- You are here
129
+ * // v
130
+ * next(message: GraphqlSubscriptionMessage<OnCreateWidgetSubscription>) {
131
+ * handle(message.value); // <-- type OnCreateWidgetSubscription
132
+ * }
133
+ * })
134
+ * ```
135
+ */
136
+ export interface GraphqlSubscriptionMessage<T> {
137
+ data: T;
138
+ }
139
+ export interface AWSAppSyncRealTimeProviderOptions {
140
+ appSyncGraphqlEndpoint?: string;
141
+ authenticationType?: GraphQLAuthMode;
142
+ query?: string;
143
+ variables?: Record<string, unknown>;
144
+ apiKey?: string;
145
+ region?: string;
146
+ libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
147
+ additionalHeaders?: CustomHeaders;
148
+ }
149
+ export interface AWSAppSyncRealTimeProvider {
150
+ subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
151
+ }
152
+ export declare enum GraphQLAuthError {
153
+ NO_API_KEY = "No api-key configured",
154
+ NO_CURRENT_USER = "No current user",
155
+ NO_CREDENTIALS = "No credentials",
156
+ NO_FEDERATED_JWT = "No federated jwt",
157
+ NO_AUTH_TOKEN = "No auth token specified"
158
+ }
159
+ /**
160
+ * GraphQLSource or string, the type of the parameter for calling graphql.parse
161
+ * @see: https://graphql.org/graphql-js/language/#parse
162
+ */
163
+ export type GraphQLOperation = Source | string;
164
+ /**
165
+ * API V6 `graphql({options})` type that can leverage branded graphql `query`
166
+ * objects and fallback types.
167
+ */
168
+ export type GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string, Options extends CommonPublicClientOptions = object> = Options['endpoint'] extends string ? Options['apiKey'] extends string ? {
169
+ query: TYPED_GQL_STRING | DocumentNode;
170
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
171
+ authMode?: GraphQLAuthMode;
172
+ apiKey?: string;
173
+ authToken?: string;
174
+ /**
175
+ * @deprecated This property should not be used
176
+ */
177
+ userAgentSuffix?: string;
178
+ } : {
179
+ query: TYPED_GQL_STRING | DocumentNode;
180
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
181
+ authMode?: never;
182
+ apiKey?: never;
183
+ authToken?: string;
184
+ /**
185
+ * @deprecated This property should not be used
186
+ */
187
+ userAgentSuffix?: string;
188
+ } | {
189
+ query: TYPED_GQL_STRING | DocumentNode;
190
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
191
+ authMode: 'apiKey';
192
+ apiKey: string;
193
+ authToken?: string;
194
+ /**
195
+ * @deprecated This property should not be used
196
+ */
197
+ userAgentSuffix?: string;
198
+ } | {
199
+ query: TYPED_GQL_STRING | DocumentNode;
200
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
201
+ authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
202
+ apiKey?: never;
203
+ authToken?: string;
204
+ /**
205
+ * @deprecated This property should not be used
206
+ */
207
+ userAgentSuffix?: string;
208
+ } : {
209
+ query: TYPED_GQL_STRING | DocumentNode;
210
+ variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
211
+ authMode?: GraphQLAuthMode;
212
+ apiKey?: string;
213
+ authToken?: string;
214
+ /**
215
+ * @deprecated This property should not be used
216
+ */
217
+ userAgentSuffix?: string;
218
+ };
219
+ /**
220
+ * Result type for `graphql()` operations that don't include any specific
221
+ * type information. The result could be either a `Promise` or `Subscription`.
222
+ *
223
+ * Invoking code should either cast the result or use `?` and `!` operators to
224
+ * navigate the result objects.
225
+ */
226
+ export type UnknownGraphQLResponse = Promise<GraphQLResult<any>> | GraphqlSubscriptionResult<any>;
227
+ /**
228
+ * The expected type for `variables` in a V6 `graphql()` operation with
229
+ * respect to the given `FALLBACK_TYPES` and `TYPED_GQL_STRING`.
230
+ */
231
+ export type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedMutation<infer IN, any> ? IN : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, any> ? IN : FALLBACK_TYPES extends GraphQLOperationType<infer IN, any> ? IN : any;
232
+ /**
233
+ * The expected return type with respect to the given `FALLBACK_TYPE`
234
+ * and `TYPED_GQL_STRING`.
235
+ */
236
+ export type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer _, infer QUERY_OUT> ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>> : TYPED_GQL_STRING extends GeneratedMutation<infer _, infer MUTATION_OUT> ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>> : TYPED_GQL_STRING extends GeneratedSubscription<infer _, infer SUB_OUT> ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>> : FALLBACK_TYPE extends GraphQLQuery<infer _> ? Promise<GraphQLResult<FALLBACK_TYPE>> : FALLBACK_TYPE extends GraphQLSubscription<infer _> ? GraphqlSubscriptionResult<FALLBACK_TYPE> : FALLBACK_TYPE extends GraphQLOperationType<infer _, infer CUSTOM_OUT> ? CUSTOM_OUT : UnknownGraphQLResponse;
237
+ /**
238
+ * The shape customers can use to provide `T` to `graphql<T>()` to specify both
239
+ * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
240
+ *
241
+ * I.E.,
242
+ *
243
+ * ```ts
244
+ * type MyVariablesType = { ... };
245
+ * type MyResultType = { ... };
246
+ * type MyOperationType = { variables: MyVariablesType, result: MyResultType };
247
+ *
248
+ * const result: MyResultType = graphql<MyOperationType>("graphql string", {
249
+ * variables: {
250
+ * // MyVariablesType
251
+ * }
252
+ * })
253
+ * ```
254
+ */
255
+ export interface GraphQLOperationType<IN extends Record<string, DocumentType>, OUT extends Record<string, DocumentType>> {
256
+ variables: IN;
257
+ result: OUT;
258
+ }
259
+ /**
260
+ * Nominal type for branding generated graphql query operation strings with
261
+ * input and output types.
262
+ *
263
+ * E.g.,
264
+ *
265
+ * ```ts
266
+ * export const getWidget = `...` as GeneratedQuery<
267
+ * GetWidgetQueryVariables,
268
+ * GetWidgetQuery
269
+ * >;
270
+ * ```
271
+ *
272
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
273
+ * assign types to the `variables` and result objects.
274
+ */
275
+ export type GeneratedQuery<InputType, OutputType> = string & {
276
+ __generatedQueryInput: InputType;
277
+ __generatedQueryOutput: OutputType;
278
+ };
279
+ /**
280
+ * Nominal type for branding generated graphql mutation operation strings with
281
+ * input and output types.
282
+ *
283
+ * E.g.,
284
+ *
285
+ * ```ts
286
+ * export const createWidget = `...` as GeneratedQuery<
287
+ * CreateWidgetMutationVariables,
288
+ * CreateWidgetMutation
289
+ * >;
290
+ * ```
291
+ *
292
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
293
+ * assign types to the `variables` and result objects.
294
+ */
295
+ export type GeneratedMutation<InputType, OutputType> = string & {
296
+ __generatedMutationInput: InputType;
297
+ __generatedMutationOutput: OutputType;
298
+ };
299
+ /**
300
+ * Nominal type for branding generated graphql mutation operation strings with
301
+ * input and output types.
302
+ *
303
+ * E.g.,
304
+ *
305
+ * ```ts
306
+ * export const createWidget = `...` as GeneratedMutation<
307
+ * CreateWidgetMutationVariables,
308
+ * CreateWidgetMutation
309
+ * >;
310
+ * ```
311
+ *
312
+ * This allows `graphql()` to extract `InputType` and `OutputType` to correctly
313
+ * assign types to the `variables` and result objects.
314
+ */
315
+ export type GeneratedSubscription<InputType, OutputType> = string & {
316
+ __generatedSubscriptionInput: InputType;
317
+ __generatedSubscriptionOutput: OutputType;
318
+ };
319
+ export declare const __amplify: unique symbol;
320
+ export declare const __authMode: unique symbol;
321
+ export declare const __authToken: unique symbol;
322
+ export declare const __apiKey: unique symbol;
323
+ export declare const __headers: unique symbol;
324
+ export declare const __endpoint: unique symbol;
325
+ export declare function getInternals(client: BaseClient): ClientInternals & {
326
+ apiKey?: string;
327
+ endpoint?: string;
328
+ };
329
+ export type ClientWithModels = V6Client | V6ClientSSRRequest | V6ClientSSRCookies;
330
+ export type V6Client<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
331
+ graphql: GraphQLMethod<Options>;
332
+ cancel(promise: Promise<any>, message?: string): boolean;
333
+ isCancelError(error: any): boolean;
334
+ } & ClientExtensions<T>;
335
+ export type V6ClientSSRRequest<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
336
+ graphql: GraphQLMethodSSR<Options>;
337
+ cancel(promise: Promise<any>, message?: string): boolean;
338
+ isCancelError(error: any): boolean;
339
+ } & ClientExtensionsSSRRequest<T>;
340
+ export type V6ClientSSRCookies<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
341
+ graphql: GraphQLMethod<Options>;
342
+ cancel(promise: Promise<any>, message?: string): boolean;
343
+ isCancelError(error: any): boolean;
344
+ } & ClientExtensionsSSRCookies<T>;
345
+ export type GraphQLMethod<Options extends CommonPublicClientOptions> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, Options>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
346
+ export type GraphQLMethodSSR<Options extends CommonPublicClientOptions> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, Options>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
347
+ /**
348
+ * @private
349
+ *
350
+ * The knobs available for configuring `server/generateClient` internally.
351
+ */
352
+ export interface ServerClientGenerationParams {
353
+ amplify: null | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
354
+ config: ResourcesConfig;
355
+ }
356
+ export type QueryArgs = Record<string, unknown>;
357
+ export interface ListArgs extends Record<string, unknown> {
358
+ selectionSet?: string[];
359
+ filter?: Record<string, unknown>;
360
+ sortDirection?: ModelSortDirection;
361
+ headers?: CustomHeaders;
362
+ }
363
+ export interface AuthModeParams extends Record<string, unknown> {
364
+ authMode?: GraphQLAuthMode;
365
+ authToken?: string;
366
+ }
367
+ export type GenerateServerClientParams = {
368
+ config: ResourcesConfig;
369
+ } & CommonPublicClientOptions;
@@ -0,0 +1,30 @@
1
+ export { CONTROL_MSG, ConnectionState } from './PubSub.mjs';
2
+
3
+ var GraphQLAuthError;
4
+ (function (GraphQLAuthError) {
5
+ GraphQLAuthError["NO_API_KEY"] = "No api-key configured";
6
+ GraphQLAuthError["NO_CURRENT_USER"] = "No current user";
7
+ GraphQLAuthError["NO_CREDENTIALS"] = "No credentials";
8
+ GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
9
+ GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
10
+ })(GraphQLAuthError || (GraphQLAuthError = {}));
11
+ const __amplify = Symbol('amplify');
12
+ const __authMode = Symbol('authMode');
13
+ const __authToken = Symbol('authToken');
14
+ const __apiKey = Symbol('apiKey');
15
+ const __headers = Symbol('headers');
16
+ const __endpoint = Symbol('endpoint');
17
+ function getInternals(client) {
18
+ const c = client;
19
+ return {
20
+ amplify: c[__amplify],
21
+ apiKey: c[__apiKey],
22
+ authMode: c[__authMode],
23
+ authToken: c[__authToken],
24
+ endpoint: c[__endpoint],
25
+ headers: c[__headers],
26
+ };
27
+ }
28
+
29
+ export { GraphQLAuthError, __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals };
30
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/types/index.ts"],"sourcesContent":["export { CONTROL_MSG, ConnectionState } from './PubSub';\nexport var 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 || (GraphQLAuthError = {}));\nexport const __amplify = Symbol('amplify');\nexport const __authMode = Symbol('authMode');\nexport const __authToken = Symbol('authToken');\nexport const __apiKey = Symbol('apiKey');\nexport const __headers = Symbol('headers');\nexport const __endpoint = Symbol('endpoint');\nexport function getInternals(client) {\n const c = client;\n return {\n amplify: c[__amplify],\n apiKey: c[__apiKey],\n authMode: c[__authMode],\n authToken: c[__authToken],\n endpoint: c[__endpoint],\n headers: c[__headers],\n };\n}\n"],"names":[],"mappings":";;AACU,IAAC;AACX,CAAC,UAAU,gBAAgB,EAAE;AAC7B,IAAI,gBAAgB,CAAC,YAAY,CAAC,GAAG,uBAAuB;AAC5D,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,iBAAiB;AAC3D,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,gBAAgB;AACzD,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,kBAAkB;AAC7D,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,yBAAyB;AACjE,CAAC,EAAE,gBAAgB,KAAK,gBAAgB,GAAG,EAAE,CAAC,CAAC;AACnC,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAC7B,MAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AAC/B,MAAC,WAAW,GAAG,MAAM,CAAC,WAAW;AACjC,MAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ;AAC3B,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAC7B,MAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACpC,SAAS,YAAY,CAAC,MAAM,EAAE;AACrC,IAAI,MAAM,CAAC,GAAG,MAAM;AACpB,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;AAC7B,QAAQ,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;AAC3B,QAAQ,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;AAC/B,QAAQ,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC;AACjC,QAAQ,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;AAC/B,QAAQ,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;AAC7B,KAAK;AACL;;;;"}
@@ -0,0 +1,69 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ConnectionState } from '../types/PubSub';
3
+ type LinkedConnectionState = 'connected' | 'disconnected';
4
+ type LinkedHealthState = 'healthy' | 'unhealthy';
5
+ interface LinkedConnectionStates {
6
+ networkState: LinkedConnectionState;
7
+ connectionState: LinkedConnectionState | 'connecting';
8
+ intendedConnectionState: LinkedConnectionState;
9
+ keepAliveState: LinkedHealthState;
10
+ }
11
+ export declare const CONNECTION_CHANGE: {
12
+ readonly KEEP_ALIVE_MISSED: {
13
+ readonly keepAliveState: "unhealthy";
14
+ };
15
+ readonly KEEP_ALIVE: {
16
+ readonly keepAliveState: "healthy";
17
+ };
18
+ readonly CONNECTION_ESTABLISHED: {
19
+ readonly connectionState: "connected";
20
+ };
21
+ readonly CONNECTION_FAILED: {
22
+ readonly intendedConnectionState: "disconnected";
23
+ readonly connectionState: "disconnected";
24
+ };
25
+ readonly CLOSING_CONNECTION: {
26
+ readonly intendedConnectionState: "disconnected";
27
+ };
28
+ readonly OPENING_CONNECTION: {
29
+ readonly intendedConnectionState: "connected";
30
+ readonly connectionState: "connecting";
31
+ };
32
+ readonly CLOSED: {
33
+ readonly connectionState: "disconnected";
34
+ };
35
+ readonly ONLINE: {
36
+ readonly networkState: "connected";
37
+ };
38
+ readonly OFFLINE: {
39
+ readonly networkState: "disconnected";
40
+ };
41
+ };
42
+ export declare class ConnectionStateMonitor {
43
+ /**
44
+ * @private
45
+ */
46
+ private _linkedConnectionState;
47
+ private _linkedConnectionStateObservable;
48
+ private _linkedConnectionStateObserver;
49
+ private _networkMonitoringSubscription?;
50
+ private _initialNetworkStateSubscription?;
51
+ constructor();
52
+ /**
53
+ * Turn network state monitoring on if it isn't on already
54
+ */
55
+ private enableNetworkMonitoring;
56
+ /**
57
+ * Turn network state monitoring off if it isn't off already
58
+ */
59
+ private disableNetworkMonitoring;
60
+ /**
61
+ * Get the observable that allows us to monitor the connection state
62
+ *
63
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
64
+ */
65
+ get connectionStateObservable(): Observable<ConnectionState>;
66
+ record(statusUpdates: Partial<LinkedConnectionStates>): void;
67
+ private connectionStatesTranslator;
68
+ }
69
+ export {};
@@ -0,0 +1,132 @@
1
+ import { Observable, map, filter } from 'rxjs';
2
+ import { ConnectionState } from '../types/PubSub.mjs';
3
+ import { ReachabilityMonitor } from './ReachabilityMonitor/index.mjs';
4
+
5
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ const CONNECTION_CHANGE = {
8
+ KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
9
+ KEEP_ALIVE: { keepAliveState: 'healthy' },
10
+ CONNECTION_ESTABLISHED: { connectionState: 'connected' },
11
+ CONNECTION_FAILED: {
12
+ intendedConnectionState: 'disconnected',
13
+ connectionState: 'disconnected',
14
+ },
15
+ CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },
16
+ OPENING_CONNECTION: {
17
+ intendedConnectionState: 'connected',
18
+ connectionState: 'connecting',
19
+ },
20
+ CLOSED: { connectionState: 'disconnected' },
21
+ ONLINE: { networkState: 'connected' },
22
+ OFFLINE: { networkState: 'disconnected' },
23
+ };
24
+ class ConnectionStateMonitor {
25
+ constructor() {
26
+ this._networkMonitoringSubscription = undefined;
27
+ this._linkedConnectionState = {
28
+ networkState: 'connected',
29
+ connectionState: 'disconnected',
30
+ intendedConnectionState: 'disconnected',
31
+ keepAliveState: 'healthy',
32
+ };
33
+ // Attempt to update the state with the current actual network state
34
+ this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(({ online }) => {
35
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
36
+ this._initialNetworkStateSubscription?.unsubscribe();
37
+ });
38
+ this._linkedConnectionStateObservable =
39
+ new Observable(connectionStateObserver => {
40
+ connectionStateObserver.next(this._linkedConnectionState);
41
+ this._linkedConnectionStateObserver = connectionStateObserver;
42
+ });
43
+ }
44
+ /**
45
+ * Turn network state monitoring on if it isn't on already
46
+ */
47
+ enableNetworkMonitoring() {
48
+ // If no initial network state was discovered, stop trying
49
+ this._initialNetworkStateSubscription?.unsubscribe();
50
+ // Maintain the network state based on the reachability monitor
51
+ if (this._networkMonitoringSubscription === undefined) {
52
+ this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(({ online }) => {
53
+ this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);
54
+ });
55
+ }
56
+ }
57
+ /**
58
+ * Turn network state monitoring off if it isn't off already
59
+ */
60
+ disableNetworkMonitoring() {
61
+ this._networkMonitoringSubscription?.unsubscribe();
62
+ this._networkMonitoringSubscription = undefined;
63
+ }
64
+ /**
65
+ * Get the observable that allows us to monitor the connection state
66
+ *
67
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
68
+ */
69
+ get connectionStateObservable() {
70
+ let previous;
71
+ // The linked state aggregates state changes to any of the network, connection,
72
+ // intendedConnection and keepAliveHealth. Some states will change these independent
73
+ // states without changing the overall connection state.
74
+ // After translating from linked states to ConnectionState, then remove any duplicates
75
+ return this._linkedConnectionStateObservable
76
+ .pipe(map(value => {
77
+ return this.connectionStatesTranslator(value);
78
+ }))
79
+ .pipe(filter(current => {
80
+ const toInclude = current !== previous;
81
+ previous = current;
82
+ return toInclude;
83
+ }));
84
+ }
85
+ /*
86
+ * Updates local connection state and emits the full state to the observer.
87
+ */
88
+ record(statusUpdates) {
89
+ // Maintain the network monitor
90
+ if (statusUpdates.intendedConnectionState === 'connected') {
91
+ this.enableNetworkMonitoring();
92
+ }
93
+ else if (statusUpdates.intendedConnectionState === 'disconnected') {
94
+ this.disableNetworkMonitoring();
95
+ }
96
+ // Maintain the socket state
97
+ const newSocketStatus = {
98
+ ...this._linkedConnectionState,
99
+ ...statusUpdates,
100
+ };
101
+ this._linkedConnectionState = { ...newSocketStatus };
102
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
103
+ }
104
+ /*
105
+ * Translate the ConnectionState structure into a specific ConnectionState string literal union
106
+ */
107
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
108
+ if (connectionState === 'connected' && networkState === 'disconnected')
109
+ return ConnectionState.ConnectedPendingNetwork;
110
+ if (connectionState === 'connected' &&
111
+ intendedConnectionState === 'disconnected')
112
+ return ConnectionState.ConnectedPendingDisconnect;
113
+ if (connectionState === 'disconnected' &&
114
+ intendedConnectionState === 'connected' &&
115
+ networkState === 'disconnected')
116
+ return ConnectionState.ConnectionDisruptedPendingNetwork;
117
+ if (connectionState === 'disconnected' &&
118
+ intendedConnectionState === 'connected')
119
+ return ConnectionState.ConnectionDisrupted;
120
+ if (connectionState === 'connected' && keepAliveState === 'unhealthy')
121
+ return ConnectionState.ConnectedPendingKeepAlive;
122
+ // All remaining states directly correspond to the connection state
123
+ if (connectionState === 'connecting')
124
+ return ConnectionState.Connecting;
125
+ if (connectionState === 'disconnected')
126
+ return ConnectionState.Disconnected;
127
+ return ConnectionState.Connected;
128
+ }
129
+ }
130
+
131
+ export { CONNECTION_CHANGE, ConnectionStateMonitor };
132
+ //# sourceMappingURL=ConnectionStateMonitor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionStateMonitor.mjs","sources":["../../../src/utils/ConnectionStateMonitor.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Observable, filter, map } from 'rxjs';\nimport { ConnectionState } from '../types/PubSub';\nimport { ReachabilityMonitor } from './ReachabilityMonitor';\nexport const CONNECTION_CHANGE = {\n KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },\n KEEP_ALIVE: { keepAliveState: 'healthy' },\n CONNECTION_ESTABLISHED: { connectionState: 'connected' },\n CONNECTION_FAILED: {\n intendedConnectionState: 'disconnected',\n connectionState: 'disconnected',\n },\n CLOSING_CONNECTION: { intendedConnectionState: 'disconnected' },\n OPENING_CONNECTION: {\n intendedConnectionState: 'connected',\n connectionState: 'connecting',\n },\n CLOSED: { connectionState: 'disconnected' },\n ONLINE: { networkState: 'connected' },\n OFFLINE: { networkState: 'disconnected' },\n};\nexport class ConnectionStateMonitor {\n constructor() {\n this._networkMonitoringSubscription = undefined;\n this._linkedConnectionState = {\n networkState: 'connected',\n connectionState: 'disconnected',\n intendedConnectionState: 'disconnected',\n keepAliveState: 'healthy',\n };\n // Attempt to update the state with the current actual network state\n this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(({ online }) => {\n this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);\n this._initialNetworkStateSubscription?.unsubscribe();\n });\n this._linkedConnectionStateObservable =\n new Observable(connectionStateObserver => {\n connectionStateObserver.next(this._linkedConnectionState);\n this._linkedConnectionStateObserver = connectionStateObserver;\n });\n }\n /**\n * Turn network state monitoring on if it isn't on already\n */\n enableNetworkMonitoring() {\n // If no initial network state was discovered, stop trying\n this._initialNetworkStateSubscription?.unsubscribe();\n // Maintain the network state based on the reachability monitor\n if (this._networkMonitoringSubscription === undefined) {\n this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(({ online }) => {\n this.record(online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE);\n });\n }\n }\n /**\n * Turn network state monitoring off if it isn't off already\n */\n disableNetworkMonitoring() {\n this._networkMonitoringSubscription?.unsubscribe();\n this._networkMonitoringSubscription = undefined;\n }\n /**\n * Get the observable that allows us to monitor the connection state\n *\n * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates\n */\n get connectionStateObservable() {\n let previous;\n // The linked state aggregates state changes to any of the network, connection,\n // intendedConnection and keepAliveHealth. Some states will change these independent\n // states without changing the overall connection state.\n // After translating from linked states to ConnectionState, then remove any duplicates\n return this._linkedConnectionStateObservable\n .pipe(map(value => {\n return this.connectionStatesTranslator(value);\n }))\n .pipe(filter(current => {\n const toInclude = current !== previous;\n previous = current;\n return toInclude;\n }));\n }\n /*\n * Updates local connection state and emits the full state to the observer.\n */\n record(statusUpdates) {\n // Maintain the network monitor\n if (statusUpdates.intendedConnectionState === 'connected') {\n this.enableNetworkMonitoring();\n }\n else if (statusUpdates.intendedConnectionState === 'disconnected') {\n this.disableNetworkMonitoring();\n }\n // Maintain the socket state\n const newSocketStatus = {\n ...this._linkedConnectionState,\n ...statusUpdates,\n };\n this._linkedConnectionState = { ...newSocketStatus };\n this._linkedConnectionStateObserver?.next(this._linkedConnectionState);\n }\n /*\n * Translate the ConnectionState structure into a specific ConnectionState string literal union\n */\n connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {\n if (connectionState === 'connected' && networkState === 'disconnected')\n return ConnectionState.ConnectedPendingNetwork;\n if (connectionState === 'connected' &&\n intendedConnectionState === 'disconnected')\n return ConnectionState.ConnectedPendingDisconnect;\n if (connectionState === 'disconnected' &&\n intendedConnectionState === 'connected' &&\n networkState === 'disconnected')\n return ConnectionState.ConnectionDisruptedPendingNetwork;\n if (connectionState === 'disconnected' &&\n intendedConnectionState === 'connected')\n return ConnectionState.ConnectionDisrupted;\n if (connectionState === 'connected' && keepAliveState === 'unhealthy')\n return ConnectionState.ConnectedPendingKeepAlive;\n // All remaining states directly correspond to the connection state\n if (connectionState === 'connecting')\n return ConnectionState.Connecting;\n if (connectionState === 'disconnected')\n return ConnectionState.Disconnected;\n return ConnectionState.Connected;\n }\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,iBAAiB,GAAG;AACjC,IAAI,iBAAiB,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE;AACtD,IAAI,UAAU,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE;AAC7C,IAAI,sBAAsB,EAAE,EAAE,eAAe,EAAE,WAAW,EAAE;AAC5D,IAAI,iBAAiB,EAAE;AACvB,QAAQ,uBAAuB,EAAE,cAAc;AAC/C,QAAQ,eAAe,EAAE,cAAc;AACvC,KAAK;AACL,IAAI,kBAAkB,EAAE,EAAE,uBAAuB,EAAE,cAAc,EAAE;AACnE,IAAI,kBAAkB,EAAE;AACxB,QAAQ,uBAAuB,EAAE,WAAW;AAC5C,QAAQ,eAAe,EAAE,YAAY;AACrC,KAAK;AACL,IAAI,MAAM,EAAE,EAAE,eAAe,EAAE,cAAc,EAAE;AAC/C,IAAI,MAAM,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE;AACzC,IAAI,OAAO,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE;AAC7C;AACO,MAAM,sBAAsB,CAAC;AACpC,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,8BAA8B,GAAG,SAAS;AACvD,QAAQ,IAAI,CAAC,sBAAsB,GAAG;AACtC,YAAY,YAAY,EAAE,WAAW;AACrC,YAAY,eAAe,EAAE,cAAc;AAC3C,YAAY,uBAAuB,EAAE,cAAc;AACnD,YAAY,cAAc,EAAE,SAAS;AACrC,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,gCAAgC,GAAG,mBAAmB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK;AAChG,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC;AACtF,YAAY,IAAI,CAAC,gCAAgC,EAAE,WAAW,EAAE;AAChE,QAAQ,CAAC,CAAC;AACV,QAAQ,IAAI,CAAC,gCAAgC;AAC7C,YAAY,IAAI,UAAU,CAAC,uBAAuB,IAAI;AACtD,gBAAgB,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;AACzE,gBAAgB,IAAI,CAAC,8BAA8B,GAAG,uBAAuB;AAC7E,YAAY,CAAC,CAAC;AACd,IAAI;AACJ;AACA;AACA;AACA,IAAI,uBAAuB,GAAG;AAC9B;AACA,QAAQ,IAAI,CAAC,gCAAgC,EAAE,WAAW,EAAE;AAC5D;AACA,QAAQ,IAAI,IAAI,CAAC,8BAA8B,KAAK,SAAS,EAAE;AAC/D,YAAY,IAAI,CAAC,8BAA8B,GAAG,mBAAmB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK;AAClG,gBAAgB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC;AAC1F,YAAY,CAAC,CAAC;AACd,QAAQ;AACR,IAAI;AACJ;AACA;AACA;AACA,IAAI,wBAAwB,GAAG;AAC/B,QAAQ,IAAI,CAAC,8BAA8B,EAAE,WAAW,EAAE;AAC1D,QAAQ,IAAI,CAAC,8BAA8B,GAAG,SAAS;AACvD,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA,IAAI,IAAI,yBAAyB,GAAG;AACpC,QAAQ,IAAI,QAAQ;AACpB;AACA;AACA;AACA;AACA,QAAQ,OAAO,IAAI,CAAC;AACpB,aAAa,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI;AAC/B,YAAY,OAAO,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC;AACzD,QAAQ,CAAC,CAAC;AACV,aAAa,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI;AACpC,YAAY,MAAM,SAAS,GAAG,OAAO,KAAK,QAAQ;AAClD,YAAY,QAAQ,GAAG,OAAO;AAC9B,YAAY,OAAO,SAAS;AAC5B,QAAQ,CAAC,CAAC,CAAC;AACX,IAAI;AACJ;AACA;AACA;AACA,IAAI,MAAM,CAAC,aAAa,EAAE;AAC1B;AACA,QAAQ,IAAI,aAAa,CAAC,uBAAuB,KAAK,WAAW,EAAE;AACnE,YAAY,IAAI,CAAC,uBAAuB,EAAE;AAC1C,QAAQ;AACR,aAAa,IAAI,aAAa,CAAC,uBAAuB,KAAK,cAAc,EAAE;AAC3E,YAAY,IAAI,CAAC,wBAAwB,EAAE;AAC3C,QAAQ;AACR;AACA,QAAQ,MAAM,eAAe,GAAG;AAChC,YAAY,GAAG,IAAI,CAAC,sBAAsB;AAC1C,YAAY,GAAG,aAAa;AAC5B,SAAS;AACT,QAAQ,IAAI,CAAC,sBAAsB,GAAG,EAAE,GAAG,eAAe,EAAE;AAC5D,QAAQ,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC;AAC9E,IAAI;AACJ;AACA;AACA;AACA,IAAI,0BAA0B,CAAC,EAAE,eAAe,EAAE,YAAY,EAAE,uBAAuB,EAAE,cAAc,GAAG,EAAE;AAC5G,QAAQ,IAAI,eAAe,KAAK,WAAW,IAAI,YAAY,KAAK,cAAc;AAC9E,YAAY,OAAO,eAAe,CAAC,uBAAuB;AAC1D,QAAQ,IAAI,eAAe,KAAK,WAAW;AAC3C,YAAY,uBAAuB,KAAK,cAAc;AACtD,YAAY,OAAO,eAAe,CAAC,0BAA0B;AAC7D,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,uBAAuB,KAAK,WAAW;AACnD,YAAY,YAAY,KAAK,cAAc;AAC3C,YAAY,OAAO,eAAe,CAAC,iCAAiC;AACpE,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,uBAAuB,KAAK,WAAW;AACnD,YAAY,OAAO,eAAe,CAAC,mBAAmB;AACtD,QAAQ,IAAI,eAAe,KAAK,WAAW,IAAI,cAAc,KAAK,WAAW;AAC7E,YAAY,OAAO,eAAe,CAAC,yBAAyB;AAC5D;AACA,QAAQ,IAAI,eAAe,KAAK,YAAY;AAC5C,YAAY,OAAO,eAAe,CAAC,UAAU;AAC7C,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,OAAO,eAAe,CAAC,YAAY;AAC/C,QAAQ,OAAO,eAAe,CAAC,SAAS;AACxC,IAAI;AACJ;;;;"}
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => import("rxjs").Observable<import("@aws-amplify/core/dist/esm/Reachability/types").NetworkStatus>;
@@ -0,0 +1,8 @@
1
+ import { Reachability } from '@aws-amplify/core/internals/utils';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const ReachabilityMonitor = () => new Reachability().networkMonitor();
6
+
7
+ export { ReachabilityMonitor };
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/utils/ReachabilityMonitor/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Reachability } from '@aws-amplify/core/internals/utils';\nexport const ReachabilityMonitor = () => new Reachability().networkMonitor();\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,mBAAmB,GAAG,MAAM,IAAI,YAAY,EAAE,CAAC,cAAc;;;;"}
@@ -0,0 +1 @@
1
+ export declare const ReachabilityMonitor: () => import("rxjs").Observable<import("@aws-amplify/core/dist/esm/Reachability/types").NetworkStatus>;
@@ -0,0 +1,9 @@
1
+ import { Reachability } from '@aws-amplify/core/internals/utils';
2
+ import NetInfo from '@react-native-community/netinfo';
3
+
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ const ReachabilityMonitor = () => new Reachability().networkMonitor(NetInfo);
7
+
8
+ export { ReachabilityMonitor };
9
+ //# sourceMappingURL=index.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.mjs","sources":["../../../../src/utils/ReachabilityMonitor/index.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Reachability } from '@aws-amplify/core/internals/utils';\nimport NetInfo from '@react-native-community/netinfo';\nexport const ReachabilityMonitor = () => new Reachability().networkMonitor(NetInfo);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,mBAAmB,GAAG,MAAM,IAAI,YAAY,EAAE,CAAC,cAAc,CAAC,OAAO;;;;"}