@aws-amplify/data-schema 1.10.2 → 1.12.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/dist/cjs/SchemaProcessor.js +40 -5
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js +21 -0
- package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js.map +1 -0
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +1 -0
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +2 -0
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -1
- package/dist/esm/ModelType.d.ts +3 -3
- package/dist/esm/SchemaProcessor.mjs +40 -5
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/ai/ConversationType.d.ts +16 -1
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.d.ts +3 -0
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs +19 -0
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs.map +1 -0
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.d.ts +2 -1
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs +1 -0
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +2 -0
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ModelType.ts +2 -7
- package/src/SchemaProcessor.ts +55 -1
- package/src/ai/ConversationType.ts +25 -2
- package/src/runtime/internals/ai/createUpdateConversationFunction.ts +58 -0
- package/src/runtime/internals/ai/getCustomUserAgentDetails.ts +1 -0
- package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +9 -0
|
@@ -69,6 +69,9 @@ function isScalarField(field) {
|
|
|
69
69
|
function isRefField(field) {
|
|
70
70
|
return isRefFieldDef(field?.data);
|
|
71
71
|
}
|
|
72
|
+
function canGenerateFieldType(fieldType) {
|
|
73
|
+
return fieldType === 'Int';
|
|
74
|
+
}
|
|
72
75
|
function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
|
|
73
76
|
const { fieldType, required, array, arrayRequired, default: _default, } = fieldDef;
|
|
74
77
|
let field = fieldType;
|
|
@@ -86,6 +89,9 @@ function scalarFieldToGql(fieldDef, identifier, secondaryIndexes = []) {
|
|
|
86
89
|
for (const index of secondaryIndexes) {
|
|
87
90
|
field += ` ${index}`;
|
|
88
91
|
}
|
|
92
|
+
if (_default === ModelField_1.__generated) {
|
|
93
|
+
field += ` @default`;
|
|
94
|
+
}
|
|
89
95
|
return field;
|
|
90
96
|
}
|
|
91
97
|
if (required === true) {
|
|
@@ -614,12 +620,40 @@ function processFieldLevelAuthRules(fields, authFields) {
|
|
|
614
620
|
}
|
|
615
621
|
return fieldLevelAuthRules;
|
|
616
622
|
}
|
|
617
|
-
function
|
|
623
|
+
function validateDBGeneration(fields, databaseEngine) {
|
|
624
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
625
|
+
const _default = fieldDef.data?.default;
|
|
626
|
+
const fieldType = fieldDef.data?.fieldType;
|
|
627
|
+
const isGenerated = _default === ModelField_1.__generated;
|
|
628
|
+
if (isGenerated && databaseEngine !== 'postgresql') {
|
|
629
|
+
throw new Error(`Invalid field definition for ${fieldName}. DB-generated fields are only supported with PostgreSQL data sources.`);
|
|
630
|
+
}
|
|
631
|
+
if (isGenerated && !canGenerateFieldType(fieldType)) {
|
|
632
|
+
throw new Error(`Incompatible field type. Field type ${fieldType} in field ${fieldName} cannot be configured as a DB-generated field.`);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function validateNullableIdentifiers(fields, identifier) {
|
|
637
|
+
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
638
|
+
const fieldType = fieldDef.data?.fieldType;
|
|
639
|
+
const required = fieldDef.data?.required;
|
|
640
|
+
const _default = fieldDef.data?.default;
|
|
641
|
+
const isGenerated = _default === ModelField_1.__generated;
|
|
642
|
+
if (identifier !== undefined && identifier.includes(fieldName)) {
|
|
643
|
+
if (!required && fieldType !== 'ID' && !isGenerated) {
|
|
644
|
+
throw new Error(`Invalid identifier definition. Field ${fieldName} cannot be used in the identifier. Identifiers must reference required or DB-generated fields)`);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
function processFields(typeName, fields, impliedFields, fieldLevelAuthRules, identifier, partitionKey, secondaryIndexes = {}, databaseEngine = 'dynamodb') {
|
|
618
650
|
const gqlFields = [];
|
|
619
651
|
// stores nested, field-level type definitions (custom types and enums)
|
|
620
652
|
// the need to be hoisted to top-level schema types and processed accordingly
|
|
621
653
|
const implicitTypes = [];
|
|
622
654
|
validateImpliedFields(fields, impliedFields);
|
|
655
|
+
validateDBGeneration(fields, databaseEngine);
|
|
656
|
+
validateNullableIdentifiers(fields, identifier);
|
|
623
657
|
for (const [fieldName, fieldDef] of Object.entries(fields)) {
|
|
624
658
|
const fieldAuth = fieldLevelAuthRules[fieldName]
|
|
625
659
|
? ` ${fieldLevelAuthRules[fieldName]}`
|
|
@@ -834,7 +868,8 @@ const schemaPreprocessor = (schema) => {
|
|
|
834
868
|
const jsFunctions = [];
|
|
835
869
|
const lambdaFunctions = {};
|
|
836
870
|
const customSqlDataSourceStrategies = [];
|
|
837
|
-
const
|
|
871
|
+
const databaseEngine = schema.data.configuration.database.engine;
|
|
872
|
+
const databaseType = databaseEngine === 'dynamodb'
|
|
838
873
|
? 'dynamodb'
|
|
839
874
|
: 'sql';
|
|
840
875
|
const staticSchema = databaseType === 'sql';
|
|
@@ -877,7 +912,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
877
912
|
}
|
|
878
913
|
const authFields = {};
|
|
879
914
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fieldAuthApplicableFields, authFields);
|
|
880
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules);
|
|
915
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, undefined, undefined, undefined, databaseEngine);
|
|
881
916
|
topLevelTypes.push(...implicitTypes);
|
|
882
917
|
const joined = gqlFields.join('\n ');
|
|
883
918
|
const model = `type ${typeName} ${customAuth}\n{\n ${joined}\n}`;
|
|
@@ -934,7 +969,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
934
969
|
const { authString, authFields } = calculateAuth(mostRelevantAuthRules);
|
|
935
970
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
936
971
|
validateStaticFields(fields, authFields);
|
|
937
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey);
|
|
972
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, undefined, databaseEngine);
|
|
938
973
|
topLevelTypes.push(...implicitTypes);
|
|
939
974
|
const joined = gqlFields.join('\n ');
|
|
940
975
|
const refersToString = typeDef.data.originalName
|
|
@@ -968,7 +1003,7 @@ const schemaPreprocessor = (schema) => {
|
|
|
968
1003
|
};
|
|
969
1004
|
validateRelationships(typeName, fields, getInternalModel);
|
|
970
1005
|
const fieldLevelAuthRules = processFieldLevelAuthRules(fields, authFields);
|
|
971
|
-
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, transformedSecondaryIndexes);
|
|
1006
|
+
const { gqlFields, implicitTypes } = processFields(typeName, fields, authFields, fieldLevelAuthRules, identifier, partitionKey, transformedSecondaryIndexes, databaseEngine);
|
|
972
1007
|
topLevelTypes.push(...implicitTypes);
|
|
973
1008
|
const joined = gqlFields.join('\n ');
|
|
974
1009
|
const modelAttrs = modelAttributesFromDisabledOps(typeDef.data.disabledOperations);
|