@aws-amplify/api-graphql 4.0.1-api-v6-models.c1977f8.0 → 4.0.1-api-v6-models.9351bcf.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.
@@ -9,7 +9,7 @@ type ListArgs = {
9
9
  * @returns response object with `items` properties flattened
10
10
  */
11
11
  export declare const flattenItems: (obj: Record<string, any>) => Record<string, any>;
12
- export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any, authMode: GraphQLAuthMode, authToken: string | undefined): any[];
12
+ export declare function initializeModel(client: any, modelName: string, result: any[], modelIntrospection: any, authMode: GraphQLAuthMode | undefined, authToken: string | undefined): any[];
13
13
  export declare const graphQLOperationsInfo: {
14
14
  CREATE: {
15
15
  operationPrefix: "create";
@@ -17,6 +17,8 @@ function generateClient(params) {
17
17
  var _a;
18
18
  var client = (_a = {},
19
19
  _a[types_1.__amplify] = params.amplify,
20
+ _a[types_1.__authMode] = params.authMode,
21
+ _a[types_1.__authToken] = params.authToken,
20
22
  _a.graphql = v6_1.graphql,
21
23
  _a.cancel = v6_1.cancel,
22
24
  _a.isCancelError = v6_1.isCancelError,
@@ -3,8 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateModelsProperty = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var APIClient_1 = require("./APIClient");
6
+ var types_1 = require("../types");
6
7
  var utils_1 = require("../utils");
7
8
  var rxjs_1 = require("rxjs");
9
+ /**
10
+ * Produces a parameter object that can contains auth mode/token overrides
11
+ * only if present in either `options` (first) or configured on the `client`
12
+ * as a fallback.
13
+ *
14
+ * @param client Configured client from `generateClient`
15
+ * @param options Args/Options obect from call site.
16
+ * @returns
17
+ */
18
+ function authModeParams(client, options) {
19
+ if (options === void 0) { options = {}; }
20
+ return {
21
+ authMode: options.authMode || client[types_1.__authMode],
22
+ authToken: options.authToken || client[types_1.__authToken],
23
+ };
24
+ }
8
25
  function generateModelsProperty(client, params) {
9
26
  var e_1, _a;
10
27
  var _this = this;
@@ -23,7 +40,7 @@ function generateModelsProperty(client, params) {
23
40
  var operation = key;
24
41
  if (operation === 'LIST') {
25
42
  models[name_1][operationPrefix] = function (args) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
26
- var query, variables, options, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
43
+ var query, variables, auth, _a, data, extensions, _b, key_1, flattenedResult, initialized, error_1;
27
44
  return tslib_1.__generator(this, function (_c) {
28
45
  switch (_c.label) {
29
46
  case 0:
@@ -32,12 +49,8 @@ function generateModelsProperty(client, params) {
32
49
  _c.label = 1;
33
50
  case 1:
34
51
  _c.trys.push([1, 3, , 4]);
35
- options = {};
36
- if (args === null || args === void 0 ? void 0 : args.authMode)
37
- options.authMode = args === null || args === void 0 ? void 0 : args.authMode;
38
- if (args === null || args === void 0 ? void 0 : args.authToken)
39
- options.authToken = args === null || args === void 0 ? void 0 : args.authToken;
40
- return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, options), { query: query, variables: variables }))];
52
+ auth = authModeParams(client, args);
53
+ return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }))];
41
54
  case 2:
42
55
  _a = (_c.sent()), data = _a.data, extensions = _a.extensions;
43
56
  // flatten response
@@ -54,7 +67,7 @@ function generateModelsProperty(client, params) {
54
67
  }];
55
68
  }
56
69
  else {
57
- initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection, options.authMode, options.authToken);
70
+ initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection, auth.authMode, auth.authToken);
58
71
  return [2 /*return*/, {
59
72
  data: initialized,
60
73
  nextToken: data[key_1].nextToken,
@@ -89,15 +102,11 @@ function generateModelsProperty(client, params) {
89
102
  models[name_1][operationPrefix] = function (args) {
90
103
  var query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, operation);
91
104
  var variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, args, modelIntrospection);
92
- var options = {};
93
- if (args === null || args === void 0 ? void 0 : args.authMode)
94
- options.authMode = args === null || args === void 0 ? void 0 : args.authMode;
95
- if (args === null || args === void 0 ? void 0 : args.authToken)
96
- options.authToken = args === null || args === void 0 ? void 0 : args.authToken;
97
- var observable = client.graphql(tslib_1.__assign(tslib_1.__assign({}, options), { query: query, variables: variables }));
105
+ var auth = authModeParams(client, args);
106
+ var observable = client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }));
98
107
  return observable.pipe((0, rxjs_1.map)(function (value) {
99
108
  var _a = tslib_1.__read(Object.keys(value.data), 1), key = _a[0];
100
- var _b = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [value.data[key]], modelIntrospection, options === null || options === void 0 ? void 0 : options.authMode, options === null || options === void 0 ? void 0 : options.authToken), 1), initialized = _b[0];
109
+ var _b = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [value.data[key]], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _b[0];
101
110
  return initialized;
102
111
  }));
103
112
  };
@@ -255,7 +264,7 @@ function generateModelsProperty(client, params) {
255
264
  }
256
265
  else {
257
266
  models[name_1][operationPrefix] = function (arg, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
258
- var query, variables, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
267
+ var query, variables, auth, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
259
268
  return tslib_1.__generator(this, function (_d) {
260
269
  switch (_d.label) {
261
270
  case 0:
@@ -264,7 +273,8 @@ function generateModelsProperty(client, params) {
264
273
  _d.label = 1;
265
274
  case 1:
266
275
  _d.trys.push([1, 3, , 4]);
267
- return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, options), { query: query, variables: variables }))];
276
+ auth = authModeParams(client, options);
277
+ return [4 /*yield*/, client.graphql(tslib_1.__assign(tslib_1.__assign({}, auth), { query: query, variables: variables }))];
268
278
  case 2:
269
279
  _a = (_d.sent()), data = _a.data, extensions = _a.extensions;
270
280
  // flatten response
@@ -275,7 +285,7 @@ function generateModelsProperty(client, params) {
275
285
  return [2 /*return*/, { data: flattenedResult, extensions: extensions }];
276
286
  }
277
287
  else {
278
- _c = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [flattenedResult], modelIntrospection, options === null || options === void 0 ? void 0 : options.authMode, options === null || options === void 0 ? void 0 : options.authToken), 1), initialized = _c[0];
288
+ _c = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken), 1), initialized = _c[0];
279
289
  return [2 /*return*/, { data: initialized, extensions: extensions }];
280
290
  }
281
291
  }
@@ -1,4 +1,5 @@
1
1
  import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
3
  /**
3
4
  * @private
4
5
  *
@@ -6,4 +7,11 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
6
7
  */
7
8
  export type ClientGenerationParams = {
8
9
  amplify: AmplifyClassV6;
10
+ } & CommonPublicClientOptions;
11
+ /**
12
+ * Common options that can be used on public `generateClient()` interfaces.
13
+ */
14
+ export type CommonPublicClientOptions = {
15
+ authMode?: GraphQLAuthMode;
16
+ authToken?: string;
9
17
  };