Files
personal_site/frontend/node_modules/@aws-amplify/data-schema/dist/cjs/CombineSchema.js
T

46 lines
1.6 KiB
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.combinedSchemaBrand = void 0;
exports.combine = combine;
const util_1 = require("./util");
const CombinedSchemaBrandName = 'CombinedSchema';
exports.combinedSchemaBrand = (0, util_1.brand)(CombinedSchemaBrandName);
/**
* The interface for merging up to 50 schemas into a single API.
* @param schemas The schemas to combine into a single API
* @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)
* or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)
*/
function combine(schemas) {
return internalCombine(schemas);
}
function internalCombine(schemas) {
validateDuplicateTypeNames(schemas);
const combined = {
...exports.combinedSchemaBrand,
schemas: schemas,
};
for (const schema of combined.schemas) {
schema.context = combined;
}
return combined;
}
function validateDuplicateTypeNames(schemas) {
const allSchemaKeys = schemas.flatMap((s) => Object.keys(s.data.types));
const keySet = new Set();
const duplicateKeySet = new Set();
allSchemaKeys.forEach((key) => {
if (keySet.has(key)) {
duplicateKeySet.add(key);
}
else {
keySet.add(key);
}
});
if (duplicateKeySet.size > 0) {
throw new Error(`The schemas you are attempting to combine have a name collision. Please remove or rename ${Array.from(duplicateKeySet).join(', ')}.`);
}
}
//# sourceMappingURL=CombineSchema.js.map