@forge/kvs 1.2.7-next.0-experimental-44a932f → 1.3.0-next.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/out/__test__/index.test.js +432 -18
- package/out/entity-query.d.ts +3 -2
- package/out/entity-query.d.ts.map +1 -1
- package/out/entity-query.js +10 -3
- package/out/entity.d.ts +6 -4
- package/out/entity.d.ts.map +1 -1
- package/out/entity.js +5 -4
- package/out/interfaces/entity-query.d.ts +2 -1
- package/out/interfaces/entity-query.d.ts.map +1 -1
- package/out/interfaces/kvs-api.d.ts +19 -10
- package/out/interfaces/kvs-api.d.ts.map +1 -1
- package/out/interfaces/kvs.d.ts +13 -6
- package/out/interfaces/kvs.d.ts.map +1 -1
- package/out/interfaces/query.d.ts +2 -1
- package/out/interfaces/query.d.ts.map +1 -1
- package/out/interfaces/transaction.d.ts +3 -1
- package/out/interfaces/transaction.d.ts.map +1 -1
- package/out/interfaces/types.d.ts +32 -1
- package/out/interfaces/types.d.ts.map +1 -1
- package/out/interfaces/types.js +6 -1
- package/out/kvs.d.ts +10 -5
- package/out/kvs.d.ts.map +1 -1
- package/out/kvs.js +6 -6
- package/out/query.d.ts.map +1 -1
- package/out/query.js +5 -1
- package/out/storage-api.d.ts +5 -4
- package/out/storage-api.d.ts.map +1 -1
- package/out/storage-api.js +52 -24
- package/out/transaction-api.d.ts +2 -1
- package/out/transaction-api.d.ts.map +1 -1
- package/out/transaction-api.js +3 -2
- package/out/utils/transaction-request-builder.d.ts.map +1 -1
- package/out/utils/transaction-request-builder.js +3 -2
- package/package.json +2 -2
package/out/storage-api.js
CHANGED
|
@@ -4,6 +4,12 @@ exports.StorageApi = void 0;
|
|
|
4
4
|
const types_1 = require("./interfaces/types");
|
|
5
5
|
const error_handling_1 = require("./utils/error-handling");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
|
+
var ResponseType;
|
|
8
|
+
(function (ResponseType) {
|
|
9
|
+
ResponseType[ResponseType["NONE"] = 0] = "NONE";
|
|
10
|
+
ResponseType[ResponseType["EXPECTED"] = 1] = "EXPECTED";
|
|
11
|
+
ResponseType[ResponseType["OPTIONAL"] = 2] = "OPTIONAL";
|
|
12
|
+
})(ResponseType || (ResponseType = {}));
|
|
7
13
|
class StorageApi {
|
|
8
14
|
apiClient;
|
|
9
15
|
constructor(apiClient) {
|
|
@@ -11,69 +17,72 @@ class StorageApi {
|
|
|
11
17
|
}
|
|
12
18
|
async get(body) {
|
|
13
19
|
const rs = await this.handleKeyNotFound(async () => {
|
|
14
|
-
return this.request('/api/v1/get', body,
|
|
20
|
+
return this.request('/api/v1/get', body, ResponseType.EXPECTED);
|
|
15
21
|
});
|
|
16
|
-
return this.processGetResponse(rs, body.options
|
|
22
|
+
return this.processGetResponse(rs, body.options);
|
|
17
23
|
}
|
|
18
24
|
async getSecret(body) {
|
|
19
25
|
const rs = await this.handleKeyNotFound(async () => {
|
|
20
|
-
return this.request('/api/v1/secret/get', body,
|
|
26
|
+
return this.request('/api/v1/secret/get', body, ResponseType.EXPECTED);
|
|
21
27
|
});
|
|
22
|
-
return this.processGetResponse(rs, body.options
|
|
28
|
+
return this.processGetResponse(rs, body.options);
|
|
23
29
|
}
|
|
24
30
|
async getEntity(body) {
|
|
25
31
|
const rs = await this.handleKeyNotFound(async () => {
|
|
26
|
-
return this.request('/api/v1/entity/get', body,
|
|
32
|
+
return this.request('/api/v1/entity/get', body, ResponseType.EXPECTED);
|
|
27
33
|
});
|
|
28
|
-
return this.processGetResponse(rs, body.options
|
|
34
|
+
return this.processGetResponse(rs, body.options);
|
|
29
35
|
}
|
|
30
36
|
async set(body) {
|
|
31
|
-
await this.request('/api/v1/set', body,
|
|
37
|
+
const rs = await this.request('/api/v1/set', body, ResponseType.OPTIONAL);
|
|
38
|
+
return rs && (0, types_1.isOverrideAndReturnOptions)(body.options) ? this.processSetResponse(rs, body.options) : undefined;
|
|
32
39
|
}
|
|
33
40
|
async setSecret(body) {
|
|
34
|
-
await this.request('/api/v1/secret/set', body,
|
|
41
|
+
const rs = await this.request('/api/v1/secret/set', body, ResponseType.OPTIONAL);
|
|
42
|
+
return rs && (0, types_1.isOverrideAndReturnOptions)(body.options) ? this.processSetResponse(rs, body.options) : undefined;
|
|
35
43
|
}
|
|
36
44
|
async setEntity(body) {
|
|
37
|
-
await this.request('/api/v1/entity/set', body,
|
|
45
|
+
const rs = await this.request('/api/v1/entity/set', body, ResponseType.OPTIONAL);
|
|
46
|
+
return rs && (0, types_1.isOverrideAndReturnOptions)(body.options) ? this.processSetResponse(rs, body.options) : undefined;
|
|
38
47
|
}
|
|
39
48
|
async delete(body) {
|
|
40
49
|
await this.handleKeyNotFound(async () => {
|
|
41
|
-
return this.request('/api/v1/delete', body,
|
|
50
|
+
return this.request('/api/v1/delete', body, ResponseType.NONE);
|
|
42
51
|
});
|
|
43
52
|
}
|
|
44
53
|
async deleteSecret(body) {
|
|
45
54
|
await this.handleKeyNotFound(async () => {
|
|
46
|
-
return this.request('/api/v1/secret/delete', body,
|
|
55
|
+
return this.request('/api/v1/secret/delete', body, ResponseType.NONE);
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
58
|
async deleteEntity(body) {
|
|
50
59
|
await this.handleKeyNotFound(async () => {
|
|
51
|
-
return this.request('/api/v1/entity/delete', body,
|
|
60
|
+
return this.request('/api/v1/entity/delete', body, ResponseType.NONE);
|
|
52
61
|
});
|
|
53
62
|
}
|
|
54
63
|
async query(body) {
|
|
55
|
-
const rs = await this.request('/api/v1/query', body,
|
|
64
|
+
const rs = await this.request('/api/v1/query', body, ResponseType.EXPECTED);
|
|
56
65
|
return {
|
|
57
66
|
results: rs.data,
|
|
58
67
|
nextCursor: rs.cursor
|
|
59
68
|
};
|
|
60
69
|
}
|
|
61
70
|
async queryEntity(body) {
|
|
62
|
-
const rs = await this.request('/api/v1/entity/query', body,
|
|
71
|
+
const rs = await this.request('/api/v1/entity/query', body, ResponseType.EXPECTED);
|
|
63
72
|
return {
|
|
64
73
|
results: rs.data,
|
|
65
74
|
nextCursor: rs.cursor
|
|
66
75
|
};
|
|
67
76
|
}
|
|
68
77
|
async batchSet(body) {
|
|
69
|
-
const rs = await this.request('/api/v1/batch/set', body,
|
|
78
|
+
const rs = await this.request('/api/v1/batch/set', body, ResponseType.EXPECTED);
|
|
70
79
|
return {
|
|
71
80
|
successfulKeys: rs.successfulKeys,
|
|
72
81
|
failedKeys: rs.failedKeys
|
|
73
82
|
};
|
|
74
83
|
}
|
|
75
84
|
async transact(transactionRequest) {
|
|
76
|
-
await this.request('/api/v1/transaction', transactionRequest,
|
|
85
|
+
await this.request('/api/v1/transaction', transactionRequest, ResponseType.NONE);
|
|
77
86
|
}
|
|
78
87
|
async handleKeyNotFound(fn) {
|
|
79
88
|
try {
|
|
@@ -86,7 +95,7 @@ class StorageApi {
|
|
|
86
95
|
throw e;
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
|
-
async request(path, body,
|
|
98
|
+
async request(path, body, responseType) {
|
|
90
99
|
const requestBody = {
|
|
91
100
|
method: 'POST',
|
|
92
101
|
body: JSON.stringify(body),
|
|
@@ -96,10 +105,13 @@ class StorageApi {
|
|
|
96
105
|
};
|
|
97
106
|
const response = await this.apiClient(path, requestBody);
|
|
98
107
|
await (0, error_handling_1.checkResponseError)(response);
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
108
|
+
if (responseType === ResponseType.NONE) {
|
|
109
|
+
return;
|
|
101
110
|
}
|
|
102
111
|
const responseText = await response.text();
|
|
112
|
+
if (responseType === ResponseType.OPTIONAL && !responseText) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
103
115
|
try {
|
|
104
116
|
return JSON.parse(responseText);
|
|
105
117
|
}
|
|
@@ -107,22 +119,38 @@ class StorageApi {
|
|
|
107
119
|
throw new errors_1.ForgeKvsError(`Unexpected error. Response was not valid JSON: ${responseText}`);
|
|
108
120
|
}
|
|
109
121
|
}
|
|
110
|
-
processGetResponse(response,
|
|
111
|
-
if (response &&
|
|
112
|
-
const maybeCreatedAt =
|
|
122
|
+
processGetResponse(response, options) {
|
|
123
|
+
if (response && options) {
|
|
124
|
+
const maybeCreatedAt = options.metadataFields?.includes(types_1.MetadataField.CREATED_AT)
|
|
113
125
|
? { createdAt: response.createdAt }
|
|
114
126
|
: {};
|
|
115
|
-
const maybeUpdatedAt =
|
|
127
|
+
const maybeUpdatedAt = options.metadataFields?.includes(types_1.MetadataField.UPDATED_AT)
|
|
116
128
|
? { updatedAt: response.updatedAt }
|
|
117
129
|
: {};
|
|
130
|
+
const maybeExpireTime = options.metadataFields?.includes(types_1.MetadataField.EXPIRE_TIME)
|
|
131
|
+
? { expireTime: response.expireTime }
|
|
132
|
+
: {};
|
|
118
133
|
return {
|
|
119
134
|
key: response.key,
|
|
120
135
|
value: response.value,
|
|
121
136
|
...maybeCreatedAt,
|
|
122
|
-
...maybeUpdatedAt
|
|
137
|
+
...maybeUpdatedAt,
|
|
138
|
+
...maybeExpireTime
|
|
123
139
|
};
|
|
124
140
|
}
|
|
125
141
|
return response?.value;
|
|
126
142
|
}
|
|
143
|
+
processSetResponse(response, options) {
|
|
144
|
+
if (!response) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
key: response.key,
|
|
149
|
+
value: response.value,
|
|
150
|
+
...(options.returnMetadataFields?.includes(types_1.MetadataField.CREATED_AT) && { createdAt: response.createdAt }),
|
|
151
|
+
...(options.returnMetadataFields?.includes(types_1.MetadataField.UPDATED_AT) && { updatedAt: response.updatedAt }),
|
|
152
|
+
...(options.returnMetadataFields?.includes(types_1.MetadataField.EXPIRE_TIME) && { expireTime: response.expireTime })
|
|
153
|
+
};
|
|
154
|
+
}
|
|
127
155
|
}
|
|
128
156
|
exports.StorageApi = StorageApi;
|
package/out/transaction-api.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { StorageApi } from './storage-api';
|
|
2
2
|
import { EntityConditions, EntityRequiredConditions, TransactCheck, TransactDelete, TransactionBuilder, TransactSet } from './interfaces/transaction';
|
|
3
|
+
import { SetOptions } from './interfaces/types';
|
|
3
4
|
export declare class TransactionBuilderImpl implements TransactionBuilder {
|
|
4
5
|
private readonly storageApi;
|
|
5
6
|
protected sets: TransactSet<unknown>[];
|
|
6
7
|
protected deletes: TransactDelete<unknown>[];
|
|
7
8
|
protected checks: TransactCheck<unknown>[];
|
|
8
9
|
constructor(storageApi: StorageApi, sets?: TransactSet<unknown>[], deletes?: TransactDelete<unknown>[], checks?: TransactCheck<unknown>[]);
|
|
9
|
-
set<T>(key: string, value: T, entity?: EntityConditions<T
|
|
10
|
+
set<T>(key: string, value: T, entity?: EntityConditions<T>, options?: SetOptions): this;
|
|
10
11
|
delete<T>(key: string, entity?: EntityConditions<T>): this;
|
|
11
12
|
check<T>(key: string, { entityName, conditions }: EntityRequiredConditions<T>): this;
|
|
12
13
|
execute(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-api.d.ts","sourceRoot":"","sources":["../src/transaction-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACZ,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction-api.d.ts","sourceRoot":"","sources":["../src/transaction-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,qBAAa,sBAAuB,YAAW,kBAAkB;IAE7D,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE;IACtC,SAAS,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE;IAC5C,SAAS,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE;gBAHzB,UAAU,EAAE,UAAU,EAC7B,IAAI,GAAE,WAAW,CAAC,OAAO,CAAC,EAAO,EACjC,OAAO,GAAE,cAAc,CAAC,OAAO,CAAC,EAAO,EACvC,MAAM,GAAE,aAAa,CAAC,OAAO,CAAC,EAAO;IAGjD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAmBvF,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI;IAiB1D,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,IAAI;IAa9E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAY/B"}
|
package/out/transaction-api.js
CHANGED
|
@@ -13,10 +13,11 @@ class TransactionBuilderImpl {
|
|
|
13
13
|
this.deletes = deletes;
|
|
14
14
|
this.checks = checks;
|
|
15
15
|
}
|
|
16
|
-
set(key, value, entity) {
|
|
16
|
+
set(key, value, entity, options) {
|
|
17
17
|
const transactSet = {
|
|
18
18
|
key,
|
|
19
|
-
value
|
|
19
|
+
value,
|
|
20
|
+
options
|
|
20
21
|
};
|
|
21
22
|
if (entity) {
|
|
22
23
|
transactSet.entity = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-request-builder.d.ts","sourceRoot":"","sources":["../../src/utils/transaction-request-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAoBvF,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"transaction-request-builder.d.ts","sourceRoot":"","sources":["../../src/utils/transaction-request-builder.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAoBvF,eAAO,MAAM,eAAe,oDAY3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,6CAA4C,aAU3E,CAAC;AAEF,eAAO,MAAM,kBAAkB,2CAA0C,YAUxE,CAAC"}
|
|
@@ -14,14 +14,15 @@ function buildConditionsRequest(filter) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
const buildRequestSet = (setOperation) => {
|
|
17
|
-
const { key, value, entity } = setOperation;
|
|
17
|
+
const { key, value, entity, options } = setOperation;
|
|
18
18
|
const entityName = entity?.entityName;
|
|
19
19
|
const conditions = buildConditionsRequest(entity?.conditions);
|
|
20
20
|
return {
|
|
21
21
|
key,
|
|
22
22
|
value,
|
|
23
23
|
entityName,
|
|
24
|
-
conditions
|
|
24
|
+
conditions,
|
|
25
|
+
options
|
|
25
26
|
};
|
|
26
27
|
};
|
|
27
28
|
exports.buildRequestSet = buildRequestSet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/kvs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-next.1",
|
|
4
4
|
"description": "Forge Key Value Store SDK",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/node": "20.19.1"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@forge/api": "^7.0.1-next.0
|
|
22
|
+
"@forge/api": "^7.0.1-next.0"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"registry": "https://packages.atlassian.com/api/npm/npm-public/"
|