@restforgejs/platform 4.1.1 → 4.3.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.
- package/SECURITY.md +83 -4
- package/bin/sdf-tools.exe +0 -0
- package/build-info.json +2 -2
- package/cli/consumer-deploy.js +1 -1
- package/cli/consumer.js +1 -1
- package/generators/cli/dashboard/create.js +4 -1
- package/generators/cli/endpoint/create.js +43 -4
- package/generators/cli/key/generate.js +2 -1
- package/generators/cli/key/revoke.js +2 -1
- package/generators/cli/payload/diff.js +3 -2
- package/generators/cli/payload/generate.js +3 -2
- package/generators/cli/payload/sync.js +3 -2
- package/generators/cli/payload/validate.js +3 -2
- package/generators/cli/processor/create.js +14 -3
- package/generators/cli/project/delete.js +2 -1
- package/generators/cli/query/validate.js +3 -2
- package/generators/cli/schema/apply.js +526 -0
- package/generators/cli/schema/describe.js +3 -2
- package/generators/cli/schema/diff.js +322 -0
- package/generators/cli/schema/generate-ddl.js +7 -10
- package/generators/cli/schema/init.js +95 -172
- package/generators/cli/schema/introspect.js +3 -2
- package/generators/cli/schema/list.js +3 -2
- package/generators/cli/schema/migrate.js +13 -18
- package/generators/cli/schema/models.js +8 -12
- package/generators/cli/schema/template.js +222 -0
- package/generators/cli/schema/validate.js +8 -12
- package/generators/cli-entry.js +17 -2
- package/generators/lib/dbschema-kit/apply-engine.js +582 -0
- package/generators/lib/dbschema-kit/diff-engine.js +703 -0
- package/generators/lib/dbschema-kit/diff-reporter.js +272 -0
- package/generators/lib/dbschema-kit/emitters/alter-table.js +275 -0
- package/generators/lib/migration/audit-table-runner.js +213 -215
- package/generators/lib/payload/endpoint-schema-validator.js +171 -0
- package/generators/lib/payload/payload-runner.js +137 -220
- package/generators/lib/payload/schema-diff.js +277 -0
- package/generators/lib/templates/dashboard-catalog.js +1 -437
- package/generators/lib/templates/db-connection-env.js +1 -212
- package/generators/lib/templates/dbschema-catalog.js +1 -489
- package/generators/lib/templates/field-validation-catalog.js +1 -531
- package/generators/lib/templates/mysql-template.js +1 -3863
- package/generators/lib/templates/oracle-template.js +1 -3915
- package/generators/lib/templates/postgres-template.js +1 -5838
- package/generators/lib/templates/query-declarative-catalog.js +1 -199
- package/generators/lib/templates/sqlite-template.js +1 -3440
- package/generators/lib/utils/audit-columns.js +181 -0
- package/generators/lib/utils/cli-output.js +17 -0
- package/generators/lib/utils/database-introspector.js +16 -13
- package/generators/lib/utils/env-manager.js +6 -0
- package/generators/lib/utils/path-validator.js +71 -0
- package/generators/lib/validators/payload-validator.js +1 -2
- package/integrity-manifest.json +28 -10
- package/package.json +11 -3
- package/scripts/verify-integrity.js +1 -1
- package/server.js +1 -1
- package/src/components/handlers/adjust_handler.js +1 -1
- package/src/components/handlers/audit_handler.js +1 -1
- package/src/components/handlers/delete_handler.js +1 -1
- package/src/components/handlers/export_handler.js +1 -1
- package/src/components/handlers/import_handler.js +1 -1
- package/src/components/handlers/insert_handler.js +1 -1
- package/src/components/handlers/update_handler.js +1 -1
- package/src/components/handlers/upload_handler.js +1 -1
- package/src/components/handlers/workflow_handler.js +1 -1
- package/src/components/integrations/webhook.js +1 -1
- package/src/consumers/baseConsumer.js +1 -1
- package/src/consumers/declarativeMapper.js +1 -1
- package/src/consumers/handlers/apiHandler.js +1 -1
- package/src/consumers/handlers/consoleHandler.js +1 -1
- package/src/consumers/handlers/databaseHandler.js +1 -1
- package/src/consumers/handlers/index.js +1 -1
- package/src/consumers/handlers/kafkaHandler.js +1 -1
- package/src/consumers/index.js +1 -1
- package/src/consumers/messageTransformer.js +1 -1
- package/src/consumers/validator.js +1 -1
- package/src/core/db/dialect/base-dialect.js +1 -1
- package/src/core/db/dialect/index.js +1 -1
- package/src/core/db/dialect/mysql-dialect.js +1 -1
- package/src/core/db/dialect/oracle-dialect.js +1 -1
- package/src/core/db/dialect/postgres-dialect.js +1 -1
- package/src/core/db/dialect/sqlite-dialect.js +1 -1
- package/src/core/db/flatten-helper.js +1 -1
- package/src/core/db/query-builder-error.js +1 -1
- package/src/core/db/query-builder.js +1 -1
- package/src/core/db/relation-helper.js +1 -1
- package/src/core/handlers/delete_handler.js +1 -1
- package/src/core/handlers/insert_handler.js +1 -1
- package/src/core/handlers/update_handler.js +1 -1
- package/src/core/models/base-model.js +1 -1
- package/src/core/utils/cache-manager.js +1 -1
- package/src/core/utils/component-engine.js +1 -1
- package/src/core/utils/context-builder.js +1 -1
- package/src/core/utils/datetime-formatter.js +1 -1
- package/src/core/utils/datetime-parser.js +1 -1
- package/src/core/utils/db.js +1 -1
- package/src/core/utils/logger.js +1 -1
- package/src/core/utils/payload-loader.js +1 -1
- package/src/core/utils/security-checks.js +1 -1
- package/src/middleware/body-options.js +1 -1
- package/src/middleware/cors.js +1 -1
- package/src/middleware/idempotency.js +1 -1
- package/src/middleware/rate-limiter.js +1 -1
- package/src/middleware/request-logger.js +1 -1
- package/src/middleware/security-headers.js +1 -1
- package/src/models/base-model-mysql.js +1 -1
- package/src/models/base-model-oracle.js +1 -1
- package/src/models/base-model-sqlite.js +1 -1
- package/src/models/base-model.js +1 -1
- package/src/pro/caching/redis-client.js +1 -1
- package/src/pro/caching/redis-helper.js +1 -1
- package/src/pro/consumers/baseConsumer.js +1 -1
- package/src/pro/consumers/declarativeMapper.js +1 -1
- package/src/pro/consumers/handlers/apiHandler.js +1 -1
- package/src/pro/consumers/handlers/consoleHandler.js +1 -1
- package/src/pro/consumers/handlers/databaseHandler.js +1 -1
- package/src/pro/consumers/handlers/index.js +1 -1
- package/src/pro/consumers/handlers/kafkaHandler.js +1 -1
- package/src/pro/consumers/index.js +1 -1
- package/src/pro/consumers/messageTransformer.js +1 -1
- package/src/pro/consumers/validator.js +1 -1
- package/src/pro/database/base-model-mysql.js +1 -1
- package/src/pro/database/base-model-oracle.js +1 -1
- package/src/pro/database/base-model-sqlite.js +1 -1
- package/src/pro/database/db-mysql.js +1 -1
- package/src/pro/database/db-oracle.js +1 -1
- package/src/pro/database/db-sqlite.js +1 -1
- package/src/pro/excel/excel-generator.js +1 -1
- package/src/pro/excel/excel-parser.js +1 -1
- package/src/pro/excel/export-service.js +1 -1
- package/src/pro/excel/export_handler.js +1 -1
- package/src/pro/excel/import-service.js +1 -1
- package/src/pro/excel/import-validator.js +1 -1
- package/src/pro/excel/import_handler.js +1 -1
- package/src/pro/excel/upsert-builder.js +1 -1
- package/src/pro/idgen/idgen-routes.js +1 -1
- package/src/pro/integrations/lookup-resolver.js +1 -1
- package/src/pro/integrations/upload-handler-v2.js +1 -1
- package/src/pro/integrations/upload-handler.js +1 -1
- package/src/pro/integrations/webhook.js +1 -1
- package/src/pro/locking/lock-routes.js +1 -1
- package/src/pro/locking/resource-lock-manager.js +1 -1
- package/src/pro/messaging/kafkaConsumerService.js +1 -1
- package/src/pro/messaging/kafkaService.js +1 -1
- package/src/pro/messaging/messagehubService.js +1 -1
- package/src/pro/messaging/rabbitmqService.js +1 -1
- package/src/pro/scheduler/job-manager.js +1 -1
- package/src/pro/scheduler/job-routes.js +1 -1
- package/src/pro/scheduler/job-validator.js +1 -1
- package/src/pro/storage/base-storage-provider.js +1 -1
- package/src/pro/storage/file-metadata-helper.js +1 -1
- package/src/pro/storage/index.js +1 -1
- package/src/pro/storage/local-storage-provider.js +1 -1
- package/src/pro/storage/s3-storage-provider.js +1 -1
- package/src/pro/storage/upload-cleanup-job.js +1 -1
- package/src/pro/storage/upload-cleanup-scheduler.js +1 -1
- package/src/pro/storage/upload-pending-tracker.js +1 -1
- package/src/pro/websocket/broadcast-helper.js +1 -1
- package/src/pro/websocket/index.js +1 -1
- package/src/pro/websocket/livesync-server.js +1 -1
- package/src/pro/websocket/ws-broadcaster.js +1 -1
- package/src/services/export-service.js +1 -1
- package/src/services/import-service.js +1 -1
- package/src/services/kafkaConsumerService.js +1 -1
- package/src/services/kafkaService.js +1 -1
- package/src/services/messagehubService.js +1 -1
- package/src/services/rabbitmqService.js +1 -1
- package/src/utils/cache-invalidation-registry.js +1 -1
- package/src/utils/cache-manager.js +1 -1
- package/src/utils/component-engine.js +1 -1
- package/src/utils/config-extractor.js +1 -1
- package/src/utils/consumerLogger.js +1 -1
- package/src/utils/context-builder.js +1 -1
- package/src/utils/dashboard-helpers.js +1 -1
- package/src/utils/dateHelper.js +1 -1
- package/src/utils/datetime-formatter.js +1 -1
- package/src/utils/datetime-parser.js +1 -1
- package/src/utils/db-bootstrap.js +1 -1
- package/src/utils/db-mysql.js +1 -1
- package/src/utils/db-oracle.js +1 -1
- package/src/utils/db-sqlite.js +1 -1
- package/src/utils/db.js +1 -1
- package/src/utils/demo-generator.js +1 -1
- package/src/utils/excel-generator.js +1 -1
- package/src/utils/excel-parser.js +1 -1
- package/src/utils/file-watcher.js +1 -1
- package/src/utils/id-generator.js +1 -1
- package/src/utils/idempotency-manager.js +1 -1
- package/src/utils/import-validator.js +1 -1
- package/src/utils/license-client.js +1 -1
- package/src/utils/lock-manager.js +1 -1
- package/src/utils/logger.js +1 -1
- package/src/utils/lookup-resolver.js +1 -1
- package/src/utils/payload-loader.js +1 -1
- package/src/utils/processor-response.js +1 -1
- package/src/utils/rabbitmq.js +1 -1
- package/src/utils/redis-client.js +1 -1
- package/src/utils/redis-helper.js +1 -1
- package/src/utils/request-scope.js +1 -1
- package/src/utils/security-checks.js +1 -1
- package/src/utils/service-resolver.js +1 -1
- package/src/utils/shutdown-coordinator.js +1 -1
- package/src/utils/trusted-keys.js +1 -1
- package/src/utils/upload-handler.js +1 -1
- package/src/utils/upsert-builder.js +1 -1
- package/src/utils/workflow-hook-executor.js +1 -1
- package/generators/metadata/global.json +0 -58
- package/generators/metadata/test-mysql-workbench.json +0 -118
- package/generators/metadata/test-mysql.json +0 -56
- package/generators/metadata/test-oracle-workbench.json +0 -118
- package/generators/metadata/test-oracle.json +0 -56
- package/generators/metadata/test-pg-workbench.json +0 -118
- package/generators/metadata/test-pg.json +0 -56
- package/generators/scripts/obfuscate-source.js +0 -356
- package/generators/scripts/validate-catalog.js +0 -430
- package/generators/scripts/validate-dbschema-catalog.js +0 -708
- package/generators/tests/baseline/mysql/mini_inventory_item/src/models/mini-inventory/item.js +0 -944
- package/generators/tests/baseline/mysql/mini_inventory_item/src/modules/mini-inventory/item.js +0 -740
- package/generators/tests/baseline/mysql/mini_inventory_item/src/modules/mini-inventory.js +0 -336
- package/generators/tests/baseline/oracle/mini_inventory_item/src/models/mini-inventory/item.js +0 -1002
- package/generators/tests/baseline/oracle/mini_inventory_item/src/modules/mini-inventory/item.js +0 -740
- package/generators/tests/baseline/oracle/mini_inventory_item/src/modules/mini-inventory.js +0 -336
- package/generators/tests/baseline/postgres/mini_inventory_item/src/models/mini-inventory/item.js +0 -1333
- package/generators/tests/baseline/postgres/mini_inventory_item/src/modules/mini-inventory/item.js +0 -1173
- package/generators/tests/baseline/postgres/mini_inventory_item/src/modules/mini-inventory.js +0 -496
- package/generators/tests/fixtures/payloads/custom-sensitive.json +0 -27
- package/generators/tests/fixtures/payloads/dynamic-search-optout.json +0 -23
- package/generators/tests/fixtures/payloads/login-with-password.json +0 -22
- package/generators/tests/fixtures/payloads/order-process.json +0 -52
- package/generators/tests/fixtures/payloads/with-inline-sql.json +0 -26
- package/generators/tests/integration-tahap4b/README.md +0 -145
- package/generators/tests/integration-tahap4b/run-concurrent.js +0 -77
- package/generators/tests/integration-tahap4b/seed.sql +0 -53
- package/generators/tests/integration-tahap4b/verify.sql +0 -110
- package/generators/tests/unit/cli/create-dashboard.test.js +0 -505
- package/generators/tests/unit/cli/create-processor.test.js +0 -319
- package/generators/tests/unit/cli/dispatch-dashboard.test.js +0 -149
- package/generators/tests/unit/lib/dashboard-generator.test.js +0 -895
- package/generators/tests/unit/lib/dashboard-validator.test.js +0 -354
- package/generators/tests/unit/lib/dbschema-kit/apply-executor.test.js +0 -437
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-introspect.test.js +0 -393
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-kit-generate-ddl.test.js +0 -104
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-kit-init.test.js +0 -119
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-kit-list.test.js +0 -48
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-kit-migrate.test.js +0 -175
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-kit-validate.test.js +0 -102
- package/generators/tests/unit/lib/dbschema-kit/cli/dbschema-models.test.js +0 -43
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/all-schemas-listing.js +0 -84
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/connection-error.js +0 -13
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/empty.js +0 -12
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/multi-schema.js +0 -124
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/single-schema-inventory.js +0 -64
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/introspect-stubs/two-tables.js +0 -66
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/migrate-stubs/connection-error.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/migrate-stubs/partial.js +0 -29
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/migrate-stubs/rollback.js +0 -26
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/migrate-stubs/success.js +0 -43
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/multi-schema/audit/events.js +0 -18
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/multi-schema/inventory/products.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/cli/fixtures/multi-schema/users.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/connection.test.js +0 -112
- package/generators/tests/unit/lib/dbschema-kit/ddl-generator.test.js +0 -205
- package/generators/tests/unit/lib/dbschema-kit/define-model.test.js +0 -56
- package/generators/tests/unit/lib/dbschema-kit/dialect/index.test.js +0 -46
- package/generators/tests/unit/lib/dbschema-kit/dialect/mysql.test.js +0 -126
- package/generators/tests/unit/lib/dbschema-kit/dialect/oracle.test.js +0 -126
- package/generators/tests/unit/lib/dbschema-kit/dialect/postgres.test.js +0 -131
- package/generators/tests/unit/lib/dbschema-kit/dialect/sqlite.test.js +0 -126
- package/generators/tests/unit/lib/dbschema-kit/driver-loader.test.js +0 -93
- package/generators/tests/unit/lib/dbschema-kit/emitters/create-index.test.js +0 -173
- package/generators/tests/unit/lib/dbschema-kit/emitters/create-table.test.js +0 -376
- package/generators/tests/unit/lib/dbschema-kit/emitters/drop-table.test.js +0 -78
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/invalid-dialect.env +0 -6
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/missing-dialect.env +0 -5
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/missing-host.env +0 -5
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/oracle-valid.env +0 -6
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/postgres-valid.env +0 -7
- package/generators/tests/unit/lib/dbschema-kit/fixtures/connection/sqlite-valid.env +0 -2
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/category.js +0 -11
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/item_product.js +0 -11
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/stock_inbound.js +0 -24
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/stock_inbound_item.js +0 -28
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/supplier.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory/warehouse.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-invalid/orphan.js +0 -17
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/master/category.js +0 -11
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/master/item_product.js +0 -11
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/master/supplier.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/master/warehouse.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/transactions/stock_inbound.js +0 -24
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/mini-inventory-multifolder/transactions/stock_inbound_item.js +0 -28
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/multi-schema/audit/events.js +0 -18
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/multi-schema/inventory/products.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/integration/multi-schema/public/users.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/duplicate-subfolder/extra/category.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/duplicate-subfolder/master/category.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/duplicate-tablename/bar.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/duplicate-tablename/foo.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/empty-folder/README.md +0 -1
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/invalid-export/plain.js +0 -3
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/invalid-schema/bad.js +0 -6
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/legacy-pattern/legacy.js +0 -12
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/multi-schema-distinct/audit/products.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/multi-schema-distinct/inventory/products.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/multi-schema-duplicate/a/products.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/multi-schema-duplicate/b/products.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/nested-deep/a/b/c/deep_table.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/recursive-multi-folder/.hidden/ignored.js +0 -7
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/recursive-multi-folder/master/category.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/recursive-multi-folder/master/supplier.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/recursive-multi-folder/transactions/stock_inbound.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/recursive-multi-folder/transactions/stock_inbound_item.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/valid-multiple/category.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/valid-multiple/item_product.js +0 -9
- package/generators/tests/unit/lib/dbschema-kit/fixtures/loader/valid-single/category.js +0 -8
- package/generators/tests/unit/lib/dbschema-kit/integration.test.js +0 -217
- package/generators/tests/unit/lib/dbschema-kit/introspect-mapper.test.js +0 -403
- package/generators/tests/unit/lib/dbschema-kit/ir-builder.test.js +0 -390
- package/generators/tests/unit/lib/dbschema-kit/loader.test.js +0 -128
- package/generators/tests/unit/lib/dbschema-kit/naming.test.js +0 -170
- package/generators/tests/unit/lib/dbschema-kit/parser/shorthand-parser.test.js +0 -237
- package/generators/tests/unit/lib/dbschema-kit/schema-printer.test.js +0 -251
- package/generators/tests/unit/lib/dbschema-kit/statement-modifier.test.js +0 -105
- package/generators/tests/unit/lib/dbschema-kit/statement-splitter.test.js +0 -165
- package/generators/tests/unit/lib/dbschema-kit/topological-sort.test.js +0 -135
- package/generators/tests/unit/lib/dbschema-kit/validator/check-compatibility-validator.test.js +0 -373
- package/generators/tests/unit/lib/dbschema-kit/validator/circular-relation-validator.test.js +0 -454
- package/generators/tests/unit/lib/dbschema-kit/validator/cross-model-validator.test.js +0 -512
- package/generators/tests/unit/lib/dbschema-kit/validator/enhanced-validate-integration.test.js +0 -390
- package/generators/tests/unit/lib/dbschema-kit/validator/naming-convention-validator.test.js +0 -306
- package/generators/tests/unit/lib/dbschema-kit/validator/schema-validator.test.js +0 -443
- package/generators/tests/unit/lib/dbschema-kit/validator/type-compatibility-validator.test.js +0 -440
- package/generators/tests/unit/lib/dbschema-kit/validator/validator-reporter.test.js +0 -172
- package/generators/tests/unit/lib/metadata-manager-dashboard.test.js +0 -256
- package/generators/tests/unit/lib/payload-validator-fieldpolicy.test.js +0 -240
- package/generators/tests/unit/lib/processor-validation-generator.test.js +0 -300
- package/generators/tests/unit/lib/sensitive-field-masker.test.js +0 -170
- package/generators/tests/unit/lib/sql-table-extractor.test.js +0 -119
- package/scripts/generate-integrity-manifest.js +0 -124
- package/scripts/snapshot-cli-contracts.js +0 -194
- package/scripts/verify-publish.js +0 -56
|
@@ -1,215 +1,213 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audit Table Runner
|
|
3
|
-
*
|
|
4
|
-
* Mengeksekusi DDL audit table ke database yang dituju.
|
|
5
|
-
* Bersifat idempotent (table existing tidak menyebabkan error).
|
|
6
|
-
*
|
|
7
|
-
* Failure mode:
|
|
8
|
-
* - Connection gagal (timeout/auth) → warning + dry-run mode (return status,
|
|
9
|
-
* tidak throw). Generator boleh lanjut karena migration bisa dijalankan
|
|
10
|
-
* manual via file SQL yang ditulis.
|
|
11
|
-
* - DDL gagal setelah connection sukses → throw, generator abort.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param {
|
|
26
|
-
*
|
|
27
|
-
* @param {Object
|
|
28
|
-
*
|
|
29
|
-
* @param {Object} [options]
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
fs.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await connection.
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
runAuditMigration
|
|
215
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Audit Table Runner
|
|
3
|
+
*
|
|
4
|
+
* Mengeksekusi DDL audit table ke database yang dituju.
|
|
5
|
+
* Bersifat idempotent (table existing tidak menyebabkan error).
|
|
6
|
+
*
|
|
7
|
+
* Failure mode:
|
|
8
|
+
* - Connection gagal (timeout/auth) → warning + dry-run mode (return status,
|
|
9
|
+
* tidak throw). Generator boleh lanjut karena migration bisa dijalankan
|
|
10
|
+
* manual via file SQL yang ditulis.
|
|
11
|
+
* - DDL gagal setelah connection sukses → throw, generator abort.
|
|
12
|
+
*
|
|
13
|
+
* @module lib/migration/audit-table-runner
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const { generateAuditTableMigration } = require('./audit-table-generator');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Jalankan migration audit table.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} tableName - Nama tabel sumber
|
|
24
|
+
* @param {string} dialect - 'postgres' | 'mysql' | 'oracle'
|
|
25
|
+
* @param {Object|null} connectionInfo - Connection info { host, port, user, password, database, connectString? }.
|
|
26
|
+
* Jika null → dry-run mode (file SQL tetap ditulis).
|
|
27
|
+
* @param {Object} [options]
|
|
28
|
+
* @param {string} [options.projectRoot=process.cwd()] - Root project untuk menulis migrations/audit/
|
|
29
|
+
* @param {Object} [options.logger=console] - Logger dengan method info/warn/error
|
|
30
|
+
* @returns {Promise<{status: string, sqlPath: string, auditTable: string}>}
|
|
31
|
+
* status: 'created' | 'exists' | 'dry-run' | 'connection-failed'
|
|
32
|
+
*/
|
|
33
|
+
async function runAuditMigration(tableName, dialect, connectionInfo, options = {}) {
|
|
34
|
+
const projectRoot = options.projectRoot || process.cwd();
|
|
35
|
+
const logger = options.logger || console;
|
|
36
|
+
const auditTable = `${tableName}_audit`;
|
|
37
|
+
const sql = generateAuditTableMigration(tableName, dialect);
|
|
38
|
+
|
|
39
|
+
const sqlPath = writeMigrationFile(projectRoot, auditTable, sql);
|
|
40
|
+
logger.info(`[restforge] audit migration written: ${path.relative(projectRoot, sqlPath)}`);
|
|
41
|
+
|
|
42
|
+
if (!connectionInfo) {
|
|
43
|
+
logger.warn(`[restforge] audit migration skipped — database connection not configured`);
|
|
44
|
+
return { status: 'dry-run', sqlPath, auditTable };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let connection;
|
|
48
|
+
try {
|
|
49
|
+
connection = await connectToDatabase(dialect, connectionInfo);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
logger.warn(`[restforge] audit migration skipped — connection failed: ${err.message}`);
|
|
52
|
+
return { status: 'connection-failed', sqlPath, auditTable };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const existed = await auditTableExists(connection, dialect, auditTable, connectionInfo);
|
|
57
|
+
await executeMigration(connection, dialect, sql);
|
|
58
|
+
logger.info(existed
|
|
59
|
+
? `[restforge] audit table exists: ${auditTable}`
|
|
60
|
+
: `[restforge] audit table created: ${auditTable}`);
|
|
61
|
+
return { status: existed ? 'exists' : 'created', sqlPath, auditTable };
|
|
62
|
+
} catch (err) {
|
|
63
|
+
logger.error(`[restforge] audit migration failed: ${err.message}`);
|
|
64
|
+
throw err;
|
|
65
|
+
} finally {
|
|
66
|
+
await closeConnection(connection, dialect);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function writeMigrationFile(projectRoot, auditTable, sql) {
|
|
71
|
+
const migrationsDir = path.join(projectRoot, 'migrations', 'audit');
|
|
72
|
+
fs.mkdirSync(migrationsDir, { recursive: true });
|
|
73
|
+
const sqlPath = path.join(migrationsDir, `${auditTable}.sql`);
|
|
74
|
+
fs.writeFileSync(sqlPath, sql + '\n', 'utf8');
|
|
75
|
+
return sqlPath;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function connectToDatabase(dialect, connectionInfo) {
|
|
79
|
+
if (dialect === 'postgres') {
|
|
80
|
+
const { Client } = require('pg');
|
|
81
|
+
const client = new Client({
|
|
82
|
+
host: connectionInfo.host,
|
|
83
|
+
port: connectionInfo.port,
|
|
84
|
+
user: connectionInfo.user,
|
|
85
|
+
password: connectionInfo.password,
|
|
86
|
+
database: connectionInfo.database
|
|
87
|
+
});
|
|
88
|
+
await client.connect();
|
|
89
|
+
return client;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (dialect === 'mysql') {
|
|
93
|
+
const mysql = require('mysql2/promise');
|
|
94
|
+
return await mysql.createConnection({
|
|
95
|
+
host: connectionInfo.host,
|
|
96
|
+
port: connectionInfo.port,
|
|
97
|
+
user: connectionInfo.user,
|
|
98
|
+
password: connectionInfo.password,
|
|
99
|
+
database: connectionInfo.database,
|
|
100
|
+
multipleStatements: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (dialect === 'oracle') {
|
|
105
|
+
const oracledb = require('oracledb');
|
|
106
|
+
return await oracledb.getConnection({
|
|
107
|
+
user: connectionInfo.user,
|
|
108
|
+
password: connectionInfo.password,
|
|
109
|
+
connectString: connectionInfo.connectString
|
|
110
|
+
|| `${connectionInfo.host}:${connectionInfo.port}/${connectionInfo.database}`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
throw new Error(`connectToDatabase: unsupported dialect '${dialect}'`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function closeConnection(connection, dialect) {
|
|
118
|
+
if (!connection) return;
|
|
119
|
+
try {
|
|
120
|
+
if (dialect === 'oracle') {
|
|
121
|
+
await connection.close();
|
|
122
|
+
} else {
|
|
123
|
+
await connection.end();
|
|
124
|
+
}
|
|
125
|
+
} catch (_err) {
|
|
126
|
+
// ignore close error — primary action sudah selesai
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function auditTableExists(connection, dialect, auditTable, connectionInfo) {
|
|
131
|
+
if (dialect === 'postgres') {
|
|
132
|
+
const { rows } = await connection.query(
|
|
133
|
+
`SELECT 1 FROM information_schema.tables
|
|
134
|
+
WHERE table_schema = current_schema() AND table_name = $1
|
|
135
|
+
LIMIT 1`,
|
|
136
|
+
[auditTable]
|
|
137
|
+
);
|
|
138
|
+
return rows.length > 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (dialect === 'mysql') {
|
|
142
|
+
const [rows] = await connection.query(
|
|
143
|
+
`SELECT 1 FROM information_schema.tables
|
|
144
|
+
WHERE table_schema = ? AND table_name = ?
|
|
145
|
+
LIMIT 1`,
|
|
146
|
+
[connectionInfo.database, auditTable]
|
|
147
|
+
);
|
|
148
|
+
return rows.length > 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (dialect === 'oracle') {
|
|
152
|
+
const result = await connection.execute(
|
|
153
|
+
`SELECT 1 FROM user_tables WHERE table_name = :name`,
|
|
154
|
+
{ name: auditTable.toUpperCase() }
|
|
155
|
+
);
|
|
156
|
+
return result.rows && result.rows.length > 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function executeMigration(connection, dialect, sql) {
|
|
163
|
+
if (dialect === 'postgres') {
|
|
164
|
+
// pg client mendukung multiple statement dalam satu query() tanpa params
|
|
165
|
+
await connection.query(sql);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (dialect === 'mysql') {
|
|
170
|
+
// mysql2 dengan multipleStatements: true
|
|
171
|
+
await connection.query(sql);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (dialect === 'oracle') {
|
|
176
|
+
// Oracle PL/SQL anonim dipisahkan oleh '/' di line tersendiri.
|
|
177
|
+
// oracledb.execute() menerima satu statement per call.
|
|
178
|
+
const blocks = splitOraclePlsqlBlocks(sql);
|
|
179
|
+
for (const block of blocks) {
|
|
180
|
+
const trimmed = block.trim();
|
|
181
|
+
if (trimmed === '') continue;
|
|
182
|
+
await connection.execute(trimmed);
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
throw new Error(`executeMigration: unsupported dialect '${dialect}'`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function splitOraclePlsqlBlocks(sql) {
|
|
191
|
+
// Pisahkan blok PL/SQL berdasarkan baris yang isinya hanya '/'
|
|
192
|
+
const lines = sql.split(/\r?\n/);
|
|
193
|
+
const blocks = [];
|
|
194
|
+
let current = [];
|
|
195
|
+
for (const line of lines) {
|
|
196
|
+
if (line.trim() === '/') {
|
|
197
|
+
if (current.length > 0) {
|
|
198
|
+
blocks.push(current.join('\n'));
|
|
199
|
+
current = [];
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
current.push(line);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (current.length > 0 && current.join('').trim() !== '') {
|
|
206
|
+
blocks.push(current.join('\n'));
|
|
207
|
+
}
|
|
208
|
+
return blocks;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = {
|
|
212
|
+
runAuditMigration
|
|
213
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Endpoint Schema Validator
|
|
5
|
+
*
|
|
6
|
+
* Orchestrator untuk validasi schema database saat `endpoint create` dijalankan.
|
|
7
|
+
* Module ini:
|
|
8
|
+
* 1. Resolve --config file (via config-resolver)
|
|
9
|
+
* 2. Load config + connect ke database (via DatabaseIntrospector)
|
|
10
|
+
* 3. Compare payload-vs-database menggunakan compareSchemaStrict
|
|
11
|
+
* 4. Map hasil ke exit-code semantics:
|
|
12
|
+
* - clean schema -> return { status: 'ok' }
|
|
13
|
+
* - drift detected -> throw error dengan exitCode=1 + formatted report
|
|
14
|
+
* - connection fail -> throw error dengan exitCode=3
|
|
15
|
+
* - usage error -> throw error dengan exitCode=2 (di-handle caller via validateContract)
|
|
16
|
+
*
|
|
17
|
+
* Module ini sengaja decoupled dari PayloadGenerator agar tidak ikut menjalankan
|
|
18
|
+
* payload regenerate/sync flow.
|
|
19
|
+
*
|
|
20
|
+
* @module lib/payload/endpoint-schema-validator
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const { DatabaseIntrospector } = require('../utils/database-introspector');
|
|
24
|
+
const { resolveConfig, printDefaultConfigWarning } = require('../utils/config-resolver');
|
|
25
|
+
const { compareSchemaStrict, formatDriftReport } = require('./schema-diff');
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Buat Error object dengan property `exitCode` agar cli-entry dapat
|
|
29
|
+
* forward exit code spesifik.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} message
|
|
32
|
+
* @param {number} exitCode
|
|
33
|
+
* @returns {Error}
|
|
34
|
+
*/
|
|
35
|
+
function createExitError(message, exitCode) {
|
|
36
|
+
const err = new Error(message);
|
|
37
|
+
err.exitCode = exitCode;
|
|
38
|
+
err.isSchemaValidationError = true;
|
|
39
|
+
return err;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Jalankan validasi schema untuk satu payload + table sebelum codegen.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} options
|
|
46
|
+
* @param {Object} options.payload - Processed payload object (harus punya tableName)
|
|
47
|
+
* @param {string} options.payloadFileName - Nama file payload untuk pesan error
|
|
48
|
+
* @param {string} options.configArg - Nilai flag --config dari CLI
|
|
49
|
+
* @param {boolean} options.skipSchemaCheck - true bila --skip-schema-check di-set
|
|
50
|
+
* @param {string} [options.workingDir] - cwd, default process.cwd()
|
|
51
|
+
* @param {Function} [options.IntrospectorClass] - Override untuk testing
|
|
52
|
+
* @returns {Promise<{
|
|
53
|
+
* status: 'ok' | 'skipped',
|
|
54
|
+
* reason?: string,
|
|
55
|
+
* columnsChecked?: number
|
|
56
|
+
* }>}
|
|
57
|
+
* @throws {Error} Dengan property exitCode (1=drift, 2=usage, 3=connection)
|
|
58
|
+
*/
|
|
59
|
+
async function validateEndpointSchema(options) {
|
|
60
|
+
const {
|
|
61
|
+
payload,
|
|
62
|
+
payloadFileName,
|
|
63
|
+
configArg,
|
|
64
|
+
skipSchemaCheck,
|
|
65
|
+
workingDir,
|
|
66
|
+
IntrospectorClass
|
|
67
|
+
} = options;
|
|
68
|
+
|
|
69
|
+
if (!payload || !payload.tableName) {
|
|
70
|
+
throw createExitError('Payload missing tableName — cannot run schema validation', 2);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (skipSchemaCheck) {
|
|
74
|
+
return { status: 'skipped', reason: '--skip-schema-check active' };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const resolved = resolveConfig(configArg, workingDir || process.cwd());
|
|
78
|
+
if (!resolved) {
|
|
79
|
+
const lines = [
|
|
80
|
+
'Error: --config is required for schema validation',
|
|
81
|
+
'Usage: npx restforge endpoint create --project=<P> --name=<N> --payload=<F> --config=<ENV> [--force=true] [--skip-schema-check]'
|
|
82
|
+
];
|
|
83
|
+
throw createExitError(lines.join('\n'), 2);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (resolved.source === 'default') {
|
|
87
|
+
printDefaultConfigWarning(resolved.defaultName);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const IntroCtor = IntrospectorClass || DatabaseIntrospector;
|
|
91
|
+
const db = new IntroCtor({ quiet: true });
|
|
92
|
+
|
|
93
|
+
const loaded = db.loadConfig(resolved.path);
|
|
94
|
+
if (!loaded) {
|
|
95
|
+
throw createExitError(
|
|
96
|
+
buildConnectionErrorMessage(`Cannot load config file: ${resolved.path}`),
|
|
97
|
+
3
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let connected = false;
|
|
102
|
+
try {
|
|
103
|
+
connected = await db.connect();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
try { await db.close(); } catch (_e) { /* ignore */ }
|
|
106
|
+
throw createExitError(
|
|
107
|
+
buildConnectionErrorMessage(e.message || String(e)),
|
|
108
|
+
3
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!connected) {
|
|
113
|
+
try { await db.close(); } catch (_e) { /* ignore */ }
|
|
114
|
+
throw createExitError(
|
|
115
|
+
buildConnectionErrorMessage('database not reachable'),
|
|
116
|
+
3
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let comparison;
|
|
121
|
+
try {
|
|
122
|
+
comparison = await compareSchemaStrict(payload, db);
|
|
123
|
+
} finally {
|
|
124
|
+
try { await db.close(); } catch (_e) { /* ignore */ }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (comparison.status === 'error') {
|
|
128
|
+
const lines = [
|
|
129
|
+
'Schema Validation:',
|
|
130
|
+
` [ERROR] ${comparison.summary}`,
|
|
131
|
+
' Endpoint generation blocked.',
|
|
132
|
+
'',
|
|
133
|
+
' Workarounds:',
|
|
134
|
+
' 1. Verify the table exists in the database',
|
|
135
|
+
' 2. Use --skip-schema-check to bypass validation (NOT recommended for production)'
|
|
136
|
+
];
|
|
137
|
+
throw createExitError(lines.join('\n'), 3);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (comparison.status === 'drift') {
|
|
141
|
+
const driftLines = formatDriftReport(comparison, {
|
|
142
|
+
payloadFileName,
|
|
143
|
+
tableName: payload.tableName
|
|
144
|
+
});
|
|
145
|
+
const lines = ['Schema Validation:', ...driftLines, '', 'Endpoint generation blocked due to schema drift'];
|
|
146
|
+
throw createExitError(lines.join('\n'), 1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
status: 'ok',
|
|
151
|
+
columnsChecked: comparison.totalColumnsChecked || 0
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildConnectionErrorMessage(reason) {
|
|
156
|
+
const lines = [
|
|
157
|
+
'Schema Validation:',
|
|
158
|
+
` [ERROR] Cannot connect to database: ${reason}`,
|
|
159
|
+
' Endpoint generation blocked.',
|
|
160
|
+
'',
|
|
161
|
+
' Workarounds:',
|
|
162
|
+
' 1. Verify db-connection.env is correct and database is reachable',
|
|
163
|
+
' 2. Use --skip-schema-check to bypass validation (NOT recommended for production)'
|
|
164
|
+
];
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = {
|
|
169
|
+
validateEndpointSchema,
|
|
170
|
+
createExitError
|
|
171
|
+
};
|