@aws-amplify/api-graphql 4.0.2-unstable.ff4e8d7.0 → 4.0.2

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 (122) hide show
  1. package/dist/cjs/GraphQLAPI.js +1 -1
  2. package/dist/cjs/GraphQLAPI.js.map +1 -1
  3. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +1 -1
  4. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  5. package/dist/cjs/internals/APIClient.js +528 -0
  6. package/dist/cjs/internals/APIClient.js.map +1 -0
  7. package/dist/cjs/internals/InternalGraphQLAPI.js +14 -23
  8. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  9. package/dist/cjs/internals/generateClient.js +33 -0
  10. package/dist/cjs/internals/generateClient.js.map +1 -0
  11. package/dist/cjs/internals/generateModelsProperty.js +43 -0
  12. package/dist/cjs/internals/generateModelsProperty.js.map +1 -0
  13. package/dist/cjs/internals/index.js +3 -1
  14. package/dist/cjs/internals/index.js.map +1 -1
  15. package/dist/cjs/internals/operations/get.js +61 -0
  16. package/dist/cjs/internals/operations/get.js.map +1 -0
  17. package/dist/cjs/internals/operations/list.js +73 -0
  18. package/dist/cjs/internals/operations/list.js.map +1 -0
  19. package/dist/cjs/internals/operations/observeQuery.js +121 -0
  20. package/dist/cjs/internals/operations/observeQuery.js.map +1 -0
  21. package/dist/cjs/internals/operations/subscription.js +30 -0
  22. package/dist/cjs/internals/operations/subscription.js.map +1 -0
  23. package/dist/cjs/internals/server/generateClient.js +32 -0
  24. package/dist/cjs/internals/server/generateClient.js.map +1 -0
  25. package/dist/cjs/internals/server/generateModelsProperty.js +47 -0
  26. package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -0
  27. package/dist/cjs/internals/server/index.js +9 -0
  28. package/dist/cjs/internals/server/index.js.map +1 -0
  29. package/dist/cjs/internals/types.js +4 -0
  30. package/dist/cjs/internals/types.js.map +1 -0
  31. package/dist/cjs/types/index.js +3 -1
  32. package/dist/cjs/types/index.js.map +1 -1
  33. package/dist/cjs/utils/findIndexByFields.js +25 -0
  34. package/dist/cjs/utils/findIndexByFields.js.map +1 -0
  35. package/dist/cjs/utils/index.js +5 -1
  36. package/dist/cjs/utils/index.js.map +1 -1
  37. package/dist/cjs/utils/resolveOwnerFields.js +42 -0
  38. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -0
  39. package/dist/cjs/utils/resolvePKFields.js +17 -0
  40. package/dist/cjs/utils/resolvePKFields.js.map +1 -0
  41. package/dist/esm/GraphQLAPI.mjs +1 -1
  42. package/dist/esm/GraphQLAPI.mjs.map +1 -1
  43. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +1 -1
  44. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  45. package/dist/esm/index.mjs +1 -1
  46. package/dist/esm/internals/APIClient.d.ts +112 -0
  47. package/dist/esm/internals/APIClient.mjs +518 -0
  48. package/dist/esm/internals/APIClient.mjs.map +1 -0
  49. package/dist/esm/internals/InternalGraphQLAPI.d.ts +0 -11
  50. package/dist/esm/internals/InternalGraphQLAPI.mjs +14 -22
  51. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  52. package/dist/esm/internals/generateClient.d.ts +12 -0
  53. package/dist/esm/internals/generateClient.mjs +31 -0
  54. package/dist/esm/internals/generateClient.mjs.map +1 -0
  55. package/dist/esm/internals/generateModelsProperty.d.ts +4 -0
  56. package/dist/esm/internals/generateModelsProperty.mjs +41 -0
  57. package/dist/esm/internals/generateModelsProperty.mjs.map +1 -0
  58. package/dist/esm/internals/index.d.ts +1 -0
  59. package/dist/esm/internals/index.mjs +1 -0
  60. package/dist/esm/internals/index.mjs.map +1 -1
  61. package/dist/esm/internals/operations/get.d.ts +5 -0
  62. package/dist/esm/internals/operations/get.mjs +59 -0
  63. package/dist/esm/internals/operations/get.mjs.map +1 -0
  64. package/dist/esm/internals/operations/list.d.ts +4 -0
  65. package/dist/esm/internals/operations/list.mjs +71 -0
  66. package/dist/esm/internals/operations/list.mjs.map +1 -0
  67. package/dist/esm/internals/operations/observeQuery.d.ts +3 -0
  68. package/dist/esm/internals/operations/observeQuery.mjs +122 -0
  69. package/dist/esm/internals/operations/observeQuery.mjs.map +1 -0
  70. package/dist/esm/internals/operations/subscription.d.ts +3 -0
  71. package/dist/esm/internals/operations/subscription.mjs +28 -0
  72. package/dist/esm/internals/operations/subscription.mjs.map +1 -0
  73. package/dist/esm/internals/server/generateClient.d.ts +11 -0
  74. package/dist/esm/internals/server/generateClient.mjs +34 -0
  75. package/dist/esm/internals/server/generateClient.mjs.map +1 -0
  76. package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -0
  77. package/dist/esm/internals/server/generateModelsProperty.mjs +45 -0
  78. package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -0
  79. package/dist/esm/internals/server/index.d.ts +1 -0
  80. package/dist/esm/internals/server/index.mjs +2 -0
  81. package/dist/esm/internals/server/index.mjs.map +1 -0
  82. package/dist/esm/internals/types.d.ts +17 -0
  83. package/dist/esm/internals/types.mjs +2 -0
  84. package/dist/esm/internals/types.mjs.map +1 -0
  85. package/dist/esm/types/index.d.ts +32 -2
  86. package/dist/esm/types/index.mjs +3 -1
  87. package/dist/esm/types/index.mjs.map +1 -1
  88. package/dist/esm/utils/findIndexByFields.d.ts +9 -0
  89. package/dist/esm/utils/findIndexByFields.mjs +22 -0
  90. package/dist/esm/utils/findIndexByFields.mjs.map +1 -0
  91. package/dist/esm/utils/index.d.ts +2 -0
  92. package/dist/esm/utils/index.mjs +2 -0
  93. package/dist/esm/utils/index.mjs.map +1 -1
  94. package/dist/esm/utils/resolveOwnerFields.d.ts +12 -0
  95. package/dist/esm/utils/resolveOwnerFields.mjs +39 -0
  96. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -0
  97. package/dist/esm/utils/resolvePKFields.d.ts +13 -0
  98. package/dist/esm/utils/resolvePKFields.mjs +14 -0
  99. package/dist/esm/utils/resolvePKFields.mjs.map +1 -0
  100. package/internals/server/package.json +8 -0
  101. package/package.json +148 -146
  102. package/src/GraphQLAPI.ts +2 -2
  103. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +9 -4
  104. package/src/internals/APIClient.ts +780 -0
  105. package/src/internals/InternalGraphQLAPI.ts +21 -31
  106. package/src/internals/generateClient.ts +33 -0
  107. package/src/internals/generateModelsProperty.ts +73 -0
  108. package/src/internals/index.ts +1 -0
  109. package/src/internals/operations/get.ts +131 -0
  110. package/src/internals/operations/list.ts +132 -0
  111. package/src/internals/operations/observeQuery.ts +144 -0
  112. package/src/internals/operations/subscription.ts +65 -0
  113. package/src/internals/server/generateClient.ts +45 -0
  114. package/src/internals/server/generateModelsProperty.ts +80 -0
  115. package/src/internals/server/index.ts +4 -0
  116. package/src/internals/types.ts +21 -0
  117. package/src/types/index.ts +42 -2
  118. package/src/utils/ConnectionStateMonitor.ts +3 -1
  119. package/src/utils/findIndexByFields.ts +31 -0
  120. package/src/utils/index.ts +2 -0
  121. package/src/utils/resolveOwnerFields.ts +65 -0
  122. package/src/utils/resolvePKFields.ts +22 -0
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = exports.graphqlOperation = void 0;
4
+ exports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = void 0;
5
5
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
6
  // SPDX-License-Identifier: Apache-2.0
7
7
  const graphql_1 = require("graphql");
@@ -13,13 +13,7 @@ const internals_1 = require("@aws-amplify/api-rest/internals");
13
13
  const AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
14
14
  const utils_2 = require("../utils");
15
15
  const USER_AGENT_HEADER = 'x-amz-user-agent';
16
- const logger = new core_1.ConsoleLogger('GraphQLAPI');
17
- const graphqlOperation = (query, variables = {}, authToken) => ({
18
- query,
19
- variables,
20
- authToken,
21
- });
22
- exports.graphqlOperation = graphqlOperation;
16
+ new core_1.ConsoleLogger('GraphQLAPI');
23
17
  const isAmplifyInstance = (amplify) => {
24
18
  return typeof amplify !== 'function';
25
19
  };
@@ -27,19 +21,17 @@ const isAmplifyInstance = (amplify) => {
27
21
  * Export Cloud Logic APIs
28
22
  */
29
23
  class InternalGraphQLAPIClass {
30
- /**
31
- * Initialize GraphQL API with AWS configuration
32
- * @param {Object} options - Configuration object for API
33
- */
34
- constructor(options) {
24
+ constructor() {
25
+ /**
26
+ * @private
27
+ */
28
+ this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
35
29
  this._api = {
36
30
  post: internals_1.post,
37
31
  cancelREST: internals_1.cancel,
38
32
  isCancelErrorREST: api_rest_1.isCancelError,
39
33
  updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,
40
34
  };
41
- this._options = options;
42
- logger.debug('API Options', this._options);
43
35
  }
44
36
  getModuleName() {
45
37
  return 'InternalGraphQLAPI';
@@ -128,7 +120,7 @@ class InternalGraphQLAPIClass {
128
120
  responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
129
121
  }
130
122
  else {
131
- const wrapper = amplifyInstance => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
123
+ const wrapper = (amplifyInstance) => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
132
124
  responsePromise = amplify(wrapper);
133
125
  }
134
126
  this._api.updateRequestToBeCancellable(responsePromise, abortController);
@@ -188,7 +180,7 @@ class InternalGraphQLAPIClass {
188
180
  authMode !== 'userPool' &&
189
181
  authMode !== 'iam' &&
190
182
  authMode !== 'lambda')) {
191
- signingServiceInfo = null;
183
+ signingServiceInfo = undefined;
192
184
  }
193
185
  else {
194
186
  signingServiceInfo = {
@@ -228,7 +220,9 @@ class InternalGraphQLAPIClass {
228
220
  }
229
221
  response = {
230
222
  data: {},
231
- errors: [new graphql_1.GraphQLError(err.message, null, null, null, null, err)],
223
+ errors: [
224
+ new graphql_1.GraphQLError(err.message, null, null, null, null, err),
225
+ ],
232
226
  };
233
227
  }
234
228
  const { errors } = response;
@@ -255,20 +249,17 @@ class InternalGraphQLAPIClass {
255
249
  }
256
250
  _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {
257
251
  const config = (0, utils_2.resolveConfig)(amplify);
258
- if (!this.appSyncRealTime) {
259
- this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
260
- }
261
252
  return this.appSyncRealTime.subscribe({
262
253
  query: (0, graphql_1.print)(query),
263
254
  variables,
264
255
  appSyncGraphqlEndpoint: config?.endpoint,
265
256
  region: config?.region,
266
- authenticationType: authMode ?? config?.defaultAuthMode,
257
+ authenticationType: authMode || config?.defaultAuthMode,
267
258
  apiKey: config?.apiKey,
268
259
  additionalHeaders,
269
260
  }, customUserAgentDetails);
270
261
  }
271
262
  }
272
263
  exports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;
273
- exports.InternalGraphQLAPI = new InternalGraphQLAPIClass(null);
264
+ exports.InternalGraphQLAPI = new InternalGraphQLAPIClass();
274
265
  //# sourceMappingURL=InternalGraphQLAPI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"InternalGraphQLAPI.js","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = exports.graphqlOperation = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst graphql_1 = require(\"graphql\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst types_1 = require(\"../types\");\nconst api_rest_1 = require(\"@aws-amplify/api-rest\");\nconst internals_1 = require(\"@aws-amplify/api-rest/internals\");\nconst AWSAppSyncRealTimeProvider_1 = require(\"../Providers/AWSAppSyncRealTimeProvider\");\nconst utils_2 = require(\"../utils\");\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst logger = new core_1.ConsoleLogger('GraphQLAPI');\nconst graphqlOperation = (query, variables = {}, authToken) => ({\n query,\n variables,\n authToken,\n});\nexports.graphqlOperation = graphqlOperation;\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nclass InternalGraphQLAPIClass {\n /**\n * Initialize GraphQL API with AWS configuration\n * @param {Object} options - Configuration object for API\n */\n constructor(options) {\n this._api = {\n post: internals_1.post,\n cancelREST: internals_1.cancel,\n isCancelErrorREST: api_rest_1.isCancelError,\n updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,\n };\n this._options = options;\n logger.debug('API Options', this._options);\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const config = amplify.getConfig();\n const { region: region, endpoint: appSyncGraphqlEndpoint, apiKey, defaultAuthMode, } = (0, utils_2.resolveConfig)(amplify);\n const authenticationType = authMode || defaultAuthMode || 'iam';\n let headers = {};\n switch (authenticationType) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(types_1.GraphQLAuthError.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam':\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);\n }\n break;\n case 'oidc':\n case 'userPool':\n try {\n let token;\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n if (!token) {\n throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (!additionalHeaders.Authorization) {\n throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = (0, graphql_1.parse)(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? (0, graphql_1.parse)(paramQuery)\n : (0, graphql_1.parse)((0, graphql_1.print)(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n headers.Authorization = authToken;\n }\n switch (operationType) {\n case 'query':\n case 'mutation':\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);\n }\n else {\n const wrapper = amplifyInstance => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode }, additionalHeaders = {}, abortController, customUserAgentDetails) {\n const { region: region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, } = (0, utils_2.resolveConfig)(amplify);\n // Retrieve library options from Amplify configuration\n const { headers: customHeaders, withCredentials } = (0, utils_2.resolveLibraryOptions)(amplify);\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: (0, graphql_1.print)(query),\n variables,\n }))),\n // Headers from individual calls to `graphql`:\n ...additionalHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails),\n }),\n };\n const body = {\n query: (0, graphql_1.print)(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = null;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n const error = new graphql_1.GraphQLError('No graphql endpoint provided.');\n throw {\n data: {},\n errors: [error],\n };\n }\n let response;\n try {\n const { body: responseBody } = await this._api.post({\n url: new utils_1.AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const result = await responseBody.json();\n response = result;\n }\n catch (err) {\n // If the exception is because user intentionally\n // cancelled the request, do not modify the exception\n // so that clients can identify the exception correctly.\n if (this.isCancelError(err)) {\n throw err;\n }\n response = {\n data: {},\n errors: [new graphql_1.GraphQLError(err.message, null, null, null, null, err)],\n };\n }\n const { errors } = response;\n if (errors && errors.length) {\n throw response;\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {\n const config = (0, utils_2.resolveConfig)(amplify);\n if (!this.appSyncRealTime) {\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n }\n return this.appSyncRealTime.subscribe({\n query: (0, graphql_1.print)(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode ?? config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n }, customUserAgentDetails);\n }\n}\nexports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;\nexports.InternalGraphQLAPI = new InternalGraphQLAPIClass(null);\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;AACjG;AACA;AACA,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACrC,MAAM,MAAM,GAAG,OAAO,CAAC,mBAA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
1
+ {"version":3,"file":"InternalGraphQLAPI.js","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.InternalGraphQLAPI = exports.InternalGraphQLAPIClass = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst graphql_1 = require(\"graphql\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst types_1 = require(\"../types\");\nconst api_rest_1 = require(\"@aws-amplify/api-rest\");\nconst internals_1 = require(\"@aws-amplify/api-rest/internals\");\nconst AWSAppSyncRealTimeProvider_1 = require(\"../Providers/AWSAppSyncRealTimeProvider\");\nconst utils_2 = require(\"../utils\");\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst logger = new core_1.ConsoleLogger('GraphQLAPI');\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nclass InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();\n this._api = {\n post: internals_1.post,\n cancelREST: internals_1.cancel,\n isCancelErrorREST: api_rest_1.isCancelError,\n updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable,\n };\n }\n getModuleName() {\n return 'InternalGraphQLAPI';\n }\n async _headerBasedAuth(amplify, authMode, additionalHeaders = {}) {\n const config = amplify.getConfig();\n const { region: region, endpoint: appSyncGraphqlEndpoint, apiKey, defaultAuthMode, } = (0, utils_2.resolveConfig)(amplify);\n const authenticationType = authMode || defaultAuthMode || 'iam';\n let headers = {};\n switch (authenticationType) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(types_1.GraphQLAuthError.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam':\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);\n }\n break;\n case 'oidc':\n case 'userPool':\n try {\n let token;\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n if (!token) {\n throw new Error(types_1.GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (!additionalHeaders.Authorization) {\n throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n }\n /**\n * to get the operation type\n * @param operation\n */\n getGraphqlOperationType(operation) {\n const doc = (0, graphql_1.parse)(operation);\n const definitions = doc.definitions;\n const [{ operation: operationType }] = definitions;\n return operationType;\n }\n /**\n * Executes a GraphQL operation\n *\n * @param options - GraphQL Options\n * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config\n * @returns An Observable if the query is a subscription query, else a promise of the graphql result.\n */\n graphql(amplify, { query: paramQuery, variables = {}, authMode, authToken }, additionalHeaders, customUserAgentDetails) {\n const query = typeof paramQuery === 'string'\n ? (0, graphql_1.parse)(paramQuery)\n : (0, graphql_1.parse)((0, graphql_1.print)(paramQuery));\n const [operationDef = {}] = query.definitions.filter(def => def.kind === 'OperationDefinition');\n const { operation: operationType } = operationDef;\n const headers = additionalHeaders || {};\n // if an authorization header is set, have the explicit authToken take precedence\n if (authToken) {\n headers.Authorization = authToken;\n }\n switch (operationType) {\n case 'query':\n case 'mutation':\n const abortController = new AbortController();\n let responsePromise;\n if (isAmplifyInstance(amplify)) {\n responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);\n }\n else {\n const wrapper = (amplifyInstance) => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);\n responsePromise = amplify(wrapper);\n }\n this._api.updateRequestToBeCancellable(responsePromise, abortController);\n return responsePromise;\n case 'subscription':\n return this._graphqlSubscribe(amplify, { query, variables, authMode }, headers, customUserAgentDetails);\n default:\n throw new Error(`invalid operation type: ${operationType}`);\n }\n }\n async _graphql(amplify, { query, variables, authMode }, additionalHeaders = {}, abortController, customUserAgentDetails) {\n const { region: region, endpoint: appSyncGraphqlEndpoint, customEndpoint, customEndpointRegion, } = (0, utils_2.resolveConfig)(amplify);\n // Retrieve library options from Amplify configuration\n const { headers: customHeaders, withCredentials } = (0, utils_2.resolveLibraryOptions)(amplify);\n // TODO: Figure what we need to do to remove `!`'s.\n const headers = {\n ...(!customEndpoint &&\n (await this._headerBasedAuth(amplify, authMode, additionalHeaders))),\n /**\n * Custom endpoint headers.\n * If there is both a custom endpoint and custom region present, we get the headers.\n * If there is a custom endpoint but no region, we return an empty object.\n * If neither are present, we return an empty object.\n */\n ...((customEndpoint &&\n (customEndpointRegion\n ? await this._headerBasedAuth(amplify, authMode, additionalHeaders)\n : {})) ||\n {}),\n // Custom headers included in Amplify configuration options:\n ...(customHeaders &&\n (await customHeaders({\n query: (0, graphql_1.print)(query),\n variables,\n }))),\n // Headers from individual calls to `graphql`:\n ...additionalHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails),\n }),\n };\n const body = {\n query: (0, graphql_1.print)(query),\n variables: variables || null,\n };\n let signingServiceInfo;\n /**\n * We do not send the signing service info to the REST API under the\n * following conditions (i.e. it will not sign the request):\n * - there is a custom endpoint but no region\n * - the auth mode is `none`, or `apiKey`\n * - the auth mode is a type other than the types listed below\n */\n if ((customEndpoint && !customEndpointRegion) ||\n (authMode !== 'oidc' &&\n authMode !== 'userPool' &&\n authMode !== 'iam' &&\n authMode !== 'lambda')) {\n signingServiceInfo = undefined;\n }\n else {\n signingServiceInfo = {\n service: !customEndpointRegion ? 'appsync' : 'execute-api',\n region: !customEndpointRegion ? region : customEndpointRegion,\n };\n }\n const endpoint = customEndpoint || appSyncGraphqlEndpoint;\n if (!endpoint) {\n const error = new graphql_1.GraphQLError('No graphql endpoint provided.');\n throw {\n data: {},\n errors: [error],\n };\n }\n let response;\n try {\n const { body: responseBody } = await this._api.post({\n url: new utils_1.AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const result = await responseBody.json();\n response = result;\n }\n catch (err) {\n // If the exception is because user intentionally\n // cancelled the request, do not modify the exception\n // so that clients can identify the exception correctly.\n if (this.isCancelError(err)) {\n throw err;\n }\n response = {\n data: {},\n errors: [\n new graphql_1.GraphQLError(err.message, null, null, null, null, err),\n ],\n };\n }\n const { errors } = response;\n if (errors && errors.length) {\n throw response;\n }\n return response;\n }\n /**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @return {boolean} - A boolean indicating if the error was from an api request cancellation\n */\n isCancelError(error) {\n return this._api.isCancelErrorREST(error);\n }\n /**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\n cancel(request, message) {\n return this._api.cancelREST(request, message);\n }\n _graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {\n const config = (0, utils_2.resolveConfig)(amplify);\n return this.appSyncRealTime.subscribe({\n query: (0, graphql_1.print)(query),\n variables,\n appSyncGraphqlEndpoint: config?.endpoint,\n region: config?.region,\n authenticationType: authMode || config?.defaultAuthMode,\n apiKey: config?.apiKey,\n additionalHeaders,\n }, customUserAgentDetails);\n }\n}\nexports.InternalGraphQLAPIClass = InternalGraphQLAPIClass;\nexports.InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAA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,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;AAClD,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE;AAC7B,QAAQ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACtD,KAAK;AACL,IAAI,iBAAiB,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAE,sBAAsB,EAAE;AAC/G,QAAQ,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC3D,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;AAC9C,YAAY,KAAK,EAAE,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;AAC9C,YAAY,SAAS;AACrB,YAAY,sBAAsB,EAAE,MAAM,EAAE,QAAQ;AACpD,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,kBAAkB,EAAE,QAAQ,IAAI,MAAM,EAAE,eAAe;AACnE,YAAY,MAAM,EAAE,MAAM,EAAE,MAAM;AAClC,YAAY,iBAAiB;AAC7B,SAAS,EAAE,sBAAsB,CAAC,CAAC;AACnC,KAAK;AACL,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC1D,OAAO,CAAC,kBAAkB,GAAG,IAAI,uBAAuB,EAAE;;"}
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.generateClient = void 0;
5
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ const v6_1 = require("./v6");
8
+ const generateModelsProperty_1 = require("./generateModelsProperty");
9
+ const types_1 = require("../types");
10
+ /**
11
+ * @private
12
+ *
13
+ * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
14
+ * compatible context object for config and auth fetching.
15
+ *
16
+ * @param params
17
+ * @returns
18
+ */
19
+ function generateClient(params) {
20
+ const client = {
21
+ [types_1.__amplify]: params.amplify,
22
+ [types_1.__authMode]: params.authMode,
23
+ [types_1.__authToken]: params.authToken,
24
+ graphql: v6_1.graphql,
25
+ cancel: v6_1.cancel,
26
+ isCancelError: v6_1.isCancelError,
27
+ models: {},
28
+ };
29
+ client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, params);
30
+ return client;
31
+ }
32
+ exports.generateClient = generateClient;
33
+ //# sourceMappingURL=generateClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClient.js","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst v6_1 = require(\"./v6\");\nconst generateModelsProperty_1 = require(\"./generateModelsProperty\");\nconst types_1 = require(\"../types\");\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nfunction generateClient(params) {\n const client = {\n [types_1.__amplify]: params.amplify,\n [types_1.__authMode]: params.authMode,\n [types_1.__authToken]: params.authToken,\n graphql: v6_1.graphql,\n cancel: v6_1.cancel,\n isCancelError: v6_1.isCancelError,\n models: {},\n };\n client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, params);\n return client;\n}\nexports.generateClient = generateClient;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC;AACA;AACA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AACrE,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,cAAc,CAAC,MAAM,EAAE;AAChC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AAC3C,QAAQ,CAAC,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AAC7C,QAAQ,CAAC,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AAC/C,QAAQ,OAAO,EAAE,IAAI,CAAC,OAAO;AAC7B,QAAQ,MAAM,EAAE,IAAI,CAAC,MAAM;AAC3B,QAAQ,aAAa,EAAE,IAAI,CAAC,aAAa;AACzC,QAAQ,MAAM,EAAE,EAAE;AAClB,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,wBAAwB,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.generateModelsProperty = void 0;
5
+ const APIClient_1 = require("./APIClient");
6
+ const list_1 = require("./operations/list");
7
+ const get_1 = require("./operations/get");
8
+ const subscription_1 = require("./operations/subscription");
9
+ const observeQuery_1 = require("./operations/observeQuery");
10
+ function generateModelsProperty(client, params) {
11
+ const models = {};
12
+ const config = params.amplify.getConfig();
13
+ if (!config.API?.GraphQL) {
14
+ throw new Error('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');
15
+ }
16
+ const modelIntrospection = config.API.GraphQL.modelIntrospection;
17
+ if (!modelIntrospection) {
18
+ return {};
19
+ }
20
+ const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];
21
+ for (const model of Object.values(modelIntrospection.models)) {
22
+ const { name } = model;
23
+ models[name] = {};
24
+ Object.entries(APIClient_1.graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {
25
+ const operation = key;
26
+ if (operation === 'LIST') {
27
+ models[name][operationPrefix] = (0, list_1.listFactory)(client, modelIntrospection, model);
28
+ }
29
+ else if (SUBSCRIPTION_OPS.includes(operation)) {
30
+ models[name][operationPrefix] = (0, subscription_1.subscriptionFactory)(client, modelIntrospection, model, operation);
31
+ }
32
+ else if (operation === 'OBSERVE_QUERY') {
33
+ models[name][operationPrefix] = (0, observeQuery_1.observeQueryFactory)(models, model);
34
+ }
35
+ else {
36
+ models[name][operationPrefix] = (0, get_1.getFactory)(client, modelIntrospection, model, operation);
37
+ }
38
+ });
39
+ }
40
+ return models;
41
+ }
42
+ exports.generateModelsProperty = generateModelsProperty;
43
+ //# sourceMappingURL=generateModelsProperty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateModelsProperty.js","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateModelsProperty = void 0;\nconst APIClient_1 = require(\"./APIClient\");\nconst list_1 = require(\"./operations/list\");\nconst get_1 = require(\"./operations/get\");\nconst subscription_1 = require(\"./operations/subscription\");\nconst observeQuery_1 = require(\"./operations/observeQuery\");\nfunction generateModelsProperty(client, params) {\n const models = {};\n const config = params.amplify.getConfig();\n if (!config.API?.GraphQL) {\n throw new Error('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const modelIntrospection = config.API.GraphQL.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(APIClient_1.graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = (0, list_1.listFactory)(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = (0, subscription_1.subscriptionFactory)(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = (0, observeQuery_1.observeQueryFactory)(models, model);\n }\n else {\n models[name][operationPrefix] = (0, get_1.getFactory)(client, modelIntrospection, model, operation);\n }\n });\n }\n return models;\n}\nexports.generateModelsProperty = generateModelsProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,SAAS,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE;AAChD,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;AAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,MAAM,IAAI,KAAK,CAAC,yHAAyH,CAAC,CAAC;AACnJ,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO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e,CAAC,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACpH,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,sBAAsB,GAAG,sBAAsB;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;
4
+ exports.generateClient = exports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;
5
5
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
6
  // SPDX-License-Identifier: Apache-2.0
7
7
  var InternalGraphQLAPI_1 = require("./InternalGraphQLAPI");
@@ -11,4 +11,6 @@ var v6_1 = require("./v6");
11
11
  Object.defineProperty(exports, "graphql", { enumerable: true, get: function () { return v6_1.graphql; } });
12
12
  Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return v6_1.cancel; } });
13
13
  Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return v6_1.isCancelError; } });
14
+ var generateClient_1 = require("./generateClient");
15
+ Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return generateClient_1.generateClient; } });
14
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/internals/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nvar InternalGraphQLAPI_1 = require(\"./InternalGraphQLAPI\");\nObject.defineProperty(exports, \"InternalGraphQLAPI\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPI; } });\nObject.defineProperty(exports, \"InternalGraphQLAPIClass\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPIClass; } });\nvar v6_1 = require(\"./v6\");\nObject.defineProperty(exports, \"graphql\", { enumerable: true, get: function () { return v6_1.graphql; } });\nObject.defineProperty(exports, \"cancel\", { enumerable: true, get: function () { return v6_1.cancel; } });\nObject.defineProperty(exports, \"isCancelError\", { enumerable: true, get: function () { return v6_1.isCancelError; } });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACjI;AACA;AACA,IAAI,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC3D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,oBAAoB,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC;AACjJ,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,yBAAyB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,oBAAoB,CAAC,uBAAuB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3J,IAAI,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC3B,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3G,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC;AACzG,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/internals/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = exports.isCancelError = exports.cancel = exports.graphql = exports.InternalGraphQLAPIClass = exports.InternalGraphQLAPI = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nvar InternalGraphQLAPI_1 = require(\"./InternalGraphQLAPI\");\nObject.defineProperty(exports, \"InternalGraphQLAPI\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPI; } });\nObject.defineProperty(exports, \"InternalGraphQLAPIClass\", { enumerable: true, get: function () { return InternalGraphQLAPI_1.InternalGraphQLAPIClass; } });\nvar v6_1 = require(\"./v6\");\nObject.defineProperty(exports, \"graphql\", { enumerable: true, get: function () { return v6_1.graphql; } });\nObject.defineProperty(exports, \"cancel\", { enumerable: true, get: function () { return v6_1.cancel; } });\nObject.defineProperty(exports, \"isCancelError\", { enumerable: true, get: function () { return v6_1.isCancelError; } });\nvar generateClient_1 = require(\"./generateClient\");\nObject.defineProperty(exports, \"generateClient\", { enumerable: true, get: function () { return generateClient_1.generateClient; } });\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,O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,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;;"}
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getFactory = void 0;
5
+ const APIClient_1 = require("../APIClient");
6
+ function getFactory(client, modelIntrospection, model, operation, useContext = false) {
7
+ const getWithContext = async (contextSpec, arg, options) => {
8
+ return _get(client, modelIntrospection, model, arg, options, operation, contextSpec);
9
+ };
10
+ const get = async (arg, options) => {
11
+ return _get(client, modelIntrospection, model, arg, options, operation);
12
+ };
13
+ return useContext ? getWithContext : get;
14
+ }
15
+ exports.getFactory = getFactory;
16
+ async function _get(client, modelIntrospection, model, arg, options, operation, context) {
17
+ const { name } = model;
18
+ const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name, operation, options);
19
+ const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
20
+ try {
21
+ const auth = (0, APIClient_1.authModeParams)(client, options);
22
+ const { data, extensions } = context
23
+ ? (await client.graphql(context, {
24
+ ...auth,
25
+ query,
26
+ variables,
27
+ }))
28
+ : (await client.graphql({
29
+ ...auth,
30
+ query,
31
+ variables,
32
+ }));
33
+ // flatten response
34
+ if (data) {
35
+ const [key] = Object.keys(data);
36
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
37
+ if (options?.selectionSet) {
38
+ return { data: flattenedResult, extensions };
39
+ }
40
+ else {
41
+ // TODO: refactor to avoid destructuring here
42
+ const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
43
+ return { data: initialized, extensions };
44
+ }
45
+ }
46
+ else {
47
+ return { data: null, extensions };
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (error.errors) {
52
+ // graphql errors pass through
53
+ return error;
54
+ }
55
+ else {
56
+ // non-graphql errors re re-thrown
57
+ throw error;
58
+ }
59
+ }
60
+ }
61
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sources":["../../../../src/internals/operations/get.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction getFactory(client, modelIntrospection, model, operation, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation);\n };\n return useContext ? getWithContext : get;\n}\nexports.getFactory = getFactory;\nasync function _get(client, modelIntrospection, model, arg, options, operation, context) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name, operation, options);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);\n try {\n const auth = (0, APIClient_1.authModeParams)(client, options);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, extensions };\n }\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,WAAW,GA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AAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;"}
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.listFactory = void 0;
5
+ const APIClient_1 = require("../APIClient");
6
+ function listFactory(client, modelIntrospection, model, context = false) {
7
+ const listWithContext = async (contextSpec, args) => {
8
+ return _list(client, modelIntrospection, model, args, contextSpec);
9
+ };
10
+ const list = async (args) => {
11
+ return _list(client, modelIntrospection, model, args);
12
+ };
13
+ return context ? listWithContext : list;
14
+ }
15
+ exports.listFactory = listFactory;
16
+ async function _list(client, modelIntrospection, model, args, contextSpec) {
17
+ const { name } = model;
18
+ const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name, 'LIST', args);
19
+ const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);
20
+ try {
21
+ const auth = (0, APIClient_1.authModeParams)(client, args);
22
+ const { data, extensions } = !!contextSpec
23
+ ? (await client.graphql(contextSpec, {
24
+ ...auth,
25
+ query,
26
+ variables,
27
+ }))
28
+ : (await client.graphql({
29
+ ...auth,
30
+ query,
31
+ variables,
32
+ }));
33
+ // flatten response
34
+ if (data !== undefined) {
35
+ const [key] = Object.keys(data);
36
+ if (data[key].items) {
37
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
38
+ // don't init if custom selection set
39
+ if (args?.selectionSet) {
40
+ return {
41
+ data: flattenedResult,
42
+ nextToken: data[key].nextToken,
43
+ extensions,
44
+ };
45
+ }
46
+ else {
47
+ const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
48
+ return {
49
+ data: initialized,
50
+ nextToken: data[key].nextToken,
51
+ extensions,
52
+ };
53
+ }
54
+ }
55
+ return {
56
+ data: data[key],
57
+ nextToken: data[key].nextToken,
58
+ extensions,
59
+ };
60
+ }
61
+ }
62
+ catch (error) {
63
+ if (error.errors) {
64
+ // graphql errors pass through
65
+ return error;
66
+ }
67
+ else {
68
+ // non-graphql errors re re-thrown
69
+ throw error;
70
+ }
71
+ }
72
+ }
73
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","sources":["../../../../src/internals/operations/list.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.listFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction listFactory(client, modelIntrospection, model, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, args);\n };\n return context ? listWithContext : list;\n}\nexports.listFactory = listFactory;\nasync function _list(client, modelIntrospection, model, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name, 'LIST', args);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);\n try {\n const auth = (0, APIClient_1.authModeParams)(client, args);\n const { data, extensions } = !!contextSpec\n ? (await client.graphql(contextSpec, {\n ...auth,\n query,\n variables,\n }))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }));\n // flatten response\n if (data !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM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AAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AAC9C,gBAAgB,UAAU;AAC1B,aAAa,CAAC;AACd,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;"}
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.observeQueryFactory = void 0;
5
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ const rxjs_1 = require("rxjs");
8
+ const utils_1 = require("../../utils");
9
+ function observeQueryFactory(models, model) {
10
+ const { name } = model;
11
+ const observeQuery = (arg) => new rxjs_1.Observable(subscriber => {
12
+ // what we'll be sending to our subscribers
13
+ const items = [];
14
+ // To enqueue subscription messages while we collect our initial
15
+ // result set.
16
+ const messageQueue = [];
17
+ // operation to take when message(s) arrive.
18
+ // this operation will be swapped out once initial "sync" is complete
19
+ // to immediately ingest messsages.
20
+ let receiveMessages = (...messages) => {
21
+ return messageQueue.push(...messages);
22
+ };
23
+ // start subscriptions
24
+ const onCreateSub = models[name].onCreate(arg).subscribe({
25
+ next(item) {
26
+ receiveMessages({ item, type: 'create' });
27
+ },
28
+ error(error) {
29
+ subscriber.error({ type: 'onCreate', error });
30
+ },
31
+ });
32
+ const onUpdateSub = models[name].onUpdate(arg).subscribe({
33
+ next(item) {
34
+ receiveMessages({ item, type: 'update' });
35
+ },
36
+ error(error) {
37
+ subscriber.error({ type: 'onUpdate', error });
38
+ },
39
+ });
40
+ const onDeleteSub = models[name].onDelete(arg).subscribe({
41
+ next(item) {
42
+ receiveMessages({ item, type: 'delete' });
43
+ },
44
+ error(error) {
45
+ subscriber.error({ type: 'onDelete', error });
46
+ },
47
+ });
48
+ // consumes a list of messages and sends a snapshot
49
+ function ingestMessages(messages) {
50
+ for (const message of messages) {
51
+ const idx = (0, utils_1.findIndexByFields)(message.item, items, pkFields);
52
+ switch (message.type) {
53
+ case 'create':
54
+ if (idx < 0)
55
+ items.push(message.item);
56
+ break;
57
+ case 'update':
58
+ if (idx >= 0)
59
+ items[idx] = message.item;
60
+ break;
61
+ case 'delete':
62
+ if (idx >= 0)
63
+ items.splice(idx, 1);
64
+ break;
65
+ default:
66
+ console.error('Unrecognized message in observeQuery.', message);
67
+ }
68
+ }
69
+ subscriber.next({
70
+ items,
71
+ isSynced: true,
72
+ });
73
+ }
74
+ const pkFields = (0, utils_1.resolvePKFields)(model);
75
+ // initial results
76
+ (async () => {
77
+ let firstPage = true;
78
+ let nextToken = null;
79
+ while (!subscriber.closed && (firstPage || nextToken)) {
80
+ firstPage = false;
81
+ const { data: page, errors, nextToken: _nextToken, } = await models[name].list({ ...arg, nextToken });
82
+ nextToken = _nextToken;
83
+ items.push(...page);
84
+ // if there are no more pages and no items we already know about
85
+ // that need to be merged in from sub, we're "synced"
86
+ const isSynced = messageQueue.length === 0 &&
87
+ (nextToken === null || nextToken === undefined);
88
+ subscriber.next({
89
+ items,
90
+ isSynced,
91
+ });
92
+ if (Array.isArray(errors)) {
93
+ for (const error of errors) {
94
+ subscriber.error(error);
95
+ }
96
+ }
97
+ }
98
+ // play through the queue
99
+ if (messageQueue.length > 0) {
100
+ ingestMessages(messageQueue);
101
+ }
102
+ // switch the queue to write directly to the items collection
103
+ receiveMessages = (...messages) => {
104
+ ingestMessages(messages);
105
+ return items.length;
106
+ };
107
+ })();
108
+ // when subscriber unsubscribes, tear down internal subs
109
+ return () => {
110
+ // 1. tear down internal subs
111
+ onCreateSub.unsubscribe();
112
+ onUpdateSub.unsubscribe();
113
+ onDeleteSub.unsubscribe();
114
+ // 2. there is no need to explicitly stop paging. instead, we
115
+ // just check `subscriber.closed` above before fetching each page.
116
+ };
117
+ });
118
+ return observeQuery;
119
+ }
120
+ exports.observeQueryFactory = observeQueryFactory;
121
+ //# sourceMappingURL=observeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observeQuery.js","sources":["../../../../src/internals/operations/observeQuery.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.observeQueryFactory = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst rxjs_1 = require(\"rxjs\");\nconst utils_1 = require(\"../../utils\");\nfunction observeQueryFactory(models, model) {\n const { name } = model;\n const observeQuery = (arg) => new rxjs_1.Observable(subscriber => {\n // what we'll be sending to our subscribers\n const items = [];\n // To enqueue subscription messages while we collect our initial\n // result set.\n const messageQueue = [];\n // operation to take when message(s) arrive.\n // this operation will be swapped out once initial \"sync\" is complete\n // to immediately ingest messsages.\n let receiveMessages = (...messages) => {\n return messageQueue.push(...messages);\n };\n // start subscriptions\n const onCreateSub = models[name].onCreate(arg).subscribe({\n next(item) {\n receiveMessages({ item, type: 'create' });\n },\n error(error) {\n subscriber.error({ type: 'onCreate', error });\n },\n });\n const onUpdateSub = models[name].onUpdate(arg).subscribe({\n next(item) {\n receiveMessages({ item, type: 'update' });\n },\n error(error) {\n subscriber.error({ type: 'onUpdate', error });\n },\n });\n const onDeleteSub = models[name].onDelete(arg).subscribe({\n next(item) {\n receiveMessages({ item, type: 'delete' });\n },\n error(error) {\n subscriber.error({ type: 'onDelete', error });\n },\n });\n // consumes a list of messages and sends a snapshot\n function ingestMessages(messages) {\n for (const message of messages) {\n const idx = (0, utils_1.findIndexByFields)(message.item, items, pkFields);\n switch (message.type) {\n case 'create':\n if (idx < 0)\n items.push(message.item);\n break;\n case 'update':\n if (idx >= 0)\n items[idx] = message.item;\n break;\n case 'delete':\n if (idx >= 0)\n items.splice(idx, 1);\n break;\n default:\n console.error('Unrecognized message in observeQuery.', message);\n }\n }\n subscriber.next({\n items,\n isSynced: true,\n });\n }\n const pkFields = (0, utils_1.resolvePKFields)(model);\n // initial results\n (async () => {\n let firstPage = true;\n let nextToken = null;\n while (!subscriber.closed && (firstPage || nextToken)) {\n firstPage = false;\n const { data: page, errors, nextToken: _nextToken, } = await models[name].list({ ...arg, nextToken });\n nextToken = _nextToken;\n items.push(...page);\n // if there are no more pages and no items we already know about\n // that need to be merged in from sub, we're \"synced\"\n const isSynced = messageQueue.length === 0 &&\n (nextToken === null || nextToken === undefined);\n subscriber.next({\n items,\n isSynced,\n });\n if (Array.isArray(errors)) {\n for (const error of errors) {\n subscriber.error(error);\n }\n }\n }\n // play through the queue\n if (messageQueue.length > 0) {\n ingestMessages(messageQueue);\n }\n // switch the queue to write directly to the items collection\n receiveMessages = (...messages) => {\n ingestMessages(messages);\n return items.length;\n };\n })();\n // when subscriber unsubscribes, tear down internal subs\n return () => {\n // 1. tear down internal subs\n onCreateSub.unsubscribe();\n onUpdateSub.unsubscribe();\n onDeleteSub.unsubscribe();\n // 2. there is no need to explicitly stop paging. instead, we\n // just check `subscriber.closed` above before fetching each page.\n };\n });\n return observeQuery;\n}\nexports.observeQueryFactory = observeQueryFactory;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,KAAK,CAAC,CAAC;AACrC;AACA;AACA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,SAAS,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE;AAC5C,IAAI,MAAM,EAAE,IAAI,EAAE,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