@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/README.md +182 -50
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/redis-resource/SKILL.md +96 -31
- package/build/consts.d.ts +20 -1
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +20 -1
- package/build/consts.js.map +1 -1
- package/build/resource.d.ts +11 -2
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +243 -217
- package/build/resource.js.map +1 -1
- package/build/types.d.ts +27 -12
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/consts.ts +27 -2
- package/src/resource.ts +289 -233
- package/src/types.ts +28 -18
- package/build/.gitkeep +0 -0
- package/build/utils/index.d.ts +0 -2
- package/build/utils/index.d.ts.map +0 -1
- package/build/utils/index.js +0 -2
- package/build/utils/index.js.map +0 -1
- package/build/utils/options.d.ts +0 -3
- package/build/utils/options.d.ts.map +0 -1
- package/build/utils/options.js +0 -17
- package/build/utils/options.js.map +0 -1
- package/src/utils/index.ts +0 -2
- package/src/utils/options.ts +0 -17
package/src/types.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
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
|
package/build/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
package/build/utils/index.js
DELETED
package/build/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
package/build/utils/options.d.ts
DELETED
|
@@ -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"}
|
package/build/utils/options.js
DELETED
|
@@ -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"}
|
package/src/utils/index.ts
DELETED
package/src/utils/options.ts
DELETED
|
@@ -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
|
-
}
|