@teamplay/backend 0.3.21 → 0.3.22

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.
Files changed (3) hide show
  1. package/index.js +10 -1
  2. package/package.json +7 -7
  3. package/redis/index.js +22 -17
package/index.js CHANGED
@@ -7,7 +7,16 @@ import initValidateSchema from './features/validateSchema.js'
7
7
  import initServerAggregate from './features/serverAggregate.js'
8
8
  import initAccessControl from './features/accessControl.js'
9
9
 
10
- export { redis, redlock, Redlock, getRedis, Redis } from './redis/index.js'
10
+ export {
11
+ prefix as redisPrefix,
12
+ generatePrefix as generateRedisPrefix,
13
+ getRedisOptions,
14
+ redis,
15
+ redlock,
16
+ Redlock,
17
+ getRedis,
18
+ Redis
19
+ } from './redis/index.js'
11
20
  export { db, mongo, mongoClient, createMongoIndex, sqlite } from './db/index.js'
12
21
 
13
22
  const usersConnectionCounter = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamplay/backend",
3
- "version": "0.3.21",
3
+ "version": "0.3.22",
4
4
  "description": "Create new ShareDB backend instance",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -13,11 +13,11 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@startupjs/sharedb-mingo-memory": "^4.0.0-1",
16
- "@teamplay/schema": "^0.3.21",
17
- "@teamplay/server-aggregate": "^0.3.21",
18
- "@teamplay/sharedb-access": "^0.3.21",
19
- "@teamplay/sharedb-schema": "^0.3.21",
20
- "@teamplay/utils": "^0.3.21",
16
+ "@teamplay/schema": "^0.3.22",
17
+ "@teamplay/server-aggregate": "^0.3.22",
18
+ "@teamplay/sharedb-access": "^0.3.22",
19
+ "@teamplay/sharedb-schema": "^0.3.22",
20
+ "@teamplay/utils": "^0.3.22",
21
21
  "@types/ioredis-mock": "^8.2.5",
22
22
  "ioredis": "^5.3.2",
23
23
  "ioredis-mock": "^8.9.0",
@@ -29,5 +29,5 @@
29
29
  "sharedb-redis-pubsub": "^2.0.1",
30
30
  "sqlite3": "^5.1.6"
31
31
  },
32
- "gitHead": "0aa8b8f87f8c9a5cb007058305a484653c45ca07"
32
+ "gitHead": "14c97ab2ee86b26c9ac4dd8066b806ddb110a3eb"
33
33
  }
package/redis/index.js CHANGED
@@ -2,23 +2,16 @@ import Redlock from 'redlock'
2
2
  import redisPubSub from 'sharedb-redis-pubsub'
3
3
  import { getRedis, Redis, RedisMock } from './getRedis.js'
4
4
 
5
- const enableRedis = !process.env.NO_REDIS
6
-
7
- const getRedisOptions = {
8
- enable: enableRedis,
9
- opts: process.env.REDIS_OPTS,
10
- url: process.env.REDIS_URL,
11
- keyPrefix: generatePrefix({
12
- mongoUrl: process.env.MONGO_URL,
13
- baseUrl: process.env.BASE_URL
14
- })
15
- }
16
-
17
- const RedisClient = enableRedis ? Redis : RedisMock
18
- export { RedisClient as Redis }
19
- export { getRedis }
20
- export const redis = getRedis(getRedisOptions)
21
- export const redisObserver = getRedis(getRedisOptions)
5
+ const ENABLE_REDIS = !process.env.NO_REDIS
6
+
7
+ const RedisClient = ENABLE_REDIS ? Redis : RedisMock
8
+ export { RedisClient as Redis, getRedis, getRedisOptions, generatePrefix }
9
+ export const redis = getRedis(getRedisOptions())
10
+ export const redisObserver = getRedis(getRedisOptions())
11
+ export const prefix = generatePrefix({
12
+ mongoUrl: process.env.MONGO_URL,
13
+ baseUrl: process.env.BASE_URL
14
+ })
22
15
 
23
16
  export const pubsub = redisPubSub({
24
17
  client: redis,
@@ -29,6 +22,18 @@ export const redlock = getRedlock(redis)
29
22
 
30
23
  export { Redlock }
31
24
 
25
+ function getRedisOptions ({ addPrefix = true }) {
26
+ const options = {
27
+ enable: ENABLE_REDIS,
28
+ opts: process.env.REDIS_OPTS,
29
+ url: process.env.REDIS_URL
30
+ }
31
+
32
+ if (addPrefix) options.keyPrefix = prefix
33
+
34
+ return options
35
+ }
36
+
32
37
  function getRedlock (redis) {
33
38
  return new Redlock([redis], {
34
39
  driftFactor: 0.01,