@aws-amplify/data-schema 1.9.2 → 1.10.1

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.
Files changed (65) hide show
  1. package/dist/cjs/{ModelRelationalField.js → ModelRelationshipField.js} +8 -5
  2. package/dist/cjs/ModelRelationshipField.js.map +1 -0
  3. package/dist/cjs/SchemaProcessor.js +31 -24
  4. package/dist/cjs/SchemaProcessor.js.map +1 -1
  5. package/dist/cjs/a.js +4 -4
  6. package/dist/cjs/a.js.map +1 -1
  7. package/dist/cjs/ai/ConversationSchemaTypes.js +7 -5
  8. package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -1
  9. package/dist/cjs/runtime/internals/APIClient.js +8 -8
  10. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  11. package/dist/esm/Authorization.d.ts +7 -0
  12. package/dist/esm/ClientSchema/Core/ClientModel.d.ts +3 -3
  13. package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +5 -5
  14. package/dist/esm/CustomOperation.d.ts +7 -0
  15. package/dist/esm/CustomType.d.ts +5 -0
  16. package/dist/esm/EnumType.d.ts +5 -0
  17. package/dist/esm/Handler.d.ts +1 -1
  18. package/dist/esm/MappedTypes/ModelMetadata.d.ts +5 -5
  19. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +9 -9
  20. package/dist/esm/MappedTypes/ResolveSchema.d.ts +3 -3
  21. package/dist/esm/ModelField.d.ts +5 -0
  22. package/dist/esm/{ModelRelationalField.d.ts → ModelRelationshipField.d.ts} +31 -14
  23. package/dist/esm/{ModelRelationalField.mjs → ModelRelationshipField.mjs} +8 -5
  24. package/dist/esm/ModelRelationshipField.mjs.map +1 -0
  25. package/dist/esm/ModelSchema.d.ts +9 -3
  26. package/dist/esm/ModelType.d.ts +18 -5
  27. package/dist/esm/RefType.d.ts +6 -0
  28. package/dist/esm/SchemaProcessor.mjs +23 -16
  29. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  30. package/dist/esm/a.d.ts +1 -1
  31. package/dist/esm/a.mjs +1 -1
  32. package/dist/esm/a.mjs.map +1 -1
  33. package/dist/esm/ai/ConversationSchemaTypes.mjs +7 -5
  34. package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -1
  35. package/dist/esm/ai/ConversationType.d.ts +6 -2
  36. package/dist/esm/index.d.ts +9 -0
  37. package/dist/esm/runtime/client/index.d.ts +3 -3
  38. package/dist/esm/runtime/internals/APIClient.mjs +8 -8
  39. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  40. package/dist/meta/cjs.tsbuildinfo +1 -1
  41. package/package.json +1 -1
  42. package/src/Authorization.ts +7 -0
  43. package/src/ClientSchema/Core/ClientModel.ts +3 -3
  44. package/src/ClientSchema/utilities/ResolveField.ts +11 -12
  45. package/src/CustomOperation.ts +7 -0
  46. package/src/CustomType.ts +8 -3
  47. package/src/EnumType.ts +5 -0
  48. package/src/Handler.ts +1 -1
  49. package/src/MappedTypes/ModelMetadata.ts +7 -7
  50. package/src/MappedTypes/ResolveFieldProperties.ts +13 -13
  51. package/src/MappedTypes/ResolveSchema.ts +5 -5
  52. package/src/ModelField.ts +5 -3
  53. package/src/{ModelRelationalField.ts → ModelRelationshipField.ts} +55 -35
  54. package/src/ModelSchema.ts +16 -6
  55. package/src/ModelType.ts +21 -8
  56. package/src/RefType.ts +6 -0
  57. package/src/SchemaProcessor.ts +45 -25
  58. package/src/a.ts +1 -1
  59. package/src/ai/ConversationSchemaTypes.ts +8 -6
  60. package/src/ai/ConversationType.ts +11 -2
  61. package/src/index.ts +14 -0
  62. package/src/runtime/client/index.ts +7 -3
  63. package/src/runtime/internals/APIClient.ts +8 -8
  64. package/dist/cjs/ModelRelationalField.js.map +0 -1
  65. package/dist/esm/ModelRelationalField.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { ModelFieldType, string, __generated } from './ModelField.mjs';
2
- import { ModelRelationshipTypes } from './ModelRelationalField.mjs';
2
+ import { ModelRelationshipTypes } from './ModelRelationshipField.mjs';
3
3
  import { accessData, accessSchemaData } from './Authorization.mjs';
4
4
  import { CustomOperationNames } from './CustomOperation.mjs';
5
5
  import { getBrand, brandSymbol } from './util/Brand.mjs';
@@ -158,7 +158,9 @@ function transformFunctionHandler(handlers, functionFieldName) {
158
158
  else if (typeof handlerData.handler.getInstance === 'function') {
159
159
  const fnName = `Fn${capitalize(functionFieldName)}${idx === 0 ? '' : `${idx + 1}`}`;
160
160
  lambdaFunctionDefinition[fnName] = handlerData.handler;
161
- const invocationTypeArg = handlerData.invocationType === 'Event' ? ', invocationType: Event)' : ')';
161
+ const invocationTypeArg = handlerData.invocationType === 'Event'
162
+ ? ', invocationType: Event)'
163
+ : ')';
162
164
  gqlHandlerContent += `@function(name: "${fnName}"${invocationTypeArg} `;
163
165
  }
164
166
  else {
@@ -837,11 +839,12 @@ const schemaPreprocessor = (schema) => {
837
839
  // - it only happens once per schema
838
840
  // - downstream validation based on `getRefTypeForSchema` finds the EventInvocationResponse type
839
841
  const containsAsyncLambdaCustomOperation = Object.entries(schema.data.types).find(([_, typeDef]) => {
840
- return isCustomOperation(typeDef)
841
- && finalHandlerIsAsyncFunctionHandler(typeDef.data.handlers);
842
+ return (isCustomOperation(typeDef) &&
843
+ finalHandlerIsAsyncFunctionHandler(typeDef.data.handlers));
842
844
  });
843
845
  if (containsAsyncLambdaCustomOperation) {
844
- schema.data.types['EventInvocationResponse'] = eventInvocationResponseCustomType;
846
+ schema.data.types['EventInvocationResponse'] =
847
+ eventInvocationResponseCustomType;
845
848
  }
846
849
  const topLevelTypes = sortTopLevelTypes(Object.entries(schema.data.types));
847
850
  const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
@@ -1019,7 +1022,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
1019
1022
  (opType === 'Query' || opType === 'Mutation' || opType === 'Generation')) {
1020
1023
  // TODO: There should be a more elegant and readable way to handle this check.
1021
1024
  // Maybe it's not even necessary anymore since we're the setting returnType in the handler() method.
1022
- if (!handlers || handlers.length === 0 || handlers[handlers.length - 1][brandSymbol] !== 'asyncFunctionHandler') {
1025
+ if (!handlers ||
1026
+ handlers.length === 0 ||
1027
+ handlers[handlers.length - 1][brandSymbol] !== 'asyncFunctionHandler') {
1023
1028
  const typeDescription = opType === 'Generation' ? 'Generation Route' : `Custom ${opType}`;
1024
1029
  throw new Error(`Invalid ${typeDescription} definition. A ${typeDescription} must include a return type. ${typeName} has no return type specified.`);
1025
1030
  }
@@ -1077,10 +1082,12 @@ const isCustomHandler = (handler) => {
1077
1082
  return Array.isArray(handler) && getBrand(handler[0]) === 'customHandler';
1078
1083
  };
1079
1084
  const isFunctionHandler = (handler) => {
1080
- return Array.isArray(handler) && ['functionHandler', 'asyncFunctionHandler'].includes(getBrand(handler[0]));
1085
+ return (Array.isArray(handler) &&
1086
+ ['functionHandler', 'asyncFunctionHandler'].includes(getBrand(handler[0])));
1081
1087
  };
1082
1088
  const finalHandlerIsAsyncFunctionHandler = (handler) => {
1083
- return Array.isArray(handler) && getBrand(handler[handler.length - 1]) === 'asyncFunctionHandler';
1089
+ return (Array.isArray(handler) &&
1090
+ getBrand(handler[handler.length - 1]) === 'asyncFunctionHandler');
1084
1091
  };
1085
1092
  const normalizeDataSourceName = (dataSource) => {
1086
1093
  // default data source
@@ -1143,11 +1150,11 @@ const eventInvocationResponseCustomType = {
1143
1150
  required: true,
1144
1151
  array: false,
1145
1152
  arrayRequired: false,
1146
- }
1147
- }
1153
+ },
1154
+ },
1148
1155
  },
1149
- type: 'customType'
1150
- }
1156
+ type: 'customType',
1157
+ },
1151
1158
  };
1152
1159
  function transformCustomOperations(typeDef, typeName, authRules, databaseType, getRefType) {
1153
1160
  const { typeName: opType, handlers } = typeDef.data;
@@ -1239,8 +1246,8 @@ function validateRelationships(typeName, record, getInternalModel) {
1239
1246
  // Create a structure representing the relationship for validation.
1240
1247
  const relationship = getModelRelationship(typeName, { name: name, def: field.data }, getInternalModel);
1241
1248
  // Validate that the references defined in the relationship follow the
1242
- // relational definition rules.
1243
- validateRelationalReferences(relationship);
1249
+ // relationship definition rules.
1250
+ validateRelationshipReferences(relationship);
1244
1251
  }
1245
1252
  }
1246
1253
  /**
@@ -1266,7 +1273,7 @@ function describeConnectFieldRelationship(sourceField, sourceModelName) {
1266
1273
  * Validates that the types of child model's reference fields match the types of the parent model's identifier fields.
1267
1274
  * @param relationship The {@link ModelRelationship} to validate.
1268
1275
  */
1269
- function validateRelationalReferences(relationship) {
1276
+ function validateRelationshipReferences(relationship) {
1270
1277
  const { parent, parentConnectionField, child, childConnectionField, references, } = relationship;
1271
1278
  const parentIdentifiers = getIndentifierTypes(parent);
1272
1279
  const childReferenceTypes = [];
@@ -1373,7 +1380,7 @@ function getAssociatedConnectionField(sourceModelName, sourceConnectionField, as
1373
1380
  }
1374
1381
  // In order to find that associated connection field, we need to do some validation that we'll depend on further downstream.
1375
1382
  // 1. Field type matches the source model's type.
1376
- // 2. A valid counterpart relational modifier is defined on the field. See `associatedRelationshipTypes` for more information.
1383
+ // 2. A valid counterpart relationship modifier is defined on the field. See `associatedRelationshipTypes` for more information.
1377
1384
  // 3. The reference arguments provided to the field match (element count + string comparison) references passed to the source connection field.
1378
1385
  return (connectionField.data.relatedModel === sourceModelName &&
1379
1386
  associatedRelationshipOptions.includes(connectionField.data.type) &&