@aws-amplify/api 5.4.6-unstable.7762f1a.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/API.d.ts +3 -25
- package/lib/API.js +14 -22
- package/lib/API.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/lib/index.js +9 -4
- package/lib/index.js.map +1 -1
- package/lib/internals/InternalAPI.d.ts +4 -95
- package/lib/internals/InternalAPI.js +28 -143
- package/lib/internals/InternalAPI.js.map +1 -1
- 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 -8
- package/lib/types/index.js +0 -1
- package/lib/types/index.js.map +1 -1
- package/lib-esm/API.d.ts +3 -25
- package/lib-esm/API.js +13 -22
- package/lib-esm/API.js.map +1 -1
- package/lib-esm/index.d.ts +4 -3
- package/lib-esm/index.js +3 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/internals/InternalAPI.d.ts +4 -95
- package/lib-esm/internals/InternalAPI.js +27 -143
- package/lib-esm/internals/InternalAPI.js.map +1 -1
- 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 -8
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/types/index.js.map +1 -1
- package/package.json +9 -24
- package/server/package.json +8 -0
- package/src/API.ts +17 -42
- package/src/index.ts +18 -6
- package/src/internals/InternalAPI.ts +17 -195
- package/src/server.ts +59 -0
- package/src/types/index.ts +2 -9
- package/index.v37.d.ts +0 -12
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
|
+
AWSAppSyncRealTimeProvider,
|
|
4
5
|
GraphQLOperation,
|
|
5
6
|
GraphQLOptions,
|
|
6
7
|
GraphQLResult,
|
|
7
8
|
OperationTypeNode,
|
|
9
|
+
GraphQLQuery,
|
|
10
|
+
GraphQLSubscription,
|
|
8
11
|
} from '@aws-amplify/api-graphql';
|
|
9
12
|
import { InternalGraphQLAPIClass } from '@aws-amplify/api-graphql/internals';
|
|
10
|
-
import {
|
|
11
|
-
import { Auth } from '@aws-amplify/auth';
|
|
12
|
-
import { Cache } from '@aws-amplify/cache';
|
|
13
|
+
import { Amplify, Cache, ConsoleLogger } from '@aws-amplify/core';
|
|
13
14
|
import {
|
|
14
|
-
Amplify,
|
|
15
15
|
ApiAction,
|
|
16
16
|
Category,
|
|
17
|
-
Credentials,
|
|
18
17
|
CustomUserAgentDetails,
|
|
19
|
-
|
|
20
|
-
} from '
|
|
21
|
-
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
22
|
-
import Observable from 'zen-observable-ts';
|
|
23
|
-
import { GraphQLQuery, GraphQLSubscription } from '../types';
|
|
18
|
+
} from '@aws-amplify/core/internals/utils';
|
|
19
|
+
import { Observable } from 'rxjs';
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* NOTE!
|
|
23
|
+
*
|
|
24
|
+
* This is used only by DataStore.
|
|
25
|
+
*
|
|
26
|
+
* This can probably be pruned and/or removed. Just leaving it as much of the same
|
|
27
|
+
* state as possible for V6 to reduce number of potentially impactful changes to DataStore.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const logger = new ConsoleLogger('API');
|
|
26
31
|
/**
|
|
27
32
|
* @deprecated
|
|
28
33
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -34,12 +39,9 @@ export class InternalAPIClass {
|
|
|
34
39
|
* @param {Object} options - Configuration object for API
|
|
35
40
|
*/
|
|
36
41
|
private _options;
|
|
37
|
-
private _restApi: RestAPIClass;
|
|
38
42
|
private _graphqlApi: InternalGraphQLAPIClass;
|
|
39
43
|
|
|
40
|
-
Auth = Auth;
|
|
41
44
|
Cache = Cache;
|
|
42
|
-
Credentials = Credentials;
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* Initialize API with AWS configuration
|
|
@@ -47,7 +49,6 @@ export class InternalAPIClass {
|
|
|
47
49
|
*/
|
|
48
50
|
constructor(options) {
|
|
49
51
|
this._options = options;
|
|
50
|
-
this._restApi = new RestAPIClass(options);
|
|
51
52
|
this._graphqlApi = new InternalGraphQLAPIClass(options);
|
|
52
53
|
logger.debug('API Options', this._options);
|
|
53
54
|
}
|
|
@@ -56,185 +57,6 @@ export class InternalAPIClass {
|
|
|
56
57
|
return 'InternalAPI';
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
/**
|
|
60
|
-
* Configure API part with aws configurations
|
|
61
|
-
* @param {Object} config - Configuration of the API
|
|
62
|
-
* @return {Object} - The current configuration
|
|
63
|
-
*/
|
|
64
|
-
configure(options) {
|
|
65
|
-
this._options = Object.assign({}, this._options, options);
|
|
66
|
-
|
|
67
|
-
// Share Amplify instance with client for SSR
|
|
68
|
-
this._restApi.Credentials = this.Credentials;
|
|
69
|
-
|
|
70
|
-
this._graphqlApi.Auth = this.Auth;
|
|
71
|
-
this._graphqlApi.Cache = this.Cache;
|
|
72
|
-
this._graphqlApi.Credentials = this.Credentials;
|
|
73
|
-
|
|
74
|
-
const restAPIConfig = this._restApi.configure(this._options);
|
|
75
|
-
const graphQLAPIConfig = this._graphqlApi.configure(this._options);
|
|
76
|
-
|
|
77
|
-
return { ...restAPIConfig, ...graphQLAPIConfig };
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Make a GET request
|
|
82
|
-
* @param apiName - The api name of the request
|
|
83
|
-
* @param path - The path of the request
|
|
84
|
-
* @param [init] - Request extra params
|
|
85
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
86
|
-
*/
|
|
87
|
-
get(
|
|
88
|
-
apiName: string,
|
|
89
|
-
path: string,
|
|
90
|
-
init: { [key: string]: any }
|
|
91
|
-
): Promise<any> {
|
|
92
|
-
return this._restApi.get(
|
|
93
|
-
apiName,
|
|
94
|
-
path,
|
|
95
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Get)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Make a POST 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
|
-
post(
|
|
107
|
-
apiName: string,
|
|
108
|
-
path: string,
|
|
109
|
-
init: { [key: string]: any }
|
|
110
|
-
): Promise<any> {
|
|
111
|
-
return this._restApi.post(
|
|
112
|
-
apiName,
|
|
113
|
-
path,
|
|
114
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Post)
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Make a PUT request
|
|
120
|
-
* @param apiName - The api name of the request
|
|
121
|
-
* @param path - The path of the request
|
|
122
|
-
* @param [init] - Request extra params
|
|
123
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
124
|
-
*/
|
|
125
|
-
put(
|
|
126
|
-
apiName: string,
|
|
127
|
-
path: string,
|
|
128
|
-
init: { [key: string]: any }
|
|
129
|
-
): Promise<any> {
|
|
130
|
-
return this._restApi.put(
|
|
131
|
-
apiName,
|
|
132
|
-
path,
|
|
133
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Put)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Make a PATCH request
|
|
139
|
-
* @param apiName - The api name of the request
|
|
140
|
-
* @param path - The path of the request
|
|
141
|
-
* @param [init] - Request extra params
|
|
142
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
143
|
-
*/
|
|
144
|
-
patch(
|
|
145
|
-
apiName: string,
|
|
146
|
-
path: string,
|
|
147
|
-
init: { [key: string]: any }
|
|
148
|
-
): Promise<any> {
|
|
149
|
-
return this._restApi.patch(
|
|
150
|
-
apiName,
|
|
151
|
-
path,
|
|
152
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Patch)
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Make a DEL request
|
|
158
|
-
* @param apiName - The api name of the request
|
|
159
|
-
* @param path - The path of the request
|
|
160
|
-
* @param [init] - Request extra params
|
|
161
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
162
|
-
*/
|
|
163
|
-
del(
|
|
164
|
-
apiName: string,
|
|
165
|
-
path: string,
|
|
166
|
-
init: { [key: string]: any }
|
|
167
|
-
): Promise<any> {
|
|
168
|
-
return this._restApi.del(
|
|
169
|
-
apiName,
|
|
170
|
-
path,
|
|
171
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Del)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Make a HEAD request
|
|
177
|
-
* @param apiName - The api name of the request
|
|
178
|
-
* @param path - The path of the request
|
|
179
|
-
* @param [init] - Request extra params
|
|
180
|
-
* @return A promise that resolves to an object with response status and JSON data, if successful.
|
|
181
|
-
*/
|
|
182
|
-
head(
|
|
183
|
-
apiName: string,
|
|
184
|
-
path: string,
|
|
185
|
-
init: { [key: string]: any }
|
|
186
|
-
): Promise<any> {
|
|
187
|
-
return this._restApi.head(
|
|
188
|
-
apiName,
|
|
189
|
-
path,
|
|
190
|
-
this.getInitWithCustomUserAgentDetails(init, ApiAction.Head)
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
196
|
-
* @param error - Any error
|
|
197
|
-
* @return If the error was from an api request cancellation
|
|
198
|
-
*/
|
|
199
|
-
isCancel(error: any): boolean {
|
|
200
|
-
return this._restApi.isCancel(error);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Cancels an inflight request for either a GraphQL request or a Rest API request.
|
|
204
|
-
* @param request - request to cancel
|
|
205
|
-
* @param [message] - custom error message
|
|
206
|
-
* @return If the request was cancelled
|
|
207
|
-
*/
|
|
208
|
-
cancel(request: Promise<any>, message?: string): boolean {
|
|
209
|
-
if (this._restApi.hasCancelToken(request)) {
|
|
210
|
-
return this._restApi.cancel(request, message);
|
|
211
|
-
} else if (this._graphqlApi.hasCancelToken(request)) {
|
|
212
|
-
return this._graphqlApi.cancel(request, message);
|
|
213
|
-
}
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private getInitWithCustomUserAgentDetails(
|
|
218
|
-
init: { [key: string]: any },
|
|
219
|
-
action: ApiAction
|
|
220
|
-
) {
|
|
221
|
-
const customUserAgentDetails: CustomUserAgentDetails = {
|
|
222
|
-
category: Category.API,
|
|
223
|
-
action,
|
|
224
|
-
};
|
|
225
|
-
const initParams = { ...init, customUserAgentDetails };
|
|
226
|
-
return initParams;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Getting endpoint for API
|
|
231
|
-
* @param apiName - The name of the api
|
|
232
|
-
* @return The endpoint of the api
|
|
233
|
-
*/
|
|
234
|
-
async endpoint(apiName: string): Promise<string> {
|
|
235
|
-
return this._restApi.endpoint(apiName);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
60
|
/**
|
|
239
61
|
* to get the operation type
|
|
240
62
|
* @param operation
|
|
@@ -274,6 +96,7 @@ export class InternalAPIClass {
|
|
|
274
96
|
};
|
|
275
97
|
|
|
276
98
|
return this._graphqlApi.graphql(
|
|
99
|
+
Amplify,
|
|
277
100
|
options,
|
|
278
101
|
additionalHeaders,
|
|
279
102
|
apiUserAgentDetails
|
|
@@ -282,4 +105,3 @@ export class InternalAPIClass {
|
|
|
282
105
|
}
|
|
283
106
|
|
|
284
107
|
export const InternalAPI = new InternalAPIClass(null);
|
|
285
|
-
Amplify.register(InternalAPI);
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { GraphQLQuery, GraphQLSubscription } from './types';
|
|
5
|
+
import {
|
|
6
|
+
graphql,
|
|
7
|
+
cancel,
|
|
8
|
+
isCancelError,
|
|
9
|
+
} from '@aws-amplify/api-graphql/internals';
|
|
10
|
+
import {
|
|
11
|
+
AmplifyServer,
|
|
12
|
+
getAmplifyServerContext,
|
|
13
|
+
} from '@aws-amplify/core/internals/adapter-core';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
__amplify,
|
|
17
|
+
V6Client,
|
|
18
|
+
V6ClientSSR,
|
|
19
|
+
ServerClientGenerationParams,
|
|
20
|
+
} from '@aws-amplify/api-graphql';
|
|
21
|
+
|
|
22
|
+
export type {
|
|
23
|
+
GraphQLResult,
|
|
24
|
+
GraphQLReturnType,
|
|
25
|
+
} from '@aws-amplify/api-graphql';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
*
|
|
30
|
+
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
31
|
+
* compatible context object for config and auth fetching.
|
|
32
|
+
*
|
|
33
|
+
* @param params
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export function generateClient<
|
|
37
|
+
T extends Record<any, any> = never,
|
|
38
|
+
ClientType extends V6ClientSSR<T> | V6Client<T> = V6ClientSSR<T>
|
|
39
|
+
>(params: ServerClientGenerationParams): ClientType {
|
|
40
|
+
const client = {
|
|
41
|
+
[__amplify]: params.amplify,
|
|
42
|
+
graphql,
|
|
43
|
+
cancel,
|
|
44
|
+
isCancelError,
|
|
45
|
+
models: {},
|
|
46
|
+
} as any;
|
|
47
|
+
|
|
48
|
+
return client as ClientType;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
get,
|
|
53
|
+
put,
|
|
54
|
+
post,
|
|
55
|
+
del,
|
|
56
|
+
head,
|
|
57
|
+
patch,
|
|
58
|
+
isCancelError,
|
|
59
|
+
} from '@aws-amplify/api-rest/server';
|
package/src/types/index.ts
CHANGED
|
@@ -10,13 +10,6 @@ export {
|
|
|
10
10
|
graphqlOperation,
|
|
11
11
|
GraphQLAuthError,
|
|
12
12
|
GraphQLResult,
|
|
13
|
-
|
|
13
|
+
GraphQLQuery,
|
|
14
|
+
GraphQLSubscription,
|
|
14
15
|
} from '@aws-amplify/api-graphql';
|
|
15
|
-
|
|
16
|
-
// Opaque type used for determining the graphql query type
|
|
17
|
-
declare const queryType: unique symbol;
|
|
18
|
-
|
|
19
|
-
export type GraphQLQuery<T> = T & { readonly [queryType]: 'query' };
|
|
20
|
-
export type GraphQLSubscription<T> = T & {
|
|
21
|
-
readonly [queryType]: 'subscription';
|
|
22
|
-
};
|
package/index.v37.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// the original ts3.7 version declaration file, used by "typesVersions" field in package.json
|
|
2
|
-
// https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#file-redirects
|
|
3
|
-
// can consider using third-party tool like downlevel-dts in the build process to automate this.
|
|
4
|
-
import { API } from './lib-esm/API';
|
|
5
|
-
export { API, APIClass } from './lib-esm/API';
|
|
6
|
-
export {
|
|
7
|
-
graphqlOperation,
|
|
8
|
-
GraphQLAuthError,
|
|
9
|
-
GRAPHQL_AUTH_MODE,
|
|
10
|
-
GraphQLResult,
|
|
11
|
-
} from '@aws-amplify/api-graphql';
|
|
12
|
-
export default API;
|