@aws-amplify/api-graphql 4.0.22 → 4.0.23

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 (106) hide show
  1. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
  2. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  3. package/dist/cjs/internals/APIClient.js +34 -19
  4. package/dist/cjs/internals/APIClient.js.map +1 -1
  5. package/dist/cjs/internals/InternalGraphQLAPI.js +10 -9
  6. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  7. package/dist/cjs/internals/generateClient.js +4 -1
  8. package/dist/cjs/internals/generateClient.js.map +1 -1
  9. package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
  10. package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
  11. package/dist/cjs/internals/operations/custom.js +90 -7
  12. package/dist/cjs/internals/operations/custom.js.map +1 -1
  13. package/dist/cjs/internals/operations/list.js +1 -1
  14. package/dist/cjs/internals/operations/list.js.map +1 -1
  15. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -1
  16. package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
  17. package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
  18. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
  19. package/dist/cjs/internals/v6.js +0 -2
  20. package/dist/cjs/internals/v6.js.map +1 -1
  21. package/dist/cjs/utils/errors/repackageAuthError.js +1 -1
  22. package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
  23. package/dist/cjs/utils/resolveOwnerFields.js +3 -0
  24. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
  25. package/dist/esm/GraphQLAPI.d.ts +2 -2
  26. package/dist/esm/GraphQLAPI.mjs.map +1 -1
  27. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
  28. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
  29. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  30. package/dist/esm/internals/APIClient.d.ts +5 -6
  31. package/dist/esm/internals/APIClient.mjs +34 -19
  32. package/dist/esm/internals/APIClient.mjs.map +1 -1
  33. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
  34. package/dist/esm/internals/InternalGraphQLAPI.mjs +10 -9
  35. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  36. package/dist/esm/internals/generateClient.mjs +5 -2
  37. package/dist/esm/internals/generateClient.mjs.map +1 -1
  38. package/dist/esm/internals/generateCustomOperationsProperty.d.ts +4 -3
  39. package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
  40. package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
  41. package/dist/esm/internals/operations/custom.d.ts +6 -3
  42. package/dist/esm/internals/operations/custom.mjs +90 -7
  43. package/dist/esm/internals/operations/custom.mjs.map +1 -1
  44. package/dist/esm/internals/operations/get.d.ts +1 -1
  45. package/dist/esm/internals/operations/get.mjs.map +1 -1
  46. package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
  47. package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
  48. package/dist/esm/internals/operations/list.d.ts +1 -1
  49. package/dist/esm/internals/operations/list.mjs +1 -1
  50. package/dist/esm/internals/operations/list.mjs.map +1 -1
  51. package/dist/esm/internals/operations/subscription.d.ts +1 -1
  52. package/dist/esm/internals/operations/subscription.mjs.map +1 -1
  53. package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
  54. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +1 -1
  55. package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
  56. package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
  57. package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
  58. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
  59. package/dist/esm/internals/types.d.ts +2 -2
  60. package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +2 -2
  61. package/dist/esm/internals/v6.d.ts +1 -1
  62. package/dist/esm/internals/v6.mjs +0 -2
  63. package/dist/esm/internals/v6.mjs.map +1 -1
  64. package/dist/esm/types/index.d.ts +34 -35
  65. package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
  66. package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
  67. package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
  68. package/dist/esm/utils/errors/repackageAuthError.d.ts +2 -2
  69. package/dist/esm/utils/errors/repackageAuthError.mjs +1 -1
  70. package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
  71. package/dist/esm/utils/findIndexByFields.d.ts +1 -1
  72. package/dist/esm/utils/resolveOwnerFields.mjs +3 -0
  73. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  74. package/package.json +8 -7
  75. package/src/GraphQLAPI.ts +4 -3
  76. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
  77. package/src/internals/APIClient.ts +83 -58
  78. package/src/internals/InternalGraphQLAPI.ts +26 -30
  79. package/src/internals/clientUtils.ts +1 -1
  80. package/src/internals/generateClient.ts +23 -10
  81. package/src/internals/generateCustomOperationsProperty.ts +31 -8
  82. package/src/internals/operations/custom.ts +159 -32
  83. package/src/internals/operations/get.ts +9 -8
  84. package/src/internals/operations/indexQuery.ts +12 -11
  85. package/src/internals/operations/list.ts +11 -15
  86. package/src/internals/operations/observeQuery.ts +3 -1
  87. package/src/internals/operations/subscription.ts +12 -10
  88. package/src/internals/server/generateClientWithAmplifyInstance.ts +7 -7
  89. package/src/internals/server/generateModelsProperty.ts +12 -6
  90. package/src/internals/types.ts +2 -2
  91. package/src/internals/utils/clientProperties/generateEnumsProperty.ts +7 -6
  92. package/src/internals/utils/clientProperties/generateModelsProperty.ts +8 -7
  93. package/src/internals/v6.ts +6 -4
  94. package/src/server/generateClient.ts +4 -1
  95. package/src/types/PubSub.ts +1 -0
  96. package/src/types/index.ts +51 -47
  97. package/src/utils/ConnectionStateMonitor.ts +8 -3
  98. package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
  99. package/src/utils/ReachabilityMonitor/index.ts +1 -0
  100. package/src/utils/ReconnectionMonitor.ts +1 -0
  101. package/src/utils/errors/repackageAuthError.ts +6 -7
  102. package/src/utils/findIndexByFields.ts +1 -1
  103. package/src/utils/resolveConfig.ts +1 -0
  104. package/src/utils/resolveLibraryOptions.ts +1 -0
  105. package/src/utils/resolveOwnerFields.ts +16 -7
  106. package/src/utils/resolvePKFields.ts +1 -0
@@ -1,10 +1,10 @@
1
1
  import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
2
- import { EnumTypes, ModelTypes, CustomHeaders, CustomQueries, CustomMutations } from '@aws-amplify/data-schema-types';
3
- import { Source, DocumentNode, GraphQLError } from 'graphql';
4
- export { OperationTypeNode } from 'graphql';
2
+ import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
3
+ import { DocumentNode, GraphQLError, Source } from 'graphql';
5
4
  import { Observable } from 'rxjs';
6
- import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
5
+ import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
7
6
  import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
7
+ export { OperationTypeNode } from 'graphql';
8
8
  export { CONTROL_MSG, ConnectionState } from './PubSub';
9
9
  export { SelectionSet } from '@aws-amplify/data-schema-types';
10
10
  export { CommonPublicClientOptions } from '../internals/types';
@@ -24,9 +24,7 @@ export interface GraphQLOptions {
24
24
  export interface GraphQLResult<T = object> {
25
25
  data: T;
26
26
  errors?: GraphQLError[];
27
- extensions?: {
28
- [key: string]: any;
29
- };
27
+ extensions?: Record<string, any>;
30
28
  }
31
29
  declare const queryType: unique symbol;
32
30
  export type GraphQLQuery<T> = T & {
@@ -56,18 +54,18 @@ export type GraphQLSubscription<T> = T & {
56
54
  *
57
55
  * This util simply makes related model properties optional recursively.
58
56
  */
59
- export type GraphQLReturnType<T> = T extends {} ? {
57
+ export type GraphQLReturnType<T> = T extends Record<string, unknown> ? {
60
58
  [K in keyof T]?: GraphQLReturnType<T[K]>;
61
59
  } : T;
62
60
  /**
63
61
  * Describes a paged list result from AppSync, which can either
64
62
  * live at the top query or property (e.g., related model) level.
65
63
  */
66
- type PagedList<T, TYPENAME> = {
64
+ interface PagedList<T, TYPENAME> {
67
65
  __typename: TYPENAME;
68
66
  nextToken?: string | null | undefined;
69
- items: Array<T>;
70
- };
67
+ items: T[];
68
+ }
71
69
  /**
72
70
  * Recursively looks through a result type and removes nulls and
73
71
  * and undefined from `PagedList` types.
@@ -76,7 +74,7 @@ type PagedList<T, TYPENAME> = {
76
74
  * array, this will only be the case when we also have errors,
77
75
  * which will then be *thrown*.
78
76
  */
79
- type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends {} ? {
77
+ type WithListsFixed<T> = T extends PagedList<infer IT, infer NAME> ? PagedList<Exclude<IT, null | undefined>, NAME> : T extends Record<string, unknown> ? {
80
78
  [K in keyof T]: WithListsFixed<T[K]>;
81
79
  } : T;
82
80
  /**
@@ -132,9 +130,9 @@ export type GraphqlSubscriptionResult<T> = Observable<GraphqlSubscriptionMessage
132
130
  * })
133
131
  * ```
134
132
  */
135
- export type GraphqlSubscriptionMessage<T> = {
133
+ export interface GraphqlSubscriptionMessage<T> {
136
134
  data: T;
137
- };
135
+ }
138
136
  export interface AWSAppSyncRealTimeProviderOptions {
139
137
  appSyncGraphqlEndpoint?: string;
140
138
  authenticationType?: GraphQLAuthMode;
@@ -142,12 +140,12 @@ export interface AWSAppSyncRealTimeProviderOptions {
142
140
  variables?: Record<string, unknown>;
143
141
  apiKey?: string;
144
142
  region?: string;
145
- libraryConfigHeaders?: () => {} | (() => Promise<{}>);
143
+ libraryConfigHeaders?(): () => Promise<Record<string, unknown> | Headers>;
146
144
  additionalHeaders?: CustomHeaders;
147
145
  }
148
- export type AWSAppSyncRealTimeProvider = {
146
+ export interface AWSAppSyncRealTimeProvider {
149
147
  subscribe(options?: AWSAppSyncRealTimeProviderOptions): Observable<Record<string, unknown>>;
150
- };
148
+ }
151
149
  export declare enum GraphQLAuthError {
152
150
  NO_API_KEY = "No api-key configured",
153
151
  NO_CURRENT_USER = "No current user",
@@ -191,7 +189,7 @@ export type GraphQLVariablesV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extend
191
189
  * The expected return type with respect to the given `FALLBACK_TYPE`
192
190
  * and `TYPED_GQL_STRING`.
193
191
  */
194
- export type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends string = string> = TYPED_GQL_STRING extends GeneratedQuery<infer IN, infer QUERY_OUT> ? Promise<GraphQLResult<FixedQueryResult<QUERY_OUT>>> : TYPED_GQL_STRING extends GeneratedMutation<infer IN, infer MUTATION_OUT> ? Promise<GraphQLResult<NeverEmpty<MUTATION_OUT>>> : TYPED_GQL_STRING extends GeneratedSubscription<infer IN, infer SUB_OUT> ? GraphqlSubscriptionResult<NeverEmpty<SUB_OUT>> : FALLBACK_TYPE extends GraphQLQuery<infer T> ? Promise<GraphQLResult<FALLBACK_TYPE>> : FALLBACK_TYPE extends GraphQLSubscription<infer T> ? GraphqlSubscriptionResult<FALLBACK_TYPE> : FALLBACK_TYPE extends GraphQLOperationType<infer IN, infer CUSTOM_OUT> ? CUSTOM_OUT : UnknownGraphQLResponse;
192
+ 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;
195
193
  /**
196
194
  * The shape customers can use to provide `T` to `graphql<T>()` to specify both
197
195
  * `IN` and `OUT` types (the type of `variables` and the return type, respectively).
@@ -210,10 +208,10 @@ export type GraphQLResponseV6<FALLBACK_TYPE = unknown, TYPED_GQL_STRING extends
210
208
  * })
211
209
  * ```
212
210
  */
213
- export type GraphQLOperationType<IN extends {}, OUT extends {}> = {
211
+ export interface GraphQLOperationType<IN extends Record<string, DocumentType>, OUT extends Record<string, DocumentType>> {
214
212
  variables: IN;
215
213
  result: OUT;
216
- };
214
+ }
217
215
  /**
218
216
  * Nominal type for branding generated graphql query operation strings with
219
217
  * input and output types.
@@ -291,12 +289,13 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
291
289
  [__authToken]?: string;
292
290
  [__headers]?: CustomHeaders;
293
291
  graphql: GraphQLMethod;
294
- cancel: (promise: Promise<any>, message?: string) => boolean;
295
- isCancelError: (error: any) => boolean;
292
+ cancel(promise: Promise<any>, message?: string): boolean;
293
+ isCancelError(error: any): boolean;
296
294
  models: ModelTypes<T>;
297
295
  enums: EnumTypes<T>;
298
296
  queries: CustomQueries<T>;
299
297
  mutations: CustomMutations<T>;
298
+ subscriptions: CustomSubscriptions<T>;
300
299
  }>;
301
300
  export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
302
301
  [__amplify]: AmplifyClassV6;
@@ -304,8 +303,8 @@ export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeve
304
303
  [__authToken]?: string;
305
304
  [__headers]?: CustomHeaders;
306
305
  graphql: GraphQLMethodSSR;
307
- cancel: (promise: Promise<any>, message?: string) => boolean;
308
- isCancelError: (error: any) => boolean;
306
+ cancel(promise: Promise<any>, message?: string): boolean;
307
+ isCancelError(error: any): boolean;
309
308
  models: ModelTypes<T, 'REQUEST'>;
310
309
  enums: EnumTypes<T>;
311
310
  queries: CustomQueries<T, 'REQUEST'>;
@@ -317,8 +316,8 @@ export type V6ClientSSRCookies<T extends Record<any, any> = never> = ExcludeNeve
317
316
  [__authToken]?: string;
318
317
  [__headers]?: CustomHeaders;
319
318
  graphql: GraphQLMethod;
320
- cancel: (promise: Promise<any>, message?: string) => boolean;
321
- isCancelError: (error: any) => boolean;
319
+ cancel(promise: Promise<any>, message?: string): boolean;
320
+ isCancelError(error: any): boolean;
322
321
  models: ModelTypes<T, 'COOKIES'>;
323
322
  enums: EnumTypes<T>;
324
323
  queries: CustomQueries<T, 'COOKIES'>;
@@ -331,22 +330,22 @@ export type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING exten
331
330
  *
332
331
  * The knobs available for configuring `server/generateClient` internally.
333
332
  */
334
- export type ServerClientGenerationParams = {
333
+ export interface ServerClientGenerationParams {
335
334
  amplify: null | ((fn: (amplify: AmplifyClassV6) => Promise<any>) => Promise<any>);
336
335
  config: ResourcesConfig;
337
- };
336
+ }
338
337
  export type QueryArgs = Record<string, unknown>;
339
- export type ListArgs = {
338
+ export interface ListArgs extends Record<string, unknown> {
340
339
  selectionSet?: string[];
341
- filter?: {};
340
+ filter?: Record<string, unknown>;
342
341
  headers?: CustomHeaders;
343
- };
344
- export type AuthModeParams = {
342
+ }
343
+ export interface AuthModeParams extends Record<string, unknown> {
345
344
  authMode?: GraphQLAuthMode;
346
345
  authToken?: string;
347
- };
348
- export type GenerateServerClientParams = {
346
+ }
347
+ export interface GenerateServerClientParams {
349
348
  config: ResourcesConfig;
350
349
  authMode?: GraphQLAuthMode;
351
350
  authToken?: string;
352
- };
351
+ }
@@ -2,12 +2,12 @@ import { Observable } from 'rxjs';
2
2
  import { ConnectionState } from '../types/PubSub';
3
3
  type LinkedConnectionState = 'connected' | 'disconnected';
4
4
  type LinkedHealthState = 'healthy' | 'unhealthy';
5
- type LinkedConnectionStates = {
5
+ interface LinkedConnectionStates {
6
6
  networkState: LinkedConnectionState;
7
7
  connectionState: LinkedConnectionState | 'connecting';
8
8
  intendedConnectionState: LinkedConnectionState;
9
9
  keepAliveState: LinkedHealthState;
10
- };
10
+ }
11
11
  export declare const CONNECTION_CHANGE: {
12
12
  [key in 'KEEP_ALIVE_MISSED' | 'KEEP_ALIVE' | 'CONNECTION_ESTABLISHED' | 'CONNECTION_FAILED' | 'CLOSING_CONNECTION' | 'OPENING_CONNECTION' | 'CLOSED' | 'ONLINE' | 'OFFLINE']: Partial<LinkedConnectionStates>;
13
13
  };
@@ -1 +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, map, filter } 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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,IAAI,CAAC,sBAAsB,GAAG,EAAE,GAAG,eAAe,EAAE,CAAC;AAC7D,QAAQ,IAAI,CAAC,8BAA8B,EAAE,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AAC/E,KAAK;AACL;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,CAAC;AAC3D,QAAQ,IAAI,eAAe,KAAK,WAAW;AAC3C,YAAY,uBAAuB,KAAK,cAAc;AACtD,YAAY,OAAO,eAAe,CAAC,0BAA0B,CAAC;AAC9D,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,uBAAuB,KAAK,WAAW;AACnD,YAAY,YAAY,KAAK,cAAc;AAC3C,YAAY,OAAO,eAAe,CAAC,iCAAiC,CAAC;AACrE,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,uBAAuB,KAAK,WAAW;AACnD,YAAY,OAAO,eAAe,CAAC,mBAAmB,CAAC;AACvD,QAAQ,IAAI,eAAe,KAAK,WAAW,IAAI,cAAc,KAAK,WAAW;AAC7E,YAAY,OAAO,eAAe,CAAC,yBAAyB,CAAC;AAC7D;AACA,QAAQ,IAAI,eAAe,KAAK,YAAY;AAC5C,YAAY,OAAO,eAAe,CAAC,UAAU,CAAC;AAC9C,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,OAAO,eAAe,CAAC,YAAY,CAAC;AAChD,QAAQ,OAAO,eAAe,CAAC,SAAS,CAAC;AACzC,KAAK;AACL;;;;"}
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":[],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,OAAO,eAAe,CAAC,mBAAmB,CAAC;AACvD,QAAQ,IAAI,eAAe,KAAK,WAAW,IAAI,cAAc,KAAK,WAAW;AAC7E,YAAY,OAAO,eAAe,CAAC,yBAAyB,CAAC;AAC7D;AACA,QAAQ,IAAI,eAAe,KAAK,YAAY;AAC5C,YAAY,OAAO,eAAe,CAAC,UAAU,CAAC;AAC9C,QAAQ,IAAI,eAAe,KAAK,cAAc;AAC9C,YAAY,OAAO,eAAe,CAAC,YAAY,CAAC;AAChD,QAAQ,OAAO,eAAe,CAAC,SAAS,CAAC;AACzC,KAAK;AACL;;;;"}
@@ -1 +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 { default as 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;;;;"}
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;;;;"}
@@ -1,7 +1,7 @@
1
1
  import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
2
- type ErrorObject = {
2
+ interface ErrorObject {
3
3
  errors: AmplifyErrorParams[];
4
- };
4
+ }
5
5
  /**
6
6
  * Checks to see if the given response or subscription message contains an
7
7
  * unauth error. If it does, it changes the error message to include instructions
@@ -21,7 +21,7 @@ function repackageUnauthError(content) {
21
21
  }
22
22
  function isUnauthError(error) {
23
23
  // Error pattern corresponding to appsync calls
24
- if (error?.['originalError']?.['name']?.startsWith('UnauthorizedException')) {
24
+ if (error?.originalError?.name?.startsWith('UnauthorizedException')) {
25
25
  return true;
26
26
  }
27
27
  // Error pattern corresponding to appsync subscriptions
@@ -1 +1 @@
1
- {"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n * unauth error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthError(content) {\n if (content.errors && Array.isArray(content.errors)) {\n content.errors.forEach(e => {\n if (isUnauthError(e)) {\n e.message = 'Unauthorized';\n e.recoverySuggestion =\n `If you're calling an Amplify-generated API, make sure ` +\n `to set the \"authMode\" in generateClient({ authMode: '...' }) to the backend authorization ` +\n `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;\n }\n });\n }\n return content;\n}\nfunction isUnauthError(error) {\n // Error pattern corresponding to appsync calls\n if (error?.['originalError']?.['name']?.startsWith('UnauthorizedException')) {\n return true;\n }\n // Error pattern corresponding to appsync subscriptions\n if (error.message?.startsWith('Connection failed:') &&\n error.message?.includes('Permission denied')) {\n return true;\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,OAAO,EAAE;AAC9C,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;AACpC,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;AAClC,gBAAgB,CAAC,CAAC,OAAO,GAAG,cAAc,CAAC;AAC3C,gBAAgB,CAAC,CAAC,kBAAkB;AACpC,oBAAoB,CAAC,sDAAsD,CAAC;AAC5E,wBAAwB,CAAC,0FAA0F,CAAC;AACpH,wBAAwB,CAAC,oEAAoE,CAAC,CAAC;AAC/F,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B;AACA,IAAI,IAAI,KAAK,GAAG,eAAe,CAAC,GAAG,MAAM,CAAC,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAAE;AACjF,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC;AACvD,QAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACtD,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"repackageAuthError.mjs","sources":["../../../../src/utils/errors/repackageAuthError.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Checks to see if the given response or subscription message contains an\n * unauth error. If it does, it changes the error message to include instructions\n * for the app developer.\n */\nexport function repackageUnauthError(content) {\n if (content.errors && Array.isArray(content.errors)) {\n content.errors.forEach(e => {\n if (isUnauthError(e)) {\n e.message = 'Unauthorized';\n e.recoverySuggestion =\n `If you're calling an Amplify-generated API, make sure ` +\n `to set the \"authMode\" in generateClient({ authMode: '...' }) to the backend authorization ` +\n `rule's auth provider ('apiKey', 'userPool', 'iam', 'oidc', 'lambda')`;\n }\n });\n }\n return content;\n}\nfunction isUnauthError(error) {\n // Error pattern corresponding to appsync calls\n if (error?.originalError?.name?.startsWith('UnauthorizedException')) {\n return true;\n }\n // Error pattern corresponding to appsync subscriptions\n if (error.message?.startsWith('Connection failed:') &&\n error.message?.includes('Permission denied')) {\n return true;\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,OAAO,EAAE;AAC9C,IAAI,IAAI,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACzD,QAAQ,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;AACpC,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;AAClC,gBAAgB,CAAC,CAAC,OAAO,GAAG,cAAc,CAAC;AAC3C,gBAAgB,CAAC,CAAC,kBAAkB;AACpC,oBAAoB,CAAC,sDAAsD,CAAC;AAC5E,wBAAwB,CAAC,0FAA0F,CAAC;AACpH,wBAAwB,CAAC,oEAAoE,CAAC,CAAC;AAC/F,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,SAAS,aAAa,CAAC,KAAK,EAAE;AAC9B;AACA,IAAI,IAAI,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,uBAAuB,CAAC,EAAE;AACzE,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;AACA,IAAI,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,oBAAoB,CAAC;AACvD,QAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACtD,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
@@ -6,4 +6,4 @@
6
6
  * @param keyFields The fields used to indicate a match
7
7
  * @returns Index of `needle` in `haystack`, otherwise -1 if not found.
8
8
  */
9
- export declare function findIndexByFields<T>(needle: T, haystack: T[], keyFields: Array<keyof T>): number;
9
+ export declare function findIndexByFields<T>(needle: T, haystack: T[], keyFields: (keyof T)[]): number;
@@ -12,6 +12,9 @@ function resolveOwnerFields(model) {
12
12
  if (rule.allow === 'owner') {
13
13
  ownerFields.add(rule.ownerField || 'owner');
14
14
  }
15
+ else if (rule.allow === 'groups') {
16
+ ownerFields.add(rule.groupsField);
17
+ }
15
18
  }
16
19
  }
17
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"resolveOwnerFields.mjs","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nexport function resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups') {\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,qBAAqB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;AAClD,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACtD,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.22",
3
+ "version": "4.0.23",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -24,7 +24,8 @@
24
24
  "clean": "npm run clean:size && rimraf dist lib lib-esm",
25
25
  "clean:size": "rimraf dual-publish-tmp tmp*",
26
26
  "format": "echo \"Not implemented\"",
27
- "lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
27
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
28
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
28
29
  "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 70.0"
29
30
  },
30
31
  "exports": {
@@ -71,7 +72,7 @@
71
72
  },
72
73
  "homepage": "https://aws-amplify.github.io/",
73
74
  "devDependencies": {
74
- "@aws-amplify/data-schema": "^0.13.9",
75
+ "@aws-amplify/data-schema": "^0.14.1",
75
76
  "@rollup/plugin-typescript": "11.1.5",
76
77
  "rollup": "^4.9.6",
77
78
  "typescript": "5.0.2"
@@ -84,9 +85,9 @@
84
85
  "server"
85
86
  ],
86
87
  "dependencies": {
87
- "@aws-amplify/api-rest": "4.0.22",
88
- "@aws-amplify/core": "6.0.22",
89
- "@aws-amplify/data-schema-types": "^0.7.6",
88
+ "@aws-amplify/api-rest": "4.0.23",
89
+ "@aws-amplify/core": "6.0.23",
90
+ "@aws-amplify/data-schema-types": "^0.7.11",
90
91
  "@aws-sdk/types": "3.387.0",
91
92
  "graphql": "15.8.0",
92
93
  "rxjs": "^7.8.1",
@@ -101,5 +102,5 @@
101
102
  "limit": "91.7 kB"
102
103
  }
103
104
  ],
104
- "gitHead": "080f8c11e9eb89cdcd29d78a2b4fe07c8c5b5404"
105
+ "gitHead": "6c46368559f4c3229024d10c18aabb34c58efe68"
105
106
  }
package/src/GraphQLAPI.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { AmplifyClassV6 } from '@aws-amplify/core';
4
- import { Category, ApiAction } from '@aws-amplify/core/internals/utils';
5
- import { GraphQLOptions, GraphQLResult } from './types';
6
- import { InternalGraphQLAPIClass } from './internals/InternalGraphQLAPI';
4
+ import { ApiAction, Category } from '@aws-amplify/core/internals/utils';
7
5
  import { CustomHeaders } from '@aws-amplify/data-schema-types';
8
6
  import { Observable } from 'rxjs';
9
7
 
8
+ import { GraphQLOptions, GraphQLResult } from './types';
9
+ import { InternalGraphQLAPIClass } from './internals/InternalGraphQLAPI';
10
+
10
11
  export const graphqlOperation = (
11
12
  query: any,
12
13
  variables = {},