@owlmeans/redis-resource 0.1.18-rc.2 → 0.1.18-rc.21

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/src/types.ts CHANGED
@@ -1,8 +1,26 @@
1
- import type { LifecycleOptions, Resource, ResourceDbService, ResourceRecord } from '@owlmeans/resource'
1
+ import type {
2
+ PubSubResource, Resource, ResourceDbService, ResourceRecord, StreamResource, WatchableResource
3
+ } from '@owlmeans/resource'
2
4
 
3
- import type { RedisCommander, Redis, Cluster } from 'ioredis'
5
+ import type { RedisCommander, Redis, Cluster, RedisOptions, ClusterNode, ClusterOptions } from 'ioredis'
4
6
 
5
7
  export interface RedisDbService extends ResourceDbService<RedisDb, RedisClient> {
8
+ /**
9
+ * The connection settings behind `alias`, in the shape a client is built from.
10
+ *
11
+ * A pooled client cannot be shared by everything: a consumer that blocks on a read holds the
12
+ * connection for the duration, so anything doing that needs one of its own. Handing out the
13
+ * settings keeps that decision with the caller while the configuration stays here — the
14
+ * alternative is every consumer re-deriving them from `cfg.dbs` and drifting.
15
+ */
16
+ options: (alias?: string) => RedisConnection
17
+ }
18
+
19
+ /** Either a single-node or a cluster connection, plus the key namespace `alias` resolves to. */
20
+ export interface RedisConnection {
21
+ single?: RedisOptions
22
+ cluster?: { nodes: ClusterNode[], options: ClusterOptions }
23
+ prefix: string
6
24
  }
7
25
 
8
26
  export type RedisClient = Redis | Cluster
@@ -12,25 +30,17 @@ export interface RedisDb {
12
30
  prefix: string
13
31
  }
14
32
 
15
- export interface RedisResource<T extends ResourceRecord> extends Resource<T> {
33
+ /**
34
+ * A `Resource` over redis strings — one JSON document per namespaced key — composed with the
35
+ * three capabilities redis actually has: pub/sub channels, keyspace watching of a single record,
36
+ * and streams with consumer groups.
37
+ */
38
+ export interface RedisResource<T extends ResourceRecord> extends Resource<T>,
39
+ PubSubResource<T>, WatchableResource<T>, StreamResource<T> {
16
40
  name?: string
17
41
 
18
42
  db: RedisDb
19
43
 
44
+ /** The namespaced redis key for `key`, or the namespace's glob when `key` is omitted. */
20
45
  key: (key?: string) => string
21
-
22
- subscribe: <Type extends T>(handler: (value: Type) => Promise<void>, key?: SubOpts) => Promise<() => Promise<void>>
23
-
24
- publish: <Type extends T>(value: Type, key?: string) => Promise<void>
25
-
26
- stream: <Type extends T>(key: string, data: Type) => Promise<void>
27
-
28
- consume: <Type extends T>(key: string, group?: string, consumer?: string) => AsyncGenerator<Type>
29
- }
30
-
31
- export type SubOpts = number |string | boolean | SubscriptionOptions
32
-
33
- export interface SubscriptionOptions extends LifecycleOptions {
34
- key?: string
35
- once?: boolean
36
46
  }
package/build/.gitkeep DELETED
File without changes
@@ -1,2 +0,0 @@
1
- export * from './options.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './options.js';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { SubOpts, SubscriptionOptions } from '../types.js';
2
- export declare const prepareSubOptions: (opts?: SubOpts) => SubscriptionOptions;
3
- //# sourceMappingURL=options.d.ts.map
@@ -1 +0,0 @@
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,17 +0,0 @@
1
- export const prepareSubOptions = (opts) => {
2
- let _opts = {};
3
- if (typeof opts === 'string') {
4
- _opts.key = opts;
5
- }
6
- else if (typeof opts === 'number') {
7
- _opts.ttl = opts;
8
- }
9
- else if (typeof opts === 'boolean') {
10
- _opts.once = opts;
11
- }
12
- else if (typeof opts === 'object') {
13
- _opts = opts;
14
- }
15
- return _opts;
16
- };
17
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAc,EAAuB,EAAE;IACvE,IAAI,KAAK,GAAwB,EAAE,CAAA;IACnC,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,KAAK,CAAC,GAAG,GAAG,IAAI,CAAA;IAClB,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,KAAK,CAAC,GAAG,GAAG,IAAI,CAAA;IAClB,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,SAAS,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACnB,CAAC;SAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,KAAK,GAAG,IAAI,CAAA;IACd,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
-
2
- export * from './options.js'
@@ -1,17 +0,0 @@
1
-
2
- import type { SubOpts, SubscriptionOptions } from '../types.js'
3
-
4
- export const prepareSubOptions = (opts?: SubOpts): SubscriptionOptions => {
5
- let _opts: SubscriptionOptions = {}
6
- if (typeof opts === 'string') {
7
- _opts.key = opts
8
- } else if (typeof opts === 'number') {
9
- _opts.ttl = opts
10
- } else if (typeof opts === 'boolean') {
11
- _opts.once = opts
12
- } else if (typeof opts === 'object') {
13
- _opts = opts
14
- }
15
-
16
- return _opts
17
- }