@cloud-cli/env 1.3.2 → 1.3.4
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/dist/index.d.ts +7 -7
- package/dist/index.js +23 -19
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,16 +17,16 @@ export interface KeyValue {
|
|
|
17
17
|
}
|
|
18
18
|
export interface AppKeyValue extends App, KeyValue {
|
|
19
19
|
}
|
|
20
|
-
declare function show(options: App):
|
|
21
|
-
declare function list(filters?: ListFilters):
|
|
22
|
-
declare function apps():
|
|
23
|
-
declare function setVar(options: AppKeyValue):
|
|
20
|
+
declare function show(options: App): EnvEntry[];
|
|
21
|
+
declare function list(filters?: ListFilters): EnvEntry[];
|
|
22
|
+
declare function apps(): string[];
|
|
23
|
+
declare function setVar(options: AppKeyValue): {
|
|
24
24
|
app: string;
|
|
25
25
|
key: string;
|
|
26
26
|
value: string;
|
|
27
|
-
}
|
|
28
|
-
declare function removeVar(options: AppKeyValue):
|
|
29
|
-
declare function getVar(options: Omit<AppKeyValue, 'value'>):
|
|
27
|
+
};
|
|
28
|
+
declare function removeVar(options: AppKeyValue): boolean;
|
|
29
|
+
declare function getVar(options: Omit<AppKeyValue, 'value'>): EnvEntry;
|
|
30
30
|
declare const _default: {
|
|
31
31
|
get: typeof getVar;
|
|
32
32
|
set: typeof setVar;
|
package/dist/index.js
CHANGED
|
@@ -2,15 +2,19 @@ import { getStorage } from '@cloud-cli/cli';
|
|
|
2
2
|
const appNotSpecifiedError = new Error('App not specified');
|
|
3
3
|
const keyNotSpecifiedError = new Error('Key not specified');
|
|
4
4
|
const { get, set, remove, getAll } = getStorage('env');
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const readName = (options) => {
|
|
6
|
+
options.app = options.app || options.name || options._?.[0];
|
|
7
|
+
};
|
|
8
|
+
function show(options) {
|
|
9
|
+
readName(options);
|
|
10
|
+
const { app } = options;
|
|
7
11
|
if (!app) {
|
|
8
12
|
throw appNotSpecifiedError;
|
|
9
13
|
}
|
|
10
14
|
return list({ app });
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
let all =
|
|
16
|
+
function list(filters = {}) {
|
|
17
|
+
let all = getAll();
|
|
14
18
|
if (filters.app) {
|
|
15
19
|
all = all.filter((e) => e.app === filters.app);
|
|
16
20
|
}
|
|
@@ -19,14 +23,14 @@ async function list(filters = {}) {
|
|
|
19
23
|
}
|
|
20
24
|
return all;
|
|
21
25
|
}
|
|
22
|
-
|
|
23
|
-
const rows =
|
|
26
|
+
function apps() {
|
|
27
|
+
const rows = getAll();
|
|
24
28
|
const apps = rows.map((entry) => entry.app);
|
|
25
29
|
return [...new Set(apps)];
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const { key, value } = options;
|
|
31
|
+
function setVar(options) {
|
|
32
|
+
readName(options);
|
|
33
|
+
const { key, value, app } = options;
|
|
30
34
|
if (!app) {
|
|
31
35
|
throw appNotSpecifiedError;
|
|
32
36
|
}
|
|
@@ -34,22 +38,22 @@ async function setVar(options) {
|
|
|
34
38
|
throw keyNotSpecifiedError;
|
|
35
39
|
}
|
|
36
40
|
const entry = { app, key, value };
|
|
37
|
-
|
|
41
|
+
set(computeId(app, key), entry);
|
|
38
42
|
return entry;
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { key } = options;
|
|
43
|
-
const found =
|
|
44
|
+
function removeVar(options) {
|
|
45
|
+
readName(options);
|
|
46
|
+
const { app, key } = options;
|
|
47
|
+
const found = getVar({ app, key });
|
|
44
48
|
if (found) {
|
|
45
|
-
|
|
49
|
+
remove(computeId(app, key));
|
|
46
50
|
return true;
|
|
47
51
|
}
|
|
48
52
|
return false;
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const { key } = options;
|
|
54
|
+
function getVar(options) {
|
|
55
|
+
readName(options);
|
|
56
|
+
const { app, key } = options;
|
|
53
57
|
if (!app) {
|
|
54
58
|
throw appNotSpecifiedError;
|
|
55
59
|
}
|
|
@@ -58,7 +62,7 @@ async function getVar(options) {
|
|
|
58
62
|
}
|
|
59
63
|
return get(computeId(app, key));
|
|
60
64
|
}
|
|
61
|
-
const invalidRe = /[^a-z09-]/
|
|
65
|
+
const invalidRe = /[^a-z09-]/gi;
|
|
62
66
|
function computeId(app, key) {
|
|
63
67
|
return `${app}.${key}`.replace(invalidRe, '-');
|
|
64
68
|
}
|