@webda/core 4.0.0-beta.2 → 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/{unpackedapplication.d.ts → application/unpackedapplication.d.ts} +43 -23
- 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 -58
- 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 +44 -19
- package/lib/contexts/httpcontext.d.ts.map +1 -0
- package/lib/{utils → contexts}/httpcontext.js +95 -27
- 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 +82 -53
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +81 -62
- 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 +20 -76
- package/lib/models/aclmodel.d.ts.map +1 -1
- package/lib/models/aclmodel.js +27 -203
- 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 +1 -1
- package/lib/models/deployment.d.ts.map +1 -1
- 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.js → rolemodel.model.js} +23 -5
- 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.d.ts → memoryqueue.service.d.ts} +26 -13
- package/lib/queues/memoryqueue.service.d.ts.map +1 -0
- package/lib/queues/{memoryqueue.js → memoryqueue.service.js} +55 -31
- package/lib/queues/memoryqueue.service.js.map +1 -0
- package/lib/queues/pubsubservice.d.ts +8 -6
- package/lib/queues/pubsubservice.d.ts.map +1 -1
- package/lib/queues/pubsubservice.js +5 -4
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queueservice.d.ts +9 -11
- package/lib/queues/queueservice.d.ts.map +1 -1
- package/lib/queues/queueservice.js +41 -13
- 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 -59
- 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 +17 -12
- package/lib/services/cloudbinary.d.ts.map +1 -1
- package/lib/services/cloudbinary.js +23 -17
- 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} +75 -141
- 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.js → debugmailer.service.js} +25 -10
- 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 -11
- 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 +52 -28
- package/lib/services/oauth.d.ts.map +1 -1
- package/lib/services/oauth.js +365 -254
- 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 -12
- 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.d.ts → resource.service.d.ts} +34 -15
- 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 +87 -188
- package/lib/services/service.d.ts.map +1 -1
- package/lib/services/service.js +407 -422
- 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 -19
- 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 +126 -626
- package/lib/stores/store.d.ts.map +1 -1
- package/lib/stores/store.js +257 -1117
- 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 +4 -2
- package/lib/utils/abstractdeployer.d.ts.map +1 -1
- package/lib/utils/abstractdeployer.js +3 -0
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/package.json +85 -60
- package/test/cachedapp/webda.config.json +1 -5
- package/test/config-cached.json +1 -5
- package/test/config.json +0 -9
- package/test/my-cnf.json +9 -0
- package/webda.module.json +3463 -2482
- package/lib/application.d.ts +0 -888
- package/lib/application.d.ts.map +0 -1
- package/lib/application.js +0 -768
- package/lib/application.js.map +0 -1
- package/lib/application.spec.d.ts +0 -2
- package/lib/application.spec.d.ts.map +0 -1
- package/lib/application.spec.js +0 -248
- package/lib/application.spec.js.map +0 -1
- package/lib/core.d.ts +0 -743
- package/lib/core.d.ts.map +0 -1
- package/lib/core.js +0 -1334
- package/lib/core.js.map +0 -1
- package/lib/core.spec.d.ts +0 -2
- package/lib/core.spec.d.ts.map +0 -1
- package/lib/core.spec.js +0 -790
- package/lib/core.spec.js.map +0 -1
- package/lib/errors.d.ts +0 -64
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js +0 -97
- package/lib/errors.js.map +0 -1
- package/lib/errors.spec.d.ts +0 -2
- package/lib/errors.spec.d.ts.map +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 -2
- package/lib/models/aclmodel.spec.d.ts.map +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 -896
- package/lib/models/coremodel.d.ts.map +0 -1
- package/lib/models/coremodel.js +0 -1214
- package/lib/models/coremodel.js.map +0 -1
- package/lib/models/coremodel.spec.d.ts +0 -2
- package/lib/models/coremodel.spec.d.ts.map +0 -1
- package/lib/models/coremodel.spec.js +0 -464
- package/lib/models/coremodel.spec.js.map +0 -1
- package/lib/models/ident.d.ts +0 -68
- package/lib/models/ident.d.ts.map +0 -1
- package/lib/models/ident.js +0 -26
- package/lib/models/ident.js.map +0 -1
- package/lib/models/ident.spec.d.ts +0 -2
- package/lib/models/ident.spec.d.ts.map +0 -1
- package/lib/models/ident.spec.js +0 -24
- package/lib/models/ident.spec.js.map +0 -1
- package/lib/models/ownermodel.d.ts +0 -51
- package/lib/models/ownermodel.d.ts.map +0 -1
- package/lib/models/ownermodel.js +0 -65
- package/lib/models/ownermodel.js.map +0 -1
- package/lib/models/ownermodel.spec.d.ts +0 -2
- package/lib/models/ownermodel.spec.d.ts.map +0 -1
- package/lib/models/ownermodel.spec.js +0 -215
- package/lib/models/ownermodel.spec.js.map +0 -1
- package/lib/models/relations.d.ts +0 -182
- package/lib/models/relations.d.ts.map +0 -1
- package/lib/models/relations.js +0 -157
- package/lib/models/relations.js.map +0 -1
- package/lib/models/relations.spec.d.ts +0 -14
- package/lib/models/relations.spec.d.ts.map +0 -1
- package/lib/models/relations.spec.js +0 -217
- package/lib/models/relations.spec.js.map +0 -1
- package/lib/models/rolemodel.d.ts +0 -11
- package/lib/models/rolemodel.d.ts.map +0 -1
- package/lib/models/rolemodel.js.map +0 -1
- package/lib/models/rolemodel.spec.d.ts +0 -2
- package/lib/models/rolemodel.spec.d.ts.map +0 -1
- package/lib/models/rolemodel.spec.js +0 -90
- package/lib/models/rolemodel.spec.js.map +0 -1
- package/lib/models/simpleuser.d.ts +0 -47
- package/lib/models/simpleuser.d.ts.map +0 -1
- package/lib/models/simpleuser.js +0 -84
- package/lib/models/simpleuser.js.map +0 -1
- package/lib/models/test.d.ts +0 -11
- package/lib/models/test.d.ts.map +0 -1
- package/lib/models/test.js +0 -7
- package/lib/models/test.js.map +0 -1
- package/lib/models/user.d.ts +0 -67
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js +0 -86
- package/lib/models/user.js.map +0 -1
- package/lib/models/user.spec.d.ts +0 -2
- package/lib/models/user.spec.d.ts.map +0 -1
- package/lib/models/user.spec.js +0 -89
- package/lib/models/user.spec.js.map +0 -1
- package/lib/queues/filequeue.d.ts +0 -59
- package/lib/queues/filequeue.d.ts.map +0 -1
- package/lib/queues/filequeue.js +0 -131
- package/lib/queues/filequeue.js.map +0 -1
- package/lib/queues/filequeue.spec.d.ts +0 -2
- package/lib/queues/filequeue.spec.d.ts.map +0 -1
- package/lib/queues/filequeue.spec.js +0 -84
- package/lib/queues/filequeue.spec.js.map +0 -1
- package/lib/queues/memoryqueue.d.ts.map +0 -1
- package/lib/queues/memoryqueue.js.map +0 -1
- package/lib/queues/memoryqueue.spec.d.ts +0 -2
- package/lib/queues/memoryqueue.spec.d.ts.map +0 -1
- package/lib/queues/memoryqueue.spec.js +0 -203
- package/lib/queues/memoryqueue.spec.js.map +0 -1
- package/lib/queues/queue.spec.d.ts +0 -6
- package/lib/queues/queue.spec.d.ts.map +0 -1
- package/lib/queues/queue.spec.js +0 -55
- package/lib/queues/queue.spec.js.map +0 -1
- package/lib/rest/restdomainservice.d.ts +0 -63
- package/lib/rest/restdomainservice.d.ts.map +0 -1
- package/lib/rest/restdomainservice.js +0 -687
- package/lib/rest/restdomainservice.js.map +0 -1
- package/lib/rest/restdomainservice.spec.d.ts +0 -2
- package/lib/rest/restdomainservice.spec.d.ts.map +0 -1
- package/lib/rest/restdomainservice.spec.js +0 -124
- package/lib/rest/restdomainservice.spec.js.map +0 -1
- package/lib/rest/router.d.ts +0 -174
- package/lib/rest/router.d.ts.map +0 -1
- package/lib/rest/router.js +0 -429
- package/lib/rest/router.js.map +0 -1
- package/lib/rest/router.spec.d.ts +0 -2
- package/lib/rest/router.spec.d.ts.map +0 -1
- package/lib/rest/router.spec.js +0 -255
- package/lib/rest/router.spec.js.map +0 -1
- package/lib/services/asyncevents.d.ts +0 -152
- package/lib/services/asyncevents.d.ts.map +0 -1
- package/lib/services/asyncevents.js +0 -217
- package/lib/services/asyncevents.js.map +0 -1
- package/lib/services/asyncevents.spec.d.ts +0 -2
- package/lib/services/asyncevents.spec.d.ts.map +0 -1
- package/lib/services/asyncevents.spec.js +0 -118
- package/lib/services/asyncevents.spec.js.map +0 -1
- package/lib/services/authentication.d.ts.map +0 -1
- package/lib/services/authentication.js +0 -773
- package/lib/services/authentication.js.map +0 -1
- package/lib/services/authentication.spec.d.ts +0 -2
- package/lib/services/authentication.spec.d.ts.map +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 -477
- package/lib/services/binary.d.ts.map +0 -1
- package/lib/services/binary.js +0 -617
- package/lib/services/binary.js.map +0 -1
- package/lib/services/binary.spec.d.ts +0 -41
- package/lib/services/binary.spec.d.ts.map +0 -1
- package/lib/services/binary.spec.js +0 -151
- package/lib/services/binary.spec.js.map +0 -1
- package/lib/services/cloudbinary.spec.d.ts +0 -6
- package/lib/services/cloudbinary.spec.d.ts.map +0 -1
- package/lib/services/cloudbinary.spec.js +0 -66
- package/lib/services/cloudbinary.spec.js.map +0 -1
- package/lib/services/configuration.d.ts.map +0 -1
- package/lib/services/configuration.js +0 -193
- package/lib/services/configuration.js.map +0 -1
- package/lib/services/configuration.spec.d.ts +0 -2
- package/lib/services/configuration.spec.d.ts.map +0 -1
- package/lib/services/configuration.spec.js +0 -130
- package/lib/services/configuration.spec.js.map +0 -1
- package/lib/services/cron.d.ts +0 -74
- package/lib/services/cron.d.ts.map +0 -1
- package/lib/services/cron.js +0 -141
- package/lib/services/cron.js.map +0 -1
- package/lib/services/cron.spec.d.ts +0 -2
- package/lib/services/cron.spec.d.ts.map +0 -1
- package/lib/services/cron.spec.js +0 -76
- package/lib/services/cron.spec.js.map +0 -1
- package/lib/services/cryptoservice.d.ts.map +0 -1
- package/lib/services/cryptoservice.js +0 -433
- package/lib/services/cryptoservice.js.map +0 -1
- package/lib/services/cryptoservice.spec.d.ts +0 -2
- package/lib/services/cryptoservice.spec.d.ts.map +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.d.ts.map +0 -1
- package/lib/services/debugmailer.js.map +0 -1
- package/lib/services/debugmailer.spec.d.ts +0 -2
- package/lib/services/debugmailer.spec.d.ts.map +0 -1
- package/lib/services/debugmailer.spec.js +0 -32
- package/lib/services/debugmailer.spec.js.map +0 -1
- package/lib/services/domainservice.d.ts +0 -272
- package/lib/services/domainservice.d.ts.map +0 -1
- package/lib/services/domainservice.js +0 -651
- package/lib/services/domainservice.js.map +0 -1
- package/lib/services/domainservice.spec.d.ts +0 -2
- package/lib/services/domainservice.spec.d.ts.map +0 -1
- package/lib/services/domainservice.spec.js +0 -592
- package/lib/services/domainservice.spec.js.map +0 -1
- package/lib/services/filebinary.d.ts +0 -136
- package/lib/services/filebinary.d.ts.map +0 -1
- package/lib/services/filebinary.js +0 -373
- package/lib/services/filebinary.js.map +0 -1
- package/lib/services/filebinary.spec.d.ts +0 -25
- package/lib/services/filebinary.spec.d.ts.map +0 -1
- package/lib/services/filebinary.spec.js +0 -428
- package/lib/services/filebinary.spec.js.map +0 -1
- package/lib/services/fileconfiguration.d.ts +0 -23
- package/lib/services/fileconfiguration.d.ts.map +0 -1
- package/lib/services/fileconfiguration.js +0 -48
- package/lib/services/fileconfiguration.js.map +0 -1
- package/lib/services/fileconfiguration.spec.d.ts +0 -2
- package/lib/services/fileconfiguration.spec.d.ts.map +0 -1
- package/lib/services/fileconfiguration.spec.js +0 -215
- package/lib/services/fileconfiguration.spec.js.map +0 -1
- package/lib/services/invitationservice.d.ts +0 -223
- package/lib/services/invitationservice.d.ts.map +0 -1
- package/lib/services/invitationservice.js +0 -529
- package/lib/services/invitationservice.js.map +0 -1
- package/lib/services/invitationservice.spec.d.ts +0 -2
- package/lib/services/invitationservice.spec.d.ts.map +0 -1
- package/lib/services/invitationservice.spec.js +0 -567
- package/lib/services/invitationservice.spec.js.map +0 -1
- package/lib/services/kubernetesconfiguration.d.ts +0 -27
- package/lib/services/kubernetesconfiguration.d.ts.map +0 -1
- package/lib/services/kubernetesconfiguration.js +0 -52
- package/lib/services/kubernetesconfiguration.js.map +0 -1
- package/lib/services/kubernetesconfiguration.spec.d.ts +0 -2
- package/lib/services/kubernetesconfiguration.spec.d.ts.map +0 -1
- package/lib/services/kubernetesconfiguration.spec.js +0 -206
- package/lib/services/kubernetesconfiguration.spec.js.map +0 -1
- package/lib/services/mailer.d.ts +0 -166
- package/lib/services/mailer.d.ts.map +0 -1
- package/lib/services/mailer.js +0 -176
- package/lib/services/mailer.js.map +0 -1
- package/lib/services/mailer.spec.d.ts +0 -2
- package/lib/services/mailer.spec.d.ts.map +0 -1
- package/lib/services/mailer.spec.js +0 -158
- package/lib/services/mailer.spec.js.map +0 -1
- package/lib/services/notificationservice.d.ts.map +0 -1
- package/lib/services/notificationservice.js.map +0 -1
- package/lib/services/notificationservice.spec.d.ts +0 -2
- package/lib/services/notificationservice.spec.d.ts.map +0 -1
- package/lib/services/notificationservice.spec.js +0 -83
- package/lib/services/notificationservice.spec.js.map +0 -1
- package/lib/services/oauth.spec.d.ts +0 -2
- package/lib/services/oauth.spec.d.ts.map +0 -1
- package/lib/services/oauth.spec.js +0 -208
- package/lib/services/oauth.spec.js.map +0 -1
- package/lib/services/prometheus.d.ts.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 -2
- package/lib/services/prometheus.spec.d.ts.map +0 -1
- package/lib/services/prometheus.spec.js +0 -76
- package/lib/services/prometheus.spec.js.map +0 -1
- package/lib/services/resource.d.ts.map +0 -1
- package/lib/services/resource.js +0 -170
- package/lib/services/resource.js.map +0 -1
- package/lib/services/resource.spec.d.ts +0 -2
- package/lib/services/resource.spec.d.ts.map +0 -1
- package/lib/services/resource.spec.js +0 -140
- package/lib/services/resource.spec.js.map +0 -1
- package/lib/services/service.spec.d.ts +0 -2
- package/lib/services/service.spec.d.ts.map +0 -1
- package/lib/services/service.spec.js +0 -286
- package/lib/services/service.spec.js.map +0 -1
- package/lib/stores/aggregator.d.ts +0 -48
- package/lib/stores/aggregator.d.ts.map +0 -1
- package/lib/stores/aggregator.js +0 -80
- package/lib/stores/aggregator.js.map +0 -1
- package/lib/stores/file.d.ts +0 -108
- package/lib/stores/file.d.ts.map +0 -1
- package/lib/stores/file.js +0 -188
- package/lib/stores/file.js.map +0 -1
- package/lib/stores/file.spec.d.ts +0 -13
- package/lib/stores/file.spec.d.ts.map +0 -1
- package/lib/stores/file.spec.js +0 -138
- package/lib/stores/file.spec.js.map +0 -1
- package/lib/stores/mapper.d.ts +0 -150
- package/lib/stores/mapper.d.ts.map +0 -1
- package/lib/stores/mapper.js +0 -293
- package/lib/stores/mapper.js.map +0 -1
- package/lib/stores/mapper.spec.d.ts +0 -2
- package/lib/stores/mapper.spec.d.ts.map +0 -1
- package/lib/stores/mapper.spec.js +0 -167
- package/lib/stores/mapper.spec.js.map +0 -1
- package/lib/stores/memory.d.ts +0 -152
- package/lib/stores/memory.d.ts.map +0 -1
- package/lib/stores/memory.js +0 -371
- package/lib/stores/memory.js.map +0 -1
- package/lib/stores/memory.spec.d.ts +0 -14
- package/lib/stores/memory.spec.d.ts.map +0 -1
- package/lib/stores/memory.spec.js +0 -263
- package/lib/stores/memory.spec.js.map +0 -1
- package/lib/stores/modelmapper.d.ts +0 -62
- package/lib/stores/modelmapper.d.ts.map +0 -1
- package/lib/stores/modelmapper.js +0 -197
- package/lib/stores/modelmapper.js.map +0 -1
- package/lib/stores/store.spec.d.ts +0 -57
- package/lib/stores/store.spec.d.ts.map +0 -1
- package/lib/stores/store.spec.js +0 -737
- package/lib/stores/store.spec.js.map +0 -1
- package/lib/test.d.ts +0 -265
- package/lib/test.d.ts.map +0 -1
- package/lib/test.js +0 -622
- package/lib/test.js.map +0 -1
- package/lib/unpackedapplication.d.ts.map +0 -1
- package/lib/unpackedapplication.js +0 -350
- package/lib/unpackedapplication.js.map +0 -1
- package/lib/utils/abstractdeployer.spec.d.ts +0 -2
- package/lib/utils/abstractdeployer.spec.d.ts.map +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 -8
- package/lib/utils/case.d.ts.map +0 -1
- package/lib/utils/case.js +0 -43
- package/lib/utils/case.js.map +0 -1
- package/lib/utils/case.spec.d.ts +0 -2
- package/lib/utils/case.spec.d.ts.map +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 -482
- package/lib/utils/context.d.ts.map +0 -1
- package/lib/utils/context.js +0 -739
- package/lib/utils/context.js.map +0 -1
- package/lib/utils/context.spec.d.ts +0 -10
- package/lib/utils/context.spec.d.ts.map +0 -1
- package/lib/utils/context.spec.js +0 -383
- package/lib/utils/context.spec.js.map +0 -1
- package/lib/utils/cookie.d.ts.map +0 -1
- package/lib/utils/cookie.js.map +0 -1
- package/lib/utils/cookie.spec.d.ts +0 -2
- package/lib/utils/cookie.spec.d.ts.map +0 -1
- package/lib/utils/cookie.spec.js +0 -88
- package/lib/utils/cookie.spec.js.map +0 -1
- package/lib/utils/esm.d.ts +0 -14
- package/lib/utils/esm.d.ts.map +0 -1
- package/lib/utils/esm.js +0 -19
- package/lib/utils/esm.js.map +0 -1
- package/lib/utils/httpcontext.d.ts.map +0 -1
- package/lib/utils/httpcontext.js.map +0 -1
- package/lib/utils/httpcontext.spec.d.ts +0 -5
- package/lib/utils/httpcontext.spec.d.ts.map +0 -1
- package/lib/utils/httpcontext.spec.js +0 -77
- package/lib/utils/httpcontext.spec.js.map +0 -1
- package/lib/utils/logger.d.ts +0 -92
- package/lib/utils/logger.d.ts.map +0 -1
- package/lib/utils/logger.js +0 -121
- package/lib/utils/logger.js.map +0 -1
- package/lib/utils/logger.spec.d.ts +0 -2
- package/lib/utils/logger.spec.d.ts.map +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 -162
- package/lib/utils/serializers.d.ts.map +0 -1
- package/lib/utils/serializers.js +0 -420
- package/lib/utils/serializers.js.map +0 -1
- package/lib/utils/serializers.spec.d.ts +0 -2
- package/lib/utils/serializers.spec.d.ts.map +0 -1
- package/lib/utils/serializers.spec.js +0 -311
- package/lib/utils/serializers.spec.js.map +0 -1
- package/lib/utils/session.d.ts +0 -123
- package/lib/utils/session.d.ts.map +0 -1
- package/lib/utils/session.js +0 -156
- package/lib/utils/session.js.map +0 -1
- package/lib/utils/session.spec.d.ts +0 -2
- package/lib/utils/session.spec.d.ts.map +0 -1
- package/lib/utils/session.spec.js +0 -81
- package/lib/utils/session.spec.js.map +0 -1
- package/lib/utils/throttler.d.ts +0 -99
- package/lib/utils/throttler.d.ts.map +0 -1
- package/lib/utils/throttler.js +0 -160
- package/lib/utils/throttler.js.map +0 -1
- package/lib/utils/throttler.spec.d.ts +0 -2
- package/lib/utils/throttler.spec.d.ts.map +0 -1
- package/lib/utils/throttler.spec.js +0 -53
- package/lib/utils/throttler.spec.js.map +0 -1
- package/lib/utils/waiter.d.ts +0 -94
- package/lib/utils/waiter.d.ts.map +0 -1
- package/lib/utils/waiter.js +0 -148
- package/lib/utils/waiter.js.map +0 -1
- package/lib/utils/waiter.spec.d.ts +0 -2
- package/lib/utils/waiter.spec.d.ts.map +0 -1
- package/lib/utils/waiter.spec.js +0 -98
- package/lib/utils/waiter.spec.js.map +0 -1
- package/test/jsonutils/mdocs.yaml +0 -56
- package/test/jsonutils/test.json +0 -3
- package/test/jsonutils/test.yml +0 -5
package/lib/stores/store.js
CHANGED
|
@@ -1,36 +1,125 @@
|
|
|
1
|
-
import { Counter, Histogram } from "../
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import { Counter, Histogram } from "../metrics/metrics.js";
|
|
2
|
+
import * as WebdaError from "../errors/errors.js";
|
|
3
|
+
import { registerRepository } from "@webda/models";
|
|
4
|
+
import { ServiceParameters } from "../services/serviceparameters.js";
|
|
5
|
+
import { Service } from "../services/service.js";
|
|
6
|
+
import { useApplication, useModel, useModelId } from "../application/hooks.js";
|
|
7
|
+
import { useLog } from "../loggers/hooks.js";
|
|
8
|
+
import { useCore, useModelMetadata } from "../core/hooks.js";
|
|
9
|
+
/** Error thrown when an item is not found in a store */
|
|
6
10
|
export class StoreNotFoundError extends WebdaError.CodeError {
|
|
11
|
+
/** Create a new StoreNotFoundError
|
|
12
|
+
* @param uuid - the item primary key
|
|
13
|
+
* @param storeName - the store name
|
|
14
|
+
*/
|
|
7
15
|
constructor(uuid, storeName) {
|
|
8
16
|
super("STORE_NOTFOUND", `Item not found ${uuid} Store(${storeName})`);
|
|
9
17
|
}
|
|
10
18
|
}
|
|
19
|
+
/** Error thrown when a conditional update fails due to a version/condition mismatch */
|
|
11
20
|
export class UpdateConditionFailError extends WebdaError.CodeError {
|
|
21
|
+
/** Create a new UpdateConditionFailError
|
|
22
|
+
* @param uuid - the item primary key
|
|
23
|
+
* @param conditionField - the condition field name
|
|
24
|
+
* @param condition - the expected condition value
|
|
25
|
+
*/
|
|
12
26
|
constructor(uuid, conditionField, condition) {
|
|
13
27
|
super("STORE_UPDATE_CONDITION_FAILED", `UpdateCondition not met on ${uuid}.${conditionField} === ${condition instanceof Date ? condition.toISOString() : condition}`);
|
|
14
28
|
}
|
|
15
29
|
}
|
|
16
30
|
/**
|
|
17
31
|
* Store parameter
|
|
32
|
+
*
|
|
33
|
+
* @internal — Store configuration schema. Authored in `webda.config`/deployment
|
|
34
|
+
* files; not consumed by app code directly.
|
|
18
35
|
*/
|
|
19
36
|
export class StoreParameters extends ServiceParameters {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Models managed by this Store.
|
|
39
|
+
*
|
|
40
|
+
* @default ["Webda/RegistryEntry"]
|
|
41
|
+
*/
|
|
42
|
+
models;
|
|
43
|
+
/**
|
|
44
|
+
* Allow to load object that does not have the type data
|
|
45
|
+
*
|
|
46
|
+
* If set to true, then the Store will only managed the defined _model and no
|
|
47
|
+
* model extending this one
|
|
48
|
+
*
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
strict;
|
|
52
|
+
/**
|
|
53
|
+
* When __type model not found, use the model
|
|
54
|
+
* If strict is setup this parameter is not used
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
defaultModel;
|
|
59
|
+
/**
|
|
60
|
+
* If set, Store will ignore the __type
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
forceModel;
|
|
65
|
+
/**
|
|
66
|
+
* Slow query threshold
|
|
67
|
+
*
|
|
68
|
+
* @default 30000
|
|
69
|
+
*/
|
|
70
|
+
slowQueryThreshold;
|
|
71
|
+
/**
|
|
72
|
+
* Model Aliases to allow easier rename of Model
|
|
73
|
+
*/
|
|
74
|
+
modelAliases;
|
|
75
|
+
/**
|
|
76
|
+
* Disable default memory cache
|
|
77
|
+
*/
|
|
78
|
+
noCache;
|
|
79
|
+
/**
|
|
80
|
+
* Load store parameters with defaults for model type, strict mode, and aliases
|
|
81
|
+
* @param params - the service parameters
|
|
82
|
+
* @returns the result
|
|
83
|
+
*/
|
|
84
|
+
load(params) {
|
|
29
85
|
// REFACTOR >= 5
|
|
30
86
|
if (params.expose) {
|
|
31
87
|
throw new Error("Expose is not supported anymore, use DomainService instead");
|
|
32
88
|
}
|
|
33
89
|
// END_REFACTOR
|
|
90
|
+
super.load(params);
|
|
91
|
+
// Deprecation mapping: model + additionalModels → models[]
|
|
92
|
+
const hasModels = Array.isArray(params.models);
|
|
93
|
+
const hasModel = typeof params.model === "string";
|
|
94
|
+
// Presence check (not length) used for the conflict guard so that
|
|
95
|
+
// `{ models: [...], additionalModels: [] }` is still detected as ambiguous.
|
|
96
|
+
const hasAdditionalKey = Array.isArray(params.additionalModels);
|
|
97
|
+
// Length check used for the deprecation branch: an empty additionalModels
|
|
98
|
+
// alongside a bare `model` is unambiguous and should not warn on its own.
|
|
99
|
+
const hasAdditional = hasAdditionalKey && params.additionalModels.length > 0;
|
|
100
|
+
if (hasModels && (hasModel || hasAdditionalKey)) {
|
|
101
|
+
throw new Error("StoreParameters: `models` and `model`/`additionalModels` are mutually exclusive — ambiguous configuration");
|
|
102
|
+
}
|
|
103
|
+
if (hasModels) {
|
|
104
|
+
this.models = [...params.models];
|
|
105
|
+
}
|
|
106
|
+
else if (hasModel || hasAdditional) {
|
|
107
|
+
useLog("WARN", `StoreParameters: \`model\` and \`additionalModels\` are deprecated. Use \`models: [...]\` instead.`);
|
|
108
|
+
this.models = [params.model ?? "Webda/RegistryEntry", ...(params.additionalModels ?? [])];
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.models = ["Webda/RegistryEntry"];
|
|
112
|
+
}
|
|
113
|
+
// When the caller passed `models[]` (or nothing at all), backfill the deprecated
|
|
114
|
+
// fields from the canonical `models[]` so any code still reading `parameters.model`
|
|
115
|
+
// or `parameters.additionalModels` keeps working. In the legacy-input branch
|
|
116
|
+
// `super.load(params)` already set both via Object.assign, so the `??=` is a no-op.
|
|
117
|
+
this.strict ??= false;
|
|
118
|
+
this.defaultModel ??= true;
|
|
119
|
+
this.forceModel ??= false;
|
|
120
|
+
this.slowQueryThreshold ??= 30000;
|
|
121
|
+
this.modelAliases ??= {};
|
|
122
|
+
return this;
|
|
34
123
|
}
|
|
35
124
|
}
|
|
36
125
|
/**
|
|
@@ -47,88 +136,162 @@ export class StoreParameters extends ServiceParameters {
|
|
|
47
136
|
* Store.Action: When an action will be done on an object
|
|
48
137
|
* Store.Actioned: When an action has been done on an object
|
|
49
138
|
*
|
|
139
|
+
* @internal — Subclassed by store packages only. App code never references a
|
|
140
|
+
* Store directly: use `useRepository(Model)` or static model methods
|
|
141
|
+
* (`Model.create()`, `Model.query()`, `Model.ref()`).
|
|
50
142
|
* @category CoreServices
|
|
51
143
|
*/
|
|
52
144
|
class Store extends Service {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
145
|
+
/** All model classes managed by this store. Index 0 is the legacy "primary" model. */
|
|
146
|
+
_models = [];
|
|
147
|
+
/** Metadata for each model in `_models`, keyed by Identifier. */
|
|
148
|
+
_modelMetadatas = new Map();
|
|
149
|
+
/** Store the manager hierarchy with their depth */
|
|
150
|
+
_modelsHierarchy = {};
|
|
151
|
+
/**
|
|
152
|
+
* Override the resolved model class for this store at runtime. Used by
|
|
153
|
+
* the abstract `StoreTest` harness so test fixtures can substitute a
|
|
154
|
+
* subclass with extra fields in place of the configured model. In
|
|
155
|
+
* production this is a no-op the framework never calls.
|
|
156
|
+
* @param model - the substitute model class
|
|
157
|
+
*/
|
|
158
|
+
setModelDefinitionHelper(model) {
|
|
159
|
+
this._models[0] = model;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Compute and register repositories for all known models based on available stores.
|
|
163
|
+
*
|
|
164
|
+
* Called from `Store.init()` so each store's init triggers a recompute.
|
|
165
|
+
* Cannot be cached: the FIRST store to init (typically `Registry`) would
|
|
166
|
+
* claim every model with its fallback repository, and subsequent
|
|
167
|
+
* stores wouldn't get a chance to claim their configured models.
|
|
168
|
+
* Re-running is idempotent — `registerRepository` overwrites map entries
|
|
169
|
+
* in place, and the resolution loop is deterministic per current
|
|
170
|
+
* service/model state.
|
|
171
|
+
*/
|
|
172
|
+
static computeStores() {
|
|
173
|
+
// Gather all stores and register Repository
|
|
174
|
+
const stores = Object.values(useCore().getServices()).filter(s => s instanceof Store);
|
|
175
|
+
const models = Object.values(useApplication().getModels());
|
|
176
|
+
const registry = useCore().getService("Registry");
|
|
177
|
+
// Check each available models
|
|
178
|
+
for (const model of models) {
|
|
179
|
+
// Model can be null?
|
|
180
|
+
if (!model)
|
|
181
|
+
continue;
|
|
182
|
+
if (!model.Metadata || !Array.isArray(model.Metadata.PrimaryKey)) {
|
|
183
|
+
useLog("WARN", `${useModelId(model)} does not have Metadata or PrimaryKey defined`);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
let currentValue = -1;
|
|
187
|
+
let currentStore = undefined;
|
|
188
|
+
for (const store of stores) {
|
|
189
|
+
const value = store.handleModel(model);
|
|
190
|
+
if (value < 0 || (value > currentValue && currentValue !== -1)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
currentValue = value;
|
|
194
|
+
currentStore = store;
|
|
195
|
+
}
|
|
196
|
+
if (!currentStore) {
|
|
197
|
+
useLog("TRACE", `${useModelId(model)} fallback to Registry store`);
|
|
198
|
+
currentStore = registry;
|
|
199
|
+
}
|
|
200
|
+
// Register the repository
|
|
201
|
+
registerRepository(model, currentStore.getRepository(model));
|
|
202
|
+
useLog("DEBUG", `${useModelId(model)} using store ${currentStore.getName()}`);
|
|
203
|
+
}
|
|
67
204
|
}
|
|
68
205
|
/**
|
|
69
|
-
* Retrieve the
|
|
206
|
+
* Retrieve the Models and build the models hierarchy map.
|
|
70
207
|
*
|
|
71
|
-
*
|
|
208
|
+
* Walks `parameters.models[]` (the canonical flat list introduced in Task 1).
|
|
209
|
+
* If the list is empty or contains only the default "Webda/RegistryEntry"
|
|
210
|
+
* fallback, the hierarchy stays empty and the store will not claim any model
|
|
211
|
+
* — preserving the pre-migration fallback behaviour for test-only or
|
|
212
|
+
* misconfigured stores.
|
|
72
213
|
*/
|
|
73
214
|
computeParameters() {
|
|
74
215
|
super.computeParameters();
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!this.parameters.noCache) {
|
|
81
|
-
this._cacheStore = new MemoryStore(this._webda, `_${this.getName()}_cache`, {
|
|
82
|
-
model: this.parameters.model
|
|
83
|
-
});
|
|
84
|
-
this._cacheStore.computeParameters();
|
|
85
|
-
this._cacheStore.initMetrics();
|
|
86
|
-
this.cacheStorePatchException();
|
|
216
|
+
const ids = this.parameters.models ?? [];
|
|
217
|
+
// Empty / default RegistryEntry → leave hierarchy empty (preserves test-only / fallback behaviour).
|
|
218
|
+
const isOnlyDefault = ids.length === 1 && ids[0] === "Webda/RegistryEntry";
|
|
219
|
+
if (ids.length === 0 || isOnlyDefault) {
|
|
220
|
+
return;
|
|
87
221
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
222
|
+
this._models = [];
|
|
223
|
+
this._modelMetadatas = new Map();
|
|
224
|
+
this._modelsHierarchy = {};
|
|
225
|
+
// Subclasses in ModelMetadata are resolved to ModelClass objects at runtime
|
|
226
|
+
// (see Application.setModelMetadata). Accept both string IDs and ModelClass
|
|
227
|
+
// references so the hierarchy is keyed by string identifier throughout.
|
|
228
|
+
const recursive = (subclasses, depth) => {
|
|
229
|
+
for (const entry of subclasses) {
|
|
230
|
+
let subModel;
|
|
231
|
+
let subId;
|
|
232
|
+
if (typeof entry === "string") {
|
|
233
|
+
subId = entry;
|
|
234
|
+
try {
|
|
235
|
+
subModel = useModel(entry);
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
subModel = entry;
|
|
243
|
+
subId = useModelId(subModel);
|
|
244
|
+
}
|
|
245
|
+
if (!subId || !subModel)
|
|
246
|
+
continue;
|
|
247
|
+
this._modelsHierarchy[subId] = Math.min(depth, this._modelsHierarchy[subId] ?? depth);
|
|
248
|
+
const subMeta = useModelMetadata(subModel);
|
|
249
|
+
if (!subMeta)
|
|
250
|
+
continue;
|
|
251
|
+
recursive(subMeta.Subclasses ?? [], depth + 1);
|
|
95
252
|
}
|
|
96
253
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (!this.parameters.strict) {
|
|
102
|
-
recursive(this._model.getHierarchy().children, 1);
|
|
103
|
-
}
|
|
104
|
-
// Add additional models
|
|
105
|
-
if (this.parameters.additionalModels.length) {
|
|
106
|
-
// Strict mode is to only allow one model per store
|
|
107
|
-
if (this.parameters.strict) {
|
|
108
|
-
this.log("ERROR", "Cannot add additional models in strict mode");
|
|
254
|
+
for (const id of ids) {
|
|
255
|
+
let model;
|
|
256
|
+
try {
|
|
257
|
+
model = useModel(id);
|
|
109
258
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
259
|
+
catch {
|
|
260
|
+
model = undefined;
|
|
261
|
+
}
|
|
262
|
+
if (!model) {
|
|
263
|
+
useLog("TRACE", `Store ${this.getName?.() ?? "unknown"}: model not found: ${id}`);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
const meta = useModelMetadata(model);
|
|
267
|
+
if (!meta) {
|
|
268
|
+
useLog("WARN", `Store ${this.getName?.() ?? "unknown"}: model metadata not found for ${id}`);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
this._models.push(model);
|
|
272
|
+
this._modelMetadatas.set(meta.Identifier, meta);
|
|
273
|
+
this._modelsHierarchy[meta.Identifier] = 0;
|
|
274
|
+
if (!this.parameters.strict) {
|
|
275
|
+
recursive(meta.Subclasses ?? [], 1);
|
|
117
276
|
}
|
|
118
277
|
}
|
|
119
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Log a slow query (placeholder for future implementation)
|
|
281
|
+
* @param _query - the query to execute
|
|
282
|
+
* @param _reason - the reason
|
|
283
|
+
* @param _time - the time
|
|
284
|
+
*/
|
|
120
285
|
logSlowQuery(_query, _reason, _time) {
|
|
121
286
|
// TODO Need to implement: https://github.com/loopingz/webda.io/issues/202
|
|
122
287
|
}
|
|
123
288
|
/**
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
289
|
+
* Initialize the store
|
|
290
|
+
* @returns this for chaining
|
|
126
291
|
*/
|
|
127
|
-
async
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
await this._cacheStore.delete(uid);
|
|
131
|
-
}
|
|
292
|
+
async init() {
|
|
293
|
+
Store.computeStores();
|
|
294
|
+
return super.init();
|
|
132
295
|
}
|
|
133
296
|
/**
|
|
134
297
|
* @override
|
|
@@ -144,1066 +307,43 @@ class Store extends Service {
|
|
|
144
307
|
name: "slow_queries",
|
|
145
308
|
help: "Number of slow queries encountered"
|
|
146
309
|
});
|
|
147
|
-
this.metrics.cache_invalidations = this.getMetric(Counter, {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
this.metrics.cache_hits = this.getMetric(Counter, {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
});
|
|
310
|
+
// this.metrics.cache_invalidations = this.getMetric(Counter, {
|
|
311
|
+
// name: "cache_invalidations",
|
|
312
|
+
// help: "Number of cache invalidation encountered"
|
|
313
|
+
// });
|
|
314
|
+
// this.metrics.cache_hits = this.getMetric(Counter, {
|
|
315
|
+
// name: "cache_hits",
|
|
316
|
+
// help: "Number of cache hits"
|
|
317
|
+
// });
|
|
155
318
|
this.metrics.queries = this.getMetric(Histogram, {
|
|
156
319
|
name: "queries",
|
|
157
320
|
help: "Query duration"
|
|
158
321
|
});
|
|
159
322
|
}
|
|
160
323
|
/**
|
|
161
|
-
*
|
|
162
|
-
* @returns
|
|
324
|
+
* All models managed by this store.
|
|
325
|
+
* @returns the array of model classes managed by this store
|
|
163
326
|
*/
|
|
164
|
-
|
|
165
|
-
return this.
|
|
327
|
+
getModels() {
|
|
328
|
+
return this._models;
|
|
166
329
|
}
|
|
167
330
|
/**
|
|
168
331
|
* Return if a model is handled by the store
|
|
169
|
-
* @param model
|
|
332
|
+
* @param model - the model to use
|
|
170
333
|
* @return distance from the managed class -1 means not managed, 0 manage exactly this model, >0 manage an ancestor model
|
|
171
334
|
*
|
|
335
|
+
* @returns the result number
|
|
172
336
|
*/
|
|
173
337
|
handleModel(model) {
|
|
174
|
-
const name =
|
|
338
|
+
const name = useModelId(model);
|
|
175
339
|
return this._modelsHierarchy[name] ?? -1;
|
|
176
340
|
}
|
|
177
341
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* @param raiseIfNotFound
|
|
181
|
-
* @returns
|
|
182
|
-
*/
|
|
183
|
-
async _getFromCache(uuid, raiseIfNotFound = false) {
|
|
184
|
-
let res = await this._cacheStore?._get(uuid);
|
|
185
|
-
if (!res) {
|
|
186
|
-
res = await this._get(uuid, raiseIfNotFound);
|
|
187
|
-
if (res) {
|
|
188
|
-
await this._cacheStore?._save(res);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
this.metrics.cache_hits.inc();
|
|
193
|
-
res.__store = this;
|
|
194
|
-
}
|
|
195
|
-
return res;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Get object from store
|
|
199
|
-
* @param uid
|
|
200
|
-
* @returns
|
|
201
|
-
*/
|
|
202
|
-
async getObject(uid) {
|
|
203
|
-
this.metrics.operations_total.inc({ operation: "get" });
|
|
204
|
-
return this._getFromCache(uid);
|
|
205
|
-
}
|
|
206
|
-
static getOpenAPI() { }
|
|
207
|
-
/**
|
|
208
|
-
* OVerwrite the model
|
|
209
|
-
* Used mainly in test
|
|
210
|
-
*/
|
|
211
|
-
setModel(model) {
|
|
212
|
-
this._model = model;
|
|
213
|
-
this._cacheStore?.setModel(model);
|
|
214
|
-
this.parameters.strict = false;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* We should ignore exception from the store
|
|
218
|
-
*/
|
|
219
|
-
cacheStorePatchException() {
|
|
220
|
-
const replacer = original => {
|
|
221
|
-
return (...args) => {
|
|
222
|
-
return original
|
|
223
|
-
.bind(this._cacheStore, ...args)()
|
|
224
|
-
.catch(err => {
|
|
225
|
-
this.log("TRACE", `Ignoring cache exception ${this._name}: ${err.message}`);
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
for (const i of [
|
|
230
|
-
"_get",
|
|
231
|
-
"_patch",
|
|
232
|
-
"_update",
|
|
233
|
-
"_delete",
|
|
234
|
-
"_incrementAttributes",
|
|
235
|
-
"_upsertItemToCollection",
|
|
236
|
-
"_deleteItemFromCollection",
|
|
237
|
-
"_removeAttribute"
|
|
238
|
-
]) {
|
|
239
|
-
this._cacheStore[i] = replacer(this._cacheStore[i]);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Init a model from the current stored data
|
|
244
|
-
*
|
|
245
|
-
* Initial the reverse map as well
|
|
246
|
-
*
|
|
247
|
-
* @param object
|
|
248
|
-
* @returns
|
|
249
|
-
*/
|
|
250
|
-
initModel(object = {}) {
|
|
251
|
-
var _a;
|
|
252
|
-
object.__type ?? (object.__type = this.getWebda().getApplication().getModelFromInstance(object) || this._modelType);
|
|
253
|
-
// Make sure to send a model object
|
|
254
|
-
if (!(object instanceof this._model)) {
|
|
255
|
-
// Dynamic load type
|
|
256
|
-
if (object.__type && !this.getParameters().forceModel) {
|
|
257
|
-
try {
|
|
258
|
-
const modelType = this.getWebda()
|
|
259
|
-
.getApplication()
|
|
260
|
-
.getModel(this.parameters.modelAliases[object.__type] || object.__type);
|
|
261
|
-
object = new modelType().load(object, true);
|
|
262
|
-
}
|
|
263
|
-
catch (err) {
|
|
264
|
-
if (!this.parameters.defaultModel) {
|
|
265
|
-
throw new Error(`Unknown model ${object.__type} found for Store(${this.getName()})`);
|
|
266
|
-
}
|
|
267
|
-
object = this._model.factory(object);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
object = this._model.factory(object);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (!object.getUuid()) {
|
|
275
|
-
object.setUuid(object.generateUid(object));
|
|
276
|
-
}
|
|
277
|
-
object.__store = this;
|
|
278
|
-
for (const i in this._reverseMap) {
|
|
279
|
-
object[_a = this._reverseMap[i].property] ?? (object[_a] = []);
|
|
280
|
-
for (const j in object[this._reverseMap[i].property]) {
|
|
281
|
-
if (object[this._reverseMap[i].property][j] instanceof ModelMapLoaderImplementation) {
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
// Use Partial
|
|
285
|
-
object[this._reverseMap[i].property][j] = this._reverseMap[i].mapper.newModel(object[this._reverseMap[i].property][j]);
|
|
286
|
-
object[this._reverseMap[i].property][j].setContext(object.getContext());
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return object;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Get a new model with this data preloaded
|
|
293
|
-
* @param object
|
|
294
|
-
* @returns
|
|
295
|
-
*/
|
|
296
|
-
newModel(object = {}) {
|
|
297
|
-
const result = this.initModel(object);
|
|
298
|
-
Object.keys(object).forEach(k => result.__dirty.add(k));
|
|
299
|
-
return result;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Add reverse map information
|
|
303
|
-
*
|
|
304
|
-
* @param prop
|
|
305
|
-
* @param cascade
|
|
306
|
-
* @param store
|
|
307
|
-
*/
|
|
308
|
-
addReverseMap(prop, store) {
|
|
309
|
-
this._reverseMap.push({
|
|
310
|
-
property: prop,
|
|
311
|
-
mapper: store
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Increment attributes of an object
|
|
316
|
-
*
|
|
317
|
-
* @param uid
|
|
318
|
-
* @param info
|
|
319
|
-
* @returns
|
|
320
|
-
*/
|
|
321
|
-
async incrementAttributes(uid, info) {
|
|
322
|
-
const params = info.filter(i => i.value !== 0);
|
|
323
|
-
// If value === 0 no need to update anything
|
|
324
|
-
if (params.length === 0) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
const updateDate = new Date();
|
|
328
|
-
this.metrics.operations_total.inc({ operation: "increment" });
|
|
329
|
-
await this._incrementAttributes(uid, params, updateDate);
|
|
330
|
-
const evt = {
|
|
331
|
-
object_id: uid,
|
|
332
|
-
store: this,
|
|
333
|
-
updateDate,
|
|
334
|
-
partial_update: {
|
|
335
|
-
increments: params
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
await this.emitStoreEvent("Store.PartialUpdated", evt);
|
|
339
|
-
return updateDate;
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Helper function that call incrementAttributes
|
|
343
|
-
* @param uid
|
|
344
|
-
* @param prop
|
|
345
|
-
* @param value
|
|
346
|
-
* @returns
|
|
347
|
-
*/
|
|
348
|
-
async incrementAttribute(uid, prop, value) {
|
|
349
|
-
return this.incrementAttributes(uid, [{ property: prop, value }]);
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Add or update an item to an array in the model
|
|
353
|
-
*
|
|
354
|
-
* @param uid of the model
|
|
355
|
-
* @param prop of the model to add in
|
|
356
|
-
* @param item to add in the array
|
|
357
|
-
* @param index if specified update item in this index
|
|
358
|
-
* @param itemWriteCondition value of the condition to test (in case of update)
|
|
359
|
-
* @param itemWriteConditionField field to read the condition from (in case of update)
|
|
360
|
-
*/
|
|
361
|
-
async upsertItemToCollection(uid, prop, item, index = undefined, itemWriteCondition = undefined, itemWriteConditionField = this._uuidField) {
|
|
362
|
-
const updateDate = new Date();
|
|
363
|
-
this.metrics.operations_total.inc({ operation: "collectionUpsert" });
|
|
364
|
-
await this._upsertItemToCollection(uid, prop, item, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
365
|
-
await this.emitStoreEvent("Store.PartialUpdated", {
|
|
366
|
-
object_id: uid,
|
|
367
|
-
store: this,
|
|
368
|
-
updateDate,
|
|
369
|
-
partial_update: {
|
|
370
|
-
addItem: {
|
|
371
|
-
value: item,
|
|
372
|
-
property: prop,
|
|
373
|
-
index: index
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
return updateDate;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Remove an item from an array in the model
|
|
381
|
-
*
|
|
382
|
-
* @param uid of the model
|
|
383
|
-
* @param prop of the model to remove from
|
|
384
|
-
* @param index of the item to remove in the array
|
|
385
|
-
* @param itemWriteCondition value of the condition
|
|
386
|
-
* @param itemWriteConditionField field to read the condition from
|
|
387
|
-
*/
|
|
388
|
-
async deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField = this._uuidField) {
|
|
389
|
-
const updateDate = new Date();
|
|
390
|
-
this.metrics.operations_total.inc({ operation: "collectionDelete" });
|
|
391
|
-
await this._deleteItemFromCollection(uid, prop, index, itemWriteCondition, itemWriteConditionField, updateDate);
|
|
392
|
-
await this.emitStoreEvent("Store.PartialUpdated", {
|
|
393
|
-
object_id: uid,
|
|
394
|
-
store: this,
|
|
395
|
-
updateDate,
|
|
396
|
-
partial_update: {
|
|
397
|
-
deleteItem: {
|
|
398
|
-
property: prop,
|
|
399
|
-
index: index
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
return updateDate;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Iterate through the results
|
|
407
|
-
*
|
|
408
|
-
* This can be resource consuming
|
|
409
|
-
*
|
|
410
|
-
* @param query
|
|
411
|
-
* @param context
|
|
412
|
-
*/
|
|
413
|
-
async *iterate(query = "", context) {
|
|
414
|
-
if (query.includes("OFFSET")) {
|
|
415
|
-
throw new Error("Cannot contain an OFFSET for iterate method");
|
|
416
|
-
}
|
|
417
|
-
let continuationToken;
|
|
418
|
-
do {
|
|
419
|
-
const q = query + (continuationToken !== undefined ? ` OFFSET "${continuationToken}"` : "");
|
|
420
|
-
const page = await this.query(q, context);
|
|
421
|
-
for (const item of page.results) {
|
|
422
|
-
yield item;
|
|
423
|
-
}
|
|
424
|
-
continuationToken = page.continuationToken;
|
|
425
|
-
} while (continuationToken);
|
|
426
|
-
}
|
|
427
|
-
// REFACTOR . >= 4
|
|
428
|
-
/**
|
|
429
|
-
* Query all the results
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
* @param query
|
|
433
|
-
* @param context
|
|
434
|
-
* @returns
|
|
435
|
-
* @deprecated use iterate instead
|
|
436
|
-
*/
|
|
437
|
-
async queryAll(query, context) {
|
|
438
|
-
const res = [];
|
|
439
|
-
for await (const item of this.iterate(query, context)) {
|
|
440
|
-
res.push(item);
|
|
441
|
-
}
|
|
442
|
-
return res;
|
|
443
|
-
}
|
|
444
|
-
// END_REFACTOR
|
|
445
|
-
/**
|
|
446
|
-
* Check that __type Comparison is only used with = and CONTAINS
|
|
447
|
-
* If CONTAINS is used, move __type to __types
|
|
448
|
-
* If __type = store._model, remove it
|
|
449
|
-
*/
|
|
450
|
-
queryTypeUpdater(query) {
|
|
451
|
-
return query;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Query store with WebdaQL
|
|
455
|
-
* @param query
|
|
456
|
-
* @param context to apply permission
|
|
457
|
-
*/
|
|
458
|
-
async query(query, context) {
|
|
459
|
-
const permissionQuery = this._model.getPermissionQuery(context);
|
|
460
|
-
let partialPermission = true;
|
|
461
|
-
let fullQuery = query;
|
|
462
|
-
if (permissionQuery) {
|
|
463
|
-
partialPermission = permissionQuery.partial;
|
|
464
|
-
fullQuery = WebdaQL.PrependCondition(query, permissionQuery.query);
|
|
465
|
-
}
|
|
466
|
-
const queryValidator = new WebdaQL.QueryValidator(fullQuery);
|
|
467
|
-
const offset = queryValidator.getOffset();
|
|
468
|
-
const limit = queryValidator.getLimit();
|
|
469
|
-
const parsedQuery = this.queryTypeUpdater(queryValidator.getQuery());
|
|
470
|
-
parsedQuery.limit = limit;
|
|
471
|
-
// __type is a special field to filter on the type of the object
|
|
472
|
-
// Emit the default event
|
|
473
|
-
await this.emitSync("Store.Query", {
|
|
474
|
-
query,
|
|
475
|
-
parsedQuery,
|
|
476
|
-
store: this,
|
|
477
|
-
context
|
|
478
|
-
});
|
|
479
|
-
const result = {
|
|
480
|
-
results: [],
|
|
481
|
-
continuationToken: undefined
|
|
482
|
-
};
|
|
483
|
-
/*
|
|
484
|
-
Offset are split in two with _
|
|
485
|
-
|
|
486
|
-
MainOffset is the database offset, retrieving a page from the database
|
|
487
|
-
SubOffset is the offset within the page
|
|
488
|
-
|
|
489
|
-
As we filter through the page, for additional filters or permissions, the page cut
|
|
490
|
-
by database does not endup being our final page cut, so we need a page offset to
|
|
491
|
-
abstract this completely
|
|
492
|
-
*/
|
|
493
|
-
// eslint-disable-next-line prefer-const
|
|
494
|
-
let [mainOffset, subOffset] = offset.split("_");
|
|
495
|
-
let secondOffset = parseInt(subOffset || "0");
|
|
496
|
-
let duration = Date.now();
|
|
497
|
-
this.metrics.operations_total.inc({ operation: "query" });
|
|
498
|
-
while (result.results.length < limit) {
|
|
499
|
-
const tmpResults = await this.find({
|
|
500
|
-
...parsedQuery,
|
|
501
|
-
continuationToken: mainOffset
|
|
502
|
-
});
|
|
503
|
-
// If no filter is returned assume it is by mistake and apply filtering
|
|
504
|
-
if (tmpResults.filter === undefined) {
|
|
505
|
-
tmpResults.filter = queryValidator.getExpression();
|
|
506
|
-
this.log("WARN", `Store '${this.getName()}' postquery full filtering`);
|
|
507
|
-
}
|
|
508
|
-
let subOffsetCount = 0;
|
|
509
|
-
for (const item of tmpResults.results) {
|
|
510
|
-
item.setContext(context);
|
|
511
|
-
// Because of dynamic filter and permission we need to suboffset the pagination
|
|
512
|
-
subOffsetCount++;
|
|
513
|
-
if (subOffsetCount <= secondOffset) {
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
if (tmpResults.filter !== true && !tmpResults.filter.eval(item)) {
|
|
517
|
-
continue;
|
|
518
|
-
}
|
|
519
|
-
if (context && partialPermission && (await item.canAct(context, "get")) !== true) {
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
result.results.push(item);
|
|
523
|
-
if (result.results.length >= limit) {
|
|
524
|
-
if (subOffsetCount === tmpResults.results.length) {
|
|
525
|
-
result.continuationToken = tmpResults.continuationToken;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
result.continuationToken = `${mainOffset}_${subOffsetCount}`;
|
|
529
|
-
}
|
|
530
|
-
break;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
// Update both offset
|
|
534
|
-
mainOffset = tmpResults.continuationToken;
|
|
535
|
-
// Fresh new query so we do not need to skip
|
|
536
|
-
secondOffset = 0;
|
|
537
|
-
if (mainOffset === undefined || result.results.length >= limit) {
|
|
538
|
-
break;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
duration = Date.now() - duration;
|
|
542
|
-
this.metrics.queries.observe(duration / 1000);
|
|
543
|
-
if (duration > this.parameters.slowQueryThreshold) {
|
|
544
|
-
this.logSlowQuery(query, "", duration);
|
|
545
|
-
this.metrics.slow_queries_total.inc();
|
|
546
|
-
}
|
|
547
|
-
await this.emitSync("Store.Queried", {
|
|
548
|
-
query,
|
|
549
|
-
parsedQuery: parsedQuery,
|
|
550
|
-
store: this,
|
|
551
|
-
continuationToken: result.continuationToken,
|
|
552
|
-
results: result.results,
|
|
553
|
-
context
|
|
554
|
-
});
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
* Handle StoreEvent and update cache based on it
|
|
559
|
-
* Then emit the event, it allows the cache to be updated
|
|
560
|
-
* before listeners are called
|
|
561
|
-
*
|
|
562
|
-
* @param event
|
|
563
|
-
* @param data
|
|
342
|
+
* Check that keys are valid
|
|
343
|
+
* All keys of model stored in a Store must have the same type of primary key
|
|
564
344
|
*/
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
await this._cacheStore?._delete(data.object_id);
|
|
568
|
-
}
|
|
569
|
-
else if (event === "Store.PartialUpdated") {
|
|
570
|
-
const partialEvent = data;
|
|
571
|
-
if (partialEvent.partial_update.increments) {
|
|
572
|
-
await this._cacheStore?._incrementAttributes(partialEvent.object_id, partialEvent.partial_update.increments, partialEvent.updateDate);
|
|
573
|
-
}
|
|
574
|
-
else if (partialEvent.partial_update.deleteAttribute) {
|
|
575
|
-
await this._cacheStore?._removeAttribute(partialEvent.object_id, partialEvent.partial_update.deleteAttribute, partialEvent.updateDate);
|
|
576
|
-
}
|
|
577
|
-
else if (partialEvent.partial_update.addItem) {
|
|
578
|
-
await this._cacheStore?._upsertItemToCollection(partialEvent.object_id, partialEvent.partial_update.addItem.property, partialEvent.partial_update.addItem.value, partialEvent.partial_update.addItem.index, undefined, undefined, partialEvent.updateDate);
|
|
579
|
-
}
|
|
580
|
-
else if (partialEvent.partial_update.deleteItem) {
|
|
581
|
-
await this._cacheStore?._deleteItemFromCollection(partialEvent.object_id, partialEvent.partial_update.deleteItem.property, partialEvent.partial_update.deleteItem.index, undefined, undefined, partialEvent.updateDate);
|
|
582
|
-
}
|
|
583
|
-
else if (partialEvent.partial_update.patch) {
|
|
584
|
-
await this._cacheStore?._patch(partialEvent.partial_update.patch, partialEvent.object_id);
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
await this.invalidateCache(partialEvent.object_id);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
else if (event === "Store.Updated") {
|
|
591
|
-
await this._cacheStore?._update(data.update, data.object_id);
|
|
592
|
-
}
|
|
593
|
-
else if (event === "Store.PatchUpdated") {
|
|
594
|
-
await this._cacheStore?._patch(data.object, data.object_id);
|
|
595
|
-
}
|
|
596
|
-
await this.emitSync(event, data);
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Save an object
|
|
600
|
-
*
|
|
601
|
-
* @param {Object} Object to save
|
|
602
|
-
* @param {String} Uuid to use, if not specified take the object.uuid or generate one if not found
|
|
603
|
-
* @return {Promise} with saved object
|
|
604
|
-
*
|
|
605
|
-
* Might want to rename to create
|
|
606
|
-
*/
|
|
607
|
-
async save(object, ctx = undefined) {
|
|
608
|
-
if (object instanceof this._model && object._creationDate !== undefined && object._lastUpdate !== undefined) {
|
|
609
|
-
if (ctx) {
|
|
610
|
-
object.setContext(ctx);
|
|
611
|
-
}
|
|
612
|
-
return await object.save();
|
|
613
|
-
}
|
|
614
|
-
return this.create(object, ctx);
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
*
|
|
618
|
-
* @param object
|
|
619
|
-
* @param ctx
|
|
620
|
-
* @returns
|
|
621
|
-
*/
|
|
622
|
-
async create(object, ctx = undefined) {
|
|
623
|
-
object = this.initModel(object);
|
|
624
|
-
// Dates should be store by the Store
|
|
625
|
-
if (!object._creationDate) {
|
|
626
|
-
object._creationDate = object._lastUpdate = new Date();
|
|
627
|
-
}
|
|
628
|
-
else {
|
|
629
|
-
object._lastUpdate = new Date();
|
|
630
|
-
}
|
|
631
|
-
const ancestors = this.getWebda().getApplication().getModelHierarchy(object.__type).ancestors;
|
|
632
|
-
object.__types = [object.__type, ...ancestors].filter(i => i !== "Webda/CoreModel" && i !== "CoreModel");
|
|
633
|
-
if (ctx) {
|
|
634
|
-
object.setContext(ctx);
|
|
635
|
-
}
|
|
636
|
-
// Handle object auto listener
|
|
637
|
-
const evt = {
|
|
638
|
-
object: object,
|
|
639
|
-
object_id: object.getUuid(),
|
|
640
|
-
store: this,
|
|
641
|
-
context: ctx
|
|
642
|
-
};
|
|
643
|
-
await Promise.all([
|
|
644
|
-
this.emitSync("Store.Save", evt),
|
|
645
|
-
object?.__class.emitSync("Store.Save", evt),
|
|
646
|
-
object._onSave()
|
|
647
|
-
]);
|
|
648
|
-
this.metrics.operations_total.inc({ operation: "save" });
|
|
649
|
-
const res = await this._save(object);
|
|
650
|
-
await this._cacheStore?._save(object);
|
|
651
|
-
object = this.initModel(res);
|
|
652
|
-
const evtSaved = {
|
|
653
|
-
object: object,
|
|
654
|
-
object_id: object.getUuid(),
|
|
655
|
-
store: this,
|
|
656
|
-
context: ctx
|
|
657
|
-
};
|
|
658
|
-
await Promise.all([
|
|
659
|
-
this.emitSync("Store.Saved", evtSaved),
|
|
660
|
-
object?.__class.emitSync("Store.Saved", evtSaved),
|
|
661
|
-
object._onSaved()
|
|
662
|
-
]);
|
|
663
|
-
return object;
|
|
664
|
-
}
|
|
665
|
-
/**
|
|
666
|
-
* Patch an object
|
|
667
|
-
*
|
|
668
|
-
* @param object
|
|
669
|
-
* @param reverseMap
|
|
670
|
-
* @returns
|
|
671
|
-
*/
|
|
672
|
-
async patch(object, reverseMap = true, conditionField, conditionValue) {
|
|
673
|
-
return this.update(object, reverseMap, true, conditionField, conditionValue);
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Check if an UpdateCondition is met
|
|
677
|
-
* @param model
|
|
678
|
-
* @param conditionField
|
|
679
|
-
* @param condition
|
|
680
|
-
* @param uid
|
|
681
|
-
*/
|
|
682
|
-
checkUpdateCondition(model, conditionField, condition, uid) {
|
|
683
|
-
if (conditionField) {
|
|
684
|
-
// Add toString to manage Date object
|
|
685
|
-
if (model[conditionField].toString() !== condition.toString()) {
|
|
686
|
-
throw new UpdateConditionFailError(uid ? uid : model.getUuid(), conditionField, condition);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Check if an UpdateCondition is met
|
|
692
|
-
* @param model
|
|
693
|
-
* @param conditionField
|
|
694
|
-
* @param condition
|
|
695
|
-
* @param uid
|
|
696
|
-
*/
|
|
697
|
-
checkCollectionUpdateCondition(model, collection, conditionField, condition, index) {
|
|
698
|
-
// No index so addition to collection
|
|
699
|
-
if (index === null) {
|
|
700
|
-
// The condition must be length of the collection
|
|
701
|
-
if (!model[collection] || model[collection].length !== condition) {
|
|
702
|
-
throw new UpdateConditionFailError(model.getUuid(), collection, condition);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
else if (condition && model[collection][index][conditionField] !== condition) {
|
|
706
|
-
throw new UpdateConditionFailError(model.getUuid(), `${collection}[${index}].${conditionField}`, condition);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Update conditionally
|
|
711
|
-
* @param uuid
|
|
712
|
-
* @param updates
|
|
713
|
-
* @param conditionField
|
|
714
|
-
* @param condition
|
|
715
|
-
*/
|
|
716
|
-
async conditionalPatch(uuid, updates, conditionField, condition) {
|
|
717
|
-
try {
|
|
718
|
-
await this._patch(updates, uuid, condition, conditionField);
|
|
719
|
-
// CoreModel should also emit this one but cannot do within this context
|
|
720
|
-
await this.emitStoreEvent("Store.PartialUpdated", {
|
|
721
|
-
object_id: uuid,
|
|
722
|
-
partial_update: {
|
|
723
|
-
patch: updates
|
|
724
|
-
},
|
|
725
|
-
store: this
|
|
726
|
-
});
|
|
727
|
-
return true;
|
|
728
|
-
}
|
|
729
|
-
catch (err) {
|
|
730
|
-
if (err instanceof UpdateConditionFailError) {
|
|
731
|
-
return false;
|
|
732
|
-
}
|
|
733
|
-
throw err;
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
*
|
|
738
|
-
* @param model
|
|
739
|
-
* @param prop
|
|
740
|
-
* @param item
|
|
741
|
-
* @param index
|
|
742
|
-
* @param itemWriteCondition
|
|
743
|
-
* @param itemWriteConditionField
|
|
744
|
-
* @param updateDate
|
|
745
|
-
*/
|
|
746
|
-
async simulateUpsertItemToCollection(model, prop, item, updateDate, index, itemWriteCondition, itemWriteConditionField) {
|
|
747
|
-
if (prop === "__proto__") {
|
|
748
|
-
throw new Error("Cannot update __proto__: js/prototype-polluting-assignment");
|
|
749
|
-
}
|
|
750
|
-
this.checkCollectionUpdateCondition(model, prop, itemWriteConditionField, itemWriteCondition, index);
|
|
751
|
-
if (index === undefined) {
|
|
752
|
-
if (model[prop] === undefined) {
|
|
753
|
-
model[prop] = [item];
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
model[prop].push(item);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
else {
|
|
760
|
-
model[prop][index] = item;
|
|
761
|
-
}
|
|
762
|
-
model._lastUpdate = updateDate;
|
|
763
|
-
await this._save(model);
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Update an object
|
|
767
|
-
*
|
|
768
|
-
* If no attribute can be updated then return undefined
|
|
769
|
-
*
|
|
770
|
-
* @param {Object} Object to save
|
|
771
|
-
* @param {Boolean} reverseMap internal use only, for disable map resolution
|
|
772
|
-
* @return {Promise} with saved object
|
|
773
|
-
*/
|
|
774
|
-
async update(object, reverseMap = true, partial = false, conditionField, conditionValue) {
|
|
775
|
-
// Dont allow to update collections from map
|
|
776
|
-
if (this._reverseMap != undefined && reverseMap) {
|
|
777
|
-
for (const i in this._reverseMap) {
|
|
778
|
-
if (object[this._reverseMap[i].property] != undefined) {
|
|
779
|
-
delete object[this._reverseMap[i].property];
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (Object.keys(object).length < 2) {
|
|
784
|
-
return undefined;
|
|
785
|
-
}
|
|
786
|
-
object._lastUpdate = new Date();
|
|
787
|
-
this.metrics.operations_total.inc({ operation: "get" });
|
|
788
|
-
const uuid = object.getUuid ? object.getUuid() : object[this._uuidField];
|
|
789
|
-
const load = await this._getFromCache(uuid, true);
|
|
790
|
-
if (load.__type !== this._modelType && this.parameters.strict) {
|
|
791
|
-
this.log("WARN", `Object '${uuid}' was not created by this store ${load.__type}:${this._modelType}`);
|
|
792
|
-
throw new StoreNotFoundError(uuid, this.getName());
|
|
793
|
-
}
|
|
794
|
-
const loaded = this.initModel(load);
|
|
795
|
-
if (object instanceof CoreModel) {
|
|
796
|
-
loaded.setContext(object.getContext());
|
|
797
|
-
}
|
|
798
|
-
const update = object;
|
|
799
|
-
const evt = {
|
|
800
|
-
object: loaded,
|
|
801
|
-
object_id: loaded.getUuid(),
|
|
802
|
-
store: this,
|
|
803
|
-
update
|
|
804
|
-
};
|
|
805
|
-
await Promise.all([
|
|
806
|
-
this.emitSync(partial ? `Store.PatchUpdate` : `Store.Update`, evt),
|
|
807
|
-
object?.__class?.emitSync(partial ? `Store.PatchUpdate` : `Store.Update`, evt),
|
|
808
|
-
loaded._onUpdate(object)
|
|
809
|
-
]);
|
|
810
|
-
let res;
|
|
811
|
-
if (conditionField !== null) {
|
|
812
|
-
conditionField ?? (conditionField = "_lastUpdate");
|
|
813
|
-
conditionValue ?? (conditionValue = load[conditionField]);
|
|
814
|
-
}
|
|
815
|
-
if (partial) {
|
|
816
|
-
this.metrics.operations_total.inc({ operation: "partialUpdate" });
|
|
817
|
-
await this._patch(object, uuid, conditionValue, conditionField);
|
|
818
|
-
res = object;
|
|
819
|
-
}
|
|
820
|
-
else {
|
|
821
|
-
// Copy back the mappers
|
|
822
|
-
for (const i in this._reverseMap) {
|
|
823
|
-
object[this._reverseMap[i].property] = loaded[this._reverseMap[i].property];
|
|
824
|
-
}
|
|
825
|
-
object = this.initModel(object);
|
|
826
|
-
this.metrics.operations_total.inc({ operation: "update" });
|
|
827
|
-
res = await this._update(object, uuid, conditionValue, conditionField);
|
|
828
|
-
}
|
|
829
|
-
// Reinit save
|
|
830
|
-
const saved = this.initModel({
|
|
831
|
-
...loaded,
|
|
832
|
-
...res
|
|
833
|
-
});
|
|
834
|
-
const evtUpdated = {
|
|
835
|
-
object: saved,
|
|
836
|
-
object_id: saved.getUuid(),
|
|
837
|
-
store: this,
|
|
838
|
-
update,
|
|
839
|
-
previous: loaded
|
|
840
|
-
};
|
|
841
|
-
await Promise.all([
|
|
842
|
-
this.emitStoreEvent(partial ? `Store.PatchUpdated` : `Store.Updated`, evtUpdated),
|
|
843
|
-
saved?.__class.emitSync(partial ? `Store.PatchUpdated` : `Store.Updated`, evtUpdated),
|
|
844
|
-
saved._onUpdated()
|
|
845
|
-
]);
|
|
846
|
-
return saved;
|
|
847
|
-
}
|
|
848
|
-
/**
|
|
849
|
-
*
|
|
850
|
-
*/
|
|
851
|
-
async recomputeTypeShortId() {
|
|
852
|
-
this.log("INFO", "Ensuring __type is using its short id form");
|
|
853
|
-
const app = this.getWebda().getApplication();
|
|
854
|
-
// We need to be laxist for migration
|
|
855
|
-
this.parameters.strict = false;
|
|
856
|
-
await this.migration("typesShortId", async (item) => {
|
|
857
|
-
if (item.__type !== undefined && item.__type.includes("/")) {
|
|
858
|
-
const model = app.getWebdaObject("models", item.__type);
|
|
859
|
-
const name = app.getShortId(app.getModelName(model));
|
|
860
|
-
if (name !== item.__type) {
|
|
861
|
-
this.log("INFO", "Migrating type " + item.__type + " to " + name);
|
|
862
|
-
return {
|
|
863
|
-
__type: name
|
|
864
|
-
};
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
* Ensure model aliases are not used in this store
|
|
871
|
-
*
|
|
872
|
-
* So alias can be cleaned
|
|
873
|
-
*/
|
|
874
|
-
async cleanModelAliases() {
|
|
875
|
-
this.log("INFO", "Ensuring __type is not using any aliases");
|
|
876
|
-
// We need to be laxist for migration
|
|
877
|
-
this.parameters.strict = false;
|
|
878
|
-
await this.migration("cleanAliases", async (item) => {
|
|
879
|
-
if (this.parameters.modelAliases[item.__type]) {
|
|
880
|
-
this.log("INFO", "Migrating type " + item.__type + " to " + this.parameters.modelAliases[item.__type]);
|
|
881
|
-
return {
|
|
882
|
-
__type: this.parameters.modelAliases[item.__type]
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Recompute the __types for all objects (storeMigration.Registry.typesCompute)
|
|
889
|
-
*/
|
|
890
|
-
async recomputeTypes() {
|
|
891
|
-
this.log("INFO", "Ensuring __types is correct from migration from v2.x");
|
|
892
|
-
// Update __types for each __type will be more efficient
|
|
893
|
-
await this.migration("typesCompute", async (item) => {
|
|
894
|
-
const __types = this.getWebda().getApplication().getModelTypes(item);
|
|
895
|
-
if (!item.__types ||
|
|
896
|
-
item.__types.length !== __types.length ||
|
|
897
|
-
!__types.every((element, index) => element === item.__types[index])) {
|
|
898
|
-
this.log("INFO", "Migrating types " + JSON.stringify(item.__types) + " to " + JSON.stringify(__types), "for", item.__type, item.getUuid());
|
|
899
|
-
return {
|
|
900
|
-
__types
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Delete a migration
|
|
907
|
-
* @param name
|
|
908
|
-
*/
|
|
909
|
-
async cancelMigration(name) {
|
|
910
|
-
await this.getWebda().getRegistry().delete(`storeMigration.${this.getName()}.${name}`);
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Get a migration
|
|
914
|
-
* @param name
|
|
915
|
-
*/
|
|
916
|
-
async getMigration(name) {
|
|
917
|
-
return await this.getWebda().getRegistry().get(`storeMigration.${this.getName()}.${name}`);
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Add a migration mechanism to store
|
|
921
|
-
* @param name
|
|
922
|
-
* @param patcher
|
|
923
|
-
*/
|
|
924
|
-
async migration(name, patcher, batchSize = 500) {
|
|
925
|
-
const status = await this.getWebda().getRegistry().get(`storeMigration.${this.getName()}.${name}`, undefined, {});
|
|
926
|
-
status.count ?? (status.count = 0);
|
|
927
|
-
status.updated ?? (status.updated = 0);
|
|
928
|
-
const worker = new Throttler(20);
|
|
929
|
-
do {
|
|
930
|
-
const res = await this.query(status.continuationToken ? `LIMIT ${batchSize} OFFSET "${status.continuationToken}"` : `LIMIT ${batchSize}`);
|
|
931
|
-
status.count += res.results.length;
|
|
932
|
-
for (const item of res.results) {
|
|
933
|
-
const updated = await patcher(item);
|
|
934
|
-
if (updated !== undefined) {
|
|
935
|
-
status.updated++;
|
|
936
|
-
if (typeof updated === "function") {
|
|
937
|
-
worker.queue(updated);
|
|
938
|
-
}
|
|
939
|
-
else {
|
|
940
|
-
worker.queue(async () => {
|
|
941
|
-
await item.patch(updated, null);
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
this.log("INFO", `storeMigration.${this.getName()}.${name}: Migrated ${status.count} items: ${status.updated} updated`);
|
|
947
|
-
status.continuationToken = res.continuationToken;
|
|
948
|
-
await worker.wait();
|
|
949
|
-
await status.save();
|
|
950
|
-
} while (status.continuationToken);
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Remove an attribute from an object
|
|
954
|
-
*
|
|
955
|
-
* @param uuid
|
|
956
|
-
* @param attribute
|
|
957
|
-
* @returns
|
|
958
|
-
*/
|
|
959
|
-
async removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField) {
|
|
960
|
-
this.metrics.operations_total.inc({ operation: "attributeDelete" });
|
|
961
|
-
await this._removeAttribute(uuid, attribute, itemWriteCondition, itemWriteConditionField);
|
|
962
|
-
await this.emitStoreEvent("Store.PartialUpdated", {
|
|
963
|
-
object_id: uuid,
|
|
964
|
-
partial_update: {
|
|
965
|
-
deleteAttribute: attribute
|
|
966
|
-
},
|
|
967
|
-
store: this
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Cascade delete a related object
|
|
972
|
-
*
|
|
973
|
-
* @param obj
|
|
974
|
-
* @param uuid
|
|
975
|
-
* @returns
|
|
976
|
-
*/
|
|
977
|
-
async cascadeDelete(obj, _uuid) {
|
|
978
|
-
// We dont need uuid but Binary store will need it
|
|
979
|
-
return this.delete(obj.getUuid());
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Delete an object
|
|
983
|
-
*
|
|
984
|
-
* @param {String} uuid to delete
|
|
985
|
-
* @return {Promise} the deletion promise
|
|
986
|
-
*/
|
|
987
|
-
async delete(uid, writeCondition, writeConditionField) {
|
|
988
|
-
/** @ignore */
|
|
989
|
-
let to_delete;
|
|
990
|
-
// Allow full object or just its uuid
|
|
991
|
-
if (typeof uid === "object") {
|
|
992
|
-
to_delete = uid;
|
|
993
|
-
}
|
|
994
|
-
else {
|
|
995
|
-
this.metrics.operations_total.inc({ operation: "get" });
|
|
996
|
-
to_delete = await this._getFromCache(uid);
|
|
997
|
-
if (to_delete === undefined) {
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
if (to_delete.__type !== this._modelType && this.parameters.strict) {
|
|
1001
|
-
this.log("WARN", `Object '${uid}' was not created by this store ${to_delete.__type}:${this._modelType}`);
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
to_delete = this.initModel(to_delete);
|
|
1005
|
-
}
|
|
1006
|
-
// Check condition as we have the object
|
|
1007
|
-
if (writeCondition) {
|
|
1008
|
-
if (to_delete[writeConditionField] !== writeCondition) {
|
|
1009
|
-
throw new UpdateConditionFailError(to_delete.getUuid(), writeConditionField, writeCondition);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
|
-
const evt = {
|
|
1013
|
-
object: to_delete,
|
|
1014
|
-
object_id: to_delete.getUuid(),
|
|
1015
|
-
store: this
|
|
1016
|
-
};
|
|
1017
|
-
// Send preevent
|
|
1018
|
-
await Promise.all([
|
|
1019
|
-
this.emitSync("Store.Delete", evt),
|
|
1020
|
-
to_delete?.__class.emitSync("Store.Delete", evt),
|
|
1021
|
-
to_delete._onDelete()
|
|
1022
|
-
]);
|
|
1023
|
-
this.metrics.operations_total.inc({ operation: "delete" });
|
|
1024
|
-
// Delete from the DB for real
|
|
1025
|
-
await this._delete(to_delete.getUuid(), writeCondition, writeConditionField);
|
|
1026
|
-
await this._cacheStore?._delete(to_delete.getUuid(), writeCondition, writeConditionField);
|
|
1027
|
-
// Send post event
|
|
1028
|
-
const evtDeleted = {
|
|
1029
|
-
object: to_delete,
|
|
1030
|
-
object_id: to_delete.getUuid(),
|
|
1031
|
-
store: this
|
|
1032
|
-
};
|
|
1033
|
-
await Promise.all([
|
|
1034
|
-
this.emitStoreEvent("Store.Deleted", evtDeleted),
|
|
1035
|
-
to_delete.__class.emitSync("Store.Deleted", evtDeleted),
|
|
1036
|
-
to_delete._onDeleted()
|
|
1037
|
-
]);
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* By default we cannot know if the store will trigger or not
|
|
1041
|
-
*
|
|
1042
|
-
* @param id
|
|
1043
|
-
* @param callback
|
|
1044
|
-
*/
|
|
1045
|
-
canTriggerConfiguration(_id, _callback) {
|
|
1046
|
-
return false;
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Provide a way to store configuration in store
|
|
1050
|
-
* @param {string} id
|
|
1051
|
-
* @returns {Promise<Map<string, any>>}
|
|
1052
|
-
*/
|
|
1053
|
-
async getConfiguration(id) {
|
|
1054
|
-
this.metrics.operations_total.inc({ operation: "get" });
|
|
1055
|
-
const object = await this._getFromCache(id);
|
|
1056
|
-
if (!object) {
|
|
1057
|
-
return undefined;
|
|
1058
|
-
}
|
|
1059
|
-
const result = {};
|
|
1060
|
-
for (const i in object) {
|
|
1061
|
-
if (i === this._uuidField || i === "_lastUpdate" || i.startsWith("_")) {
|
|
1062
|
-
continue;
|
|
1063
|
-
}
|
|
1064
|
-
result[i] = object[i];
|
|
1065
|
-
}
|
|
1066
|
-
return result;
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Upsert the uuid object
|
|
1070
|
-
* @param uuid
|
|
1071
|
-
* @param data
|
|
1072
|
-
*/
|
|
1073
|
-
async put(uuid, data) {
|
|
1074
|
-
if (await this.exists(uuid)) {
|
|
1075
|
-
return this.update({ ...data, uuid });
|
|
1076
|
-
}
|
|
1077
|
-
return this.save(data instanceof CoreModel ? data.setUuid(uuid) : { ...data, uuid });
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Get an object
|
|
1081
|
-
*
|
|
1082
|
-
* @param {String} uuid to get
|
|
1083
|
-
* @return {Promise} the object retrieved ( can be undefined if not found )
|
|
1084
|
-
*/
|
|
1085
|
-
async get(uid, ctx = undefined, defaultValue = undefined) {
|
|
1086
|
-
/** @ignore */
|
|
1087
|
-
if (!uid) {
|
|
1088
|
-
return undefined;
|
|
1089
|
-
}
|
|
1090
|
-
this.metrics.operations_total.inc({ operation: "get" });
|
|
1091
|
-
let object = await this._getFromCache(uid);
|
|
1092
|
-
if (!object) {
|
|
1093
|
-
return defaultValue ? this.initModel(defaultValue).setUuid(uid) : undefined;
|
|
1094
|
-
}
|
|
1095
|
-
if (object.__type !== this._modelType && this.parameters.strict) {
|
|
1096
|
-
this.log("WARN", `Object '${uid}' was not created by this store ${object.__type}:${this._modelType}`);
|
|
1097
|
-
return undefined;
|
|
1098
|
-
}
|
|
1099
|
-
object = this.initModel(object);
|
|
1100
|
-
object.setContext(ctx);
|
|
1101
|
-
const evt = {
|
|
1102
|
-
object: object,
|
|
1103
|
-
object_id: object.getUuid(),
|
|
1104
|
-
store: this,
|
|
1105
|
-
context: ctx
|
|
1106
|
-
};
|
|
1107
|
-
await Promise.all([this.emitSync("Store.Get", evt), object.__class.emitSync("Store.Get", evt), object._onGet()]);
|
|
1108
|
-
return object;
|
|
1109
|
-
}
|
|
1110
|
-
/**
|
|
1111
|
-
* Set one attribute in an object
|
|
1112
|
-
*
|
|
1113
|
-
* this is an helper function that calls patch
|
|
1114
|
-
*
|
|
1115
|
-
* @param uid of the object
|
|
1116
|
-
* @param property to update1
|
|
1117
|
-
* @param value new value
|
|
1118
|
-
* @returns
|
|
1119
|
-
*/
|
|
1120
|
-
async setAttribute(uid, property, value) {
|
|
1121
|
-
const patch = {};
|
|
1122
|
-
patch[property] = value;
|
|
1123
|
-
patch[this.getUuidField()] = uid;
|
|
1124
|
-
await this.patch(patch);
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* @override
|
|
1128
|
-
*/
|
|
1129
|
-
async simulateFind(query, uuids) {
|
|
1130
|
-
const result = {
|
|
1131
|
-
results: [],
|
|
1132
|
-
continuationToken: undefined,
|
|
1133
|
-
filter: true
|
|
1134
|
-
};
|
|
1135
|
-
let count = 0;
|
|
1136
|
-
let limit = query.limit;
|
|
1137
|
-
let offset = parseInt(query.continuationToken || "0");
|
|
1138
|
-
const originalOffset = offset;
|
|
1139
|
-
if (query.orderBy && query.orderBy.length) {
|
|
1140
|
-
offset = 0;
|
|
1141
|
-
// We need to retrieve everything to orderBy after
|
|
1142
|
-
limit = Number.MAX_SAFE_INTEGER;
|
|
1143
|
-
}
|
|
1144
|
-
// Need to transfert to Array
|
|
1145
|
-
for (const uuid of uuids) {
|
|
1146
|
-
count++;
|
|
1147
|
-
// Offset start
|
|
1148
|
-
if (offset >= count) {
|
|
1149
|
-
continue;
|
|
1150
|
-
}
|
|
1151
|
-
const obj = await this._getFromCache(uuid);
|
|
1152
|
-
if (obj && query.filter.eval(obj)) {
|
|
1153
|
-
result.results.push(obj);
|
|
1154
|
-
if (result.results.length >= limit) {
|
|
1155
|
-
result.continuationToken = count.toString();
|
|
1156
|
-
return result;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
// Order by
|
|
1161
|
-
if (query.orderBy && query.orderBy.length) {
|
|
1162
|
-
// Sorting the results
|
|
1163
|
-
result.results.sort((a, b) => {
|
|
1164
|
-
let valA, valB;
|
|
1165
|
-
for (const orderBy of query.orderBy) {
|
|
1166
|
-
const invert = orderBy.direction === "ASC" ? 1 : -1;
|
|
1167
|
-
valA = WebdaQL.ComparisonExpression.getAttributeValue(a, orderBy.field.split("."));
|
|
1168
|
-
valB = WebdaQL.ComparisonExpression.getAttributeValue(b, orderBy.field.split("."));
|
|
1169
|
-
if (valA === valB) {
|
|
1170
|
-
continue;
|
|
1171
|
-
}
|
|
1172
|
-
if (typeof valA === "string") {
|
|
1173
|
-
return valA.localeCompare(valB) * invert;
|
|
1174
|
-
}
|
|
1175
|
-
return (valA < valB ? -1 : 1) * invert;
|
|
1176
|
-
}
|
|
1177
|
-
return -1;
|
|
1178
|
-
});
|
|
1179
|
-
result.results = result.results.slice(originalOffset, query.limit + originalOffset);
|
|
1180
|
-
if (result.results.length >= query.limit) {
|
|
1181
|
-
result.continuationToken = (query.limit + originalOffset).toString();
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
return result;
|
|
1185
|
-
}
|
|
1186
|
-
getOpenApiReplacements() {
|
|
1187
|
-
return {
|
|
1188
|
-
modelName: this._model.name
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Return the model uuid field
|
|
1193
|
-
*/
|
|
1194
|
-
getUuidField() {
|
|
1195
|
-
return this._uuidField;
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Check if an object exists
|
|
1199
|
-
* @abstract
|
|
1200
|
-
* @params {String} uuid of the object or the object
|
|
1201
|
-
*/
|
|
1202
|
-
async exists(uid) {
|
|
1203
|
-
if (typeof uid !== "string") {
|
|
1204
|
-
uid = uid.getUuid();
|
|
1205
|
-
}
|
|
1206
|
-
return this._exists(uid);
|
|
345
|
+
checkKeys() {
|
|
346
|
+
// TODO Implement
|
|
1207
347
|
}
|
|
1208
348
|
}
|
|
1209
349
|
export { Store };
|