@redis/json 1.0.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/README.md +80 -0
- package/dist/commands/ARRAPPEND.d.ts +4 -0
- package/dist/commands/ARRAPPEND.js +13 -0
- package/dist/commands/ARRINDEX.d.ts +5 -0
- package/dist/commands/ARRINDEX.js +17 -0
- package/dist/commands/ARRINSERT.d.ts +4 -0
- package/dist/commands/ARRINSERT.js +13 -0
- package/dist/commands/ARRLEN.d.ts +4 -0
- package/dist/commands/ARRLEN.js +13 -0
- package/dist/commands/ARRPOP.d.ts +4 -0
- package/dist/commands/ARRPOP.js +25 -0
- package/dist/commands/ARRTRIM.d.ts +3 -0
- package/dist/commands/ARRTRIM.js +8 -0
- package/dist/commands/DEBUG_MEMORY.d.ts +3 -0
- package/dist/commands/DEBUG_MEMORY.js +12 -0
- package/dist/commands/DEL.d.ts +3 -0
- package/dist/commands/DEL.js +12 -0
- package/dist/commands/FORGET.d.ts +3 -0
- package/dist/commands/FORGET.js +12 -0
- package/dist/commands/GET.d.ts +11 -0
- package/dist/commands/GET.js +28 -0
- package/dist/commands/MGET.d.ts +4 -0
- package/dist/commands/MGET.js +17 -0
- package/dist/commands/NUMINCRBY.d.ts +3 -0
- package/dist/commands/NUMINCRBY.js +10 -0
- package/dist/commands/NUMMULTBY.d.ts +3 -0
- package/dist/commands/NUMMULTBY.js +10 -0
- package/dist/commands/OBJKEYS.d.ts +3 -0
- package/dist/commands/OBJKEYS.js +12 -0
- package/dist/commands/OBJLEN.d.ts +3 -0
- package/dist/commands/OBJLEN.js +12 -0
- package/dist/commands/RESP.d.ts +5 -0
- package/dist/commands/RESP.js +12 -0
- package/dist/commands/SET.d.ts +11 -0
- package/dist/commands/SET.js +16 -0
- package/dist/commands/STRAPPEND.d.ts +6 -0
- package/dist/commands/STRAPPEND.js +16 -0
- package/dist/commands/STRLEN.d.ts +4 -0
- package/dist/commands/STRLEN.js +13 -0
- package/dist/commands/TYPE.d.ts +3 -0
- package/dist/commands/TYPE.js +12 -0
- package/dist/commands/index.d.ts +74 -0
- package/dist/commands/index.js +83 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @redis/json
|
|
2
|
+
|
|
3
|
+
This package provides support for the [RedisJSON](https://redisjson.io) module, which adds JSON as a native data type to Redis. It extends the [Node Redis client](https://github.com/redis/node-redis) to include functions for each of the RedisJSON commands.
|
|
4
|
+
|
|
5
|
+
To use these extra commands, your Redis server must have the RedisJSON module installed.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
For a complete example, see [`managing-json.js`](https://github.com/redis/node-redis/blob/master/examples/managing-json.js) in the Node Redis examples folder.
|
|
10
|
+
|
|
11
|
+
### Storing JSON Documents in Redis
|
|
12
|
+
|
|
13
|
+
The [`JSON.SET`](https://oss.redis.com/redisjson/commands/#jsonset) command stores a JSON value at a given JSON Path in a Redis key.
|
|
14
|
+
|
|
15
|
+
Here, we'll store a JSON document in the root of the Redis key "`mydoc`":
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { createClient } from 'redis';
|
|
19
|
+
|
|
20
|
+
...
|
|
21
|
+
await client.json.set('noderedis:jsondata', '$', {
|
|
22
|
+
name: 'Roberta McDonald',
|
|
23
|
+
pets: [
|
|
24
|
+
{
|
|
25
|
+
name: 'Rex',
|
|
26
|
+
species: 'dog',
|
|
27
|
+
age: 3,
|
|
28
|
+
isMammal: true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'Goldie',
|
|
32
|
+
species: 'fish',
|
|
33
|
+
age: 2,
|
|
34
|
+
isMammal: false
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For more information about RedisJSON's path syntax, [check out the documentation](https://oss.redis.com/redisjson/path/).
|
|
41
|
+
|
|
42
|
+
### Retrieving JSON Documents from Redis
|
|
43
|
+
|
|
44
|
+
With RedisJSON, we can retrieve all or part(s) of a JSON document using the [`JSON.GET`]() command and one or more JSON Paths. Let's get the name and age of one of the pets:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const results = await client.json.get('noderedis:jsondata', {
|
|
48
|
+
path: [
|
|
49
|
+
'.pets[1].name',
|
|
50
|
+
'.pets[1].age'
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`results` will contain the following:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
{ '.pets[1].name': 'Goldie', '.pets[1].age': 2 }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Performing Atomic Updates on JSON Documents Stored in Redis
|
|
62
|
+
|
|
63
|
+
RedisJSON includes commands that can atomically update values in a JSON document, in place in Redis without having to first retrieve the entire document.
|
|
64
|
+
|
|
65
|
+
Using the [`JSON.NUMINCRBY`](https://oss.redis.com/redisjson/commands/#jsonnumincrby) command, we can update the age of one of the pets like this:
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
await client.json.numIncrBy('noderedis:jsondata', '.pets[1].age', 1);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
And we can add a new object to the pets array with the [`JSON.ARRAPPEND`](https://oss.redis.com/redisjson/commands/#jsonarrappend) command:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
await client.json.arrAppend('noderedis:jsondata', '.pets', {
|
|
75
|
+
name: 'Robin',
|
|
76
|
+
species: 'bird',
|
|
77
|
+
age: 1,
|
|
78
|
+
isMammal: false
|
|
79
|
+
});
|
|
80
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(key, path, ...jsons) {
|
|
7
|
+
const args = ['JSON.ARRAPPEND', key, path];
|
|
8
|
+
for (const json of jsons) {
|
|
9
|
+
args.push((0, _1.transformRedisJsonArgument)(json));
|
|
10
|
+
}
|
|
11
|
+
return args;
|
|
12
|
+
}
|
|
13
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RedisJSON } from '.';
|
|
2
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
3
|
+
export declare const IS_READ_ONLY = true;
|
|
4
|
+
export declare function transformArguments(key: string, path: string, json: RedisJSON, start?: number, stop?: number): Array<string>;
|
|
5
|
+
export declare function transformReply(): number | Array<number>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
exports.IS_READ_ONLY = true;
|
|
7
|
+
function transformArguments(key, path, json, start, stop) {
|
|
8
|
+
const args = ['JSON.ARRINDEX', key, path, (0, _1.transformRedisJsonArgument)(json)];
|
|
9
|
+
if (start !== undefined && start !== null) {
|
|
10
|
+
args.push(start.toString());
|
|
11
|
+
if (stop !== undefined && stop !== null) {
|
|
12
|
+
args.push(stop.toString());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
17
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(key, path, index, ...jsons) {
|
|
7
|
+
const args = ['JSON.ARRINSERT', key, path, index.toString()];
|
|
8
|
+
for (const json of jsons) {
|
|
9
|
+
args.push((0, _1.transformRedisJsonArgument)(json));
|
|
10
|
+
}
|
|
11
|
+
return args;
|
|
12
|
+
}
|
|
13
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
exports.IS_READ_ONLY = true;
|
|
6
|
+
function transformArguments(key, path) {
|
|
7
|
+
const args = ['JSON.ARRLEN', key];
|
|
8
|
+
if (path) {
|
|
9
|
+
args.push(path);
|
|
10
|
+
}
|
|
11
|
+
return args;
|
|
12
|
+
}
|
|
13
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RedisJSON } from '.';
|
|
2
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
3
|
+
export declare function transformArguments(key: string, path?: string, index?: number): Array<string>;
|
|
4
|
+
export declare function transformReply(reply: null | string | Array<null | string>): null | RedisJSON | Array<RedisJSON>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(key, path, index) {
|
|
7
|
+
const args = ['JSON.ARRPOP', key];
|
|
8
|
+
if (path) {
|
|
9
|
+
args.push(path);
|
|
10
|
+
if (index !== undefined && index !== null) {
|
|
11
|
+
args.push(index.toString());
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return args;
|
|
15
|
+
}
|
|
16
|
+
exports.transformArguments = transformArguments;
|
|
17
|
+
function transformReply(reply) {
|
|
18
|
+
if (reply === null)
|
|
19
|
+
return null;
|
|
20
|
+
if (Array.isArray(reply)) {
|
|
21
|
+
return reply.map(_1.transformRedisJsonNullReply);
|
|
22
|
+
}
|
|
23
|
+
return (0, _1.transformRedisJsonNullReply)(reply);
|
|
24
|
+
}
|
|
25
|
+
exports.transformReply = transformReply;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path, start, stop) {
|
|
6
|
+
return ['JSON.ARRTRIM', key, path, start.toString(), stop.toString()];
|
|
7
|
+
}
|
|
8
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 2;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.DEBUG', 'MEMORY', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.DEL', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.FORGET', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
2
|
+
export declare const IS_READ_ONLY = true;
|
|
3
|
+
interface GetOptions {
|
|
4
|
+
path?: string | Array<string>;
|
|
5
|
+
INDENT?: string;
|
|
6
|
+
NEWLINE?: string;
|
|
7
|
+
SPACE?: string;
|
|
8
|
+
NOESCAPE?: true;
|
|
9
|
+
}
|
|
10
|
+
export declare function transformArguments(key: string, options?: GetOptions): Array<string>;
|
|
11
|
+
export { transformRedisJsonNullReply as transformReply } from '.';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformReply = exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
exports.IS_READ_ONLY = true;
|
|
7
|
+
function transformArguments(key, options) {
|
|
8
|
+
const args = ['JSON.GET', key];
|
|
9
|
+
if (options?.path) {
|
|
10
|
+
(0, generic_transformers_1.pushVerdictArguments)(args, options.path);
|
|
11
|
+
}
|
|
12
|
+
if (options?.INDENT) {
|
|
13
|
+
args.push('INDENT', options.INDENT);
|
|
14
|
+
}
|
|
15
|
+
if (options?.NEWLINE) {
|
|
16
|
+
args.push('NEWLINE', options.NEWLINE);
|
|
17
|
+
}
|
|
18
|
+
if (options?.SPACE) {
|
|
19
|
+
args.push('SPACE', options.SPACE);
|
|
20
|
+
}
|
|
21
|
+
if (options?.NOESCAPE) {
|
|
22
|
+
args.push('NOESCAPE');
|
|
23
|
+
}
|
|
24
|
+
return args;
|
|
25
|
+
}
|
|
26
|
+
exports.transformArguments = transformArguments;
|
|
27
|
+
var _1 = require(".");
|
|
28
|
+
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return _1.transformRedisJsonNullReply; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(keys, path) {
|
|
7
|
+
return [
|
|
8
|
+
'JSON.MGET',
|
|
9
|
+
...keys,
|
|
10
|
+
path
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
exports.transformArguments = transformArguments;
|
|
14
|
+
function transformReply(reply) {
|
|
15
|
+
return reply.map(_1.transformRedisJsonNullReply);
|
|
16
|
+
}
|
|
17
|
+
exports.transformReply = transformReply;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path, by) {
|
|
6
|
+
return ['JSON.NUMINCRBY', key, path, by.toString()];
|
|
7
|
+
}
|
|
8
|
+
exports.transformArguments = transformArguments;
|
|
9
|
+
var _1 = require(".");
|
|
10
|
+
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return _1.transformNumbersReply; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformReply = exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path, by) {
|
|
6
|
+
return ['JSON.NUMMULTBY', key, path, by.toString()];
|
|
7
|
+
}
|
|
8
|
+
exports.transformArguments = transformArguments;
|
|
9
|
+
var _1 = require(".");
|
|
10
|
+
Object.defineProperty(exports, "transformReply", { enumerable: true, get: function () { return _1.transformNumbersReply; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.OBJKEYS', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.OBJLEN', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.RESP', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RedisJSON } from '.';
|
|
2
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
3
|
+
interface NX {
|
|
4
|
+
NX: true;
|
|
5
|
+
}
|
|
6
|
+
interface XX {
|
|
7
|
+
XX: true;
|
|
8
|
+
}
|
|
9
|
+
export declare function transformArguments(key: string, path: string, json: RedisJSON, options?: NX | XX): Array<string>;
|
|
10
|
+
export declare function transformReply(): 'OK' | null;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(key, path, json, options) {
|
|
7
|
+
const args = ['JSON.SET', key, path, (0, _1.transformRedisJsonArgument)(json)];
|
|
8
|
+
if (options?.NX) {
|
|
9
|
+
args.push('NX');
|
|
10
|
+
}
|
|
11
|
+
else if (options?.XX) {
|
|
12
|
+
args.push('XX');
|
|
13
|
+
}
|
|
14
|
+
return args;
|
|
15
|
+
}
|
|
16
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const FIRST_KEY_INDEX = 1;
|
|
2
|
+
declare type AppendArguments = [key: string, append: string];
|
|
3
|
+
declare type AppendWithPathArguments = [key: string, path: string, append: string];
|
|
4
|
+
export declare function transformArguments(...[key, pathOrAppend, append]: AppendArguments | AppendWithPathArguments): Array<string>;
|
|
5
|
+
export declare function transformReply(): number | Array<number>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
6
|
+
function transformArguments(...[key, pathOrAppend, append]) {
|
|
7
|
+
const args = ['JSON.STRAPPEND', key];
|
|
8
|
+
if (append !== undefined && append !== null) {
|
|
9
|
+
args.push(pathOrAppend, (0, _1.transformRedisJsonArgument)(append));
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
args.push((0, _1.transformRedisJsonArgument)(pathOrAppend));
|
|
13
|
+
}
|
|
14
|
+
return args;
|
|
15
|
+
}
|
|
16
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.IS_READ_ONLY = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
exports.IS_READ_ONLY = true;
|
|
6
|
+
function transformArguments(key, path) {
|
|
7
|
+
const args = ['JSON.STRLEN', key];
|
|
8
|
+
if (path) {
|
|
9
|
+
args.push(path);
|
|
10
|
+
}
|
|
11
|
+
return args;
|
|
12
|
+
}
|
|
13
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformArguments = exports.FIRST_KEY_INDEX = void 0;
|
|
4
|
+
exports.FIRST_KEY_INDEX = 1;
|
|
5
|
+
function transformArguments(key, path) {
|
|
6
|
+
const args = ['JSON.TYPE', key];
|
|
7
|
+
if (path) {
|
|
8
|
+
args.push(path);
|
|
9
|
+
}
|
|
10
|
+
return args;
|
|
11
|
+
}
|
|
12
|
+
exports.transformArguments = transformArguments;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as ARRAPPEND from './ARRAPPEND';
|
|
2
|
+
import * as ARRINDEX from './ARRINDEX';
|
|
3
|
+
import * as ARRINSERT from './ARRINSERT';
|
|
4
|
+
import * as ARRLEN from './ARRLEN';
|
|
5
|
+
import * as ARRPOP from './ARRPOP';
|
|
6
|
+
import * as ARRTRIM from './ARRTRIM';
|
|
7
|
+
import * as DEBUG_MEMORY from './DEBUG_MEMORY';
|
|
8
|
+
import * as DEL from './DEL';
|
|
9
|
+
import * as FORGET from './FORGET';
|
|
10
|
+
import * as GET from './GET';
|
|
11
|
+
import * as MGET from './MGET';
|
|
12
|
+
import * as NUMINCRBY from './NUMINCRBY';
|
|
13
|
+
import * as NUMMULTBY from './NUMMULTBY';
|
|
14
|
+
import * as OBJKEYS from './OBJKEYS';
|
|
15
|
+
import * as OBJLEN from './OBJLEN';
|
|
16
|
+
import * as RESP from './RESP';
|
|
17
|
+
import * as SET from './SET';
|
|
18
|
+
import * as STRAPPEND from './STRAPPEND';
|
|
19
|
+
import * as STRLEN from './STRLEN';
|
|
20
|
+
import * as TYPE from './TYPE';
|
|
21
|
+
declare const _default: {
|
|
22
|
+
ARRAPPEND: typeof ARRAPPEND;
|
|
23
|
+
arrAppend: typeof ARRAPPEND;
|
|
24
|
+
ARRINDEX: typeof ARRINDEX;
|
|
25
|
+
arrIndex: typeof ARRINDEX;
|
|
26
|
+
ARRINSERT: typeof ARRINSERT;
|
|
27
|
+
arrInsert: typeof ARRINSERT;
|
|
28
|
+
ARRLEN: typeof ARRLEN;
|
|
29
|
+
arrLen: typeof ARRLEN;
|
|
30
|
+
ARRPOP: typeof ARRPOP;
|
|
31
|
+
arrPop: typeof ARRPOP;
|
|
32
|
+
ARRTRIM: typeof ARRTRIM;
|
|
33
|
+
arrTrim: typeof ARRTRIM;
|
|
34
|
+
DEBUG_MEMORY: typeof DEBUG_MEMORY;
|
|
35
|
+
debugMemory: typeof DEBUG_MEMORY;
|
|
36
|
+
DEL: typeof DEL;
|
|
37
|
+
del: typeof DEL;
|
|
38
|
+
FORGET: typeof FORGET;
|
|
39
|
+
forget: typeof FORGET;
|
|
40
|
+
GET: typeof GET;
|
|
41
|
+
get: typeof GET;
|
|
42
|
+
MGET: typeof MGET;
|
|
43
|
+
mGet: typeof MGET;
|
|
44
|
+
NUMINCRBY: typeof NUMINCRBY;
|
|
45
|
+
numIncrBy: typeof NUMINCRBY;
|
|
46
|
+
NUMMULTBY: typeof NUMMULTBY;
|
|
47
|
+
numMultBy: typeof NUMMULTBY;
|
|
48
|
+
OBJKEYS: typeof OBJKEYS;
|
|
49
|
+
objKeys: typeof OBJKEYS;
|
|
50
|
+
OBJLEN: typeof OBJLEN;
|
|
51
|
+
objLen: typeof OBJLEN;
|
|
52
|
+
RESP: typeof RESP;
|
|
53
|
+
resp: typeof RESP;
|
|
54
|
+
SET: typeof SET;
|
|
55
|
+
set: typeof SET;
|
|
56
|
+
STRAPPEND: typeof STRAPPEND;
|
|
57
|
+
strAppend: typeof STRAPPEND;
|
|
58
|
+
STRLEN: typeof STRLEN;
|
|
59
|
+
strLen: typeof STRLEN;
|
|
60
|
+
TYPE: typeof TYPE;
|
|
61
|
+
type: typeof TYPE;
|
|
62
|
+
};
|
|
63
|
+
export default _default;
|
|
64
|
+
interface RedisJSONArray extends Array<RedisJSON> {
|
|
65
|
+
}
|
|
66
|
+
interface RedisJSONObject {
|
|
67
|
+
[key: string]: RedisJSON;
|
|
68
|
+
[key: number]: RedisJSON;
|
|
69
|
+
}
|
|
70
|
+
export declare type RedisJSON = null | boolean | number | string | Date | RedisJSONArray | RedisJSONObject;
|
|
71
|
+
export declare function transformRedisJsonArgument(json: RedisJSON): string;
|
|
72
|
+
export declare function transformRedisJsonReply(json: string): RedisJSON;
|
|
73
|
+
export declare function transformRedisJsonNullReply(json: string | null): RedisJSON | null;
|
|
74
|
+
export declare function transformNumbersReply(reply: string): number | Array<number>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformNumbersReply = exports.transformRedisJsonNullReply = exports.transformRedisJsonReply = exports.transformRedisJsonArgument = void 0;
|
|
4
|
+
const ARRAPPEND = require("./ARRAPPEND");
|
|
5
|
+
const ARRINDEX = require("./ARRINDEX");
|
|
6
|
+
const ARRINSERT = require("./ARRINSERT");
|
|
7
|
+
const ARRLEN = require("./ARRLEN");
|
|
8
|
+
const ARRPOP = require("./ARRPOP");
|
|
9
|
+
const ARRTRIM = require("./ARRTRIM");
|
|
10
|
+
const DEBUG_MEMORY = require("./DEBUG_MEMORY");
|
|
11
|
+
const DEL = require("./DEL");
|
|
12
|
+
const FORGET = require("./FORGET");
|
|
13
|
+
const GET = require("./GET");
|
|
14
|
+
const MGET = require("./MGET");
|
|
15
|
+
const NUMINCRBY = require("./NUMINCRBY");
|
|
16
|
+
const NUMMULTBY = require("./NUMMULTBY");
|
|
17
|
+
const OBJKEYS = require("./OBJKEYS");
|
|
18
|
+
const OBJLEN = require("./OBJLEN");
|
|
19
|
+
const RESP = require("./RESP");
|
|
20
|
+
const SET = require("./SET");
|
|
21
|
+
const STRAPPEND = require("./STRAPPEND");
|
|
22
|
+
const STRLEN = require("./STRLEN");
|
|
23
|
+
const TYPE = require("./TYPE");
|
|
24
|
+
exports.default = {
|
|
25
|
+
ARRAPPEND,
|
|
26
|
+
arrAppend: ARRAPPEND,
|
|
27
|
+
ARRINDEX,
|
|
28
|
+
arrIndex: ARRINDEX,
|
|
29
|
+
ARRINSERT,
|
|
30
|
+
arrInsert: ARRINSERT,
|
|
31
|
+
ARRLEN,
|
|
32
|
+
arrLen: ARRLEN,
|
|
33
|
+
ARRPOP,
|
|
34
|
+
arrPop: ARRPOP,
|
|
35
|
+
ARRTRIM,
|
|
36
|
+
arrTrim: ARRTRIM,
|
|
37
|
+
DEBUG_MEMORY,
|
|
38
|
+
debugMemory: DEBUG_MEMORY,
|
|
39
|
+
DEL,
|
|
40
|
+
del: DEL,
|
|
41
|
+
FORGET,
|
|
42
|
+
forget: FORGET,
|
|
43
|
+
GET,
|
|
44
|
+
get: GET,
|
|
45
|
+
MGET,
|
|
46
|
+
mGet: MGET,
|
|
47
|
+
NUMINCRBY,
|
|
48
|
+
numIncrBy: NUMINCRBY,
|
|
49
|
+
NUMMULTBY,
|
|
50
|
+
numMultBy: NUMMULTBY,
|
|
51
|
+
OBJKEYS,
|
|
52
|
+
objKeys: OBJKEYS,
|
|
53
|
+
OBJLEN,
|
|
54
|
+
objLen: OBJLEN,
|
|
55
|
+
RESP,
|
|
56
|
+
resp: RESP,
|
|
57
|
+
SET,
|
|
58
|
+
set: SET,
|
|
59
|
+
STRAPPEND,
|
|
60
|
+
strAppend: STRAPPEND,
|
|
61
|
+
STRLEN,
|
|
62
|
+
strLen: STRLEN,
|
|
63
|
+
TYPE,
|
|
64
|
+
type: TYPE
|
|
65
|
+
};
|
|
66
|
+
function transformRedisJsonArgument(json) {
|
|
67
|
+
return JSON.stringify(json);
|
|
68
|
+
}
|
|
69
|
+
exports.transformRedisJsonArgument = transformRedisJsonArgument;
|
|
70
|
+
function transformRedisJsonReply(json) {
|
|
71
|
+
return JSON.parse(json);
|
|
72
|
+
}
|
|
73
|
+
exports.transformRedisJsonReply = transformRedisJsonReply;
|
|
74
|
+
function transformRedisJsonNullReply(json) {
|
|
75
|
+
if (json === null)
|
|
76
|
+
return null;
|
|
77
|
+
return transformRedisJsonReply(json);
|
|
78
|
+
}
|
|
79
|
+
exports.transformRedisJsonNullReply = transformRedisJsonNullReply;
|
|
80
|
+
function transformNumbersReply(reply) {
|
|
81
|
+
return JSON.parse(reply);
|
|
82
|
+
}
|
|
83
|
+
exports.transformNumbersReply = transformNumbersReply;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './commands';
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@redis/json",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "nyc -r text-summary -r lcov mocha -r source-map-support/register -r ts-node/register './lib/**/*.spec.ts'",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"documentation": "typedoc"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@redis/client": "^1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
20
|
+
"@redis/test-utils": "*",
|
|
21
|
+
"@types/node": "^17.0.31",
|
|
22
|
+
"nyc": "^15.1.0",
|
|
23
|
+
"release-it": "^15.0.0",
|
|
24
|
+
"source-map-support": "^0.5.21",
|
|
25
|
+
"ts-node": "^10.7.0",
|
|
26
|
+
"typedoc": "^0.22.15",
|
|
27
|
+
"typescript": "^4.6.4"
|
|
28
|
+
}
|
|
29
|
+
}
|