npm package diff

Package: @forge/manifest

Versions: 8.0.0-next.6 - 8.0.0-next.7

File: package/out/validators/storage-validator.js

Index: package/out/validators/storage-validator.js
===================================================================
--- package/out/validators/storage-validator.js
+++ package/out/validators/storage-validator.js
@@ -8,101 +8,112 @@
     entityAttributesMaxCount = 50;
     entityIndexesMaxCount = 7;
     reservedIndexName = 'by-key';
     async validate(manifest) {
-        if (!manifest?.typedContent?.app?.storage) {
-            return {
-                success: true,
-                manifestObject: manifest
-            };
-        }
         const validationErrors = [];
-        if (!manifest.typedContent.app.storage.entities) {
-            return {
-                success: true,
-                manifestObject: manifest
-            };
-        }
-        const entities = manifest.typedContent.app.storage.entities;
-        entities.forEach((entity) => {
-            const { name, attributes } = entity;
-            if (Object.keys(attributes).length > this.entityAttributesMaxCount) {
+        validationErrors.push(...this.validateSqlModules(manifest));
+        validationErrors.push(...this.validateCustomEntities(manifest));
+        return {
+            success: validationErrors.length === 0,
+            manifestObject: manifest,
+            ...(validationErrors.length ? { errors: validationErrors } : {})
+        };
+    }
+    validateSqlModules(manifest) {
+        const validationErrors = [];
+        const sqlModules = manifest?.typedContent?.modules?.sql;
+        if (sqlModules && sqlModules.length) {
+            if (sqlModules.length > 1) {
                 validationErrors.push({
-                    message: text_1.errors.app.storage.entities.tooManyAttributes(name, this.entityAttributesMaxCount),
-                    reference: text_1.References.App,
+                    message: `Found ${sqlModules.length} SQL modules; only one is allowed.`,
+                    reference: text_1.References.Modules,
                     level: 'error',
-                    ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
+                    ...(0, utils_1.findPosition)('sql', manifest.yamlContentByLine)
                 });
             }
-            Object.keys(attributes).forEach((attributeKey) => {
-                if (attributeKey.length > this.entityAttributeMaxLength) {
+        }
+        return validationErrors;
+    }
+    validateCustomEntities(manifest) {
+        const validationErrors = [];
+        const entities = manifest?.typedContent?.app?.storage?.entities;
+        if (entities) {
+            entities.forEach((entity) => {
+                const { name, attributes } = entity;
+                if (Object.keys(attributes).length > this.entityAttributesMaxCount) {
                     validationErrors.push({
-                        message: text_1.errors.app.storage.entities.attributeNameTooLong(name, attributeKey, this.entityAttributeMaxLength),
+                        message: text_1.errors.app.storage.entities.tooManyAttributes(name, this.entityAttributesMaxCount),
                         reference: text_1.References.App,
                         level: 'error',
                         ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
                     });
                 }
-            });
-            if (entity.indexes) {
-                const { indexes } = entity;
-                if (indexes.length > this.entityIndexesMaxCount) {
-                    validationErrors.push({
-                        message: text_1.errors.app.storage.entities.tooManyIndexes(name, this.entityIndexesMaxCount),
-                        reference: text_1.References.App,
-                        level: 'error',
-                        ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
-                    });
-                }
-                const indexName = [];
-                const indexRange = [];
-                const indexPartition = [];
-                indexes.forEach((index) => {
-                    if (typeof index === 'string') {
-                        indexRange.push(index);
+                Object.keys(attributes).forEach((attributeKey) => {
+                    if (attributeKey.length > this.entityAttributeMaxLength) {
+                        validationErrors.push({
+                            message: text_1.errors.app.storage.entities.attributeNameTooLong(name, attributeKey, this.entityAttributeMaxLength),
+                            reference: text_1.References.App,
+                            level: 'error',
+                            ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
+                        });
                     }
-                    else if (typeof index === 'object') {
-                        indexName.push(index.name);
-                        indexRange.push(...index.range);
-                        if (index.partition) {
-                            indexPartition.push(...index.partition);
-                        }
-                    }
                 });
-                if (indexName.find((name) => name === this.reservedIndexName)) {
-                    validationErrors.push({
-                        message: text_1.errors.app.storage.entities.reservedIndexName(name, this.reservedIndexName),
-                        reference: text_1.References.App,
-                        level: 'error',
-                        ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
-                    });
-                }
-                indexRange.forEach((range) => {
-                    if (!Object.keys(attributes).length || !attributes[range]) {
+                if (entity.indexes) {
+                    const { indexes } = entity;
+                    if (indexes.length > this.entityIndexesMaxCount) {
                         validationErrors.push({
-                            message: text_1.errors.app.storage.entities.invalidIndexRange(name, range),
+                            message: text_1.errors.app.storage.entities.tooManyIndexes(name, this.entityIndexesMaxCount),
                             reference: text_1.References.App,
                             level: 'error',
                             ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
                         });
                     }
-                });
-                indexPartition.forEach((partition) => {
-                    if (!Object.keys(attributes).length || !attributes[partition]) {
+                    const indexName = [];
+                    const indexRange = [];
+                    const indexPartition = [];
+                    indexes.forEach((index) => {
+                        if (typeof index === 'string') {
+                            indexRange.push(index);
+                        }
+                        else if (typeof index === 'object') {
+                            indexName.push(index.name);
+                            indexRange.push(...index.range);
+                            if (index.partition) {
+                                indexPartition.push(...index.partition);
+                            }
+                        }
+                    });
+                    if (indexName.find((name) => name === this.reservedIndexName)) {
                         validationErrors.push({
-                            message: text_1.errors.app.storage.entities.invalidIndexPartition(name, partition),
+                            message: text_1.errors.app.storage.entities.reservedIndexName(name, this.reservedIndexName),
                             reference: text_1.References.App,
                             level: 'error',
                             ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
                         });
                     }
-                });
-            }
-        });
-        return {
-            success: validationErrors.length === 0,
-            manifestObject: manifest,
-            errors: validationErrors
-        };
+                    indexRange.forEach((range) => {
+                        if (!Object.keys(attributes).length || !attributes[range]) {
+                            validationErrors.push({
+                                message: text_1.errors.app.storage.entities.invalidIndexRange(name, range),
+                                reference: text_1.References.App,
+                                level: 'error',
+                                ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
+                            });
+                        }
+                    });
+                    indexPartition.forEach((partition) => {
+                        if (!Object.keys(attributes).length || !attributes[partition]) {
+                            validationErrors.push({
+                                message: text_1.errors.app.storage.entities.invalidIndexPartition(name, partition),
+                                reference: text_1.References.App,
+                                level: 'error',
+                                ...(0, utils_1.findPosition)('entities', manifest.yamlContentByLine)
+                            });
+                        }
+                    });
+                }
+            });
+        }
+        return validationErrors;
     }
 }
 exports.StorageValidator = StorageValidator;