@aws-amplify/datastore 4.5.2-unstable.c1fa9c7.5 → 4.6.0

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.
@@ -1,8 +1,12 @@
1
- import { API, GraphQLResult, GRAPHQL_AUTH_MODE } from '@aws-amplify/api';
1
+ import { GraphQLResult, GRAPHQL_AUTH_MODE } from '@aws-amplify/api';
2
+ import { InternalAPI } from '@aws-amplify/api/internals';
2
3
  import { Auth } from '@aws-amplify/auth';
3
4
  import { Cache } from '@aws-amplify/cache';
4
5
  import {
6
+ Category,
5
7
  ConsoleLogger as Logger,
8
+ CustomUserAgentDetails,
9
+ DataStoreAction,
6
10
  Hub,
7
11
  HubCapsule,
8
12
  BackgroundProcessManager,
@@ -37,7 +41,7 @@ import {
37
41
  generateRTFRemediation,
38
42
  } from '../utils';
39
43
  import { ModelPredicateCreator } from '../../predicates';
40
- import { validatePredicate, USER_AGENT_SUFFIX_DATASTORE } from '../../util';
44
+ import { validatePredicate } from '../../util';
41
45
  import { getSubscriptionErrorType } from './errorMaps';
42
46
 
43
47
  const logger = new Logger('DataStore');
@@ -79,7 +83,11 @@ class SubscriptionProcessor {
79
83
  private readonly amplifyConfig: Record<string, any> = {},
80
84
  private readonly authModeStrategy: AuthModeStrategy,
81
85
  private readonly errorHandler: ErrorHandler,
82
- private readonly amplifyContext: AmplifyContext = { Auth, API, Cache }
86
+ private readonly amplifyContext: AmplifyContext = {
87
+ Auth,
88
+ InternalAPI,
89
+ Cache,
90
+ }
83
91
  ) {}
84
92
 
85
93
  private buildSubscription(
@@ -421,6 +429,11 @@ class SubscriptionProcessor {
421
429
 
422
430
  const variables = {};
423
431
 
432
+ const customUserAgentDetails: CustomUserAgentDetails = {
433
+ category: Category.DataStore,
434
+ action: DataStoreAction.Subscribe,
435
+ };
436
+
424
437
  if (addFilter && predicatesGroup) {
425
438
  variables['filter'] =
426
439
  predicateToGraphQLFilter(predicatesGroup);
@@ -443,19 +456,20 @@ class SubscriptionProcessor {
443
456
  }`
444
457
  );
445
458
 
446
- const userAgentSuffix = USER_AGENT_SUFFIX_DATASTORE;
447
-
448
459
  const queryObservable = <
449
460
  Observable<{
450
461
  value: GraphQLResult<Record<string, PersistentModel>>;
451
462
  }>
452
- >(<unknown>this.amplifyContext.API.graphql({
453
- query,
454
- variables,
455
- ...{ authMode },
456
- authToken,
457
- userAgentSuffix,
458
- }));
463
+ >(<unknown>this.amplifyContext.InternalAPI.graphql(
464
+ {
465
+ query,
466
+ variables,
467
+ ...{ authMode },
468
+ authToken,
469
+ },
470
+ undefined,
471
+ customUserAgentDetails
472
+ ));
459
473
 
460
474
  let subscriptionReadyCallback: () => void;
461
475
 
@@ -1,4 +1,5 @@
1
- import { API, GraphQLResult, GRAPHQL_AUTH_MODE } from '@aws-amplify/api';
1
+ import { GraphQLResult, GRAPHQL_AUTH_MODE } from '@aws-amplify/api';
2
+ import { InternalAPI } from '@aws-amplify/api/internals';
2
3
  import Observable from 'zen-observable-ts';
3
4
  import {
4
5
  InternalSchema,
@@ -20,10 +21,12 @@ import {
20
21
  predicateToGraphQLFilter,
21
22
  getTokenForCustomAuth,
22
23
  } from '../utils';
23
- import { USER_AGENT_SUFFIX_DATASTORE } from '../../util';
24
24
  import {
25
25
  jitteredExponentialRetry,
26
+ Category,
26
27
  ConsoleLogger as Logger,
28
+ CustomUserAgentDetails,
29
+ DataStoreAction,
27
30
  Hub,
28
31
  NonRetryableError,
29
32
  BackgroundProcessManager,
@@ -54,7 +57,7 @@ class SyncProcessor {
54
57
  private readonly errorHandler: ErrorHandler,
55
58
  private readonly amplifyContext: AmplifyContext
56
59
  ) {
57
- amplifyContext.API = amplifyContext.API || API;
60
+ amplifyContext.InternalAPI = amplifyContext.InternalAPI || InternalAPI;
58
61
  this.generateQueries();
59
62
  }
60
63
 
@@ -214,13 +217,21 @@ class SyncProcessor {
214
217
  this.amplifyConfig
215
218
  );
216
219
 
217
- return await this.amplifyContext.API.graphql({
218
- query,
219
- variables,
220
- authMode,
221
- authToken,
222
- userAgentSuffix: USER_AGENT_SUFFIX_DATASTORE,
223
- });
220
+ const customUserAgentDetails: CustomUserAgentDetails = {
221
+ category: Category.DataStore,
222
+ action: DataStoreAction.GraphQl,
223
+ };
224
+
225
+ return await this.amplifyContext.InternalAPI.graphql(
226
+ {
227
+ query,
228
+ variables,
229
+ authMode,
230
+ authToken,
231
+ },
232
+ undefined,
233
+ customUserAgentDetails
234
+ );
224
235
 
225
236
  // TODO: onTerminate.then(() => API.cancel(...))
226
237
  } catch (error) {
package/src/types.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  import { PredicateAll } from './predicates';
16
16
  import { GRAPHQL_AUTH_MODE } from '@aws-amplify/api-graphql';
17
17
  import { Auth } from '@aws-amplify/auth';
18
- import { API } from '@aws-amplify/api';
18
+ import { InternalAPI } from '@aws-amplify/api/internals';
19
19
  import { Cache } from '@aws-amplify/cache';
20
20
  import { Adapter } from './storage/adapter';
21
21
 
@@ -1101,7 +1101,7 @@ export enum LimitTimerRaceResolvedValues {
1101
1101
 
1102
1102
  export type AmplifyContext = {
1103
1103
  Auth: typeof Auth;
1104
- API: typeof API;
1104
+ InternalAPI: typeof InternalAPI;
1105
1105
  Cache: typeof Cache;
1106
1106
  };
1107
1107
 
package/src/util.ts CHANGED
@@ -75,7 +75,6 @@ const SYNC = NAMESPACES.SYNC;
75
75
  const STORAGE = NAMESPACES.STORAGE;
76
76
 
77
77
  export { USER, SYNC, STORAGE, DATASTORE };
78
- export const USER_AGENT_SUFFIX_DATASTORE = '/DataStore';
79
78
 
80
79
  export const exhaustiveCheck = (obj: never, throwOnError: boolean = true) => {
81
80
  if (throwOnError) {