@aws-amplify/api 5.4.6-api-v6-models.b3abc9b.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/.tsbuildinfo +3 -0
- package/lib/API.d.ts +3 -41
- package/lib/API.js +15 -131
- package/lib/API.js.map +1 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +11 -6
- package/lib/index.js.map +1 -0
- package/lib/internals/InternalAPI.d.ts +4 -94
- package/lib/internals/InternalAPI.js +29 -144
- package/lib/internals/InternalAPI.js.map +1 -0
- package/lib/internals/index.js +3 -3
- package/lib/internals/index.js.map +1 -0
- package/lib/server.d.ts +14 -0
- package/lib/server.js +35 -0
- package/lib/server.js.map +1 -0
- package/lib/types/index.d.ts +1 -2
- package/lib/types/index.js +3 -4
- package/lib/types/index.js.map +1 -0
- package/lib-esm/.tsbuildinfo +3 -0
- package/lib-esm/API.d.ts +3 -41
- package/lib-esm/API.js +14 -130
- package/lib-esm/API.js.map +1 -0
- package/lib-esm/index.d.ts +4 -3
- package/lib-esm/index.js +4 -2
- package/lib-esm/index.js.map +1 -0
- package/lib-esm/internals/InternalAPI.d.ts +4 -94
- package/lib-esm/internals/InternalAPI.js +28 -143
- package/lib-esm/internals/InternalAPI.js.map +1 -0
- package/lib-esm/internals/index.js +1 -0
- package/lib-esm/internals/index.js.map +1 -0
- package/lib-esm/server.d.ts +14 -0
- package/lib-esm/server.js +25 -0
- package/lib-esm/server.js.map +1 -0
- package/lib-esm/types/index.d.ts +1 -2
- package/lib-esm/types/index.js +2 -1
- package/lib-esm/types/index.js.map +1 -0
- package/package.json +12 -32
- package/server/package.json +8 -0
- package/src/API.ts +16 -200
- package/src/index.ts +18 -6
- package/src/internals/InternalAPI.ts +15 -194
- package/src/server.ts +59 -0
- package/src/types/index.ts +0 -2
- package/index.v37.d.ts +0 -12
- package/lib/APIClient.d.ts +0 -55
- package/lib/APIClient.js +0 -404
- package/lib/tsconfig.build.tsbuildinfo +0 -1
- package/lib-esm/APIClient.d.ts +0 -55
- package/lib-esm/APIClient.js +0 -393
- package/lib-esm/tsconfig.build.tsbuildinfo +0 -1
- package/src/APIClient.ts +0 -534
package/README.md
ADDED
package/lib/.tsbuildinfo
ADDED
package/lib/API.d.ts
CHANGED
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { GraphQLOptions, GraphQLResult, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
3
|
-
import { graphql as v6graphql } from '@aws-amplify/api-graphql/internals';
|
|
4
|
-
import Observable from 'zen-observable-ts';
|
|
5
|
-
import { InternalAPIClass } from './internals/InternalAPI';
|
|
6
|
-
import type { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
1
|
+
import { V6Client } from '@aws-amplify/api-graphql';
|
|
7
2
|
/**
|
|
8
|
-
*
|
|
9
|
-
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
10
|
-
* Export Cloud Logic APIs
|
|
3
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
11
4
|
*/
|
|
12
|
-
export declare
|
|
13
|
-
getModuleName(): string;
|
|
14
|
-
/**
|
|
15
|
-
* Executes a GraphQL operation
|
|
16
|
-
*
|
|
17
|
-
* @param options - GraphQL Options
|
|
18
|
-
* @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
|
|
19
|
-
* @returns An Observable if queryType is 'subscription', else a promise of the graphql result from the query.
|
|
20
|
-
*/
|
|
21
|
-
graphql<T>(options: GraphQLOptions, additionalHeaders?: {
|
|
22
|
-
[key: string]: string;
|
|
23
|
-
}): T extends GraphQLQuery<T> ? Promise<GraphQLResult<T>> : T extends GraphQLSubscription<T> ? Observable<{
|
|
24
|
-
provider: AWSAppSyncRealTimeProvider;
|
|
25
|
-
value: GraphQLResult<T>;
|
|
26
|
-
}> : Promise<GraphQLResult<any>> | Observable<object>;
|
|
27
|
-
/**
|
|
28
|
-
* Generates an API client that can work with models or raw GraphQL
|
|
29
|
-
*/
|
|
30
|
-
generateClient<T extends Record<any, any> = never>(): V6Client<T>;
|
|
31
|
-
}
|
|
32
|
-
type FilteredKeys<T> = {
|
|
33
|
-
[P in keyof T]: T[P] extends never ? never : P;
|
|
34
|
-
}[keyof T];
|
|
35
|
-
type ExcludeNeverFields<O> = {
|
|
36
|
-
[K in FilteredKeys<O>]: O[K];
|
|
37
|
-
};
|
|
38
|
-
declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
39
|
-
graphql: typeof v6graphql;
|
|
40
|
-
models: ModelTypes<T>;
|
|
41
|
-
}>;
|
|
42
|
-
export declare const API: APIClass;
|
|
43
|
-
export {};
|
|
5
|
+
export declare function generateClient<T extends Record<any, any> = never>(): V6Client<T>;
|
package/lib/API.js
CHANGED
|
@@ -1,136 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var APIClient_1 = require("./APIClient");
|
|
9
|
-
var logger = new core_1.ConsoleLogger('API');
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
const api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
6
|
+
const internals_1 = require("@aws-amplify/api-graphql/internals");
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
13
|
-
* Export Cloud Logic APIs
|
|
9
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
14
10
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return 'API';
|
|
11
|
+
function generateClient() {
|
|
12
|
+
return {
|
|
13
|
+
[api_graphql_1.__amplify]: core_1.Amplify,
|
|
14
|
+
graphql: internals_1.graphql,
|
|
15
|
+
cancel: internals_1.cancel,
|
|
16
|
+
isCancelError: internals_1.isCancelError,
|
|
22
17
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Generates an API client that can work with models or raw GraphQL
|
|
28
|
-
*/
|
|
29
|
-
APIClass.prototype.generateClient = function () {
|
|
30
|
-
var e_1, _a;
|
|
31
|
-
var _this = this;
|
|
32
|
-
var config = _super.prototype.configure.call(this, {});
|
|
33
|
-
var modelIntrospection = config.modelIntrospection;
|
|
34
|
-
var client = {
|
|
35
|
-
graphql: internals_1.graphql,
|
|
36
|
-
models: {},
|
|
37
|
-
};
|
|
38
|
-
var _loop_1 = function (model) {
|
|
39
|
-
var name_1 = model.name;
|
|
40
|
-
client.models[name_1] = {};
|
|
41
|
-
Object.entries(APIClient_1.graphQLOperationsInfo).forEach(function (_a) {
|
|
42
|
-
var _b = tslib_1.__read(_a, 2), key = _b[0], operationPrefix = _b[1].operationPrefix;
|
|
43
|
-
var operation = key;
|
|
44
|
-
if (operation === 'LIST') {
|
|
45
|
-
client.models[name_1][operationPrefix] = function (args) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
46
|
-
var query, variables, res, _a, key_1, flattenedResult, initialized;
|
|
47
|
-
return tslib_1.__generator(this, function (_b) {
|
|
48
|
-
switch (_b.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, 'LIST', args);
|
|
51
|
-
variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);
|
|
52
|
-
console.log('API list', query, variables);
|
|
53
|
-
return [4 /*yield*/, this.graphql({
|
|
54
|
-
query: query,
|
|
55
|
-
variables: variables,
|
|
56
|
-
})];
|
|
57
|
-
case 1:
|
|
58
|
-
res = (_b.sent());
|
|
59
|
-
// flatten response
|
|
60
|
-
if (res.data !== undefined) {
|
|
61
|
-
_a = tslib_1.__read(Object.keys(res.data), 1), key_1 = _a[0];
|
|
62
|
-
if (res.data[key_1].items) {
|
|
63
|
-
flattenedResult = (0, APIClient_1.flattenItems)(res.data)[key_1];
|
|
64
|
-
// don't init if custom selection set
|
|
65
|
-
if (args === null || args === void 0 ? void 0 : args.selectionSet) {
|
|
66
|
-
return [2 /*return*/, flattenedResult];
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
initialized = (0, APIClient_1.initializeModel)(client, name_1, flattenedResult, modelIntrospection);
|
|
70
|
-
console.log('initialized', initialized);
|
|
71
|
-
return [2 /*return*/, initialized];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return [2 /*return*/, res.data[key_1]];
|
|
75
|
-
}
|
|
76
|
-
return [2 /*return*/, res];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}); };
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
client.models[name_1][operationPrefix] = function (arg, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
83
|
-
var query, variables, res, _a, key_2, flattenedResult, _b, initialized;
|
|
84
|
-
return tslib_1.__generator(this, function (_c) {
|
|
85
|
-
switch (_c.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, operation, options);
|
|
88
|
-
variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
|
|
89
|
-
console.log("API ".concat(operationPrefix), query, variables);
|
|
90
|
-
return [4 /*yield*/, this.graphql({
|
|
91
|
-
query: query,
|
|
92
|
-
variables: variables,
|
|
93
|
-
})];
|
|
94
|
-
case 1:
|
|
95
|
-
res = (_c.sent());
|
|
96
|
-
// flatten response
|
|
97
|
-
if (res.data !== undefined) {
|
|
98
|
-
_a = tslib_1.__read(Object.keys(res.data), 1), key_2 = _a[0];
|
|
99
|
-
flattenedResult = (0, APIClient_1.flattenItems)(res.data)[key_2];
|
|
100
|
-
if (options === null || options === void 0 ? void 0 : options.selectionSet) {
|
|
101
|
-
return [2 /*return*/, flattenedResult];
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
_b = tslib_1.__read((0, APIClient_1.initializeModel)(client, name_1, [flattenedResult], modelIntrospection), 1), initialized = _b[0];
|
|
105
|
-
return [2 /*return*/, initialized];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return [2 /*return*/, res];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}); };
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
try {
|
|
116
|
-
// TODO: refactor this to use separate methods for each CRUDL.
|
|
117
|
-
// Doesn't make sense to gen the methods dynamically given the different args and return values
|
|
118
|
-
for (var _b = tslib_1.__values(Object.values(modelIntrospection.models)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
119
|
-
var model = _c.value;
|
|
120
|
-
_loop_1(model);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
124
|
-
finally {
|
|
125
|
-
try {
|
|
126
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
127
|
-
}
|
|
128
|
-
finally { if (e_1) throw e_1.error; }
|
|
129
|
-
}
|
|
130
|
-
return client;
|
|
131
|
-
};
|
|
132
|
-
return APIClass;
|
|
133
|
-
}(InternalAPI_1.InternalAPIClass));
|
|
134
|
-
exports.APIClass = APIClass;
|
|
135
|
-
exports.API = new APIClass(null);
|
|
136
|
-
core_1.Amplify.register(exports.API);
|
|
18
|
+
}
|
|
19
|
+
exports.generateClient = generateClient;
|
|
20
|
+
//# sourceMappingURL=API.js.map
|
package/lib/API.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,0DAA+D;AAC/D,kEAI4C;AAC5C,4CAA4C;AAE5C;;GAEG;AACH,SAAgB,cAAc;IAG7B,OAAO;QACN,CAAC,uBAAS,CAAC,EAAE,cAAO;QACpB,OAAO,EAAE,mBAAS;QAClB,MAAM,EAAE,kBAAQ;QAChB,aAAa,EAAE,yBAAe;KAC9B,CAAC;AACH,CAAC;AATD,wCASC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { GraphQLQuery, GraphQLSubscription } from './types';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export type { GraphQLResult } from '@aws-amplify/api-graphql';
|
|
2
|
+
export { generateClient } from './API';
|
|
3
|
+
export { GraphQLAuthError } from '@aws-amplify/api-graphql';
|
|
4
|
+
export type { GraphQLResult, GraphQLReturnType, } from '@aws-amplify/api-graphql';
|
|
5
|
+
export { get, put, post, del, head, patch, isCancelError, } from '@aws-amplify/api-rest';
|
package/lib/index.js
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.GRAPHQL_AUTH_MODE = exports.GraphQLAuthError = exports.graphqlOperation = exports.APIClass = exports.API = void 0;
|
|
6
5
|
var API_1 = require("./API");
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "APIClass", { enumerable: true, get: function () { return API_1.APIClass; } });
|
|
6
|
+
exports.generateClient = API_1.generateClient;
|
|
9
7
|
var api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
exports.GraphQLAuthError = api_graphql_1.GraphQLAuthError;
|
|
9
|
+
var api_rest_1 = require("@aws-amplify/api-rest");
|
|
10
|
+
exports.get = api_rest_1.get;
|
|
11
|
+
exports.put = api_rest_1.put;
|
|
12
|
+
exports.post = api_rest_1.post;
|
|
13
|
+
exports.del = api_rest_1.del;
|
|
14
|
+
exports.head = api_rest_1.head;
|
|
15
|
+
exports.patch = api_rest_1.patch;
|
|
16
|
+
exports.isCancelError = api_rest_1.isCancelError;
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAKtC,6BAAuC;AAA9B,+BAAA,cAAc,CAAA;AAEvB,wDAA4D;AAAnD,yCAAA,gBAAgB,CAAA;AAOzB,kDAQ+B;AAP9B,yBAAA,GAAG,CAAA;AACH,yBAAA,GAAG,CAAA;AACH,0BAAA,IAAI,CAAA;AACJ,yBAAA,GAAG,CAAA;AACH,0BAAA,IAAI,CAAA;AACJ,2BAAA,KAAK,CAAA;AACL,mCAAA,aAAa,CAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
2
|
-
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
3
|
-
import {
|
|
4
|
-
import Observable from 'zen-observable-ts';
|
|
1
|
+
import { AWSAppSyncRealTimeProvider, GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
2
|
+
import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
5
4
|
/**
|
|
6
5
|
* @deprecated
|
|
7
6
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -13,103 +12,14 @@ export declare class InternalAPIClass {
|
|
|
13
12
|
* @param {Object} options - Configuration object for API
|
|
14
13
|
*/
|
|
15
14
|
private _options;
|
|
16
|
-
private _restApi;
|
|
17
15
|
private _graphqlApi;
|
|
18
|
-
|
|
19
|
-
Cache: import("@aws-amplify/cache/lib-esm/types").ICache;
|
|
20
|
-
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
16
|
+
Cache: import("@aws-amplify/core/lib-esm/Cache/StorageCache").StorageCache;
|
|
21
17
|
/**
|
|
22
18
|
* Initialize API with AWS configuration
|
|
23
19
|
* @param {Object} options - Configuration object for API
|
|
24
20
|
*/
|
|
25
21
|
constructor(options: any);
|
|
26
22
|
getModuleName(): string;
|
|
27
|
-
/**
|
|
28
|
-
* Configure API part with aws configurations
|
|
29
|
-
* @param {Object} config - Configuration of the API
|
|
30
|
-
* @return {Object} - The current configuration
|
|
31
|
-
*/
|
|
32
|
-
configure(options: any): any;
|
|
33
|
-
/**
|
|
34
|
-
* Make a GET request
|
|
35
|
-
* @param apiName - The api name of the request
|
|
36
|
-
* @param path - The path of the request
|
|
37
|
-
* @param [init] - Request extra params
|
|
38
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
39
|
-
*/
|
|
40
|
-
get(apiName: string, path: string, init: {
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
}): Promise<any>;
|
|
43
|
-
/**
|
|
44
|
-
* Make a POST request
|
|
45
|
-
* @param apiName - The api name of the request
|
|
46
|
-
* @param path - The path of the request
|
|
47
|
-
* @param [init] - Request extra params
|
|
48
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
49
|
-
*/
|
|
50
|
-
post(apiName: string, path: string, init: {
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
}): Promise<any>;
|
|
53
|
-
/**
|
|
54
|
-
* Make a PUT request
|
|
55
|
-
* @param apiName - The api name of the request
|
|
56
|
-
* @param path - The path of the request
|
|
57
|
-
* @param [init] - Request extra params
|
|
58
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
59
|
-
*/
|
|
60
|
-
put(apiName: string, path: string, init: {
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
}): Promise<any>;
|
|
63
|
-
/**
|
|
64
|
-
* Make a PATCH request
|
|
65
|
-
* @param apiName - The api name of the request
|
|
66
|
-
* @param path - The path of the request
|
|
67
|
-
* @param [init] - Request extra params
|
|
68
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
69
|
-
*/
|
|
70
|
-
patch(apiName: string, path: string, init: {
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
}): Promise<any>;
|
|
73
|
-
/**
|
|
74
|
-
* Make a DEL request
|
|
75
|
-
* @param apiName - The api name of the request
|
|
76
|
-
* @param path - The path of the request
|
|
77
|
-
* @param [init] - Request extra params
|
|
78
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
79
|
-
*/
|
|
80
|
-
del(apiName: string, path: string, init: {
|
|
81
|
-
[key: string]: any;
|
|
82
|
-
}): Promise<any>;
|
|
83
|
-
/**
|
|
84
|
-
* Make a HEAD request
|
|
85
|
-
* @param apiName - The api name of the request
|
|
86
|
-
* @param path - The path of the request
|
|
87
|
-
* @param [init] - Request extra params
|
|
88
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
89
|
-
*/
|
|
90
|
-
head(apiName: string, path: string, init: {
|
|
91
|
-
[key: string]: any;
|
|
92
|
-
}): Promise<any>;
|
|
93
|
-
/**
|
|
94
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
95
|
-
* @param error - Any error
|
|
96
|
-
* @return If the error was from an api request cancellation
|
|
97
|
-
*/
|
|
98
|
-
isCancel(error: any): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* Cancels an inflight request for either a GraphQL request or a Rest API request.
|
|
101
|
-
* @param request - request to cancel
|
|
102
|
-
* @param [message] - custom error message
|
|
103
|
-
* @return If the request was cancelled
|
|
104
|
-
*/
|
|
105
|
-
cancel(request: Promise<any>, message?: string): boolean;
|
|
106
|
-
private getInitWithCustomUserAgentDetails;
|
|
107
|
-
/**
|
|
108
|
-
* Getting endpoint for API
|
|
109
|
-
* @param apiName - The name of the api
|
|
110
|
-
* @return The endpoint of the api
|
|
111
|
-
*/
|
|
112
|
-
endpoint(apiName: string): Promise<string>;
|
|
113
23
|
/**
|
|
114
24
|
* to get the operation type
|
|
115
25
|
* @param operation
|
|
@@ -1,167 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const internals_1 = require("@aws-amplify/api-graphql/internals");
|
|
4
|
+
const core_1 = require("@aws-amplify/core");
|
|
5
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
6
|
+
/**
|
|
7
|
+
* NOTE!
|
|
8
|
+
*
|
|
9
|
+
* This is used only by DataStore.
|
|
10
|
+
*
|
|
11
|
+
* This can probably be pruned and/or removed. Just leaving it as much of the same
|
|
12
|
+
* state as possible for V6 to reduce number of potentially impactful changes to DataStore.
|
|
13
|
+
*/
|
|
14
|
+
const logger = new core_1.ConsoleLogger('API');
|
|
11
15
|
/**
|
|
12
16
|
* @deprecated
|
|
13
17
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
14
18
|
* Export Cloud Logic APIs
|
|
15
19
|
*/
|
|
16
|
-
|
|
20
|
+
class InternalAPIClass {
|
|
17
21
|
/**
|
|
18
22
|
* Initialize API with AWS configuration
|
|
19
23
|
* @param {Object} options - Configuration object for API
|
|
20
24
|
*/
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.Cache = cache_1.Cache;
|
|
24
|
-
this.Credentials = core_1.Credentials;
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.Cache = core_1.Cache;
|
|
25
27
|
this._options = options;
|
|
26
|
-
this._restApi = new api_rest_1.RestAPIClass(options);
|
|
27
28
|
this._graphqlApi = new internals_1.InternalGraphQLAPIClass(options);
|
|
28
29
|
logger.debug('API Options', this._options);
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
getModuleName() {
|
|
31
32
|
return 'InternalAPI';
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Configure API part with aws configurations
|
|
35
|
-
* @param {Object} config - Configuration of the API
|
|
36
|
-
* @return {Object} - The current configuration
|
|
37
|
-
*/
|
|
38
|
-
InternalAPIClass.prototype.configure = function (options) {
|
|
39
|
-
this._options = Object.assign({}, this._options, options);
|
|
40
|
-
// Share Amplify instance with client for SSR
|
|
41
|
-
this._restApi.Credentials = this.Credentials;
|
|
42
|
-
this._graphqlApi.Auth = this.Auth;
|
|
43
|
-
this._graphqlApi.Cache = this.Cache;
|
|
44
|
-
this._graphqlApi.Credentials = this.Credentials;
|
|
45
|
-
var restAPIConfig = this._restApi.configure(this._options);
|
|
46
|
-
var graphQLAPIConfig = this._graphqlApi.configure(this._options);
|
|
47
|
-
return tslib_1.__assign(tslib_1.__assign({}, restAPIConfig), graphQLAPIConfig);
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Make a GET request
|
|
51
|
-
* @param apiName - The api name of the request
|
|
52
|
-
* @param path - The path of the request
|
|
53
|
-
* @param [init] - Request extra params
|
|
54
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
55
|
-
*/
|
|
56
|
-
InternalAPIClass.prototype.get = function (apiName, path, init) {
|
|
57
|
-
return this._restApi.get(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Get));
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Make a POST request
|
|
61
|
-
* @param apiName - The api name of the request
|
|
62
|
-
* @param path - The path of the request
|
|
63
|
-
* @param [init] - Request extra params
|
|
64
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
65
|
-
*/
|
|
66
|
-
InternalAPIClass.prototype.post = function (apiName, path, init) {
|
|
67
|
-
return this._restApi.post(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Post));
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Make a PUT request
|
|
71
|
-
* @param apiName - The api name of the request
|
|
72
|
-
* @param path - The path of the request
|
|
73
|
-
* @param [init] - Request extra params
|
|
74
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
75
|
-
*/
|
|
76
|
-
InternalAPIClass.prototype.put = function (apiName, path, init) {
|
|
77
|
-
return this._restApi.put(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Put));
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Make a PATCH request
|
|
81
|
-
* @param apiName - The api name of the request
|
|
82
|
-
* @param path - The path of the request
|
|
83
|
-
* @param [init] - Request extra params
|
|
84
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
85
|
-
*/
|
|
86
|
-
InternalAPIClass.prototype.patch = function (apiName, path, init) {
|
|
87
|
-
return this._restApi.patch(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Patch));
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Make a DEL request
|
|
91
|
-
* @param apiName - The api name of the request
|
|
92
|
-
* @param path - The path of the request
|
|
93
|
-
* @param [init] - Request extra params
|
|
94
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
95
|
-
*/
|
|
96
|
-
InternalAPIClass.prototype.del = function (apiName, path, init) {
|
|
97
|
-
return this._restApi.del(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Del));
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Make a HEAD request
|
|
101
|
-
* @param apiName - The api name of the request
|
|
102
|
-
* @param path - The path of the request
|
|
103
|
-
* @param [init] - Request extra params
|
|
104
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
105
|
-
*/
|
|
106
|
-
InternalAPIClass.prototype.head = function (apiName, path, init) {
|
|
107
|
-
return this._restApi.head(apiName, path, this.getInitWithCustomUserAgentDetails(init, core_1.ApiAction.Head));
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
111
|
-
* @param error - Any error
|
|
112
|
-
* @return If the error was from an api request cancellation
|
|
113
|
-
*/
|
|
114
|
-
InternalAPIClass.prototype.isCancel = function (error) {
|
|
115
|
-
return this._restApi.isCancel(error);
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Cancels an inflight request for either a GraphQL request or a Rest API request.
|
|
119
|
-
* @param request - request to cancel
|
|
120
|
-
* @param [message] - custom error message
|
|
121
|
-
* @return If the request was cancelled
|
|
122
|
-
*/
|
|
123
|
-
InternalAPIClass.prototype.cancel = function (request, message) {
|
|
124
|
-
if (this._restApi.hasCancelToken(request)) {
|
|
125
|
-
return this._restApi.cancel(request, message);
|
|
126
|
-
}
|
|
127
|
-
else if (this._graphqlApi.hasCancelToken(request)) {
|
|
128
|
-
return this._graphqlApi.cancel(request, message);
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
|
-
};
|
|
132
|
-
InternalAPIClass.prototype.getInitWithCustomUserAgentDetails = function (init, action) {
|
|
133
|
-
var customUserAgentDetails = {
|
|
134
|
-
category: core_1.Category.API,
|
|
135
|
-
action: action,
|
|
136
|
-
};
|
|
137
|
-
var initParams = tslib_1.__assign(tslib_1.__assign({}, init), { customUserAgentDetails: customUserAgentDetails });
|
|
138
|
-
return initParams;
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Getting endpoint for API
|
|
142
|
-
* @param apiName - The name of the api
|
|
143
|
-
* @return The endpoint of the api
|
|
144
|
-
*/
|
|
145
|
-
InternalAPIClass.prototype.endpoint = function (apiName) {
|
|
146
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
147
|
-
return tslib_1.__generator(this, function (_a) {
|
|
148
|
-
return [2 /*return*/, this._restApi.endpoint(apiName)];
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
33
|
+
}
|
|
152
34
|
/**
|
|
153
35
|
* to get the operation type
|
|
154
36
|
* @param operation
|
|
155
37
|
*/
|
|
156
|
-
|
|
38
|
+
getGraphqlOperationType(operation) {
|
|
157
39
|
return this._graphqlApi.getGraphqlOperationType(operation);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
40
|
+
}
|
|
41
|
+
graphql(options, additionalHeaders, customUserAgentDetails) {
|
|
42
|
+
const apiUserAgentDetails = {
|
|
43
|
+
category: utils_1.Category.API,
|
|
44
|
+
action: utils_1.ApiAction.GraphQl,
|
|
45
|
+
...customUserAgentDetails,
|
|
46
|
+
};
|
|
47
|
+
return this._graphqlApi.graphql(core_1.Amplify, options, additionalHeaders, apiUserAgentDetails);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
165
50
|
exports.InternalAPIClass = InternalAPIClass;
|
|
166
51
|
exports.InternalAPI = new InternalAPIClass(null);
|
|
167
|
-
|
|
52
|
+
//# sourceMappingURL=InternalAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InternalAPI.js","sourceRoot":"","sources":["../../src/internals/InternalAPI.ts"],"names":[],"mappings":";;AAWA,kEAA6E;AAC7E,4CAAkE;AAClE,6DAI2C;AAG3C;;;;;;;GAOG;AAEH,MAAM,MAAM,GAAG,IAAI,oBAAa,CAAC,KAAK,CAAC,CAAC;AACxC;;;;GAIG;AACH,MAAa,gBAAgB;IAU5B;;;OAGG;IACH,YAAY,OAAO;QANnB,UAAK,GAAG,YAAK,CAAC;QAOb,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,mCAAuB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEM,aAAa;QACnB,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,uBAAuB,CAAC,SAA2B;QAClD,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAqBD,OAAO,CACN,OAAuB,EACvB,iBAA6C,EAC7C,sBAA+C;QAE/C,MAAM,mBAAmB,GAA2B;YACnD,QAAQ,EAAE,gBAAQ,CAAC,GAAG;YACtB,MAAM,EAAE,iBAAS,CAAC,OAAO;YACzB,GAAG,sBAAsB;SACzB,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAC9B,cAAO,EACP,OAAO,EACP,iBAAiB,EACjB,mBAAmB,CACnB,CAAC;IACH,CAAC;CACD;AArED,4CAqEC;AAEY,QAAA,WAAW,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC"}
|
package/lib/internals/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternalAPIClass = exports.InternalAPI = void 0;
|
|
4
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
5
|
var InternalAPI_1 = require("./InternalAPI");
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
exports.InternalAPI = InternalAPI_1.InternalAPI;
|
|
7
|
+
exports.InternalAPIClass = InternalAPI_1.InternalAPIClass;
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internals/index.ts"],"names":[],"mappings":";;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,6CAA8D;AAArD,oCAAA,WAAW,CAAA;AAAE,yCAAA,gBAAgB,CAAA"}
|
package/lib/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { GraphQLQuery, GraphQLSubscription } from './types';
|
|
2
|
+
import { V6Client, V6ClientSSR, ServerClientGenerationParams } from '@aws-amplify/api-graphql';
|
|
3
|
+
export type { GraphQLResult, GraphQLReturnType, } from '@aws-amplify/api-graphql';
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
*
|
|
7
|
+
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
8
|
+
* compatible context object for config and auth fetching.
|
|
9
|
+
*
|
|
10
|
+
* @param params
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateClient<T extends Record<any, any> = never, ClientType extends V6ClientSSR<T> | V6Client<T> = V6ClientSSR<T>>(params: ServerClientGenerationParams): ClientType;
|
|
14
|
+
export { get, put, post, del, head, patch, isCancelError, } from '@aws-amplify/api-rest/server';
|
package/lib/server.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const internals_1 = require("@aws-amplify/api-graphql/internals");
|
|
6
|
+
const api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
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
|
+
[api_graphql_1.__amplify]: params.amplify,
|
|
19
|
+
graphql: internals_1.graphql,
|
|
20
|
+
cancel: internals_1.cancel,
|
|
21
|
+
isCancelError: internals_1.isCancelError,
|
|
22
|
+
models: {},
|
|
23
|
+
};
|
|
24
|
+
return client;
|
|
25
|
+
}
|
|
26
|
+
exports.generateClient = generateClient;
|
|
27
|
+
var server_1 = require("@aws-amplify/api-rest/server");
|
|
28
|
+
exports.get = server_1.get;
|
|
29
|
+
exports.put = server_1.put;
|
|
30
|
+
exports.post = server_1.post;
|
|
31
|
+
exports.del = server_1.del;
|
|
32
|
+
exports.head = server_1.head;
|
|
33
|
+
exports.patch = server_1.patch;
|
|
34
|
+
exports.isCancelError = server_1.isCancelError;
|
|
35
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAGtC,kEAI4C;AAM5C,0DAKkC;AAOlC;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAG5B,MAAoC;IACrC,MAAM,MAAM,GAAG;QACd,CAAC,uBAAS,CAAC,EAAE,MAAM,CAAC,OAAO;QAC3B,OAAO,EAAP,mBAAO;QACP,MAAM,EAAN,kBAAM;QACN,aAAa,EAAb,yBAAa;QACb,MAAM,EAAE,EAAE;KACH,CAAC;IAET,OAAO,MAAoB,CAAC;AAC7B,CAAC;AAbD,wCAaC;AAED,uDAQsC;AAPrC,uBAAA,GAAG,CAAA;AACH,uBAAA,GAAG,CAAA;AACH,wBAAA,IAAI,CAAA;AACJ,uBAAA,GAAG,CAAA;AACH,wBAAA,IAAI,CAAA;AACJ,yBAAA,KAAK,CAAA;AACL,iCAAA,aAAa,CAAA"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,5 +3,4 @@
|
|
|
3
3
|
* generates code that relies on this import path https://github.com/aws-amplify/amplify-cli/issues/3863
|
|
4
4
|
* This will be removed in future release when CLI and customers moves to recommeneded import styles.
|
|
5
5
|
*/
|
|
6
|
-
export { graphqlOperation, GraphQLAuthError, GraphQLResult,
|
|
7
|
-
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
6
|
+
export { graphqlOperation, GraphQLAuthError, GraphQLResult, GraphQLQuery, GraphQLSubscription, } from '@aws-amplify/api-graphql';
|