@warlock.js/core 4.0.48 → 4.0.59
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/esm/application.d.ts +27 -0
- package/esm/application.d.ts.map +1 -0
- package/esm/bootstrap/setup.d.ts +2 -0
- package/esm/bootstrap/setup.d.ts.map +1 -0
- package/esm/bootstrap/setup.js +14 -0
- package/esm/bootstrap/setup.js.map +1 -0
- package/esm/bootstrap.d.ts +2 -0
- package/esm/bootstrap.d.ts.map +1 -0
- package/esm/bootstrap.js +5 -0
- package/esm/bootstrap.js.map +1 -0
- package/esm/cache/database-cache-driver.d.ts +56 -0
- package/esm/cache/database-cache-driver.d.ts.map +1 -0
- package/esm/cache/database-cache-driver.js +112 -0
- package/esm/cache/database-cache-driver.js.map +1 -0
- package/esm/cache/index.d.ts +3 -0
- package/esm/cache/index.d.ts.map +1 -0
- package/esm/cache/index.js +1 -0
- package/esm/cache/index.js.map +1 -0
- package/esm/cli/cli-command.d.ts +115 -0
- package/esm/cli/cli-command.d.ts.map +1 -0
- package/esm/cli/cli-command.js +227 -0
- package/esm/cli/cli-command.js.map +1 -0
- package/esm/cli/cli-commands.manager.d.ts +71 -0
- package/esm/cli/cli-commands.manager.d.ts.map +1 -0
- package/esm/cli/cli-commands.manager.js +348 -0
- package/esm/cli/cli-commands.manager.js.map +1 -0
- package/esm/cli/cli-commands.utils.d.ts +73 -0
- package/esm/cli/cli-commands.utils.d.ts.map +1 -0
- package/esm/cli/cli-commands.utils.js +195 -0
- package/esm/cli/cli-commands.utils.js.map +1 -0
- package/esm/cli/commands/add.command.d.ts +2 -0
- package/esm/cli/commands/add.command.d.ts.map +1 -0
- package/esm/cli/commands/add.command.js +15 -0
- package/esm/cli/commands/add.command.js.map +1 -0
- package/esm/cli/commands/build.command.d.ts +2 -0
- package/esm/cli/commands/build.command.d.ts.map +1 -0
- package/esm/cli/commands/build.command.js +8 -0
- package/esm/cli/commands/build.command.js.map +1 -0
- package/esm/cli/commands/dev-server.command.d.ts +2 -0
- package/esm/cli/commands/dev-server.command.d.ts.map +1 -0
- package/esm/cli/commands/dev-server.command.js +16 -0
- package/esm/cli/commands/dev-server.command.js.map +1 -0
- package/esm/cli/commands/migrate.command.d.ts +2 -0
- package/esm/cli/commands/migrate.command.d.ts.map +1 -0
- package/esm/cli/commands/migrate.command.js +37 -0
- package/esm/cli/commands/migrate.command.js.map +1 -0
- package/esm/cli/commands/seed.command.d.ts +2 -0
- package/esm/cli/commands/seed.command.d.ts.map +1 -0
- package/esm/cli/commands/seed.command.js +17 -0
- package/esm/cli/commands/seed.command.js.map +1 -0
- package/esm/cli/commands/start-production.command.d.ts +2 -0
- package/esm/cli/commands/start-production.command.d.ts.map +1 -0
- package/esm/cli/commands/start-production.command.js +65 -0
- package/esm/cli/commands/start-production.command.js.map +1 -0
- package/esm/cli/commands/typings-generator.command.d.ts +2 -0
- package/esm/cli/commands/typings-generator.command.d.ts.map +1 -0
- package/esm/cli/commands/typings-generator.command.js +37 -0
- package/esm/cli/commands/typings-generator.command.js.map +1 -0
- package/esm/cli/commands-loader.d.ts +18 -0
- package/esm/cli/commands-loader.d.ts.map +1 -0
- package/esm/cli/commands-loader.js +45 -0
- package/esm/cli/commands-loader.js.map +1 -0
- package/esm/cli/framework-cli-commands.d.ts +2 -0
- package/esm/cli/framework-cli-commands.d.ts.map +1 -0
- package/esm/cli/framework-cli-commands.js +11 -0
- package/esm/cli/framework-cli-commands.js.map +1 -0
- package/esm/cli/index.d.ts +3 -0
- package/esm/cli/index.d.ts.map +1 -0
- package/esm/cli/index.js +1 -4
- package/esm/cli/index.js.map +1 -1
- package/esm/cli/parse-cli-args.d.ts +18 -0
- package/esm/cli/parse-cli-args.d.ts.map +1 -0
- package/esm/cli/parse-cli-args.js +82 -0
- package/esm/cli/parse-cli-args.js.map +1 -0
- package/esm/cli/start.d.ts +2 -0
- package/esm/cli/start.d.ts.map +1 -0
- package/esm/cli/start.js +2 -6
- package/esm/cli/start.js.map +1 -1
- package/esm/cli/string-similarity.d.ts +44 -0
- package/esm/cli/string-similarity.d.ts.map +1 -0
- package/esm/cli/string-similarity.js +57 -0
- package/esm/cli/string-similarity.js.map +1 -0
- package/esm/cli/types.d.ts +206 -0
- package/esm/cli/types.d.ts.map +1 -0
- package/esm/config/config-getter.d.ts +35 -0
- package/esm/config/config-getter.d.ts.map +1 -0
- package/esm/config/config-getter.js +21 -0
- package/esm/config/config-getter.js.map +1 -0
- package/esm/config/config-handlers.d.ts +19 -0
- package/esm/config/config-handlers.d.ts.map +1 -0
- package/esm/config/config-handlers.js +47 -0
- package/esm/config/config-handlers.js.map +1 -0
- package/esm/config/config-loader.d.ts +37 -0
- package/esm/config/config-loader.d.ts.map +1 -0
- package/esm/config/config-loader.js +85 -0
- package/esm/config/config-loader.js.map +1 -0
- package/esm/config/config-manager.d.ts +22 -0
- package/esm/config/config-manager.d.ts.map +1 -0
- package/esm/config/config-manager.js +25 -0
- package/esm/config/config-manager.js.map +1 -0
- package/esm/config/config-special-handlers.d.ts +17 -0
- package/esm/config/config-special-handlers.d.ts.map +1 -0
- package/esm/config/config-special-handlers.js +23 -0
- package/esm/config/config-special-handlers.js.map +1 -0
- package/esm/config/index.d.ts +5 -0
- package/esm/config/index.d.ts.map +1 -0
- package/esm/config/load-config-files.d.ts +6 -0
- package/esm/config/load-config-files.d.ts.map +1 -0
- package/esm/config/load-config-files.js +19 -0
- package/esm/config/load-config-files.js.map +1 -0
- package/esm/config/types.d.ts +52 -0
- package/esm/config/types.d.ts.map +1 -0
- package/esm/database/index.d.ts +4 -0
- package/esm/database/index.d.ts.map +1 -0
- package/esm/database/migrate-action.d.ts +8 -0
- package/esm/database/migrate-action.d.ts.map +1 -0
- package/esm/database/migrate-action.js +95 -0
- package/esm/database/migrate-action.js.map +1 -0
- package/esm/database/models/database-log/database-log.d.ts +16 -0
- package/esm/database/models/database-log/database-log.d.ts.map +1 -0
- package/esm/database/models/database-log/database-log.js +17 -0
- package/esm/database/models/database-log/database-log.js.map +1 -0
- package/esm/database/models/database-log/index.d.ts +2 -0
- package/esm/database/models/database-log/index.d.ts.map +1 -0
- package/esm/database/seed-command-action.d.ts +3 -0
- package/esm/database/seed-command-action.d.ts.map +1 -0
- package/esm/database/seed-command-action.js +36 -0
- package/esm/database/seed-command-action.js.map +1 -0
- package/esm/database/seeds/index.d.ts +3 -0
- package/esm/database/seeds/index.d.ts.map +1 -0
- package/esm/database/seeds/seeder.d.ts +36 -0
- package/esm/database/seeds/seeder.d.ts.map +1 -0
- package/esm/database/seeds/seeder.js +6 -0
- package/esm/database/seeds/seeder.js.map +1 -0
- package/esm/database/seeds/seeders.manager.d.ts +47 -0
- package/esm/database/seeds/seeders.manager.d.ts.map +1 -0
- package/esm/database/seeds/seeders.manager.js +137 -0
- package/esm/database/seeds/seeders.manager.js.map +1 -0
- package/esm/database/seeds/seeds-table-migration.d.ts +8 -0
- package/esm/database/seeds/seeds-table-migration.d.ts.map +1 -0
- package/esm/database/seeds/seeds-table-migration.js +18 -0
- package/esm/database/seeds/seeds-table-migration.js.map +1 -0
- package/esm/database/seeds/types.d.ts +13 -0
- package/esm/database/seeds/types.d.ts.map +1 -0
- package/esm/database/seeds/utils.d.ts +2 -0
- package/esm/database/seeds/utils.d.ts.map +1 -0
- package/esm/database/seeds/utils.js +1 -0
- package/esm/database/seeds/utils.js.map +1 -0
- package/esm/database/utils.d.ts +18 -0
- package/esm/database/utils.d.ts.map +1 -0
- package/esm/database/utils.js +30 -0
- package/esm/database/utils.js.map +1 -0
- package/esm/dev2-server/connectors/base-connector.d.ts +49 -0
- package/esm/dev2-server/connectors/base-connector.d.ts.map +1 -0
- package/esm/dev2-server/connectors/base-connector.js +48 -0
- package/esm/dev2-server/connectors/base-connector.js.map +1 -0
- package/esm/dev2-server/connectors/cache-connector.d.ts +23 -0
- package/esm/dev2-server/connectors/cache-connector.d.ts.map +1 -0
- package/esm/dev2-server/connectors/cache-connector.js +35 -0
- package/esm/dev2-server/connectors/cache-connector.js.map +1 -0
- package/esm/dev2-server/connectors/connectors-manager.d.ts +38 -0
- package/esm/dev2-server/connectors/connectors-manager.d.ts.map +1 -0
- package/esm/dev2-server/connectors/connectors-manager.js +81 -0
- package/esm/dev2-server/connectors/connectors-manager.js.map +1 -0
- package/esm/dev2-server/connectors/database-connector.d.ts +23 -0
- package/esm/dev2-server/connectors/database-connector.d.ts.map +1 -0
- package/esm/dev2-server/connectors/database-connector.js +51 -0
- package/esm/dev2-server/connectors/database-connector.js.map +1 -0
- package/esm/dev2-server/connectors/http-connector.d.ts +29 -0
- package/esm/dev2-server/connectors/http-connector.d.ts.map +1 -0
- package/esm/dev2-server/connectors/http-connector.js +69 -0
- package/esm/dev2-server/connectors/http-connector.js.map +1 -0
- package/esm/dev2-server/connectors/index.d.ts +12 -0
- package/esm/dev2-server/connectors/index.d.ts.map +1 -0
- package/esm/dev2-server/connectors/storage.connector.d.ts +23 -0
- package/esm/dev2-server/connectors/storage.connector.d.ts.map +1 -0
- package/esm/dev2-server/connectors/storage.connector.js +29 -0
- package/esm/dev2-server/connectors/storage.connector.js.map +1 -0
- package/esm/dev2-server/connectors/types.d.ts +51 -0
- package/esm/dev2-server/connectors/types.d.ts.map +1 -0
- package/esm/dev2-server/connectors/types.js +10 -0
- package/esm/dev2-server/connectors/types.js.map +1 -0
- package/esm/dev2-server/create-worker.d.ts +34 -0
- package/esm/dev2-server/create-worker.d.ts.map +1 -0
- package/esm/dev2-server/create-worker.js +37 -0
- package/esm/dev2-server/create-worker.js.map +1 -0
- package/esm/dev2-server/dependency-graph.d.ts +93 -0
- package/esm/dev2-server/dependency-graph.d.ts.map +1 -0
- package/esm/dev2-server/dependency-graph.js +266 -0
- package/esm/dev2-server/dependency-graph.js.map +1 -0
- package/esm/dev2-server/dev-logger.d.ts +14 -0
- package/esm/dev2-server/dev-logger.d.ts.map +1 -0
- package/esm/dev2-server/dev-logger.js +130 -0
- package/esm/dev2-server/dev-logger.js.map +1 -0
- package/esm/dev2-server/development-server.d.ts +47 -0
- package/esm/dev2-server/development-server.d.ts.map +1 -0
- package/esm/dev2-server/development-server.js +149 -0
- package/esm/dev2-server/development-server.js.map +1 -0
- package/esm/dev2-server/events.d.ts +5 -0
- package/esm/dev2-server/events.d.ts.map +1 -0
- package/esm/dev2-server/events.js +4 -0
- package/esm/dev2-server/events.js.map +1 -0
- package/esm/dev2-server/export-analyzer.d.ts +84 -0
- package/esm/dev2-server/export-analyzer.d.ts.map +1 -0
- package/esm/dev2-server/export-analyzer.js +206 -0
- package/esm/dev2-server/export-analyzer.js.map +1 -0
- package/esm/dev2-server/file-event-handler.d.ts +156 -0
- package/esm/dev2-server/file-event-handler.d.ts.map +1 -0
- package/esm/dev2-server/file-event-handler.js +300 -0
- package/esm/dev2-server/file-event-handler.js.map +1 -0
- package/esm/dev2-server/file-manager.d.ts +385 -0
- package/esm/dev2-server/file-manager.d.ts.map +1 -0
- package/esm/dev2-server/file-manager.js +580 -0
- package/esm/dev2-server/file-manager.js.map +1 -0
- package/esm/dev2-server/file-operations.d.ts +203 -0
- package/esm/dev2-server/file-operations.d.ts.map +1 -0
- package/esm/dev2-server/file-operations.js +365 -0
- package/esm/dev2-server/file-operations.js.map +1 -0
- package/esm/dev2-server/files-orchestrator.d.ts +146 -0
- package/esm/dev2-server/files-orchestrator.d.ts.map +1 -0
- package/esm/dev2-server/files-orchestrator.js +314 -0
- package/esm/dev2-server/files-orchestrator.js.map +1 -0
- package/esm/dev2-server/files-watcher.d.ts +67 -0
- package/esm/dev2-server/files-watcher.d.ts.map +1 -0
- package/esm/dev2-server/files-watcher.js +95 -0
- package/esm/dev2-server/files-watcher.js.map +1 -0
- package/esm/dev2-server/flags.d.ts +10 -0
- package/esm/dev2-server/flags.d.ts.map +1 -0
- package/esm/dev2-server/flags.js +9 -0
- package/esm/dev2-server/flags.js.map +1 -0
- package/esm/dev2-server/health-checker/checkers/base-health-checker.d.ts +52 -0
- package/esm/dev2-server/health-checker/checkers/base-health-checker.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/checkers/base-health-checker.js +71 -0
- package/esm/dev2-server/health-checker/checkers/base-health-checker.js.map +1 -0
- package/esm/dev2-server/health-checker/checkers/eslint-health-checker.d.ts +40 -0
- package/esm/dev2-server/health-checker/checkers/eslint-health-checker.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/checkers/eslint-health-checker.js +217 -0
- package/esm/dev2-server/health-checker/checkers/eslint-health-checker.js.map +1 -0
- package/esm/dev2-server/health-checker/checkers/typescript-health-checker.d.ts +56 -0
- package/esm/dev2-server/health-checker/checkers/typescript-health-checker.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/checkers/typescript-health-checker.js +279 -0
- package/esm/dev2-server/health-checker/checkers/typescript-health-checker.js.map +1 -0
- package/esm/dev2-server/health-checker/file-health-checker.contract.d.ts +59 -0
- package/esm/dev2-server/health-checker/file-health-checker.contract.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/file-health-result.d.ts +68 -0
- package/esm/dev2-server/health-checker/file-health-result.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/file-health-result.js +40 -0
- package/esm/dev2-server/health-checker/file-health-result.js.map +1 -0
- package/esm/dev2-server/health-checker/files-healthcare.manager.d.ts +115 -0
- package/esm/dev2-server/health-checker/files-healthcare.manager.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/files-healthcare.manager.js +422 -0
- package/esm/dev2-server/health-checker/files-healthcare.manager.js.map +1 -0
- package/esm/dev2-server/health-checker/index.d.ts +6 -0
- package/esm/dev2-server/health-checker/index.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/workers/eslint-health.worker.d.ts +2 -0
- package/esm/dev2-server/health-checker/workers/eslint-health.worker.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/workers/eslint-health.worker.js +214 -0
- package/esm/dev2-server/health-checker/workers/eslint-health.worker.js.map +1 -0
- package/esm/dev2-server/health-checker/workers/ts-health.worker.d.ts +2 -0
- package/esm/dev2-server/health-checker/workers/ts-health.worker.d.ts.map +1 -0
- package/esm/dev2-server/health-checker/workers/ts-health.worker.js +261 -0
- package/esm/dev2-server/health-checker/workers/ts-health.worker.js.map +1 -0
- package/esm/dev2-server/import-transformer.d.ts +17 -0
- package/esm/dev2-server/import-transformer.d.ts.map +1 -0
- package/esm/dev2-server/import-transformer.js +280 -0
- package/esm/dev2-server/import-transformer.js.map +1 -0
- package/esm/dev2-server/index.d.ts +1 -0
- package/esm/dev2-server/index.d.ts.map +1 -0
- package/esm/dev2-server/layer-executor.d.ts +61 -0
- package/esm/dev2-server/layer-executor.d.ts.map +1 -0
- package/esm/dev2-server/layer-executor.js +314 -0
- package/esm/dev2-server/layer-executor.js.map +1 -0
- package/esm/dev2-server/manifest-manager.d.ts +80 -0
- package/esm/dev2-server/manifest-manager.d.ts.map +1 -0
- package/esm/dev2-server/manifest-manager.js +107 -0
- package/esm/dev2-server/manifest-manager.js.map +1 -0
- package/esm/dev2-server/module-loader.d.ts +108 -0
- package/esm/dev2-server/module-loader.d.ts.map +1 -0
- package/esm/dev2-server/module-loader.js +266 -0
- package/esm/dev2-server/module-loader.js.map +1 -0
- package/esm/dev2-server/package-json-manager.d.ts +16 -0
- package/esm/dev2-server/package-json-manager.d.ts.map +1 -0
- package/esm/dev2-server/package-json-manager.js +20 -0
- package/esm/dev2-server/package-json-manager.js.map +1 -0
- package/esm/dev2-server/parse-imports.d.ts +13 -0
- package/esm/dev2-server/parse-imports.d.ts.map +1 -0
- package/esm/dev2-server/parse-imports.js +329 -0
- package/esm/dev2-server/parse-imports.js.map +1 -0
- package/esm/dev2-server/path.d.ts +39 -0
- package/esm/dev2-server/path.d.ts.map +1 -0
- package/esm/dev2-server/path.js +56 -0
- package/esm/dev2-server/path.js.map +1 -0
- package/esm/dev2-server/runtime-import-helper.d.ts +8 -0
- package/esm/dev2-server/runtime-import-helper.d.ts.map +1 -0
- package/esm/dev2-server/runtime-import-helper.js +157 -0
- package/esm/dev2-server/runtime-import-helper.js.map +1 -0
- package/esm/dev2-server/special-files-collector.d.ts +114 -0
- package/esm/dev2-server/special-files-collector.d.ts.map +1 -0
- package/esm/dev2-server/special-files-collector.js +212 -0
- package/esm/dev2-server/special-files-collector.js.map +1 -0
- package/esm/dev2-server/start-development-server.d.ts +7 -0
- package/esm/dev2-server/start-development-server.d.ts.map +1 -0
- package/esm/dev2-server/start-development-server.js +21 -0
- package/esm/dev2-server/start-development-server.js.map +1 -0
- package/esm/dev2-server/transpile-file.d.ts +11 -0
- package/esm/dev2-server/transpile-file.d.ts.map +1 -0
- package/esm/dev2-server/transpile-file.js +21 -0
- package/esm/dev2-server/transpile-file.js.map +1 -0
- package/esm/dev2-server/tsconfig-manager.d.ts +45 -0
- package/esm/dev2-server/tsconfig-manager.d.ts.map +1 -0
- package/esm/dev2-server/tsconfig-manager.js +107 -0
- package/esm/dev2-server/tsconfig-manager.js.map +1 -0
- package/esm/dev2-server/type-generator.d.ts +115 -0
- package/esm/dev2-server/type-generator.d.ts.map +1 -0
- package/esm/dev2-server/type-generator.js +566 -0
- package/esm/dev2-server/type-generator.js.map +1 -0
- package/esm/dev2-server/types.d.ts +30 -0
- package/esm/dev2-server/types.d.ts.map +1 -0
- package/esm/dev2-server/utils.d.ts +15 -0
- package/esm/dev2-server/utils.d.ts.map +1 -0
- package/esm/dev2-server/utils.js +40 -0
- package/esm/dev2-server/utils.js.map +1 -0
- package/esm/generations/add-command.action.d.ts +3 -0
- package/esm/generations/add-command.action.d.ts.map +1 -0
- package/esm/generations/add-command.action.js +154 -0
- package/esm/generations/add-command.action.js.map +1 -0
- package/esm/http/config.d.ts +10 -0
- package/esm/http/config.d.ts.map +1 -0
- package/esm/http/config.js +22 -0
- package/esm/http/config.js.map +1 -0
- package/esm/http/context/request-context.d.ts +47 -0
- package/esm/http/context/request-context.d.ts.map +1 -0
- package/esm/http/context/request-context.js +52 -0
- package/esm/http/context/request-context.js.map +1 -0
- package/esm/http/createHttpApplication.d.ts +3 -0
- package/esm/http/createHttpApplication.d.ts.map +1 -0
- package/esm/http/createHttpApplication.js +28 -0
- package/esm/http/createHttpApplication.js.map +1 -0
- package/esm/http/database/RequestLog.d.ts +16 -0
- package/esm/http/database/RequestLog.d.ts.map +1 -0
- package/esm/http/database/RequestLog.js +26 -0
- package/esm/http/database/RequestLog.js.map +1 -0
- package/esm/http/errors/index.d.ts +2 -0
- package/esm/http/errors/index.d.ts.map +1 -0
- package/esm/http/errors/resource-not-found.error.d.ts +21 -0
- package/esm/http/errors/resource-not-found.error.d.ts.map +1 -0
- package/esm/http/errors/resource-not-found.error.js +40 -0
- package/esm/http/errors/resource-not-found.error.js.map +1 -0
- package/esm/http/events.d.ts +4 -0
- package/esm/http/events.d.ts.map +1 -0
- package/esm/http/events.js +26 -0
- package/esm/http/events.js.map +1 -0
- package/esm/http/index.d.ts +17 -0
- package/esm/http/index.d.ts.map +1 -0
- package/esm/http/middleware/cache-response-middleware.d.ts +34 -0
- package/esm/http/middleware/cache-response-middleware.d.ts.map +1 -0
- package/esm/http/middleware/cache-response-middleware.js +45 -0
- package/esm/http/middleware/cache-response-middleware.js.map +1 -0
- package/esm/http/middleware/index.d.ts +3 -0
- package/esm/http/middleware/index.d.ts.map +1 -0
- package/esm/http/middleware/inject-request-context.d.ts +21 -0
- package/esm/http/middleware/inject-request-context.d.ts.map +1 -0
- package/esm/http/middleware/inject-request-context.js +105 -0
- package/esm/http/middleware/inject-request-context.js.map +1 -0
- package/esm/http/plugins/index.d.ts +3 -0
- package/esm/http/plugins/index.d.ts.map +1 -0
- package/esm/http/plugins.d.ts +3 -0
- package/esm/http/plugins.d.ts.map +1 -0
- package/esm/http/plugins.js +31 -0
- package/esm/http/plugins.js.map +1 -0
- package/esm/http/request-controller.d.ts +11 -0
- package/esm/http/request-controller.d.ts.map +1 -0
- package/esm/http/request-controller.js +9 -0
- package/esm/http/request-controller.js.map +1 -0
- package/esm/http/request.d.ts +380 -0
- package/esm/http/request.d.ts.map +1 -0
- package/esm/http/request.js +733 -0
- package/esm/http/request.js.map +1 -0
- package/esm/http/response.js +914 -0
- package/esm/http/response.js.map +1 -0
- package/esm/http/server.d.ts +8 -0
- package/esm/http/server.d.ts.map +1 -0
- package/esm/http/server.js +15 -0
- package/esm/http/server.js.map +1 -0
- package/esm/http/types.d.ts +174 -0
- package/esm/http/types.d.ts.map +1 -0
- package/esm/http/uploaded-file.d.ts +459 -0
- package/esm/http/uploaded-file.d.ts.map +1 -0
- package/esm/http/uploaded-file.js +709 -0
- package/esm/http/uploaded-file.js.map +1 -0
- package/esm/http/uploads-config.d.ts +26 -0
- package/esm/http/uploads-config.d.ts.map +1 -0
- package/esm/http/uploads-config.js +35 -0
- package/esm/http/uploads-config.js.map +1 -0
- package/esm/http/uploads-types.d.ts +236 -0
- package/esm/http/uploads-types.d.ts.map +1 -0
- package/esm/image/image.d.ts +388 -0
- package/esm/image/image.d.ts.map +1 -0
- package/esm/image/image.js +602 -0
- package/esm/image/image.js.map +1 -0
- package/esm/image/index.d.ts +2 -0
- package/esm/image/index.d.ts.map +1 -0
- package/esm/index.d.ts +28 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -28
- package/esm/index.js.map +1 -1
- package/esm/logger/index.d.ts +3 -0
- package/esm/logger/index.d.ts.map +1 -0
- package/esm/logger/logger.d.ts +3 -0
- package/esm/logger/logger.d.ts.map +1 -0
- package/esm/logger/logger.js +16 -0
- package/esm/logger/logger.js.map +1 -0
- package/esm/logger/types.d.ts +39 -0
- package/esm/logger/types.d.ts.map +1 -0
- package/esm/mail/config.d.ts +83 -0
- package/esm/mail/config.d.ts.map +1 -0
- package/esm/mail/config.js +152 -0
- package/esm/mail/config.js.map +1 -0
- package/esm/mail/events.d.ts +96 -0
- package/esm/mail/events.d.ts.map +1 -0
- package/esm/mail/events.js +123 -0
- package/esm/mail/events.js.map +1 -0
- package/esm/mail/index.d.ts +10 -0
- package/esm/mail/index.d.ts.map +1 -0
- package/esm/mail/mail.d.ts +175 -0
- package/esm/mail/mail.d.ts.map +1 -0
- package/esm/mail/mail.js +286 -0
- package/esm/mail/mail.js.map +1 -0
- package/esm/mail/mailer-pool.d.ts +27 -0
- package/esm/mail/mailer-pool.d.ts.map +1 -0
- package/esm/mail/mailer-pool.js +143 -0
- package/esm/mail/mailer-pool.js.map +1 -0
- package/esm/mail/react-mail.d.ts +9 -0
- package/esm/mail/react-mail.d.ts.map +1 -0
- package/esm/mail/react-mail.js +28 -0
- package/esm/mail/react-mail.js.map +1 -0
- package/esm/mail/send-mail.d.ts +33 -0
- package/esm/mail/send-mail.d.ts.map +1 -0
- package/esm/mail/send-mail.js +309 -0
- package/esm/mail/send-mail.js.map +1 -0
- package/esm/mail/test-mailbox.d.ts +110 -0
- package/esm/mail/test-mailbox.d.ts.map +1 -0
- package/esm/mail/test-mailbox.js +143 -0
- package/esm/mail/test-mailbox.js.map +1 -0
- package/esm/mail/types.d.ts +245 -0
- package/esm/mail/types.d.ts.map +1 -0
- package/esm/mail/types.js +13 -0
- package/esm/mail/types.js.map +1 -0
- package/esm/manifest/manifest-manager.d.ts +74 -0
- package/esm/manifest/manifest-manager.d.ts.map +1 -0
- package/esm/manifest/manifest-manager.js +88 -0
- package/esm/manifest/manifest-manager.js.map +1 -0
- package/esm/production/build-app-production.d.ts +6 -0
- package/esm/production/build-app-production.d.ts.map +1 -0
- package/esm/production/build-app-production.js +8 -0
- package/esm/production/build-app-production.js.map +1 -0
- package/esm/production/esbuild-plugins.d.ts +5 -0
- package/esm/production/esbuild-plugins.d.ts.map +1 -0
- package/esm/production/esbuild-plugins.js +23 -0
- package/esm/production/esbuild-plugins.js.map +1 -0
- package/esm/production/production-builder.d.ts +76 -0
- package/esm/production/production-builder.d.ts.map +1 -0
- package/esm/production/production-builder.js +247 -0
- package/esm/production/production-builder.js.map +1 -0
- package/esm/react/index.d.ts +14 -0
- package/esm/react/index.d.ts.map +1 -0
- package/esm/react/index.js +65 -0
- package/esm/react/index.js.map +1 -0
- package/esm/repositories/adapters/cascade/cascade-adapter.d.ts +85 -0
- package/esm/repositories/adapters/cascade/cascade-adapter.d.ts.map +1 -0
- package/esm/repositories/adapters/cascade/cascade-adapter.js +179 -0
- package/esm/repositories/adapters/cascade/cascade-adapter.js.map +1 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.d.ts +124 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.d.ts.map +1 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.js +267 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.js.map +1 -0
- package/esm/repositories/adapters/cascade/filter-applicator.d.ts +62 -0
- package/esm/repositories/adapters/cascade/filter-applicator.d.ts.map +1 -0
- package/esm/repositories/adapters/cascade/filter-applicator.js +423 -0
- package/esm/repositories/adapters/cascade/filter-applicator.js.map +1 -0
- package/esm/repositories/adapters/cascade/index.d.ts +7 -0
- package/esm/repositories/adapters/cascade/index.d.ts.map +1 -0
- package/esm/repositories/contracts/index.d.ts +8 -0
- package/esm/repositories/contracts/index.d.ts.map +1 -0
- package/esm/repositories/contracts/query-builder.contract.d.ts +279 -0
- package/esm/repositories/contracts/query-builder.contract.d.ts.map +1 -0
- package/esm/repositories/contracts/repository-adapter.contract.d.ts +183 -0
- package/esm/repositories/contracts/repository-adapter.contract.d.ts.map +1 -0
- package/esm/repositories/contracts/types.d.ts +278 -0
- package/esm/repositories/contracts/types.d.ts.map +1 -0
- package/esm/repositories/index.d.ts +8 -0
- package/esm/repositories/index.d.ts.map +1 -0
- package/esm/repositories/repository.manager.d.ts +619 -0
- package/esm/repositories/repository.manager.d.ts.map +1 -0
- package/esm/repositories/repository.manager.js +978 -0
- package/esm/repositories/repository.manager.js.map +1 -0
- package/esm/resource/define-resource.js +58 -0
- package/esm/resource/define-resource.js.map +1 -0
- package/esm/resource/index.d.ts +5 -0
- package/esm/resource/index.d.ts.map +1 -0
- package/esm/resource/resource-field-builder.d.ts +83 -0
- package/esm/resource/resource-field-builder.d.ts.map +1 -0
- package/esm/resource/resource-field-builder.js +189 -0
- package/esm/resource/resource-field-builder.js.map +1 -0
- package/esm/resource/resource.d.ts +105 -0
- package/esm/resource/resource.d.ts.map +1 -0
- package/esm/resource/resource.js +231 -0
- package/esm/resource/resource.js.map +1 -0
- package/esm/resource/types.d.ts +40 -0
- package/esm/resource/types.d.ts.map +1 -0
- package/esm/restful/index.d.ts +2 -0
- package/esm/restful/index.d.ts.map +1 -0
- package/esm/restful/restful.d.ts +110 -0
- package/esm/restful/restful.d.ts.map +1 -0
- package/esm/restful/restful.js +317 -0
- package/esm/restful/restful.js.map +1 -0
- package/esm/router/index.d.ts +4 -0
- package/esm/router/index.d.ts.map +1 -0
- package/esm/router/route-registry.d.ts +30 -0
- package/esm/router/route-registry.d.ts.map +1 -0
- package/esm/router/route-registry.js +67 -0
- package/esm/router/route-registry.js.map +1 -0
- package/esm/router/route.d.ts +34 -0
- package/esm/router/route.d.ts.map +1 -0
- package/esm/router/router.d.ts +169 -0
- package/esm/router/router.d.ts.map +1 -0
- package/esm/router/router.js +578 -0
- package/esm/router/router.js.map +1 -0
- package/esm/router/types.d.ts +267 -0
- package/esm/router/types.d.ts.map +1 -0
- package/esm/router/utils.d.ts +5 -0
- package/esm/router/utils.d.ts.map +1 -0
- package/esm/router/utils.js +6 -0
- package/esm/router/utils.js.map +1 -0
- package/esm/storage/config.d.ts +15 -0
- package/esm/storage/config.d.ts.map +1 -0
- package/esm/storage/config.js +32 -0
- package/esm/storage/config.js.map +1 -0
- package/esm/storage/context/storage-driver-context.d.ts +69 -0
- package/esm/storage/context/storage-driver-context.d.ts.map +1 -0
- package/esm/storage/context/storage-driver-context.js +80 -0
- package/esm/storage/context/storage-driver-context.js.map +1 -0
- package/esm/storage/drivers/cloud-driver.d.ts +196 -0
- package/esm/storage/drivers/cloud-driver.d.ts.map +1 -0
- package/esm/storage/drivers/cloud-driver.js +697 -0
- package/esm/storage/drivers/cloud-driver.js.map +1 -0
- package/esm/storage/drivers/do-spaces-driver.d.ts +43 -0
- package/esm/storage/drivers/do-spaces-driver.d.ts.map +1 -0
- package/esm/storage/drivers/do-spaces-driver.js +50 -0
- package/esm/storage/drivers/do-spaces-driver.js.map +1 -0
- package/esm/storage/drivers/local-driver.d.ts +151 -0
- package/esm/storage/drivers/local-driver.d.ts.map +1 -0
- package/esm/storage/drivers/local-driver.js +448 -0
- package/esm/storage/drivers/local-driver.js.map +1 -0
- package/esm/storage/drivers/r2-driver.d.ts +47 -0
- package/esm/storage/drivers/r2-driver.d.ts.map +1 -0
- package/esm/storage/drivers/r2-driver.js +60 -0
- package/esm/storage/drivers/r2-driver.js.map +1 -0
- package/esm/storage/drivers/s3-driver.d.ts +32 -0
- package/esm/storage/drivers/s3-driver.d.ts.map +1 -0
- package/esm/storage/drivers/s3-driver.js +37 -0
- package/esm/storage/drivers/s3-driver.js.map +1 -0
- package/esm/storage/index.d.ts +13 -0
- package/esm/storage/index.d.ts.map +1 -0
- package/esm/storage/scoped-storage.d.ts +514 -0
- package/esm/storage/scoped-storage.d.ts.map +1 -0
- package/esm/storage/scoped-storage.js +656 -0
- package/esm/storage/scoped-storage.js.map +1 -0
- package/esm/storage/storage-file.d.ts +216 -0
- package/esm/storage/storage-file.d.ts.map +1 -0
- package/esm/storage/storage-file.js +358 -0
- package/esm/storage/storage-file.js.map +1 -0
- package/esm/storage/storage.d.ts +583 -0
- package/esm/storage/storage.d.ts.map +1 -0
- package/esm/storage/storage.js +945 -0
- package/esm/storage/storage.js.map +1 -0
- package/esm/storage/types.d.ts +909 -0
- package/esm/storage/types.d.ts.map +1 -0
- package/esm/storage/utils/mime.d.ts +33 -0
- package/esm/storage/utils/mime.d.ts.map +1 -0
- package/esm/storage/utils/mime.js +45 -0
- package/esm/storage/utils/mime.js.map +1 -0
- package/esm/store/index.d.ts +25 -0
- package/esm/store/index.d.ts.map +1 -0
- package/esm/store/index.js +52 -0
- package/esm/store/index.js.map +1 -0
- package/esm/utils/app-log.d.ts +8 -0
- package/esm/utils/app-log.d.ts.map +1 -0
- package/esm/utils/app-log.js +7 -0
- package/esm/utils/app-log.js.map +1 -0
- package/esm/utils/cleanup-temp-files.d.ts +5 -0
- package/esm/utils/cleanup-temp-files.d.ts.map +1 -0
- package/esm/utils/database-log.d.ts +25 -0
- package/esm/utils/database-log.d.ts.map +1 -0
- package/esm/utils/database-log.js +43 -0
- package/esm/utils/database-log.js.map +1 -0
- package/esm/utils/download-file.d.ts +3 -0
- package/esm/utils/download-file.d.ts.map +1 -0
- package/esm/utils/environment.d.ts +4 -0
- package/esm/utils/environment.d.ts.map +1 -0
- package/esm/utils/environment.js +6 -0
- package/esm/utils/environment.js.map +1 -0
- package/esm/utils/get-localized.d.ts +10 -0
- package/esm/utils/get-localized.d.ts.map +1 -0
- package/esm/utils/get-localized.js +15 -0
- package/esm/utils/get-localized.js.map +1 -0
- package/esm/utils/index.d.ts +12 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/internal.d.ts +4 -0
- package/esm/utils/internal.d.ts.map +1 -0
- package/esm/utils/paths.d.ts +55 -0
- package/esm/utils/paths.d.ts.map +1 -0
- package/esm/utils/paths.js +89 -0
- package/esm/utils/paths.js.map +1 -0
- package/esm/utils/promise-all-object.d.ts +8 -0
- package/esm/utils/promise-all-object.d.ts.map +1 -0
- package/esm/utils/promise-all-object.js +12 -0
- package/esm/utils/promise-all-object.js.map +1 -0
- package/esm/utils/queue.d.ts +49 -0
- package/esm/utils/queue.d.ts.map +1 -0
- package/esm/utils/queue.js +89 -0
- package/esm/utils/queue.js.map +1 -0
- package/esm/utils/sleep.d.ts +2 -0
- package/esm/utils/sleep.d.ts.map +1 -0
- package/esm/utils/sleep.js +3 -0
- package/esm/utils/sleep.js.map +1 -0
- package/esm/utils/sluggable.d.ts +5 -0
- package/esm/utils/sluggable.d.ts.map +1 -0
- package/esm/utils/sluggable.js +15 -0
- package/esm/utils/sluggable.js.map +1 -0
- package/esm/utils/to-json.d.ts +2 -0
- package/esm/utils/to-json.d.ts.map +1 -0
- package/esm/utils/to-json.js +26 -0
- package/esm/utils/to-json.js.map +1 -0
- package/esm/utils/types.d.ts +22 -0
- package/esm/utils/types.d.ts.map +1 -0
- package/esm/utils/urls.d.ts +21 -0
- package/esm/utils/urls.d.ts.map +1 -0
- package/esm/utils/urls.js +31 -0
- package/esm/utils/urls.js.map +1 -0
- package/esm/validation/database/exists-except-current-id.d.ts +7 -0
- package/esm/validation/database/exists-except-current-id.d.ts.map +1 -0
- package/esm/validation/database/exists-except-current-id.js +23 -0
- package/esm/validation/database/exists-except-current-id.js.map +1 -0
- package/esm/validation/database/exists-except-current-user.d.ts +7 -0
- package/esm/validation/database/exists-except-current-user.d.ts.map +1 -0
- package/esm/validation/database/exists-except-current-user.js +25 -0
- package/esm/validation/database/exists-except-current-user.js.map +1 -0
- package/esm/validation/database/exists.d.ts +7 -0
- package/esm/validation/database/exists.d.ts.map +1 -0
- package/esm/validation/database/exists.js +21 -0
- package/esm/validation/database/exists.js.map +1 -0
- package/esm/validation/database/index.d.ts +12 -0
- package/esm/validation/database/index.d.ts.map +1 -0
- package/esm/validation/database/types.d.ts +68 -0
- package/esm/validation/database/types.d.ts.map +1 -0
- package/esm/validation/database/unique-except-current-id.d.ts +7 -0
- package/esm/validation/database/unique-except-current-id.d.ts.map +1 -0
- package/esm/validation/database/unique-except-current-id.js +23 -0
- package/esm/validation/database/unique-except-current-id.js.map +1 -0
- package/esm/validation/database/unique-except-current-user.d.ts +7 -0
- package/esm/validation/database/unique-except-current-user.d.ts.map +1 -0
- package/esm/validation/database/unique-except-current-user.js +25 -0
- package/esm/validation/database/unique-except-current-user.js.map +1 -0
- package/esm/validation/database/unique.d.ts +7 -0
- package/esm/validation/database/unique.d.ts.map +1 -0
- package/esm/validation/database/unique.js +30 -0
- package/esm/validation/database/unique.js.map +1 -0
- package/esm/validation/file/file.d.ts +22 -0
- package/esm/validation/file/file.d.ts.map +1 -0
- package/esm/validation/file/file.js +60 -0
- package/esm/validation/file/file.js.map +1 -0
- package/esm/validation/file/index.d.ts +6 -0
- package/esm/validation/file/index.d.ts.map +1 -0
- package/esm/validation/index.d.ts +16 -0
- package/esm/validation/index.d.ts.map +1 -0
- package/esm/validation/init.d.ts +7 -0
- package/esm/validation/init.d.ts.map +1 -0
- package/esm/validation/init.js +36 -0
- package/esm/validation/init.js.map +1 -0
- package/esm/validation/plugins/database-plugin.d.ts +14 -0
- package/esm/validation/plugins/database-plugin.d.ts.map +1 -0
- package/esm/validation/plugins/database-plugin.js +95 -0
- package/esm/validation/plugins/database-plugin.js.map +1 -0
- package/esm/validation/plugins/file-plugin.d.ts +11 -0
- package/esm/validation/plugins/file-plugin.d.ts.map +1 -0
- package/esm/validation/plugins/file-plugin.js +17 -0
- package/esm/validation/plugins/file-plugin.js.map +1 -0
- package/esm/validation/plugins/index.d.ts +9 -0
- package/esm/validation/plugins/index.d.ts.map +1 -0
- package/esm/validation/plugins/localized-plugin.d.ts +11 -0
- package/esm/validation/plugins/localized-plugin.d.ts.map +1 -0
- package/esm/validation/plugins/localized-plugin.js +19 -0
- package/esm/validation/plugins/localized-plugin.js.map +1 -0
- package/esm/validation/types.d.ts +87 -0
- package/esm/validation/types.d.ts.map +1 -0
- package/esm/validation/validateAll.d.ts +7 -0
- package/esm/validation/validateAll.d.ts.map +1 -0
- package/esm/validation/validateAll.js +60 -0
- package/esm/validation/validateAll.js.map +1 -0
- package/esm/validation/validators/file-validator.d.ts +46 -0
- package/esm/validation/validators/file-validator.d.ts.map +1 -0
- package/esm/validation/validators/file-validator.js +112 -0
- package/esm/validation/validators/file-validator.js.map +1 -0
- package/esm/validation/validators/index.d.ts +7 -0
- package/esm/validation/validators/index.d.ts.map +1 -0
- package/esm/warlock-config/default-configurations.d.ts +3 -0
- package/esm/warlock-config/default-configurations.d.ts.map +1 -0
- package/esm/warlock-config/default-configurations.js +8 -0
- package/esm/warlock-config/default-configurations.js.map +1 -0
- package/esm/warlock-config/define-config.d.ts +3 -0
- package/esm/warlock-config/define-config.d.ts.map +1 -0
- package/esm/warlock-config/define-config.js +3 -0
- package/esm/warlock-config/define-config.js.map +1 -0
- package/esm/warlock-config/index.d.ts +4 -0
- package/esm/warlock-config/index.d.ts.map +1 -0
- package/esm/warlock-config/types.d.ts +79 -0
- package/esm/warlock-config/types.d.ts.map +1 -0
- package/esm/warlock-config/warlock-config.manager.d.ts +83 -0
- package/esm/warlock-config/warlock-config.manager.d.ts.map +1 -0
- package/esm/warlock-config/warlock-config.manager.js +141 -0
- package/esm/warlock-config/warlock-config.manager.js.map +1 -0
- package/package.json +66 -71
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
import config from'@mongez/config';import events from'@mongez/events';import {fileExistsAsync}from'@mongez/fs';import {isScalar,isIterable,isPlainObject}from'@mongez/supportive-is';import {log}from'@warlock.js/logger';import fs from'fs';import mime from'mime';import path from'path';import {renderReact}from'../react/index.js';var ResponseStatus;
|
|
2
|
+
(function (ResponseStatus) {
|
|
3
|
+
ResponseStatus[ResponseStatus["OK"] = 200] = "OK";
|
|
4
|
+
ResponseStatus[ResponseStatus["CREATED"] = 201] = "CREATED";
|
|
5
|
+
ResponseStatus[ResponseStatus["ACCEPTED"] = 202] = "ACCEPTED";
|
|
6
|
+
ResponseStatus[ResponseStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
7
|
+
ResponseStatus[ResponseStatus["FOUND"] = 302] = "FOUND";
|
|
8
|
+
ResponseStatus[ResponseStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
9
|
+
ResponseStatus[ResponseStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
10
|
+
ResponseStatus[ResponseStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
11
|
+
ResponseStatus[ResponseStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
12
|
+
ResponseStatus[ResponseStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
13
|
+
ResponseStatus[ResponseStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
14
|
+
ResponseStatus[ResponseStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
15
|
+
ResponseStatus[ResponseStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
16
|
+
ResponseStatus[ResponseStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
17
|
+
ResponseStatus[ResponseStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
18
|
+
ResponseStatus[ResponseStatus["CONFLICT"] = 409] = "CONFLICT";
|
|
19
|
+
ResponseStatus[ResponseStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
20
|
+
ResponseStatus[ResponseStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
21
|
+
ResponseStatus[ResponseStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
22
|
+
})(ResponseStatus || (ResponseStatus = {}));
|
|
23
|
+
class Response {
|
|
24
|
+
/**
|
|
25
|
+
* Current route
|
|
26
|
+
*/
|
|
27
|
+
route;
|
|
28
|
+
/**
|
|
29
|
+
* Fastify response object
|
|
30
|
+
*/
|
|
31
|
+
baseResponse;
|
|
32
|
+
/**
|
|
33
|
+
* Current status code
|
|
34
|
+
*/
|
|
35
|
+
currentStatusCode = 200;
|
|
36
|
+
/**
|
|
37
|
+
* Current response body
|
|
38
|
+
*/
|
|
39
|
+
currentBody;
|
|
40
|
+
/**
|
|
41
|
+
* A flag to determine if response is being sent
|
|
42
|
+
*/
|
|
43
|
+
isSending = false;
|
|
44
|
+
/**
|
|
45
|
+
* Request object
|
|
46
|
+
*/
|
|
47
|
+
request;
|
|
48
|
+
/**
|
|
49
|
+
* Internal events related to this particular response object
|
|
50
|
+
*/
|
|
51
|
+
events = new Map();
|
|
52
|
+
/**
|
|
53
|
+
* Parsed body
|
|
54
|
+
* This will return the parsed body of the response
|
|
55
|
+
* Please note that if this property is called before the response is sent, it will return undefined
|
|
56
|
+
*/
|
|
57
|
+
parsedBody;
|
|
58
|
+
/**
|
|
59
|
+
* Get Current response body
|
|
60
|
+
*/
|
|
61
|
+
get body() {
|
|
62
|
+
return this.currentBody;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set response body
|
|
66
|
+
*/
|
|
67
|
+
set body(body) {
|
|
68
|
+
this.currentBody = body;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Add event on sending response
|
|
72
|
+
*/
|
|
73
|
+
onSending(callback) {
|
|
74
|
+
this.events.set("sending", [...(this.events.get("sending") || []), callback]);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Add event on sent response
|
|
79
|
+
*/
|
|
80
|
+
onSent(callback) {
|
|
81
|
+
this.events.set("sent", [...(this.events.get("sent") || []), callback]);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Set the Fastify response object
|
|
86
|
+
*/
|
|
87
|
+
setResponse(response) {
|
|
88
|
+
this.baseResponse = response;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reset the response state
|
|
93
|
+
*/
|
|
94
|
+
reset() {
|
|
95
|
+
this.route = {};
|
|
96
|
+
this.currentBody = null;
|
|
97
|
+
this.currentStatusCode = 200;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set current route
|
|
101
|
+
*/
|
|
102
|
+
setRoute(route) {
|
|
103
|
+
this.route = route;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the content type
|
|
108
|
+
*/
|
|
109
|
+
get contentType() {
|
|
110
|
+
return this.baseResponse.getHeader("Content-Type");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Set the content type
|
|
114
|
+
*/
|
|
115
|
+
setContentType(contentType) {
|
|
116
|
+
this.baseResponse.header("Content-Type", contentType);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the status code
|
|
121
|
+
*/
|
|
122
|
+
get statusCode() {
|
|
123
|
+
return this.currentStatusCode ?? this.baseResponse.statusCode;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Check if response status is ok
|
|
127
|
+
*/
|
|
128
|
+
get isOk() {
|
|
129
|
+
return this.currentStatusCode >= 200 && this.currentStatusCode < 300;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if the response has been sent
|
|
133
|
+
*/
|
|
134
|
+
get sent() {
|
|
135
|
+
return this.baseResponse.sent;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Add a listener to the response event
|
|
139
|
+
*/
|
|
140
|
+
static on(event, listener) {
|
|
141
|
+
return events.subscribe(`response.${event}`, listener);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Trigger the response event
|
|
145
|
+
*/
|
|
146
|
+
static async trigger(event, ...args) {
|
|
147
|
+
// make a timeout to make sure the request events is executed first
|
|
148
|
+
return new Promise((resolve) => {
|
|
149
|
+
setTimeout(async () => {
|
|
150
|
+
await events.triggerAllAsync(`response.${event}`, ...args);
|
|
151
|
+
resolve(true);
|
|
152
|
+
}, 0);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Parse body
|
|
157
|
+
*/
|
|
158
|
+
async parseBody() {
|
|
159
|
+
return await this.parse(this.currentBody);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Parse the given value
|
|
163
|
+
*/
|
|
164
|
+
async parse(value) {
|
|
165
|
+
// if it is a falsy value, return it
|
|
166
|
+
if (!value || isScalar(value))
|
|
167
|
+
return value;
|
|
168
|
+
// if it has a `toJSON` method, call it and await the result then return it
|
|
169
|
+
if (value.toJSON) {
|
|
170
|
+
value.request = this.request;
|
|
171
|
+
return await value.toJSON();
|
|
172
|
+
}
|
|
173
|
+
// if it is iterable, an array or array-like object then parse each item
|
|
174
|
+
if (isIterable(value)) {
|
|
175
|
+
const values = Array.from(value);
|
|
176
|
+
return Promise.all(values.map(async (item) => {
|
|
177
|
+
return await this.parse(item);
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
// if not plain object, then return it
|
|
181
|
+
if (!isPlainObject(value)) {
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
// loop over the object and check if the value and call `parse` on it
|
|
185
|
+
for (const key in value) {
|
|
186
|
+
const subValue = value[key];
|
|
187
|
+
value[key] = await this.parse(subValue);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Make a log message
|
|
193
|
+
*/
|
|
194
|
+
log(message, level = "info") {
|
|
195
|
+
if (!config.get("http.log"))
|
|
196
|
+
return;
|
|
197
|
+
log({
|
|
198
|
+
module: "response",
|
|
199
|
+
action: this.route.method + " " + this.route.path.replace("/*", "") + `:${this.request.id}`,
|
|
200
|
+
message,
|
|
201
|
+
type: level,
|
|
202
|
+
context: {
|
|
203
|
+
request: this.request,
|
|
204
|
+
response: this,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Check if returning response is json
|
|
210
|
+
*/
|
|
211
|
+
get isJson() {
|
|
212
|
+
return this.getHeader("Content-Type") === "application/json";
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Send the response
|
|
216
|
+
* @param data - Response data
|
|
217
|
+
* @param statusCode - HTTP status code
|
|
218
|
+
* @param triggerEvents - Whether to trigger response events (default: true)
|
|
219
|
+
*/
|
|
220
|
+
async send(data, statusCode, triggerEvents = true) {
|
|
221
|
+
if (statusCode) {
|
|
222
|
+
this.currentStatusCode = statusCode;
|
|
223
|
+
}
|
|
224
|
+
if (data === this)
|
|
225
|
+
return this;
|
|
226
|
+
if (data) {
|
|
227
|
+
this.currentBody = data;
|
|
228
|
+
}
|
|
229
|
+
if (!this.currentStatusCode) {
|
|
230
|
+
this.currentStatusCode = 200;
|
|
231
|
+
}
|
|
232
|
+
this.log("Sending response");
|
|
233
|
+
// trigger the sending event
|
|
234
|
+
if (Array.isArray(this.currentBody) || isPlainObject(this.currentBody)) {
|
|
235
|
+
this.setContentType("application/json");
|
|
236
|
+
}
|
|
237
|
+
if (triggerEvents) {
|
|
238
|
+
await Response.trigger("sending", this);
|
|
239
|
+
for (const callback of this.events.get("sending") || []) {
|
|
240
|
+
await callback(this);
|
|
241
|
+
}
|
|
242
|
+
if (this.isJson) {
|
|
243
|
+
await Response.trigger("sendingJson", this);
|
|
244
|
+
for (const callback of this.events.get("sendingJson") || []) {
|
|
245
|
+
await callback(this);
|
|
246
|
+
}
|
|
247
|
+
if (this.isOk) {
|
|
248
|
+
await Response.trigger("sendingSuccessJson", this);
|
|
249
|
+
for (const callback of this.events.get("sendingSuccessJson") || []) {
|
|
250
|
+
await callback(this);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// parse the body and make sure it is transformed to sync data instead of async data
|
|
256
|
+
if (typeof this.currentBody !== "string") {
|
|
257
|
+
this.parsedBody = await this.parseBody();
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
this.parsedBody = data;
|
|
261
|
+
}
|
|
262
|
+
// Set the status first
|
|
263
|
+
this.baseResponse.status(this.currentStatusCode);
|
|
264
|
+
// Then send the response with the parsed body
|
|
265
|
+
await this.baseResponse.send(this.parsedBody);
|
|
266
|
+
this.log("Response sent");
|
|
267
|
+
if (triggerEvents) {
|
|
268
|
+
// trigger the sent event
|
|
269
|
+
Response.trigger("sent", this);
|
|
270
|
+
for (const callback of this.events.get("sent") || []) {
|
|
271
|
+
callback(this);
|
|
272
|
+
}
|
|
273
|
+
// trigger the success event if the status code is 2xx
|
|
274
|
+
if (this.currentStatusCode >= 200 && this.currentStatusCode < 300) {
|
|
275
|
+
Response.trigger("success", this);
|
|
276
|
+
}
|
|
277
|
+
// trigger the successCreate event if the status code is 201
|
|
278
|
+
if (this.currentStatusCode === 201) {
|
|
279
|
+
Response.trigger("successCreate", this);
|
|
280
|
+
}
|
|
281
|
+
// trigger the badRequest event if the status code is 400
|
|
282
|
+
if (this.currentStatusCode === 400) {
|
|
283
|
+
Response.trigger("badRequest", this);
|
|
284
|
+
}
|
|
285
|
+
// trigger the unauthorized event if the status code is 401
|
|
286
|
+
if (this.currentStatusCode === 401) {
|
|
287
|
+
Response.trigger("unauthorized", this);
|
|
288
|
+
}
|
|
289
|
+
// trigger the forbidden event if the status code is 403
|
|
290
|
+
if (this.currentStatusCode === 403) {
|
|
291
|
+
Response.trigger("forbidden", this);
|
|
292
|
+
}
|
|
293
|
+
// trigger the notFound event if the status code is 404
|
|
294
|
+
if (this.currentStatusCode === 404) {
|
|
295
|
+
Response.trigger("notFound", this);
|
|
296
|
+
}
|
|
297
|
+
// trigger the throttled event if the status code is 429
|
|
298
|
+
if (this.currentStatusCode === 429) {
|
|
299
|
+
Response.trigger("throttled", this);
|
|
300
|
+
}
|
|
301
|
+
// trigger the serverError event if the status code is 500
|
|
302
|
+
if (this.currentStatusCode === 500) {
|
|
303
|
+
Response.trigger("serverError", this);
|
|
304
|
+
}
|
|
305
|
+
// trigger the error event if the status code is 4xx or 5xx
|
|
306
|
+
if (this.currentStatusCode >= 400) {
|
|
307
|
+
Response.trigger("error", this);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Send html response
|
|
314
|
+
*/
|
|
315
|
+
html(data, statusCode) {
|
|
316
|
+
return this.setContentType("text/html").send(data, statusCode);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Render the given react component
|
|
320
|
+
*/
|
|
321
|
+
render(element, status = 200) {
|
|
322
|
+
return this.setStatusCode(status).html(renderReact(element));
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Send xml response
|
|
326
|
+
*/
|
|
327
|
+
xml(data, statusCode) {
|
|
328
|
+
return this.setContentType("text/xml").send(data, statusCode);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Send plain text response
|
|
332
|
+
*/
|
|
333
|
+
text(data, statusCode) {
|
|
334
|
+
return this.setContentType("text/plain").send(data, statusCode);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Create a streaming response for progressive/chunked data sending
|
|
338
|
+
*
|
|
339
|
+
* This method allows you to send data in chunks and control when the response ends.
|
|
340
|
+
* Perfect for Server-Sent Events (SSE), progressive rendering, or streaming large responses.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const stream = response.stream("text/html");
|
|
345
|
+
* stream.send("<html><body>");
|
|
346
|
+
* stream.send("<h1>Hello</h1>");
|
|
347
|
+
* stream.render(<MyComponent />);
|
|
348
|
+
* stream.send("</body></html>");
|
|
349
|
+
* stream.end();
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* @param contentType - The content type for the stream (default: "text/plain")
|
|
353
|
+
* @returns Stream controller with send(), render(), and end() methods
|
|
354
|
+
*/
|
|
355
|
+
stream(contentType = "text/plain") {
|
|
356
|
+
// Set headers using the response API
|
|
357
|
+
this.setContentType(contentType);
|
|
358
|
+
this.header("Transfer-Encoding", "chunked");
|
|
359
|
+
this.header("Cache-Control", "no-cache");
|
|
360
|
+
this.header("Connection", "keep-alive");
|
|
361
|
+
this.header("X-Content-Type-Options", "nosniff");
|
|
362
|
+
// Trigger sending events
|
|
363
|
+
Response.trigger("sending", this);
|
|
364
|
+
for (const callback of this.events.get("sending") || []) {
|
|
365
|
+
callback(this);
|
|
366
|
+
}
|
|
367
|
+
this.log("Starting stream");
|
|
368
|
+
// Track stream state
|
|
369
|
+
let isEnded = false;
|
|
370
|
+
const chunks = [];
|
|
371
|
+
// Write headers to start the stream
|
|
372
|
+
// Note: We use raw here because we need chunked encoding control
|
|
373
|
+
// This is the only valid use case for bypassing Fastify's abstraction
|
|
374
|
+
this.baseResponse.raw.writeHead(this.statusCode, this.getHeaders());
|
|
375
|
+
return {
|
|
376
|
+
/**
|
|
377
|
+
* Send a chunk of data to the client
|
|
378
|
+
* @param data - Data to send (string, Buffer, or any serializable data)
|
|
379
|
+
*/
|
|
380
|
+
send: (data) => {
|
|
381
|
+
if (isEnded) {
|
|
382
|
+
throw new Error("Cannot send data: stream has already ended");
|
|
383
|
+
}
|
|
384
|
+
this.baseResponse.raw.write(data);
|
|
385
|
+
return this;
|
|
386
|
+
},
|
|
387
|
+
/**
|
|
388
|
+
* Render a React component and send it as a chunk
|
|
389
|
+
* @param element - React element or component to render
|
|
390
|
+
*/
|
|
391
|
+
render: (element) => {
|
|
392
|
+
if (isEnded) {
|
|
393
|
+
throw new Error("Cannot render: stream has already ended");
|
|
394
|
+
}
|
|
395
|
+
const html = renderReact(element);
|
|
396
|
+
chunks.push(html);
|
|
397
|
+
this.baseResponse.raw.write(html);
|
|
398
|
+
return this;
|
|
399
|
+
},
|
|
400
|
+
/**
|
|
401
|
+
* End the stream and trigger completion events
|
|
402
|
+
*/
|
|
403
|
+
end: () => {
|
|
404
|
+
if (isEnded) {
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
isEnded = true;
|
|
408
|
+
// Store the streamed content for logging/debugging
|
|
409
|
+
this.currentBody = chunks;
|
|
410
|
+
this.parsedBody = chunks;
|
|
411
|
+
// End the response
|
|
412
|
+
this.baseResponse.raw.end();
|
|
413
|
+
this.log("Stream ended");
|
|
414
|
+
// Trigger sent events
|
|
415
|
+
Response.trigger("sent", this);
|
|
416
|
+
for (const callback of this.events.get("sent") || []) {
|
|
417
|
+
callback(this);
|
|
418
|
+
}
|
|
419
|
+
// Trigger success event if status is 2xx
|
|
420
|
+
if (this.isOk) {
|
|
421
|
+
Response.trigger("success", this);
|
|
422
|
+
}
|
|
423
|
+
// Trigger status-specific events
|
|
424
|
+
if (this.currentStatusCode === 201) {
|
|
425
|
+
Response.trigger("successCreate", this);
|
|
426
|
+
}
|
|
427
|
+
return this;
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* Check if the stream has ended
|
|
431
|
+
*/
|
|
432
|
+
get ended() {
|
|
433
|
+
return isEnded;
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Create a Server-Sent Events (SSE) stream
|
|
439
|
+
*
|
|
440
|
+
* SSE is a standard for pushing real-time updates from server to client.
|
|
441
|
+
* Perfect for live notifications, progress updates, or real-time data feeds.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* const sse = response.sse();
|
|
446
|
+
*
|
|
447
|
+
* // Send events
|
|
448
|
+
* sse.send("message", { text: "Hello!" });
|
|
449
|
+
* sse.send("notification", { type: "info", message: "Update available" }, "msg-123");
|
|
450
|
+
*
|
|
451
|
+
* // Keep connection alive
|
|
452
|
+
* const keepAlive = setInterval(() => sse.comment("ping"), 30000);
|
|
453
|
+
*
|
|
454
|
+
* // Clean up when done
|
|
455
|
+
* clearInterval(keepAlive);
|
|
456
|
+
* sse.end();
|
|
457
|
+
* ```
|
|
458
|
+
*
|
|
459
|
+
* @returns SSE controller with send(), comment(), and end() methods
|
|
460
|
+
*/
|
|
461
|
+
sse() {
|
|
462
|
+
// Set SSE-specific headers
|
|
463
|
+
this.setContentType("text/event-stream");
|
|
464
|
+
this.header("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
465
|
+
this.header("Connection", "keep-alive");
|
|
466
|
+
this.header("X-Accel-Buffering", "no"); // Disable nginx buffering
|
|
467
|
+
// Trigger sending events
|
|
468
|
+
Response.trigger("sending", this);
|
|
469
|
+
for (const callback of this.events.get("sending") || []) {
|
|
470
|
+
callback(this);
|
|
471
|
+
}
|
|
472
|
+
this.log("Starting SSE stream");
|
|
473
|
+
// Track stream state
|
|
474
|
+
let isEnded = false;
|
|
475
|
+
const events = [];
|
|
476
|
+
// Write headers to start the stream
|
|
477
|
+
this.baseResponse.raw.writeHead(this.statusCode, this.getHeaders());
|
|
478
|
+
return {
|
|
479
|
+
/**
|
|
480
|
+
* Send an SSE event
|
|
481
|
+
* @param event - Event name (e.g., "message", "notification")
|
|
482
|
+
* @param data - Event data (will be JSON stringified)
|
|
483
|
+
* @param id - Optional event ID for client-side tracking
|
|
484
|
+
*/
|
|
485
|
+
send: (event, data, id) => {
|
|
486
|
+
if (isEnded) {
|
|
487
|
+
throw new Error("Cannot send event: SSE stream has already ended");
|
|
488
|
+
}
|
|
489
|
+
let message = "";
|
|
490
|
+
if (id)
|
|
491
|
+
message += `id: ${id}\n`;
|
|
492
|
+
message += `event: ${event}\n`;
|
|
493
|
+
message += `data: ${JSON.stringify(data)}\n\n`;
|
|
494
|
+
events.push({ event, data, id });
|
|
495
|
+
this.baseResponse.raw.write(message);
|
|
496
|
+
return this;
|
|
497
|
+
},
|
|
498
|
+
/**
|
|
499
|
+
* Send a comment (keeps connection alive, invisible to client)
|
|
500
|
+
* Useful for preventing timeout on long-lived connections
|
|
501
|
+
* @param text - Comment text
|
|
502
|
+
*/
|
|
503
|
+
comment: (text) => {
|
|
504
|
+
if (isEnded) {
|
|
505
|
+
throw new Error("Cannot send comment: SSE stream has already ended");
|
|
506
|
+
}
|
|
507
|
+
this.baseResponse.raw.write(`: ${text}\n\n`);
|
|
508
|
+
return this;
|
|
509
|
+
},
|
|
510
|
+
/**
|
|
511
|
+
* End the SSE stream and trigger completion events
|
|
512
|
+
*/
|
|
513
|
+
end: () => {
|
|
514
|
+
if (isEnded) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
isEnded = true;
|
|
518
|
+
// Store the events for logging/debugging
|
|
519
|
+
this.currentBody = events;
|
|
520
|
+
this.parsedBody = events;
|
|
521
|
+
// End the response
|
|
522
|
+
this.baseResponse.raw.end();
|
|
523
|
+
this.log("SSE stream ended");
|
|
524
|
+
// Trigger sent events
|
|
525
|
+
Response.trigger("sent", this);
|
|
526
|
+
for (const callback of this.events.get("sent") || []) {
|
|
527
|
+
callback(this);
|
|
528
|
+
}
|
|
529
|
+
// Trigger success event if status is 2xx
|
|
530
|
+
if (this.isOk) {
|
|
531
|
+
Response.trigger("success", this);
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
/**
|
|
535
|
+
* Check if the stream has ended
|
|
536
|
+
*/
|
|
537
|
+
get ended() {
|
|
538
|
+
return isEnded;
|
|
539
|
+
},
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Set the status code
|
|
544
|
+
*/
|
|
545
|
+
setStatusCode(statusCode) {
|
|
546
|
+
this.currentStatusCode = statusCode;
|
|
547
|
+
return this;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Redirect the user to another route
|
|
551
|
+
*/
|
|
552
|
+
redirect(url, statusCode = 302) {
|
|
553
|
+
this.baseResponse.redirect(url, statusCode);
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Permanent redirect
|
|
558
|
+
*/
|
|
559
|
+
permanentRedirect(url) {
|
|
560
|
+
this.baseResponse.redirect(url, 301);
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Get the response time
|
|
565
|
+
*/
|
|
566
|
+
getResponseTime() {
|
|
567
|
+
return this.baseResponse.elapsedTime;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Remove a specific header
|
|
571
|
+
*/
|
|
572
|
+
removeHeader(key) {
|
|
573
|
+
this.baseResponse.removeHeader(key);
|
|
574
|
+
return this;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Get a specific header
|
|
578
|
+
*/
|
|
579
|
+
getHeader(key) {
|
|
580
|
+
return this.baseResponse.getHeader(key);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Get the response headers
|
|
584
|
+
*/
|
|
585
|
+
getHeaders() {
|
|
586
|
+
return this.baseResponse.getHeaders();
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Set multiple headers
|
|
590
|
+
*/
|
|
591
|
+
headers(headers) {
|
|
592
|
+
this.baseResponse.headers(headers);
|
|
593
|
+
return this;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Set the response header
|
|
597
|
+
*/
|
|
598
|
+
header(key, value) {
|
|
599
|
+
this.baseResponse.header(key, value);
|
|
600
|
+
return this;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Alias to header method
|
|
604
|
+
*/
|
|
605
|
+
setHeader(key, value) {
|
|
606
|
+
return this.header(key, value);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Send an error response with status code 500
|
|
610
|
+
*/
|
|
611
|
+
serverError(data) {
|
|
612
|
+
return this.send(data, 500);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Send a forbidden response with status code 403
|
|
616
|
+
*/
|
|
617
|
+
forbidden(data = {
|
|
618
|
+
error: "You are not allowed to access this resource, FORBIDDEN",
|
|
619
|
+
}) {
|
|
620
|
+
return this.send(data, 403);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Send a service unavailable response with status code 503
|
|
624
|
+
*/
|
|
625
|
+
serviceUnavailable(data) {
|
|
626
|
+
return this.send(data, 503);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Send an unauthorized response with status code 401
|
|
630
|
+
*/
|
|
631
|
+
unauthorized(data = {
|
|
632
|
+
error: "unauthorized",
|
|
633
|
+
}) {
|
|
634
|
+
return this.send(data, 401);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Send a not found response with status code 404
|
|
638
|
+
*/
|
|
639
|
+
notFound(data = {
|
|
640
|
+
error: "notFound",
|
|
641
|
+
}) {
|
|
642
|
+
return this.send(data, 404);
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Send a bad request response with status code 400
|
|
646
|
+
*/
|
|
647
|
+
badRequest(data) {
|
|
648
|
+
return this.send(data, 400);
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Send a success response with status code 201
|
|
652
|
+
*/
|
|
653
|
+
successCreate(data) {
|
|
654
|
+
return this.send(data, 201);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Send a success response
|
|
658
|
+
*/
|
|
659
|
+
success(data = { success: true }) {
|
|
660
|
+
return this.send(data);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Send a no content response with status code 204
|
|
664
|
+
*/
|
|
665
|
+
noContent() {
|
|
666
|
+
return this.baseResponse.status(204).send();
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Send an accepted response with status code 202
|
|
670
|
+
* Used for async operations that have been accepted but not yet processed
|
|
671
|
+
*/
|
|
672
|
+
accepted(data = { message: "Request accepted for processing" }) {
|
|
673
|
+
return this.send(data, 202);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Send a conflict response with status code 409
|
|
677
|
+
*/
|
|
678
|
+
conflict(data = { error: "Resource conflict" }) {
|
|
679
|
+
return this.send(data, 409);
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Send an unprocessable entity response with status code 422
|
|
683
|
+
* Used for semantic validation errors
|
|
684
|
+
*/
|
|
685
|
+
unprocessableEntity(data) {
|
|
686
|
+
return this.send(data, 422);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Apply response options (cache, disposition, etag)
|
|
690
|
+
* Shared helper for sendFile and sendBuffer
|
|
691
|
+
*/
|
|
692
|
+
applyResponseOptions(options, defaultFilename) {
|
|
693
|
+
// Set content type if provided
|
|
694
|
+
if (options.contentType) {
|
|
695
|
+
this.baseResponse.type(options.contentType);
|
|
696
|
+
}
|
|
697
|
+
// Set cache headers if specified
|
|
698
|
+
if (options.cacheTime) {
|
|
699
|
+
const cacheControl = options.immutable
|
|
700
|
+
? `public, max-age=${options.cacheTime}, immutable`
|
|
701
|
+
: `public, max-age=${options.cacheTime}`;
|
|
702
|
+
this.header("Cache-Control", cacheControl);
|
|
703
|
+
this.header("Expires", new Date(Date.now() + options.cacheTime * 1000).toUTCString());
|
|
704
|
+
}
|
|
705
|
+
// Set ETag if provided (for conditional requests)
|
|
706
|
+
if (options.etag) {
|
|
707
|
+
this.header("ETag", options.etag);
|
|
708
|
+
// Check If-None-Match for conditional request
|
|
709
|
+
const ifNoneMatch = this.request.header("if-none-match");
|
|
710
|
+
if (ifNoneMatch && ifNoneMatch === options.etag) {
|
|
711
|
+
this.log("Content not modified (ETag match), sending 304");
|
|
712
|
+
this.baseResponse.status(304).send();
|
|
713
|
+
return true; // Indicates 304 was sent
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
// Set Content-Disposition if inline or filename is specified
|
|
717
|
+
if (options.inline !== undefined || options.filename) {
|
|
718
|
+
const disposition = options.inline ? "inline" : "attachment";
|
|
719
|
+
const filename = options.filename || defaultFilename || "file";
|
|
720
|
+
this.header("Content-Disposition", `${disposition}; filename=\"${filename}\"`);
|
|
721
|
+
}
|
|
722
|
+
return false; // No 304 sent
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Send a file as a response
|
|
726
|
+
*/
|
|
727
|
+
async sendFile(filePath, options) {
|
|
728
|
+
this.log(`Sending file: ${filePath}`);
|
|
729
|
+
// Check if file exists first
|
|
730
|
+
if (!(await fileExistsAsync(filePath))) {
|
|
731
|
+
return this.notFound({
|
|
732
|
+
error: "File Not Found",
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
try {
|
|
736
|
+
// Normalize options to object format
|
|
737
|
+
const opts = typeof options === "number" ? { cacheTime: options } : options || {};
|
|
738
|
+
// Get file stats for ETag and Last-Modified
|
|
739
|
+
const stats = await fs.promises.stat(filePath);
|
|
740
|
+
const lastModified = stats.mtime;
|
|
741
|
+
// Generate ETag based on file size and modification time
|
|
742
|
+
const etag = `"${stats.size}-${stats.mtime.getTime()}"`;
|
|
743
|
+
// Set Last-Modified header
|
|
744
|
+
this.header("Last-Modified", lastModified.toUTCString());
|
|
745
|
+
this.header("ETag", etag);
|
|
746
|
+
// Set content type
|
|
747
|
+
const contentType = this.getFileContentType(filePath);
|
|
748
|
+
this.baseResponse.type(contentType);
|
|
749
|
+
// Apply common response options (cache, disposition)
|
|
750
|
+
const defaultFilename = path.basename(filePath);
|
|
751
|
+
const sent304 = this.applyResponseOptions({ ...opts, etag, contentType }, defaultFilename);
|
|
752
|
+
if (sent304)
|
|
753
|
+
return this.baseResponse;
|
|
754
|
+
// Check conditional request headers
|
|
755
|
+
const ifNoneMatch = this.request.header("if-none-match");
|
|
756
|
+
const ifModifiedSince = this.request.header("if-modified-since");
|
|
757
|
+
// Handle If-None-Match (ETag validation)
|
|
758
|
+
if (ifNoneMatch && ifNoneMatch === etag) {
|
|
759
|
+
this.log("File not modified (ETag match), sending 304");
|
|
760
|
+
return this.baseResponse.status(304).send();
|
|
761
|
+
}
|
|
762
|
+
// Handle If-Modified-Since (Last-Modified validation)
|
|
763
|
+
if (ifModifiedSince) {
|
|
764
|
+
const modifiedSinceDate = new Date(ifModifiedSince);
|
|
765
|
+
if (lastModified.getTime() <= modifiedSinceDate.getTime()) {
|
|
766
|
+
this.log("File not modified (Last-Modified check), sending 304");
|
|
767
|
+
return this.baseResponse.status(304).send();
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
// Use streaming for efficient file sending
|
|
771
|
+
const stream = fs.createReadStream(filePath);
|
|
772
|
+
// Handle stream errors
|
|
773
|
+
stream.on("error", (error) => {
|
|
774
|
+
this.log(`Error reading file: ${error.message}`, "error");
|
|
775
|
+
if (!this.baseResponse.sent) {
|
|
776
|
+
this.serverError({
|
|
777
|
+
error: "Error reading file",
|
|
778
|
+
message: error.message,
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
// Send the stream
|
|
783
|
+
return this.baseResponse.send(stream);
|
|
784
|
+
}
|
|
785
|
+
catch (error) {
|
|
786
|
+
this.log(`Error sending file: ${error.message}`, "error");
|
|
787
|
+
return this.serverError({
|
|
788
|
+
error: "Error sending file",
|
|
789
|
+
message: error.message,
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Send buffer as a response
|
|
795
|
+
* Useful for dynamically generated content (e.g., resized images, generated PDFs)
|
|
796
|
+
*/
|
|
797
|
+
sendBuffer(buffer, options) {
|
|
798
|
+
this.log("Sending buffer");
|
|
799
|
+
// Normalize options to object format
|
|
800
|
+
const opts = typeof options === "number" ? { cacheTime: options } : options || {};
|
|
801
|
+
// Apply common response options (cache, disposition, etag)
|
|
802
|
+
const sent304 = this.applyResponseOptions(opts);
|
|
803
|
+
if (sent304)
|
|
804
|
+
return this.baseResponse;
|
|
805
|
+
return this.baseResponse.send(buffer);
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Send an Image instance as a response
|
|
809
|
+
* Automatically detects image format and sets content type
|
|
810
|
+
*/
|
|
811
|
+
async sendImage(image, // Type as 'any' to avoid circular dependency with Image class
|
|
812
|
+
options) {
|
|
813
|
+
this.log("Sending image");
|
|
814
|
+
// Normalize options to object format
|
|
815
|
+
const opts = typeof options === "number" ? { cacheTime: options } : options || {};
|
|
816
|
+
// Get image metadata to determine format
|
|
817
|
+
const metadata = await image.metadata();
|
|
818
|
+
const format = metadata.format || "jpeg";
|
|
819
|
+
// Convert image to buffer
|
|
820
|
+
const buffer = await image.toBuffer();
|
|
821
|
+
// Auto-set content type if not provided
|
|
822
|
+
const contentType = opts.contentType || `image/${format}`;
|
|
823
|
+
// Auto-generate ETag if not provided
|
|
824
|
+
// Format: "format-widthxheight-size" (e.g., "jpeg-800x600-45231")
|
|
825
|
+
// This catches changes in dimensions, quality, filters, and format
|
|
826
|
+
if (!opts.etag) {
|
|
827
|
+
const width = metadata.width || 0;
|
|
828
|
+
const height = metadata.height || 0;
|
|
829
|
+
opts.etag = `"${format}-${width}x${height}-${buffer.length}"`;
|
|
830
|
+
}
|
|
831
|
+
// Apply common response options with auto-detected content type
|
|
832
|
+
const sent304 = this.applyResponseOptions({ ...opts, contentType });
|
|
833
|
+
if (sent304)
|
|
834
|
+
return this.baseResponse;
|
|
835
|
+
return this.baseResponse.send(buffer);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Send file and cache it
|
|
839
|
+
* Cache time in seconds
|
|
840
|
+
* Cache time will be one year
|
|
841
|
+
*/
|
|
842
|
+
sendCachedFile(path, cacheTime = 31536000) {
|
|
843
|
+
return this.sendFile(path, cacheTime);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Download the given file path
|
|
847
|
+
*/
|
|
848
|
+
download(path, filename) {
|
|
849
|
+
return this.downloadFile(path, filename);
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Download the given file path
|
|
853
|
+
*/
|
|
854
|
+
async downloadFile(filePath, filename) {
|
|
855
|
+
// Check if file exists first
|
|
856
|
+
if (!(await fileExistsAsync(filePath))) {
|
|
857
|
+
return this.notFound({
|
|
858
|
+
error: "File Not Found",
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
try {
|
|
862
|
+
if (!filename) {
|
|
863
|
+
filename = path.basename(filePath);
|
|
864
|
+
}
|
|
865
|
+
this.baseResponse.header("Content-Disposition", `attachment; filename="${filename}"`);
|
|
866
|
+
// this.baseResponse.header("Content-Type", this.getFileContentType(filePath));
|
|
867
|
+
this.baseResponse.header("Content-Type", "application/octet-stream");
|
|
868
|
+
const stream = fs.createReadStream(filePath);
|
|
869
|
+
// Handle stream errors
|
|
870
|
+
stream.on("error", (error) => {
|
|
871
|
+
this.log(`Error reading file for download: ${error.message}`, "error");
|
|
872
|
+
if (!this.baseResponse.sent) {
|
|
873
|
+
this.serverError({
|
|
874
|
+
error: "Error reading file",
|
|
875
|
+
message: error.message,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
return this.baseResponse.send(stream);
|
|
880
|
+
}
|
|
881
|
+
catch (error) {
|
|
882
|
+
this.log(`Error downloading file: ${error.message}`, "error");
|
|
883
|
+
return this.serverError({
|
|
884
|
+
error: "Error downloading file",
|
|
885
|
+
message: error.message,
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Get content type of the given path
|
|
891
|
+
*/
|
|
892
|
+
getFileContentType(filePath) {
|
|
893
|
+
const type = mime.getType(filePath) || "application/octet-stream";
|
|
894
|
+
return type;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Mark the response as failed
|
|
898
|
+
*/
|
|
899
|
+
failedSchema(result) {
|
|
900
|
+
const { errors, inputKey, inputError, status } = config.get("validation.response", {
|
|
901
|
+
errors: "errors",
|
|
902
|
+
inputKey: "input",
|
|
903
|
+
inputError: "error",
|
|
904
|
+
status: 400,
|
|
905
|
+
});
|
|
906
|
+
log.error("request", "validation", `${this.request.id} - Validation failed`);
|
|
907
|
+
return this.send({
|
|
908
|
+
[errors]: result.errors.map((error) => ({
|
|
909
|
+
[inputKey]: error.input,
|
|
910
|
+
[inputError]: error.error,
|
|
911
|
+
})),
|
|
912
|
+
}, status);
|
|
913
|
+
}
|
|
914
|
+
}export{Response,ResponseStatus};//# sourceMappingURL=response.js.map
|