@or-sdk/key-value-storage 0.9.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.
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.KeyValueStorage = void 0;
40
+ var sdk_api_1 = require("@or-sdk/sdk-api");
41
+ var constants_1 = require("./constants");
42
+ var KeyValueStorage = (function () {
43
+ function KeyValueStorage(params) {
44
+ var token = params.token, discoveryUrl = params.discoveryUrl;
45
+ this.sdkApi = new sdk_api_1.SdkApi({
46
+ token: token,
47
+ discoveryUrl: discoveryUrl,
48
+ });
49
+ }
50
+ KeyValueStorage.prototype.listKeys = function (tableName, prefix, withValues) {
51
+ if (withValues === void 0) { withValues = false; }
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ var records;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4, this.sdkApi.makeRequest({
57
+ method: 'GET',
58
+ route: "".concat(constants_1.STORAGE_ROUTE, "/").concat(tableName),
59
+ params: {
60
+ prefix: prefix ? prefix : undefined,
61
+ withValues: withValues,
62
+ },
63
+ })];
64
+ case 1:
65
+ records = (_a.sent()).value.records;
66
+ return [2, records];
67
+ }
68
+ });
69
+ });
70
+ };
71
+ KeyValueStorage.prototype.getValueByKey = function (tableName, key) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ return [2, this.sdkApi.makeRequest({
75
+ method: 'GET',
76
+ route: "".concat(constants_1.STORAGE_ROUTE, "/").concat(tableName, "/").concat(key),
77
+ })];
78
+ });
79
+ });
80
+ };
81
+ KeyValueStorage.prototype.setValueByKey = function (tableName, key, value, expire) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ return __generator(this, function (_a) {
84
+ return [2, this.sdkApi.makeRequest({
85
+ method: 'POST',
86
+ route: "".concat(constants_1.STORAGE_ROUTE, "/").concat(tableName, "/").concat(key),
87
+ data: {
88
+ expire: expire,
89
+ value: value,
90
+ },
91
+ })];
92
+ });
93
+ });
94
+ };
95
+ KeyValueStorage.prototype.deleteKey = function (tableName, key) {
96
+ return __awaiter(this, void 0, void 0, function () {
97
+ return __generator(this, function (_a) {
98
+ return [2, this.sdkApi.makeRequest({
99
+ method: 'DELETE',
100
+ route: "".concat(constants_1.STORAGE_ROUTE, "/").concat(tableName, "/").concat(key),
101
+ })];
102
+ });
103
+ });
104
+ };
105
+ return KeyValueStorage;
106
+ }());
107
+ exports.KeyValueStorage = KeyValueStorage;
108
+ //# sourceMappingURL=KeyValueStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStorage.js","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAOzC,yCAA4C;AAS5C;IASE,yBAAY,MAA6B;QAC/B,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,YAAY,GAAK,MAAM,aAAX,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC;YACvB,KAAK,OAAA;YACL,YAAY,cAAA;SACb,CAAC,CAAC;IACL,CAAC;IAYY,kCAAQ,GAArB,UACE,SAAiB,EACjB,MAAe,EACf,UAAkB;QAAlB,2BAAA,EAAA,kBAAkB;;;;;4BAId,WAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;4BAChC,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,UAAG,yBAAa,cAAI,SAAS,CAAE;4BACtC,MAAM,EAAE;gCACN,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;gCACnC,UAAU,YAAA;6BACX;yBACF,CAAC,EAAA;;wBARS,OAAO,GACd,CAAA,SAOF,CAAA,cARgB;wBAUlB,WAAO,OAAO,EAAC;;;;KAChB;IAWY,uCAAa,GAA1B,UACE,SAAiB,EACjB,GAAW;;;gBAEX,WAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;wBAC7B,MAAM,EAAE,KAAK;wBACb,KAAK,EAAE,UAAG,yBAAa,cAAI,SAAS,cAAI,GAAG,CAAE;qBAC9C,CAAC,EAAC;;;KACJ;IAaY,uCAAa,GAA1B,UACE,SAAiB,EACjB,GAAW,EACX,KAAuC,EACvC,MAAe;;;gBAEf,WAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;wBAC7B,MAAM,EAAE,MAAM;wBACd,KAAK,EAAE,UAAG,yBAAa,cAAI,SAAS,cAAI,GAAG,CAAE;wBAC7C,IAAI,EAAE;4BACJ,MAAM,QAAA;4BACN,KAAK,OAAA;yBACN;qBACF,CAAC,EAAC;;;KACJ;IAWY,mCAAS,GAAtB,UACE,SAAiB,EACjB,GAAW;;;gBAEX,WAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;wBAC7B,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE,UAAG,yBAAa,cAAI,SAAS,cAAI,GAAG,CAAE;qBAC9C,CAAC,EAAC;;;KACJ;IACH,sBAAC;AAAD,CAAC,AA/GD,IA+GC;AA/GY,0CAAe"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STORAGE_ROUTE = void 0;
4
+ exports.STORAGE_ROUTE = '/storage';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,UAAU,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.KeyValueStorage = void 0;
14
+ var KeyValueStorage_1 = require("./KeyValueStorage");
15
+ Object.defineProperty(exports, "KeyValueStorage", { enumerable: true, get: function () { return KeyValueStorage_1.KeyValueStorage; } });
16
+ __exportStar(require("./types"), exports);
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { SdkApi } from '@or-sdk/sdk-api';
11
+ import { STORAGE_ROUTE } from './constants';
12
+ export class KeyValueStorage {
13
+ constructor(params) {
14
+ const { token, discoveryUrl } = params;
15
+ this.sdkApi = new SdkApi({
16
+ token,
17
+ discoveryUrl,
18
+ });
19
+ }
20
+ listKeys(tableName, prefix, withValues = false) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const { value: { records }, } = yield this.sdkApi.makeRequest({
23
+ method: 'GET',
24
+ route: `${STORAGE_ROUTE}/${tableName}`,
25
+ params: {
26
+ prefix: prefix ? prefix : undefined,
27
+ withValues,
28
+ },
29
+ });
30
+ return records;
31
+ });
32
+ }
33
+ getValueByKey(tableName, key) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return this.sdkApi.makeRequest({
36
+ method: 'GET',
37
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
38
+ });
39
+ });
40
+ }
41
+ setValueByKey(tableName, key, value, expire) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return this.sdkApi.makeRequest({
44
+ method: 'POST',
45
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
46
+ data: {
47
+ expire,
48
+ value,
49
+ },
50
+ });
51
+ });
52
+ }
53
+ deleteKey(tableName, key) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ return this.sdkApi.makeRequest({
56
+ method: 'DELETE',
57
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
58
+ });
59
+ });
60
+ }
61
+ }
62
+ //# sourceMappingURL=KeyValueStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStorage.js","sourceRoot":"","sources":["../../src/KeyValueStorage.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAS5C,MAAM,OAAO,eAAe;IAS1B,YAAY,MAA6B;QACvC,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC;YACvB,KAAK;YACL,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAYY,QAAQ,CACnB,SAAiB,EACjB,MAAe,EACf,UAAU,GAAG,KAAK;;YAElB,MAAM,EACJ,KAAK,EAAE,EAAE,OAAO,EAAE,GACnB,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBAChC,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG,aAAa,IAAI,SAAS,EAAE;gBACtC,MAAM,EAAE;oBACN,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;oBACnC,UAAU;iBACX;aACF,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;IAWY,aAAa,CACxB,SAAiB,EACjB,GAAW;;YAEX,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBAC7B,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,GAAG,aAAa,IAAI,SAAS,IAAI,GAAG,EAAE;aAC9C,CAAC,CAAC;QACL,CAAC;KAAA;IAaY,aAAa,CACxB,SAAiB,EACjB,GAAW,EACX,KAAuC,EACvC,MAAe;;YAEf,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBAC7B,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,GAAG,aAAa,IAAI,SAAS,IAAI,GAAG,EAAE;gBAC7C,IAAI,EAAE;oBACJ,MAAM;oBACN,KAAK;iBACN;aACF,CAAC,CAAC;QACL,CAAC;KAAA;IAWY,SAAS,CACpB,SAAiB,EACjB,GAAW;;YAEX,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBAC7B,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,GAAG,aAAa,IAAI,SAAS,IAAI,GAAG,EAAE;aAC9C,CAAC,CAAC;QACL,CAAC;KAAA;CACF"}
@@ -0,0 +1,2 @@
1
+ export const STORAGE_ROUTE = '/storage';
2
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { KeyValueStorage } from './KeyValueStorage';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { KeyValueStorageConfig, KeyValueStorageRecord, KeyValueStorageRecordWithLastModified, DeletedKeyValueStorageRecord } from './types';
2
+ export declare class KeyValueStorage {
3
+ private readonly sdkApi;
4
+ constructor(params: KeyValueStorageConfig);
5
+ listKeys(tableName: string, prefix?: string, withValues?: boolean): Promise<KeyValueStorageRecordWithLastModified[]>;
6
+ getValueByKey(tableName: string, key: string): Promise<KeyValueStorageRecord>;
7
+ setValueByKey(tableName: string, key: string, value: Record<string, unknown> | string, expire?: number): Promise<KeyValueStorageRecord>;
8
+ deleteKey(tableName: string, key: string): Promise<DeletedKeyValueStorageRecord>;
9
+ }
@@ -0,0 +1 @@
1
+ export declare const STORAGE_ROUTE = "/storage";
@@ -0,0 +1,2 @@
1
+ export { KeyValueStorage } from './KeyValueStorage';
2
+ export * from './types';
@@ -0,0 +1,13 @@
1
+ import { Token } from '@or-sdk/base';
2
+ export declare type KeyValueStorageConfig = {
3
+ token: Token;
4
+ discoveryUrl: string;
5
+ };
6
+ export declare type KeyValueStorageRecord = {
7
+ key: string;
8
+ value?: Record<string, unknown> | string;
9
+ };
10
+ export declare type KeyValueStorageRecordWithLastModified = KeyValueStorageRecord & {
11
+ lastModified: string;
12
+ };
13
+ export declare type DeletedKeyValueStorageRecord = Required<Pick<KeyValueStorageRecord, 'value'>>;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "version": "0.9.1",
3
+ "name": "@or-sdk/key-value-storage",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "types": "dist/types/index.d.ts",
7
+ "scripts": {
8
+ "build": "npm run clean && concurrently \"npm run build:cjs\" \"npm run build:esm\" \"npm run build:types\"",
9
+ "build:watch": "concurrently -r --hide 1,2 \"npm run build:watch:cjs\" \"npm run build:watch:esm\" \"npm run build:watch:types\"",
10
+ "build:cjs": "tsc --project tsconfig.json",
11
+ "build:watch:cjs": "tsc --project tsconfig.json -w",
12
+ "build:esm": "tsc --project tsconfig.esm.json",
13
+ "build:watch:esm": "tsc --project tsconfig.esm.json -w",
14
+ "build:types": "tsc --project tsconfig.types.json",
15
+ "build:watch:types": "tsc --project tsconfig.types.json -w",
16
+ "clean": "rm -rf ./dist"
17
+ },
18
+ "devDependencies": {
19
+ "concurrently": "^6.4.0",
20
+ "typescript": "^4.4.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "@or-sdk/base": "^0.9.1",
27
+ "@or-sdk/sdk-api": "^0.9.1"
28
+ },
29
+ "gitHead": "19c2221d6f95694979b32f51d729771a558ef189"
30
+ }
@@ -0,0 +1,128 @@
1
+ import { SdkApi } from '@or-sdk/sdk-api';
2
+ import {
3
+ KeyValueStorageConfig,
4
+ KeyValueStorageRecord,
5
+ KeyValueStorageRecordWithLastModified,
6
+ DeletedKeyValueStorageRecord,
7
+ } from './types';
8
+ import { STORAGE_ROUTE } from './constants';
9
+
10
+ /**
11
+ * OneReach KeyValueStorage service client
12
+ * ## Installation:
13
+ * ```
14
+ * $ npm i @or-sdk/key-value-storage
15
+ * ```
16
+ */
17
+ export class KeyValueStorage {
18
+ private readonly sdkApi: SdkApi;
19
+
20
+ /**
21
+ * ```typescript
22
+ * import { KeyValueStorage } from '@or-sdk/key-value-storage'
23
+ * const keyValueStorage = new KeyValueStorage({token: 'my-account-token-string', discoveryUrl: 'http://example.tables/endpoint'});
24
+ * ```
25
+ */
26
+ constructor(params: KeyValueStorageConfig) {
27
+ const { token, discoveryUrl } = params;
28
+
29
+ this.sdkApi = new SdkApi({
30
+ token,
31
+ discoveryUrl,
32
+ });
33
+ }
34
+
35
+ /**
36
+ * List keys in a table starting with given substring
37
+ *
38
+ * ```typescript
39
+ * const tableName = 'my-table';
40
+ * const prefix = '__some_prefix';
41
+ * const withValues = false; // set to true to receive record values alongside key names
42
+ * const list = await keyValueStorage.listKeys(tableName, prefix, withValues);
43
+ * ```
44
+ */
45
+ public async listKeys(
46
+ tableName: string,
47
+ prefix?: string,
48
+ withValues = false
49
+ ): Promise<KeyValueStorageRecordWithLastModified[]> {
50
+ const {
51
+ value: { records },
52
+ } = await this.sdkApi.makeRequest({
53
+ method: 'GET',
54
+ route: `${STORAGE_ROUTE}/${tableName}`,
55
+ params: {
56
+ prefix: prefix ? prefix : undefined,
57
+ withValues,
58
+ },
59
+ });
60
+
61
+ return records;
62
+ }
63
+
64
+ /**
65
+ * Get value from table by key
66
+ *
67
+ * ```typescript
68
+ * const tableName = 'my-table';
69
+ * const key = 'my-key';
70
+ * const record = await keyValueStorage.getValueByKey(tableName, key);
71
+ * ```
72
+ */
73
+ public async getValueByKey(
74
+ tableName: string,
75
+ key: string
76
+ ): Promise<KeyValueStorageRecord> {
77
+ return this.sdkApi.makeRequest({
78
+ method: 'GET',
79
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
80
+ });
81
+ }
82
+
83
+ /**
84
+ * Set value to table by key
85
+ *
86
+ * ```typescript
87
+ * const tableName = 'my-table';
88
+ * const key = 'my-key';
89
+ * const value = { 'prop': 'value' };
90
+ * const expire = 300000; // time before record deletion in milliseconds
91
+ * await keyValueStorage.setValueByKey(tableName, key, value, expire);
92
+ * ```
93
+ */
94
+ public async setValueByKey(
95
+ tableName: string,
96
+ key: string,
97
+ value: Record<string, unknown> | string,
98
+ expire?: number
99
+ ): Promise<KeyValueStorageRecord> {
100
+ return this.sdkApi.makeRequest({
101
+ method: 'POST',
102
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
103
+ data: {
104
+ expire,
105
+ value,
106
+ },
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Delete a key from a table
112
+ *
113
+ * ```typescript
114
+ * const tableName = 'my-table';
115
+ * const key = 'my-key';
116
+ * const record = await keyValueStorage.deleteKey(tableName, key);
117
+ * ```
118
+ */
119
+ public async deleteKey(
120
+ tableName: string,
121
+ key: string
122
+ ): Promise<DeletedKeyValueStorageRecord> {
123
+ return this.sdkApi.makeRequest({
124
+ method: 'DELETE',
125
+ route: `${STORAGE_ROUTE}/${tableName}/${key}`,
126
+ });
127
+ }
128
+ }
@@ -0,0 +1 @@
1
+ export const STORAGE_ROUTE = '/storage';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { KeyValueStorage } from './KeyValueStorage';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { Token } from '@or-sdk/base';
2
+
3
+ export type KeyValueStorageConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * function which return token
10
+ */
11
+ discoveryUrl: string;
12
+ };
13
+
14
+
15
+ export type KeyValueStorageRecord = {
16
+ /**
17
+ * Record key
18
+ */
19
+ key: string;
20
+
21
+ value?: Record<string, unknown> | string;
22
+ };
23
+
24
+ export type KeyValueStorageRecordWithLastModified = KeyValueStorageRecord & {
25
+ lastModified: string;
26
+ };
27
+
28
+ export type DeletedKeyValueStorageRecord = Required<Pick<KeyValueStorageRecord, 'value'>>;
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "ES6",
5
+ "target": "es6",
6
+ "outDir": "./dist/esm/",
7
+ "rootDir": "./src"
8
+ }
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/types/",
5
+ "rootDir": "./src",
6
+ "declaration": true,
7
+ "emitDeclarationOnly": true
8
+ }
9
+ }