@baeta/cache-ioredis 2.0.0-next.13 → 2.0.0-next.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @baeta/cache-ioredis
2
2
 
3
+ ## 2.0.0-next.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies:
8
+ - @baeta/cache@2.0.0-next.14
9
+
3
10
  ## 2.0.0-next.13
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CacheClient } from "@baeta/cache";
2
- import { doBatched } from "@baeta/cache/sdk";
3
2
  import { assertNoPipelineErrors, batchPipeline, createRedisScripts } from "@baeta/cache-redis-common";
3
+ import { doBatched } from "@baeta/cache/sdk";
4
4
  //#region lib/cache-client.ts
5
5
  const INDEX_BUFFER_MS = 1e3;
6
6
  const MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../lib/cache-client.ts"],"sourcesContent":["import type {\n\tCacheClientSaveOptions,\n\tItemCacheKey,\n\tQueryCacheIndexKey,\n\tQueryCacheKey,\n} from '@baeta/cache';\nimport { CacheClient, type CacheClientArgs, type CacheClientOptions } from '@baeta/cache';\nimport { doBatched } from '@baeta/cache/sdk';\nimport {\n\tassertNoPipelineErrors,\n\tbatchPipeline,\n\tcreateRedisScripts,\n\ttype RedisScripts,\n} from '@baeta/cache-redis-common';\nimport type Redis from 'ioredis';\nimport type { Cluster as RedisCluster } from 'ioredis';\n\nconst INDEX_BUFFER_MS = 1_000;\nconst MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024; // 50MB\nconst MAX_PIPELINE_COMMAND_LIMIT = 100_000;\nconst MAX_COMMAND_KEYS_LIMIT = 100_000;\n\nexport interface RedisCacheClientOptions extends CacheClientOptions {\n\t/**\n\t * Maximum total size of commands in a single pipeline batch. If the batch exceeds this size, it will be executed immediately.\n\t * @defaultValue 50 * 1024 * 1024 (50MB)\n\t */\n\tmaxPipelineSizeLimit?: number;\n\t/**\n\t * Maximum number of commands in a single pipeline batch. If the batch exceeds this number, it will be executed immediately.\n\t * @defaultValue 100_000\n\t */\n\tmaxPipelineCommandLimit?: number;\n\t/**\n\t * Maximum number of keys in a single command. If the number of keys exceeds this limit, multiple commands will be executed.\n\t * @defaultValue 100_000\n\t */\n\tmaxCommandKeysLimit?: number;\n}\n\nexport class RedisCacheClient extends CacheClient {\n\tredis: Redis | RedisCluster;\n\tprotected maxPipelineSizeLimit: number;\n\tprotected maxPipelineCommandLimit: number;\n\tprotected maxCommandKeysLimit: number;\n\tprotected scripts: RedisScripts;\n\n\tconstructor(redis: Redis | RedisCluster, options?: RedisCacheClientOptions) {\n\t\tsuper({\n\t\t\tnamespace: options?.namespace,\n\t\t\trevision: options?.revision,\n\t\t\tttlMs: options?.ttlMs,\n\t\t});\n\t\tthis.redis = redis;\n\t\tthis.maxPipelineSizeLimit = options?.maxPipelineSizeLimit ?? MAX_PIPELINE_SIZE_LIMIT;\n\t\tthis.maxPipelineCommandLimit = options?.maxPipelineCommandLimit ?? MAX_PIPELINE_COMMAND_LIMIT;\n\t\tthis.maxCommandKeysLimit = options?.maxCommandKeysLimit ?? MAX_COMMAND_KEYS_LIMIT;\n\t\tconst loadScript = async (script: string) => {\n\t\t\treturn await this.redis.script('LOAD', script);\n\t\t};\n\t\tconst evalSha = async (sha: string, keys: string[], args: string[]) => {\n\t\t\treturn await this.redis.evalsha(sha, keys.length, ...keys, ...args);\n\t\t};\n\t\tthis.scripts = createRedisScripts(loadScript, evalSha);\n\t}\n\n\tasync getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst values: Array<Item | null> = [];\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tconst batchValues = await this.redis.mget(batch);\n\t\t\tfor (const value of batchValues) {\n\t\t\t\tvalues.push(value == null ? null : options.parse(value));\n\t\t\t}\n\t\t});\n\t\treturn values;\n\t}\n\n\tasync saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions: CacheClientSaveOptions = {},\n\t): Promise<void> {\n\t\tif (items.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst serialized = items.map(([key, value]) => ({\n\t\t\tkey,\n\t\t\tvalue: options.serialize(value),\n\t\t}));\n\t\tawait batchPipeline({\n\t\t\tmakePipeline: () => this.redis.pipeline(),\n\t\t\taddCommand: (pipeline, item) => {\n\t\t\t\tif (saveOptions.disableOverwrite !== true) {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt);\n\t\t\t\t} else {\n\t\t\t\t\tpipeline.setnx(item.key, item.value);\n\t\t\t\t\tpipeline.pexpireat(item.key, expiresAt);\n\t\t\t\t}\n\t\t\t},\n\t\t\texecutePipeline: async (pipeline) => {\n\t\t\t\tconst result = await pipeline.exec();\n\t\t\t\tif (result == null) {\n\t\t\t\t\tthrow new Error('Unexpected null result from Redis pipeline');\n\t\t\t\t}\n\t\t\t\tassertNoPipelineErrors(result);\n\t\t\t\treturn [];\n\t\t\t},\n\t\t\testimateSize: (item) => {\n\t\t\t\treturn item.key.length + item.value.length;\n\t\t\t},\n\t\t\titems: serialized,\n\t\t\tmaxBatchBytes: this.maxPipelineSizeLimit,\n\t\t\tmaxBatchCount: this.maxPipelineCommandLimit,\n\t\t});\n\t}\n\n\tasync saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (items.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst keys: ItemCacheKey[] = new Array(items.length);\n\t\tconst values: string[] = new Array(items.length);\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tkeys[i] = items[i][0];\n\t\t\tvalues[i] = options.serialize(items[i][1]);\n\t\t}\n\t\tconst result = await this.scripts.saveWithDiffScript(keys, [...values, expiresAt.toString()]);\n\t\tif (!Array.isArray(result)) {\n\t\t\tthrow new Error(`Unexpected non-array result from Redis script: ${typeof result}`);\n\t\t}\n\t\treturn result.map((value) => {\n\t\t\tif (typeof value === 'string') {\n\t\t\t\treturn options.parse(value);\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\tasync deleteItems(keys: ItemCacheKey[]): Promise<void> {\n\t\tif (keys.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tawait this.redis.unlink(batch);\n\t\t});\n\t}\n\n\tasync deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst result = await this.scripts.deleteWithDiffScript(keys, []);\n\t\tif (!Array.isArray(result)) {\n\t\t\tthrow new Error(`Unexpected non-array result from Redis script: ${typeof result}`);\n\t\t}\n\t\treturn result.map((value) => {\n\t\t\tif (typeof value === 'string') {\n\t\t\t\treturn options.parse(value);\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\tasync getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null> {\n\t\tconst meta = await this.redis.get(key);\n\t\treturn meta == null ? null : options.parse(meta);\n\t}\n\n\tasync saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void> {\n\t\tconst now = Date.now();\n\t\tconst expiresAt = now + options.ttlMs;\n\t\tconst pipeline = this.redis.pipeline();\n\t\tpipeline.set(key, options.serialize(metadata), 'PXAT', expiresAt);\n\t\tfor (const indexKey of indexes) {\n\t\t\tpipeline.zadd(indexKey, expiresAt, key);\n\t\t\tpipeline.zremrangebyscore(indexKey, '-inf', now - INDEX_BUFFER_MS);\n\t\t\tpipeline.pexpireat(indexKey, expiresAt + INDEX_BUFFER_MS);\n\t\t}\n\t\tconst result = await pipeline.exec();\n\t\tassertNoPipelineErrors(result);\n\t}\n\n\tasync deleteQueries(indexes: QueryCacheIndexKey[]): Promise<void> {\n\t\tif (indexes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = await this.scripts.deleteQueriesScript(indexes, []);\n\t\tif (typeof result !== 'number') {\n\t\t\tthrow new Error(`Unexpected non-number result from Redis script: ${typeof result}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAiBA,MAAM,kBAAkB;AACxB,MAAM,0BAA0B,KAAK,OAAO;AAC5C,MAAM,6BAA6B;AACnC,MAAM,yBAAyB;AAoB/B,IAAa,mBAAb,cAAsC,YAAY;CACjD;CACA;CACA;CACA;CACA;CAEA,YAAY,OAA6B,SAAmC;AAC3E,QAAM;GACL,WAAW,SAAS;GACpB,UAAU,SAAS;GACnB,OAAO,SAAS;GAChB,CAAC;AACF,OAAK,QAAQ;AACb,OAAK,uBAAuB,SAAS,wBAAwB;AAC7D,OAAK,0BAA0B,SAAS,2BAA2B;AACnE,OAAK,sBAAsB,SAAS,uBAAuB;EAC3D,MAAM,aAAa,OAAO,WAAmB;AAC5C,UAAO,MAAM,KAAK,MAAM,OAAO,QAAQ,OAAO;;EAE/C,MAAM,UAAU,OAAO,KAAa,MAAgB,SAAmB;AACtE,UAAO,MAAM,KAAK,MAAM,QAAQ,KAAK,KAAK,QAAQ,GAAG,MAAM,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I,KAAK,QAAQ,UAAU,SAAS,EAAE,QAAQ,UAAU;AACjE,OAAK,MAAM,YAAY,SAAS;AAC/B,YAAS,KAAK,UAAU,WAAW,IAAI;AACvC,YAAS,iBAAiB,UAAU,QAAQ,MAAM,gBAAgB;AAClE,YAAS,UAAU,UAAU,YAAY,gBAAgB;;AAG1D,yBAAuB,MADF,SAAS,MAAM,CACN;;CAG/B,MAAM,cAAc,SAA8C;AACjE,MAAI,QAAQ,WAAW,EACtB;EAED,MAAM,SAAS,MAAM,KAAK,QAAQ,oBAAoB,SAAS,EAAE,CAAC;AAClE,MAAI,OAAO,WAAW,SACrB,OAAM,IAAI,MAAM,mDAAmD,OAAO,SAAS"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/cache-client.ts"],"sourcesContent":["import {\n\tCacheClient,\n\ttype CacheClientSaveOptions,\n\ttype ItemCacheKey,\n\ttype QueryCacheIndexKey,\n\ttype QueryCacheKey,\n\ttype CacheClientArgs,\n\ttype CacheClientOptions,\n} from '@baeta/cache';\nimport {\n\tassertNoPipelineErrors,\n\tbatchPipeline,\n\tcreateRedisScripts,\n\ttype RedisScripts,\n} from '@baeta/cache-redis-common';\nimport { doBatched } from '@baeta/cache/sdk';\nimport type Redis from 'ioredis';\nimport type { Cluster as RedisCluster } from 'ioredis';\n\nconst INDEX_BUFFER_MS = 1_000;\nconst MAX_PIPELINE_SIZE_LIMIT = 50 * 1024 * 1024; // 50MB\nconst MAX_PIPELINE_COMMAND_LIMIT = 100_000;\nconst MAX_COMMAND_KEYS_LIMIT = 100_000;\n\nexport interface RedisCacheClientOptions extends CacheClientOptions {\n\t/**\n\t * Maximum total size of commands in a single pipeline batch. If the batch exceeds this size, it will be executed immediately.\n\t * @defaultValue 50 * 1024 * 1024 (50MB)\n\t */\n\tmaxPipelineSizeLimit?: number;\n\t/**\n\t * Maximum number of commands in a single pipeline batch. If the batch exceeds this number, it will be executed immediately.\n\t * @defaultValue 100_000\n\t */\n\tmaxPipelineCommandLimit?: number;\n\t/**\n\t * Maximum number of keys in a single command. If the number of keys exceeds this limit, multiple commands will be executed.\n\t * @defaultValue 100_000\n\t */\n\tmaxCommandKeysLimit?: number;\n}\n\nexport class RedisCacheClient extends CacheClient {\n\tredis: Redis | RedisCluster;\n\tprotected maxPipelineSizeLimit: number;\n\tprotected maxPipelineCommandLimit: number;\n\tprotected maxCommandKeysLimit: number;\n\tprotected scripts: RedisScripts;\n\n\tconstructor(redis: Redis | RedisCluster, options?: RedisCacheClientOptions) {\n\t\tsuper({\n\t\t\tnamespace: options?.namespace,\n\t\t\trevision: options?.revision,\n\t\t\tttlMs: options?.ttlMs,\n\t\t});\n\t\tthis.redis = redis;\n\t\tthis.maxPipelineSizeLimit = options?.maxPipelineSizeLimit ?? MAX_PIPELINE_SIZE_LIMIT;\n\t\tthis.maxPipelineCommandLimit = options?.maxPipelineCommandLimit ?? MAX_PIPELINE_COMMAND_LIMIT;\n\t\tthis.maxCommandKeysLimit = options?.maxCommandKeysLimit ?? MAX_COMMAND_KEYS_LIMIT;\n\t\tconst loadScript = async (script: string) => {\n\t\t\treturn await this.redis.script('LOAD', script);\n\t\t};\n\t\tconst evalSha = async (sha: string, keys: string[], args: string[]) => {\n\t\t\treturn await this.redis.evalsha(sha, keys.length, ...keys, ...args);\n\t\t};\n\t\tthis.scripts = createRedisScripts(loadScript, evalSha);\n\t}\n\n\tasync getPartialItems<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst values: Array<Item | null> = [];\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tconst batchValues = await this.redis.mget(batch);\n\t\t\tfor (const value of batchValues) {\n\t\t\t\tvalues.push(value == null ? null : options.parse(value));\n\t\t\t}\n\t\t});\n\t\treturn values;\n\t}\n\n\tasync saveItems<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t\tsaveOptions: CacheClientSaveOptions = {},\n\t): Promise<void> {\n\t\tif (items.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst serialized = items.map(([key, value]) => ({\n\t\t\tkey,\n\t\t\tvalue: options.serialize(value),\n\t\t}));\n\t\tawait batchPipeline({\n\t\t\tmakePipeline: () => this.redis.pipeline(),\n\t\t\taddCommand: (pipeline, item) => {\n\t\t\t\tif (saveOptions.disableOverwrite !== true) {\n\t\t\t\t\tpipeline.set(item.key, item.value, 'PXAT', expiresAt);\n\t\t\t\t} else {\n\t\t\t\t\tpipeline.setnx(item.key, item.value);\n\t\t\t\t\tpipeline.pexpireat(item.key, expiresAt);\n\t\t\t\t}\n\t\t\t},\n\t\t\texecutePipeline: async (pipeline) => {\n\t\t\t\tconst result = await pipeline.exec();\n\t\t\t\tif (result == null) {\n\t\t\t\t\tthrow new Error('Unexpected null result from Redis pipeline');\n\t\t\t\t}\n\t\t\t\tassertNoPipelineErrors(result);\n\t\t\t\treturn [];\n\t\t\t},\n\t\t\testimateSize: (item) => {\n\t\t\t\treturn item.key.length + item.value.length;\n\t\t\t},\n\t\t\titems: serialized,\n\t\t\tmaxBatchBytes: this.maxPipelineSizeLimit,\n\t\t\tmaxBatchCount: this.maxPipelineCommandLimit,\n\t\t});\n\t}\n\n\tasync saveItemsWithDiff<Item>(\n\t\titems: Array<[ItemCacheKey, Item]>,\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (items.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst expiresAt = Date.now() + options.ttlMs;\n\t\tconst keys: ItemCacheKey[] = new Array(items.length);\n\t\tconst values: string[] = new Array(items.length);\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tkeys[i] = items[i][0];\n\t\t\tvalues[i] = options.serialize(items[i][1]);\n\t\t}\n\t\tconst result = await this.scripts.saveWithDiffScript(keys, [...values, expiresAt.toString()]);\n\t\tif (!Array.isArray(result)) {\n\t\t\tthrow new Error(`Unexpected non-array result from Redis script: ${typeof result}`);\n\t\t}\n\t\treturn result.map((value) => {\n\t\t\tif (typeof value === 'string') {\n\t\t\t\treturn options.parse(value);\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\tasync deleteItems(keys: ItemCacheKey[]): Promise<void> {\n\t\tif (keys.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait doBatched(keys, this.maxCommandKeysLimit, async (batch) => {\n\t\t\tawait this.redis.unlink(batch);\n\t\t});\n\t}\n\n\tasync deleteItemsWithDiff<Item>(\n\t\tkeys: ItemCacheKey[],\n\t\toptions: CacheClientArgs<Item>,\n\t): Promise<Array<Item | null>> {\n\t\tif (keys.length === 0) {\n\t\t\treturn [];\n\t\t}\n\t\tconst result = await this.scripts.deleteWithDiffScript(keys, []);\n\t\tif (!Array.isArray(result)) {\n\t\t\tthrow new Error(`Unexpected non-array result from Redis script: ${typeof result}`);\n\t\t}\n\t\treturn result.map((value) => {\n\t\t\tif (typeof value === 'string') {\n\t\t\t\treturn options.parse(value);\n\t\t\t}\n\t\t\treturn null;\n\t\t});\n\t}\n\n\tasync getQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<QueryMetadata | null> {\n\t\tconst meta = await this.redis.get(key);\n\t\treturn meta == null ? null : options.parse(meta);\n\t}\n\n\tasync saveQuery<QueryMetadata>(\n\t\tkey: QueryCacheKey,\n\t\tindexes: QueryCacheIndexKey[],\n\t\tmetadata: QueryMetadata,\n\t\toptions: CacheClientArgs<QueryMetadata>,\n\t): Promise<void> {\n\t\tconst now = Date.now();\n\t\tconst expiresAt = now + options.ttlMs;\n\t\tconst pipeline = this.redis.pipeline();\n\t\tpipeline.set(key, options.serialize(metadata), 'PXAT', expiresAt);\n\t\tfor (const indexKey of indexes) {\n\t\t\tpipeline.zadd(indexKey, expiresAt, key);\n\t\t\tpipeline.zremrangebyscore(indexKey, '-inf', now - INDEX_BUFFER_MS);\n\t\t\tpipeline.pexpireat(indexKey, expiresAt + INDEX_BUFFER_MS);\n\t\t}\n\t\tconst result = await pipeline.exec();\n\t\tassertNoPipelineErrors(result);\n\t}\n\n\tasync deleteQueries(indexes: QueryCacheIndexKey[]): Promise<void> {\n\t\tif (indexes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tconst result = await this.scripts.deleteQueriesScript(indexes, []);\n\t\tif (typeof result !== 'number') {\n\t\t\tthrow new Error(`Unexpected non-number result from Redis script: ${typeof result}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;AAmBA,MAAM,kBAAkB;AACxB,MAAM,0BAA0B,KAAK,OAAO;AAC5C,MAAM,6BAA6B;AACnC,MAAM,yBAAyB;AAoB/B,IAAa,mBAAb,cAAsC,YAAY;CACjD;CACA;CACA;CACA;CACA;CAEA,YAAY,OAA6B,SAAmC;AAC3E,QAAM;GACL,WAAW,SAAS;GACpB,UAAU,SAAS;GACnB,OAAO,SAAS;GAChB,CAAC;AACF,OAAK,QAAQ;AACb,OAAK,uBAAuB,SAAS,wBAAwB;AAC7D,OAAK,0BAA0B,SAAS,2BAA2B;AACnE,OAAK,sBAAsB,SAAS,uBAAuB;EAC3D,MAAM,aAAa,OAAO,WAAmB;AAC5C,UAAO,MAAM,KAAK,MAAM,OAAO,QAAQ,OAAO;;EAE/C,MAAM,UAAU,OAAO,KAAa,MAAgB,SAAmB;AACtE,UAAO,MAAM,KAAK,MAAM,QAAQ,KAAK,KAAK,QAAQ,GAAG,MAAM,GAAG,KAAK;;AAEpE,OAAK,UAAU,mBAAmB,YAAY,QAAQ;;CAGvD,MAAM,gBACL,MACA,SAC8B;AAC9B,MAAI,KAAK,WAAW,EACnB,QAAO,EAAE;EAEV,MAAM,SAA6B,EAAE;AACrC,QAAM,UAAU,MAAM,KAAK,qBAAqB,OAAO,UAAU;GAChE,MAAM,c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ADF,SAAS,MAAM,CACN;;CAG/B,MAAM,cAAc,SAA8C;AACjE,MAAI,QAAQ,WAAW,EACtB;EAED,MAAM,SAAS,MAAM,KAAK,QAAQ,oBAAoB,SAAS,EAAE,CAAC;AAClE,MAAI,OAAO,WAAW,SACrB,OAAM,IAAI,MAAM,mDAAmD,OAAO,SAAS"}
package/package.json CHANGED
@@ -1,60 +1,64 @@
1
1
  {
2
2
  "name": "@baeta/cache-ioredis",
3
- "version": "2.0.0-next.13",
3
+ "version": "2.0.0-next.14",
4
4
  "keywords": [
5
5
  "baeta",
6
+ "builder",
7
+ "framework",
6
8
  "graphql",
7
9
  "schema",
8
10
  "types",
9
- "typescript",
10
- "framework",
11
- "builder"
11
+ "typescript"
12
12
  ],
13
13
  "homepage": "https://github.com/andreisergiu98/baeta#readme",
14
14
  "bugs": {
15
15
  "url": "https://github.com/andreisergiu98/baeta/issues"
16
16
  },
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/andreisergiu98/baeta.git",
20
- "directory": "packages/cache-ioredis"
21
- },
22
17
  "license": "MIT",
23
18
  "author": {
24
19
  "name": "Andrei Pampu",
25
20
  "url": "https://github.com/andreisergiu98"
26
21
  },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/andreisergiu98/baeta.git",
25
+ "directory": "packages/cache-ioredis"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "package.json"
30
+ ],
27
31
  "type": "module",
32
+ "types": "dist/index.d.ts",
28
33
  "exports": {
29
34
  ".": {
30
35
  "types": "./dist/index.d.ts",
31
36
  "default": "./dist/index.js"
32
37
  }
33
38
  },
34
- "types": "dist/index.d.ts",
35
- "files": [
36
- "dist",
37
- "package.json"
38
- ],
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/index.d.ts",
44
+ "default": "./dist/index.js"
45
+ }
46
+ }
47
+ },
39
48
  "scripts": {
40
49
  "build": "builder build",
41
50
  "check:deps": "builder check-deps",
42
- "prepack": "builder prepare",
43
51
  "postpack": "builder prepare --restore",
52
+ "prepack": "builder prepare",
44
53
  "test": "builder test --skip-coverage",
45
54
  "types": "tsc --noEmit"
46
55
  },
47
- "ava": {
48
- "extensions": [
49
- "ts"
50
- ]
51
- },
52
56
  "dependencies": {
53
57
  "@baeta/cache-redis-common": "^2.0.0-next.12"
54
58
  },
55
59
  "devDependencies": {
56
60
  "@baeta/builder": "^0.0.0",
57
- "@baeta/cache": "^2.0.0-next.13",
61
+ "@baeta/cache": "^2.0.0-next.14",
58
62
  "@baeta/testing": "^0.0.0",
59
63
  "@baeta/tests-cache-clients": "^0.0.0",
60
64
  "@baeta/tsconfig": "^0.0.0",
@@ -62,21 +66,17 @@
62
66
  "typescript": "^6.0.0"
63
67
  },
64
68
  "peerDependencies": {
65
- "@baeta/cache": "^2.0.0-next.13",
69
+ "@baeta/cache": "^2.0.0-next.14",
66
70
  "ioredis": "^5.10.0"
67
71
  },
72
+ "ava": {
73
+ "extensions": [
74
+ "ts"
75
+ ]
76
+ },
68
77
  "engines": {
69
78
  "node": ">=22.20.0"
70
79
  },
71
- "publishConfig": {
72
- "access": "public",
73
- "exports": {
74
- ".": {
75
- "types": "./dist/index.d.ts",
76
- "default": "./dist/index.js"
77
- }
78
- }
79
- },
80
80
  "typedocOptions": {
81
81
  "entryPoints": [
82
82
  "./index.ts"