@atproto-labs/simple-store-redis 0.1.1 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atproto-labs/simple-store-redis
2
2
 
3
+ ## 0.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update TypeScript build to rely on references to composite internal projects
8
+
9
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Bundle only necessary files in the NPM tarball, including the `CHANGELOG.md` and `README.md` files (if present).
10
+
11
+ - [#5099](https://github.com/bluesky-social/atproto/pull/5099) [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build with `noImplicitAny` enabled
12
+
13
+ - Updated dependencies [[`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07), [`b43ec31`](https://github.com/bluesky-social/atproto/commit/b43ec31f247f4461725b01226885f88bd430ca07)]:
14
+ - @atproto-labs/simple-store@0.4.3
15
+
16
+ ## 0.1.2
17
+
18
+ ### Patch Changes
19
+
20
+ - [#5151](https://github.com/bluesky-social/atproto/pull/5151) [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependencies
21
+
22
+ - Updated dependencies [[`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7)]:
23
+ - @atproto-labs/simple-store@0.4.2
24
+
3
25
  ## 0.1.1
4
26
 
5
27
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Redis } from 'ioredis';
2
- import { Awaitable, GetOptions, SimpleStore, Value } from '@atproto-labs/simple-store';
2
+ import type { Awaitable, GetOptions, SimpleStore, Value } from '@atproto-labs/simple-store';
3
3
  export type { Awaitable, GetOptions, SimpleStore, Value };
4
4
  export type Encoder<K extends string, V extends Value> = (value: V, key: K) => Awaitable<string>;
5
5
  export type Decoder<K extends string, V extends Value> = (value: string, key: K) => Awaitable<V>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,EACN,MAAM,4BAA4B,CAAA;AAEnC,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;AAEzD,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,KAAK,IAAI,CACvD,KAAK,EAAE,CAAC,EACR,GAAG,EAAE,CAAC,KACH,SAAS,CAAC,MAAM,CAAC,CAAA;AACtB,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,KAAK,IAAI,CACvD,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,CAAC,KACH,SAAS,CAAC,CAAC,CAAC,CAAA;AAEjB,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,CACxB,CAAA;AACvB,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAgC,CAAA;AAE/E,MAAM,MAAM,uBAAuB,CAAC,CAAC,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;QAChC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACzC,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,SAAS,CAAA;QACpC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAA;QACjC,MAAM,EAAE,MAAM,GAAG,cAAiC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QACnE,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM,EAAE,KAAQ;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QACrD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QACvC,IAAI,GAAG;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;;YACjD,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;CACF","sourcesContent":["import type { Redis } from 'ioredis'\nimport {\n Awaitable,\n GetOptions,\n SimpleStore,\n Value,\n} from '@atproto-labs/simple-store'\n\nexport type { Awaitable, GetOptions, SimpleStore, Value }\n\nexport type Encoder<K extends string, V extends Value> = (\n value: V,\n key: K,\n) => Awaitable<string>\nexport type Decoder<K extends string, V extends Value> = (\n value: string,\n key: K,\n) => Awaitable<V>\n\nexport const defaultEncoder: Encoder<any, Value> = (value) =>\n JSON.stringify(value)\nexport const defaultDecoder: Decoder<any, Value> = (value) => JSON.parse(value)\n\nexport type SimpleStoreRedisOptions<K extends string, V extends Value> = {\n keyPrefix: string\n /** In milliseconds */\n ttl?: number\n /** @default JSON.stringify */\n encode?: Encoder<K, V>\n /** @default JSON.parse */\n decode?: Decoder<K, V>\n}\n\nexport class SimpleStoreRedis<K extends string, V extends Value>\n implements SimpleStore<K, V>\n{\n constructor(\n protected readonly redis: Redis,\n protected readonly options: SimpleStoreRedisOptions<K, V>,\n ) {\n if (!options.keyPrefix) {\n throw new TypeError(`keyPrefix must be a non-empty string`)\n }\n if (options.ttl != null && options.ttl <= 0) {\n throw new TypeError(`ttl must be greater than 0`)\n }\n }\n\n protected encodeKey(key: K): string {\n return `${this.options.keyPrefix}${key satisfies string}`\n }\n\n async get(key: K, options?: GetOptions): Promise<V | undefined> {\n const eKey = this.encodeKey(key)\n const eValue = await this.redis.get(eKey)\n if (eValue == null) return undefined\n options?.signal?.throwIfAborted()\n const { decode = defaultDecoder as Decoder<any, V> } = this.options\n return decode(eValue, key)\n }\n\n async set(key: K, value: V): Promise<void> {\n const eKey = this.encodeKey(key)\n const { encode = defaultEncoder, ttl } = this.options\n const eValue = await encode(value, key)\n if (ttl) await this.redis.set(eKey, eValue, 'PX', ttl)\n else await this.redis.set(eKey, eValue)\n }\n\n async del(key: K): Promise<void> {\n const eKey = this.encodeKey(key)\n await this.redis.del(eKey)\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,cAAc,GAAwB,CAAC,KAAK,EAAE,EAAE,CAC3D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AACvB,MAAM,CAAC,MAAM,cAAc,GAAwB,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AAY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C,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;;YACjD,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAChC,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;CACF","sourcesContent":["import type { Redis } from 'ioredis'\nimport type {\n Awaitable,\n GetOptions,\n SimpleStore,\n Value,\n} from '@atproto-labs/simple-store'\n\nexport type { Awaitable, GetOptions, SimpleStore, Value }\n\nexport type Encoder<K extends string, V extends Value> = (\n value: V,\n key: K,\n) => Awaitable<string>\nexport type Decoder<K extends string, V extends Value> = (\n value: string,\n key: K,\n) => Awaitable<V>\n\nexport const defaultEncoder: Encoder<any, Value> = (value) =>\n JSON.stringify(value)\nexport const defaultDecoder: Decoder<any, Value> = (value) => JSON.parse(value)\n\nexport type SimpleStoreRedisOptions<K extends string, V extends Value> = {\n keyPrefix: string\n /** In milliseconds */\n ttl?: number\n /** @default JSON.stringify */\n encode?: Encoder<K, V>\n /** @default JSON.parse */\n decode?: Decoder<K, V>\n}\n\nexport class SimpleStoreRedis<K extends string, V extends Value>\n implements SimpleStore<K, V>\n{\n constructor(\n protected readonly redis: Redis,\n protected readonly options: SimpleStoreRedisOptions<K, V>,\n ) {\n if (!options.keyPrefix) {\n throw new TypeError(`keyPrefix must be a non-empty string`)\n }\n if (options.ttl != null && options.ttl <= 0) {\n throw new TypeError(`ttl must be greater than 0`)\n }\n }\n\n protected encodeKey(key: K): string {\n return `${this.options.keyPrefix}${key satisfies string}`\n }\n\n async get(key: K, options?: GetOptions): Promise<V | undefined> {\n const eKey = this.encodeKey(key)\n const eValue = await this.redis.get(eKey)\n if (eValue == null) return undefined\n options?.signal?.throwIfAborted()\n const { decode = defaultDecoder as Decoder<any, V> } = this.options\n return decode(eValue, key)\n }\n\n async set(key: K, value: V): Promise<void> {\n const eKey = this.encodeKey(key)\n const { encode = defaultEncoder, ttl } = this.options\n const eValue = await encode(value, key)\n if (ttl) await this.redis.set(eKey, eValue, 'PX', ttl)\n else await this.redis.set(eKey, eValue)\n }\n\n async del(key: K): Promise<void> {\n const eKey = this.encodeKey(key)\n await this.redis.del(eKey)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,6 @@
1
1
  {
2
2
  "name": "@atproto-labs/simple-store-redis",
3
- "version": "0.1.1",
4
- "engines": {
5
- "node": ">=22"
6
- },
3
+ "version": "0.1.3",
7
4
  "license": "MIT",
8
5
  "description": "Redis based simple-store implementation",
9
6
  "keywords": [
@@ -17,6 +14,10 @@
17
14
  "url": "https://github.com/bluesky-social/atproto",
18
15
  "directory": "packages/internal/simple-store-redis"
19
16
  },
17
+ "files": [
18
+ "./dist",
19
+ "./CHANGELOG.md"
20
+ ],
20
21
  "type": "module",
21
22
  "exports": {
22
23
  ".": {
@@ -24,10 +25,12 @@
24
25
  "default": "./dist/index.js"
25
26
  }
26
27
  },
28
+ "engines": {
29
+ "node": ">=22"
30
+ },
27
31
  "dependencies": {
28
- "@atproto-labs/simple-store": "^0.4.1"
32
+ "@atproto-labs/simple-store": "^0.4.3"
29
33
  },
30
- "devDependencies": {},
31
34
  "peerDependencies": {
32
35
  "ioredis": "^5.3.2"
33
36
  },
package/src/index.ts DELETED
@@ -1,74 +0,0 @@
1
- import type { Redis } from 'ioredis'
2
- import {
3
- Awaitable,
4
- GetOptions,
5
- SimpleStore,
6
- Value,
7
- } from '@atproto-labs/simple-store'
8
-
9
- export type { Awaitable, GetOptions, SimpleStore, Value }
10
-
11
- export type Encoder<K extends string, V extends Value> = (
12
- value: V,
13
- key: K,
14
- ) => Awaitable<string>
15
- export type Decoder<K extends string, V extends Value> = (
16
- value: string,
17
- key: K,
18
- ) => Awaitable<V>
19
-
20
- export const defaultEncoder: Encoder<any, Value> = (value) =>
21
- JSON.stringify(value)
22
- export const defaultDecoder: Decoder<any, Value> = (value) => JSON.parse(value)
23
-
24
- export type SimpleStoreRedisOptions<K extends string, V extends Value> = {
25
- keyPrefix: string
26
- /** In milliseconds */
27
- ttl?: number
28
- /** @default JSON.stringify */
29
- encode?: Encoder<K, V>
30
- /** @default JSON.parse */
31
- decode?: Decoder<K, V>
32
- }
33
-
34
- export class SimpleStoreRedis<K extends string, V extends Value>
35
- implements SimpleStore<K, V>
36
- {
37
- constructor(
38
- protected readonly redis: Redis,
39
- protected readonly options: SimpleStoreRedisOptions<K, V>,
40
- ) {
41
- if (!options.keyPrefix) {
42
- throw new TypeError(`keyPrefix must be a non-empty string`)
43
- }
44
- if (options.ttl != null && options.ttl <= 0) {
45
- throw new TypeError(`ttl must be greater than 0`)
46
- }
47
- }
48
-
49
- protected encodeKey(key: K): string {
50
- return `${this.options.keyPrefix}${key satisfies string}`
51
- }
52
-
53
- async get(key: K, options?: GetOptions): Promise<V | undefined> {
54
- const eKey = this.encodeKey(key)
55
- const eValue = await this.redis.get(eKey)
56
- if (eValue == null) return undefined
57
- options?.signal?.throwIfAborted()
58
- const { decode = defaultDecoder as Decoder<any, V> } = this.options
59
- return decode(eValue, key)
60
- }
61
-
62
- async set(key: K, value: V): Promise<void> {
63
- const eKey = this.encodeKey(key)
64
- const { encode = defaultEncoder, ttl } = this.options
65
- const eValue = await encode(value, key)
66
- if (ttl) await this.redis.set(eKey, eValue, 'PX', ttl)
67
- else await this.redis.set(eKey, eValue)
68
- }
69
-
70
- async del(key: K): Promise<void> {
71
- const eKey = this.encodeKey(key)
72
- await this.redis.del(eKey)
73
- }
74
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig/node.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- },
7
- "include": ["./src"],
8
- }
@@ -1 +0,0 @@
1
- {"version":"7.0.0-dev.20260614.1","root":["./src/index.ts"]}
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "include": [],
3
- "references": [{ "path": "./tsconfig.build.json" }],
4
- }