@aws-amplify/api-graphql 4.0.1-server-generate-client.1e317a1.0 → 4.0.1-ssr-api.df60e41.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/lib/GraphQLAPI.d.ts +1 -1
- package/lib/GraphQLAPI.js +25 -30
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +468 -584
- package/lib/Providers/constants.js +4 -5
- package/lib/index.js +5 -6
- package/lib/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib/internals/InternalGraphQLAPI.js +203 -263
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +5 -8
- package/lib/internals/v6.js +3 -4
- package/lib/tsconfig.tsbuildinfo +6798 -1
- package/lib/types/PubSub.d.ts +2 -2
- package/lib/types/PubSub.js +2 -3
- package/lib/types/index.d.ts +39 -28
- package/lib/types/index.js +3 -4
- package/lib/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib/utils/ConnectionStateMonitor.js +51 -65
- package/lib/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.js +2 -4
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -8
- package/lib/utils/ReconnectionMonitor.js +21 -26
- package/lib/utils/errors/APIError.js +7 -12
- package/lib/utils/errors/assertValidationError.js +4 -5
- package/lib/utils/errors/index.js +4 -5
- package/lib/utils/errors/validation.js +6 -8
- package/lib/utils/index.js +2 -3
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +10 -13
- package/lib/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib/utils/resolveLibraryOptions.js +4 -7
- package/lib-esm/GraphQLAPI.d.ts +1 -1
- package/lib-esm/GraphQLAPI.js +25 -29
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +459 -575
- package/lib-esm/Providers/constants.js +10 -10
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/lib-esm/internals/InternalGraphQLAPI.js +197 -256
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js +0 -1
- package/lib-esm/internals/v6.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +6798 -1
- package/lib-esm/types/PubSub.d.ts +2 -2
- package/lib-esm/types/index.d.ts +39 -28
- package/lib-esm/types/index.js +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +3 -3
- package/lib-esm/utils/ConnectionStateMonitor.js +49 -63
- package/lib-esm/utils/ReachabilityMonitor/index.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.js +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.d.ts +1 -1
- package/lib-esm/utils/ReachabilityMonitor/index.native.js +1 -3
- package/lib-esm/utils/ReconnectionMonitor.js +19 -24
- package/lib-esm/utils/errors/APIError.js +6 -11
- package/lib-esm/utils/errors/assertValidationError.js +2 -2
- package/lib-esm/utils/errors/validation.js +5 -6
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +8 -9
- package/lib-esm/utils/resolveLibraryOptions.d.ts +1 -1
- package/lib-esm/utils/resolveLibraryOptions.js +4 -5
- package/package.json +6 -12
- package/src/GraphQLAPI.ts +6 -1
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +6 -5
- package/src/internals/InternalGraphQLAPI.ts +7 -8
- package/src/internals/index.ts +0 -1
- package/src/types/index.ts +39 -15
- package/lib/internals/APIClient.d.ts +0 -101
- package/lib/internals/APIClient.js +0 -443
- package/lib/internals/generateClient.d.ts +0 -12
- package/lib/internals/generateClient.js +0 -30
- package/lib/internals/generateModelsProperty.d.ts +0 -4
- package/lib/internals/generateModelsProperty.js +0 -169
- package/lib/internals/types.d.ts +0 -10
- package/lib/internals/types.js +0 -2
- package/lib/utils/resolveOwnerFields.d.ts +0 -12
- package/lib/utils/resolveOwnerFields.js +0 -63
- package/lib-esm/internals/APIClient.d.ts +0 -101
- package/lib-esm/internals/APIClient.js +0 -432
- package/lib-esm/internals/generateClient.d.ts +0 -12
- package/lib-esm/internals/generateClient.js +0 -26
- package/lib-esm/internals/generateModelsProperty.d.ts +0 -4
- package/lib-esm/internals/generateModelsProperty.js +0 -165
- package/lib-esm/internals/types.d.ts +0 -10
- package/lib-esm/internals/types.js +0 -1
- package/lib-esm/utils/resolveOwnerFields.d.ts +0 -12
- package/lib-esm/utils/resolveOwnerFields.js +0 -59
- package/src/internals/APIClient.ts +0 -583
- package/src/internals/generateClient.ts +0 -30
- package/src/internals/generateModelsProperty.ts +0 -192
- package/src/internals/types.ts +0 -15
- package/src/utils/resolveOwnerFields.ts +0 -65
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { __awaiter, __generator, __read, __values } from "tslib";
|
|
2
|
-
import { initializeModel, generateGraphQLDocument, buildGraphQLVariables, graphQLOperationsInfo, flattenItems, } from './APIClient';
|
|
3
|
-
import { map } from 'rxjs';
|
|
4
|
-
import { Amplify } from '@aws-amplify/core';
|
|
5
|
-
export function generateModelsProperty(client, params) {
|
|
6
|
-
var e_1, _a;
|
|
7
|
-
var _this = this;
|
|
8
|
-
var _b, _c, _d;
|
|
9
|
-
var models = {};
|
|
10
|
-
// params.config gets populated in SSR only; otherwise we get it from the singleton
|
|
11
|
-
var config = (_b = params.config) !== null && _b !== void 0 ? _b : Amplify.getConfig();
|
|
12
|
-
var modelIntrospection = (_d = (_c = config.API) === null || _c === void 0 ? void 0 : _c.GraphQL) === null || _d === void 0 ? void 0 : _d.modelIntrospection;
|
|
13
|
-
if (!modelIntrospection) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
var _loop_1 = function (model) {
|
|
17
|
-
var name_1 = model.name;
|
|
18
|
-
models[name_1] = {};
|
|
19
|
-
Object.entries(graphQLOperationsInfo).forEach(function (_a) {
|
|
20
|
-
var _b = __read(_a, 2), key = _b[0], operationPrefix = _b[1].operationPrefix;
|
|
21
|
-
var operation = key;
|
|
22
|
-
if (operation === 'LIST') {
|
|
23
|
-
models[name_1][operationPrefix] = function (args) { return __awaiter(_this, void 0, void 0, function () {
|
|
24
|
-
var query, variables, _a, data, nextToken, extensions, _b, key_1, flattenedResult, initialized, error_1;
|
|
25
|
-
return __generator(this, function (_c) {
|
|
26
|
-
switch (_c.label) {
|
|
27
|
-
case 0:
|
|
28
|
-
query = generateGraphQLDocument(modelIntrospection.models, name_1, 'LIST', args);
|
|
29
|
-
variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);
|
|
30
|
-
_c.label = 1;
|
|
31
|
-
case 1:
|
|
32
|
-
_c.trys.push([1, 3, , 4]);
|
|
33
|
-
return [4 /*yield*/, client.graphql({
|
|
34
|
-
query: query,
|
|
35
|
-
variables: variables,
|
|
36
|
-
})];
|
|
37
|
-
case 2:
|
|
38
|
-
_a = (_c.sent()), data = _a.data, nextToken = _a.nextToken, extensions = _a.extensions;
|
|
39
|
-
// flatten response
|
|
40
|
-
if (data !== undefined) {
|
|
41
|
-
_b = __read(Object.keys(data), 1), key_1 = _b[0];
|
|
42
|
-
if (data[key_1].items) {
|
|
43
|
-
flattenedResult = flattenItems(data)[key_1];
|
|
44
|
-
// don't init if custom selection set
|
|
45
|
-
if (args === null || args === void 0 ? void 0 : args.selectionSet) {
|
|
46
|
-
return [2 /*return*/, {
|
|
47
|
-
data: flattenedResult,
|
|
48
|
-
nextToken: nextToken,
|
|
49
|
-
extensions: extensions,
|
|
50
|
-
}];
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
initialized = initializeModel(client, name_1, flattenedResult, modelIntrospection);
|
|
54
|
-
return [2 /*return*/, {
|
|
55
|
-
data: initialized,
|
|
56
|
-
nextToken: nextToken,
|
|
57
|
-
extensions: extensions,
|
|
58
|
-
}];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return [2 /*return*/, {
|
|
62
|
-
data: data[key_1],
|
|
63
|
-
nextToken: nextToken,
|
|
64
|
-
extensions: extensions,
|
|
65
|
-
}];
|
|
66
|
-
}
|
|
67
|
-
return [3 /*break*/, 4];
|
|
68
|
-
case 3:
|
|
69
|
-
error_1 = _c.sent();
|
|
70
|
-
if (error_1.errors) {
|
|
71
|
-
// graphql errors pass through
|
|
72
|
-
return [2 /*return*/, error_1];
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// non-graphql errors re re-thrown
|
|
76
|
-
throw error_1;
|
|
77
|
-
}
|
|
78
|
-
return [3 /*break*/, 4];
|
|
79
|
-
case 4: return [2 /*return*/];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}); };
|
|
83
|
-
}
|
|
84
|
-
else if (['ONCREATE', 'ONUPDATE', 'ONDELETE'].includes(operation)) {
|
|
85
|
-
models[name_1][operationPrefix] = function (arg, options) {
|
|
86
|
-
var query = generateGraphQLDocument(modelIntrospection.models, name_1, operation);
|
|
87
|
-
var variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
|
|
88
|
-
var observable = client.graphql({
|
|
89
|
-
query: query,
|
|
90
|
-
variables: variables,
|
|
91
|
-
});
|
|
92
|
-
return observable.pipe(map(function (value) {
|
|
93
|
-
var _a = __read(Object.keys(value.data), 1), key = _a[0];
|
|
94
|
-
return value.data[key];
|
|
95
|
-
}));
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
models[name_1][operationPrefix] = function (arg, options) { return __awaiter(_this, void 0, void 0, function () {
|
|
100
|
-
var query, variables, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;
|
|
101
|
-
return __generator(this, function (_d) {
|
|
102
|
-
switch (_d.label) {
|
|
103
|
-
case 0:
|
|
104
|
-
query = generateGraphQLDocument(modelIntrospection.models, name_1, operation, options);
|
|
105
|
-
variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
|
|
106
|
-
_d.label = 1;
|
|
107
|
-
case 1:
|
|
108
|
-
_d.trys.push([1, 3, , 4]);
|
|
109
|
-
return [4 /*yield*/, client.graphql({
|
|
110
|
-
query: query,
|
|
111
|
-
variables: variables,
|
|
112
|
-
})];
|
|
113
|
-
case 2:
|
|
114
|
-
_a = (_d.sent()), data = _a.data, extensions = _a.extensions;
|
|
115
|
-
// flatten response
|
|
116
|
-
if (data !== undefined) {
|
|
117
|
-
_b = __read(Object.keys(data), 1), key_2 = _b[0];
|
|
118
|
-
flattenedResult = flattenItems(data)[key_2];
|
|
119
|
-
if (options === null || options === void 0 ? void 0 : options.selectionSet) {
|
|
120
|
-
return [2 /*return*/, { data: flattenedResult, extensions: extensions }];
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
_c = __read(initializeModel(client, name_1, [flattenedResult], modelIntrospection), 1), initialized = _c[0];
|
|
124
|
-
return [2 /*return*/, { data: initialized, extensions: extensions }];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return [2 /*return*/, { data: null, extensions: extensions }];
|
|
129
|
-
}
|
|
130
|
-
return [3 /*break*/, 4];
|
|
131
|
-
case 3:
|
|
132
|
-
error_2 = _d.sent();
|
|
133
|
-
if (error_2.errors) {
|
|
134
|
-
// graphql errors pass through
|
|
135
|
-
return [2 /*return*/, error_2];
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
// non-graphql errors re re-thrown
|
|
139
|
-
throw error_2;
|
|
140
|
-
}
|
|
141
|
-
return [3 /*break*/, 4];
|
|
142
|
-
case 4: return [2 /*return*/];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}); };
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
try {
|
|
150
|
-
// TODO: refactor this to use separate methods for each CRUDL.
|
|
151
|
-
// Doesn't make sense to gen the methods dynamically given the different args and return values
|
|
152
|
-
for (var _e = __values(Object.values(modelIntrospection.models)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
153
|
-
var model = _f.value;
|
|
154
|
-
_loop_1(model);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
158
|
-
finally {
|
|
159
|
-
try {
|
|
160
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
161
|
-
}
|
|
162
|
-
finally { if (e_1) throw e_1.error; }
|
|
163
|
-
}
|
|
164
|
-
return models;
|
|
165
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
-
/**
|
|
3
|
-
* @private
|
|
4
|
-
*
|
|
5
|
-
* The knobs available for configuring `generateClient` internally.
|
|
6
|
-
*/
|
|
7
|
-
export type ClientGenerationParams = {
|
|
8
|
-
amplify: AmplifyClassV6 | ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>);
|
|
9
|
-
config?: object;
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
-
type GraphQLConfig = Exclude<ResourcesConfig['API'], undefined>['GraphQL'];
|
|
3
|
-
type ModelIntrospectionSchema = Exclude<Exclude<GraphQLConfig, undefined>['modelIntrospection'], undefined>;
|
|
4
|
-
type Model = ModelIntrospectionSchema['models'][string];
|
|
5
|
-
/**
|
|
6
|
-
* Given an introspection schema model, returns all owner fields.
|
|
7
|
-
*
|
|
8
|
-
* @param model Model from an introspection schema
|
|
9
|
-
* @returns List of owner field names
|
|
10
|
-
*/
|
|
11
|
-
export declare function resolveOwnerFields(model: Model): string[];
|
|
12
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { __values } from "tslib";
|
|
2
|
-
/**
|
|
3
|
-
* Given an introspection schema model, returns all owner fields.
|
|
4
|
-
*
|
|
5
|
-
* @param model Model from an introspection schema
|
|
6
|
-
* @returns List of owner field names
|
|
7
|
-
*/
|
|
8
|
-
export function resolveOwnerFields(model) {
|
|
9
|
-
var e_1, _a, e_2, _b;
|
|
10
|
-
var ownerFields = new Set();
|
|
11
|
-
try {
|
|
12
|
-
for (var _c = __values(model.attributes || []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
13
|
-
var attr = _d.value;
|
|
14
|
-
if (isAuthAttribute(attr)) {
|
|
15
|
-
try {
|
|
16
|
-
for (var _e = (e_2 = void 0, __values(attr.properties.rules)), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
17
|
-
var rule = _f.value;
|
|
18
|
-
if (rule.allow === 'owner') {
|
|
19
|
-
ownerFields.add(rule.ownerField || 'owner');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
24
|
-
finally {
|
|
25
|
-
try {
|
|
26
|
-
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
27
|
-
}
|
|
28
|
-
finally { if (e_2) throw e_2.error; }
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
34
|
-
finally {
|
|
35
|
-
try {
|
|
36
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
37
|
-
}
|
|
38
|
-
finally { if (e_1) throw e_1.error; }
|
|
39
|
-
}
|
|
40
|
-
return Array.from(ownerFields);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Type guard that identifies an auth attribute with an attached rules list that
|
|
44
|
-
* specifies an `allow` attribute at a minimum.
|
|
45
|
-
*
|
|
46
|
-
* @param attribute Any object. Ideally a model introspection schema model attribute
|
|
47
|
-
* @returns True if given object is an auth attribute
|
|
48
|
-
*/
|
|
49
|
-
function isAuthAttribute(attribute) {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'auth') {
|
|
52
|
-
if (typeof (attribute === null || attribute === void 0 ? void 0 : attribute.properties) === 'object') {
|
|
53
|
-
if (Array.isArray((_a = attribute === null || attribute === void 0 ? void 0 : attribute.properties) === null || _a === void 0 ? void 0 : _a.rules)) {
|
|
54
|
-
return ((_b = attribute === null || attribute === void 0 ? void 0 : attribute.properties) === null || _b === void 0 ? void 0 : _b.rules).every(function (rule) { return !!rule.allow; });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|