@forge/cache 1.0.2 → 1.0.3-next.0-experimental-ab129b0

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.
Files changed (61) hide show
  1. package/out/cache.d.ts +4 -1
  2. package/out/cache.d.ts.map +1 -1
  3. package/out/cache.js +11 -0
  4. package/out/kvs/conditions.d.ts +38 -0
  5. package/out/kvs/conditions.d.ts.map +1 -0
  6. package/out/kvs/conditions.js +98 -0
  7. package/out/kvs/entity-query.d.ts +26 -0
  8. package/out/kvs/entity-query.d.ts.map +1 -0
  9. package/out/kvs/entity-query.js +102 -0
  10. package/out/kvs/entity.d.ts +13 -0
  11. package/out/kvs/entity.d.ts.map +1 -0
  12. package/out/kvs/entity.js +35 -0
  13. package/out/kvs/errors.d.ts +21 -0
  14. package/out/kvs/errors.d.ts.map +1 -0
  15. package/out/kvs/errors.js +26 -0
  16. package/out/kvs/index.d.ts +10 -0
  17. package/out/kvs/index.d.ts.map +1 -0
  18. package/out/kvs/index.js +42 -0
  19. package/out/kvs/interfaces/entity-query.d.ts +41 -0
  20. package/out/kvs/interfaces/entity-query.d.ts.map +1 -0
  21. package/out/kvs/interfaces/entity-query.js +2 -0
  22. package/out/kvs/interfaces/kvs-api.d.ts +95 -0
  23. package/out/kvs/interfaces/kvs-api.d.ts.map +1 -0
  24. package/out/kvs/interfaces/kvs-api.js +2 -0
  25. package/out/kvs/interfaces/kvs.d.ts +21 -0
  26. package/out/kvs/interfaces/kvs.d.ts.map +1 -0
  27. package/out/kvs/interfaces/kvs.js +2 -0
  28. package/out/kvs/interfaces/query.d.ts +17 -0
  29. package/out/kvs/interfaces/query.d.ts.map +1 -0
  30. package/out/kvs/interfaces/query.js +2 -0
  31. package/out/kvs/interfaces/transaction.d.ts +29 -0
  32. package/out/kvs/interfaces/transaction.d.ts.map +1 -0
  33. package/out/kvs/interfaces/transaction.js +2 -0
  34. package/out/kvs/interfaces/types.d.ts +64 -0
  35. package/out/kvs/interfaces/types.d.ts.map +1 -0
  36. package/out/kvs/interfaces/types.js +8 -0
  37. package/out/kvs/kvs.d.ts +18 -0
  38. package/out/kvs/kvs.d.ts.map +1 -0
  39. package/out/kvs/kvs.js +40 -0
  40. package/out/kvs/query.d.ts +14 -0
  41. package/out/kvs/query.d.ts.map +1 -0
  42. package/out/kvs/query.js +38 -0
  43. package/out/kvs/storage-api.d.ts +22 -0
  44. package/out/kvs/storage-api.d.ts.map +1 -0
  45. package/out/kvs/storage-api.js +103 -0
  46. package/out/kvs/transaction-api.d.ts +14 -0
  47. package/out/kvs/transaction-api.d.ts.map +1 -0
  48. package/out/kvs/transaction-api.js +66 -0
  49. package/out/kvs/utils/error-handling.d.ts +7 -0
  50. package/out/kvs/utils/error-handling.d.ts.map +1 -0
  51. package/out/kvs/utils/error-handling.js +42 -0
  52. package/out/kvs/utils/transaction-request-builder.d.ts +6 -0
  53. package/out/kvs/utils/transaction-request-builder.d.ts.map +1 -0
  54. package/out/kvs/utils/transaction-request-builder.js +49 -0
  55. package/package.json +2 -2
  56. package/out/__test__/cache.test.d.ts +0 -2
  57. package/out/__test__/cache.test.d.ts.map +0 -1
  58. package/out/__test__/cache.test.js +0 -358
  59. package/out/__test__/tunnel.test.d.ts +0 -2
  60. package/out/__test__/tunnel.test.d.ts.map +0 -1
  61. package/out/__test__/tunnel.test.js +0 -176
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs-api.d.ts","sourceRoot":"","sources":["../../../src/kvs/interfaces/kvs-api.ts"],"names":[],"mappings":"AAAA,aAAK,SAAS,GAAG;IACf,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,aAAK,cAAc,CAAC,CAAC,IAAI,SAAS,GAAG;IACnC,KAAK,EAAE,CAAC,CAAC;CACV,CAAC;AAEF,oBAAY,UAAU,GAAG,SAAS,CAAC;AACnC,oBAAY,WAAW,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC;AAE/C,oBAAY,UAAU,CAAC,CA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,MAAM,CAAC;CACjB,CAAC;AAGF,oBAAY,oBAAoB,GAAG,kBAAkB,CAAC;AAEtD,oBAAY,UAAU,CAAC,CAAC,IAAI;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;IACT,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,oBAAoB,CAAC;CAClC,CAAC;AAGF,oBAAY,kBAAkB,CAAC,CAAC,IAAI;IAClC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IACtB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { IndexQueryBuilder } from './entity-query';
2
+ import { QueryBuilder } from './query';
3
+ import { TransactionBuilder } from './transaction';
4
+ export interface Kvs {
5
+ get<T>(key: string): Promise<T | undefined>;
6
+ set<T>(key: string, value: T): Promise<void>;
7
+ delete(key: string): Promise<void>;
8
+ query(): QueryBuilder;
9
+ getSecret<T>(key: string): Promise<T | undefined>;
10
+ setSecret<T>(key: string, value: T): Promise<void>;
11
+ deleteSecret(key: string): Promise<void>;
12
+ entity<T>(entityName: string): KvsEntity<T>;
13
+ transact(): TransactionBuilder;
14
+ }
15
+ export interface KvsEntity<T> {
16
+ get(key: string): Promise<T | undefined>;
17
+ set(key: string, value: T): Promise<void>;
18
+ delete(key: string): Promise<void>;
19
+ query(): IndexQueryBuilder<T>;
20
+ }
21
+ //# sourceMappingURL=kvs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs.d.ts","sourceRoot":"","sources":["../../../src/kvs/interfaces/kvs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,WAAW,GAAG;IAClB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAC5C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,YAAY,CAAC;IAEtB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAClD,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAE5C,QAAQ,IAAI,kBAAkB,CAAC;CAChC;AAED,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAC/B"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ import { BeginsWithClause, ListResult, Result } from './types';
2
+ export declare type WhereClause = BeginsWithClause;
3
+ export interface QueryBuilder {
4
+ where(property: 'key', condition: WhereClause): QueryBuilder;
5
+ cursor(cursor: string): QueryBuilder;
6
+ limit(limit: number): QueryBuilder;
7
+ getMany<T>(): Promise<ListResult<T>>;
8
+ getOne<T>(): Promise<Result<T> | undefined>;
9
+ }
10
+ export interface QueryOptions {
11
+ where?: Array<{
12
+ property: 'key';
13
+ } & WhereClause>;
14
+ cursor?: string;
15
+ limit?: number;
16
+ }
17
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/kvs/interfaces/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE/D,oBAAY,WAAW,GAAG,gBAAgB,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,YAAY,CAAC;IAC7D,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC;IACrC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC;IACnC,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAA;KAAE,GAAG,WAAW,CAAC,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ import { BaseFilter } from '../entity-query';
2
+ export interface TransactSet<T> {
3
+ key: string;
4
+ value: T;
5
+ entity?: EntityConditions<T>;
6
+ }
7
+ export interface TransactDelete<T> {
8
+ key: string;
9
+ entity?: EntityConditions<T>;
10
+ }
11
+ export interface TransactCheck<T> {
12
+ key: string;
13
+ entity: EntityRequiredConditions<T>;
14
+ }
15
+ export declare type EntityConditions<T> = {
16
+ entityName: string;
17
+ conditions?: BaseFilter<T>;
18
+ };
19
+ export declare type EntityRequiredConditions<T> = Omit<EntityConditions<T>, 'conditions'> & {
20
+ conditions: BaseFilter<T>;
21
+ };
22
+ export declare type StorageValue = string | number | boolean | Record<string, any> | any[];
23
+ export interface TransactionBuilder {
24
+ set<T>(key: string, value: T, entity?: EntityConditions<T>): this;
25
+ delete<T>(key: string, entity?: EntityConditions<T>): this;
26
+ check<T>(key: string, entity: EntityRequiredConditions<T>): this;
27
+ execute(): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../../src/kvs/interfaces/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC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1
+ export interface Result<T> {
2
+ key: string;
3
+ value: T;
4
+ }
5
+ export interface ListResult<T> {
6
+ results: Result<T>[];
7
+ nextCursor?: string;
8
+ }
9
+ export declare enum Sort {
10
+ ASC = "ASC",
11
+ DESC = "DESC"
12
+ }
13
+ export declare type StringOrNumberOrBoolean = string | number | boolean;
14
+ export declare type StringOrNumber = string | number;
15
+ export interface BetweenClause<T extends StringOrNumber> {
16
+ condition: 'BETWEEN';
17
+ values: [T, T];
18
+ }
19
+ export interface BeginsWithClause {
20
+ condition: 'BEGINS_WITH';
21
+ values: [StringOrNumber];
22
+ }
23
+ export interface ExistsClause {
24
+ condition: 'EXISTS';
25
+ values: [true];
26
+ }
27
+ export interface NotExistsClause {
28
+ condition: 'NOT_EXISTS';
29
+ values: [true];
30
+ }
31
+ export interface GreaterThanClause {
32
+ condition: 'GREATER_THAN';
33
+ values: [StringOrNumber];
34
+ }
35
+ export interface GreaterThanEqualToClause {
36
+ condition: 'GREATER_THAN_EQUAL_TO';
37
+ values: [StringOrNumber];
38
+ }
39
+ export interface LessThanClause {
40
+ condition: 'LESS_THAN';
41
+ values: [StringOrNumber];
42
+ }
43
+ export interface LessThanEqualToClause {
44
+ condition: 'LESS_THAN_EQUAL_TO';
45
+ values: [StringOrNumber];
46
+ }
47
+ export interface ContainsClause {
48
+ condition: 'CONTAINS';
49
+ values: [string];
50
+ }
51
+ export interface NotContainsClause {
52
+ condition: 'NOT_CONTAINS';
53
+ values: [string];
54
+ }
55
+ export interface EqualToClause {
56
+ condition: 'EQUAL_TO';
57
+ values: [StringOrNumberOrBoolean];
58
+ }
59
+ export interface NotEqualToClause {
60
+ condition: 'NOT_EQUAL_TO';
61
+ values: [StringOrNumberOrBoolean];
62
+ }
63
+ export declare type FilterOperator = 'or' | 'and';
64
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/kvs/interfaces/types.ts"],"names":[],"mappings":"AAAA,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M,EAAE,CAAC,cAAc,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,UAAU,CAAC;IACtB,MAAM,EAAE,CAAC,uBAAuB,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,CAAC,uBAAuB,CAAC,CAAC;CACnC;AAED,oBAAY,cAAc,GAAG,IAAI,GAAG,KAAK,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sort = void 0;
4
+ var Sort;
5
+ (function (Sort) {
6
+ Sort["ASC"] = "ASC";
7
+ Sort["DESC"] = "DESC";
8
+ })(Sort = exports.Sort || (exports.Sort = {}));
@@ -0,0 +1,18 @@
1
+ import { KvsEntity, Kvs } from './interfaces/kvs';
2
+ import { QueryBuilder } from './interfaces/query';
3
+ import { TransactionBuilder } from './interfaces/transaction';
4
+ import { StorageApi } from './storage-api';
5
+ export declare class KvsImpl implements Kvs {
6
+ private readonly storageApi;
7
+ constructor(storageApi: StorageApi);
8
+ get<T>(key: string): Promise<T | undefined>;
9
+ set<T>(key: string, value: T): Promise<void>;
10
+ delete(key: string): Promise<void>;
11
+ query(): QueryBuilder;
12
+ getSecret<T>(key: string): Promise<T | undefined>;
13
+ setSecret<T>(key: string, value: T): Promise<void>;
14
+ deleteSecret(key: string): Promise<void>;
15
+ entity<T>(entityName: string): KvsEntity<T>;
16
+ transact(): TransactionBuilder;
17
+ }
18
+ //# sourceMappingURL=kvs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs.d.ts","sourceRoot":"","sources":["../../src/kvs/kvs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,OAAQ,YAAW,GAAG;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAEnD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAI3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,YAAY;IAIrB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIjD,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAI3C,QAAQ,IAAI,kBAAkB;CAG/B"}
package/out/kvs/kvs.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KvsImpl = void 0;
4
+ const entity_1 = require("./entity");
5
+ const query_1 = require("./query");
6
+ const transaction_api_1 = require("./transaction-api");
7
+ class KvsImpl {
8
+ storageApi;
9
+ constructor(storageApi) {
10
+ this.storageApi = storageApi;
11
+ }
12
+ get(key) {
13
+ return this.storageApi.get({ key });
14
+ }
15
+ set(key, value) {
16
+ return this.storageApi.set({ key, value });
17
+ }
18
+ delete(key) {
19
+ return this.storageApi.delete({ key });
20
+ }
21
+ query() {
22
+ return new query_1.KvsQueryBuilder(this.storageApi);
23
+ }
24
+ getSecret(key) {
25
+ return this.storageApi.getSecret({ key });
26
+ }
27
+ setSecret(key, value) {
28
+ return this.storageApi.setSecret({ key, value });
29
+ }
30
+ deleteSecret(key) {
31
+ return this.storageApi.deleteSecret({ key });
32
+ }
33
+ entity(entityName) {
34
+ return new entity_1.EntityImpl(entityName, this.storageApi);
35
+ }
36
+ transact() {
37
+ return new transaction_api_1.TransactionBuilderImpl(this.storageApi);
38
+ }
39
+ }
40
+ exports.KvsImpl = KvsImpl;
@@ -0,0 +1,14 @@
1
+ import { QueryBuilder, QueryOptions, WhereClause } from './interfaces/query';
2
+ import { ListResult, Result } from './interfaces/types';
3
+ import { StorageApi } from './storage-api';
4
+ export declare class KvsQueryBuilder implements QueryBuilder {
5
+ private storageApi;
6
+ private options;
7
+ constructor(storageApi: StorageApi, options?: QueryOptions);
8
+ where(property: 'key', condition: WhereClause): this;
9
+ cursor(cursor: string): this;
10
+ limit(limit: number): this;
11
+ getOne<T>(): Promise<Result<T> | undefined>;
12
+ getMany<T>(): Promise<ListResult<T>>;
13
+ }
14
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/kvs/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBAAa,eAAgB,YAAW,YAAY;IAEhD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,OAAO;gBADP,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,YAAiB;IAGpC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,IAAI;IAKpD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAKpB,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAQjD,OAAO,CAAC,CAAC,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;CAOrC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KvsQueryBuilder = void 0;
4
+ class KvsQueryBuilder {
5
+ storageApi;
6
+ options;
7
+ constructor(storageApi, options = {}) {
8
+ this.storageApi = storageApi;
9
+ this.options = options;
10
+ }
11
+ where(property, condition) {
12
+ this.options.where = [{ property, ...condition }];
13
+ return this;
14
+ }
15
+ cursor(cursor) {
16
+ this.options.cursor = cursor;
17
+ return this;
18
+ }
19
+ limit(limit) {
20
+ this.options.limit = limit;
21
+ return this;
22
+ }
23
+ async getOne() {
24
+ const { results } = await this.limit(1).getMany();
25
+ if (results && results.length > 0) {
26
+ return results[0];
27
+ }
28
+ return undefined;
29
+ }
30
+ getMany() {
31
+ return this.storageApi.query({
32
+ limit: this.options.limit,
33
+ after: this.options.cursor,
34
+ where: this.options.where
35
+ });
36
+ }
37
+ }
38
+ exports.KvsQueryBuilder = KvsQueryBuilder;
@@ -0,0 +1,22 @@
1
+ import { FetchMethod } from '@forge/api';
2
+ import { ListResult } from './interfaces/types';
3
+ import { DeleteRequest, EntityDeleteRequest, EntityGetRequest, EntityQueryRequest, EntitySetRequest, GetRequest, QueryRequest, SecretDeleteRequest, SecretGetRequest, SecretSetRequest, SetRequest, TransactionRequest } from './interfaces/kvs-api';
4
+ export declare class StorageApi {
5
+ private apiClient;
6
+ constructor(apiClient: FetchMethod);
7
+ get<T>(body: GetRequest): Promise<T | undefined>;
8
+ getSecret<T>(body: SecretGetRequest): Promise<T | undefined>;
9
+ getEntity<T>(body: EntityGetRequest): Promise<T | undefined>;
10
+ set<T>(body: SetRequest<T>): Promise<void>;
11
+ setSecret<T>(body: SecretSetRequest<T>): Promise<void>;
12
+ setEntity<T>(body: EntitySetRequest<T>): Promise<void>;
13
+ delete(body: DeleteRequest): Promise<void>;
14
+ deleteSecret(body: SecretDeleteRequest): Promise<void>;
15
+ deleteEntity(body: EntityDeleteRequest): Promise<void>;
16
+ query<T>(body: QueryRequest): Promise<ListResult<T>>;
17
+ queryEntity<T>(body: EntityQueryRequest): Promise<ListResult<T>>;
18
+ transact<T>(transactionRequest: TransactionRequest<T>): Promise<void>;
19
+ private handleKeyNotFound;
20
+ private request;
21
+ }
22
+ //# sourceMappingURL=storage-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-api.d.ts","sourceRoot":"","sources":["../../src/kvs/storage-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EACL,aAAa,EAEb,mBAAmB,EAEnB,gBAAgB,EAEhB,kBAAkB,EAElB,gBAAgB,EAEhB,UAAU,EAEV,YAAY,EAEZ,mBAAmB,EAEnB,gBAAgB,EAEhB,gBAAgB,EAEhB,UAAU,EAEV,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,UAAU;IACT,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,WAAW;IAEpC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAOhD,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAO5D,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAO5D,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAQpD,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAQhE,QAAQ,CAAC,CAAC,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAI7D,iBAAiB;YAWjB,OAAO;CAyBtB"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageApi = void 0;
4
+ const error_handling_1 = require("./utils/error-handling");
5
+ const errors_1 = require("./errors");
6
+ class StorageApi {
7
+ apiClient;
8
+ constructor(apiClient) {
9
+ this.apiClient = apiClient;
10
+ }
11
+ async get(body) {
12
+ const rs = await this.handleKeyNotFound(async () => {
13
+ return this.request('/api/v1/get', body, true);
14
+ });
15
+ return rs?.value;
16
+ }
17
+ async getSecret(body) {
18
+ const rs = await this.handleKeyNotFound(async () => {
19
+ return this.request('/api/v1/secret/get', body, true);
20
+ });
21
+ return rs?.value;
22
+ }
23
+ async getEntity(body) {
24
+ const rs = await this.handleKeyNotFound(async () => {
25
+ return this.request('/api/v1/entity/get', body, true);
26
+ });
27
+ return rs?.value;
28
+ }
29
+ async set(body) {
30
+ await this.request('/api/v1/set', body, false);
31
+ }
32
+ async setSecret(body) {
33
+ await this.request('/api/v1/secret/set', body, false);
34
+ }
35
+ async setEntity(body) {
36
+ await this.request('/api/v1/entity/set', body, false);
37
+ }
38
+ async delete(body) {
39
+ await this.handleKeyNotFound(async () => {
40
+ return this.request('/api/v1/delete', body, false);
41
+ });
42
+ }
43
+ async deleteSecret(body) {
44
+ await this.handleKeyNotFound(async () => {
45
+ return this.request('/api/v1/secret/delete', body, false);
46
+ });
47
+ }
48
+ async deleteEntity(body) {
49
+ await this.handleKeyNotFound(async () => {
50
+ return this.request('/api/v1/entity/delete', body, false);
51
+ });
52
+ }
53
+ async query(body) {
54
+ const rs = await this.request('/api/v1/query', body, true);
55
+ return {
56
+ results: rs.data,
57
+ nextCursor: rs.cursor
58
+ };
59
+ }
60
+ async queryEntity(body) {
61
+ const rs = await this.request('/api/v1/entity/query', body, true);
62
+ return {
63
+ results: rs.data,
64
+ nextCursor: rs.cursor
65
+ };
66
+ }
67
+ async transact(transactionRequest) {
68
+ await this.request('/api/v1/transaction', transactionRequest, false);
69
+ }
70
+ async handleKeyNotFound(fn) {
71
+ try {
72
+ return await fn();
73
+ }
74
+ catch (e) {
75
+ if (e instanceof errors_1.ForgeKvsAPIError && e.code === 'KEY_NOT_FOUND') {
76
+ return undefined;
77
+ }
78
+ throw e;
79
+ }
80
+ }
81
+ async request(path, body, isResponseExpected) {
82
+ const requestBody = {
83
+ method: 'POST',
84
+ body: JSON.stringify(body),
85
+ headers: {
86
+ 'content-type': 'application/json'
87
+ }
88
+ };
89
+ const response = await this.apiClient(path, requestBody);
90
+ await (0, error_handling_1.checkResponseError)(response);
91
+ if (!isResponseExpected) {
92
+ return {};
93
+ }
94
+ const responseText = await response.text();
95
+ try {
96
+ return JSON.parse(responseText);
97
+ }
98
+ catch (error) {
99
+ throw new errors_1.ForgeKvsError(`Unexpected error. Response was not valid JSON: ${responseText}`);
100
+ }
101
+ }
102
+ }
103
+ exports.StorageApi = StorageApi;
@@ -0,0 +1,14 @@
1
+ import { StorageApi } from './storage-api';
2
+ import { EntityConditions, EntityRequiredConditions, TransactCheck, TransactDelete, TransactionBuilder, TransactSet } from './interfaces/transaction';
3
+ export declare class TransactionBuilderImpl implements TransactionBuilder {
4
+ private readonly storageApi;
5
+ protected sets: TransactSet<unknown>[];
6
+ protected deletes: TransactDelete<unknown>[];
7
+ protected checks: TransactCheck<unknown>[];
8
+ constructor(storageApi: StorageApi, sets?: TransactSet<unknown>[], deletes?: TransactDelete<unknown>[], checks?: TransactCheck<unknown>[]);
9
+ set<T>(key: string, value: T, entity?: EntityConditions<T>): this;
10
+ delete<T>(key: string, entity?: EntityConditions<T>): this;
11
+ check<T>(key: string, { entityName, conditions }: EntityRequiredConditions<T>): this;
12
+ execute(): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=transaction-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-api.d.ts","sourceRoot":"","sources":["../../src/kvs/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;AAIlC,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,GAAG,IAAI;IAkBjE,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"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionBuilderImpl = void 0;
4
+ const transaction_request_builder_1 = require("./utils/transaction-request-builder");
5
+ class TransactionBuilderImpl {
6
+ storageApi;
7
+ sets;
8
+ deletes;
9
+ checks;
10
+ constructor(storageApi, sets = [], deletes = [], checks = []) {
11
+ this.storageApi = storageApi;
12
+ this.sets = sets;
13
+ this.deletes = deletes;
14
+ this.checks = checks;
15
+ }
16
+ set(key, value, entity) {
17
+ const transactSet = {
18
+ key,
19
+ value
20
+ };
21
+ if (entity) {
22
+ transactSet.entity = {
23
+ entityName: entity.entityName,
24
+ conditions: entity.conditions
25
+ };
26
+ }
27
+ this.sets.push(transactSet);
28
+ return this;
29
+ }
30
+ delete(key, entity) {
31
+ const transactDelete = {
32
+ key
33
+ };
34
+ if (entity) {
35
+ transactDelete.entity = {
36
+ entityName: entity.entityName,
37
+ conditions: entity.conditions
38
+ };
39
+ }
40
+ this.deletes.push(transactDelete);
41
+ return this;
42
+ }
43
+ check(key, { entityName, conditions }) {
44
+ const transactCheck = {
45
+ key,
46
+ entity: {
47
+ entityName,
48
+ conditions
49
+ }
50
+ };
51
+ this.checks.push(transactCheck);
52
+ return this;
53
+ }
54
+ async execute() {
55
+ const undefineEmptyArray = (arr) => {
56
+ return arr.length === 0 ? undefined : arr;
57
+ };
58
+ const request = {
59
+ set: undefineEmptyArray(this.sets.map(transaction_request_builder_1.buildRequestSet)),
60
+ delete: undefineEmptyArray(this.deletes.map(transaction_request_builder_1.buildRequestDeletes)),
61
+ check: undefineEmptyArray(this.checks.map(transaction_request_builder_1.buildRequestChecks))
62
+ };
63
+ await this.storageApi.transact(request);
64
+ }
65
+ }
66
+ exports.TransactionBuilderImpl = TransactionBuilderImpl;
@@ -0,0 +1,7 @@
1
+ import { APIResponse } from '@forge/api';
2
+ import { ForgeError } from '../errors';
3
+ export declare function isForgeError(body: unknown): body is ForgeError;
4
+ export declare function safeGetParsedBody(text: string): unknown | undefined;
5
+ export declare function extractTraceId(response: APIResponse): string | null;
6
+ export declare function checkResponseError(response: APIResponse): Promise<void>;
7
+ //# sourceMappingURL=error-handling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handling.d.ts","sourceRoot":"","sources":["../../../src/kvs/utils/error-handling.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAA2B,UAAU,EAAoB,MAAM,WAAW,CAAC;AAElF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,UAAU,CAE9D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAMnE;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAEnE;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAwB7E"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkResponseError = exports.extractTraceId = exports.safeGetParsedBody = exports.isForgeError = void 0;
4
+ const errors_1 = require("../errors");
5
+ function isForgeError(body) {
6
+ return typeof body === 'object' && body !== null && 'code' in body && 'message' in body;
7
+ }
8
+ exports.isForgeError = isForgeError;
9
+ function safeGetParsedBody(text) {
10
+ try {
11
+ return JSON.parse(text);
12
+ }
13
+ catch (error) {
14
+ return undefined;
15
+ }
16
+ }
17
+ exports.safeGetParsedBody = safeGetParsedBody;
18
+ function extractTraceId(response) {
19
+ return response.headers.get('x-b3-traceid') || response.headers.get('x-trace-id');
20
+ }
21
+ exports.extractTraceId = extractTraceId;
22
+ async function checkResponseError(response) {
23
+ if (response.ok) {
24
+ return;
25
+ }
26
+ const responseText = await response.text();
27
+ const details = {
28
+ status: response.status,
29
+ statusText: response.statusText,
30
+ traceId: extractTraceId(response)
31
+ };
32
+ const parsedBody = safeGetParsedBody(responseText);
33
+ if (parsedBody && isForgeError(parsedBody)) {
34
+ throw new errors_1.ForgeKvsAPIError(details, parsedBody);
35
+ }
36
+ throw new errors_1.ForgeKvsAPIError(details, {
37
+ code: 'UNKNOWN_ERROR',
38
+ message: 'Unexpected error in Forge KVS API',
39
+ context: { responseText }
40
+ });
41
+ }
42
+ exports.checkResponseError = checkResponseError;
@@ -0,0 +1,6 @@
1
+ import { RequestCheck, RequestDelete, RequestSet } from '../interfaces/kvs-api';
2
+ import { TransactCheck, TransactDelete, TransactSet } from '../interfaces/transaction';
3
+ export declare const buildRequestSet: <T>(setOperation: TransactSet<T>) => RequestSet<T>;
4
+ export declare const buildRequestDeletes: <T>(deleteOperation: TransactDelete<T>) => RequestDelete;
5
+ export declare const buildRequestChecks: <T>(checkOperation: TransactCheck<T>) => RequestCheck;
6
+ //# sourceMappingURL=transaction-request-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-request-builder.d.ts","sourceRoot":"","sources":["../../../src/kvs/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,oDAW3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,6CAA4C,aAU3E,CAAC;AAEF,eAAO,MAAM,kBAAkB,2CAA0C,YAUxE,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildRequestChecks = exports.buildRequestDeletes = exports.buildRequestSet = void 0;
4
+ const errors_1 = require("../errors");
5
+ function buildConditionsRequest(filter) {
6
+ if (!filter) {
7
+ return undefined;
8
+ }
9
+ if (filter.filters().length === 0) {
10
+ throw new errors_1.ForgeKvsError('Builder must have at least one condition set');
11
+ }
12
+ return {
13
+ [filter.operator()]: filter.filters()
14
+ };
15
+ }
16
+ const buildRequestSet = (setOperation) => {
17
+ const { key, value, entity } = setOperation;
18
+ const entityName = entity?.entityName;
19
+ const conditions = buildConditionsRequest(entity?.conditions);
20
+ return {
21
+ key,
22
+ value,
23
+ entityName,
24
+ conditions
25
+ };
26
+ };
27
+ exports.buildRequestSet = buildRequestSet;
28
+ const buildRequestDeletes = (deleteOperation) => {
29
+ const { key, entity } = deleteOperation;
30
+ const entityName = entity?.entityName;
31
+ const conditions = buildConditionsRequest(entity?.conditions);
32
+ return {
33
+ key,
34
+ entityName,
35
+ conditions
36
+ };
37
+ };
38
+ exports.buildRequestDeletes = buildRequestDeletes;
39
+ const buildRequestChecks = (checkOperation) => {
40
+ const { key, entity } = checkOperation;
41
+ const entityName = entity.entityName;
42
+ const conditions = buildConditionsRequest(entity.conditions);
43
+ return {
44
+ key,
45
+ entityName,
46
+ conditions
47
+ };
48
+ };
49
+ exports.buildRequestChecks = buildRequestChecks;