@brimble/consul 0.0.1
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/LICENSE +19 -0
- package/README.md +2423 -0
- package/lib/acl/legacy.d.ts +75 -0
- package/lib/acl/legacy.js +167 -0
- package/lib/acl.d.ts +37 -0
- package/lib/acl.js +49 -0
- package/lib/agent/check.d.ts +113 -0
- package/lib/agent/check.js +164 -0
- package/lib/agent/service.d.ts +63 -0
- package/lib/agent/service.js +113 -0
- package/lib/agent.d.ts +77 -0
- package/lib/agent.js +162 -0
- package/lib/catalog/connect.d.ts +11 -0
- package/lib/catalog/connect.js +37 -0
- package/lib/catalog/node.d.ts +30 -0
- package/lib/catalog/node.js +57 -0
- package/lib/catalog/service.d.ts +32 -0
- package/lib/catalog/service.js +61 -0
- package/lib/catalog.d.ts +118 -0
- package/lib/catalog.js +113 -0
- package/lib/constants.js +21 -0
- package/lib/consul.d.ts +93 -0
- package/lib/consul.js +98 -0
- package/lib/errors.js +29 -0
- package/lib/event.d.ts +43 -0
- package/lib/event.js +91 -0
- package/lib/health.d.ts +77 -0
- package/lib/health.js +126 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +3 -0
- package/lib/intention.d.ts +73 -0
- package/lib/intention.js +180 -0
- package/lib/kv.d.ts +80 -0
- package/lib/kv.js +180 -0
- package/lib/query.d.ts +84 -0
- package/lib/query.js +244 -0
- package/lib/resolver/algorithms.js +127 -0
- package/lib/resolver/dns.js +182 -0
- package/lib/resolver/health.js +51 -0
- package/lib/resolver/metrics.js +199 -0
- package/lib/resolver/scoring.js +95 -0
- package/lib/resolver/types.js +28 -0
- package/lib/resolver.d.ts +76 -0
- package/lib/resolver.js +290 -0
- package/lib/session.d.ts +92 -0
- package/lib/session.js +164 -0
- package/lib/status.d.ts +19 -0
- package/lib/status.js +43 -0
- package/lib/transaction.d.ts +50 -0
- package/lib/transaction.js +58 -0
- package/lib/utils.js +655 -0
- package/lib/watch.d.ts +22 -0
- package/lib/watch.js +183 -0
- package/package.json +55 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "./consul";
|
|
2
|
+
|
|
3
|
+
interface ListOptions extends CommonOptions {}
|
|
4
|
+
|
|
5
|
+
interface IntentionResult {
|
|
6
|
+
ID: string;
|
|
7
|
+
SourceName: string;
|
|
8
|
+
DestinationName: string;
|
|
9
|
+
SourceType?: string;
|
|
10
|
+
Action: "allow" | "deny";
|
|
11
|
+
Description?: string;
|
|
12
|
+
Meta?: Record<string, string>;
|
|
13
|
+
Precedence?: number;
|
|
14
|
+
Permissions?: any[];
|
|
15
|
+
CreateIndex?: number;
|
|
16
|
+
ModifyIndex?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ListResult = IntentionResult[];
|
|
20
|
+
|
|
21
|
+
interface CreateOptions extends CommonOptions {
|
|
22
|
+
sourcename: string;
|
|
23
|
+
destinationname: string;
|
|
24
|
+
action: "allow" | "deny";
|
|
25
|
+
description?: string;
|
|
26
|
+
sourcetype?: string;
|
|
27
|
+
meta?: Record<string, string>;
|
|
28
|
+
precedence?: number;
|
|
29
|
+
permissions?: any[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface CreateResult {
|
|
33
|
+
ID: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface GetOptions extends CommonOptions {
|
|
37
|
+
id: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type GetResult = IntentionResult;
|
|
41
|
+
|
|
42
|
+
interface UpdateOptions extends CreateOptions {
|
|
43
|
+
id: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type UpdateResult = boolean;
|
|
47
|
+
|
|
48
|
+
interface DestroyOptions extends CommonOptions {
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type DestroyResult = boolean;
|
|
53
|
+
|
|
54
|
+
declare class Intention {
|
|
55
|
+
constructor(consul: Consul);
|
|
56
|
+
|
|
57
|
+
consul: Consul;
|
|
58
|
+
|
|
59
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
60
|
+
|
|
61
|
+
create(options: CreateOptions): Promise<CreateResult>;
|
|
62
|
+
|
|
63
|
+
get(options: GetOptions): Promise<GetResult>;
|
|
64
|
+
get(id: string): Promise<GetResult>;
|
|
65
|
+
|
|
66
|
+
update(options: UpdateOptions): Promise<UpdateResult>;
|
|
67
|
+
|
|
68
|
+
destroy(options: DestroyOptions): Promise<DestroyResult>;
|
|
69
|
+
destroy(id: string): Promise<DestroyResult>;
|
|
70
|
+
|
|
71
|
+
delete(options: DestroyOptions): Promise<DestroyResult>;
|
|
72
|
+
delete(id: string): Promise<DestroyResult>;
|
|
73
|
+
}
|
package/lib/intention.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const errors = require("./errors");
|
|
2
|
+
const utils = require("./utils");
|
|
3
|
+
|
|
4
|
+
class Intention {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Lists all intentions
|
|
11
|
+
*/
|
|
12
|
+
async list(opts) {
|
|
13
|
+
opts = utils.normalizeKeys(opts);
|
|
14
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
15
|
+
|
|
16
|
+
const req = {
|
|
17
|
+
name: "intention.list",
|
|
18
|
+
path: "/connect/intentions",
|
|
19
|
+
query: {},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
utils.options(req, opts);
|
|
23
|
+
|
|
24
|
+
return await this.consul._get(req, utils.body);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new intention
|
|
29
|
+
*/
|
|
30
|
+
async create(opts) {
|
|
31
|
+
opts = utils.normalizeKeys(opts);
|
|
32
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
33
|
+
|
|
34
|
+
const req = {
|
|
35
|
+
name: "intention.create",
|
|
36
|
+
path: "/connect/intentions",
|
|
37
|
+
query: {},
|
|
38
|
+
type: "json",
|
|
39
|
+
body: {},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (!opts.sourcename) {
|
|
43
|
+
throw this.consul._err(errors.Validation("sourcename required"), req);
|
|
44
|
+
}
|
|
45
|
+
if (!opts.destinationname) {
|
|
46
|
+
throw this.consul._err(
|
|
47
|
+
errors.Validation("destinationname required"),
|
|
48
|
+
req,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (!opts.action) {
|
|
52
|
+
throw this.consul._err(errors.Validation("action required"), req);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
req.body.SourceName = opts.sourcename;
|
|
56
|
+
req.body.DestinationName = opts.destinationname;
|
|
57
|
+
req.body.Action = opts.action;
|
|
58
|
+
|
|
59
|
+
if (opts.description) req.body.Description = opts.description;
|
|
60
|
+
if (opts.sourcetype) req.body.SourceType = opts.sourcetype;
|
|
61
|
+
if (opts.meta) req.body.Meta = opts.meta;
|
|
62
|
+
if (typeof opts.precedence === "number") {
|
|
63
|
+
req.body.Precedence = opts.precedence;
|
|
64
|
+
}
|
|
65
|
+
if (opts.permissions) req.body.Permissions = opts.permissions;
|
|
66
|
+
|
|
67
|
+
utils.options(req, opts);
|
|
68
|
+
|
|
69
|
+
return await this.consul._post(req, utils.body);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets a given intention
|
|
74
|
+
*/
|
|
75
|
+
async get(opts) {
|
|
76
|
+
if (typeof opts === "string") {
|
|
77
|
+
opts = { id: opts };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
opts = utils.normalizeKeys(opts);
|
|
81
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
82
|
+
|
|
83
|
+
const req = {
|
|
84
|
+
name: "intention.get",
|
|
85
|
+
path: "/connect/intentions/{id}",
|
|
86
|
+
params: { id: opts.id },
|
|
87
|
+
query: {},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (!opts.id) {
|
|
91
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
utils.options(req, opts);
|
|
95
|
+
|
|
96
|
+
return await this.consul._get(req, utils.bodyItem);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Updates an existing intention
|
|
101
|
+
*/
|
|
102
|
+
async update(opts) {
|
|
103
|
+
opts = utils.normalizeKeys(opts);
|
|
104
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
105
|
+
|
|
106
|
+
const req = {
|
|
107
|
+
name: "intention.update",
|
|
108
|
+
path: "/connect/intentions/{id}",
|
|
109
|
+
params: { id: opts.id },
|
|
110
|
+
query: {},
|
|
111
|
+
type: "json",
|
|
112
|
+
body: {},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (!opts.id) {
|
|
116
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
117
|
+
}
|
|
118
|
+
if (!opts.sourcename) {
|
|
119
|
+
throw this.consul._err(errors.Validation("sourcename required"), req);
|
|
120
|
+
}
|
|
121
|
+
if (!opts.destinationname) {
|
|
122
|
+
throw this.consul._err(
|
|
123
|
+
errors.Validation("destinationname required"),
|
|
124
|
+
req,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (!opts.action) {
|
|
128
|
+
throw this.consul._err(errors.Validation("action required"), req);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
req.body.SourceName = opts.sourcename;
|
|
132
|
+
req.body.DestinationName = opts.destinationname;
|
|
133
|
+
req.body.Action = opts.action;
|
|
134
|
+
|
|
135
|
+
if (opts.description) req.body.Description = opts.description;
|
|
136
|
+
if (opts.sourcetype) req.body.SourceType = opts.sourcetype;
|
|
137
|
+
if (opts.meta) req.body.Meta = opts.meta;
|
|
138
|
+
if (typeof opts.precedence === "number") {
|
|
139
|
+
req.body.Precedence = opts.precedence;
|
|
140
|
+
}
|
|
141
|
+
if (opts.permissions) req.body.Permissions = opts.permissions;
|
|
142
|
+
|
|
143
|
+
utils.options(req, opts);
|
|
144
|
+
|
|
145
|
+
return await this.consul._put(req, utils.empty);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Deletes a given intention
|
|
150
|
+
*/
|
|
151
|
+
async destroy(opts) {
|
|
152
|
+
if (typeof opts === "string") {
|
|
153
|
+
opts = { id: opts };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
opts = utils.normalizeKeys(opts);
|
|
157
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
158
|
+
|
|
159
|
+
const req = {
|
|
160
|
+
name: "intention.destroy",
|
|
161
|
+
path: "/connect/intentions/{id}",
|
|
162
|
+
params: { id: opts.id },
|
|
163
|
+
query: {},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (!opts.id) {
|
|
167
|
+
throw this.consul._err(errors.Validation("id required"), req);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
utils.options(req, opts);
|
|
171
|
+
|
|
172
|
+
return await this.consul._delete(req, utils.empty);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
delete() {
|
|
176
|
+
return this.destroy.apply(this, arguments);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
exports.Intention = Intention;
|
package/lib/kv.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Consul } from "./consul";
|
|
2
|
+
|
|
3
|
+
interface GetOptions {
|
|
4
|
+
key?: string;
|
|
5
|
+
dc?: string;
|
|
6
|
+
raw?: boolean;
|
|
7
|
+
keys?: boolean;
|
|
8
|
+
separator?: string;
|
|
9
|
+
ns?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface GetOptionsRecurse extends GetOptions {
|
|
13
|
+
recurse: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface GetItem {
|
|
17
|
+
CreateIndex: number;
|
|
18
|
+
ModifyIndex: number;
|
|
19
|
+
LockIndex: number;
|
|
20
|
+
Key: string;
|
|
21
|
+
Flags: number;
|
|
22
|
+
Value: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type GetResult = GetItem | null;
|
|
26
|
+
|
|
27
|
+
type GetResultRecurse = GetItem[] | GetItem | null;
|
|
28
|
+
|
|
29
|
+
interface KeysOptions extends GetOptions {
|
|
30
|
+
recurse?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type KeysResult = string[];
|
|
34
|
+
|
|
35
|
+
interface SetOptions {
|
|
36
|
+
key?: string;
|
|
37
|
+
value: string | Buffer;
|
|
38
|
+
dc?: string;
|
|
39
|
+
flags?: number;
|
|
40
|
+
cas?: number;
|
|
41
|
+
acquire?: string;
|
|
42
|
+
release?: string;
|
|
43
|
+
ns?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type SetResult = boolean;
|
|
47
|
+
|
|
48
|
+
interface DelOptions {
|
|
49
|
+
key?: string;
|
|
50
|
+
dc?: string;
|
|
51
|
+
recurse?: boolean;
|
|
52
|
+
cas?: number;
|
|
53
|
+
ns?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type DelResult = boolean;
|
|
57
|
+
|
|
58
|
+
declare class Kv {
|
|
59
|
+
constructor(consul: Consul);
|
|
60
|
+
|
|
61
|
+
consul: Consul;
|
|
62
|
+
|
|
63
|
+
get(options?: GetOptions): Promise<GetResult>;
|
|
64
|
+
get(key: string): Promise<GetResult>;
|
|
65
|
+
get(options?: GetOptionsRecurse): Promise<GetResultRecurse>;
|
|
66
|
+
|
|
67
|
+
keys(options?: KeysOptions): Promise<KeysResult>;
|
|
68
|
+
keys(key: string): Promise<KeysResult>;
|
|
69
|
+
|
|
70
|
+
set(options: SetOptions): Promise<SetResult>;
|
|
71
|
+
set(key: string, value: string | Buffer): Promise<SetResult>;
|
|
72
|
+
set(
|
|
73
|
+
key: string,
|
|
74
|
+
value: string | Buffer,
|
|
75
|
+
options: SetOptions,
|
|
76
|
+
): Promise<SetResult>;
|
|
77
|
+
|
|
78
|
+
del(options: DelOptions): Promise<DelResult>;
|
|
79
|
+
del(key: string): Promise<DelResult>;
|
|
80
|
+
}
|
package/lib/kv.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const errors = require("./errors");
|
|
2
|
+
const utils = require("./utils");
|
|
3
|
+
|
|
4
|
+
class Kv {
|
|
5
|
+
constructor(consul) {
|
|
6
|
+
this.consul = consul;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get
|
|
11
|
+
*/
|
|
12
|
+
async get(opts) {
|
|
13
|
+
if (typeof opts === "string") {
|
|
14
|
+
opts = { key: opts };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
opts = utils.normalizeKeys(opts);
|
|
18
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
19
|
+
|
|
20
|
+
const req = {
|
|
21
|
+
name: "kv.get",
|
|
22
|
+
path: "/kv/{key}",
|
|
23
|
+
params: { key: opts.key || "" },
|
|
24
|
+
query: {},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (opts.recurse) req.query.recurse = "true";
|
|
28
|
+
if (opts.raw) {
|
|
29
|
+
req.query.raw = "true";
|
|
30
|
+
req.buffer = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
utils.options(req, opts);
|
|
34
|
+
|
|
35
|
+
return await this.consul._get(req, function (request, next) {
|
|
36
|
+
const res = request.res;
|
|
37
|
+
|
|
38
|
+
if (res && res.statusCode === 404) {
|
|
39
|
+
return next(false, undefined, utils.responseResult(request));
|
|
40
|
+
}
|
|
41
|
+
if (request.err) {
|
|
42
|
+
utils.applyErrorResponse(request);
|
|
43
|
+
return next(request.err);
|
|
44
|
+
}
|
|
45
|
+
if (opts.raw) {
|
|
46
|
+
return next(false, undefined, utils.responseResult(request, res.body));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (res.body && Array.isArray(res.body) && res.body.length) {
|
|
50
|
+
res.body.forEach((item) => {
|
|
51
|
+
if (item.hasOwnProperty("Value")) {
|
|
52
|
+
item.Value = utils.decode(item.Value, opts);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
return next(false, undefined, utils.responseResult(request));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!opts.recurse) {
|
|
60
|
+
return next(
|
|
61
|
+
false,
|
|
62
|
+
undefined,
|
|
63
|
+
utils.responseResult(request, res.body[0]),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
next(false, undefined, utils.responseResult(request, res.body));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Keys
|
|
73
|
+
*/
|
|
74
|
+
async keys(opts) {
|
|
75
|
+
if (typeof opts === "string") {
|
|
76
|
+
opts = { key: opts };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
opts = utils.normalizeKeys(opts);
|
|
80
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
81
|
+
|
|
82
|
+
const req = {
|
|
83
|
+
name: "kv.keys",
|
|
84
|
+
path: "/kv/{key}",
|
|
85
|
+
params: { key: opts.key || "" },
|
|
86
|
+
query: { keys: true },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
if (opts.separator) req.query.separator = opts.separator;
|
|
90
|
+
|
|
91
|
+
utils.options(req, opts);
|
|
92
|
+
|
|
93
|
+
return await this.consul._get(req, utils.body);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Set
|
|
98
|
+
*/
|
|
99
|
+
async set(opts) {
|
|
100
|
+
let options;
|
|
101
|
+
switch (arguments.length) {
|
|
102
|
+
case 3:
|
|
103
|
+
// set(key, value, opts)
|
|
104
|
+
options = arguments[2];
|
|
105
|
+
options.key = arguments[0];
|
|
106
|
+
options.value = arguments[1];
|
|
107
|
+
break;
|
|
108
|
+
case 2:
|
|
109
|
+
// set(key, value)
|
|
110
|
+
options = {
|
|
111
|
+
key: arguments[0],
|
|
112
|
+
value: arguments[1],
|
|
113
|
+
};
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
options = opts;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
options = utils.normalizeKeys(options);
|
|
120
|
+
options = utils.defaults(options, this.consul._defaults);
|
|
121
|
+
|
|
122
|
+
const req = {
|
|
123
|
+
name: "kv.set",
|
|
124
|
+
path: "/kv/{key}",
|
|
125
|
+
params: { key: options.key },
|
|
126
|
+
query: {},
|
|
127
|
+
type: "text",
|
|
128
|
+
body: options.value || "",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
if (!options.key) {
|
|
132
|
+
throw this.consul._err(errors.Validation("key required"), req);
|
|
133
|
+
}
|
|
134
|
+
if (!options.hasOwnProperty("value")) {
|
|
135
|
+
throw this.consul._err(errors.Validation("value required"), req);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (options.hasOwnProperty("cas")) req.query.cas = options.cas;
|
|
139
|
+
if (options.hasOwnProperty("flags")) req.query.flags = options.flags;
|
|
140
|
+
if (options.hasOwnProperty("acquire")) req.query.acquire = options.acquire;
|
|
141
|
+
if (options.hasOwnProperty("release")) req.query.release = options.release;
|
|
142
|
+
|
|
143
|
+
utils.options(req, options);
|
|
144
|
+
|
|
145
|
+
return await this.consul._put(req, utils.body);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Delete
|
|
150
|
+
*/
|
|
151
|
+
async del(opts) {
|
|
152
|
+
if (typeof opts === "string") {
|
|
153
|
+
opts = { key: opts };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
opts = utils.normalizeKeys(opts);
|
|
157
|
+
opts = utils.defaults(opts, this.consul._defaults);
|
|
158
|
+
|
|
159
|
+
const req = {
|
|
160
|
+
name: "kv.del",
|
|
161
|
+
path: "/kv/{key}",
|
|
162
|
+
params: { key: opts.key || "" },
|
|
163
|
+
query: {},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (opts.recurse) req.query.recurse = "true";
|
|
167
|
+
|
|
168
|
+
if (opts.hasOwnProperty("cas")) req.query.cas = opts.cas;
|
|
169
|
+
|
|
170
|
+
utils.options(req, opts);
|
|
171
|
+
|
|
172
|
+
return await this.consul._delete(req, utils.body);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
delete() {
|
|
176
|
+
return this.del.apply(this, arguments);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
exports.Kv = Kv;
|
package/lib/query.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CommonOptions, Consul } from "./consul";
|
|
2
|
+
|
|
3
|
+
interface ListOptions extends CommonOptions {}
|
|
4
|
+
|
|
5
|
+
type ListResult = any[];
|
|
6
|
+
|
|
7
|
+
interface CreateServiceOptions {
|
|
8
|
+
service: string;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
failover?: {
|
|
11
|
+
nearestn?: number;
|
|
12
|
+
datacenters?: string[];
|
|
13
|
+
targets?: { peer?: string; datacenter?: string }[];
|
|
14
|
+
};
|
|
15
|
+
ignorecheckids?: string[];
|
|
16
|
+
onlypassing?: boolean;
|
|
17
|
+
near?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface CreateDnsOptions {
|
|
21
|
+
ttl?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface CreateOptions extends CommonOptions {
|
|
25
|
+
name?: string;
|
|
26
|
+
session?: string;
|
|
27
|
+
token?: string;
|
|
28
|
+
service: CreateServiceOptions;
|
|
29
|
+
tags?: string[];
|
|
30
|
+
nodemeta?: Record<string, string>;
|
|
31
|
+
servicemeta?: Record<string, string>;
|
|
32
|
+
connect?: boolean;
|
|
33
|
+
dns?: CreateDnsOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface CreateResult {
|
|
37
|
+
ID: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface GetOptions extends CommonOptions {
|
|
41
|
+
query: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type GetResult = any;
|
|
45
|
+
|
|
46
|
+
interface UpdateOptions extends CreateOptions {
|
|
47
|
+
query: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type UpdateResult = any;
|
|
51
|
+
|
|
52
|
+
interface ExecuteOptions extends CommonOptions {
|
|
53
|
+
query: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type ExecuteResult = any;
|
|
57
|
+
|
|
58
|
+
interface ExplainOptions extends CommonOptions {
|
|
59
|
+
query: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type ExplainResult = any;
|
|
63
|
+
|
|
64
|
+
declare class Query {
|
|
65
|
+
constructor(consul: Consul);
|
|
66
|
+
|
|
67
|
+
consul: Consul;
|
|
68
|
+
|
|
69
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
70
|
+
|
|
71
|
+
create(options: CreateOptions): Promise<CreateResult>;
|
|
72
|
+
create(service: string): Promise<CreateResult>;
|
|
73
|
+
|
|
74
|
+
get(options: GetOptions): Promise<GetResult>;
|
|
75
|
+
get(query: string): Promise<GetResult>;
|
|
76
|
+
|
|
77
|
+
update(options: UpdateOptions): Promise<UpdateResult>;
|
|
78
|
+
|
|
79
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
80
|
+
execute(query: string): Promise<ExecuteResult>;
|
|
81
|
+
|
|
82
|
+
explain(options: ExplainOptions): Promise<ExplainResult>;
|
|
83
|
+
explain(query: string): Promise<ExplainResult>;
|
|
84
|
+
}
|