@osaas/client-db 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Eyevinn Technology Open Source Software Center
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /** @module @osaas/client-db */
2
+ export { ValkeyDb } from './valkey';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /** @module @osaas/client-db */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ValkeyDb = void 0;
5
+ var valkey_1 = require("./valkey");
6
+ Object.defineProperty(exports, "ValkeyDb", { enumerable: true, get: function () { return valkey_1.ValkeyDb; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+BAA+B;;;AAE/B,mCAAoC;AAA3B,kGAAA,QAAQ,OAAA"}
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import { Context } from '@osaas/client-core';
3
+ export declare class ValkeyDb {
4
+ private context;
5
+ private name;
6
+ private token?;
7
+ private url?;
8
+ constructor({ context, name }: {
9
+ context: Context;
10
+ name: string;
11
+ });
12
+ static list(ctx: Context): Promise<ValkeyDb[]>;
13
+ private getRedisPort;
14
+ init(): Promise<void>;
15
+ destroy(): Promise<void>;
16
+ getRedisUrl(): Promise<URL | undefined>;
17
+ getName(): string;
18
+ }
19
+ //# sourceMappingURL=valkey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valkey.d.ts","sourceRoot":"","sources":["../src/valkey.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,OAAO,EAOR,MAAM,oBAAoB,CAAC;AAI5B,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,GAAG,CAAC,CAAM;gBAEN,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;WAK7C,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YAQ7C,YAAY;IAcb,IAAI;IAyBJ,OAAO;IASP,WAAW,IAAI,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAO7C,OAAO,IAAI,MAAM;CAGzB"}
package/lib/valkey.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValkeyDb = void 0;
4
+ const client_core_1 = require("@osaas/client-core");
5
+ const SERVICE_ID = 'valkey-io-valkey';
6
+ class ValkeyDb {
7
+ context;
8
+ name;
9
+ token;
10
+ url;
11
+ constructor({ context, name }) {
12
+ this.context = context;
13
+ this.name = name;
14
+ }
15
+ static async list(ctx) {
16
+ const token = await ctx.getServiceAccessToken(SERVICE_ID);
17
+ const instances = await (0, client_core_1.listInstances)(ctx, SERVICE_ID, token);
18
+ return instances.map((instance) => {
19
+ return new ValkeyDb({ context: ctx, name: instance.name });
20
+ });
21
+ }
22
+ async getRedisPort() {
23
+ if (!this.token) {
24
+ this.token = await this.context.getServiceAccessToken(SERVICE_ID);
25
+ }
26
+ const ports = await (0, client_core_1.getPortsForInstance)(this.context, SERVICE_ID, this.name, this.token);
27
+ const redisPort = ports.find((port) => port.internalPort == 6379);
28
+ return redisPort;
29
+ }
30
+ async init() {
31
+ this.token = await this.context.getServiceAccessToken(SERVICE_ID);
32
+ const instance = await (0, client_core_1.getInstance)(this.context, SERVICE_ID, this.name, this.token);
33
+ if (!instance) {
34
+ if (!(await (0, client_core_1.createInstance)(this.context, SERVICE_ID, this.token, {
35
+ name: this.name
36
+ }))) {
37
+ throw new Error('Failed to create Valkey instance');
38
+ }
39
+ }
40
+ const redisPort = await this.getRedisPort();
41
+ if (redisPort) {
42
+ this.url = new URL(`redis://${redisPort.externalIp}:${redisPort.externalPort}`);
43
+ }
44
+ }
45
+ async destroy() {
46
+ try {
47
+ this.token = await this.context.getServiceAccessToken(SERVICE_ID);
48
+ await (0, client_core_1.removeInstance)(this.context, SERVICE_ID, this.name, this.token);
49
+ }
50
+ catch (err) {
51
+ (0, client_core_1.Log)().error(err.message);
52
+ }
53
+ }
54
+ async getRedisUrl() {
55
+ if (!this.url) {
56
+ await this.init();
57
+ }
58
+ return this.url;
59
+ }
60
+ getName() {
61
+ return this.name;
62
+ }
63
+ }
64
+ exports.ValkeyDb = ValkeyDb;
65
+ //# sourceMappingURL=valkey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valkey.js","sourceRoot":"","sources":["../src/valkey.ts"],"names":[],"mappings":";;;AAAA,oDAQ4B;AAE5B,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC,MAAa,QAAQ;IACX,OAAO,CAAU;IACjB,IAAI,CAAS;IACb,KAAK,CAAU;IACf,GAAG,CAAO;IAElB,YAAY,EAAE,OAAO,EAAE,IAAI,EAAsC;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAY;QACnC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAa,EAAC,GAAG,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,QAA0B,EAAE,EAAE;YAClD,OAAO,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,YAAY;QACxB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC;SACnE;QACD,MAAM,KAAK,GAAG,MAAM,IAAA,iCAAmB,EACrC,IAAI,CAAC,OAAO,EACZ,UAAU,EACV,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,KAAK,CACX,CAAC;QACF,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC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AI,CAAC,IAAI,CAAC,GAAG,EAAE;YACb,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;SACnB;QACD,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF;AA7ED,4BA6EC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@osaas/client-db",
3
+ "version": "0.1.0",
4
+ "description": "Open Source Cloud Client SDK database library",
5
+ "author": "Eyevinn Technology <work@eyevinn.se>",
6
+ "homepage": "https://www.osaas.io",
7
+ "license": "MIT",
8
+ "main": "lib/index.js",
9
+ "types": "lib/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Eyevinn/osaas-client-ts.git"
13
+ },
14
+ "directories": {
15
+ "lib": "lib"
16
+ },
17
+ "files": [
18
+ "lib"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json",
22
+ "lint": "eslint .",
23
+ "pretty": "prettier --check --ignore-unknown .",
24
+ "typecheck": "tsc --noEmit -p tsconfig.json",
25
+ "test": "jest --passWithNoTests"
26
+ },
27
+ "dependencies": {
28
+ "@osaas/client-core": "^0.8.0",
29
+ "chalk": "4.1.2"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "gitHead": "779baa027421ac20b4c05b0c11fd88278d316f09"
35
+ }