@owlmeans/redis-resource 0.1.18-rc.8 → 0.1.18

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/build/types.d.ts CHANGED
@@ -1,24 +1,39 @@
1
- import type { LifecycleOptions, Resource, ResourceDbService, ResourceRecord } from '@owlmeans/resource';
2
- import type { RedisCommander, Redis, Cluster } from 'ioredis';
1
+ import type { PubSubResource, Resource, ResourceDbService, ResourceRecord, StreamResource, WatchableResource } from '@owlmeans/resource';
2
+ import type { RedisCommander, Redis, Cluster, RedisOptions, ClusterNode, ClusterOptions } from 'ioredis';
3
3
  export interface RedisDbService extends ResourceDbService<RedisDb, RedisClient> {
4
+ /**
5
+ * The connection settings behind `alias`, in the shape a client is built from.
6
+ *
7
+ * A pooled client cannot be shared by everything: a consumer that blocks on a read holds the
8
+ * connection for the duration, so anything doing that needs one of its own. Handing out the
9
+ * settings keeps that decision with the caller while the configuration stays here — the
10
+ * alternative is every consumer re-deriving them from `cfg.dbs` and drifting.
11
+ */
12
+ options: (alias?: string) => RedisConnection;
13
+ }
14
+ /** Either a single-node or a cluster connection, plus the key namespace `alias` resolves to. */
15
+ export interface RedisConnection {
16
+ single?: RedisOptions;
17
+ cluster?: {
18
+ nodes: ClusterNode[];
19
+ options: ClusterOptions;
20
+ };
21
+ prefix: string;
4
22
  }
5
23
  export type RedisClient = Redis | Cluster;
6
24
  export interface RedisDb {
7
25
  client: RedisCommander;
8
26
  prefix: string;
9
27
  }
10
- export interface RedisResource<T extends ResourceRecord> extends Resource<T> {
28
+ /**
29
+ * A `Resource` over redis strings — one JSON document per namespaced key — composed with the
30
+ * three capabilities redis actually has: pub/sub channels, keyspace watching of a single record,
31
+ * and streams with consumer groups.
32
+ */
33
+ export interface RedisResource<T extends ResourceRecord> extends Resource<T>, PubSubResource<T>, WatchableResource<T>, StreamResource<T> {
11
34
  name?: string;
12
35
  db: RedisDb;
36
+ /** The namespaced redis key for `key`, or the namespace's glob when `key` is omitted. */
13
37
  key: (key?: string) => string;
14
- subscribe: <Type extends T>(handler: (value: Type) => Promise<void>, key?: SubOpts) => Promise<() => Promise<void>>;
15
- publish: <Type extends T>(value: Type, key?: string) => Promise<void>;
16
- stream: <Type extends T>(key: string, data: Type) => Promise<void>;
17
- consume: <Type extends T>(key: string, group?: string, consumer?: string) => AsyncGenerator<Type>;
18
- }
19
- export type SubOpts = number | string | boolean | SubscriptionOptions;
20
- export interface SubscriptionOptions extends LifecycleOptions {
21
- key?: string;
22
- once?: boolean;
23
38
  }
24
39
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEvG,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAE7D,MAAM,WAAW,cAAe,SAAQ,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC;CAC9E;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,CAAA;AAEzC,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,cAAc,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,EAAE,EAAE,OAAO,CAAA;IAEX,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAE7B,SAAS,EAAE,CAAC,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,M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EAAE;QAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAAC,OAAO,EAAE,cAAc,CAAA;KAAE,CAAA;IAC3D,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,CAAA;AAEzC,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,cAAc,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,cAAc,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC,EAC1E,cAAc,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,EAAE,EAAE,OAAO,CAAA;IAEX,yFAAyF;IACzF,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;CAC9B"}
@@ -0,0 +1,4 @@
1
+ import type { ServerConfig, ServerContext } from '@owlmeans/server-context';
2
+ export type Config = ServerConfig;
3
+ export type Context<C extends Config = Config> = ServerContext<C>;
4
+ //# sourceMappingURL=types.local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE3E,MAAM,MAAM,MAAM,GAAG,YAAY,CAAA;AAEjC,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAE/D,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,mBAalD,CAAA"}
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAE/D,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,mBAalD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/redis-resource",
3
- "version": "0.1.18-rc.8",
3
+ "version": "0.1.18",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -25,14 +25,15 @@
25
25
  "ioredis": "*"
26
26
  },
27
27
  "dependencies": {
28
- "@owlmeans/basic-ids": "^0.1.18-rc.7",
29
- "@owlmeans/context": "^0.1.18-rc.6",
30
- "@owlmeans/resource": "^0.1.18-rc.7",
31
- "@owlmeans/server-context": "^0.1.18-rc.8"
28
+ "@owlmeans/basic-ids": "^0.1.18",
29
+ "@owlmeans/context": "^0.1.18",
30
+ "@owlmeans/log": "^0.1.18",
31
+ "@owlmeans/resource": "^0.1.18",
32
+ "@owlmeans/server-context": "^0.1.18"
32
33
  },
33
34
  "devDependencies": {
34
- "@owlmeans/dep-config": "workspace:*",
35
- "@types/node": "^26.1.0",
35
+ "@owlmeans/dep-config": "^0.1.18",
36
+ "@types/node": "^26.6.4",
36
37
  "nodemon": "^3.1.14",
37
38
  "typescript": "^7.0.2"
38
39
  },
package/src/consts.ts CHANGED
@@ -1,4 +1,29 @@
1
-
2
1
  export const DEFAULT_DB_ALIAS = 'redis'
3
2
 
4
- export const DEFAULT_PAGE_SIZE = 10
3
+ /**
4
+ * Redis is UNPAGED: `list()` without a `size` returns every match, and `0` says exactly that.
5
+ * There is no server side LIMIT to fall back on — answering a criteria already walked the whole
6
+ * namespace — so an implied default would only hide records without saving any work.
7
+ */
8
+ export const DEFAULT_PAGE_SIZE = 0
9
+
10
+ /** Keys per SCAN round trip. Bounded so one sweep never blocks the server the way KEYS does. */
11
+ export const SCAN_BATCH = 200
12
+
13
+ /** Keys per MGET / DEL round trip once SCAN has collected them. */
14
+ export const READ_BATCH = 200
15
+
16
+ /** Entries kept in a stream, trimmed approximately (`MAXLEN ~`) so trimming stays O(1)-ish. */
17
+ export const STREAM_MAX_LENGTH = 10000
18
+
19
+ /** How long a stream read blocks before the consumer loops and looks for pending entries. */
20
+ export const DEFAULT_STREAM_BLOCK = 1000
21
+
22
+ /** How long an unacknowledged entry may sit with its consumer before another may reclaim it. */
23
+ export const RECLAIM_IDLE = 60000
24
+
25
+ /** Entries reclaimed per XAUTOCLAIM pass. */
26
+ export const RECLAIM_COUNT = 10
27
+
28
+ /** Length of the generated consumer name when `consume` is not given one. */
29
+ export const CONSUMER_ID_LENGTH = 15