@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.
- package/dist/cjs/GraphQLAPI.js +1 -1
- package/dist/cjs/GraphQLAPI.js.map +1 -1
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +1 -1
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/internals/APIClient.js +528 -0
- package/dist/cjs/internals/APIClient.js.map +1 -0
- package/dist/cjs/internals/InternalGraphQLAPI.js +14 -23
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +33 -0
- package/dist/cjs/internals/generateClient.js.map +1 -0
- package/dist/cjs/internals/generateModelsProperty.js +43 -0
- package/dist/cjs/internals/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/index.js +3 -1
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/internals/operations/get.js +61 -0
- package/dist/cjs/internals/operations/get.js.map +1 -0
- package/dist/cjs/internals/operations/list.js +73 -0
- package/dist/cjs/internals/operations/list.js.map +1 -0
- package/dist/cjs/internals/operations/observeQuery.js +121 -0
- package/dist/cjs/internals/operations/observeQuery.js.map +1 -0
- package/dist/cjs/internals/operations/subscription.js +30 -0
- package/dist/cjs/internals/operations/subscription.js.map +1 -0
- package/dist/cjs/internals/server/generateClient.js +32 -0
- package/dist/cjs/internals/server/generateClient.js.map +1 -0
- package/dist/cjs/internals/server/generateModelsProperty.js +47 -0
- package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/server/index.js +9 -0
- package/dist/cjs/internals/server/index.js.map +1 -0
- package/dist/cjs/internals/types.js +4 -0
- package/dist/cjs/internals/types.js.map +1 -0
- package/dist/cjs/types/index.js +3 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/findIndexByFields.js +25 -0
- package/dist/cjs/utils/findIndexByFields.js.map +1 -0
- package/dist/cjs/utils/index.js +5 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/resolveOwnerFields.js +42 -0
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -0
- package/dist/cjs/utils/resolvePKFields.js +17 -0
- package/dist/cjs/utils/resolvePKFields.js.map +1 -0
- package/dist/esm/GraphQLAPI.mjs +1 -1
- package/dist/esm/GraphQLAPI.mjs.map +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internals/APIClient.d.ts +112 -0
- package/dist/esm/internals/APIClient.mjs +518 -0
- package/dist/esm/internals/APIClient.mjs.map +1 -0
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +0 -11
- package/dist/esm/internals/InternalGraphQLAPI.mjs +14 -22
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.d.ts +12 -0
- package/dist/esm/internals/generateClient.mjs +31 -0
- package/dist/esm/internals/generateClient.mjs.map +1 -0
- package/dist/esm/internals/generateModelsProperty.d.ts +4 -0
- package/dist/esm/internals/generateModelsProperty.mjs +41 -0
- package/dist/esm/internals/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/index.d.ts +1 -0
- package/dist/esm/internals/index.mjs +1 -0
- package/dist/esm/internals/index.mjs.map +1 -1
- package/dist/esm/internals/operations/get.d.ts +5 -0
- package/dist/esm/internals/operations/get.mjs +59 -0
- package/dist/esm/internals/operations/get.mjs.map +1 -0
- package/dist/esm/internals/operations/list.d.ts +4 -0
- package/dist/esm/internals/operations/list.mjs +71 -0
- package/dist/esm/internals/operations/list.mjs.map +1 -0
- package/dist/esm/internals/operations/observeQuery.d.ts +3 -0
- package/dist/esm/internals/operations/observeQuery.mjs +122 -0
- package/dist/esm/internals/operations/observeQuery.mjs.map +1 -0
- package/dist/esm/internals/operations/subscription.d.ts +3 -0
- package/dist/esm/internals/operations/subscription.mjs +28 -0
- package/dist/esm/internals/operations/subscription.mjs.map +1 -0
- package/dist/esm/internals/server/generateClient.d.ts +11 -0
- package/dist/esm/internals/server/generateClient.mjs +34 -0
- package/dist/esm/internals/server/generateClient.mjs.map +1 -0
- package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -0
- package/dist/esm/internals/server/generateModelsProperty.mjs +45 -0
- package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/server/index.d.ts +1 -0
- package/dist/esm/internals/server/index.mjs +2 -0
- package/dist/esm/internals/server/index.mjs.map +1 -0
- package/dist/esm/internals/types.d.ts +17 -0
- package/dist/esm/internals/types.mjs +2 -0
- package/dist/esm/internals/types.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +32 -2
- package/dist/esm/types/index.mjs +3 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/utils/findIndexByFields.d.ts +9 -0
- package/dist/esm/utils/findIndexByFields.mjs +22 -0
- package/dist/esm/utils/findIndexByFields.mjs.map +1 -0
- package/dist/esm/utils/index.d.ts +2 -0
- package/dist/esm/utils/index.mjs +2 -0
- package/dist/esm/utils/index.mjs.map +1 -1
- package/dist/esm/utils/resolveOwnerFields.d.ts +12 -0
- package/dist/esm/utils/resolveOwnerFields.mjs +39 -0
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -0
- package/dist/esm/utils/resolvePKFields.d.ts +13 -0
- package/dist/esm/utils/resolvePKFields.mjs +14 -0
- package/dist/esm/utils/resolvePKFields.mjs.map +1 -0
- package/internals/server/package.json +8 -0
- package/package.json +148 -146
- package/src/GraphQLAPI.ts +2 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +9 -4
- package/src/internals/APIClient.ts +780 -0
- package/src/internals/InternalGraphQLAPI.ts +21 -31
- package/src/internals/generateClient.ts +33 -0
- package/src/internals/generateModelsProperty.ts +73 -0
- package/src/internals/index.ts +1 -0
- package/src/internals/operations/get.ts +131 -0
- package/src/internals/operations/list.ts +132 -0
- package/src/internals/operations/observeQuery.ts +144 -0
- package/src/internals/operations/subscription.ts +65 -0
- package/src/internals/server/generateClient.ts +45 -0
- package/src/internals/server/generateModelsProperty.ts +80 -0
- package/src/internals/server/index.ts +4 -0
- package/src/internals/types.ts +21 -0
- package/src/types/index.ts +42 -2
- package/src/utils/ConnectionStateMonitor.ts +3 -1
- package/src/utils/findIndexByFields.ts +31 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/resolveOwnerFields.ts +65 -0
- package/src/utils/resolvePKFields.ts +22 -0
|
@@ -11,12 +11,7 @@ import { resolveLibraryOptions } from '../utils/resolveLibraryOptions.mjs';
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
13
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
14
|
-
|
|
15
|
-
const graphqlOperation = (query, variables = {}, authToken) => ({
|
|
16
|
-
query,
|
|
17
|
-
variables,
|
|
18
|
-
authToken,
|
|
19
|
-
});
|
|
14
|
+
new ConsoleLogger('GraphQLAPI');
|
|
20
15
|
const isAmplifyInstance = (amplify) => {
|
|
21
16
|
return typeof amplify !== 'function';
|
|
22
17
|
};
|
|
@@ -24,19 +19,17 @@ const isAmplifyInstance = (amplify) => {
|
|
|
24
19
|
* Export Cloud Logic APIs
|
|
25
20
|
*/
|
|
26
21
|
class InternalGraphQLAPIClass {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
constructor() {
|
|
23
|
+
/**
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
32
27
|
this._api = {
|
|
33
28
|
post,
|
|
34
29
|
cancelREST: cancel,
|
|
35
30
|
isCancelErrorREST: isCancelError,
|
|
36
31
|
updateRequestToBeCancellable,
|
|
37
32
|
};
|
|
38
|
-
this._options = options;
|
|
39
|
-
logger.debug('API Options', this._options);
|
|
40
33
|
}
|
|
41
34
|
getModuleName() {
|
|
42
35
|
return 'InternalGraphQLAPI';
|
|
@@ -125,7 +118,7 @@ class InternalGraphQLAPIClass {
|
|
|
125
118
|
responsePromise = this._graphql(amplify, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
126
119
|
}
|
|
127
120
|
else {
|
|
128
|
-
const wrapper = amplifyInstance => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
121
|
+
const wrapper = (amplifyInstance) => this._graphql(amplifyInstance, { query, variables, authMode }, headers, abortController, customUserAgentDetails);
|
|
129
122
|
responsePromise = amplify(wrapper);
|
|
130
123
|
}
|
|
131
124
|
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
@@ -185,7 +178,7 @@ class InternalGraphQLAPIClass {
|
|
|
185
178
|
authMode !== 'userPool' &&
|
|
186
179
|
authMode !== 'iam' &&
|
|
187
180
|
authMode !== 'lambda')) {
|
|
188
|
-
signingServiceInfo =
|
|
181
|
+
signingServiceInfo = undefined;
|
|
189
182
|
}
|
|
190
183
|
else {
|
|
191
184
|
signingServiceInfo = {
|
|
@@ -225,7 +218,9 @@ class InternalGraphQLAPIClass {
|
|
|
225
218
|
}
|
|
226
219
|
response = {
|
|
227
220
|
data: {},
|
|
228
|
-
errors: [
|
|
221
|
+
errors: [
|
|
222
|
+
new GraphQLError(err.message, null, null, null, null, err),
|
|
223
|
+
],
|
|
229
224
|
};
|
|
230
225
|
}
|
|
231
226
|
const { errors } = response;
|
|
@@ -252,21 +247,18 @@ class InternalGraphQLAPIClass {
|
|
|
252
247
|
}
|
|
253
248
|
_graphqlSubscribe(amplify, { query, variables, authMode }, additionalHeaders = {}, customUserAgentDetails) {
|
|
254
249
|
const config = resolveConfig(amplify);
|
|
255
|
-
if (!this.appSyncRealTime) {
|
|
256
|
-
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
257
|
-
}
|
|
258
250
|
return this.appSyncRealTime.subscribe({
|
|
259
251
|
query: print(query),
|
|
260
252
|
variables,
|
|
261
253
|
appSyncGraphqlEndpoint: config?.endpoint,
|
|
262
254
|
region: config?.region,
|
|
263
|
-
authenticationType: authMode
|
|
255
|
+
authenticationType: authMode || config?.defaultAuthMode,
|
|
264
256
|
apiKey: config?.apiKey,
|
|
265
257
|
additionalHeaders,
|
|
266
258
|
}, customUserAgentDetails);
|
|
267
259
|
}
|
|
268
260
|
}
|
|
269
|
-
const InternalGraphQLAPI = new InternalGraphQLAPIClass(
|
|
261
|
+
const InternalGraphQLAPI = new InternalGraphQLAPIClass();
|
|
270
262
|
|
|
271
|
-
export { InternalGraphQLAPI, InternalGraphQLAPIClass
|
|
263
|
+
export { InternalGraphQLAPI, InternalGraphQLAPIClass };
|
|
272
264
|
//# sourceMappingURL=InternalGraphQLAPI.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { print, parse, GraphQLError, } from 'graphql';\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { getAmplifyUserAgent, AmplifyUrl, } from '@aws-amplify/core/internals/utils';\nimport { GraphQLAuthError, } from '../types';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst logger = new ConsoleLogger('GraphQLAPI');\nexport const graphqlOperation = (query, variables = {}, authToken) => ({\n query,\n variables,\n authToken,\n});\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class 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,\n cancelREST,\n isCancelErrorREST,\n 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, } = resolveConfig(amplify);\n const authenticationType = authMode || defaultAuthMode || 'iam';\n let headers = {};\n switch (authenticationType) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(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(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(GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (!additionalHeaders.Authorization) {\n throw new Error(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 = 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 ? parse(paramQuery)\n : parse(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, } = resolveConfig(amplify);\n // Retrieve library options from Amplify configuration\n const { headers: customHeaders, withCredentials } = 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: print(query),\n variables,\n }))),\n // Headers from individual calls to `graphql`:\n ...additionalHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: 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 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 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 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 = resolveConfig(amplify);\n if (!this.appSyncRealTime) {\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n }\n return this.appSyncRealTime.subscribe({\n query: 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}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass(null);\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;AAAA;AACA;AASA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;AACnC,MAAC,gBAAgB,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,EAAE,EAAE,SAAS,MAAM;AACvE,IAAI,KAAK;AACT,IAAI,SAAS;AACb,IAAI,SAAS;AACb,CAAC,EAAE;AACH,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAAI;AAChB,wBAAYA,MAAU;AACtB,+BAAYC,aAAiB;AAC7B,YAAY,4BAA4B;AACxC,SAAS,CAAC;AACV,QAAQ,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;AAChC,QAAQ,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,oBAAoB,CAAC;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,CAAC,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KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAE,sBAAsB,EAAE;AAC/G,QAAQ,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;AACnC,YAAY,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,EAAE,CAAC;AACpE,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;AAC9C,YAAY,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;AAC/B,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;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB,CAAC,IAAI;;;;"}
|
|
1
|
+
{"version":3,"file":"InternalGraphQLAPI.mjs","sources":["../../../src/internals/InternalGraphQLAPI.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { print, parse, GraphQLError, } from 'graphql';\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { getAmplifyUserAgent, AmplifyUrl, } from '@aws-amplify/core/internals/utils';\nimport { GraphQLAuthError, } from '../types';\nimport { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';\nimport { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';\nimport { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';\nimport { resolveConfig, resolveLibraryOptions } from '../utils';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\nconst logger = new ConsoleLogger('GraphQLAPI');\nconst isAmplifyInstance = (amplify) => {\n return typeof amplify !== 'function';\n};\n/**\n * Export Cloud Logic APIs\n */\nexport class InternalGraphQLAPIClass {\n constructor() {\n /**\n * @private\n */\n this.appSyncRealTime = new AWSAppSyncRealTimeProvider();\n this._api = {\n post,\n cancelREST,\n isCancelErrorREST,\n 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, } = resolveConfig(amplify);\n const authenticationType = authMode || defaultAuthMode || 'iam';\n let headers = {};\n switch (authenticationType) {\n case 'apiKey':\n if (!apiKey) {\n throw new Error(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(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(GraphQLAuthError.NO_FEDERATED_JWT);\n }\n headers = {\n Authorization: token,\n };\n }\n catch (e) {\n throw new Error(GraphQLAuthError.NO_CURRENT_USER);\n }\n break;\n case 'lambda':\n if (!additionalHeaders.Authorization) {\n throw new Error(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 = 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 ? parse(paramQuery)\n : parse(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, } = resolveConfig(amplify);\n // Retrieve library options from Amplify configuration\n const { headers: customHeaders, withCredentials } = 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: print(query),\n variables,\n }))),\n // Headers from individual calls to `graphql`:\n ...additionalHeaders,\n // User agent headers:\n ...(!customEndpoint && {\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n }),\n };\n const body = {\n query: 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 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 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 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 = resolveConfig(amplify);\n return this.appSyncRealTime.subscribe({\n query: 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}\nexport const InternalGraphQLAPI = new InternalGraphQLAPIClass();\n"],"names":["cancelREST","isCancelErrorREST"],"mappings":";;;;;;;;;;AAAA;AACA;AASA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC9B,IAAI,aAAa,CAAC,YAAY,EAAE;AAC/C,MAAM,iBAAiB,GAAG,CAAC,OAAO,KAAK;AACvC,IAAI,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC;AACzC,CAAC,CAAC;AACF;AACA;AACA;AACO,MAAM,uBAAuB,CAAC;AACrC,IAAI,WAAW,GAAG;AAClB;AACA;AACA;AACA,QAAQ,IAAI,CAAC,eAAe,GAAG,IAAI,0BAA0B,EAAE,CAAC;AAChE,QAAQ,IAAI,CAAC,IAAI,GAAG;AACpB,YAAY,IAAI;AAChB,wBAAYA,MAAU;AACtB,+BAAYC,aAAiB;AAC7B,YAAY,4BAA4B;AACxC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,oBAAoB,CAAC;AACpC,KAAK;AACL,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACtE,QAAuB,OAAO,CAAC,SAAS,GAAG;AAC3C,QAAQ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,EAAE,eAAe,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AACtH,QAAQ,MAAM,kBAAkB,GAAG,QAAQ,IAAI,eAAe,IAAI,KAAK,CAAC;AACxE,QAAQ,IAAI,OAAO,GAAG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M,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;AACW,MAAC,kBAAkB,GAAG,IAAI,uBAAuB;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { V6Client } from '../types';
|
|
2
|
+
import { ClientGenerationParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
*
|
|
6
|
+
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
7
|
+
* compatible context object for config and auth fetching.
|
|
8
|
+
*
|
|
9
|
+
* @param params
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateClient<T extends Record<any, any> = never>(params: ClientGenerationParams): V6Client<T>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
2
|
+
import { generateModelsProperty } from './generateModelsProperty.mjs';
|
|
3
|
+
import { __amplify, __authMode, __authToken } from '../types/index.mjs';
|
|
4
|
+
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*
|
|
10
|
+
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
11
|
+
* compatible context object for config and auth fetching.
|
|
12
|
+
*
|
|
13
|
+
* @param params
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function generateClient(params) {
|
|
17
|
+
const client = {
|
|
18
|
+
[__amplify]: params.amplify,
|
|
19
|
+
[__authMode]: params.authMode,
|
|
20
|
+
[__authToken]: params.authToken,
|
|
21
|
+
graphql,
|
|
22
|
+
cancel,
|
|
23
|
+
isCancelError,
|
|
24
|
+
models: {},
|
|
25
|
+
};
|
|
26
|
+
client.models = generateModelsProperty(client, params);
|
|
27
|
+
return client;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { generateClient };
|
|
31
|
+
//# sourceMappingURL=generateClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { graphql, cancel, isCancelError } from './v6';\nimport { generateModelsProperty } from './generateModelsProperty';\nimport { __amplify, __authMode, __authToken } from '../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 */\nexport function generateClient(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n graphql,\n cancel,\n isCancelError,\n models: {},\n };\n client.models = generateModelsProperty(client, params);\n return client;\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,QAAQ,MAAM,EAAE,EAAE;AAClB,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { ClientGenerationParams } from './types';
|
|
3
|
+
import { V6Client } from '../types';
|
|
4
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, params: ClientGenerationParams): ModelTypes<T>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { graphQLOperationsInfo } from './APIClient.mjs';
|
|
2
|
+
import { listFactory } from './operations/list.mjs';
|
|
3
|
+
import { getFactory } from './operations/get.mjs';
|
|
4
|
+
import { subscriptionFactory } from './operations/subscription.mjs';
|
|
5
|
+
import { observeQueryFactory } from './operations/observeQuery.mjs';
|
|
6
|
+
|
|
7
|
+
function generateModelsProperty(client, params) {
|
|
8
|
+
const models = {};
|
|
9
|
+
const config = params.amplify.getConfig();
|
|
10
|
+
if (!config.API?.GraphQL) {
|
|
11
|
+
throw new Error('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');
|
|
12
|
+
}
|
|
13
|
+
const modelIntrospection = config.API.GraphQL.modelIntrospection;
|
|
14
|
+
if (!modelIntrospection) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];
|
|
18
|
+
for (const model of Object.values(modelIntrospection.models)) {
|
|
19
|
+
const { name } = model;
|
|
20
|
+
models[name] = {};
|
|
21
|
+
Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {
|
|
22
|
+
const operation = key;
|
|
23
|
+
if (operation === 'LIST') {
|
|
24
|
+
models[name][operationPrefix] = listFactory(client, modelIntrospection, model);
|
|
25
|
+
}
|
|
26
|
+
else if (SUBSCRIPTION_OPS.includes(operation)) {
|
|
27
|
+
models[name][operationPrefix] = subscriptionFactory(client, modelIntrospection, model, operation);
|
|
28
|
+
}
|
|
29
|
+
else if (operation === 'OBSERVE_QUERY') {
|
|
30
|
+
models[name][operationPrefix] = observeQueryFactory(models, model);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return models;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { generateModelsProperty };
|
|
41
|
+
//# sourceMappingURL=generateModelsProperty.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelsProperty.mjs","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from './APIClient';\nimport { listFactory } from './operations/list';\nimport { getFactory } from './operations/get';\nimport { subscriptionFactory } from './operations/subscription';\nimport { observeQueryFactory } from './operations/observeQuery';\nexport function 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(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = subscriptionFactory(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = observeQueryFactory(models, model);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation);\n }\n });\n }\n return models;\n}\n"],"names":[],"mappings":";;;;;;AAKO,SAAS,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE;AACvD,IAAI,MAAM,MAAM,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BAAiB,IAAI,SAAS,KAAK,eAAe,EAAE;AACpD,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACnF,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACzG,aAAa;AACb,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { ModelOperation } from '../APIClient';
|
|
3
|
+
import { ClientWithModels, GraphQLOptionsV6 } from '../../types';
|
|
4
|
+
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
export declare function getFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation, useContext?: boolean): (contextSpec: AmplifyServer.ContextSpec & GraphQLOptionsV6<unknown, string>, arg?: any, options?: any) => Promise<any>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, flattenItems, initializeModel } from '../APIClient.mjs';
|
|
2
|
+
|
|
3
|
+
function getFactory(client, modelIntrospection, model, operation, useContext = false) {
|
|
4
|
+
const getWithContext = async (contextSpec, arg, options) => {
|
|
5
|
+
return _get(client, modelIntrospection, model, arg, options, operation, contextSpec);
|
|
6
|
+
};
|
|
7
|
+
const get = async (arg, options) => {
|
|
8
|
+
return _get(client, modelIntrospection, model, arg, options, operation);
|
|
9
|
+
};
|
|
10
|
+
return useContext ? getWithContext : get;
|
|
11
|
+
}
|
|
12
|
+
async function _get(client, modelIntrospection, model, arg, options, operation, context) {
|
|
13
|
+
const { name } = model;
|
|
14
|
+
const query = generateGraphQLDocument(modelIntrospection.models, name, operation, options);
|
|
15
|
+
const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
|
|
16
|
+
try {
|
|
17
|
+
const auth = authModeParams(client, options);
|
|
18
|
+
const { data, extensions } = context
|
|
19
|
+
? (await client.graphql(context, {
|
|
20
|
+
...auth,
|
|
21
|
+
query,
|
|
22
|
+
variables,
|
|
23
|
+
}))
|
|
24
|
+
: (await client.graphql({
|
|
25
|
+
...auth,
|
|
26
|
+
query,
|
|
27
|
+
variables,
|
|
28
|
+
}));
|
|
29
|
+
// flatten response
|
|
30
|
+
if (data) {
|
|
31
|
+
const [key] = Object.keys(data);
|
|
32
|
+
const flattenedResult = flattenItems(data)[key];
|
|
33
|
+
if (options?.selectionSet) {
|
|
34
|
+
return { data: flattenedResult, extensions };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// TODO: refactor to avoid destructuring here
|
|
38
|
+
const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
|
|
39
|
+
return { data: initialized, extensions };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return { data: null, extensions };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.errors) {
|
|
48
|
+
// graphql errors pass through
|
|
49
|
+
return error;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// non-graphql errors re re-thrown
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { getFactory };
|
|
59
|
+
//# sourceMappingURL=get.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.mjs","sources":["../../../../src/internals/operations/get.ts"],"sourcesContent":["import { initializeModel, generateGraphQLDocument, buildGraphQLVariables, flattenItems, authModeParams, } from '../APIClient';\nexport function 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}\nasync function _get(client, modelIntrospection, model, arg, options, operation, context) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection.models, name, operation, options);\n const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);\n try {\n const auth = 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 = 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] = 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":";;AACO,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK,EAAE;AAC7F,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAC7F,KAAK,CAAC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IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC5D,YAAY,IAAI,OAAO,EAAE,YAAY,EAAE;AACvC,gBAAgB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AAC7D,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,MAAM,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AACrJ,gBAAgB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACzD,aAAa;AACb,SAAS;AACT,aAAa;AACb,YAAY,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9C,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,4 @@
|
|
|
1
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { ClientWithModels, ListArgs } from '../../types';
|
|
3
|
+
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
export declare function listFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, context?: boolean): (contextSpec: AmplifyServer.ContextSpec, args?: ListArgs) => Promise<any>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, flattenItems, initializeModel } from '../APIClient.mjs';
|
|
2
|
+
|
|
3
|
+
function listFactory(client, modelIntrospection, model, context = false) {
|
|
4
|
+
const listWithContext = async (contextSpec, args) => {
|
|
5
|
+
return _list(client, modelIntrospection, model, args, contextSpec);
|
|
6
|
+
};
|
|
7
|
+
const list = async (args) => {
|
|
8
|
+
return _list(client, modelIntrospection, model, args);
|
|
9
|
+
};
|
|
10
|
+
return context ? listWithContext : list;
|
|
11
|
+
}
|
|
12
|
+
async function _list(client, modelIntrospection, model, args, contextSpec) {
|
|
13
|
+
const { name } = model;
|
|
14
|
+
const query = generateGraphQLDocument(modelIntrospection.models, name, 'LIST', args);
|
|
15
|
+
const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);
|
|
16
|
+
try {
|
|
17
|
+
const auth = authModeParams(client, args);
|
|
18
|
+
const { data, extensions } = !!contextSpec
|
|
19
|
+
? (await client.graphql(contextSpec, {
|
|
20
|
+
...auth,
|
|
21
|
+
query,
|
|
22
|
+
variables,
|
|
23
|
+
}))
|
|
24
|
+
: (await client.graphql({
|
|
25
|
+
...auth,
|
|
26
|
+
query,
|
|
27
|
+
variables,
|
|
28
|
+
}));
|
|
29
|
+
// flatten response
|
|
30
|
+
if (data !== undefined) {
|
|
31
|
+
const [key] = Object.keys(data);
|
|
32
|
+
if (data[key].items) {
|
|
33
|
+
const flattenedResult = flattenItems(data)[key];
|
|
34
|
+
// don't init if custom selection set
|
|
35
|
+
if (args?.selectionSet) {
|
|
36
|
+
return {
|
|
37
|
+
data: flattenedResult,
|
|
38
|
+
nextToken: data[key].nextToken,
|
|
39
|
+
extensions,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
|
|
44
|
+
return {
|
|
45
|
+
data: initialized,
|
|
46
|
+
nextToken: data[key].nextToken,
|
|
47
|
+
extensions,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
data: data[key],
|
|
53
|
+
nextToken: data[key].nextToken,
|
|
54
|
+
extensions,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.errors) {
|
|
60
|
+
// graphql errors pass through
|
|
61
|
+
return error;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// non-graphql errors re re-thrown
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { listFactory };
|
|
71
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.mjs","sources":["../../../../src/internals/operations/list.ts"],"sourcesContent":["import { initializeModel, generateGraphQLDocument, buildGraphQLVariables, flattenItems, authModeParams, } from '../APIClient';\nexport function 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}\nasync function _list(client, modelIntrospection, model, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection.models, name, 'LIST', args);\n const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);\n try {\n const auth = 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 = 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 = 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":";;AACO,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE;AAChF,IAAI,MAAM,eAAe,GAAG,OAAO,WAAW,EAAE,IAAI,KAAK;AACzD,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAC3E,KAAK,CAAC;AACN,IAAI,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK;AACjC,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAC9D,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,GAAG,eAAe,GAAG,IAAI,CAAC;AAC5C,CAAC;AACD,eAAe,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;AAC3E,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,KAAK,GAAG,uBAAuB,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACzF,IAAI,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;AACrF,IAAI,IAAI;AACR,QAAQ,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClD,QAAQ,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,WAAW;AAClD,eAAe,MAAM,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;AACjD,gBAAgB,GAAG,IAAI;AACvB,gBAAgB,KAAK;AACrB,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AK;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,122 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import '@aws-amplify/core/internals/utils';
|
|
3
|
+
import '../../utils/errors/validation.mjs';
|
|
4
|
+
import { resolvePKFields } from '../../utils/resolvePKFields.mjs';
|
|
5
|
+
import { findIndexByFields } from '../../utils/findIndexByFields.mjs';
|
|
6
|
+
|
|
7
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
function observeQueryFactory(models, model) {
|
|
10
|
+
const { name } = model;
|
|
11
|
+
const observeQuery = (arg) => new 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 = 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 = 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
|
+
|
|
121
|
+
export { observeQueryFactory };
|
|
122
|
+
//# sourceMappingURL=observeQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observeQuery.mjs","sources":["../../../../src/internals/operations/observeQuery.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Observable } from 'rxjs';\nimport { findIndexByFields, resolvePKFields } from '../../utils';\nexport function observeQueryFactory(models, model) {\n const { name } = model;\n const observeQuery = (arg) => new 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 = 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 = 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}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAGO,SAAS,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE;AACnD,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,IAAI,UAAU,CAAC,UAAU,IAAI;AAC/D;AACA,QAAQ,MAAM,KAAK,GAAG,EAAE,CAAC;AACzB;AACA;AACA,QAAQ,MAAM,YAAY,GAAG,EAAE,CAAC;AAChC;AACA;AACA;AACA,QAAQ,IAAI,eAAe,GAAG,CAAC,GAAG,QAAQ,KAAK;AAC/C,YAAY,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;AAClD,SAAS,CAAC;AACV;AACA,QAAQ,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC;AACjE,YAAY,IAAI,CAAC,IAAI,EAAE;AACvB,gBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC1D,aAAa;AACb,YAAY,KAAK,CAAC,KAAK,EAAE;AACzB,gBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9D,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC;AACjE,YAAY,IAAI,CAAC,IAAI,EAAE;AACvB,gBAAgB,eAAe,CAAC,EAAE,I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EAAE;AAC3C,oBAAoB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;AAChD,wBAAwB,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAChD,qBAAqB;AACrB,iBAAiB;AACjB,aAAa;AACb;AACA,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;AACzC,gBAAgB,cAAc,CAAC,YAAY,CAAC,CAAC;AAC7C,aAAa;AACb;AACA,YAAY,eAAe,GAAG,CAAC,GAAG,QAAQ,KAAK;AAC/C,gBAAgB,cAAc,CAAC,QAAQ,CAAC,CAAC;AACzC,gBAAgB,OAAO,KAAK,CAAC,MAAM,CAAC;AACpC,aAAa,CAAC;AACd,SAAS,GAAG,CAAC;AACb;AACA,QAAQ,OAAO,MAAM;AACrB;AACA,YAAY,WAAW,CAAC,WAAW,EAAE,CAAC;AACtC,YAAY,WAAW,CAAC,WAAW,EAAE,CAAC;AACtC,YAAY,WAAW,CAAC,WAAW,EAAE,CAAC;AACtC;AACA;AACA,SAAS,CAAC;AACV,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,YAAY,CAAC;AACxB;;;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ModelOperation } from '../APIClient';
|
|
2
|
+
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
3
|
+
export declare function subscriptionFactory(client: any, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation): (args?: any) => import("rxjs").Observable<any>;
|