@hotmeshio/hotmesh 0.0.8 → 0.0.10
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/LICENSE +4 -7
- package/README.md +82 -85
- package/build/{cjs/modules → modules}/key.d.ts +2 -2
- package/build/{cjs/modules → modules}/key.js +3 -3
- package/build/{esm/package.json → package.json} +4 -11
- package/build/{cjs/services → services}/durable/native.js +2 -3
- package/build/{esm/services → services}/durable/worker.d.ts +1 -3
- package/build/{cjs/services → services}/durable/worker.js +9 -33
- package/build/{cjs/services → services}/durable/workflow.js +6 -1
- package/build/{cjs/services → services}/hotmesh/index.js +1 -1
- package/build/{cjs/services → services}/store/index.js +2 -2
- package/build/{cjs/services → services}/stream/clients/ioredis.js +1 -1
- package/build/{cjs/services → services}/stream/clients/redis.js +1 -1
- package/build/{cjs/services → services}/sub/clients/ioredis.js +1 -1
- package/build/{cjs/services → services}/sub/clients/redis.js +1 -1
- package/build/{cjs/types → types}/durable.d.ts +5 -7
- package/modules/key.ts +2 -2
- package/package.json +4 -11
- package/services/durable/native.ts +2 -3
- package/services/durable/worker.ts +9 -10
- package/services/durable/workflow.ts +7 -1
- package/services/hotmesh/index.ts +2 -2
- package/services/store/index.ts +3 -3
- package/services/stream/clients/ioredis.ts +2 -2
- package/services/stream/clients/redis.ts +2 -2
- package/services/sub/clients/ioredis.ts +2 -2
- package/services/sub/clients/redis.ts +2 -2
- package/types/durable.ts +5 -5
- package/build/cjs/package.json +0 -82
- package/build/cjs/services/durable/worker.d.ts +0 -38
- package/build/esm/index.d.ts +0 -4
- package/build/esm/index.js +0 -3
- package/build/esm/modules/errors.d.ts +0 -28
- package/build/esm/modules/errors.js +0 -41
- package/build/esm/modules/key.d.ts +0 -75
- package/build/esm/modules/key.js +0 -111
- package/build/esm/modules/utils.d.ts +0 -34
- package/build/esm/modules/utils.js +0 -154
- package/build/esm/services/activities/activity.d.ts +0 -67
- package/build/esm/services/activities/activity.js +0 -486
- package/build/esm/services/activities/await.d.ts +0 -16
- package/build/esm/services/activities/await.js +0 -140
- package/build/esm/services/activities/cycle.d.ts +0 -19
- package/build/esm/services/activities/cycle.js +0 -74
- package/build/esm/services/activities/emit.d.ts +0 -9
- package/build/esm/services/activities/emit.js +0 -10
- package/build/esm/services/activities/index.d.ts +0 -17
- package/build/esm/services/activities/index.js +0 -16
- package/build/esm/services/activities/iterate.d.ts +0 -9
- package/build/esm/services/activities/iterate.js +0 -10
- package/build/esm/services/activities/trigger.d.ts +0 -22
- package/build/esm/services/activities/trigger.js +0 -158
- package/build/esm/services/activities/worker.d.ts +0 -11
- package/build/esm/services/activities/worker.js +0 -70
- package/build/esm/services/collator/index.d.ts +0 -73
- package/build/esm/services/collator/index.js +0 -221
- package/build/esm/services/compiler/deployer.d.ts +0 -36
- package/build/esm/services/compiler/deployer.js +0 -423
- package/build/esm/services/compiler/index.d.ts +0 -30
- package/build/esm/services/compiler/index.js +0 -82
- package/build/esm/services/compiler/validator.d.ts +0 -32
- package/build/esm/services/compiler/validator.js +0 -131
- package/build/esm/services/connector/clients/ioredis.d.ts +0 -13
- package/build/esm/services/connector/clients/ioredis.js +0 -47
- package/build/esm/services/connector/clients/redis.d.ts +0 -13
- package/build/esm/services/connector/clients/redis.js +0 -59
- package/build/esm/services/connector/index.d.ts +0 -5
- package/build/esm/services/connector/index.js +0 -27
- package/build/esm/services/dimension/index.d.ts +0 -29
- package/build/esm/services/dimension/index.js +0 -32
- package/build/esm/services/durable/asyncLocalStorage.d.ts +0 -3
- package/build/esm/services/durable/asyncLocalStorage.js +0 -2
- package/build/esm/services/durable/client.d.ts +0 -15
- package/build/esm/services/durable/client.js +0 -114
- package/build/esm/services/durable/connection.d.ts +0 -4
- package/build/esm/services/durable/connection.js +0 -47
- package/build/esm/services/durable/factory.d.ts +0 -3
- package/build/esm/services/durable/factory.js +0 -135
- package/build/esm/services/durable/handle.d.ts +0 -8
- package/build/esm/services/durable/handle.js +0 -34
- package/build/esm/services/durable/index.d.ts +0 -57
- package/build/esm/services/durable/index.js +0 -55
- package/build/esm/services/durable/native.d.ts +0 -4
- package/build/esm/services/durable/native.js +0 -43
- package/build/esm/services/durable/worker.js +0 -267
- package/build/esm/services/durable/workflow.d.ts +0 -6
- package/build/esm/services/durable/workflow.js +0 -132
- package/build/esm/services/engine/index.d.ts +0 -82
- package/build/esm/services/engine/index.js +0 -522
- package/build/esm/services/hotmesh/index.d.ts +0 -45
- package/build/esm/services/hotmesh/index.js +0 -131
- package/build/esm/services/logger/index.d.ts +0 -17
- package/build/esm/services/logger/index.js +0 -70
- package/build/esm/services/mapper/index.d.ts +0 -24
- package/build/esm/services/mapper/index.js +0 -72
- package/build/esm/services/pipe/functions/array.d.ts +0 -24
- package/build/esm/services/pipe/functions/array.js +0 -66
- package/build/esm/services/pipe/functions/bitwise.d.ts +0 -9
- package/build/esm/services/pipe/functions/bitwise.js +0 -21
- package/build/esm/services/pipe/functions/conditional.d.ts +0 -10
- package/build/esm/services/pipe/functions/conditional.js +0 -24
- package/build/esm/services/pipe/functions/date.d.ts +0 -57
- package/build/esm/services/pipe/functions/date.js +0 -164
- package/build/esm/services/pipe/functions/index.d.ts +0 -25
- package/build/esm/services/pipe/functions/index.js +0 -24
- package/build/esm/services/pipe/functions/json.d.ts +0 -5
- package/build/esm/services/pipe/functions/json.js +0 -9
- package/build/esm/services/pipe/functions/math.d.ts +0 -38
- package/build/esm/services/pipe/functions/math.js +0 -108
- package/build/esm/services/pipe/functions/number.d.ts +0 -25
- package/build/esm/services/pipe/functions/number.js +0 -130
- package/build/esm/services/pipe/functions/object.d.ts +0 -22
- package/build/esm/services/pipe/functions/object.js +0 -60
- package/build/esm/services/pipe/functions/string.d.ts +0 -23
- package/build/esm/services/pipe/functions/string.js +0 -66
- package/build/esm/services/pipe/functions/symbol.d.ts +0 -12
- package/build/esm/services/pipe/functions/symbol.js +0 -30
- package/build/esm/services/pipe/functions/unary.d.ts +0 -7
- package/build/esm/services/pipe/functions/unary.js +0 -15
- package/build/esm/services/pipe/index.d.ts +0 -30
- package/build/esm/services/pipe/index.js +0 -122
- package/build/esm/services/quorum/index.d.ts +0 -34
- package/build/esm/services/quorum/index.js +0 -144
- package/build/esm/services/reporter/index.d.ts +0 -47
- package/build/esm/services/reporter/index.js +0 -327
- package/build/esm/services/serializer/index.d.ts +0 -41
- package/build/esm/services/serializer/index.js +0 -251
- package/build/esm/services/signaler/store.d.ts +0 -15
- package/build/esm/services/signaler/store.js +0 -50
- package/build/esm/services/signaler/stream.d.ts +0 -43
- package/build/esm/services/signaler/stream.js +0 -314
- package/build/esm/services/store/cache.d.ts +0 -66
- package/build/esm/services/store/cache.js +0 -124
- package/build/esm/services/store/clients/ioredis.d.ts +0 -27
- package/build/esm/services/store/clients/ioredis.js +0 -93
- package/build/esm/services/store/clients/redis.d.ts +0 -29
- package/build/esm/services/store/clients/redis.js +0 -140
- package/build/esm/services/store/index.d.ts +0 -88
- package/build/esm/services/store/index.js +0 -623
- package/build/esm/services/stream/clients/ioredis.d.ts +0 -23
- package/build/esm/services/stream/clients/ioredis.js +0 -112
- package/build/esm/services/stream/clients/redis.d.ts +0 -23
- package/build/esm/services/stream/clients/redis.js +0 -116
- package/build/esm/services/stream/index.d.ts +0 -21
- package/build/esm/services/stream/index.js +0 -6
- package/build/esm/services/sub/clients/ioredis.d.ts +0 -20
- package/build/esm/services/sub/clients/ioredis.js +0 -69
- package/build/esm/services/sub/clients/redis.d.ts +0 -20
- package/build/esm/services/sub/clients/redis.js +0 -60
- package/build/esm/services/sub/index.d.ts +0 -18
- package/build/esm/services/sub/index.js +0 -6
- package/build/esm/services/task/index.d.ts +0 -18
- package/build/esm/services/task/index.js +0 -70
- package/build/esm/services/telemetry/index.d.ts +0 -49
- package/build/esm/services/telemetry/index.js +0 -217
- package/build/esm/services/worker/index.d.ts +0 -30
- package/build/esm/services/worker/index.js +0 -102
- package/build/esm/types/activity.d.ts +0 -92
- package/build/esm/types/activity.js +0 -1
- package/build/esm/types/app.d.ts +0 -16
- package/build/esm/types/app.js +0 -1
- package/build/esm/types/async.d.ts +0 -5
- package/build/esm/types/async.js +0 -1
- package/build/esm/types/cache.d.ts +0 -1
- package/build/esm/types/cache.js +0 -1
- package/build/esm/types/collator.d.ts +0 -8
- package/build/esm/types/collator.js +0 -8
- package/build/esm/types/durable.d.ts +0 -59
- package/build/esm/types/durable.js +0 -1
- package/build/esm/types/hook.d.ts +0 -31
- package/build/esm/types/hook.js +0 -6
- package/build/esm/types/hotmesh.d.ts +0 -82
- package/build/esm/types/hotmesh.js +0 -1
- package/build/esm/types/index.d.ts +0 -20
- package/build/esm/types/index.js +0 -5
- package/build/esm/types/ioredisclient.d.ts +0 -5
- package/build/esm/types/ioredisclient.js +0 -2
- package/build/esm/types/job.d.ts +0 -50
- package/build/esm/types/job.js +0 -1
- package/build/esm/types/logger.d.ts +0 -6
- package/build/esm/types/logger.js +0 -1
- package/build/esm/types/map.d.ts +0 -4
- package/build/esm/types/map.js +0 -1
- package/build/esm/types/pipe.d.ts +0 -4
- package/build/esm/types/pipe.js +0 -1
- package/build/esm/types/quorum.d.ts +0 -46
- package/build/esm/types/quorum.js +0 -1
- package/build/esm/types/redis.d.ts +0 -8
- package/build/esm/types/redis.js +0 -1
- package/build/esm/types/redisclient.d.ts +0 -25
- package/build/esm/types/redisclient.js +0 -1
- package/build/esm/types/serializer.d.ts +0 -33
- package/build/esm/types/serializer.js +0 -1
- package/build/esm/types/stats.d.ts +0 -83
- package/build/esm/types/stats.js +0 -1
- package/build/esm/types/stream.d.ts +0 -67
- package/build/esm/types/stream.js +0 -22
- package/build/esm/types/telemetry.d.ts +0 -1
- package/build/esm/types/telemetry.js +0 -1
- package/build/esm/types/transition.d.ts +0 -17
- package/build/esm/types/transition.js +0 -1
- package/tsconfig.cjs.json +0 -8
- package/tsconfig.esm.json +0 -9
- /package/build/{cjs/index.d.ts → index.d.ts} +0 -0
- /package/build/{cjs/index.js → index.js} +0 -0
- /package/build/{cjs/modules → modules}/errors.d.ts +0 -0
- /package/build/{cjs/modules → modules}/errors.js +0 -0
- /package/build/{cjs/modules → modules}/utils.d.ts +0 -0
- /package/build/{cjs/modules → modules}/utils.js +0 -0
- /package/build/{cjs/services → services}/activities/activity.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/activity.js +0 -0
- /package/build/{cjs/services → services}/activities/await.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/await.js +0 -0
- /package/build/{cjs/services → services}/activities/cycle.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/cycle.js +0 -0
- /package/build/{cjs/services → services}/activities/emit.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/emit.js +0 -0
- /package/build/{cjs/services → services}/activities/index.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/index.js +0 -0
- /package/build/{cjs/services → services}/activities/iterate.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/iterate.js +0 -0
- /package/build/{cjs/services → services}/activities/trigger.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/trigger.js +0 -0
- /package/build/{cjs/services → services}/activities/worker.d.ts +0 -0
- /package/build/{cjs/services → services}/activities/worker.js +0 -0
- /package/build/{cjs/services → services}/collator/index.d.ts +0 -0
- /package/build/{cjs/services → services}/collator/index.js +0 -0
- /package/build/{cjs/services → services}/compiler/deployer.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/deployer.js +0 -0
- /package/build/{cjs/services → services}/compiler/index.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/index.js +0 -0
- /package/build/{cjs/services → services}/compiler/validator.d.ts +0 -0
- /package/build/{cjs/services → services}/compiler/validator.js +0 -0
- /package/build/{cjs/services → services}/connector/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/connector/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/connector/index.d.ts +0 -0
- /package/build/{cjs/services → services}/connector/index.js +0 -0
- /package/build/{cjs/services → services}/dimension/index.d.ts +0 -0
- /package/build/{cjs/services → services}/dimension/index.js +0 -0
- /package/build/{cjs/services → services}/durable/asyncLocalStorage.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/asyncLocalStorage.js +0 -0
- /package/build/{cjs/services → services}/durable/client.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/client.js +0 -0
- /package/build/{cjs/services → services}/durable/connection.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/connection.js +0 -0
- /package/build/{cjs/services → services}/durable/factory.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/factory.js +0 -0
- /package/build/{cjs/services → services}/durable/handle.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/handle.js +0 -0
- /package/build/{cjs/services → services}/durable/index.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/index.js +0 -0
- /package/build/{cjs/services → services}/durable/native.d.ts +0 -0
- /package/build/{cjs/services → services}/durable/workflow.d.ts +0 -0
- /package/build/{cjs/services → services}/engine/index.d.ts +0 -0
- /package/build/{cjs/services → services}/engine/index.js +0 -0
- /package/build/{cjs/services → services}/hotmesh/index.d.ts +0 -0
- /package/build/{cjs/services → services}/logger/index.d.ts +0 -0
- /package/build/{cjs/services → services}/logger/index.js +0 -0
- /package/build/{cjs/services → services}/mapper/index.d.ts +0 -0
- /package/build/{cjs/services → services}/mapper/index.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/array.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/array.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/bitwise.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/bitwise.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/conditional.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/conditional.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/date.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/date.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/index.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/index.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/json.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/json.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/math.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/math.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/number.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/number.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/object.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/object.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/string.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/string.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/symbol.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/symbol.js +0 -0
- /package/build/{cjs/services → services}/pipe/functions/unary.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/functions/unary.js +0 -0
- /package/build/{cjs/services → services}/pipe/index.d.ts +0 -0
- /package/build/{cjs/services → services}/pipe/index.js +0 -0
- /package/build/{cjs/services → services}/quorum/index.d.ts +0 -0
- /package/build/{cjs/services → services}/quorum/index.js +0 -0
- /package/build/{cjs/services → services}/reporter/index.d.ts +0 -0
- /package/build/{cjs/services → services}/reporter/index.js +0 -0
- /package/build/{cjs/services → services}/serializer/index.d.ts +0 -0
- /package/build/{cjs/services → services}/serializer/index.js +0 -0
- /package/build/{cjs/services → services}/signaler/store.d.ts +0 -0
- /package/build/{cjs/services → services}/signaler/store.js +0 -0
- /package/build/{cjs/services → services}/signaler/stream.d.ts +0 -0
- /package/build/{cjs/services → services}/signaler/stream.js +0 -0
- /package/build/{cjs/services → services}/store/cache.d.ts +0 -0
- /package/build/{cjs/services → services}/store/cache.js +0 -0
- /package/build/{cjs/services → services}/store/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/store/clients/ioredis.js +0 -0
- /package/build/{cjs/services → services}/store/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/store/clients/redis.js +0 -0
- /package/build/{cjs/services → services}/store/index.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/index.d.ts +0 -0
- /package/build/{cjs/services → services}/stream/index.js +0 -0
- /package/build/{cjs/services → services}/sub/clients/ioredis.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/clients/redis.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/index.d.ts +0 -0
- /package/build/{cjs/services → services}/sub/index.js +0 -0
- /package/build/{cjs/services → services}/task/index.d.ts +0 -0
- /package/build/{cjs/services → services}/task/index.js +0 -0
- /package/build/{cjs/services → services}/telemetry/index.d.ts +0 -0
- /package/build/{cjs/services → services}/telemetry/index.js +0 -0
- /package/build/{cjs/services → services}/worker/index.d.ts +0 -0
- /package/build/{cjs/services → services}/worker/index.js +0 -0
- /package/build/{cjs/types → types}/activity.d.ts +0 -0
- /package/build/{cjs/types → types}/activity.js +0 -0
- /package/build/{cjs/types → types}/app.d.ts +0 -0
- /package/build/{cjs/types → types}/app.js +0 -0
- /package/build/{cjs/types → types}/async.d.ts +0 -0
- /package/build/{cjs/types → types}/async.js +0 -0
- /package/build/{cjs/types → types}/cache.d.ts +0 -0
- /package/build/{cjs/types → types}/cache.js +0 -0
- /package/build/{cjs/types → types}/collator.d.ts +0 -0
- /package/build/{cjs/types → types}/collator.js +0 -0
- /package/build/{cjs/types → types}/durable.js +0 -0
- /package/build/{cjs/types → types}/hook.d.ts +0 -0
- /package/build/{cjs/types → types}/hook.js +0 -0
- /package/build/{cjs/types → types}/hotmesh.d.ts +0 -0
- /package/build/{cjs/types → types}/hotmesh.js +0 -0
- /package/build/{cjs/types → types}/index.d.ts +0 -0
- /package/build/{cjs/types → types}/index.js +0 -0
- /package/build/{cjs/types → types}/ioredisclient.d.ts +0 -0
- /package/build/{cjs/types → types}/ioredisclient.js +0 -0
- /package/build/{cjs/types → types}/job.d.ts +0 -0
- /package/build/{cjs/types → types}/job.js +0 -0
- /package/build/{cjs/types → types}/logger.d.ts +0 -0
- /package/build/{cjs/types → types}/logger.js +0 -0
- /package/build/{cjs/types → types}/map.d.ts +0 -0
- /package/build/{cjs/types → types}/map.js +0 -0
- /package/build/{cjs/types → types}/pipe.d.ts +0 -0
- /package/build/{cjs/types → types}/pipe.js +0 -0
- /package/build/{cjs/types → types}/quorum.d.ts +0 -0
- /package/build/{cjs/types → types}/quorum.js +0 -0
- /package/build/{cjs/types → types}/redis.d.ts +0 -0
- /package/build/{cjs/types → types}/redis.js +0 -0
- /package/build/{cjs/types → types}/redisclient.d.ts +0 -0
- /package/build/{cjs/types → types}/redisclient.js +0 -0
- /package/build/{cjs/types → types}/serializer.d.ts +0 -0
- /package/build/{cjs/types → types}/serializer.js +0 -0
- /package/build/{cjs/types → types}/stats.d.ts +0 -0
- /package/build/{cjs/types → types}/stats.js +0 -0
- /package/build/{cjs/types → types}/stream.d.ts +0 -0
- /package/build/{cjs/types → types}/stream.js +0 -0
- /package/build/{cjs/types → types}/telemetry.d.ts +0 -0
- /package/build/{cjs/types → types}/telemetry.js +0 -0
- /package/build/{cjs/types → types}/transition.d.ts +0 -0
- /package/build/{cjs/types → types}/transition.js +0 -0
|
@@ -1,623 +0,0 @@
|
|
|
1
|
-
import { KeyService, KeyType, PSNS } from '../../modules/key';
|
|
2
|
-
import { MDATA_SYMBOLS, SerializerService as Serializer } from '../serializer';
|
|
3
|
-
import { Cache } from './cache';
|
|
4
|
-
import { formatISODate, getSymKey } from '../../modules/utils';
|
|
5
|
-
class StoreService {
|
|
6
|
-
constructor(redisClient) {
|
|
7
|
-
this.commands = {
|
|
8
|
-
setnx: 'setnx',
|
|
9
|
-
del: 'del',
|
|
10
|
-
expire: 'expire',
|
|
11
|
-
hset: 'hset',
|
|
12
|
-
hsetnx: 'hsetnx',
|
|
13
|
-
hincrby: 'hincrby',
|
|
14
|
-
hdel: 'hdel',
|
|
15
|
-
hget: 'hget',
|
|
16
|
-
hmget: 'hmget',
|
|
17
|
-
hgetall: 'hgetall',
|
|
18
|
-
hincrbyfloat: 'hincrbyfloat',
|
|
19
|
-
zrange: 'zrange',
|
|
20
|
-
zrangebyscore_withscores: 'zrangebyscore',
|
|
21
|
-
zrangebyscore: 'zrangebyscore',
|
|
22
|
-
zrem: 'zrem',
|
|
23
|
-
zadd: 'zadd',
|
|
24
|
-
lmove: 'lmove',
|
|
25
|
-
llen: 'llen',
|
|
26
|
-
lpop: 'lpop',
|
|
27
|
-
lrange: 'lrange',
|
|
28
|
-
rename: 'rename',
|
|
29
|
-
rpush: 'rpush',
|
|
30
|
-
xack: 'xack',
|
|
31
|
-
xdel: 'xdel',
|
|
32
|
-
};
|
|
33
|
-
this.redisClient = redisClient;
|
|
34
|
-
}
|
|
35
|
-
async init(namespace = PSNS, appId, logger) {
|
|
36
|
-
this.namespace = namespace;
|
|
37
|
-
this.appId = appId;
|
|
38
|
-
this.logger = logger;
|
|
39
|
-
const settings = await this.getSettings(true);
|
|
40
|
-
this.cache = new Cache(appId, settings);
|
|
41
|
-
this.serializer = new Serializer();
|
|
42
|
-
await this.getApp(appId);
|
|
43
|
-
return this.cache.getApps();
|
|
44
|
-
}
|
|
45
|
-
isSuccessful(result) {
|
|
46
|
-
return result > 0 || result === 'OK' || result === true;
|
|
47
|
-
}
|
|
48
|
-
async zAdd(key, score, value, redisMulti) {
|
|
49
|
-
//default call signature uses 'ioredis' NPM Package format
|
|
50
|
-
return await (redisMulti || this.redisClient)[this.commands.zadd](key, score, value);
|
|
51
|
-
}
|
|
52
|
-
async zRangeByScoreWithScores(key, score, value) {
|
|
53
|
-
const result = await this.redisClient[this.commands.zrangebyscore_withscores](key, score, value, 'WITHSCORES');
|
|
54
|
-
if (result?.length > 0) {
|
|
55
|
-
return result[0];
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
async zRangeByScore(key, score, value) {
|
|
60
|
-
const result = await this.redisClient[this.commands.zrangebyscore](key, score, value);
|
|
61
|
-
if (result?.length > 0) {
|
|
62
|
-
return result[0];
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
mintKey(type, params) {
|
|
67
|
-
if (!this.namespace)
|
|
68
|
-
throw new Error('namespace not set');
|
|
69
|
-
return KeyService.mintKey(this.namespace, type, params);
|
|
70
|
-
}
|
|
71
|
-
invalidateCache() {
|
|
72
|
-
this.cache.invalidate();
|
|
73
|
-
}
|
|
74
|
-
async reserveEngineId(engineId) {
|
|
75
|
-
const key = this.mintKey(KeyType.ENGINE_ID, { engineId });
|
|
76
|
-
const success = await this.redisClient[this.commands.setnx](key, 'id', 1);
|
|
77
|
-
return this.isSuccessful(success);
|
|
78
|
-
}
|
|
79
|
-
async getSettings(bCreate = false) {
|
|
80
|
-
let settings = this.cache?.getSettings();
|
|
81
|
-
if (settings) {
|
|
82
|
-
return settings;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
if (bCreate) {
|
|
86
|
-
const packageJson = await import('../../package.json');
|
|
87
|
-
const version = packageJson['version'] || '0.0.0';
|
|
88
|
-
settings = { namespace: PSNS, version };
|
|
89
|
-
await this.setSettings(settings);
|
|
90
|
-
return settings;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
throw new Error('settings not found');
|
|
94
|
-
}
|
|
95
|
-
async setSettings(manifest) {
|
|
96
|
-
//HotMesh heartbeat. If a connection is made, the version will be set
|
|
97
|
-
const params = {};
|
|
98
|
-
const key = this.mintKey(KeyType.HOTMESH, params);
|
|
99
|
-
return await this.redisClient[this.commands.hset](key, manifest);
|
|
100
|
-
}
|
|
101
|
-
async reserveSymbolRange(target, size, type) {
|
|
102
|
-
const rangeKey = this.mintKey(KeyType.SYMKEYS, { appId: this.appId });
|
|
103
|
-
const symbolKey = this.mintKey(KeyType.SYMKEYS, { activityId: target, appId: this.appId });
|
|
104
|
-
//reserve the slot in a `pending` state (range will be established in the next step)
|
|
105
|
-
const response = await this.redisClient[this.commands.hsetnx](rangeKey, target, '?:?');
|
|
106
|
-
if (response) {
|
|
107
|
-
//if the key didn't exist, set the inclusive range and seed metadata fields
|
|
108
|
-
const upperLimit = await this.redisClient[this.commands.hincrby](rangeKey, ':cursor', size);
|
|
109
|
-
const lowerLimit = upperLimit - size;
|
|
110
|
-
const inclusiveRange = `${lowerLimit}:${upperLimit - 1}`;
|
|
111
|
-
await this.redisClient[this.commands.hset](rangeKey, target, inclusiveRange);
|
|
112
|
-
const metadataSeeds = this.seedSymbols(target, type, lowerLimit);
|
|
113
|
-
await this.redisClient[this.commands.hset](symbolKey, metadataSeeds);
|
|
114
|
-
return [lowerLimit + MDATA_SYMBOLS.SLOTS, upperLimit - 1, {}];
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
//if the key already existed, get the lower limit and add the number of symbols
|
|
118
|
-
const range = await this.redisClient[this.commands.hget](rangeKey, target);
|
|
119
|
-
const [lowerLimitString] = range.split(':');
|
|
120
|
-
const lowerLimit = parseInt(lowerLimitString, 10);
|
|
121
|
-
const symbols = await this.redisClient[this.commands.hgetall](symbolKey);
|
|
122
|
-
const symbolCount = Object.keys(symbols).length;
|
|
123
|
-
const actualLowerLimit = lowerLimit + MDATA_SYMBOLS.SLOTS + symbolCount;
|
|
124
|
-
const upperLimit = Number(lowerLimit + size - 1);
|
|
125
|
-
return [actualLowerLimit, upperLimit, symbols];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async getSymbols(activityId) {
|
|
129
|
-
let symbols = this.cache.getSymbols(this.appId, activityId);
|
|
130
|
-
if (symbols) {
|
|
131
|
-
return symbols;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const params = { activityId, appId: this.appId };
|
|
135
|
-
const key = this.mintKey(KeyType.SYMKEYS, params);
|
|
136
|
-
symbols = (await this.redisClient[this.commands.hgetall](key));
|
|
137
|
-
this.cache.setSymbols(this.appId, activityId, symbols);
|
|
138
|
-
return symbols;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async addSymbols(activityId, symbols) {
|
|
142
|
-
if (!symbols || !Object.keys(symbols).length)
|
|
143
|
-
return false;
|
|
144
|
-
const params = { activityId, appId: this.appId };
|
|
145
|
-
const key = this.mintKey(KeyType.SYMKEYS, params);
|
|
146
|
-
const success = await this.redisClient[this.commands.hset](key, symbols);
|
|
147
|
-
this.cache.deleteSymbols(this.appId, activityId);
|
|
148
|
-
return success > 0;
|
|
149
|
-
}
|
|
150
|
-
seedSymbols(target, type, startIndex) {
|
|
151
|
-
if (type === 'JOB') {
|
|
152
|
-
return this.seedJobSymbols(startIndex);
|
|
153
|
-
}
|
|
154
|
-
return this.seedActivitySymbols(startIndex, target);
|
|
155
|
-
}
|
|
156
|
-
seedJobSymbols(startIndex) {
|
|
157
|
-
const hash = {};
|
|
158
|
-
MDATA_SYMBOLS.JOB.KEYS.forEach((key) => {
|
|
159
|
-
hash[`metadata/${key}`] = getSymKey(startIndex);
|
|
160
|
-
startIndex++;
|
|
161
|
-
});
|
|
162
|
-
return hash;
|
|
163
|
-
}
|
|
164
|
-
seedActivitySymbols(startIndex, activityId) {
|
|
165
|
-
const hash = {};
|
|
166
|
-
MDATA_SYMBOLS.ACTIVITY.KEYS.forEach((key) => {
|
|
167
|
-
hash[`${activityId}/output/metadata/${key}`] = getSymKey(startIndex);
|
|
168
|
-
startIndex++;
|
|
169
|
-
});
|
|
170
|
-
return hash;
|
|
171
|
-
}
|
|
172
|
-
async getSymbolValues() {
|
|
173
|
-
let symvals = this.cache.getSymbolValues(this.appId);
|
|
174
|
-
if (symvals) {
|
|
175
|
-
return symvals;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const key = this.mintKey(KeyType.SYMVALS, { appId: this.appId });
|
|
179
|
-
symvals = await this.redisClient[this.commands.hgetall](key);
|
|
180
|
-
this.cache.setSymbolValues(this.appId, symvals);
|
|
181
|
-
return symvals;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async addSymbolValues(symvals) {
|
|
185
|
-
if (!symvals || !Object.keys(symvals).length)
|
|
186
|
-
return false;
|
|
187
|
-
const key = this.mintKey(KeyType.SYMVALS, { appId: this.appId });
|
|
188
|
-
const success = await this.redisClient[this.commands.hset](key, symvals);
|
|
189
|
-
this.cache.deleteSymbolValues(this.appId);
|
|
190
|
-
return this.isSuccessful(success);
|
|
191
|
-
}
|
|
192
|
-
async getSymbolKeys(symbolNames) {
|
|
193
|
-
const symbolLookups = [];
|
|
194
|
-
for (const symbolName of symbolNames) {
|
|
195
|
-
symbolLookups.push(this.getSymbols(symbolName));
|
|
196
|
-
}
|
|
197
|
-
const symbolSets = await Promise.all(symbolLookups);
|
|
198
|
-
const symKeys = {};
|
|
199
|
-
for (const symbolName of symbolNames) {
|
|
200
|
-
symKeys[symbolName] = symbolSets.shift();
|
|
201
|
-
}
|
|
202
|
-
return symKeys;
|
|
203
|
-
}
|
|
204
|
-
async getApp(id, refresh = false) {
|
|
205
|
-
let app = this.cache.getApp(id);
|
|
206
|
-
if (refresh || !(app && Object.keys(app).length > 0)) {
|
|
207
|
-
const params = { appId: id };
|
|
208
|
-
const key = this.mintKey(KeyType.APP, params);
|
|
209
|
-
const sApp = await this.redisClient[this.commands.hgetall](key);
|
|
210
|
-
if (!sApp)
|
|
211
|
-
return null;
|
|
212
|
-
app = {};
|
|
213
|
-
for (const field in sApp) {
|
|
214
|
-
try {
|
|
215
|
-
if (field === 'active') {
|
|
216
|
-
app[field] = sApp[field] === 'true';
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
app[field] = sApp[field];
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
catch (e) {
|
|
223
|
-
app[field] = sApp[field];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
this.cache.setApp(id, app);
|
|
227
|
-
}
|
|
228
|
-
return app;
|
|
229
|
-
}
|
|
230
|
-
async setApp(id, version) {
|
|
231
|
-
const params = { appId: id };
|
|
232
|
-
const key = this.mintKey(KeyType.APP, params);
|
|
233
|
-
const versionId = `versions/${version}`;
|
|
234
|
-
const payload = {
|
|
235
|
-
id,
|
|
236
|
-
version,
|
|
237
|
-
[versionId]: `deployed:${formatISODate(new Date())}`,
|
|
238
|
-
};
|
|
239
|
-
await this.redisClient[this.commands.hset](key, payload);
|
|
240
|
-
this.cache.setApp(id, payload);
|
|
241
|
-
return payload;
|
|
242
|
-
}
|
|
243
|
-
async activateAppVersion(id, version) {
|
|
244
|
-
const params = { appId: id };
|
|
245
|
-
const key = this.mintKey(KeyType.APP, params);
|
|
246
|
-
const versionId = `versions/${version}`;
|
|
247
|
-
const app = await this.getApp(id, true);
|
|
248
|
-
if (app && app[versionId]) {
|
|
249
|
-
const payload = {
|
|
250
|
-
id,
|
|
251
|
-
version: version.toString(),
|
|
252
|
-
[versionId]: `activated:${formatISODate(new Date())}`,
|
|
253
|
-
active: true
|
|
254
|
-
};
|
|
255
|
-
Object.entries(payload).forEach(([key, value]) => {
|
|
256
|
-
payload[key] = value.toString();
|
|
257
|
-
});
|
|
258
|
-
await this.redisClient[this.commands.hset](key, payload);
|
|
259
|
-
return true;
|
|
260
|
-
}
|
|
261
|
-
throw new Error(`Version ${version} does not exist for app ${id}`);
|
|
262
|
-
}
|
|
263
|
-
async registerAppVersion(appId, version) {
|
|
264
|
-
const params = { appId };
|
|
265
|
-
const key = this.mintKey(KeyType.APP, params);
|
|
266
|
-
const payload = {
|
|
267
|
-
id: appId,
|
|
268
|
-
version: version.toString(),
|
|
269
|
-
[`versions/${version}`]: formatISODate(new Date()),
|
|
270
|
-
};
|
|
271
|
-
return await this.redisClient[this.commands.hset](key, payload);
|
|
272
|
-
}
|
|
273
|
-
async setStats(jobKey, jobId, dateTime, stats, appVersion, multi) {
|
|
274
|
-
const params = { appId: appVersion.id, jobId, jobKey, dateTime };
|
|
275
|
-
const privateMulti = multi || this.getMulti();
|
|
276
|
-
if (stats.general.length) {
|
|
277
|
-
const generalStatsKey = this.mintKey(KeyType.JOB_STATS_GENERAL, params);
|
|
278
|
-
for (const { target, value } of stats.general) {
|
|
279
|
-
privateMulti[this.commands.hincrbyfloat](generalStatsKey, target, value);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
for (const { target, value } of stats.index) {
|
|
283
|
-
const indexParams = { ...params, facet: target };
|
|
284
|
-
const indexStatsKey = this.mintKey(KeyType.JOB_STATS_INDEX, indexParams);
|
|
285
|
-
privateMulti[this.commands.rpush](indexStatsKey, value.toString());
|
|
286
|
-
}
|
|
287
|
-
for (const { target, value } of stats.median) {
|
|
288
|
-
const medianParams = { ...params, facet: target };
|
|
289
|
-
const medianStatsKey = this.mintKey(KeyType.JOB_STATS_MEDIAN, medianParams);
|
|
290
|
-
this.zAdd(medianStatsKey, value, target, privateMulti);
|
|
291
|
-
}
|
|
292
|
-
if (!multi) {
|
|
293
|
-
return await privateMulti.exec();
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
hGetAllResult(result) {
|
|
297
|
-
//default response signature uses 'redis' NPM Package format
|
|
298
|
-
return result;
|
|
299
|
-
}
|
|
300
|
-
async getJobStats(jobKeys) {
|
|
301
|
-
const multi = this.getMulti();
|
|
302
|
-
for (const jobKey of jobKeys) {
|
|
303
|
-
multi[this.commands.hgetall](jobKey);
|
|
304
|
-
}
|
|
305
|
-
const results = await multi.exec();
|
|
306
|
-
const output = {};
|
|
307
|
-
for (const [index, result] of results.entries()) {
|
|
308
|
-
const key = jobKeys[index];
|
|
309
|
-
const statsHash = this.hGetAllResult(result);
|
|
310
|
-
if (statsHash && Object.keys(statsHash).length > 0) {
|
|
311
|
-
const resolvedStatsHash = { ...statsHash };
|
|
312
|
-
for (const [key, val] of Object.entries(resolvedStatsHash)) {
|
|
313
|
-
resolvedStatsHash[key] = Number(val);
|
|
314
|
-
}
|
|
315
|
-
output[key] = resolvedStatsHash;
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
output[key] = {};
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
return output;
|
|
322
|
-
}
|
|
323
|
-
async getJobIds(indexKeys, idRange) {
|
|
324
|
-
const multi = this.getMulti();
|
|
325
|
-
for (const idsKey of indexKeys) {
|
|
326
|
-
multi[this.commands.lrange](idsKey, idRange[0], idRange[1]); //0,-1 returns all ids
|
|
327
|
-
}
|
|
328
|
-
const results = await multi.exec();
|
|
329
|
-
const output = {};
|
|
330
|
-
for (const [index, result] of results.entries()) {
|
|
331
|
-
const key = indexKeys[index];
|
|
332
|
-
const idsList = result[1];
|
|
333
|
-
if (idsList && idsList.length > 0) {
|
|
334
|
-
output[key] = idsList;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
output[key] = [];
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return output;
|
|
341
|
-
}
|
|
342
|
-
async setStatus(collationKeyStatus, jobId, appId, multi) {
|
|
343
|
-
const jobKey = this.mintKey(KeyType.JOB_STATE, { appId, jobId });
|
|
344
|
-
return await (multi || this.redisClient)[this.commands.hincrbyfloat](jobKey, ':', collationKeyStatus);
|
|
345
|
-
}
|
|
346
|
-
async getStatus(jobId, appId) {
|
|
347
|
-
const jobKey = this.mintKey(KeyType.JOB_STATE, { appId, jobId });
|
|
348
|
-
const status = await this.redisClient[this.commands.hget](jobKey, ':');
|
|
349
|
-
return Number(status);
|
|
350
|
-
}
|
|
351
|
-
async setState({ ...state }, status, jobId, symbolNames, dIds, multi) {
|
|
352
|
-
delete state['metadata/js'];
|
|
353
|
-
const hashKey = this.mintKey(KeyType.JOB_STATE, { appId: this.appId, jobId });
|
|
354
|
-
const symKeys = await this.getSymbolKeys(symbolNames);
|
|
355
|
-
const symVals = await this.getSymbolValues();
|
|
356
|
-
this.serializer.resetSymbols(symKeys, symVals, dIds);
|
|
357
|
-
const hashData = this.serializer.package(state, symbolNames);
|
|
358
|
-
if (status !== null) {
|
|
359
|
-
hashData[':'] = status.toString();
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
delete hashData[':'];
|
|
363
|
-
}
|
|
364
|
-
await (multi || this.redisClient)[this.commands.hset](hashKey, hashData);
|
|
365
|
-
return jobId;
|
|
366
|
-
}
|
|
367
|
-
async getState(jobId, consumes, dIds) {
|
|
368
|
-
//get abbreviated field list (the symbols for the paths)
|
|
369
|
-
const key = this.mintKey(KeyType.JOB_STATE, { appId: this.appId, jobId });
|
|
370
|
-
const symbolNames = Object.keys(consumes);
|
|
371
|
-
const symKeys = await this.getSymbolKeys(symbolNames);
|
|
372
|
-
this.serializer.resetSymbols(symKeys, {}, dIds);
|
|
373
|
-
const fields = this.serializer.abbreviate(consumes, symbolNames, [':']);
|
|
374
|
-
const jobDataArray = await this.redisClient[this.commands.hmget](key, fields);
|
|
375
|
-
const jobData = {};
|
|
376
|
-
let atLeast1 = false; //if status field (':') isn't present assume 404
|
|
377
|
-
fields.forEach((field, index) => {
|
|
378
|
-
if (jobDataArray[index]) {
|
|
379
|
-
atLeast1 = true;
|
|
380
|
-
}
|
|
381
|
-
jobData[field] = jobDataArray[index];
|
|
382
|
-
});
|
|
383
|
-
if (atLeast1) {
|
|
384
|
-
const symVals = await this.getSymbolValues();
|
|
385
|
-
this.serializer.resetSymbols(symKeys, symVals, dIds);
|
|
386
|
-
const state = this.serializer.unpackage(jobData, symbolNames);
|
|
387
|
-
let status = 0;
|
|
388
|
-
if (state[':']) {
|
|
389
|
-
status = Number(state[':']);
|
|
390
|
-
state[`metadata/js`] = status;
|
|
391
|
-
delete state[':'];
|
|
392
|
-
}
|
|
393
|
-
return [state, status];
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async collate(jobId, activityId, amount, dIds, multi) {
|
|
397
|
-
const jobKey = this.mintKey(KeyType.JOB_STATE, { appId: this.appId, jobId });
|
|
398
|
-
const collationKey = `${activityId}/output/metadata/as`; //activity state
|
|
399
|
-
const symbolNames = [activityId];
|
|
400
|
-
const symKeys = await this.getSymbolKeys(symbolNames);
|
|
401
|
-
const symVals = await this.getSymbolValues();
|
|
402
|
-
this.serializer.resetSymbols(symKeys, symVals, dIds);
|
|
403
|
-
const payload = { [collationKey]: amount.toString() };
|
|
404
|
-
const hashData = this.serializer.package(payload, symbolNames);
|
|
405
|
-
const targetId = Object.keys(hashData)[0];
|
|
406
|
-
return await (multi || this.redisClient)[this.commands.hincrbyfloat](jobKey, targetId, amount);
|
|
407
|
-
}
|
|
408
|
-
async setStateNX(jobId, appId) {
|
|
409
|
-
const hashKey = this.mintKey(KeyType.JOB_STATE, { appId, jobId });
|
|
410
|
-
const result = await this.redisClient[this.commands.hsetnx](hashKey, ':', '1');
|
|
411
|
-
return this.isSuccessful(result);
|
|
412
|
-
}
|
|
413
|
-
async getSchema(activityId, appVersion) {
|
|
414
|
-
const schema = this.cache.getSchema(appVersion.id, appVersion.version, activityId);
|
|
415
|
-
if (schema) {
|
|
416
|
-
return schema;
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
const schemas = await this.getSchemas(appVersion);
|
|
420
|
-
return schemas[activityId];
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
async getSchemas(appVersion) {
|
|
424
|
-
let schemas = this.cache.getSchemas(appVersion.id, appVersion.version);
|
|
425
|
-
if (schemas && Object.keys(schemas).length > 0) {
|
|
426
|
-
return schemas;
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
430
|
-
const key = this.mintKey(KeyType.SCHEMAS, params);
|
|
431
|
-
schemas = {};
|
|
432
|
-
const hash = await this.redisClient[this.commands.hgetall](key);
|
|
433
|
-
Object.entries(hash).forEach(([key, value]) => {
|
|
434
|
-
schemas[key] = JSON.parse(value);
|
|
435
|
-
});
|
|
436
|
-
this.cache.setSchemas(appVersion.id, appVersion.version, schemas);
|
|
437
|
-
return schemas;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
async setSchemas(schemas, appVersion) {
|
|
441
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
442
|
-
const key = this.mintKey(KeyType.SCHEMAS, params);
|
|
443
|
-
const _schemas = { ...schemas };
|
|
444
|
-
Object.entries(_schemas).forEach(([key, value]) => {
|
|
445
|
-
_schemas[key] = JSON.stringify(value);
|
|
446
|
-
});
|
|
447
|
-
const response = await this.redisClient[this.commands.hset](key, _schemas);
|
|
448
|
-
this.cache.setSchemas(appVersion.id, appVersion.version, schemas);
|
|
449
|
-
return response;
|
|
450
|
-
}
|
|
451
|
-
async setSubscriptions(subscriptions, appVersion) {
|
|
452
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
453
|
-
const key = this.mintKey(KeyType.SUBSCRIPTIONS, params);
|
|
454
|
-
const _subscriptions = { ...subscriptions };
|
|
455
|
-
Object.entries(_subscriptions).forEach(([key, value]) => {
|
|
456
|
-
_subscriptions[key] = JSON.stringify(value);
|
|
457
|
-
});
|
|
458
|
-
const status = await this.redisClient[this.commands.hset](key, _subscriptions);
|
|
459
|
-
this.cache.setSubscriptions(appVersion.id, appVersion.version, subscriptions);
|
|
460
|
-
return this.isSuccessful(status);
|
|
461
|
-
}
|
|
462
|
-
async getSubscriptions(appVersion) {
|
|
463
|
-
let subscriptions = this.cache.getSubscriptions(appVersion.id, appVersion.version);
|
|
464
|
-
if (subscriptions && Object.keys(subscriptions).length > 0) {
|
|
465
|
-
return subscriptions;
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
469
|
-
const key = this.mintKey(KeyType.SUBSCRIPTIONS, params);
|
|
470
|
-
subscriptions = await this.redisClient[this.commands.hgetall](key) || {};
|
|
471
|
-
Object.entries(subscriptions).forEach(([key, value]) => {
|
|
472
|
-
subscriptions[key] = JSON.parse(value);
|
|
473
|
-
});
|
|
474
|
-
this.cache.setSubscriptions(appVersion.id, appVersion.version, subscriptions);
|
|
475
|
-
return subscriptions;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
async getSubscription(topic, appVersion) {
|
|
479
|
-
const subscriptions = await this.getSubscriptions(appVersion);
|
|
480
|
-
return subscriptions[topic];
|
|
481
|
-
}
|
|
482
|
-
async setTransitions(transitions, appVersion) {
|
|
483
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
484
|
-
const key = this.mintKey(KeyType.SUBSCRIPTION_PATTERNS, params);
|
|
485
|
-
const _subscriptions = { ...transitions };
|
|
486
|
-
Object.entries(_subscriptions).forEach(([key, value]) => {
|
|
487
|
-
_subscriptions[key] = JSON.stringify(value);
|
|
488
|
-
});
|
|
489
|
-
if (Object.keys(_subscriptions).length !== 0) {
|
|
490
|
-
const response = await this.redisClient[this.commands.hset](key, _subscriptions);
|
|
491
|
-
this.cache.setTransitions(appVersion.id, appVersion.version, transitions);
|
|
492
|
-
return response;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
async getTransitions(appVersion) {
|
|
496
|
-
let transitions = this.cache.getTransitions(appVersion.id, appVersion.version);
|
|
497
|
-
if (transitions && Object.keys(transitions).length > 0) {
|
|
498
|
-
return transitions;
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
const params = { appId: appVersion.id, appVersion: appVersion.version };
|
|
502
|
-
const key = this.mintKey(KeyType.SUBSCRIPTION_PATTERNS, params);
|
|
503
|
-
transitions = {};
|
|
504
|
-
const hash = await this.redisClient[this.commands.hgetall](key);
|
|
505
|
-
Object.entries(hash).forEach(([key, value]) => {
|
|
506
|
-
transitions[key] = JSON.parse(value);
|
|
507
|
-
});
|
|
508
|
-
this.cache.setTransitions(appVersion.id, appVersion.version, transitions);
|
|
509
|
-
return transitions;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
async setHookRules(hookRules) {
|
|
513
|
-
const key = this.mintKey(KeyType.HOOKS, { appId: this.appId });
|
|
514
|
-
const _hooks = {};
|
|
515
|
-
Object.entries(hookRules).forEach(([key, value]) => {
|
|
516
|
-
_hooks[key.toString()] = JSON.stringify(value);
|
|
517
|
-
});
|
|
518
|
-
if (Object.keys(_hooks).length !== 0) {
|
|
519
|
-
const response = await this.redisClient[this.commands.hset](key, _hooks);
|
|
520
|
-
this.cache.setHookRules(this.appId, hookRules);
|
|
521
|
-
return response;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
async getHookRules() {
|
|
525
|
-
let patterns = this.cache.getHookRules(this.appId);
|
|
526
|
-
if (patterns && Object.keys(patterns).length > 0) {
|
|
527
|
-
return patterns;
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
const key = this.mintKey(KeyType.HOOKS, { appId: this.appId });
|
|
531
|
-
const _hooks = await this.redisClient[this.commands.hgetall](key);
|
|
532
|
-
patterns = {};
|
|
533
|
-
Object.entries(_hooks).forEach(([key, value]) => {
|
|
534
|
-
patterns[key] = JSON.parse(value);
|
|
535
|
-
});
|
|
536
|
-
this.cache.setHookRules(this.appId, patterns);
|
|
537
|
-
return patterns;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
async setHookSignal(hook, multi) {
|
|
541
|
-
const key = this.mintKey(KeyType.SIGNALS, { appId: this.appId });
|
|
542
|
-
const { topic, resolved, jobId } = hook;
|
|
543
|
-
const payload = {
|
|
544
|
-
[`${topic}:${resolved}`]: jobId
|
|
545
|
-
};
|
|
546
|
-
return await (multi || this.redisClient)[this.commands.hset](key, payload);
|
|
547
|
-
}
|
|
548
|
-
async getHookSignal(topic, resolved) {
|
|
549
|
-
const key = this.mintKey(KeyType.SIGNALS, { appId: this.appId });
|
|
550
|
-
const response = await this.redisClient[this.commands.hget](key, `${topic}:${resolved}`);
|
|
551
|
-
return response ? response.toString() : undefined;
|
|
552
|
-
}
|
|
553
|
-
async deleteHookSignal(topic, resolved) {
|
|
554
|
-
const key = this.mintKey(KeyType.SIGNALS, { appId: this.appId });
|
|
555
|
-
const response = await this.redisClient[this.commands.hdel](key, `${topic}:${resolved}`);
|
|
556
|
-
return response ? Number(response) : undefined;
|
|
557
|
-
}
|
|
558
|
-
async addTaskQueues(keys) {
|
|
559
|
-
const multi = this.getMulti();
|
|
560
|
-
const zsetKey = this.mintKey(KeyType.WORK_ITEMS, { appId: this.appId });
|
|
561
|
-
for (const key of keys) {
|
|
562
|
-
multi[this.commands.zadd](zsetKey, { score: Date.now().toString(), value: key }, { NX: true });
|
|
563
|
-
}
|
|
564
|
-
await multi.exec();
|
|
565
|
-
}
|
|
566
|
-
async getActiveTaskQueue() {
|
|
567
|
-
let workItemKey = this.cache.getActiveTaskQueue(this.appId) || null;
|
|
568
|
-
if (!workItemKey) {
|
|
569
|
-
const zsetKey = this.mintKey(KeyType.WORK_ITEMS, { appId: this.appId });
|
|
570
|
-
const result = await this.redisClient[this.commands.zrange](zsetKey, 0, 0);
|
|
571
|
-
workItemKey = result.length > 0 ? result[0] : null;
|
|
572
|
-
if (workItemKey) {
|
|
573
|
-
this.cache.setWorkItem(this.appId, workItemKey);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
return workItemKey;
|
|
577
|
-
}
|
|
578
|
-
async deleteProcessedTaskQueue(workItemKey, key, processedKey) {
|
|
579
|
-
const zsetKey = this.mintKey(KeyType.WORK_ITEMS, { appId: this.appId });
|
|
580
|
-
const didRemove = await this.redisClient[this.commands.zrem](zsetKey, workItemKey);
|
|
581
|
-
if (didRemove) {
|
|
582
|
-
await this.redisClient[this.commands.rename](processedKey, key);
|
|
583
|
-
}
|
|
584
|
-
this.cache.removeWorkItem(this.appId);
|
|
585
|
-
}
|
|
586
|
-
async processTaskQueue(sourceKey, destinationKey) {
|
|
587
|
-
return await this.redisClient[this.commands.lmove](sourceKey, destinationKey, 'LEFT', 'RIGHT');
|
|
588
|
-
}
|
|
589
|
-
async expireJob(jobId, inSeconds) {
|
|
590
|
-
if (!isNaN(inSeconds) && inSeconds > 0) {
|
|
591
|
-
const jobKey = this.mintKey(KeyType.JOB_STATE, { appId: this.appId, jobId });
|
|
592
|
-
await this.redisClient[this.commands.expire](jobKey, inSeconds);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
async registerTimeHook(jobId, activityId, type, deletionTime, multi) {
|
|
596
|
-
const listKey = this.mintKey(KeyType.TIME_RANGE, { appId: this.appId, timeValue: deletionTime });
|
|
597
|
-
const timeEvent = `${type}::${activityId}::${jobId}`;
|
|
598
|
-
const len = await (multi || this.redisClient)[this.commands.rpush](listKey, timeEvent);
|
|
599
|
-
if (multi || len === 1) {
|
|
600
|
-
const zsetKey = this.mintKey(KeyType.TIME_RANGE, { appId: this.appId });
|
|
601
|
-
await this.zAdd(zsetKey, deletionTime.toString(), listKey, multi);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
async getNextTimeJob(listKey) {
|
|
605
|
-
const zsetKey = this.mintKey(KeyType.TIME_RANGE, { appId: this.appId });
|
|
606
|
-
const now = Date.now();
|
|
607
|
-
listKey = listKey || await this.zRangeByScore(zsetKey, 0, now);
|
|
608
|
-
if (listKey) {
|
|
609
|
-
const timeEvent = await this.redisClient[this.commands.lpop](listKey);
|
|
610
|
-
if (timeEvent) {
|
|
611
|
-
//placeholder: there are 3 time-related event triggers: sleep, expire, cron
|
|
612
|
-
const [type, activityId, ...jobId] = timeEvent.split('::');
|
|
613
|
-
return [listKey, jobId.join('::'), activityId];
|
|
614
|
-
}
|
|
615
|
-
await this.redisClient[this.commands.zrem](zsetKey, listKey);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
async scrub(jobId) {
|
|
619
|
-
const jobKey = this.mintKey(KeyType.JOB_STATE, { appId: this.appId, jobId });
|
|
620
|
-
await this.redisClient[this.commands.del](jobKey);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
export { StoreService };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { KeyStoreParams, KeyType } from '../../../modules/key';
|
|
2
|
-
import { ILogger } from '../../logger';
|
|
3
|
-
import { StreamService } from '../index';
|
|
4
|
-
import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
|
|
5
|
-
import { ReclaimedMessageType } from '../../../types/stream';
|
|
6
|
-
declare class IORedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
|
|
7
|
-
redisClient: RedisClientType;
|
|
8
|
-
namespace: string;
|
|
9
|
-
logger: ILogger;
|
|
10
|
-
appId: string;
|
|
11
|
-
constructor(redisClient: RedisClientType);
|
|
12
|
-
init(namespace: string, appId: string, logger: ILogger): Promise<void>;
|
|
13
|
-
getMulti(): RedisMultiType;
|
|
14
|
-
mintKey(type: KeyType, params: KeyStoreParams): string;
|
|
15
|
-
xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
|
|
16
|
-
xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType>;
|
|
17
|
-
xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: 'BLOCK' | 'COUNT', blockTime: number | string, streamsOption: 'STREAMS', streamName: string, id: string): Promise<string[][][] | null | unknown[]>;
|
|
18
|
-
xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
|
|
19
|
-
xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
|
|
20
|
-
xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
21
|
-
xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
|
|
22
|
-
}
|
|
23
|
-
export { IORedisStreamService };
|