@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/services/binary.js
DELETED
|
@@ -1,986 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
import * as crypto from "crypto";
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as mime from "mime-types";
|
|
11
|
-
import * as path from "path";
|
|
12
|
-
import { Readable } from "stream";
|
|
13
|
-
import { Core, Counter, WebdaError } from "../index.js";
|
|
14
|
-
import { NotEnumerable } from "../models/coremodel.js";
|
|
15
|
-
import { Store } from "../stores/store.js";
|
|
16
|
-
import { Service, ServiceParameters } from "./service.js";
|
|
17
|
-
/**
|
|
18
|
-
* Emitted if binary does not exist
|
|
19
|
-
*/
|
|
20
|
-
export class BinaryNotFoundError extends WebdaError.CodeError {
|
|
21
|
-
constructor(hash, storeName) {
|
|
22
|
-
super("BINARY_NOTFOUND", `Binary not found ${hash} BinaryService(${storeName})`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Represent a file to store
|
|
27
|
-
* @WebdaSchema
|
|
28
|
-
*/
|
|
29
|
-
export class BinaryFile {
|
|
30
|
-
constructor(info) {
|
|
31
|
-
this.set(info);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Set the information
|
|
35
|
-
* @param info
|
|
36
|
-
*/
|
|
37
|
-
set(info) {
|
|
38
|
-
this.name = info.name;
|
|
39
|
-
this.challenge = info.challenge;
|
|
40
|
-
this.hash = info.hash;
|
|
41
|
-
this.mimetype = info.mimetype || "application/octet-stream";
|
|
42
|
-
this.metadata = info.metadata || {};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Retrieve a plain BinaryFileInfo object
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
toBinaryFileInfo() {
|
|
49
|
-
return {
|
|
50
|
-
hash: this.hash,
|
|
51
|
-
size: this.size,
|
|
52
|
-
mimetype: this.mimetype,
|
|
53
|
-
metadata: this.metadata,
|
|
54
|
-
challenge: this.challenge,
|
|
55
|
-
// Fallback on original name
|
|
56
|
-
name: this.name || this.originalname
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Create hashes
|
|
61
|
-
* @param buffer
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
async getHashes() {
|
|
65
|
-
if (!this.hash) {
|
|
66
|
-
// Using MD5 as S3 content verification use md5
|
|
67
|
-
const hash = crypto.createHash("md5");
|
|
68
|
-
const challenge = crypto.createHash("md5");
|
|
69
|
-
const stream = await this.get();
|
|
70
|
-
challenge.update("WEBDA");
|
|
71
|
-
await new Promise((resolve, reject) => {
|
|
72
|
-
stream.on("error", err => reject(err));
|
|
73
|
-
stream.on("end", () => {
|
|
74
|
-
this.hash = hash.digest("hex");
|
|
75
|
-
this.challenge = challenge.digest("hex");
|
|
76
|
-
resolve();
|
|
77
|
-
});
|
|
78
|
-
stream.on("data", chunk => {
|
|
79
|
-
let buffer = Buffer.from(chunk);
|
|
80
|
-
hash.update(buffer);
|
|
81
|
-
challenge.update(buffer);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
hash: this.hash,
|
|
87
|
-
challenge: this.challenge
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export class LocalBinaryFile extends BinaryFile {
|
|
92
|
-
constructor(filePath) {
|
|
93
|
-
super({
|
|
94
|
-
name: path.basename(filePath),
|
|
95
|
-
size: fs.statSync(filePath).size,
|
|
96
|
-
mimetype: mime.lookup(filePath) || "application/octet-stream"
|
|
97
|
-
});
|
|
98
|
-
this.path = filePath;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* @override
|
|
102
|
-
*/
|
|
103
|
-
async get() {
|
|
104
|
-
return fs.createReadStream(this.path);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export class MemoryBinaryFile extends BinaryFile {
|
|
108
|
-
constructor(buffer, info = {}) {
|
|
109
|
-
super({
|
|
110
|
-
...info,
|
|
111
|
-
size: info.size || buffer.length,
|
|
112
|
-
name: info.name || "data.bin",
|
|
113
|
-
mimetype: info.mimetype || "application/octet-stream"
|
|
114
|
-
});
|
|
115
|
-
this.buffer = typeof buffer === "string" ? Buffer.from(buffer) : buffer;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @override
|
|
119
|
-
*/
|
|
120
|
-
async get() {
|
|
121
|
-
return Readable.from(this.buffer);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* This is a map used to retrieve binary
|
|
126
|
-
*
|
|
127
|
-
* @class BinaryMap
|
|
128
|
-
*/
|
|
129
|
-
export class BinaryMap extends BinaryFile {
|
|
130
|
-
constructor(service, obj) {
|
|
131
|
-
super(obj);
|
|
132
|
-
this.set(obj);
|
|
133
|
-
this.__store = service;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Get the binary data
|
|
137
|
-
*
|
|
138
|
-
* @returns
|
|
139
|
-
*/
|
|
140
|
-
get() {
|
|
141
|
-
return this.__store.get(this);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Get into a buffer
|
|
145
|
-
*/
|
|
146
|
-
async getAsBuffer() {
|
|
147
|
-
return BinaryService.streamToBuffer(await this.get());
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Download the binary to a path
|
|
151
|
-
*
|
|
152
|
-
* Shortcut to call {@link Binary.downloadTo} with current object
|
|
153
|
-
*
|
|
154
|
-
* @param filename
|
|
155
|
-
*/
|
|
156
|
-
async downloadTo(filename) {
|
|
157
|
-
return this.__store.downloadTo(this, filename);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Set the http context
|
|
161
|
-
* @param ctx
|
|
162
|
-
*/
|
|
163
|
-
setContext(ctx) {
|
|
164
|
-
this.__ctx = ctx;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
__decorate([
|
|
168
|
-
NotEnumerable
|
|
169
|
-
], BinaryMap.prototype, "__ctx", void 0);
|
|
170
|
-
__decorate([
|
|
171
|
-
NotEnumerable
|
|
172
|
-
], BinaryMap.prototype, "__store", void 0);
|
|
173
|
-
/**
|
|
174
|
-
* One Binary instance
|
|
175
|
-
*/
|
|
176
|
-
export class Binary extends BinaryMap {
|
|
177
|
-
constructor(attribute, model) {
|
|
178
|
-
super(Core.get().getBinaryStore(model, attribute), model[attribute] || {});
|
|
179
|
-
this.empty = model[attribute] === undefined;
|
|
180
|
-
this.attribute = attribute;
|
|
181
|
-
this.model = model;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* isEmpty
|
|
185
|
-
* @returns
|
|
186
|
-
*/
|
|
187
|
-
isEmpty() {
|
|
188
|
-
return this.empty;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Ensure empty is set correctly
|
|
192
|
-
* @param info
|
|
193
|
-
*/
|
|
194
|
-
set(info) {
|
|
195
|
-
super.set(info);
|
|
196
|
-
this.empty = false;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Replace the binary
|
|
200
|
-
* @param id
|
|
201
|
-
* @param ctx
|
|
202
|
-
* @returns
|
|
203
|
-
*/
|
|
204
|
-
async upload(file) {
|
|
205
|
-
await this.__store.store(this.model, this.attribute, file);
|
|
206
|
-
this.set(file);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Delete the binary, if you need to replace just use upload
|
|
210
|
-
*/
|
|
211
|
-
async delete() {
|
|
212
|
-
await this.__store.delete(this.model, this.attribute);
|
|
213
|
-
this.set({});
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Return undefined if no hash
|
|
217
|
-
* @returns
|
|
218
|
-
*/
|
|
219
|
-
toJSON() {
|
|
220
|
-
if (!this.hash) {
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
return this;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
__decorate([
|
|
227
|
-
NotEnumerable
|
|
228
|
-
], Binary.prototype, "model", void 0);
|
|
229
|
-
__decorate([
|
|
230
|
-
NotEnumerable
|
|
231
|
-
], Binary.prototype, "attribute", void 0);
|
|
232
|
-
__decorate([
|
|
233
|
-
NotEnumerable
|
|
234
|
-
], Binary.prototype, "empty", void 0);
|
|
235
|
-
/**
|
|
236
|
-
* Define a Binary map stored in a Binaries collection
|
|
237
|
-
*/
|
|
238
|
-
export class BinariesItem extends BinaryMap {
|
|
239
|
-
constructor(parent, info) {
|
|
240
|
-
super(parent.__service, info);
|
|
241
|
-
this.parent = parent;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Replace the binary
|
|
245
|
-
* @param id
|
|
246
|
-
* @param ctx
|
|
247
|
-
* @returns
|
|
248
|
-
*/
|
|
249
|
-
async upload(file) {
|
|
250
|
-
await this.parent.upload(file, this);
|
|
251
|
-
this.set(file);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Delete the binary, if you need to replace just use upload
|
|
255
|
-
*/
|
|
256
|
-
async delete() {
|
|
257
|
-
return this.parent.delete(this);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
__decorate([
|
|
261
|
-
NotEnumerable
|
|
262
|
-
], BinariesItem.prototype, "parent", void 0);
|
|
263
|
-
/**
|
|
264
|
-
* Define a collection of Binary
|
|
265
|
-
*/
|
|
266
|
-
export class BinariesImpl extends Array {
|
|
267
|
-
assign(model, attribute) {
|
|
268
|
-
this.model = model;
|
|
269
|
-
this.attribute = attribute;
|
|
270
|
-
for (let binary of model[attribute] || []) {
|
|
271
|
-
this.push(binary);
|
|
272
|
-
}
|
|
273
|
-
this.__service = Core.get().getBinaryStore(model, attribute);
|
|
274
|
-
return this;
|
|
275
|
-
}
|
|
276
|
-
// Readonly methods
|
|
277
|
-
pop() {
|
|
278
|
-
throw new Error("Readonly");
|
|
279
|
-
}
|
|
280
|
-
slice() {
|
|
281
|
-
throw new Error("Readonly");
|
|
282
|
-
}
|
|
283
|
-
unshift() {
|
|
284
|
-
throw new Error("Readonly");
|
|
285
|
-
}
|
|
286
|
-
shift() {
|
|
287
|
-
throw new Error("Readonly");
|
|
288
|
-
}
|
|
289
|
-
push(...args) {
|
|
290
|
-
return super.push(...args.map(arg => (arg instanceof BinariesItem ? arg : new BinariesItem(this, arg))));
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Upload a file to this model
|
|
294
|
-
* @param file
|
|
295
|
-
*/
|
|
296
|
-
async upload(file, replace) {
|
|
297
|
-
await this.__service.store(this.model, this.attribute, file);
|
|
298
|
-
// Should call the store first
|
|
299
|
-
super.push(new BinariesItem(this, file));
|
|
300
|
-
if (replace) {
|
|
301
|
-
await this.delete(replace);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Delete an item
|
|
306
|
-
* @param item
|
|
307
|
-
*/
|
|
308
|
-
async delete(item) {
|
|
309
|
-
let itemIndex = this.indexOf(item);
|
|
310
|
-
if (itemIndex === -1) {
|
|
311
|
-
throw new Error("Item not found");
|
|
312
|
-
}
|
|
313
|
-
await this.__service.delete(this.model, this.attribute, itemIndex);
|
|
314
|
-
itemIndex = this.indexOf(item);
|
|
315
|
-
if (itemIndex >= 0) {
|
|
316
|
-
// Call store delete here
|
|
317
|
-
this.splice(itemIndex, 1);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
__decorate([
|
|
322
|
-
NotEnumerable
|
|
323
|
-
], BinariesImpl.prototype, "__service", void 0);
|
|
324
|
-
__decorate([
|
|
325
|
-
NotEnumerable
|
|
326
|
-
], BinariesImpl.prototype, "model", void 0);
|
|
327
|
-
__decorate([
|
|
328
|
-
NotEnumerable
|
|
329
|
-
], BinariesImpl.prototype, "attribute", void 0);
|
|
330
|
-
export class BinaryParameters extends ServiceParameters {
|
|
331
|
-
constructor(params, _service) {
|
|
332
|
-
super(params);
|
|
333
|
-
if (this.expose) {
|
|
334
|
-
this.expose.restrict = this.expose.restrict || {};
|
|
335
|
-
}
|
|
336
|
-
this.map ?? (this.map = {});
|
|
337
|
-
// Store all models in it by default
|
|
338
|
-
this.models ?? (this.models = {
|
|
339
|
-
"*": ["*"]
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* This is an abstract service to represent a storage of files
|
|
345
|
-
* The binary allow you to expose this service as HTTP
|
|
346
|
-
*
|
|
347
|
-
* It supports two modes:
|
|
348
|
-
* - attached to a CoreModel (attach, detach, reattach)
|
|
349
|
-
* - pure storage with no managed id (read, write, delete)
|
|
350
|
-
*
|
|
351
|
-
* As we have deduplication builtin you can get some stats
|
|
352
|
-
* - getUsageCount(hash)
|
|
353
|
-
* - getUsageCountForRaw()
|
|
354
|
-
* - getUsageCountForMap()
|
|
355
|
-
*
|
|
356
|
-
* The Binary storage should store only once a binary and reference every object that are used by this binary, so it can be cleaned.
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* @see FileBinary
|
|
360
|
-
* @see S3Binary
|
|
361
|
-
*
|
|
362
|
-
* @exports
|
|
363
|
-
* @abstract
|
|
364
|
-
* @WebdaModda Binary
|
|
365
|
-
*/
|
|
366
|
-
export class BinaryService extends Service {
|
|
367
|
-
/**
|
|
368
|
-
* @override
|
|
369
|
-
*/
|
|
370
|
-
initMetrics() {
|
|
371
|
-
super.initMetrics();
|
|
372
|
-
this.metrics.upload = this.getMetric(Counter, {
|
|
373
|
-
name: "binary_upload",
|
|
374
|
-
help: "Number of binary upload"
|
|
375
|
-
});
|
|
376
|
-
this.metrics.delete = this.getMetric(Counter, {
|
|
377
|
-
name: "binary_delete",
|
|
378
|
-
help: "Number of binary deleted"
|
|
379
|
-
});
|
|
380
|
-
this.metrics.download = this.getMetric(Counter, {
|
|
381
|
-
name: "binary_download",
|
|
382
|
-
help: "Number of binary upload"
|
|
383
|
-
});
|
|
384
|
-
this.metrics.metadataUpdate = this.getMetric(Counter, {
|
|
385
|
-
name: "binary_metadata_update",
|
|
386
|
-
help: "Number of binary metadata updated"
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Redirect to the temporary link to S3 object
|
|
391
|
-
* or return it if returnInfo=true
|
|
392
|
-
*
|
|
393
|
-
* @param ctx of the request
|
|
394
|
-
* @param returnInfo
|
|
395
|
-
*/
|
|
396
|
-
async httpGet(context) {
|
|
397
|
-
const returnInfo = context.getHttpContext().getRelativeUri().endsWith("/url");
|
|
398
|
-
const { uuid, index, property } = context.getParameters();
|
|
399
|
-
let targetStore = this._verifyMapAndStore(context);
|
|
400
|
-
let object = await targetStore.get(uuid);
|
|
401
|
-
if (!object || (Array.isArray(object[property]) && object[property].length <= index)) {
|
|
402
|
-
throw new WebdaError.NotFound("Object does not exist or attachment does not exist");
|
|
403
|
-
}
|
|
404
|
-
await object.checkAct(context, "get_binary");
|
|
405
|
-
const file = Array.isArray(object[property]) ? object[property][index] : object[property];
|
|
406
|
-
await this.emitSync("Binary.Get", {
|
|
407
|
-
object: file,
|
|
408
|
-
service: this,
|
|
409
|
-
context: context
|
|
410
|
-
});
|
|
411
|
-
let url = await this.getRedirectUrlFromObject(file, context);
|
|
412
|
-
// No url, we return the file
|
|
413
|
-
if (url === null) {
|
|
414
|
-
if (returnInfo) {
|
|
415
|
-
// Redirect to same url without /url
|
|
416
|
-
context.write({
|
|
417
|
-
Location: context
|
|
418
|
-
.getHttpContext()
|
|
419
|
-
.getAbsoluteUrl()
|
|
420
|
-
.replace(/\/url$/, ""),
|
|
421
|
-
Map: file
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
// Output
|
|
426
|
-
context.writeHead(200, {
|
|
427
|
-
"Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
|
|
428
|
-
"Content-Length": file.size
|
|
429
|
-
});
|
|
430
|
-
let readStream = await this.get(file);
|
|
431
|
-
await new Promise((resolve, reject) => {
|
|
432
|
-
// We replaced all the event handlers with a simple call to readStream.pipe()
|
|
433
|
-
context._stream.on("finish", resolve);
|
|
434
|
-
context._stream.on("error", reject);
|
|
435
|
-
readStream.pipe(context._stream);
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
else if (returnInfo) {
|
|
440
|
-
context.write({ Location: url, Map: file });
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
context.writeHead(302, {
|
|
444
|
-
Location: url
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Get a UrlFromObject
|
|
450
|
-
*
|
|
451
|
-
*/
|
|
452
|
-
async getRedirectUrlFromObject(binaryMap, _context, _expires = 30) {
|
|
453
|
-
return null;
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Define if binary is managed by the store
|
|
457
|
-
* @param modelName
|
|
458
|
-
* @param attribute
|
|
459
|
-
* @returns -1 if not managed, 0 if managed but by default, 1 if managed and in the map, 2 if explicit with attribute and model
|
|
460
|
-
*/
|
|
461
|
-
handleBinary(modelName, attribute) {
|
|
462
|
-
let key = Object.keys(this.parameters.models).find(k => k === modelName);
|
|
463
|
-
if (key) {
|
|
464
|
-
// Explicit model
|
|
465
|
-
let attributes = this.parameters.models[key];
|
|
466
|
-
if (attributes.includes(attribute)) {
|
|
467
|
-
return 2;
|
|
468
|
-
}
|
|
469
|
-
else if (attributes.includes("*")) {
|
|
470
|
-
return 1;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
// Default to all model - 593-594,598-599
|
|
474
|
-
key = Object.keys(this.parameters.models).find(k => k === "*");
|
|
475
|
-
if (!key) {
|
|
476
|
-
return -1;
|
|
477
|
-
}
|
|
478
|
-
let attributes = this.parameters.models[key];
|
|
479
|
-
if (attributes.includes(attribute)) {
|
|
480
|
-
return 1;
|
|
481
|
-
}
|
|
482
|
-
if (attributes.includes("*")) {
|
|
483
|
-
return 0;
|
|
484
|
-
}
|
|
485
|
-
return -1;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Get a binary
|
|
489
|
-
*
|
|
490
|
-
* @param {Object} info The reference stored in your target object
|
|
491
|
-
* @emits 'binaryGet'
|
|
492
|
-
*/
|
|
493
|
-
async get(info) {
|
|
494
|
-
await this.emitSync("Binary.Get", {
|
|
495
|
-
object: info,
|
|
496
|
-
service: this
|
|
497
|
-
});
|
|
498
|
-
this.metrics.download.inc();
|
|
499
|
-
return this._get(info);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Download a binary to a file
|
|
503
|
-
*
|
|
504
|
-
* @param {Object} info The reference stored in your target object
|
|
505
|
-
* @param {String} filepath to save the binary to
|
|
506
|
-
*/
|
|
507
|
-
async downloadTo(info, filename) {
|
|
508
|
-
await this.emitSync("Binary.Get", {
|
|
509
|
-
object: info,
|
|
510
|
-
service: this
|
|
511
|
-
});
|
|
512
|
-
this.metrics.download.inc();
|
|
513
|
-
let readStream = await this._get(info);
|
|
514
|
-
let writeStream = fs.createWriteStream(filename);
|
|
515
|
-
return new Promise((resolve, reject) => {
|
|
516
|
-
writeStream.on("finish", _src => {
|
|
517
|
-
return resolve();
|
|
518
|
-
});
|
|
519
|
-
writeStream.on("error", src => {
|
|
520
|
-
try {
|
|
521
|
-
fs.unlinkSync(filename);
|
|
522
|
-
// Stubing the fs module in ESM seems complicated for now
|
|
523
|
-
/* c8 ignore next 3 */
|
|
524
|
-
}
|
|
525
|
-
catch (err) {
|
|
526
|
-
this._webda.log("ERROR", err);
|
|
527
|
-
}
|
|
528
|
-
return reject(src);
|
|
529
|
-
});
|
|
530
|
-
readStream.pipe(writeStream);
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* @override
|
|
535
|
-
*/
|
|
536
|
-
resolve() {
|
|
537
|
-
super.resolve();
|
|
538
|
-
this.initMap(this.parameters.map);
|
|
539
|
-
return this;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* Init the declared maps, adding reverse maps
|
|
543
|
-
*
|
|
544
|
-
* @param map
|
|
545
|
-
*/
|
|
546
|
-
initMap(map) {
|
|
547
|
-
if (map == undefined || map._init) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
this._lowercaseMaps = {};
|
|
551
|
-
Object.keys(map).forEach(prop => {
|
|
552
|
-
this._lowercaseMaps[prop.toLowerCase()] = prop;
|
|
553
|
-
let reverseStore = this._webda.getService(prop);
|
|
554
|
-
if (reverseStore === undefined || !(reverseStore instanceof Store)) {
|
|
555
|
-
this._webda.log("WARN", "Can't setup mapping as store ", prop, " doesn't exist");
|
|
556
|
-
map[prop]["-onerror"] = "NoStore";
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
for (let i in map[prop]) {
|
|
560
|
-
reverseStore.addReverseMap(map[prop][i], this);
|
|
561
|
-
}
|
|
562
|
-
// Cascade delete
|
|
563
|
-
reverseStore.on("Store.Deleted", async (evt) => {
|
|
564
|
-
let infos = [];
|
|
565
|
-
if (evt.object[map[prop]]) {
|
|
566
|
-
infos.push(...evt.object[map[prop]]);
|
|
567
|
-
}
|
|
568
|
-
await Promise.all(infos.map(info => this.cascadeDelete(info, evt.object.getUuid())));
|
|
569
|
-
});
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
/**
|
|
573
|
-
* Based on the raw Map init a BinaryMap
|
|
574
|
-
* @param obj
|
|
575
|
-
* @returns
|
|
576
|
-
*/
|
|
577
|
-
newModel(obj) {
|
|
578
|
-
return new BinaryMap(this, obj);
|
|
579
|
-
}
|
|
580
|
-
/**
|
|
581
|
-
* Read a stream to a buffer
|
|
582
|
-
*
|
|
583
|
-
* @param stream
|
|
584
|
-
* @returns
|
|
585
|
-
*/
|
|
586
|
-
static streamToBuffer(stream) {
|
|
587
|
-
// codesnippet from https://stackoverflow.com/questions/14269233/node-js-how-to-read-a-stream-into-a-buffer
|
|
588
|
-
const chunks = [];
|
|
589
|
-
return new Promise((resolve, reject) => {
|
|
590
|
-
stream.on("data", chunk => chunks.push(Buffer.from(chunk)));
|
|
591
|
-
stream.on("error", err => reject(err));
|
|
592
|
-
stream.on("end", () => resolve(Buffer.concat(chunks)));
|
|
593
|
-
});
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Check if a map is defined
|
|
597
|
-
*
|
|
598
|
-
* @param name
|
|
599
|
-
* @param property
|
|
600
|
-
*/
|
|
601
|
-
checkMap(object, property) {
|
|
602
|
-
if (this.handleBinary(object.__type, property) !== -1) {
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
// DELETE_IN_4.0.0
|
|
606
|
-
const name = object.getStore().getName();
|
|
607
|
-
let map = this.parameters.map[this._lowercaseMaps[name.toLowerCase()]];
|
|
608
|
-
if (map === undefined) {
|
|
609
|
-
throw new Error("Unknown mapping");
|
|
610
|
-
}
|
|
611
|
-
if (Array.isArray(map) && map.indexOf(property) === -1) {
|
|
612
|
-
throw new Error("Unknown mapping");
|
|
613
|
-
}
|
|
614
|
-
/*
|
|
615
|
-
// END_DELETE_IN_4.0.0
|
|
616
|
-
throw new Error("Unknown mapping");
|
|
617
|
-
// DELETE_IN_4.0.0
|
|
618
|
-
*/
|
|
619
|
-
// END_DELETE_IN_4.0.0
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Ensure events are sent correctly after an upload and update the BinaryFileInfo in targetted object
|
|
623
|
-
*/
|
|
624
|
-
async uploadSuccess(object, property, file) {
|
|
625
|
-
let object_uid = object.getUuid();
|
|
626
|
-
// Check if the file is already in the array then skip
|
|
627
|
-
if (Array.isArray(object[property]) && object[property].find(i => i.hash === file.hash)) {
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
await this.emitSync("Binary.UploadSuccess", {
|
|
631
|
-
object: file,
|
|
632
|
-
service: this,
|
|
633
|
-
target: object
|
|
634
|
-
});
|
|
635
|
-
const relations = this.getWebda().getApplication().getRelations(object);
|
|
636
|
-
const cardinality = (relations.binaries || []).find(p => p.attribute === property)?.cardinality || "MANY";
|
|
637
|
-
if (cardinality === "MANY") {
|
|
638
|
-
await object.getStore().upsertItemToCollection(object_uid, property, file);
|
|
639
|
-
}
|
|
640
|
-
else {
|
|
641
|
-
await object.getStore().setAttribute(object_uid, property, file);
|
|
642
|
-
}
|
|
643
|
-
await this.emitSync("Binary.Create", {
|
|
644
|
-
object: file,
|
|
645
|
-
service: this,
|
|
646
|
-
target: object
|
|
647
|
-
});
|
|
648
|
-
this.metrics.upload.inc();
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
*
|
|
652
|
-
* @param targetStore
|
|
653
|
-
* @param object
|
|
654
|
-
* @param property
|
|
655
|
-
* @param index
|
|
656
|
-
* @returns
|
|
657
|
-
*/
|
|
658
|
-
async deleteSuccess(object, property, index) {
|
|
659
|
-
let info = (index !== undefined ? object[property][index] : object[property]);
|
|
660
|
-
const relations = this.getWebda().getApplication().getRelations(object);
|
|
661
|
-
const cardinality = (relations.binaries || []).find(p => p.attribute === property)?.cardinality || "MANY";
|
|
662
|
-
let update;
|
|
663
|
-
if (cardinality === "MANY") {
|
|
664
|
-
update = object.getStore().deleteItemFromCollection(object.getUuid(), property, index, info.hash, "hash");
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
object.getStore().removeAttribute(object.getUuid(), property);
|
|
668
|
-
}
|
|
669
|
-
await this.emitSync("Binary.Delete", {
|
|
670
|
-
object: info,
|
|
671
|
-
service: this
|
|
672
|
-
});
|
|
673
|
-
this.metrics.delete.inc();
|
|
674
|
-
return update;
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* Get file either from multipart post or raw
|
|
678
|
-
* @param req
|
|
679
|
-
* @returns
|
|
680
|
-
*/
|
|
681
|
-
async _getFile(req) {
|
|
682
|
-
let file = await req.getHttpContext().getRawBody(10 * 1024 * 1024);
|
|
683
|
-
// TODO Check if we have other type
|
|
684
|
-
return new MemoryBinaryFile(Buffer.from(file), {
|
|
685
|
-
mimetype: req.getHttpContext().getUniqueHeader("Content-Type", "application/octet-stream"),
|
|
686
|
-
size: parseInt(req.getHttpContext().getUniqueHeader("Content-Length")) || file.length,
|
|
687
|
-
name: req.getHttpContext().getUniqueHeader("X-Filename", "")
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* @override
|
|
692
|
-
*/
|
|
693
|
-
initRoutes() {
|
|
694
|
-
if (!this.parameters.expose) {
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
this._initRoutes();
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* Init the Binary system routes
|
|
701
|
-
*
|
|
702
|
-
* Making sure parameters.expose exists prior
|
|
703
|
-
*/
|
|
704
|
-
_initRoutes() {
|
|
705
|
-
let url;
|
|
706
|
-
let name = this.getOperationName();
|
|
707
|
-
if (!this.parameters.expose.restrict.get) {
|
|
708
|
-
url = this.parameters.expose.url + "/{store}/{uuid}/{property}/{index}";
|
|
709
|
-
this.addRoute(url, ["GET"], this.httpGet, {
|
|
710
|
-
get: {
|
|
711
|
-
operationId: `get${name}Binary`,
|
|
712
|
-
description: "Download a binary linked to an object",
|
|
713
|
-
summary: "Download a binary",
|
|
714
|
-
responses: {
|
|
715
|
-
"200": {
|
|
716
|
-
description: "Binary stream"
|
|
717
|
-
},
|
|
718
|
-
"403": {
|
|
719
|
-
description: "You don't have permissions"
|
|
720
|
-
},
|
|
721
|
-
"404": {
|
|
722
|
-
description: "Object does not exist or attachment does not exist"
|
|
723
|
-
},
|
|
724
|
-
"412": {
|
|
725
|
-
description: "Provided hash does not match"
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
this.addRoute(url + "/url", ["GET"], this.httpGet, {
|
|
731
|
-
get: {
|
|
732
|
-
operationId: `get${name}BinaryInfo`,
|
|
733
|
-
description: "Return the url and information of a binary linked to an object",
|
|
734
|
-
summary: "GetInfo of a binary",
|
|
735
|
-
responses: {
|
|
736
|
-
"200": {
|
|
737
|
-
description: "Url and BinaryMap"
|
|
738
|
-
},
|
|
739
|
-
"403": {
|
|
740
|
-
description: "You don't have permissions"
|
|
741
|
-
},
|
|
742
|
-
"404": {
|
|
743
|
-
description: "Object does not exist or attachment does not exist"
|
|
744
|
-
},
|
|
745
|
-
"412": {
|
|
746
|
-
description: "Provided hash does not match"
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
if (!this.parameters.expose.restrict.create) {
|
|
753
|
-
// No need the index to add file
|
|
754
|
-
url = this.parameters.expose.url + "/{store}/{uuid}/{property}";
|
|
755
|
-
this.addRoute(url, ["POST"], this.httpRoute, {
|
|
756
|
-
post: {
|
|
757
|
-
operationId: `add${name}Binary`,
|
|
758
|
-
description: "Add a binary linked to an object",
|
|
759
|
-
summary: "Add a binary",
|
|
760
|
-
responses: {
|
|
761
|
-
"200": {
|
|
762
|
-
description: ""
|
|
763
|
-
},
|
|
764
|
-
"403": {
|
|
765
|
-
description: "You don't have permissions"
|
|
766
|
-
},
|
|
767
|
-
"404": {
|
|
768
|
-
description: "Object does not exist or attachment does not exist"
|
|
769
|
-
},
|
|
770
|
-
"412": {
|
|
771
|
-
description: "Provided hash does not match"
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
if (!this.parameters.expose.restrict.create) {
|
|
778
|
-
// Add file with challenge
|
|
779
|
-
url = this.parameters.expose.url + "/upload/{store}/{uuid}/{property}";
|
|
780
|
-
this.addRoute(url, ["PUT"], this.httpChallenge, {
|
|
781
|
-
put: {
|
|
782
|
-
operationId: `put${name}Binary`,
|
|
783
|
-
description: "Add a binary to an object after challenge",
|
|
784
|
-
summary: "Add a binary",
|
|
785
|
-
responses: {
|
|
786
|
-
"204": {
|
|
787
|
-
description: ""
|
|
788
|
-
},
|
|
789
|
-
"403": {
|
|
790
|
-
description: "You don't have permissions"
|
|
791
|
-
},
|
|
792
|
-
"404": {
|
|
793
|
-
description: "Object does not exist or attachment does not exist"
|
|
794
|
-
},
|
|
795
|
-
"412": {
|
|
796
|
-
description: "Provided hash does not match"
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
if (!this.parameters.expose.restrict.delete) {
|
|
803
|
-
// Need hash to avoid concurrent delete
|
|
804
|
-
url = this.parameters.expose.url + "/{store}/{uuid}/{property}/{index}/{hash}";
|
|
805
|
-
this.addRoute(url, ["DELETE"], this.httpRoute, {
|
|
806
|
-
delete: {
|
|
807
|
-
operationId: `delete${name}Binary`,
|
|
808
|
-
description: "Delete a binary linked to an object",
|
|
809
|
-
summary: "Delete a binary",
|
|
810
|
-
responses: {
|
|
811
|
-
"204": {
|
|
812
|
-
description: ""
|
|
813
|
-
},
|
|
814
|
-
"403": {
|
|
815
|
-
description: "You don't have permissions"
|
|
816
|
-
},
|
|
817
|
-
"404": {
|
|
818
|
-
description: "Object does not exist or attachment does not exist"
|
|
819
|
-
},
|
|
820
|
-
"412": {
|
|
821
|
-
description: "Provided hash does not match"
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
if (!this.parameters.expose.restrict.metadata) {
|
|
828
|
-
// Need hash to avoid concurrent delete
|
|
829
|
-
url = this.parameters.expose.url + "/{store}/{uuid}/{property}/{index}/{hash}";
|
|
830
|
-
this.addRoute(url, ["PUT"], this.httpRoute, {
|
|
831
|
-
put: {
|
|
832
|
-
operationId: `update${name}BinaryMetadata`,
|
|
833
|
-
description: "Update a binary metadata linked to an object",
|
|
834
|
-
summary: "Update a binary metadata",
|
|
835
|
-
responses: {
|
|
836
|
-
"204": {
|
|
837
|
-
description: ""
|
|
838
|
-
},
|
|
839
|
-
"403": {
|
|
840
|
-
description: "You don't have permissions"
|
|
841
|
-
},
|
|
842
|
-
"404": {
|
|
843
|
-
description: "Object does not exist or attachment does not exist"
|
|
844
|
-
},
|
|
845
|
-
"412": {
|
|
846
|
-
description: "Provided hash does not match"
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Return the name of the service for OpenAPI
|
|
855
|
-
* @returns
|
|
856
|
-
*/
|
|
857
|
-
getOperationName() {
|
|
858
|
-
return this._name.toLowerCase() === "binary" ? "" : this._name;
|
|
859
|
-
}
|
|
860
|
-
/**
|
|
861
|
-
* Based on the request parameter verify it match a known mapping
|
|
862
|
-
* @param ctx
|
|
863
|
-
* @returns
|
|
864
|
-
*/
|
|
865
|
-
_verifyMapAndStore(ctx) {
|
|
866
|
-
// Check for model
|
|
867
|
-
if (ctx.parameter("model")) {
|
|
868
|
-
if (this.handleBinary(ctx.parameter("model"), ctx.parameter("property")) === -1) {
|
|
869
|
-
throw new WebdaError.NotFound("Model not managed by this store");
|
|
870
|
-
}
|
|
871
|
-
return this.getWebda().getModelStore(this.getWebda().getModel(ctx.parameter("model")));
|
|
872
|
-
}
|
|
873
|
-
let store = ctx.parameter("store").toLowerCase();
|
|
874
|
-
// To avoid any problem lowercase everything
|
|
875
|
-
let map = this.parameters.map[this._lowercaseMaps[store]];
|
|
876
|
-
if (map === undefined) {
|
|
877
|
-
throw new WebdaError.NotFound("Unknown map");
|
|
878
|
-
}
|
|
879
|
-
if (!map.includes(ctx.parameter("property"))) {
|
|
880
|
-
throw new WebdaError.NotFound("Unknown property");
|
|
881
|
-
}
|
|
882
|
-
let targetStore = this.getService(this._lowercaseMaps[store]);
|
|
883
|
-
if (targetStore === undefined) {
|
|
884
|
-
throw new WebdaError.NotFound("Unknown store");
|
|
885
|
-
}
|
|
886
|
-
return targetStore;
|
|
887
|
-
}
|
|
888
|
-
/**
|
|
889
|
-
* By default no challenge is managed so throws 404
|
|
890
|
-
*
|
|
891
|
-
* @param ctx
|
|
892
|
-
*/
|
|
893
|
-
async putRedirectUrl(_ctx) {
|
|
894
|
-
// Dont handle the redirect url
|
|
895
|
-
throw new WebdaError.NotFound("No redirect url");
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Mechanism to add a data based on challenge
|
|
899
|
-
*/
|
|
900
|
-
async httpChallenge(ctx) {
|
|
901
|
-
let body = await ctx.getRequestBody();
|
|
902
|
-
if (!body.hash || !body.challenge) {
|
|
903
|
-
throw new WebdaError.BadRequest("Missing hash or challenge");
|
|
904
|
-
}
|
|
905
|
-
// First verify if map exist
|
|
906
|
-
let targetStore = this._verifyMapAndStore(ctx);
|
|
907
|
-
// Get the object
|
|
908
|
-
let object = await targetStore.get(ctx.parameter("uuid"), ctx);
|
|
909
|
-
if (object === undefined) {
|
|
910
|
-
throw new WebdaError.NotFound("Object does not exist");
|
|
911
|
-
}
|
|
912
|
-
await object.checkAct(ctx, "attach_binary");
|
|
913
|
-
let url = await this.putRedirectUrl(ctx);
|
|
914
|
-
let base64String = Buffer.from(body.hash, "hex").toString("base64");
|
|
915
|
-
ctx.write({
|
|
916
|
-
...url,
|
|
917
|
-
done: url === undefined,
|
|
918
|
-
md5: base64String
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Manage the different routes
|
|
923
|
-
* @param ctx
|
|
924
|
-
*/
|
|
925
|
-
async httpRoute(ctx) {
|
|
926
|
-
// First verify if map exist
|
|
927
|
-
let targetStore = this._verifyMapAndStore(ctx);
|
|
928
|
-
// Get the object
|
|
929
|
-
let object = await targetStore.get(ctx.parameter("uuid"), ctx);
|
|
930
|
-
if (object === undefined) {
|
|
931
|
-
throw new WebdaError.NotFound("Object does not exist");
|
|
932
|
-
}
|
|
933
|
-
const { property, index } = ctx.getParameters();
|
|
934
|
-
// Current file - would be empty on creation
|
|
935
|
-
const file = Array.isArray(object[property]) ? object[property][index] : object[property];
|
|
936
|
-
// Check permissions
|
|
937
|
-
let action = "unknown";
|
|
938
|
-
if (ctx.getHttpContext().getMethod() === "DELETE") {
|
|
939
|
-
action = "detach_binary";
|
|
940
|
-
}
|
|
941
|
-
else if (ctx.getHttpContext().getMethod() === "POST") {
|
|
942
|
-
action = "attach_binary";
|
|
943
|
-
}
|
|
944
|
-
else if (ctx.getHttpContext().getMethod() === "PUT") {
|
|
945
|
-
action = "update_binary_metadata";
|
|
946
|
-
}
|
|
947
|
-
await object.checkAct(ctx, action);
|
|
948
|
-
// Now do the action
|
|
949
|
-
if (ctx.getHttpContext().getMethod() === "POST") {
|
|
950
|
-
await this.store(object, property, await this._getFile(ctx));
|
|
951
|
-
}
|
|
952
|
-
else {
|
|
953
|
-
if (file.hash !== ctx.parameter("hash")) {
|
|
954
|
-
throw new WebdaError.BadRequest("Hash does not match");
|
|
955
|
-
}
|
|
956
|
-
if (ctx.getHttpContext().getMethod() === "DELETE") {
|
|
957
|
-
await this.delete(object, property, index);
|
|
958
|
-
}
|
|
959
|
-
else if (ctx.getHttpContext().getMethod() === "PUT") {
|
|
960
|
-
let metadata = await ctx.getRequestBody();
|
|
961
|
-
// Limit metadata to 4kb
|
|
962
|
-
if (JSON.stringify(metadata).length >= 4096) {
|
|
963
|
-
throw new WebdaError.BadRequest("Metadata is too big: 4kb max");
|
|
964
|
-
}
|
|
965
|
-
let evt = {
|
|
966
|
-
service: this,
|
|
967
|
-
object: file,
|
|
968
|
-
target: object
|
|
969
|
-
};
|
|
970
|
-
await this.emitSync("Binary.MetadataUpdate", {
|
|
971
|
-
...evt,
|
|
972
|
-
metadata
|
|
973
|
-
});
|
|
974
|
-
file.metadata = metadata;
|
|
975
|
-
// Update mapper on purpose
|
|
976
|
-
await object.getStore().patch({
|
|
977
|
-
[object.__class.getUuidField()]: object.getUuid(),
|
|
978
|
-
[property]: object[property]
|
|
979
|
-
}, false);
|
|
980
|
-
this.metrics.metadataUpdate.inc();
|
|
981
|
-
await this.emitSync("Binary.MetadataUpdated", evt);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
//# sourceMappingURL=binary.js.map
|