@aws-amplify/data-schema 0.14.4 → 0.14.6
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-esm/index.d.ts +1 -0
- package/lib-esm/index.d.ts.map +1 -0
- package/lib-esm/src/Authorization.d.ts +1 -0
- package/lib-esm/src/Authorization.d.ts.map +1 -0
- package/lib-esm/src/ClientSchema.d.ts +1 -0
- package/lib-esm/src/ClientSchema.d.ts.map +1 -0
- package/lib-esm/src/CombineSchema.d.ts +1 -0
- package/lib-esm/src/CombineSchema.d.ts.map +1 -0
- package/lib-esm/src/CombineSchema.js +17 -0
- package/lib-esm/src/CustomOperation.d.ts +3 -2
- package/lib-esm/src/CustomOperation.d.ts.map +1 -0
- package/lib-esm/src/CustomType.d.ts +1 -0
- package/lib-esm/src/CustomType.d.ts.map +1 -0
- package/lib-esm/src/EnumType.d.ts +1 -0
- package/lib-esm/src/EnumType.d.ts.map +1 -0
- package/lib-esm/src/Handler.d.ts +1 -0
- package/lib-esm/src/Handler.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/CustomOperations.d.ts +17 -12
- package/lib-esm/src/MappedTypes/CustomOperations.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts +1 -0
- package/lib-esm/src/MappedTypes/ExtractNonModelTypes.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts +1 -0
- package/lib-esm/src/MappedTypes/ForeignKeys.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts +1 -0
- package/lib-esm/src/MappedTypes/ImplicitFieldInjector.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts +1 -0
- package/lib-esm/src/MappedTypes/MapSecondaryIndexes.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts +1 -0
- package/lib-esm/src/MappedTypes/ModelMetadata.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts +3 -1
- package/lib-esm/src/MappedTypes/ResolveFieldProperties.d.ts.map +1 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.d.ts +1 -0
- package/lib-esm/src/MappedTypes/ResolveSchema.d.ts.map +1 -0
- package/lib-esm/src/ModelField.d.ts +1 -0
- package/lib-esm/src/ModelField.d.ts.map +1 -0
- package/lib-esm/src/ModelIndex.d.ts +1 -0
- package/lib-esm/src/ModelIndex.d.ts.map +1 -0
- package/lib-esm/src/ModelRelationalField.d.ts +1 -0
- package/lib-esm/src/ModelRelationalField.d.ts.map +1 -0
- package/lib-esm/src/ModelSchema.d.ts +1 -0
- package/lib-esm/src/ModelSchema.d.ts.map +1 -0
- package/lib-esm/src/ModelType.d.ts +1 -0
- package/lib-esm/src/ModelType.d.ts.map +1 -0
- package/lib-esm/src/RefType.d.ts +1 -0
- package/lib-esm/src/RefType.d.ts.map +1 -0
- package/lib-esm/src/SchemaProcessor.d.ts +1 -0
- package/lib-esm/src/SchemaProcessor.d.ts.map +1 -0
- package/lib-esm/src/SchemaProcessor.js +68 -45
- package/lib-esm/src/index.d.ts +1 -0
- package/lib-esm/src/index.d.ts.map +1 -0
- package/lib-esm/src/internals/index.d.ts +1 -0
- package/lib-esm/src/internals/index.d.ts.map +1 -0
- package/lib-esm/src/util/Brand.d.ts +1 -0
- package/lib-esm/src/util/Brand.d.ts.map +1 -0
- package/lib-esm/src/util/IndexLimit.d.ts +1 -0
- package/lib-esm/src/util/IndexLimit.d.ts.map +1 -0
- package/lib-esm/src/util/SpreadTuple.d.ts +1 -0
- package/lib-esm/src/util/SpreadTuple.d.ts.map +1 -0
- package/lib-esm/src/util/index.d.ts +1 -0
- package/lib-esm/src/util/index.d.ts.map +1 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
|
@@ -183,19 +183,51 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
|
|
|
183
183
|
const { authString } = isCustom
|
|
184
184
|
? calculateCustomAuth(authorization)
|
|
185
185
|
: calculateAuth(authorization);
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param returnType The return type from the `data` field of a customer operation.
|
|
189
|
+
* @param refererTypeName The type the refers {@link returnType} by `a.ref()`.
|
|
190
|
+
* @param shouldAddCustomTypeToImplicitModels A flag indicates wether it should push
|
|
191
|
+
* the return type resolved CustomType to the `implicitModels` list.
|
|
192
|
+
* @returns
|
|
193
|
+
*/
|
|
194
|
+
const resolveReturnTypeNameFromReturnType = (returnType, { refererTypeName, shouldAddCustomTypeToImplicitModels = true, }) => {
|
|
195
|
+
if (isRefField(returnType)) {
|
|
196
|
+
return refFieldToGql(returnType?.data);
|
|
197
|
+
}
|
|
198
|
+
else if (isCustomType(returnType)) {
|
|
199
|
+
const returnTypeName = `${capitalize(refererTypeName)}ReturnType`;
|
|
200
|
+
if (shouldAddCustomTypeToImplicitModels) {
|
|
201
|
+
implicitModels.push([returnTypeName, returnType]);
|
|
202
|
+
}
|
|
203
|
+
return returnTypeName;
|
|
204
|
+
}
|
|
205
|
+
else if (isScalarField(returnType)) {
|
|
206
|
+
return scalarFieldToGql(returnType?.data);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw new Error(`Unrecognized return type on ${typeName}`);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
186
212
|
let returnTypeName;
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
213
|
+
if (opType === 'Subscription' && returnType === null) {
|
|
214
|
+
// up to this point, we've validated that each subscription resource resolves
|
|
215
|
+
// the same return type, so it's safe to use subscriptionSource[0] here.
|
|
216
|
+
const { type, def } = getRefType(subscriptionSource[0].data.link, typeName);
|
|
217
|
+
if (type === 'CustomOperation') {
|
|
218
|
+
returnTypeName = resolveReturnTypeNameFromReturnType(def.data.returnType, {
|
|
219
|
+
refererTypeName: subscriptionSource[0].data.link,
|
|
220
|
+
shouldAddCustomTypeToImplicitModels: false,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
returnTypeName = refFieldToGql(subscriptionSource[0].data);
|
|
225
|
+
}
|
|
196
226
|
}
|
|
197
227
|
else {
|
|
198
|
-
|
|
228
|
+
returnTypeName = resolveReturnTypeNameFromReturnType(returnType, {
|
|
229
|
+
refererTypeName: typeName,
|
|
230
|
+
});
|
|
199
231
|
}
|
|
200
232
|
if (Object.keys(fieldArgs).length > 0) {
|
|
201
233
|
const { gqlFields, models } = processFields(typeName, fieldArgs, {}, {});
|
|
@@ -875,7 +907,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
875
907
|
};
|
|
876
908
|
};
|
|
877
909
|
function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
|
|
878
|
-
const { functionRef, handlers, typeName: opType, subscriptionSource,
|
|
910
|
+
const { functionRef, handlers, typeName: opType, subscriptionSource, } = typeDef.data;
|
|
879
911
|
// TODO: remove `functionRef` after deprecating
|
|
880
912
|
const handlerConfigured = functionRef !== null || handlers?.length;
|
|
881
913
|
const authConfigured = authRules.length > 0;
|
|
@@ -902,52 +934,43 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
|
|
|
902
934
|
if (subscriptionSource.length < 1) {
|
|
903
935
|
throw new Error(`${typeName} is missing a mutation source. Custom subscriptions must reference a mutation source via subscription().for(a.ref('ModelOrOperationName')) `);
|
|
904
936
|
}
|
|
905
|
-
|
|
937
|
+
let expectedReturnType;
|
|
938
|
+
for (const source of subscriptionSource) {
|
|
906
939
|
const sourceName = source.data.link;
|
|
907
940
|
const { type, def } = getRefType(sourceName, typeName);
|
|
908
941
|
if (type !== 'Model' && source.data.mutationOperations.length > 0) {
|
|
909
942
|
throw new Error(`Invalid subscription definition. .mutations() modifier can only be used with a Model ref. ${typeName} is referencing ${type}`);
|
|
910
943
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
throw new Error(`Invalid subscription definition. .for() can only reference a mutation. ${typeName} is referencing ${sourceName} which is a ${def.data.typeName}`);
|
|
916
|
-
}
|
|
917
|
-
// Ensure subscription return type matches the return type of triggering mutation(s)
|
|
918
|
-
// TODO: when we remove .returns() for custom subscriptions, minor changes will be needed here. Instead of comparing subscriptionSource return val
|
|
919
|
-
// to a root returnType, we'll need to ensure that each subscriptionSource has the same return type
|
|
920
|
-
if (returnType.data.type === 'ref') {
|
|
921
|
-
const returnTypeName = returnType.data.link;
|
|
922
|
-
if (type === 'Model') {
|
|
923
|
-
if (returnTypeName !== sourceName ||
|
|
924
|
-
returnType.data.array !== source.data.array) {
|
|
925
|
-
throw new Error(`Invalid subscription definition. Subscription return type must match the return type of the mutation triggering it. ${typeName} is referencing ${sourceName} which has a different return type`);
|
|
926
|
-
}
|
|
944
|
+
let resolvedReturnType;
|
|
945
|
+
if (type === 'Model') {
|
|
946
|
+
if (source.data.mutationOperations.length === 0) {
|
|
947
|
+
throw new Error(`Invalid subscription definition. .mutations() modifier must be used with a Model ref subscription source. ${typeName} is referencing ${sourceName} without specifying a mutation`);
|
|
927
948
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
const customOperationReturnTypeArray = def.data.returnType.data.array;
|
|
931
|
-
if (returnTypeName !== customOperationReturnType ||
|
|
932
|
-
returnType.data.array !== customOperationReturnTypeArray) {
|
|
933
|
-
throw new Error(`Invalid subscription definition. Subscription return type must match the return type of the mutation triggering it. ${typeName} is referencing ${sourceName} which has a different return type`);
|
|
934
|
-
}
|
|
949
|
+
else {
|
|
950
|
+
resolvedReturnType = def;
|
|
935
951
|
}
|
|
936
952
|
}
|
|
937
|
-
|
|
938
|
-
if (
|
|
939
|
-
throw new Error(`Invalid subscription definition.
|
|
953
|
+
if (type === 'CustomOperation') {
|
|
954
|
+
if (def.data.typeName !== 'Mutation') {
|
|
955
|
+
throw new Error(`Invalid subscription definition. .for() can only reference a mutation. ${typeName} is referencing ${sourceName} which is a ${def.data.typeName}`);
|
|
940
956
|
}
|
|
941
|
-
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
957
|
+
else {
|
|
958
|
+
const returnType = def.data.returnType;
|
|
959
|
+
if (isRefField(returnType)) {
|
|
960
|
+
({ def: resolvedReturnType } = getRefType(returnType.data.link, typeName));
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
resolvedReturnType = returnType;
|
|
947
964
|
}
|
|
948
965
|
}
|
|
949
966
|
}
|
|
950
|
-
|
|
967
|
+
expectedReturnType = expectedReturnType ?? resolvedReturnType;
|
|
968
|
+
// As the return types are resolved from the root `schema` object and they should
|
|
969
|
+
// not be mutated, we compare by references here.
|
|
970
|
+
if (expectedReturnType !== resolvedReturnType) {
|
|
971
|
+
throw new Error(`Invalid subscription definition. .for() can only reference resources that have the same return type. ${typeName} is referencing resources that have different return types.`);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
951
974
|
}
|
|
952
975
|
}
|
|
953
976
|
const isCustomHandler = (handler) => {
|
package/lib-esm/src/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ import { enumType } from './EnumType';
|
|
|
10
10
|
import { query, mutation, subscription } from './CustomOperation';
|
|
11
11
|
import { handler } from './Handler';
|
|
12
12
|
export { schema, combine, model, ref, customType, enumType as enum, query, mutation, subscription, hasOne, hasMany, belongsTo, manyToMany, allow, id, string, integer, float, boolean, date, time, datetime, timestamp, email, json, phone, url, ipAddress, handler, };
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACL,EAAE,EACF,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,GAAG,EACH,UAAU,EACV,QAAQ,IAAI,IAAI,EAChB,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,OAAO,EACP,SAAS,EACT,UAAU,EACV,KAAK,EACL,EAAE,EACF,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,SAAS,EACT,OAAO,GACR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internals/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../../src/util/Brand.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,WAAW,eAAkB,CAAC;AAEpC;;;;;;;;;GASG;AACH,MAAM,MAAM,KAAK,CAAC,QAAQ,SAAS,MAAM,IAAI;IAC3C,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,QAAQ,SAAS,MAAM,EAC3C,KAAK,EAAE,QAAQ,GACd,KAAK,CAAC,QAAQ,CAAC,CAIjB;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,UAE9C"}
|
|
@@ -5,3 +5,4 @@
|
|
|
5
5
|
* @typeParam N - The number of literal values to include
|
|
6
6
|
*/
|
|
7
7
|
export type IndexLimitUnion<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : IndexLimitUnion<N, [...Result, `${Result['length']}`]>;
|
|
8
|
+
//# sourceMappingURL=IndexLimit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexLimit.d.ts","sourceRoot":"","sources":["../../../src/util/IndexLimit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,MAAM,EAChB,MAAM,SAAS,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,IAChC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,GAC1B,MAAM,GACN,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpreadTuple.d.ts","sourceRoot":"","sources":["../../../src/util/SpreadTuple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GACnE,CAAC,GACD,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAC7B,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAClB,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|