@webda/core 4.0.0-beta.1 → 4.0.0-beta.3
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/README.md +252 -0
- package/lib/application/application.d.ts +437 -0
- package/lib/application/application.d.ts.map +1 -0
- package/lib/application/application.js +792 -0
- package/lib/application/application.js.map +1 -0
- package/lib/application/hooks.d.ts +34 -0
- package/lib/application/hooks.d.ts.map +1 -0
- package/lib/application/hooks.js +57 -0
- package/lib/application/hooks.js.map +1 -0
- package/lib/application/iapplication.d.ts +43 -0
- package/lib/application/iapplication.d.ts.map +1 -0
- package/lib/application/iapplication.js +2 -0
- package/lib/application/iapplication.js.map +1 -0
- package/lib/application/iconfiguration.d.ts +176 -0
- package/lib/application/iconfiguration.d.ts.map +1 -0
- package/lib/application/iconfiguration.js +8 -0
- package/lib/application/iconfiguration.js.map +1 -0
- package/lib/application/runner.d.ts +8 -0
- package/lib/application/runner.d.ts.map +1 -0
- package/lib/application/runner.js +26 -0
- package/lib/application/runner.js.map +1 -0
- package/lib/application/unpackedapplication.d.ts +104 -0
- package/lib/application/unpackedapplication.d.ts.map +1 -0
- package/lib/application/unpackedapplication.js +492 -0
- package/lib/application/unpackedapplication.js.map +1 -0
- package/lib/bin/cli-phase.d.ts +28 -0
- package/lib/bin/cli-phase.d.ts.map +1 -0
- package/lib/bin/cli-phase.js +44 -0
- package/lib/bin/cli-phase.js.map +1 -0
- package/lib/bin/cli.d.ts +161 -0
- package/lib/bin/cli.d.ts.map +1 -0
- package/lib/bin/cli.js +828 -0
- package/lib/bin/cli.js.map +1 -0
- package/lib/bin/launcher.d.ts +3 -0
- package/lib/bin/launcher.d.ts.map +1 -0
- package/lib/bin/launcher.js +50 -0
- package/lib/bin/launcher.js.map +1 -0
- package/lib/cache/cache.d.ts +33 -0
- package/lib/cache/cache.d.ts.map +1 -0
- package/lib/cache/cache.js +8 -0
- package/lib/cache/cache.js.map +1 -0
- package/lib/{services/configuration.d.ts → configurations/configuration.service.d.ts} +58 -49
- package/lib/configurations/configuration.service.d.ts.map +1 -0
- package/lib/configurations/configuration.service.js +248 -0
- package/lib/configurations/configuration.service.js.map +1 -0
- package/lib/configurations/fileconfiguration.service.d.ts +30 -0
- package/lib/configurations/fileconfiguration.service.d.ts.map +1 -0
- package/lib/configurations/fileconfiguration.service.js +65 -0
- package/lib/configurations/fileconfiguration.service.js.map +1 -0
- package/lib/configurations/kubernetesconfiguration.service.d.ts +43 -0
- package/lib/configurations/kubernetesconfiguration.service.d.ts.map +1 -0
- package/lib/configurations/kubernetesconfiguration.service.js +83 -0
- package/lib/configurations/kubernetesconfiguration.service.js.map +1 -0
- package/lib/contexts/execution.d.ts +33 -0
- package/lib/contexts/execution.d.ts.map +1 -0
- package/lib/contexts/execution.js +73 -0
- package/lib/contexts/execution.js.map +1 -0
- package/lib/contexts/globalcontext.d.ts +29 -0
- package/lib/contexts/globalcontext.d.ts.map +1 -0
- package/lib/contexts/globalcontext.js +38 -0
- package/lib/contexts/globalcontext.js.map +1 -0
- package/lib/{utils → contexts}/httpcontext.d.ts +45 -19
- package/lib/contexts/httpcontext.d.ts.map +1 -0
- package/lib/{utils → contexts}/httpcontext.js +102 -34
- package/lib/contexts/httpcontext.js.map +1 -0
- package/lib/contexts/icontext.d.ts +236 -0
- package/lib/contexts/icontext.d.ts.map +1 -0
- package/lib/contexts/icontext.js +230 -0
- package/lib/contexts/icontext.js.map +1 -0
- package/lib/contexts/operationcontext.d.ts +179 -0
- package/lib/contexts/operationcontext.d.ts.map +1 -0
- package/lib/contexts/operationcontext.js +358 -0
- package/lib/contexts/operationcontext.js.map +1 -0
- package/lib/contexts/simplecontext.d.ts +31 -0
- package/lib/contexts/simplecontext.d.ts.map +1 -0
- package/lib/contexts/simplecontext.js +45 -0
- package/lib/contexts/simplecontext.js.map +1 -0
- package/lib/contexts/webcontext.d.ts +218 -0
- package/lib/contexts/webcontext.d.ts.map +1 -0
- package/lib/contexts/webcontext.js +389 -0
- package/lib/contexts/webcontext.js.map +1 -0
- package/lib/core/authorizer.d.ts +23 -0
- package/lib/core/authorizer.d.ts.map +1 -0
- package/lib/core/authorizer.js +17 -0
- package/lib/core/authorizer.js.map +1 -0
- package/lib/core/core.d.ts +225 -0
- package/lib/core/core.d.ts.map +1 -0
- package/lib/core/core.js +576 -0
- package/lib/core/core.js.map +1 -0
- package/lib/core/hooks.d.ts +72 -0
- package/lib/core/hooks.d.ts.map +1 -0
- package/lib/core/hooks.js +73 -0
- package/lib/core/hooks.js.map +1 -0
- package/lib/core/icore.d.ts +249 -0
- package/lib/core/icore.d.ts.map +1 -0
- package/lib/core/icore.js +15 -0
- package/lib/core/icore.js.map +1 -0
- package/lib/core/instancestorage.d.ts +61 -0
- package/lib/core/instancestorage.d.ts.map +1 -0
- package/lib/core/instancestorage.js +75 -0
- package/lib/core/instancestorage.js.map +1 -0
- package/lib/core/operations.d.ts +181 -0
- package/lib/core/operations.d.ts.map +1 -0
- package/lib/core/operations.js +559 -0
- package/lib/core/operations.js.map +1 -0
- package/lib/errors/errors.d.ts +126 -0
- package/lib/errors/errors.d.ts.map +1 -0
- package/lib/errors/errors.js +165 -0
- package/lib/errors/errors.js.map +1 -0
- package/lib/events/asynceventemitter.d.ts +159 -0
- package/lib/events/asynceventemitter.d.ts.map +1 -0
- package/lib/events/asynceventemitter.js +152 -0
- package/lib/events/asynceventemitter.js.map +1 -0
- package/lib/events/events.d.ts +112 -0
- package/lib/events/events.d.ts.map +1 -0
- package/lib/events/events.js +45 -0
- package/lib/events/events.js.map +1 -0
- package/lib/index.d.ts +84 -51
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +82 -59
- package/lib/index.js.map +1 -1
- package/lib/loggers/console.service.d.ts +24 -0
- package/lib/loggers/console.service.d.ts.map +1 -0
- package/lib/loggers/console.service.js +30 -0
- package/lib/loggers/console.service.js.map +1 -0
- package/lib/loggers/file.service.d.ts +25 -0
- package/lib/loggers/file.service.d.ts.map +1 -0
- package/lib/loggers/file.service.js +33 -0
- package/lib/loggers/file.service.js.map +1 -0
- package/lib/loggers/hooks.d.ts +20 -0
- package/lib/loggers/hooks.d.ts.map +1 -0
- package/lib/loggers/hooks.js +40 -0
- package/lib/loggers/hooks.js.map +1 -0
- package/lib/loggers/ilogger.d.ts +76 -0
- package/lib/loggers/ilogger.d.ts.map +1 -0
- package/lib/loggers/ilogger.js +108 -0
- package/lib/loggers/ilogger.js.map +1 -0
- package/lib/loggers/logger.d.ts +13 -0
- package/lib/loggers/logger.d.ts.map +1 -0
- package/lib/loggers/logger.js +18 -0
- package/lib/loggers/logger.js.map +1 -0
- package/lib/loggers/memory.service.d.ts +18 -0
- package/lib/loggers/memory.service.d.ts.map +1 -0
- package/lib/loggers/memory.service.js +21 -0
- package/lib/loggers/memory.service.js.map +1 -0
- package/lib/loggers/params.d.ts +47 -0
- package/lib/loggers/params.d.ts.map +1 -0
- package/lib/loggers/params.js +56 -0
- package/lib/loggers/params.js.map +1 -0
- package/lib/metrics/metrics.d.ts +25 -0
- package/lib/metrics/metrics.d.ts.map +1 -0
- package/lib/metrics/metrics.js +51 -0
- package/lib/metrics/metrics.js.map +1 -0
- package/lib/models/aclmodel.d.ts +21 -77
- package/lib/models/aclmodel.d.ts.map +1 -0
- package/lib/models/aclmodel.js +27 -204
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/coremodel.model.d.ts +5 -0
- package/lib/models/coremodel.model.d.ts.map +1 -0
- package/lib/models/coremodel.model.js +5 -0
- package/lib/models/coremodel.model.js.map +1 -0
- package/lib/models/decorator.d.ts +63 -0
- package/lib/models/decorator.d.ts.map +1 -0
- package/lib/models/decorator.js +63 -0
- package/lib/models/decorator.js.map +1 -0
- package/lib/models/deployment.d.ts +2 -1
- package/lib/models/deployment.d.ts.map +1 -0
- package/lib/models/ident.model.d.ts +89 -0
- package/lib/models/ident.model.d.ts.map +1 -0
- package/lib/models/ident.model.js +115 -0
- package/lib/models/ident.model.js.map +1 -0
- package/lib/models/ownermodel.model.d.ts +68 -0
- package/lib/models/ownermodel.model.d.ts.map +1 -0
- package/lib/models/ownermodel.model.js +112 -0
- package/lib/models/ownermodel.model.js.map +1 -0
- package/lib/models/registry.model.d.ts +76 -0
- package/lib/models/registry.model.d.ts.map +1 -0
- package/lib/models/registry.model.js +104 -0
- package/lib/models/registry.model.js.map +1 -0
- package/lib/models/rolemodel.model.d.ts +28 -0
- package/lib/models/rolemodel.model.d.ts.map +1 -0
- package/lib/models/rolemodel.model.js +53 -0
- package/lib/models/rolemodel.model.js.map +1 -0
- package/lib/models/simpleuser.model.d.ts +78 -0
- package/lib/models/simpleuser.model.d.ts.map +1 -0
- package/lib/models/simpleuser.model.js +123 -0
- package/lib/models/simpleuser.model.js.map +1 -0
- package/lib/models/types.d.ts +113 -0
- package/lib/models/types.d.ts.map +1 -0
- package/lib/models/types.js +2 -0
- package/lib/models/types.js.map +1 -0
- package/lib/models/user.model.d.ts +103 -0
- package/lib/models/user.model.d.ts.map +1 -0
- package/lib/models/user.model.js +125 -0
- package/lib/models/user.model.js.map +1 -0
- package/lib/queues/memoryqueue.service.d.ts +72 -0
- package/lib/queues/memoryqueue.service.d.ts.map +1 -0
- package/lib/queues/memoryqueue.service.js +136 -0
- package/lib/queues/memoryqueue.service.js.map +1 -0
- package/lib/queues/pubsubservice.d.ts +9 -6
- package/lib/queues/pubsubservice.d.ts.map +1 -0
- package/lib/queues/pubsubservice.js +5 -4
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queueservice.d.ts +10 -11
- package/lib/queues/queueservice.d.ts.map +1 -0
- package/lib/queues/queueservice.js +48 -20
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/rest/hooks.d.ts +8 -0
- package/lib/rest/hooks.d.ts.map +1 -0
- package/lib/rest/hooks.js +10 -0
- package/lib/rest/hooks.js.map +1 -0
- package/lib/rest/irest.d.ts +212 -0
- package/lib/rest/irest.d.ts.map +1 -0
- package/lib/rest/irest.js +39 -0
- package/lib/rest/irest.js.map +1 -0
- package/lib/rest/originfilter.d.ts +38 -0
- package/lib/rest/originfilter.d.ts.map +1 -0
- package/lib/rest/originfilter.js +61 -0
- package/lib/rest/originfilter.js.map +1 -0
- package/lib/rest/restoperationstransport.service.d.ts +193 -0
- package/lib/rest/restoperationstransport.service.d.ts.map +1 -0
- package/lib/rest/restoperationstransport.service.js +780 -0
- package/lib/rest/restoperationstransport.service.js.map +1 -0
- package/lib/rest/router.service.d.ts +244 -0
- package/lib/rest/router.service.d.ts.map +1 -0
- package/lib/rest/router.service.js +843 -0
- package/lib/rest/router.service.js.map +1 -0
- package/lib/schemas/hooks.d.ts +48 -0
- package/lib/schemas/hooks.d.ts.map +1 -0
- package/lib/schemas/hooks.js +152 -0
- package/lib/schemas/hooks.js.map +1 -0
- package/lib/services/audit.model.d.ts +208 -0
- package/lib/services/audit.model.d.ts.map +1 -0
- package/lib/services/audit.model.js +431 -0
- package/lib/services/audit.model.js.map +1 -0
- package/lib/services/{authentication.d.ts → authentication.service.d.ts} +140 -58
- package/lib/services/authentication.service.d.ts.map +1 -0
- package/lib/services/authentication.service.js +932 -0
- package/lib/services/authentication.service.js.map +1 -0
- package/lib/services/binary.service.d.ts +808 -0
- package/lib/services/binary.service.d.ts.map +1 -0
- package/lib/services/binary.service.js +1365 -0
- package/lib/services/binary.service.js.map +1 -0
- package/lib/services/cloudbinary.d.ts +19 -13
- package/lib/services/cloudbinary.d.ts.map +1 -0
- package/lib/services/cloudbinary.js +24 -18
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/command.d.ts +118 -0
- package/lib/services/command.d.ts.map +1 -0
- package/lib/services/command.js +97 -0
- package/lib/services/command.js.map +1 -0
- package/lib/services/cron.service.d.ts +142 -0
- package/lib/services/cron.service.d.ts.map +1 -0
- package/lib/services/cron.service.js +291 -0
- package/lib/services/cron.service.js.map +1 -0
- package/lib/services/{cryptoservice.d.ts → cryptoservice.service.d.ts} +77 -142
- package/lib/services/cryptoservice.service.d.ts.map +1 -0
- package/lib/services/cryptoservice.service.js +527 -0
- package/lib/services/cryptoservice.service.js.map +1 -0
- package/lib/services/debugmailer.service.d.ts +49 -0
- package/lib/services/debugmailer.service.d.ts.map +1 -0
- package/lib/services/debugmailer.service.js +66 -0
- package/lib/services/debugmailer.service.js.map +1 -0
- package/lib/services/domainservice.service.d.ts +203 -0
- package/lib/services/domainservice.service.d.ts.map +1 -0
- package/lib/services/domainservice.service.js +600 -0
- package/lib/services/domainservice.service.js.map +1 -0
- package/lib/services/httpserver.service.d.ts +248 -0
- package/lib/services/httpserver.service.d.ts.map +1 -0
- package/lib/services/httpserver.service.js +673 -0
- package/lib/services/httpserver.service.js.map +1 -0
- package/lib/services/iauthentication.d.ts +9 -0
- package/lib/services/iauthentication.d.ts.map +1 -0
- package/lib/services/iauthentication.js +2 -0
- package/lib/services/iauthentication.js.map +1 -0
- package/lib/services/icryptoservice.d.ts +127 -0
- package/lib/services/icryptoservice.d.ts.map +1 -0
- package/lib/services/icryptoservice.js +68 -0
- package/lib/services/icryptoservice.js.map +1 -0
- package/lib/services/imailer.d.ts +17 -0
- package/lib/services/imailer.d.ts.map +1 -0
- package/lib/services/imailer.js +2 -0
- package/lib/services/imailer.js.map +1 -0
- package/lib/services/iservice.d.ts +104 -0
- package/lib/services/iservice.d.ts.map +1 -0
- package/lib/services/iservice.js +63 -0
- package/lib/services/iservice.js.map +1 -0
- package/lib/services/mailer.service.d.ts +220 -0
- package/lib/services/mailer.service.d.ts.map +1 -0
- package/lib/services/mailer.service.js +251 -0
- package/lib/services/mailer.service.js.map +1 -0
- package/lib/services/{notificationservice.d.ts → notificationservice.service.d.ts} +10 -10
- package/lib/services/notificationservice.service.d.ts.map +1 -0
- package/lib/services/{notificationservice.js → notificationservice.service.js} +24 -12
- package/lib/services/notificationservice.service.js.map +1 -0
- package/lib/services/oauth.d.ts +58 -31
- package/lib/services/oauth.d.ts.map +1 -0
- package/lib/services/oauth.js +365 -251
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/operationstransport.d.ts +65 -0
- package/lib/services/operationstransport.d.ts.map +1 -0
- package/lib/services/operationstransport.js +103 -0
- package/lib/services/operationstransport.js.map +1 -0
- package/lib/services/{prometheus.d.ts → prometheus.service.d.ts} +13 -11
- package/lib/services/prometheus.service.d.ts.map +1 -0
- package/lib/services/prometheus.service.js +203 -0
- package/lib/services/prometheus.service.js.map +1 -0
- package/lib/services/resource.service.d.ts +121 -0
- package/lib/services/resource.service.d.ts.map +1 -0
- package/lib/services/resource.service.js +301 -0
- package/lib/services/resource.service.js.map +1 -0
- package/lib/services/service.d.ts +88 -189
- package/lib/services/service.d.ts.map +1 -0
- package/lib/services/service.js +407 -432
- package/lib/services/service.js.map +1 -1
- package/lib/services/servicecommands.d.ts +99 -0
- package/lib/services/servicecommands.d.ts.map +1 -0
- package/lib/services/servicecommands.js +165 -0
- package/lib/services/servicecommands.js.map +1 -0
- package/lib/services/serviceparameters.d.ts +33 -0
- package/lib/services/serviceparameters.d.ts.map +1 -0
- package/lib/services/serviceparameters.js +79 -0
- package/lib/services/serviceparameters.js.map +1 -0
- package/lib/{utils → session}/cookie.d.ts +32 -18
- package/lib/session/cookie.d.ts.map +1 -0
- package/lib/{utils → session}/cookie.js +76 -23
- package/lib/session/cookie.js.map +1 -0
- package/lib/session/manager.model.d.ts +71 -0
- package/lib/session/manager.model.d.ts.map +1 -0
- package/lib/session/manager.model.js +155 -0
- package/lib/session/manager.model.js.map +1 -0
- package/lib/session/session.d.ts +57 -0
- package/lib/session/session.d.ts.map +1 -0
- package/lib/session/session.js +126 -0
- package/lib/session/session.js.map +1 -0
- package/lib/stores/istore.d.ts +99 -0
- package/lib/stores/istore.d.ts.map +1 -0
- package/lib/stores/istore.js +26 -0
- package/lib/stores/istore.js.map +1 -0
- package/lib/stores/memory.service.d.ts +114 -0
- package/lib/stores/memory.service.d.ts.map +1 -0
- package/lib/stores/memory.service.js +343 -0
- package/lib/stores/memory.service.js.map +1 -0
- package/lib/stores/store.d.ts +127 -768
- package/lib/stores/store.d.ts.map +1 -0
- package/lib/stores/store.js +258 -1718
- package/lib/stores/store.js.map +1 -1
- package/lib/templates/templates.d.ts +39 -0
- package/lib/templates/templates.d.ts.map +1 -0
- package/lib/templates/templates.js +92 -0
- package/lib/templates/templates.js.map +1 -0
- package/lib/test/application.d.ts +174 -0
- package/lib/test/application.d.ts.map +1 -0
- package/lib/test/application.js +288 -0
- package/lib/test/application.js.map +1 -0
- package/lib/test/asyncstorage.d.ts +16 -0
- package/lib/test/asyncstorage.d.ts.map +1 -0
- package/lib/test/asyncstorage.js +32 -0
- package/lib/test/asyncstorage.js.map +1 -0
- package/lib/test/core.d.ts +63 -0
- package/lib/test/core.d.ts.map +1 -0
- package/lib/test/core.js +190 -0
- package/lib/test/core.js.map +1 -0
- package/lib/test/index.d.ts +7 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +8 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/internal.d.ts +34 -0
- package/lib/test/internal.d.ts.map +1 -0
- package/lib/test/internal.js +156 -0
- package/lib/test/internal.js.map +1 -0
- package/lib/test/objects.d.ts +318 -0
- package/lib/test/objects.d.ts.map +1 -0
- package/lib/test/objects.js +443 -0
- package/lib/test/objects.js.map +1 -0
- package/lib/utils/abstractdeployer.d.ts +5 -2
- package/lib/utils/abstractdeployer.d.ts.map +1 -0
- package/lib/utils/abstractdeployer.js +3 -0
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/package.json +85 -56
- package/test/cachedapp/webda.config.json +1 -5
- package/test/config-cached.json +1 -5
- package/test/config.json +6 -99
- package/test/data/.env +1 -0
- package/test/my-cnf.json +9 -0
- package/webda.module.json +3462 -2231
- package/lib/application.d.ts +0 -876
- package/lib/application.js +0 -741
- package/lib/application.js.map +0 -1
- package/lib/application.spec.d.ts +0 -1
- package/lib/application.spec.js +0 -234
- package/lib/application.spec.js.map +0 -1
- package/lib/core.d.ts +0 -740
- package/lib/core.js +0 -1310
- package/lib/core.js.map +0 -1
- package/lib/core.spec.d.ts +0 -1
- package/lib/core.spec.js +0 -761
- package/lib/core.spec.js.map +0 -1
- package/lib/errors.d.ts +0 -65
- package/lib/errors.js +0 -113
- package/lib/errors.js.map +0 -1
- package/lib/errors.spec.d.ts +0 -1
- package/lib/errors.spec.js +0 -33
- package/lib/errors.spec.js.map +0 -1
- package/lib/models/aclmodel.spec.d.ts +0 -1
- package/lib/models/aclmodel.spec.js +0 -187
- package/lib/models/aclmodel.spec.js.map +0 -1
- package/lib/models/coremodel.d.ts +0 -887
- package/lib/models/coremodel.js +0 -1208
- package/lib/models/coremodel.js.map +0 -1
- package/lib/models/coremodel.spec.d.ts +0 -1
- package/lib/models/coremodel.spec.js +0 -462
- package/lib/models/coremodel.spec.js.map +0 -1
- package/lib/models/ident.d.ts +0 -53
- package/lib/models/ident.js +0 -40
- package/lib/models/ident.js.map +0 -1
- package/lib/models/ident.spec.d.ts +0 -1
- package/lib/models/ident.spec.js +0 -43
- package/lib/models/ident.spec.js.map +0 -1
- package/lib/models/ownermodel.d.ts +0 -50
- package/lib/models/ownermodel.js +0 -65
- package/lib/models/ownermodel.js.map +0 -1
- package/lib/models/ownermodel.spec.d.ts +0 -1
- package/lib/models/ownermodel.spec.js +0 -191
- package/lib/models/ownermodel.spec.js.map +0 -1
- package/lib/models/relations.d.ts +0 -181
- package/lib/models/relations.js +0 -157
- package/lib/models/relations.js.map +0 -1
- package/lib/models/relations.spec.d.ts +0 -12
- package/lib/models/relations.spec.js +0 -224
- package/lib/models/relations.spec.js.map +0 -1
- package/lib/models/rolemodel.d.ts +0 -10
- package/lib/models/rolemodel.js +0 -35
- package/lib/models/rolemodel.js.map +0 -1
- package/lib/models/rolemodel.spec.d.ts +0 -1
- package/lib/models/rolemodel.spec.js +0 -86
- package/lib/models/rolemodel.spec.js.map +0 -1
- package/lib/models/user.d.ts +0 -100
- package/lib/models/user.js +0 -157
- package/lib/models/user.js.map +0 -1
- package/lib/models/user.spec.d.ts +0 -1
- package/lib/models/user.spec.js +0 -88
- package/lib/models/user.spec.js.map +0 -1
- package/lib/queues/filequeue.d.ts +0 -58
- package/lib/queues/filequeue.js +0 -131
- package/lib/queues/filequeue.js.map +0 -1
- package/lib/queues/filequeue.spec.d.ts +0 -1
- package/lib/queues/filequeue.spec.js +0 -78
- package/lib/queues/filequeue.spec.js.map +0 -1
- package/lib/queues/memoryqueue.d.ts +0 -45
- package/lib/queues/memoryqueue.js +0 -81
- package/lib/queues/memoryqueue.js.map +0 -1
- package/lib/queues/memoryqueue.spec.d.ts +0 -1
- package/lib/queues/memoryqueue.spec.js +0 -192
- package/lib/queues/memoryqueue.spec.js.map +0 -1
- package/lib/queues/queue.spec.d.ts +0 -5
- package/lib/queues/queue.spec.js +0 -55
- package/lib/queues/queue.spec.js.map +0 -1
- package/lib/router.d.ts +0 -172
- package/lib/router.js +0 -419
- package/lib/router.js.map +0 -1
- package/lib/router.spec.d.ts +0 -1
- package/lib/router.spec.js +0 -229
- package/lib/router.spec.js.map +0 -1
- package/lib/services/asyncevents.d.ts +0 -151
- package/lib/services/asyncevents.js +0 -217
- package/lib/services/asyncevents.js.map +0 -1
- package/lib/services/asyncevents.spec.d.ts +0 -1
- package/lib/services/asyncevents.spec.js +0 -118
- package/lib/services/asyncevents.spec.js.map +0 -1
- package/lib/services/authentication.js +0 -772
- package/lib/services/authentication.js.map +0 -1
- package/lib/services/authentication.spec.d.ts +0 -1
- package/lib/services/authentication.spec.js +0 -458
- package/lib/services/authentication.spec.js.map +0 -1
- package/lib/services/binary.d.ts +0 -549
- package/lib/services/binary.js +0 -986
- package/lib/services/binary.js.map +0 -1
- package/lib/services/binary.spec.d.ts +0 -44
- package/lib/services/binary.spec.js +0 -438
- package/lib/services/binary.spec.js.map +0 -1
- package/lib/services/cloudbinary.spec.d.ts +0 -13
- package/lib/services/cloudbinary.spec.js +0 -192
- package/lib/services/cloudbinary.spec.js.map +0 -1
- package/lib/services/configuration.js +0 -178
- package/lib/services/configuration.js.map +0 -1
- package/lib/services/configuration.spec.d.ts +0 -1
- package/lib/services/configuration.spec.js +0 -87
- package/lib/services/configuration.spec.js.map +0 -1
- package/lib/services/cron.d.ts +0 -73
- package/lib/services/cron.js +0 -141
- package/lib/services/cron.js.map +0 -1
- package/lib/services/cron.spec.d.ts +0 -1
- package/lib/services/cron.spec.js +0 -76
- package/lib/services/cron.spec.js.map +0 -1
- package/lib/services/cryptoservice.js +0 -434
- package/lib/services/cryptoservice.js.map +0 -1
- package/lib/services/cryptoservice.spec.d.ts +0 -1
- package/lib/services/cryptoservice.spec.js +0 -177
- package/lib/services/cryptoservice.spec.js.map +0 -1
- package/lib/services/debugmailer.d.ts +0 -36
- package/lib/services/debugmailer.js +0 -52
- package/lib/services/debugmailer.js.map +0 -1
- package/lib/services/debugmailer.spec.d.ts +0 -1
- package/lib/services/debugmailer.spec.js +0 -29
- package/lib/services/debugmailer.spec.js.map +0 -1
- package/lib/services/domainservice.d.ts +0 -152
- package/lib/services/domainservice.js +0 -881
- package/lib/services/domainservice.js.map +0 -1
- package/lib/services/domainservice.spec.d.ts +0 -1
- package/lib/services/domainservice.spec.js +0 -401
- package/lib/services/domainservice.spec.js.map +0 -1
- package/lib/services/filebinary.d.ts +0 -133
- package/lib/services/filebinary.js +0 -371
- package/lib/services/filebinary.js.map +0 -1
- package/lib/services/filebinary.spec.d.ts +0 -21
- package/lib/services/filebinary.spec.js +0 -415
- package/lib/services/filebinary.spec.js.map +0 -1
- package/lib/services/fileconfiguration.d.ts +0 -22
- package/lib/services/fileconfiguration.js +0 -48
- package/lib/services/fileconfiguration.js.map +0 -1
- package/lib/services/fileconfiguration.spec.d.ts +0 -1
- package/lib/services/fileconfiguration.spec.js +0 -177
- package/lib/services/fileconfiguration.spec.js.map +0 -1
- package/lib/services/invitationservice.d.ts +0 -222
- package/lib/services/invitationservice.js +0 -526
- package/lib/services/invitationservice.js.map +0 -1
- package/lib/services/invitationservice.spec.d.ts +0 -1
- package/lib/services/invitationservice.spec.js +0 -516
- package/lib/services/invitationservice.spec.js.map +0 -1
- package/lib/services/kubernetesconfiguration.d.ts +0 -26
- package/lib/services/kubernetesconfiguration.js +0 -54
- package/lib/services/kubernetesconfiguration.js.map +0 -1
- package/lib/services/kubernetesconfiguration.spec.d.ts +0 -1
- package/lib/services/kubernetesconfiguration.spec.js +0 -147
- package/lib/services/kubernetesconfiguration.spec.js.map +0 -1
- package/lib/services/mailer.d.ts +0 -165
- package/lib/services/mailer.js +0 -176
- package/lib/services/mailer.js.map +0 -1
- package/lib/services/mailer.spec.d.ts +0 -1
- package/lib/services/mailer.spec.js +0 -144
- package/lib/services/mailer.spec.js.map +0 -1
- package/lib/services/notificationservice.js.map +0 -1
- package/lib/services/notificationservice.spec.d.ts +0 -1
- package/lib/services/notificationservice.spec.js +0 -78
- package/lib/services/notificationservice.spec.js.map +0 -1
- package/lib/services/oauth.spec.d.ts +0 -1
- package/lib/services/oauth.spec.js +0 -184
- package/lib/services/oauth.spec.js.map +0 -1
- package/lib/services/prometheus.js +0 -160
- package/lib/services/prometheus.js.map +0 -1
- package/lib/services/prometheus.spec.d.ts +0 -1
- package/lib/services/prometheus.spec.js +0 -57
- package/lib/services/prometheus.spec.js.map +0 -1
- package/lib/services/resource.d.ts +0 -87
- package/lib/services/resource.js +0 -156
- package/lib/services/resource.js.map +0 -1
- package/lib/services/resource.spec.d.ts +0 -1
- package/lib/services/resource.spec.js +0 -122
- package/lib/services/resource.spec.js.map +0 -1
- package/lib/services/service.spec.d.ts +0 -1
- package/lib/services/service.spec.js +0 -268
- package/lib/services/service.spec.js.map +0 -1
- package/lib/stores/aggregator.d.ts +0 -41
- package/lib/stores/aggregator.js +0 -80
- package/lib/stores/aggregator.js.map +0 -1
- package/lib/stores/aliasstore.d.ts +0 -108
- package/lib/stores/aliasstore.js +0 -168
- package/lib/stores/aliasstore.js.map +0 -1
- package/lib/stores/aliasstore.spec.d.ts +0 -11
- package/lib/stores/aliasstore.spec.js +0 -89
- package/lib/stores/aliasstore.spec.js.map +0 -1
- package/lib/stores/file.d.ts +0 -107
- package/lib/stores/file.js +0 -188
- package/lib/stores/file.js.map +0 -1
- package/lib/stores/file.spec.d.ts +0 -19
- package/lib/stores/file.spec.js +0 -232
- package/lib/stores/file.spec.js.map +0 -1
- package/lib/stores/mapper.d.ts +0 -149
- package/lib/stores/mapper.js +0 -293
- package/lib/stores/mapper.js.map +0 -1
- package/lib/stores/mapper.spec.d.ts +0 -1
- package/lib/stores/mapper.spec.js +0 -160
- package/lib/stores/mapper.spec.js.map +0 -1
- package/lib/stores/memory.d.ts +0 -151
- package/lib/stores/memory.js +0 -371
- package/lib/stores/memory.js.map +0 -1
- package/lib/stores/memory.spec.d.ts +0 -20
- package/lib/stores/memory.spec.js +0 -328
- package/lib/stores/memory.spec.js.map +0 -1
- package/lib/stores/modelmapper.d.ts +0 -61
- package/lib/stores/modelmapper.js +0 -199
- package/lib/stores/modelmapper.js.map +0 -1
- package/lib/stores/store.spec.d.ts +0 -65
- package/lib/stores/store.spec.js +0 -906
- package/lib/stores/store.spec.js.map +0 -1
- package/lib/test.d.ts +0 -162
- package/lib/test.js +0 -399
- package/lib/test.js.map +0 -1
- package/lib/unpackedapplication.d.ts +0 -76
- package/lib/unpackedapplication.js +0 -299
- package/lib/unpackedapplication.js.map +0 -1
- package/lib/utils/abstractdeployer.spec.d.ts +0 -1
- package/lib/utils/abstractdeployer.spec.js +0 -21
- package/lib/utils/abstractdeployer.spec.js.map +0 -1
- package/lib/utils/case.d.ts +0 -7
- package/lib/utils/case.js +0 -43
- package/lib/utils/case.js.map +0 -1
- package/lib/utils/case.spec.d.ts +0 -1
- package/lib/utils/case.spec.js +0 -50
- package/lib/utils/case.spec.js.map +0 -1
- package/lib/utils/context.d.ts +0 -462
- package/lib/utils/context.js +0 -732
- package/lib/utils/context.js.map +0 -1
- package/lib/utils/context.spec.d.ts +0 -9
- package/lib/utils/context.spec.js +0 -372
- package/lib/utils/context.spec.js.map +0 -1
- package/lib/utils/cookie.js.map +0 -1
- package/lib/utils/cookie.spec.d.ts +0 -1
- package/lib/utils/cookie.spec.js +0 -78
- package/lib/utils/cookie.spec.js.map +0 -1
- package/lib/utils/esm.d.ts +0 -13
- package/lib/utils/esm.js +0 -19
- package/lib/utils/esm.js.map +0 -1
- package/lib/utils/httpcontext.js.map +0 -1
- package/lib/utils/httpcontext.spec.d.ts +0 -4
- package/lib/utils/httpcontext.spec.js +0 -77
- package/lib/utils/httpcontext.spec.js.map +0 -1
- package/lib/utils/logger.d.ts +0 -91
- package/lib/utils/logger.js +0 -121
- package/lib/utils/logger.js.map +0 -1
- package/lib/utils/logger.spec.d.ts +0 -1
- package/lib/utils/logger.spec.js +0 -48
- package/lib/utils/logger.spec.js.map +0 -1
- package/lib/utils/serializers.d.ts +0 -161
- package/lib/utils/serializers.js +0 -420
- package/lib/utils/serializers.js.map +0 -1
- package/lib/utils/serializers.spec.d.ts +0 -1
- package/lib/utils/serializers.spec.js +0 -313
- package/lib/utils/serializers.spec.js.map +0 -1
- package/lib/utils/session.d.ts +0 -126
- package/lib/utils/session.js +0 -166
- package/lib/utils/session.js.map +0 -1
- package/lib/utils/session.spec.d.ts +0 -1
- package/lib/utils/session.spec.js +0 -71
- package/lib/utils/session.spec.js.map +0 -1
- package/lib/utils/throttler.d.ts +0 -102
- package/lib/utils/throttler.js +0 -168
- package/lib/utils/throttler.js.map +0 -1
- package/lib/utils/throttler.spec.d.ts +0 -1
- package/lib/utils/throttler.spec.js +0 -55
- package/lib/utils/throttler.spec.js.map +0 -1
- package/lib/utils/waiter.d.ts +0 -93
- package/lib/utils/waiter.js +0 -148
- package/lib/utils/waiter.js.map +0 -1
- package/lib/utils/waiter.spec.d.ts +0 -1
- package/lib/utils/waiter.spec.js +0 -98
- package/lib/utils/waiter.spec.js.map +0 -1
- package/test/config-file-missing-file-no-default.json +0 -44
- package/test/config-file-missing-file.json +0 -55
- package/test/config-file-no-reload.json +0 -69
- package/test/config-file-reload.json +0 -68
- package/test/config-invitation.json +0 -63
- package/test/config-kube-reload.json +0 -68
- package/test/config-reload.json +0 -66
- package/test/config.old.json +0 -152
- package/test/jsonutils/mdocs.yaml +0 -56
- package/test/jsonutils/test.json +0 -3
- package/test/jsonutils/test.yml +0 -5
- package/test/moddas/annotatedservice.js +0 -23
- package/test/moddas/debugmailer.js +0 -13
- package/test/moddas/fakeservice.js +0 -4
- package/test/moddas/voidstore.js +0 -66
- package/test/models/ident.js +0 -36
- package/test/models/task.js +0 -42
package/lib/core.js
DELETED
|
@@ -1,1310 +0,0 @@
|
|
|
1
|
-
import Ajv from "ajv";
|
|
2
|
-
import addFormats from "ajv-formats";
|
|
3
|
-
import { deepmerge } from "deepmerge-ts";
|
|
4
|
-
import * as events from "events";
|
|
5
|
-
import jsonpath from "jsonpath";
|
|
6
|
-
import pkg from "node-machine-id";
|
|
7
|
-
import { Counter, Gauge, Histogram, register } from "prom-client";
|
|
8
|
-
import { randomUUID } from "crypto";
|
|
9
|
-
import { BinaryService, GlobalContext, Logger, OperationContext, RegExpValidator, Store, UnpackedApplication, WebContext, WebdaError } from "./index.js";
|
|
10
|
-
import * as WebdaQL from "@webda/ql";
|
|
11
|
-
import { CoreModel } from "./models/coremodel.js";
|
|
12
|
-
import { Router } from "./router.js";
|
|
13
|
-
import { JSONUtils } from "./utils/serializers.js";
|
|
14
|
-
const { machineIdSync } = pkg;
|
|
15
|
-
export class EventEmitterUtils {
|
|
16
|
-
static emit(eventEmitter, event, data) {
|
|
17
|
-
for (let listener of eventEmitter.listeners(event)) {
|
|
18
|
-
let start = Date.now();
|
|
19
|
-
listener(data);
|
|
20
|
-
this.elapse(start);
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
static async emitSync(eventEmitter, event, data) {
|
|
25
|
-
let promises = [];
|
|
26
|
-
for (let listener of eventEmitter.listeners(event)) {
|
|
27
|
-
let start = Date.now();
|
|
28
|
-
let result = listener(data);
|
|
29
|
-
if (result instanceof Promise) {
|
|
30
|
-
promises.push(result
|
|
31
|
-
.catch(err => {
|
|
32
|
-
Core.get().log("ERROR", "Listener error", err);
|
|
33
|
-
})
|
|
34
|
-
.then(() => {
|
|
35
|
-
this.elapse(start);
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
this.elapse(start);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return Promise.all(promises);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Display a message if the listener takes too long
|
|
46
|
-
* @param start
|
|
47
|
-
*/
|
|
48
|
-
static elapse(start) {
|
|
49
|
-
let elapsed = Date.now() - start;
|
|
50
|
-
if (elapsed > 100) {
|
|
51
|
-
Core.get().log("INFO", "Long listener", elapsed, "ms");
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Copy from https://github.com/ajv-validator/ajv/blob/master/lib/runtime/validation_error.ts
|
|
57
|
-
* It is not exported by ajv
|
|
58
|
-
*/
|
|
59
|
-
export class ValidationError extends Error {
|
|
60
|
-
constructor(errors) {
|
|
61
|
-
super(`validation failed: ${errors.map(e => e.message).join("; ")}`);
|
|
62
|
-
this.errors = errors;
|
|
63
|
-
this.ajv = this.validation = true;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Operation
|
|
68
|
-
*/
|
|
69
|
-
export class OperationError extends Error {
|
|
70
|
-
constructor(operation, type) {
|
|
71
|
-
super(`Operation ${operation} ${type}`);
|
|
72
|
-
this.operation = operation;
|
|
73
|
-
this.type = type;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Filter request based on their origin
|
|
78
|
-
*
|
|
79
|
-
* @category CoreFeatures
|
|
80
|
-
*/
|
|
81
|
-
export class OriginFilter {
|
|
82
|
-
constructor(origins) {
|
|
83
|
-
this.regexs = new RegExpValidator(origins);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
* @param context
|
|
88
|
-
* @returns
|
|
89
|
-
*/
|
|
90
|
-
async checkRequest(context) {
|
|
91
|
-
let httpContext = context.getHttpContext();
|
|
92
|
-
return this.regexs.validate(httpContext.hostname) || this.regexs.validate(httpContext.origin);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Authorize requests based on the website
|
|
97
|
-
*/
|
|
98
|
-
export class WebsiteOriginFilter {
|
|
99
|
-
constructor(website) {
|
|
100
|
-
this.websites = [];
|
|
101
|
-
if (!Array.isArray(website)) {
|
|
102
|
-
if (typeof website === "object") {
|
|
103
|
-
this.websites.push(website.url);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
this.websites.push(website);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.websites = [...website];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async checkRequest(context) {
|
|
114
|
-
let httpContext = context.getHttpContext();
|
|
115
|
-
if (this.websites.indexOf(httpContext.origin) >= 0 ||
|
|
116
|
-
this.websites.indexOf(httpContext.host) >= 0 ||
|
|
117
|
-
this.websites.indexOf("*") >= 0) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// @Bean to declare as a Singleton service
|
|
124
|
-
export function Bean(constructor) {
|
|
125
|
-
let name = constructor.name;
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
process.webdaBeans ?? (process.webdaBeans = {});
|
|
128
|
-
// @ts-ignore
|
|
129
|
-
const beans = process.webdaBeans;
|
|
130
|
-
beans[name] ?? (beans[name] = constructor);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* This is the main class of the framework, it handles the routing, the services initialization and resolution
|
|
134
|
-
*
|
|
135
|
-
* @class Core
|
|
136
|
-
* @category CoreFeatures
|
|
137
|
-
*/
|
|
138
|
-
export class Core extends events.EventEmitter {
|
|
139
|
-
/**
|
|
140
|
-
* @params {Object} config - The configuration Object, if undefined will load the configuration file
|
|
141
|
-
*/
|
|
142
|
-
constructor(application) {
|
|
143
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
144
|
-
/** @ignore */
|
|
145
|
-
super();
|
|
146
|
-
/**
|
|
147
|
-
* Webda Services
|
|
148
|
-
* @hidden
|
|
149
|
-
*/
|
|
150
|
-
this.services = {};
|
|
151
|
-
/**
|
|
152
|
-
* Router that will route http request in
|
|
153
|
-
*/
|
|
154
|
-
this.router = new Router(this);
|
|
155
|
-
/**
|
|
156
|
-
* If Core is already initiated
|
|
157
|
-
*/
|
|
158
|
-
this._initiated = false;
|
|
159
|
-
/**
|
|
160
|
-
* Services who failed to create or initialize
|
|
161
|
-
*/
|
|
162
|
-
this.failedServices = {};
|
|
163
|
-
/**
|
|
164
|
-
* Request Filter registry
|
|
165
|
-
*
|
|
166
|
-
* Added via [[Webda.registerRequestFilter]]
|
|
167
|
-
* See [[CorsFilter]]
|
|
168
|
-
*/
|
|
169
|
-
this._requestFilters = [];
|
|
170
|
-
/**
|
|
171
|
-
* CORS Filter registry
|
|
172
|
-
*
|
|
173
|
-
* Added via [[Webda.registerCORSRequestFilter]]
|
|
174
|
-
* See [[CorsFilter]]
|
|
175
|
-
*/
|
|
176
|
-
this._requestCORSFilters = [];
|
|
177
|
-
/**
|
|
178
|
-
* Contains all operations defined by services
|
|
179
|
-
*/
|
|
180
|
-
this.operations = {};
|
|
181
|
-
/**
|
|
182
|
-
* Cache for model to store resolution
|
|
183
|
-
*/
|
|
184
|
-
this._modelStoresCache = new Map();
|
|
185
|
-
/**
|
|
186
|
-
* Cache for model to store resolution
|
|
187
|
-
*/
|
|
188
|
-
this._modelBinariesCache = new Map();
|
|
189
|
-
/**
|
|
190
|
-
* True if the dual import warning has been sent
|
|
191
|
-
*/
|
|
192
|
-
this._dualImportWarn = false;
|
|
193
|
-
/**
|
|
194
|
-
* Registered context providers
|
|
195
|
-
*/
|
|
196
|
-
this._contextProviders = [
|
|
197
|
-
{
|
|
198
|
-
getContext: (info) => {
|
|
199
|
-
// If http is defined, return a WebContext
|
|
200
|
-
if (info.http) {
|
|
201
|
-
return new WebContext(this, info.http, info.stream);
|
|
202
|
-
}
|
|
203
|
-
return new OperationContext(this, info.stream);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
];
|
|
207
|
-
/**
|
|
208
|
-
*
|
|
209
|
-
*/
|
|
210
|
-
this.interuptables = [];
|
|
211
|
-
// Store WebdaCore in process to avoid conflict with import
|
|
212
|
-
// @ts-ignore
|
|
213
|
-
Core.singleton = process.webda = this;
|
|
214
|
-
/**
|
|
215
|
-
* SIGINT handler
|
|
216
|
-
*/
|
|
217
|
-
process.on("SIGINT", async () => {
|
|
218
|
-
if (Core.get()?.interuptables.length > 0) {
|
|
219
|
-
console.log("Received SIGINT. Cancelling all interuptables.");
|
|
220
|
-
await Promise.all(Core.get().interuptables.map(i => i.cancel()));
|
|
221
|
-
}
|
|
222
|
-
process.exit(0);
|
|
223
|
-
});
|
|
224
|
-
this.workerOutput = application.getWorkerOutput();
|
|
225
|
-
this.logger = new Logger(this.workerOutput, "@webda/core/lib/core.js");
|
|
226
|
-
this.application = application || new UnpackedApplication(".");
|
|
227
|
-
this._initTime = new Date().getTime();
|
|
228
|
-
// Schema validations
|
|
229
|
-
this._ajv = new Ajv();
|
|
230
|
-
addFormats(this._ajv);
|
|
231
|
-
this._ajvSchemas = {};
|
|
232
|
-
// Load the configuration and migrate
|
|
233
|
-
this.configuration = this.application.getCurrentConfiguration();
|
|
234
|
-
// Init default values for configuration
|
|
235
|
-
(_a = this.configuration).parameters ?? (_a.parameters = {});
|
|
236
|
-
(_b = this.configuration.parameters).apiUrl ?? (_b.apiUrl = "http://localhost:18080");
|
|
237
|
-
(_c = this.configuration.parameters).defaultStore ?? (_c.defaultStore = "Registry");
|
|
238
|
-
(_d = this.configuration.parameters).metrics ?? (_d.metrics = {});
|
|
239
|
-
if (this.configuration.parameters.metrics) {
|
|
240
|
-
(_e = this.configuration.parameters.metrics).labels ?? (_e.labels = {});
|
|
241
|
-
(_f = this.configuration.parameters.metrics).config ?? (_f.config = {});
|
|
242
|
-
(_g = this.configuration.parameters.metrics).prefix ?? (_g.prefix = "");
|
|
243
|
-
}
|
|
244
|
-
(_h = this.configuration).services ?? (_h.services = {});
|
|
245
|
-
// Add CSRF origins filtering
|
|
246
|
-
if (this.configuration.parameters.csrfOrigins) {
|
|
247
|
-
this.registerCORSFilter(new OriginFilter(this.configuration.parameters.csrfOrigins));
|
|
248
|
-
}
|
|
249
|
-
// Add CSRF website filtering
|
|
250
|
-
if (this.configuration.parameters.website) {
|
|
251
|
-
this.registerCORSFilter(new WebsiteOriginFilter(this.configuration.parameters.website));
|
|
252
|
-
}
|
|
253
|
-
this.setGlobalContext(new GlobalContext(this));
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Register a cancelable process
|
|
257
|
-
* @param interuptable
|
|
258
|
-
*/
|
|
259
|
-
static registerInteruptableProcess(interuptable) {
|
|
260
|
-
Core.get()?.interuptables.push(interuptable);
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Unregister a cancelable process
|
|
264
|
-
* @param interuptable
|
|
265
|
-
*/
|
|
266
|
-
static unregisterInteruptableProcess(interuptable) {
|
|
267
|
-
let id = Core.get()?.interuptables.findIndex(i => i === interuptable);
|
|
268
|
-
id ?? (id = -1);
|
|
269
|
-
if (id >= 0) {
|
|
270
|
-
Core.get().interuptables.splice(id, 1);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Get the current script location
|
|
275
|
-
* @returns
|
|
276
|
-
*/
|
|
277
|
-
getScriptUrl() {
|
|
278
|
-
return import.meta.url;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Return information on the singleton import and version
|
|
282
|
-
* @param singleton
|
|
283
|
-
* @returns
|
|
284
|
-
*/
|
|
285
|
-
static getSingletonInfo(singleton) {
|
|
286
|
-
let res = `- `;
|
|
287
|
-
if (singleton.getScriptUrl) {
|
|
288
|
-
res += singleton.getScriptUrl();
|
|
289
|
-
}
|
|
290
|
-
res += " / " + singleton.getVersion();
|
|
291
|
-
return res;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Get the singleton of Webda Core
|
|
295
|
-
* @returns
|
|
296
|
-
*/
|
|
297
|
-
static get() {
|
|
298
|
-
// @ts-ignore
|
|
299
|
-
let singleton = process.webda;
|
|
300
|
-
if (Core.singleton !== singleton &&
|
|
301
|
-
!singleton._dualImportWarn &&
|
|
302
|
-
Core.singleton !== undefined &&
|
|
303
|
-
singleton !== undefined) {
|
|
304
|
-
singleton._dualImportWarn = true;
|
|
305
|
-
singleton.log("ERROR", `Several import version of WebdaCore has been identified.\n\tIt can impact your models.\n\t- ${this.getSingletonInfo(singleton)}\n\t- ${this.getSingletonInfo(Core.singleton)}`);
|
|
306
|
-
}
|
|
307
|
-
// Store WebdaCore in process to avoid conflict with import
|
|
308
|
-
return singleton;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Enforce a specific store for a model
|
|
312
|
-
*
|
|
313
|
-
* Useful in some specific case when you want to update store dynamically
|
|
314
|
-
*
|
|
315
|
-
* @param model
|
|
316
|
-
* @param store
|
|
317
|
-
*/
|
|
318
|
-
setModelStore(model, store) {
|
|
319
|
-
this._modelStoresCache.set(model, store);
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Get the store assigned to this model
|
|
323
|
-
* @param model
|
|
324
|
-
* @returns
|
|
325
|
-
*/
|
|
326
|
-
getModelStore(modelOrConstructor) {
|
|
327
|
-
const model = ((modelOrConstructor instanceof CoreModel ? modelOrConstructor.__class : modelOrConstructor));
|
|
328
|
-
if (this._modelStoresCache.has(model)) {
|
|
329
|
-
return this._modelStoresCache.get(model);
|
|
330
|
-
}
|
|
331
|
-
const setCache = store => {
|
|
332
|
-
this._modelStoresCache.set(model, store);
|
|
333
|
-
};
|
|
334
|
-
const stores = this.getStores();
|
|
335
|
-
let actualScore;
|
|
336
|
-
let actualStore = this.getService(this.parameter("defaultStore") || "Registry");
|
|
337
|
-
for (let store in stores) {
|
|
338
|
-
let score = stores[store].handleModel(model);
|
|
339
|
-
// As 0 mean exact match we stop there
|
|
340
|
-
if (score === 0) {
|
|
341
|
-
setCache(stores[store]);
|
|
342
|
-
return stores[store];
|
|
343
|
-
}
|
|
344
|
-
else if (score > 0 && (actualScore === undefined || actualScore > score)) {
|
|
345
|
-
actualScore = score;
|
|
346
|
-
actualStore = stores[store];
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
setCache(actualStore);
|
|
350
|
-
return actualStore;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Get the service that manage a model
|
|
354
|
-
* @param modelOrConstructor
|
|
355
|
-
* @param attribute
|
|
356
|
-
* @returns
|
|
357
|
-
*/
|
|
358
|
-
getBinaryStore(modelOrConstructor, attribute) {
|
|
359
|
-
const binaries = this.getServicesOfType(BinaryService);
|
|
360
|
-
const model = this.application.getModelName(modelOrConstructor);
|
|
361
|
-
let actualScore = -1;
|
|
362
|
-
let actualService;
|
|
363
|
-
const setCache = store => {
|
|
364
|
-
this._modelBinariesCache.set(model, store);
|
|
365
|
-
};
|
|
366
|
-
for (let binary in binaries) {
|
|
367
|
-
let score = binaries[binary].handleBinary(model, attribute);
|
|
368
|
-
// As 0 mean exact match we stop there
|
|
369
|
-
if (score === 2) {
|
|
370
|
-
setCache(binaries[binary]);
|
|
371
|
-
return binaries[binary];
|
|
372
|
-
}
|
|
373
|
-
else if (score >= 0 && (actualService === undefined || actualScore > score)) {
|
|
374
|
-
actualScore = score;
|
|
375
|
-
actualService = binaries[binary];
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (!actualService) {
|
|
379
|
-
throw new Error("No binary store found for " + model + " " + attribute);
|
|
380
|
-
}
|
|
381
|
-
setCache(actualService);
|
|
382
|
-
return actualService;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Return Core instance id
|
|
386
|
-
*
|
|
387
|
-
* It is a random generated string
|
|
388
|
-
*/
|
|
389
|
-
getInstanceId() {
|
|
390
|
-
this.instanceId ?? (this.instanceId = this.getUuid());
|
|
391
|
-
return this.instanceId;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Get absolute url with subpath
|
|
395
|
-
* @param subpath
|
|
396
|
-
*/
|
|
397
|
-
getApiUrl(subpath = "") {
|
|
398
|
-
if (subpath.length > 0 && !subpath.startsWith("/")) {
|
|
399
|
-
subpath = "/" + subpath;
|
|
400
|
-
}
|
|
401
|
-
return this.configuration.parameters.apiUrl + subpath;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Return application path with subpath
|
|
405
|
-
*
|
|
406
|
-
* Helper that redirect to this.application.getAppPath
|
|
407
|
-
*
|
|
408
|
-
* @param subpath
|
|
409
|
-
* @returns
|
|
410
|
-
*/
|
|
411
|
-
getAppPath(subpath = "") {
|
|
412
|
-
return this.application.getAppPath(subpath);
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Retrieve all detected modules definition
|
|
416
|
-
*/
|
|
417
|
-
getModules() {
|
|
418
|
-
return this.application.getModules();
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Return application definition
|
|
422
|
-
*/
|
|
423
|
-
getApplication() {
|
|
424
|
-
return this.application;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Get WorkerOutput
|
|
428
|
-
*/
|
|
429
|
-
getWorkerOutput() {
|
|
430
|
-
return this.workerOutput;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Init one service
|
|
434
|
-
* @param service
|
|
435
|
-
*/
|
|
436
|
-
async initService(service) {
|
|
437
|
-
try {
|
|
438
|
-
this.log("TRACE", "Initializing service", service);
|
|
439
|
-
this.services[service]._initTime = Date.now();
|
|
440
|
-
await this.services[service].init();
|
|
441
|
-
}
|
|
442
|
-
catch (err) {
|
|
443
|
-
this.services[service]._initException = err;
|
|
444
|
-
this.failedServices[service] = { _initException: err };
|
|
445
|
-
this.log("ERROR", "Init service " + service + " failed: " + err.message);
|
|
446
|
-
this.log("TRACE", err.stack);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Get an object from the application based on its full uuid
|
|
451
|
-
* @param fullUuid
|
|
452
|
-
* @param partials
|
|
453
|
-
*/
|
|
454
|
-
async getModelObject(fullUuid, partials) {
|
|
455
|
-
return CoreModel.fromFullUuid(fullUuid, this, partials);
|
|
456
|
-
}
|
|
457
|
-
/**
|
|
458
|
-
* Init Webda
|
|
459
|
-
*
|
|
460
|
-
* It will resolve Services init method and autolink
|
|
461
|
-
*/
|
|
462
|
-
async init() {
|
|
463
|
-
if (this._init) {
|
|
464
|
-
return this._init;
|
|
465
|
-
}
|
|
466
|
-
if (this.configuration.parameters.configurationService) {
|
|
467
|
-
try {
|
|
468
|
-
this.log("INFO", "Create and init ConfigurationService", this.configuration.parameters.configurationService);
|
|
469
|
-
// Create the configuration service
|
|
470
|
-
this.createService(this.configuration.services, this.configuration.parameters.configurationService);
|
|
471
|
-
let cfg = await this.getService(this.configuration.parameters.configurationService).initConfiguration();
|
|
472
|
-
if (cfg) {
|
|
473
|
-
cfg.parameters ?? (cfg.parameters = {});
|
|
474
|
-
cfg.services ?? (cfg.services = {});
|
|
475
|
-
this.configuration.parameters = deepmerge(this.configuration.parameters, cfg.parameters);
|
|
476
|
-
// Ensure beans are known too
|
|
477
|
-
Object.keys(this.getBeans()).forEach(bean => {
|
|
478
|
-
var _a;
|
|
479
|
-
(_a = this.configuration.services)[bean] ?? (_a[bean] = {
|
|
480
|
-
type: `Beans/${bean}`
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
// Merge services - for security reason we cannot add new services from configuration
|
|
484
|
-
for (let i in this.configuration.services) {
|
|
485
|
-
this.configuration.services[i] = {
|
|
486
|
-
...deepmerge(this.configuration.services[i], cfg.services[i] || {}),
|
|
487
|
-
type: this.configuration.services[i].type
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
await this.getService(this.configuration.parameters.configurationService).init();
|
|
492
|
-
}
|
|
493
|
-
catch (err) {
|
|
494
|
-
this.log("ERROR", "Cannot use ConfigurationService", this.configuration.parameters.configurationService, err);
|
|
495
|
-
this.services = {};
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
// Init the other services
|
|
499
|
-
this.initStatics();
|
|
500
|
-
// Reset the model cache
|
|
501
|
-
this._modelStoresCache.clear();
|
|
502
|
-
this._modelBinariesCache.clear();
|
|
503
|
-
this.log("TRACE", "Create Webda init promise");
|
|
504
|
-
this._init = (async () => {
|
|
505
|
-
await this.initService("Registry");
|
|
506
|
-
await this.initService("CryptoService");
|
|
507
|
-
// Init services
|
|
508
|
-
let service;
|
|
509
|
-
let inits = [];
|
|
510
|
-
for (service in this.services) {
|
|
511
|
-
if (this.services[service].init !== undefined &&
|
|
512
|
-
!this.services[service]._createException &&
|
|
513
|
-
!this.services[service]._initTime) {
|
|
514
|
-
inits.push(this.initService(service));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
await Promise.all(inits);
|
|
518
|
-
await this.emitSync("Webda.Init.Services", this.services);
|
|
519
|
-
})();
|
|
520
|
-
return this._init;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Pause for time ms
|
|
524
|
-
*
|
|
525
|
-
* @param time ms
|
|
526
|
-
*/
|
|
527
|
-
static async sleep(time) {
|
|
528
|
-
return new Promise(resolve => {
|
|
529
|
-
setTimeout(resolve, time);
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Check if an operation can be executed with the current context
|
|
534
|
-
* Not checking the input use `checkOperation` instead to check everything
|
|
535
|
-
* @param context
|
|
536
|
-
* @param operationId
|
|
537
|
-
* @throws OperationError if operation is unknown
|
|
538
|
-
* @returns true if operation can be executed
|
|
539
|
-
*/
|
|
540
|
-
checkOperationPermission(context, operationId) {
|
|
541
|
-
var _a;
|
|
542
|
-
if (!this.operations[operationId]) {
|
|
543
|
-
throw new OperationError(operationId, "Unknown");
|
|
544
|
-
}
|
|
545
|
-
if (this.operations[operationId].permission) {
|
|
546
|
-
(_a = this.operations[operationId]).permissionQuery ?? (_a.permissionQuery = new WebdaQL.QueryValidator(this.operations[operationId].permission));
|
|
547
|
-
return this.operations[operationId].permissionQuery.eval(context.getSession());
|
|
548
|
-
}
|
|
549
|
-
return true;
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Check if an operation can be executed with the current context
|
|
553
|
-
* @param context
|
|
554
|
-
* @param operationId
|
|
555
|
-
*/
|
|
556
|
-
async checkOperation(context, operationId) {
|
|
557
|
-
if (!this.checkOperationPermission(context, operationId)) {
|
|
558
|
-
throw new OperationError(operationId, "PermissionDenied");
|
|
559
|
-
}
|
|
560
|
-
let input = await context.getInput();
|
|
561
|
-
this.log("TRACE", `Operation ${operationId} input is '${JSONUtils.safeStringify(input, undefined, 2)}' (schema: ${this.operations[operationId].input})`);
|
|
562
|
-
try {
|
|
563
|
-
if (this.operations[operationId].input &&
|
|
564
|
-
(input === undefined || this.validateSchema(this.operations[operationId].input, input) !== true)) {
|
|
565
|
-
throw new OperationError(operationId, "InvalidInput");
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
catch (err) {
|
|
569
|
-
if (err instanceof ValidationError) {
|
|
570
|
-
throw new OperationError(operationId, "InvalidInput");
|
|
571
|
-
}
|
|
572
|
-
throw err;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Call an operation within the framework
|
|
577
|
-
*/
|
|
578
|
-
async callOperation(context, operationId) {
|
|
579
|
-
context.setExtension("operation", operationId);
|
|
580
|
-
await this.checkOperation(context, operationId);
|
|
581
|
-
return this.getService(this.operations[operationId].service)[this.operations[operationId].method](context);
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Get available operations
|
|
585
|
-
* @returns
|
|
586
|
-
*/
|
|
587
|
-
listOperations() {
|
|
588
|
-
const list = {};
|
|
589
|
-
Object.keys(this.operations).forEach(o => {
|
|
590
|
-
list[o] = {
|
|
591
|
-
...this.operations[o]
|
|
592
|
-
};
|
|
593
|
-
delete list[o].service;
|
|
594
|
-
delete list[o].method;
|
|
595
|
-
});
|
|
596
|
-
return list;
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Register a new operation within the app
|
|
600
|
-
* @param operationId
|
|
601
|
-
* @param definition
|
|
602
|
-
*/
|
|
603
|
-
registerOperation(operationId, definition) {
|
|
604
|
-
if (operationId.match(/[^a-zA-Z0-9.]/)) {
|
|
605
|
-
throw new Error("OperationId can only contain [a-zA-Z0-9.]");
|
|
606
|
-
}
|
|
607
|
-
this.operations[operationId] = { ...definition, id: operationId };
|
|
608
|
-
["input", "output"]
|
|
609
|
-
.filter(key => this.operations[operationId][key])
|
|
610
|
-
.forEach(key => {
|
|
611
|
-
if (!this.getApplication().hasSchema(this.operations[operationId][key])) {
|
|
612
|
-
delete this.operations[operationId][key];
|
|
613
|
-
}
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* Register a request filtering
|
|
618
|
-
*
|
|
619
|
-
* Will apply to all requests regardless of the devMode
|
|
620
|
-
* @param filter
|
|
621
|
-
*/
|
|
622
|
-
registerRequestFilter(filter) {
|
|
623
|
-
this._requestFilters.push(filter);
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Register a CORS request filtering
|
|
627
|
-
*
|
|
628
|
-
* Does not apply in devMode
|
|
629
|
-
* @param filter
|
|
630
|
-
*/
|
|
631
|
-
registerCORSFilter(filter) {
|
|
632
|
-
this._requestCORSFilters.push(filter);
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Register a new context provider
|
|
636
|
-
* @param provider
|
|
637
|
-
*/
|
|
638
|
-
registerContextProvider(provider) {
|
|
639
|
-
this._contextProviders.unshift(provider);
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Validate the object with schema
|
|
643
|
-
*
|
|
644
|
-
* @param schema path to use
|
|
645
|
-
* @param object to validate
|
|
646
|
-
*/
|
|
647
|
-
validateSchema(webdaObject, object, ignoreRequired) {
|
|
648
|
-
let name = typeof webdaObject === "string" ? webdaObject : this.application.getModelFromInstance(webdaObject);
|
|
649
|
-
let cacheName = name;
|
|
650
|
-
if (name?.endsWith("?")) {
|
|
651
|
-
name = name.substring(0, name.length - 1);
|
|
652
|
-
ignoreRequired = true;
|
|
653
|
-
}
|
|
654
|
-
if (ignoreRequired) {
|
|
655
|
-
cacheName += "_noRequired";
|
|
656
|
-
}
|
|
657
|
-
if (!this._ajvSchemas[cacheName]) {
|
|
658
|
-
let schema = this.application.getSchema(name);
|
|
659
|
-
if (!schema) {
|
|
660
|
-
return null;
|
|
661
|
-
}
|
|
662
|
-
if (ignoreRequired) {
|
|
663
|
-
schema = JSONUtils.duplicate(schema);
|
|
664
|
-
schema.required = [];
|
|
665
|
-
}
|
|
666
|
-
this.log("TRACE", "Add schema for", name);
|
|
667
|
-
this._ajv.addSchema(schema, cacheName);
|
|
668
|
-
this._ajvSchemas[cacheName] = true;
|
|
669
|
-
}
|
|
670
|
-
if (this._ajv.validate(cacheName, object)) {
|
|
671
|
-
return true;
|
|
672
|
-
}
|
|
673
|
-
throw new ValidationError(this._ajv.errors);
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Return webda current version
|
|
677
|
-
*
|
|
678
|
-
* @returns package version
|
|
679
|
-
* @since 0.4.0
|
|
680
|
-
*/
|
|
681
|
-
getVersion() {
|
|
682
|
-
return this.getApplication().getWebdaVersion();
|
|
683
|
-
}
|
|
684
|
-
/**
|
|
685
|
-
* To define the locales just add a locales: ['en-GB', 'fr-FR'] in your host global configuration
|
|
686
|
-
*
|
|
687
|
-
* @return The configured locales or "en-GB" if none are defined
|
|
688
|
-
*/
|
|
689
|
-
getLocales() {
|
|
690
|
-
if (!this.configuration || !this.configuration.parameters.locales) {
|
|
691
|
-
return ["en-GB"];
|
|
692
|
-
}
|
|
693
|
-
return this.configuration.parameters.locales;
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Get a Logger for a class
|
|
697
|
-
* @param clazz
|
|
698
|
-
*/
|
|
699
|
-
getLogger(clazz) {
|
|
700
|
-
let className = clazz;
|
|
701
|
-
if (typeof clazz !== "string") {
|
|
702
|
-
let definitions = this.application.getModdas();
|
|
703
|
-
for (let i in definitions) {
|
|
704
|
-
if (definitions[i] === clazz.constructor) {
|
|
705
|
-
className = i.replace(/\//g, ".");
|
|
706
|
-
break;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return new Logger(this.workerOutput, className);
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Add a route dynamicaly
|
|
714
|
-
*
|
|
715
|
-
* @param {String} url of the route can contains dynamic part like {uuid}
|
|
716
|
-
* @param {Object} info the type of executor
|
|
717
|
-
*/
|
|
718
|
-
addRoute(url, info) {
|
|
719
|
-
this.router.addRoute(url, info);
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Remove a route dynamicly
|
|
723
|
-
*
|
|
724
|
-
* @param {String} url to remove
|
|
725
|
-
*/
|
|
726
|
-
removeRoute(url) {
|
|
727
|
-
this.router.removeRoute(url);
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
* Return current Router object
|
|
731
|
-
*/
|
|
732
|
-
getRouter() {
|
|
733
|
-
return this.router;
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Check for a service name and return the wanted singleton or undefined if none found
|
|
737
|
-
*
|
|
738
|
-
* @param {String} name The service name to retrieve
|
|
739
|
-
*/
|
|
740
|
-
getService(name = "") {
|
|
741
|
-
return this.services[name];
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* Return a map of defined services
|
|
745
|
-
* @returns {{}}
|
|
746
|
-
*/
|
|
747
|
-
getServices() {
|
|
748
|
-
return this.services;
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Return a map of services that extends type
|
|
752
|
-
* @param type The type of implementation
|
|
753
|
-
* @returns {{}}
|
|
754
|
-
*/
|
|
755
|
-
getServicesOfType(type = undefined) {
|
|
756
|
-
let result = {};
|
|
757
|
-
for (let i in this.services) {
|
|
758
|
-
let service = this.services[i];
|
|
759
|
-
if (!type || service instanceof type) {
|
|
760
|
-
result[i] = service;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return result;
|
|
764
|
-
}
|
|
765
|
-
getConfiguration() {
|
|
766
|
-
return this.configuration;
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Return a map of defined stores
|
|
770
|
-
* @returns {{}}
|
|
771
|
-
*/
|
|
772
|
-
getStores() {
|
|
773
|
-
return this.getServicesOfType(Store);
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Return a map of defined models
|
|
777
|
-
* @returns {{}}
|
|
778
|
-
*/
|
|
779
|
-
getModels() {
|
|
780
|
-
return this.application.getModels();
|
|
781
|
-
}
|
|
782
|
-
/**
|
|
783
|
-
* Check for a model name and return the wanted class or throw exception if none found
|
|
784
|
-
*
|
|
785
|
-
* @param {String} name The model name to retrieve
|
|
786
|
-
*/
|
|
787
|
-
getModel(name) {
|
|
788
|
-
return this.application.getModel(name);
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* Add to context information and executor based on the http context
|
|
792
|
-
*/
|
|
793
|
-
updateContextWithRoute(ctx) {
|
|
794
|
-
let http = ctx.getHttpContext();
|
|
795
|
-
// Check mapping
|
|
796
|
-
let route = this.router.getRouteFromUrl(ctx, http.getMethod(), http.getRelativeUri());
|
|
797
|
-
if (route === undefined) {
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
ctx.setRoute({ ...this.configuration, ...route });
|
|
801
|
-
ctx.setExecutor(this.getService(route.executor));
|
|
802
|
-
this.emit("Webda.UpdateContextRoute", { context: ctx });
|
|
803
|
-
return true;
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Flush the headers to the response, no more header modification is possible after that
|
|
807
|
-
*
|
|
808
|
-
* This method should set the `context.setFlushedHeaders()` and use of `context.hasFlushedHeaders()`
|
|
809
|
-
*
|
|
810
|
-
* @abstract
|
|
811
|
-
*/
|
|
812
|
-
flushHeaders(_context) {
|
|
813
|
-
// Should be overriden by implementation
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Flush the entire response to the client
|
|
817
|
-
*/
|
|
818
|
-
flush(_context) {
|
|
819
|
-
// Should be overriden by implementation
|
|
820
|
-
}
|
|
821
|
-
/**
|
|
822
|
-
* Return if Webda is in debug mode
|
|
823
|
-
*/
|
|
824
|
-
isDebug() {
|
|
825
|
-
return false;
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* Return the global parameters of a domain
|
|
829
|
-
*/
|
|
830
|
-
getGlobalParams() {
|
|
831
|
-
return this.configuration.parameters || {};
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Get the system context
|
|
835
|
-
* @returns
|
|
836
|
-
*/
|
|
837
|
-
getGlobalContext() {
|
|
838
|
-
return this.globalContext;
|
|
839
|
-
}
|
|
840
|
-
/**
|
|
841
|
-
* Set the system context
|
|
842
|
-
* @param context
|
|
843
|
-
*/
|
|
844
|
-
setGlobalContext(context) {
|
|
845
|
-
this.globalContext = context;
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Reinit one service
|
|
849
|
-
* @param service
|
|
850
|
-
*/
|
|
851
|
-
async reinitService(service) {
|
|
852
|
-
try {
|
|
853
|
-
this.log("TRACE", "Re-Initializing service", service);
|
|
854
|
-
let serviceBean = this.services[service];
|
|
855
|
-
await serviceBean.reinit(this.getServiceParams(serviceBean.getName()));
|
|
856
|
-
}
|
|
857
|
-
catch (err) {
|
|
858
|
-
this.log("ERROR", "Re-Init service " + service + " failed", err);
|
|
859
|
-
this.log("TRACE", err.stack);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
/**
|
|
863
|
-
* Reinit all services with updated parameters
|
|
864
|
-
* @param updates
|
|
865
|
-
* @returns
|
|
866
|
-
*/
|
|
867
|
-
async reinit(updates) {
|
|
868
|
-
let configuration = JSON.parse(JSON.stringify(this.configuration.services));
|
|
869
|
-
for (let service in updates) {
|
|
870
|
-
jsonpath.value(configuration, service, updates[service]);
|
|
871
|
-
}
|
|
872
|
-
if (JSON.stringify(Object.keys(configuration)) !== JSON.stringify(Object.keys(this.configuration.services))) {
|
|
873
|
-
this.log("ERROR", "Configuration update cannot modify services");
|
|
874
|
-
throw new WebdaError.CodeError("REINIT_SERVICE_INJECTION", "Configuration is not designed to add dynamically services");
|
|
875
|
-
}
|
|
876
|
-
this.configuration.services = configuration;
|
|
877
|
-
let inits = [];
|
|
878
|
-
for (let service in this.services) {
|
|
879
|
-
inits.push(this.reinitService(service));
|
|
880
|
-
}
|
|
881
|
-
await Promise.all(inits);
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Get a full resolved service parameter
|
|
885
|
-
*
|
|
886
|
-
* @param service
|
|
887
|
-
* @param configuration
|
|
888
|
-
* @returns
|
|
889
|
-
*/
|
|
890
|
-
getServiceParams(service, configuration = { parameters: {}, services: {} }) {
|
|
891
|
-
var _a;
|
|
892
|
-
configuration.parameters ?? (configuration.parameters = {});
|
|
893
|
-
configuration.services ?? (configuration.services = {});
|
|
894
|
-
(_a = configuration.services)[service] ?? (_a[service] = {});
|
|
895
|
-
const params = deepmerge(this.configuration.parameters || {}, configuration.parameters || {}, this.configuration.services[service] || {}, configuration.services[service] || {});
|
|
896
|
-
delete params.require;
|
|
897
|
-
return params;
|
|
898
|
-
}
|
|
899
|
-
createService(services, service) {
|
|
900
|
-
let type = services[service]?.type;
|
|
901
|
-
if (type === undefined) {
|
|
902
|
-
type = service;
|
|
903
|
-
}
|
|
904
|
-
let serviceConstructor = undefined;
|
|
905
|
-
try {
|
|
906
|
-
serviceConstructor = this.application.getModda(type);
|
|
907
|
-
}
|
|
908
|
-
catch (ex) {
|
|
909
|
-
this.log("ERROR", `Create service ${service}(${type}) failed ${ex.message}`);
|
|
910
|
-
this.log("TRACE", ex.stack);
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
try {
|
|
914
|
-
this.log("TRACE", "Constructing service", service);
|
|
915
|
-
this.services[service] = new serviceConstructor(this, service, this.getServiceParams(service));
|
|
916
|
-
}
|
|
917
|
-
catch (err) {
|
|
918
|
-
this.log("ERROR", "Cannot create service", service, err);
|
|
919
|
-
// @ts-ignore
|
|
920
|
-
this.failedServices[service] = { _createException: err };
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
getBeans() {
|
|
924
|
-
// @ts-ignore
|
|
925
|
-
return process.webdaBeans || {};
|
|
926
|
-
}
|
|
927
|
-
/**
|
|
928
|
-
* @hidden
|
|
929
|
-
*
|
|
930
|
-
*/
|
|
931
|
-
createServices(excludes = []) {
|
|
932
|
-
const services = this.configuration.services;
|
|
933
|
-
const beans = this.getBeans();
|
|
934
|
-
this.log("DEBUG", "BEANS", beans);
|
|
935
|
-
for (let i in beans) {
|
|
936
|
-
let name = beans[i].name;
|
|
937
|
-
if (!services[name]) {
|
|
938
|
-
services[name] = {};
|
|
939
|
-
}
|
|
940
|
-
// Force type to Bean
|
|
941
|
-
services[name].type = `Beans/${name}`;
|
|
942
|
-
// Register the type
|
|
943
|
-
this.application.addService(`Beans/${name}`, beans[i]);
|
|
944
|
-
}
|
|
945
|
-
// Construct services
|
|
946
|
-
for (let service in services) {
|
|
947
|
-
if (excludes.indexOf(service) >= 0) {
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
this.createService(services, service);
|
|
951
|
-
}
|
|
952
|
-
// Call resolve on all services
|
|
953
|
-
Object.keys(this.services)
|
|
954
|
-
.filter(s => !excludes.includes(s))
|
|
955
|
-
.forEach(s => {
|
|
956
|
-
try {
|
|
957
|
-
this.services[s].resolve();
|
|
958
|
-
}
|
|
959
|
-
catch (err) {
|
|
960
|
-
this.log("ERROR", `Service(${s})`, err);
|
|
961
|
-
}
|
|
962
|
-
});
|
|
963
|
-
this.emit("Webda.Create.Services", this.services);
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* A registry is a predefined store
|
|
967
|
-
* @returns
|
|
968
|
-
*/
|
|
969
|
-
getRegistry() {
|
|
970
|
-
return this.registry;
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* Return the crypto service
|
|
974
|
-
* @returns
|
|
975
|
-
*/
|
|
976
|
-
getCrypto() {
|
|
977
|
-
return this.cryptoService;
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* Stop all services
|
|
981
|
-
*/
|
|
982
|
-
async stop() {
|
|
983
|
-
const services = this.getServices();
|
|
984
|
-
await Promise.all(Object.keys(services).map(async (s) => {
|
|
985
|
-
try {
|
|
986
|
-
await services[s].stop();
|
|
987
|
-
}
|
|
988
|
-
catch (err) {
|
|
989
|
-
this.log("ERROR", `Cannot stop service ${s}`, err);
|
|
990
|
-
}
|
|
991
|
-
}));
|
|
992
|
-
}
|
|
993
|
-
jsonFilter(key, value) {
|
|
994
|
-
if (key[0] === "_")
|
|
995
|
-
return undefined;
|
|
996
|
-
return value;
|
|
997
|
-
}
|
|
998
|
-
static getMachineId() {
|
|
999
|
-
try {
|
|
1000
|
-
return process.env["WEBDA_MACHINE_ID"] || machineIdSync();
|
|
1001
|
-
/* c8 ignore next 4 */
|
|
1002
|
-
}
|
|
1003
|
-
catch (err) {
|
|
1004
|
-
// Useful in k8s pod
|
|
1005
|
-
return process.env["HOSTNAME"];
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
/**
|
|
1009
|
-
* Init services and Beans along with Routes
|
|
1010
|
-
*/
|
|
1011
|
-
initStatics() {
|
|
1012
|
-
var _a, _b, _c;
|
|
1013
|
-
// Init the registry
|
|
1014
|
-
const autoRegistry = this.configuration.services["Registry"] === undefined;
|
|
1015
|
-
(_a = this.configuration.services)["Registry"] ?? (_a["Registry"] = {
|
|
1016
|
-
type: "Webda/MemoryStore",
|
|
1017
|
-
persistence: {
|
|
1018
|
-
path: ".registry",
|
|
1019
|
-
key: Core.getMachineId()
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
|
-
this.createService(this.configuration.services, "Registry");
|
|
1023
|
-
this.registry = this.getService("Registry").resolve();
|
|
1024
|
-
// Init the key service
|
|
1025
|
-
(_b = this.configuration.services)["CryptoService"] ?? (_b["CryptoService"] = {
|
|
1026
|
-
type: "Webda/CryptoService",
|
|
1027
|
-
autoRotate: autoRegistry ? 30 : undefined,
|
|
1028
|
-
autoCreate: true
|
|
1029
|
-
});
|
|
1030
|
-
this.createService(this.configuration.services, "CryptoService");
|
|
1031
|
-
this.cryptoService = this.getService("CryptoService").resolve();
|
|
1032
|
-
// Session Manager
|
|
1033
|
-
(_c = this.configuration.services)["SessionManager"] ?? (_c["SessionManager"] = {
|
|
1034
|
-
type: "Webda/CookieSessionManager"
|
|
1035
|
-
});
|
|
1036
|
-
if (this.configuration.services !== undefined) {
|
|
1037
|
-
let excludes = ["Registry", "CryptoService"];
|
|
1038
|
-
if (this.configuration.parameters.configurationService) {
|
|
1039
|
-
excludes.push(this.configuration.parameters.configurationService);
|
|
1040
|
-
}
|
|
1041
|
-
// Do not recreate the configuration services
|
|
1042
|
-
this.createServices(excludes);
|
|
1043
|
-
}
|
|
1044
|
-
this.router.remapRoutes();
|
|
1045
|
-
this._initiated = true;
|
|
1046
|
-
this.emit("Webda.Init", this.configuration);
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Get a context based on the info
|
|
1050
|
-
* @param info
|
|
1051
|
-
* @returns
|
|
1052
|
-
*/
|
|
1053
|
-
async newContext(info, noInit = false) {
|
|
1054
|
-
let context;
|
|
1055
|
-
this._contextProviders.find(provider => (context = provider.getContext(info)) !== undefined);
|
|
1056
|
-
if (!noInit) {
|
|
1057
|
-
await context.init();
|
|
1058
|
-
}
|
|
1059
|
-
await this.emitSync("Webda.NewContext", { context, info });
|
|
1060
|
-
return context;
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Create a new context for a request
|
|
1064
|
-
*
|
|
1065
|
-
* @class Service
|
|
1066
|
-
* @param httpContext THe HTTP request context
|
|
1067
|
-
* @param stream - The request output stream if any
|
|
1068
|
-
* @return A new context object to pass along
|
|
1069
|
-
*/
|
|
1070
|
-
async newWebContext(httpContext, stream = undefined, noInit = false) {
|
|
1071
|
-
return await this.newContext({ http: httpContext, stream: stream });
|
|
1072
|
-
}
|
|
1073
|
-
/**
|
|
1074
|
-
* Convert an object to JSON using the Webda json filter
|
|
1075
|
-
*
|
|
1076
|
-
* @class Service
|
|
1077
|
-
* @param {Object} object - The object to export
|
|
1078
|
-
* @return {String} The export of the strip object ( removed all attribute with _ )
|
|
1079
|
-
*/
|
|
1080
|
-
toPublicJSON(object) {
|
|
1081
|
-
return JSON.stringify(object, this.jsonFilter);
|
|
1082
|
-
}
|
|
1083
|
-
/**
|
|
1084
|
-
* Return a UUID
|
|
1085
|
-
*
|
|
1086
|
-
* @param format to return different type of format
|
|
1087
|
-
* Plan to implement base64 and maybe base85
|
|
1088
|
-
*/
|
|
1089
|
-
getUuid(format = "uuid") {
|
|
1090
|
-
let uid = randomUUID();
|
|
1091
|
-
if (format === "uuid") {
|
|
1092
|
-
return uid;
|
|
1093
|
-
}
|
|
1094
|
-
let buffer = Buffer.from(uid.replace(/-/g, ""), "hex");
|
|
1095
|
-
if (format === "base64") {
|
|
1096
|
-
// Remove useless = we won't transfer back to original value or could just add ==
|
|
1097
|
-
// https://datatracker.ietf.org/doc/html/rfc4648#page-7
|
|
1098
|
-
return buffer.toString(format).replace(/=/g, "").replace(/\//g, "_").replace(/\+/g, "-");
|
|
1099
|
-
}
|
|
1100
|
-
return buffer.toString(format);
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* @override
|
|
1104
|
-
*/
|
|
1105
|
-
emit(eventType, event, ...data) {
|
|
1106
|
-
return super.emit(eventType, event, ...data);
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Emit the event with data and wait for Promise to finish if listener returned a Promise
|
|
1110
|
-
*/
|
|
1111
|
-
emitSync(eventType, event, ...data) {
|
|
1112
|
-
let result;
|
|
1113
|
-
let promises = [];
|
|
1114
|
-
let listeners = this.listeners(eventType);
|
|
1115
|
-
for (let listener of listeners) {
|
|
1116
|
-
result = listener(event, ...data);
|
|
1117
|
-
if (result instanceof Promise) {
|
|
1118
|
-
promises.push(result);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return Promise.all(promises);
|
|
1122
|
-
}
|
|
1123
|
-
/**
|
|
1124
|
-
* Type the listener part
|
|
1125
|
-
* @param event
|
|
1126
|
-
* @param listener
|
|
1127
|
-
* @param queue
|
|
1128
|
-
* @returns
|
|
1129
|
-
*/
|
|
1130
|
-
on(event, listener) {
|
|
1131
|
-
super.on(event, listener);
|
|
1132
|
-
return this;
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Logs
|
|
1136
|
-
* @param level
|
|
1137
|
-
* @param args
|
|
1138
|
-
*/
|
|
1139
|
-
log(level, ...args) {
|
|
1140
|
-
this.logger.log(level, ...args);
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Retrieve a global parameter
|
|
1144
|
-
*/
|
|
1145
|
-
parameter(name) {
|
|
1146
|
-
return this.getGlobalParams()[name];
|
|
1147
|
-
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Verify if a request can be done
|
|
1150
|
-
*
|
|
1151
|
-
* @param context Context of the request
|
|
1152
|
-
*/
|
|
1153
|
-
async checkRequest(ctx) {
|
|
1154
|
-
// Do not need to filter on OPTIONS as CORS is for that
|
|
1155
|
-
if (ctx.getHttpContext().getMethod() === "OPTIONS" || this._requestFilters.length === 0) {
|
|
1156
|
-
return true;
|
|
1157
|
-
}
|
|
1158
|
-
return (await Promise.all(this._requestFilters.map(filter => filter.checkRequest(ctx, "AUTH")))).some(v => v);
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* Verify if an origin is allowed to do request on the API
|
|
1162
|
-
*
|
|
1163
|
-
* @param context Context of the request
|
|
1164
|
-
*/
|
|
1165
|
-
async checkCORSRequest(ctx) {
|
|
1166
|
-
return (await Promise.all(this._requestCORSFilters.map(filter => filter.checkRequest(ctx, "CORS")))).some(v => v);
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* Export OpenAPI
|
|
1170
|
-
* @param skipHidden
|
|
1171
|
-
* @returns
|
|
1172
|
-
*/
|
|
1173
|
-
exportOpenAPI(skipHidden = true) {
|
|
1174
|
-
var _a, _b, _c;
|
|
1175
|
-
let packageInfo = this.application.getPackageDescription();
|
|
1176
|
-
let contact;
|
|
1177
|
-
if (typeof packageInfo.author === "string") {
|
|
1178
|
-
contact = {
|
|
1179
|
-
name: packageInfo.author
|
|
1180
|
-
};
|
|
1181
|
-
}
|
|
1182
|
-
else if (packageInfo.author) {
|
|
1183
|
-
contact = packageInfo.author;
|
|
1184
|
-
}
|
|
1185
|
-
let license;
|
|
1186
|
-
if (typeof packageInfo.license === "string") {
|
|
1187
|
-
license = {
|
|
1188
|
-
name: packageInfo.license
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
else if (packageInfo.license) {
|
|
1192
|
-
license = packageInfo.license;
|
|
1193
|
-
}
|
|
1194
|
-
let openapi = deepmerge({
|
|
1195
|
-
openapi: "3.0.3",
|
|
1196
|
-
info: {
|
|
1197
|
-
description: packageInfo.description,
|
|
1198
|
-
version: packageInfo.version || "0.0.0",
|
|
1199
|
-
title: packageInfo.title || "Webda-based application",
|
|
1200
|
-
termsOfService: packageInfo.termsOfService,
|
|
1201
|
-
contact,
|
|
1202
|
-
license
|
|
1203
|
-
},
|
|
1204
|
-
components: {
|
|
1205
|
-
schemas: {
|
|
1206
|
-
Object: {
|
|
1207
|
-
type: "object"
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
},
|
|
1211
|
-
paths: {},
|
|
1212
|
-
tags: []
|
|
1213
|
-
}, this.application.getConfiguration().openapi || {});
|
|
1214
|
-
let models = this.application.getModels();
|
|
1215
|
-
const schemas = this.application.getSchemas();
|
|
1216
|
-
// Copy all input/output from actions
|
|
1217
|
-
for (let i in schemas) {
|
|
1218
|
-
if (!(i.endsWith(".input") || i.endsWith(".output"))) {
|
|
1219
|
-
continue;
|
|
1220
|
-
}
|
|
1221
|
-
// @ts-ignore
|
|
1222
|
-
(_a = openapi.components.schemas)[i] ?? (_a[i] = schemas[i]);
|
|
1223
|
-
// Not sure how to test following
|
|
1224
|
-
/* c8 ignore next 5 */
|
|
1225
|
-
for (let j in schemas[i].definitions) {
|
|
1226
|
-
// @ts-ignore
|
|
1227
|
-
(_b = openapi.components.schemas)[j] ?? (_b[j] = schemas[i].definitions[j]);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
for (let i in models) {
|
|
1231
|
-
let model = models[i];
|
|
1232
|
-
let desc = {
|
|
1233
|
-
type: "object"
|
|
1234
|
-
};
|
|
1235
|
-
let modelName = model.name || i.split("/").pop();
|
|
1236
|
-
let schema = this.application.getSchema(i);
|
|
1237
|
-
if (schema) {
|
|
1238
|
-
for (let j in schema.definitions) {
|
|
1239
|
-
// @ts-ignore
|
|
1240
|
-
(_c = openapi.components.schemas)[j] ?? (_c[j] = schema.definitions[j]);
|
|
1241
|
-
}
|
|
1242
|
-
delete schema.definitions;
|
|
1243
|
-
desc = schema;
|
|
1244
|
-
}
|
|
1245
|
-
// Remove empty required as openapi does not like that
|
|
1246
|
-
// Our compiler is not generating this anymore but it is additional protection
|
|
1247
|
-
/* c8 ignore next 3 */
|
|
1248
|
-
if (desc.required && desc.required.length === 0) {
|
|
1249
|
-
delete desc.required;
|
|
1250
|
-
}
|
|
1251
|
-
// Remove $schema
|
|
1252
|
-
delete desc.$schema;
|
|
1253
|
-
// Rename all #/definitions/ by #/components/schemas/
|
|
1254
|
-
openapi.components.schemas[modelName] = JSON.parse(JSON.stringify(desc).replace(/#\/definitions\//g, "#/components/schemas/"));
|
|
1255
|
-
}
|
|
1256
|
-
this.router.completeOpenAPI(openapi, skipHidden);
|
|
1257
|
-
openapi.tags.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
1258
|
-
let paths = {};
|
|
1259
|
-
Object.keys(openapi.paths)
|
|
1260
|
-
.sort()
|
|
1261
|
-
.forEach(i => (paths[i] = openapi.paths[i]));
|
|
1262
|
-
openapi.paths = paths;
|
|
1263
|
-
return openapi;
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Get a metric object
|
|
1267
|
-
*
|
|
1268
|
-
* Use the Service.getMetric method if possible
|
|
1269
|
-
*
|
|
1270
|
-
* This is map from prometheus 3 types of metrics
|
|
1271
|
-
* Our hope is that we can adapt them to export to other
|
|
1272
|
-
* metrics system if needed
|
|
1273
|
-
*
|
|
1274
|
-
* @param type
|
|
1275
|
-
* @param configuration
|
|
1276
|
-
* @returns
|
|
1277
|
-
*/
|
|
1278
|
-
getMetric(type, configuration) {
|
|
1279
|
-
const metrics = this.getGlobalParams().metrics;
|
|
1280
|
-
if (metrics === false) {
|
|
1281
|
-
// Return a mock
|
|
1282
|
-
return {
|
|
1283
|
-
inc: () => { },
|
|
1284
|
-
reset: () => { },
|
|
1285
|
-
labels: () => undefined,
|
|
1286
|
-
remove: () => { },
|
|
1287
|
-
observe: () => { },
|
|
1288
|
-
startTimer: () => {
|
|
1289
|
-
return () => 0;
|
|
1290
|
-
},
|
|
1291
|
-
zero: () => { },
|
|
1292
|
-
dec: () => { },
|
|
1293
|
-
setToCurrentTime: () => { },
|
|
1294
|
-
set: () => { }
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
const name = `${metrics.prefix}webda_${configuration.name}`;
|
|
1298
|
-
const labelNames = [...(configuration.labelNames || []), ...Object.keys(metrics.labels)];
|
|
1299
|
-
// Will probably need to override with a staticLabels property
|
|
1300
|
-
return (register.getSingleMetric(name) ||
|
|
1301
|
-
new type({
|
|
1302
|
-
...configuration,
|
|
1303
|
-
...metrics.config[configuration.name],
|
|
1304
|
-
name,
|
|
1305
|
-
labelNames
|
|
1306
|
-
}));
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
export { Counter, Gauge, Histogram };
|
|
1310
|
-
//# sourceMappingURL=core.js.map
|