@cloud-cli/env 1.2.0 → 1.3.0
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 +17 -12
- package/dist/index.js +40 -43
- package/package.json +8 -8
- package/cloud.db +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { init } from '@cloud-cli/cli';
|
|
3
|
-
export declare class EnvEntry extends Resource {
|
|
1
|
+
export declare class EnvEntry {
|
|
4
2
|
app: string;
|
|
5
3
|
key: string;
|
|
6
4
|
value: string;
|
|
@@ -9,25 +7,32 @@ export interface App {
|
|
|
9
7
|
app: string;
|
|
10
8
|
name?: string;
|
|
11
9
|
}
|
|
10
|
+
export interface ListFilters {
|
|
11
|
+
app?: string;
|
|
12
|
+
key?: string;
|
|
13
|
+
}
|
|
12
14
|
export interface KeyValue {
|
|
13
15
|
key: string;
|
|
14
16
|
value?: string;
|
|
15
17
|
}
|
|
16
18
|
export interface AppKeyValue extends App, KeyValue {
|
|
17
19
|
}
|
|
18
|
-
declare function reload(): Promise<void>;
|
|
19
20
|
declare function show(options: App): Promise<EnvEntry[]>;
|
|
21
|
+
declare function list(filters?: ListFilters): Promise<EnvEntry[]>;
|
|
20
22
|
declare function apps(): Promise<string[]>;
|
|
21
|
-
declare function
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
declare function setVar(options: AppKeyValue): Promise<{
|
|
24
|
+
app: string;
|
|
25
|
+
key: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}>;
|
|
28
|
+
declare function removeVar(options: AppKeyValue): Promise<boolean>;
|
|
29
|
+
declare function getVar(options: Omit<AppKeyValue, 'value'>): Promise<EnvEntry>;
|
|
24
30
|
declare const _default: {
|
|
25
|
-
get: typeof
|
|
26
|
-
set: typeof
|
|
31
|
+
get: typeof getVar;
|
|
32
|
+
set: typeof setVar;
|
|
33
|
+
remove: typeof removeVar;
|
|
27
34
|
show: typeof show;
|
|
28
|
-
remove: typeof remove;
|
|
29
35
|
apps: typeof apps;
|
|
30
|
-
|
|
31
|
-
[init]: typeof reload;
|
|
36
|
+
list: typeof list;
|
|
32
37
|
};
|
|
33
38
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,48 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Model, NotNull, Property, Query, Resource, SQLiteDriver, Unique } from '@cloud-cli/store';
|
|
8
|
-
import { init } from '@cloud-cli/cli';
|
|
1
|
+
import { getStorage } from '@cloud-cli/cli';
|
|
9
2
|
const appNotSpecifiedError = new Error('App not specified');
|
|
10
3
|
const keyNotSpecifiedError = new Error('Key not specified');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__decorate([
|
|
14
|
-
Unique(),
|
|
15
|
-
NotNull(),
|
|
16
|
-
Property(String)
|
|
17
|
-
], EnvEntry.prototype, "app", void 0);
|
|
18
|
-
__decorate([
|
|
19
|
-
Unique(),
|
|
20
|
-
NotNull(),
|
|
21
|
-
Property(String)
|
|
22
|
-
], EnvEntry.prototype, "key", void 0);
|
|
23
|
-
__decorate([
|
|
24
|
-
Property(String)
|
|
25
|
-
], EnvEntry.prototype, "value", void 0);
|
|
26
|
-
EnvEntry = __decorate([
|
|
27
|
-
Model('env')
|
|
28
|
-
], EnvEntry);
|
|
29
|
-
export { EnvEntry };
|
|
30
|
-
async function reload() {
|
|
31
|
-
Resource.use(new SQLiteDriver());
|
|
32
|
-
await Resource.create(EnvEntry);
|
|
4
|
+
const { get, set, remove, getAll } = getStorage('env');
|
|
5
|
+
export class EnvEntry {
|
|
33
6
|
}
|
|
34
7
|
async function show(options) {
|
|
35
8
|
const app = options.app || options.name;
|
|
36
9
|
if (!app) {
|
|
37
10
|
throw appNotSpecifiedError;
|
|
38
11
|
}
|
|
39
|
-
return
|
|
12
|
+
return list({ app });
|
|
13
|
+
}
|
|
14
|
+
async function list(filters = {}) {
|
|
15
|
+
let all = await getAll();
|
|
16
|
+
if (filters.app) {
|
|
17
|
+
all = all.filter((e) => e.app === filters.app);
|
|
18
|
+
}
|
|
19
|
+
if (filters.key) {
|
|
20
|
+
all = all.filter((e) => e.key === filters.key);
|
|
21
|
+
}
|
|
22
|
+
return all;
|
|
40
23
|
}
|
|
41
24
|
async function apps() {
|
|
42
|
-
const rows = await
|
|
43
|
-
|
|
25
|
+
const rows = await getAll();
|
|
26
|
+
const apps = rows.map((entry) => entry.app);
|
|
27
|
+
return [...new Set(apps)];
|
|
44
28
|
}
|
|
45
|
-
async function
|
|
29
|
+
async function setVar(options) {
|
|
46
30
|
const app = options.app || options.name;
|
|
47
31
|
const { key, value } = options;
|
|
48
32
|
if (!app) {
|
|
@@ -51,19 +35,21 @@ async function set(options) {
|
|
|
51
35
|
if (!key) {
|
|
52
36
|
throw keyNotSpecifiedError;
|
|
53
37
|
}
|
|
54
|
-
const entry =
|
|
55
|
-
await
|
|
38
|
+
const entry = { app, key, value };
|
|
39
|
+
await set(computeId(app, key), entry);
|
|
56
40
|
return entry;
|
|
57
41
|
}
|
|
58
|
-
async function
|
|
42
|
+
async function removeVar(options) {
|
|
59
43
|
const app = options.app || options.name;
|
|
60
44
|
const { key } = options;
|
|
61
|
-
const found = await
|
|
62
|
-
if (
|
|
63
|
-
|
|
45
|
+
const found = await getVar({ app, key });
|
|
46
|
+
if (found) {
|
|
47
|
+
await remove(computeId(app, key));
|
|
48
|
+
return true;
|
|
64
49
|
}
|
|
50
|
+
return false;
|
|
65
51
|
}
|
|
66
|
-
async function
|
|
52
|
+
async function getVar(options) {
|
|
67
53
|
const app = options.app || options.name;
|
|
68
54
|
const { key } = options;
|
|
69
55
|
if (!app) {
|
|
@@ -72,6 +58,17 @@ async function get(options) {
|
|
|
72
58
|
if (!key) {
|
|
73
59
|
throw keyNotSpecifiedError;
|
|
74
60
|
}
|
|
75
|
-
return
|
|
61
|
+
return get(computeId(app, key));
|
|
62
|
+
}
|
|
63
|
+
const invalidRe = /[^a-z09-]/g;
|
|
64
|
+
function computeId(app, key) {
|
|
65
|
+
return `${app}.${key}`.replace(invalidRe, '-');
|
|
76
66
|
}
|
|
77
|
-
export default {
|
|
67
|
+
export default {
|
|
68
|
+
get: getVar,
|
|
69
|
+
set: setVar,
|
|
70
|
+
remove: removeVar,
|
|
71
|
+
show,
|
|
72
|
+
apps,
|
|
73
|
+
list,
|
|
74
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-cli/env",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Storage for app environment variables",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"prettier": "@cloud-cli/prettier-config",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "
|
|
11
|
-
"tdd": "jest --watchAll",
|
|
10
|
+
"test": "vitest",
|
|
12
11
|
"build": "rm -rf ./dist/* && tsc --project ./tsconfig.json"
|
|
13
12
|
},
|
|
14
13
|
"keywords": [
|
|
@@ -16,9 +15,11 @@
|
|
|
16
15
|
],
|
|
17
16
|
"license": "MIT",
|
|
18
17
|
"devDependencies": {
|
|
19
|
-
"@cloud-cli/jest-config": "^1.0.0",
|
|
20
18
|
"@cloud-cli/prettier-config": "^1.0.0",
|
|
21
|
-
"@cloud-cli/typescript-config": "^1.0.1"
|
|
19
|
+
"@cloud-cli/typescript-config": "^1.0.1",
|
|
20
|
+
"@types/node": "^20.12.8",
|
|
21
|
+
"typescript": "^5.4.5",
|
|
22
|
+
"vitest": "^1.6.0"
|
|
22
23
|
},
|
|
23
24
|
"repository": {
|
|
24
25
|
"type": "git",
|
|
@@ -28,7 +29,6 @@
|
|
|
28
29
|
"access": "public"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@cloud-cli/cli": "^1.4.4"
|
|
32
|
-
"@cloud-cli/store": "^1.5.1"
|
|
32
|
+
"@cloud-cli/cli": "^1.4.4"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/cloud.db
DELETED
|
Binary file
|