@forge/storage 1.5.15-experimental-1828c63 → 1.5.15-experimental-204139e

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.
@@ -257,7 +257,13 @@ describe('GlobalStorage', () => {
257
257
  setAppStoredEntities: {
258
258
  success: true,
259
259
  savedKeys: ['testKey'],
260
- failedKeys: []
260
+ failedKeys: [
261
+ {
262
+ key: 'testKey2',
263
+ code: 'KEY_TOO_LARGE',
264
+ message: 'The provided key exceeds maximum allowed length'
265
+ }
266
+ ]
261
267
  }
262
268
  }
263
269
  }
@@ -267,6 +273,10 @@ describe('GlobalStorage', () => {
267
273
  {
268
274
  key: 'testKey',
269
275
  value: 'testValue'
276
+ },
277
+ {
278
+ key: 'testKey2',
279
+ value: 'testValue2'
270
280
  }
271
281
  ]);
272
282
  verifyApiClientCalledWith(apiClientMock, {
@@ -276,13 +286,19 @@ describe('GlobalStorage', () => {
276
286
  {
277
287
  key: 'testKey',
278
288
  value: 'testValue'
289
+ },
290
+ {
291
+ key: 'testKey2',
292
+ value: 'testValue2'
279
293
  }
280
294
  ],
281
295
  encrypted: false
282
296
  }
283
297
  });
284
298
  expect(response).toHaveProperty('savedKeys', ['testKey']);
285
- expect(response).toHaveProperty('failedKeys', []);
299
+ expect(response).toHaveProperty('failedKeys', [
300
+ { key: 'testKey2', code: 'KEY_TOO_LARGE', message: 'The provided key exceeds maximum allowed length' }
301
+ ]);
286
302
  });
287
303
  it('should throw an error if the storage API returns successful = false', async () => {
288
304
  const apiClientMock = getApiClientMock({
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transaction-api.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-api.test.d.ts","sourceRoot":"","sources":["../../src/__test__/transaction-api.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __1 = require("..");
4
+ const transaction_api_1 = require("../transaction-api");
5
+ const contextAri = 'app-ari';
6
+ const getStorage = (apiClientMock) => new __1.GlobalStorage(() => contextAri, apiClientMock);
7
+ const getApiClientMock = (response, statusCode = 200) => {
8
+ return jest.fn().mockReturnValue({
9
+ ok: statusCode === 200,
10
+ status: statusCode,
11
+ text: jest.fn().mockResolvedValue(JSON.stringify(response))
12
+ });
13
+ };
14
+ describe('Transaction', () => {
15
+ it('KVS Test', async () => {
16
+ const apiClientMock = getApiClientMock({
17
+ data: {
18
+ appStoredEntity: {
19
+ value: 'testValue'
20
+ }
21
+ }
22
+ });
23
+ const globalStorage = getStorage(apiClientMock);
24
+ await new transaction_api_1.DefaultTransactionBuilder(globalStorage)
25
+ .set('user1', { name: 'anirudh' })
26
+ .set('user2', { name: 'Shivam' })
27
+ .delete('FSQL-101')
28
+ .execute();
29
+ });
30
+ it('Custom Entity Test', async () => {
31
+ const apiClientMock = getApiClientMock({
32
+ data: {
33
+ appStoredEntity: {
34
+ value: 'testValue'
35
+ }
36
+ }
37
+ });
38
+ const globalStorage = getStorage(apiClientMock);
39
+ await new transaction_api_1.DefaultTransactionBuilder(globalStorage)
40
+ .entity('users')
41
+ .set('user1', { name: 'anirudh' })
42
+ .andCondition('name', __1.FilterConditions.beginsWith('An'))
43
+ .andCondition('age', __1.FilterConditions.isLessThan(20))
44
+ .set('user2', { name: 'Shivam' })
45
+ .orCondition('name', __1.FilterConditions.beginsWith('Si'))
46
+ .orCondition('type', __1.FilterConditions.equalsTo('admin'))
47
+ .entity('projects')
48
+ .delete('FSQL-101')
49
+ .andCondition('type', __1.FilterConditions.equalsTo('BUG'))
50
+ .set('ESS-2', { type: 'Story' })
51
+ .andCondition('name', __1.FilterConditions.doesNotExist())
52
+ .execute();
53
+ });
54
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transaction-api.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-api.test.d.ts","sourceRoot":"","sources":["../../../src/entity-storage/__test__/transaction-api.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("../../index");
4
+ const custom_entity_transaction_api_1 = require("../custom-entity-transaction-api");
5
+ const contextAri = 'app-ari';
6
+ const getStorage = (apiClientMock) => new index_1.GlobalStorage(() => contextAri, apiClientMock);
7
+ const getApiClientMock = (response, statusCode = 200) => {
8
+ return jest.fn().mockReturnValue({
9
+ ok: statusCode === 200,
10
+ status: statusCode,
11
+ text: jest.fn().mockResolvedValue(JSON.stringify(response))
12
+ });
13
+ };
14
+ describe.skip('Transaction', () => {
15
+ it('Test', async () => {
16
+ const apiClientMock = getApiClientMock({
17
+ data: {
18
+ appStoredEntity: {
19
+ value: 'testValue'
20
+ }
21
+ }
22
+ });
23
+ const globalStorage = getStorage(apiClientMock);
24
+ await new custom_entity_transaction_api_1.DefaultCustomEntityTransactionBuilder(globalStorage, 'users')
25
+ .set('user1', { name: 'anirudh' })
26
+ .andCondition('name', index_1.FilterConditions.beginsWith('An'))
27
+ .andCondition('age', index_1.FilterConditions.isLessThan(20))
28
+ .set('user2', { name: 'Shivam' })
29
+ .orCondition('name', index_1.FilterConditions.beginsWith('Si'))
30
+ .orCondition('type', index_1.FilterConditions.equalsTo('admin'))
31
+ .entity('projects')
32
+ .delete('FSQL-101')
33
+ .andCondition('type', index_1.FilterConditions.equalsTo('BUG'))
34
+ .set('ESS-2', { type: 'Story' })
35
+ .andCondition('name', index_1.FilterConditions.doesNotExist())
36
+ .execute();
37
+ });
38
+ });
@@ -0,0 +1,64 @@
1
+ import { FilterPredicate, GlobalStorage } from '..';
2
+ import { FilterOperator } from '../query-interfaces';
3
+ interface CustomEntityTransactionSet {
4
+ transactionType: 'set' | 'delete' | 'check';
5
+ entity: string;
6
+ key: string;
7
+ value: Record<string, any>;
8
+ conditions?: any[];
9
+ conditionOperator?: FilterOperator;
10
+ }
11
+ interface CustomEntityTransactionDelete {
12
+ transactionType: 'set' | 'delete' | 'check';
13
+ entity: string;
14
+ key: string;
15
+ conditions?: any[];
16
+ conditionOperator?: FilterOperator;
17
+ }
18
+ export declare type CustomEntityTransactionOptions = Record<string, CustomEntityTransactionSet | CustomEntityTransactionDelete>;
19
+ export declare class DefaultCustomEntityTransactionBuilder implements CustomEntityTransactionBuilder {
20
+ protected globalStorage: Pick<GlobalStorage, 'transaction'>;
21
+ protected entityName: string;
22
+ protected transactionOptions: CustomEntityTransactionOptions;
23
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, entityName: string, transactionOptions?: CustomEntityTransactionOptions);
24
+ private getKeyWithEntityName;
25
+ entity(name: string): CustomEntityTransactionBuilder;
26
+ set(key: string, value: Record<string, any>): CustomEntityTransactionBuilderWithAndOrCondition;
27
+ delete(key: string): CustomEntityTransactionBuilderWithAndOrCondition;
28
+ check(key: string): CustomEntityTransactionBuilderWithAndOrCondition;
29
+ execute(): Promise<void>;
30
+ }
31
+ export declare class CustomEntityTransactionBuilderWithAndCondition extends DefaultCustomEntityTransactionBuilder {
32
+ protected globalStorage: Pick<GlobalStorage, 'transaction'>;
33
+ protected entityName: string;
34
+ protected key: string;
35
+ protected transactionOptions: CustomEntityTransactionOptions;
36
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, entityName: string, key: string, transactionOptions?: CustomEntityTransactionOptions);
37
+ andCondition(field: string, condition: FilterPredicate): CustomEntityTransactionBuilderWithAndCondition;
38
+ }
39
+ export declare class CustomEntityTransactionBuilderWithOrCondition extends DefaultCustomEntityTransactionBuilder {
40
+ protected globalStorage: Pick<GlobalStorage, 'transaction'>;
41
+ protected entityName: string;
42
+ protected key: string;
43
+ protected transactionOptions: CustomEntityTransactionOptions;
44
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, entityName: string, key: string, transactionOptions?: CustomEntityTransactionOptions);
45
+ orCondition(field: string, condition: FilterPredicate): CustomEntityTransactionBuilderWithOrCondition;
46
+ }
47
+ export declare class CustomEntityTransactionBuilderWithAndOrCondition extends DefaultCustomEntityTransactionBuilder {
48
+ protected globalStorage: Pick<GlobalStorage, 'transaction'>;
49
+ protected entityName: string;
50
+ protected key: string;
51
+ protected transactionOptions: CustomEntityTransactionOptions;
52
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, entityName: string, key: string, transactionOptions?: CustomEntityTransactionOptions);
53
+ andCondition(field: string, condition: FilterPredicate): CustomEntityTransactionBuilderWithAndCondition;
54
+ orCondition(field: string, condition: FilterPredicate): CustomEntityTransactionBuilderWithOrCondition;
55
+ }
56
+ export interface CustomEntityTransactionBuilder {
57
+ entity(name: string): CustomEntityTransactionBuilder;
58
+ set(key: string, value: Record<string, any>, conditions?: any[]): CustomEntityTransactionBuilderWithAndOrCondition;
59
+ delete(key: string, conditions?: any[]): CustomEntityTransactionBuilderWithAndOrCondition;
60
+ check(key: string, conditions: any[]): CustomEntityTransactionBuilderWithAndOrCondition;
61
+ execute(): Promise<void>;
62
+ }
63
+ export {};
64
+ //# sourceMappingURL=custom-entity-transaction-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-entity-transaction-api.d.ts","sourceRoot":"","sources":["../../src/entity-storage/custom-entity-transaction-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,UAAU,0BAA0B;IAClC,eAAe,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,iBAAiB,CAAC,EAAE,cAAc,CAAC;CACpC;AAED,UAAU,6BAA6B;IACrC,eAAe,EAAE,KAAK,GAAG,QAAQ,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AG,EAAE,GAAG,gDAAgD,CAAC;IACnH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,gDAAgD,CAAC;IAC1F,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,gDAAgD,CAAC;IACxF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomEntityTransactionBuilderWithAndOrCondition = exports.CustomEntityTransactionBuilderWithOrCondition = exports.CustomEntityTransactionBuilderWithAndCondition = exports.DefaultCustomEntityTransactionBuilder = void 0;
4
+ class DefaultCustomEntityTransactionBuilder {
5
+ globalStorage;
6
+ entityName;
7
+ transactionOptions;
8
+ constructor(globalStorage, entityName, transactionOptions = {}) {
9
+ this.globalStorage = globalStorage;
10
+ this.entityName = entityName;
11
+ this.transactionOptions = transactionOptions;
12
+ this.transactionOptions = {
13
+ ...transactionOptions
14
+ };
15
+ }
16
+ getKeyWithEntityName(entity, key) {
17
+ const keyWithEntityName = `${entity}-${key}`;
18
+ return keyWithEntityName;
19
+ }
20
+ entity(name) {
21
+ return new DefaultCustomEntityTransactionBuilder(this.globalStorage, name, {
22
+ ...this.transactionOptions
23
+ });
24
+ }
25
+ set(key, value) {
26
+ const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
27
+ const input = {
28
+ transactionType: 'set',
29
+ key,
30
+ value,
31
+ entity: this.entityName
32
+ };
33
+ return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
34
+ ...this.transactionOptions,
35
+ [keyWithEntityName]: input
36
+ });
37
+ }
38
+ delete(key) {
39
+ const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
40
+ const input = {
41
+ transactionType: 'delete',
42
+ key,
43
+ entity: this.entityName
44
+ };
45
+ return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
46
+ ...this.transactionOptions,
47
+ [keyWithEntityName]: input
48
+ });
49
+ }
50
+ check(key) {
51
+ const keyWithEntityName = this.getKeyWithEntityName(this.entityName, key);
52
+ const input = {
53
+ transactionType: 'check',
54
+ key,
55
+ entity: this.entityName
56
+ };
57
+ return new CustomEntityTransactionBuilderWithAndOrCondition(this.globalStorage, this.entityName, keyWithEntityName, {
58
+ ...this.transactionOptions,
59
+ [keyWithEntityName]: input
60
+ });
61
+ }
62
+ async execute() {
63
+ if (!Object.keys(this.transactionOptions).length) {
64
+ throw new Error('Nothing to execute');
65
+ }
66
+ const transformedInput = {};
67
+ Object.entries(this.transactionOptions).forEach(([_, value]) => {
68
+ const { transactionType } = value;
69
+ if (!transformedInput[transactionType]) {
70
+ transformedInput[transactionType] = [];
71
+ }
72
+ const input = {
73
+ key: value.key,
74
+ entityName: value.entity
75
+ };
76
+ if (value.conditions?.length && value.conditionOperator) {
77
+ input.conditions = {
78
+ [value.conditionOperator]: value.conditions
79
+ };
80
+ }
81
+ if (transactionType === 'set') {
82
+ input.value = value.value;
83
+ transformedInput[transactionType]?.push(input);
84
+ }
85
+ else {
86
+ transformedInput[transactionType]?.push(input);
87
+ }
88
+ });
89
+ await this.globalStorage.transaction(transformedInput, true);
90
+ }
91
+ }
92
+ exports.DefaultCustomEntityTransactionBuilder = DefaultCustomEntityTransactionBuilder;
93
+ class CustomEntityTransactionBuilderWithAndCondition extends DefaultCustomEntityTransactionBuilder {
94
+ globalStorage;
95
+ entityName;
96
+ key;
97
+ transactionOptions;
98
+ constructor(globalStorage, entityName, key, transactionOptions = {}) {
99
+ super(globalStorage, entityName, transactionOptions);
100
+ this.globalStorage = globalStorage;
101
+ this.entityName = entityName;
102
+ this.key = key;
103
+ this.transactionOptions = transactionOptions;
104
+ this.transactionOptions = {
105
+ ...transactionOptions
106
+ };
107
+ }
108
+ andCondition(field, condition) {
109
+ const newQueryOptions = {
110
+ ...this.transactionOptions
111
+ };
112
+ newQueryOptions[this.key].conditions = [
113
+ ...(newQueryOptions[this.key].conditions ?? []),
114
+ { property: field, ...condition }
115
+ ];
116
+ newQueryOptions[this.key].conditionOperator = 'and';
117
+ return new CustomEntityTransactionBuilderWithAndCondition(this.globalStorage, this.entityName, this.key, newQueryOptions);
118
+ }
119
+ }
120
+ exports.CustomEntityTransactionBuilderWithAndCondition = CustomEntityTransactionBuilderWithAndCondition;
121
+ class CustomEntityTransactionBuilderWithOrCondition extends DefaultCustomEntityTransactionBuilder {
122
+ globalStorage;
123
+ entityName;
124
+ key;
125
+ transactionOptions;
126
+ constructor(globalStorage, entityName, key, transactionOptions = {}) {
127
+ super(globalStorage, entityName, transactionOptions);
128
+ this.globalStorage = globalStorage;
129
+ this.entityName = entityName;
130
+ this.key = key;
131
+ this.transactionOptions = transactionOptions;
132
+ this.transactionOptions = {
133
+ ...transactionOptions
134
+ };
135
+ }
136
+ orCondition(field, condition) {
137
+ const newQueryOptions = {
138
+ ...this.transactionOptions
139
+ };
140
+ newQueryOptions[this.key].conditions = [
141
+ ...(newQueryOptions[this.key].conditions ?? []),
142
+ { property: field, ...condition }
143
+ ];
144
+ newQueryOptions[this.key].conditionOperator = 'or';
145
+ return new CustomEntityTransactionBuilderWithOrCondition(this.globalStorage, this.entityName, this.key, newQueryOptions);
146
+ }
147
+ }
148
+ exports.CustomEntityTransactionBuilderWithOrCondition = CustomEntityTransactionBuilderWithOrCondition;
149
+ class CustomEntityTransactionBuilderWithAndOrCondition extends DefaultCustomEntityTransactionBuilder {
150
+ globalStorage;
151
+ entityName;
152
+ key;
153
+ transactionOptions;
154
+ constructor(globalStorage, entityName, key, transactionOptions = {}) {
155
+ super(globalStorage, entityName, transactionOptions);
156
+ this.globalStorage = globalStorage;
157
+ this.entityName = entityName;
158
+ this.key = key;
159
+ this.transactionOptions = transactionOptions;
160
+ this.transactionOptions = {
161
+ ...transactionOptions
162
+ };
163
+ }
164
+ andCondition(field, condition) {
165
+ return new CustomEntityTransactionBuilderWithAndCondition(this.globalStorage, this.entityName, this.key, this.transactionOptions).andCondition(field, condition);
166
+ }
167
+ orCondition(field, condition) {
168
+ return new CustomEntityTransactionBuilderWithOrCondition(this.globalStorage, this.entityName, this.key, this.transactionOptions).orCondition(field, condition);
169
+ }
170
+ }
171
+ exports.CustomEntityTransactionBuilderWithAndOrCondition = CustomEntityTransactionBuilderWithAndOrCondition;
@@ -1,5 +1,5 @@
1
1
  import { BulkResponse, FetchMethod } from './index';
2
- import { CustomEntityListOptions, ListOptions } from './query-interfaces';
2
+ import { CustomEntityListOptions, FilterClause, ListOptions } from './query-interfaces';
3
3
  import { BulkItem, SharedStorageAdapter } from './storage-adapter';
4
4
  interface ListResults {
5
5
  results: {
@@ -8,6 +8,26 @@ interface ListResults {
8
8
  }[];
9
9
  nextCursor?: string;
10
10
  }
11
+ export declare type colorsEnum = 'or' | 'and';
12
+ declare type TransactionRequestCondition = {
13
+ [key in colorsEnum]?: FilterClause[];
14
+ };
15
+ export interface TransactionRequestSet {
16
+ key: string;
17
+ value: string | number | boolean | Record<string, any> | any[];
18
+ entityName?: string;
19
+ conditions?: TransactionRequestCondition;
20
+ }
21
+ export interface TransactionRequestDeleteCheck {
22
+ key: string;
23
+ entityName?: string;
24
+ conditions?: TransactionRequestCondition;
25
+ }
26
+ export interface TransactionRequestInput {
27
+ set?: TransactionRequestSet[];
28
+ delete?: TransactionRequestDeleteCheck[];
29
+ check?: TransactionRequestDeleteCheck[];
30
+ }
11
31
  export declare class GlobalStorage implements SharedStorageAdapter {
12
32
  private getAppContextAri;
13
33
  private apiClient;
@@ -17,6 +37,7 @@ export declare class GlobalStorage implements SharedStorageAdapter {
17
37
  get(key: string): Promise<any>;
18
38
  getSecret(key: string): Promise<any>;
19
39
  list(options: ListOptions): Promise<ListResults>;
40
+ transaction(options: TransactionRequestInput, isCustomEntity?: boolean): Promise<void>;
20
41
  listCustomEntities(options: CustomEntityListOptions): Promise<ListResults>;
21
42
  set(key: string, value: any): Promise<void>;
22
43
  setSecret(key: string, value: any): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"global-storage.d.ts","sourceRoot":"","sources":["../src/global-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIjE,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEnE,UAAU,WAAW;IACnB,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2CD,qBAAa,aAAc,YAAW,oBAAoB;IAGtD,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,SAAS;IAHnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;gBAE5C,gBAAgB,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,WAAW;IAGhC,OAAO,CAAC,kBAAkB;IAIpB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAI9B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAqBhD,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAc1E,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,OAAO,CAAC,KAAK,EAAE,QAAQ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AAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjD,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAgBjD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxC,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/D,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5E,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAK1D,WAAW;YAUX,iBAAiB;IAU/B,OAAO,CAAC,YAAY;YAUN,KAAK;YAML,QAAQ;CA6BvB"}
@@ -56,6 +56,16 @@ class GlobalStorage {
56
56
  nextCursor
57
57
  };
58
58
  }
59
+ async transaction(options, isCustomEntity) {
60
+ if (isCustomEntity) {
61
+ const requestBody = gql_queries_1.CustomEntityQueries.transaction(this.doGetAppContextAri(), options);
62
+ await this.mutation(requestBody, 'appStorageCustomEntity', 'transactAppStoredCustomEntity');
63
+ }
64
+ else {
65
+ const requestBody = gql_queries_1.UntypedQueries.transaction(this.doGetAppContextAri(), options);
66
+ await this.mutation(requestBody, 'appStorage', 'transactAppStoredEntity');
67
+ }
68
+ }
59
69
  async listCustomEntities(options) {
60
70
  const requestBody = gql_queries_1.CustomEntityQueries.listQuery(this.doGetAppContextAri(), options);
61
71
  const response = await this.query(requestBody);
@@ -1,3 +1,4 @@
1
+ import { TransactionRequestInput } from './global-storage';
1
2
  import { CustomEntityListOptions, ListOptions } from './query-interfaces';
2
3
  import { BulkItem } from './storage-adapter';
3
4
  export declare class UntypedQueries {
@@ -58,6 +59,15 @@ export declare class UntypedQueries {
58
59
  };
59
60
  };
60
61
  };
62
+ static transaction: (contextAri: string, items: TransactionRequestInput) => {
63
+ query: string;
64
+ variables: {
65
+ input: {
66
+ contextAri: string;
67
+ items: TransactionRequestInput;
68
+ };
69
+ };
70
+ };
61
71
  }
62
72
  export declare class CustomEntityQueries {
63
73
  static get: (contextAri: string, entityName: string, key: string) => {
@@ -105,5 +115,14 @@ export declare class CustomEntityQueries {
105
115
  range: import("./query-interfaces").RangeClause | undefined;
106
116
  };
107
117
  };
118
+ static transaction: (contextAri: string, items: TransactionRequestInput) => {
119
+ query: string;
120
+ variables: {
121
+ input: {
122
+ contextAri: string;
123
+ items: TransactionRequestInput;
124
+ };
125
+ };
126
+ };
108
127
  }
109
128
  //# sourceMappingURL=gql-queries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gql-queries.d.ts","sourceRoot":"","sources":["../src/gql-queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,qBAAa,cAAc;IACzB,OAAc,GAAG,eAAgB,MAAM,OAAO,MAAM,aAAa,OAAO;;;;;;;MAcrE;IAEH,OAAc,GAAG,eAAgB,MAAM,OAAO,MAAM,SAAS,GAAG,aAAa,OAAO;;;;;;;;;;MA0BjF;IAEH,OAAc,MAAM,eAAgB,MAAM,OAAO,MAAM,aAAa,OAAO;;;;;;;;;MAyBxE;IAEH,OAAc,SAAS,eAAgB,MAAM,WAAW,WAAW;;;;;;;;MAuBhE;IAEH,OAAc,mBAAmB,eAAgB,MAAM,WAAW,WAAW;;;;;;;;MAuB1E;IAEH,OAAc,OAAO,eAAgB,MAAM,UAAU,QAAQ,EAAE,aAAa,OAAO;;;;;;;;;MA0BhF;CACJ;AAED,qBAAa,mBA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,GAAG;;;;;;;;;;MA0BjF;IAEH,OAAc,MAAM,eAAgB,MAAM,cAAc,MAAM,OAAO,MAAM;;;;;;;;;MAyBxE;IAEH,OAAc,SAAS,eAAgB,MAAM,WAAW,uBAAuB;;;;;;;;;;;;;;;MAuC7E;IAEF,OAAc,WAAW,eAAgB,MAAM,SAAS,uBAAuB;;;;;;;;MAuB5E;CACJ"}
@@ -50,7 +50,7 @@ class UntypedQueries {
50
50
  appStorage {
51
51
  deleteAppStoredEntity(input: $input) {
52
52
  success
53
-
53
+
54
54
  errors {
55
55
  message
56
56
  extensions {
@@ -79,7 +79,7 @@ class UntypedQueries {
79
79
  value
80
80
  key
81
81
  }
82
-
82
+
83
83
  cursor
84
84
  }
85
85
  }
@@ -101,7 +101,7 @@ class UntypedQueries {
101
101
  value
102
102
  key
103
103
  }
104
-
104
+
105
105
  cursor
106
106
  }
107
107
  }
@@ -121,7 +121,11 @@ class UntypedQueries {
121
121
  setAppStoredEntities(input: $input) {
122
122
  success
123
123
  savedKeys
124
- failedKeys
124
+ failedKeys {
125
+ key
126
+ code
127
+ message
128
+ }
125
129
  errors {
126
130
  message
127
131
  extensions {
@@ -141,6 +145,30 @@ class UntypedQueries {
141
145
  }
142
146
  }
143
147
  });
148
+ static transaction = (contextAri, items) => ({
149
+ query: `
150
+ mutation forge_app_setApplicationStorageTransact($input: TransactMutationInput!) {
151
+ appStorage {
152
+ transactAppStoredEntity(input: $input) {
153
+ success
154
+ errors {
155
+ message
156
+ extensions {
157
+ errorType
158
+ statusCode
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+ `,
165
+ variables: {
166
+ input: {
167
+ contextAri,
168
+ items
169
+ }
170
+ }
171
+ });
144
172
  }
145
173
  exports.UntypedQueries = UntypedQueries;
146
174
  class CustomEntityQueries {
@@ -166,7 +194,7 @@ class CustomEntityQueries {
166
194
  appStorageCustomEntity{
167
195
  setAppStoredCustomEntity(input: $input) {
168
196
  success
169
-
197
+
170
198
  errors {
171
199
  message
172
200
  extensions {
@@ -193,7 +221,7 @@ class CustomEntityQueries {
193
221
  appStorageCustomEntity {
194
222
  deleteAppStoredCustomEntity(input: $input) {
195
223
  success
196
-
224
+
197
225
  errors {
198
226
  message
199
227
  extensions {
@@ -232,7 +260,7 @@ class CustomEntityQueries {
232
260
  totalCount
233
261
  cursor
234
262
  }
235
- }
263
+ }
236
264
  `,
237
265
  variables: {
238
266
  contextAri,
@@ -253,5 +281,29 @@ class CustomEntityQueries {
253
281
  }
254
282
  };
255
283
  };
284
+ static transaction = (contextAri, items) => ({
285
+ query: `
286
+ mutation forge_app_setApplicationStorageTransact($input: TransactMutationInput!) {
287
+ appStorageCustomEntity {
288
+ transactAppStoredCustomEntity(input: $input) {
289
+ success
290
+ errors {
291
+ message
292
+ extensions {
293
+ errorType
294
+ statusCode
295
+ }
296
+ }
297
+ }
298
+ }
299
+ }
300
+ `,
301
+ variables: {
302
+ input: {
303
+ contextAri,
304
+ items
305
+ }
306
+ }
307
+ });
256
308
  }
257
309
  exports.CustomEntityQueries = CustomEntityQueries;
package/out/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { RequestInit, Response } from 'node-fetch';
2
2
  import { EntityStorageBuilder } from './entity-storage';
3
3
  import { GlobalStorage } from './global-storage';
4
4
  import { DefaultQueryBuilder } from './query-api';
5
+ import { DefaultTransactionBuilder } from './transaction-api';
5
6
  export declare type APIResponse = Pick<Response, 'json' | 'text' | 'arrayBuffer' | 'ok' | 'status' | 'statusText'>;
6
7
  export declare type FetchMethod = (url: string, init: RequestInit) => Promise<APIResponse>;
7
8
  export declare const getStorageInstanceWithQuery: (adapter: GlobalStorage) => {
@@ -13,15 +14,15 @@ export declare const getStorageInstanceWithQuery: (adapter: GlobalStorage) => {
13
14
  deleteSecret: (key: string) => Promise<void>;
14
15
  bulkSet: (items: import("./storage-adapter").BulkItem[]) => Promise<import("./storage-adapter").BulkResponse>;
15
16
  query: () => DefaultQueryBuilder;
17
+ transaction: () => DefaultTransactionBuilder;
16
18
  entity: <T>(entityName: string) => EntityStorageBuilder<T>;
17
19
  };
18
20
  export { GlobalStorage } from './global-storage';
19
21
  export { startsWith } from './conditions';
20
22
  export { WhereConditions, FilterConditions } from './eap/conditions';
21
- export { QueryBuilder, QueryApi, Condition, ListResult, Predicate, Result, EntityStorageApi, WherePredicate, FilterPredicate } from './storage-adapter';
23
+ export { QueryBuilder, QueryApi, Condition, ListResult, Predicate, Result, EntityStorageApi, WherePredicate, FilterPredicate, TransactionApi, BulkItem, BulkResponse } from './storage-adapter';
22
24
  export { EntityStorageBuilder, EntityStorageBuilderType } from './entity-storage';
23
25
  export { Value, SortOrder } from './query-interfaces';
24
26
  export { APIError } from './errors';
25
- export { BulkItem, BulkResponse } from './storage-adapter';
26
27
  export { CustomEntityIndexBuilder } from './entity-storage/query-api';
27
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,oBAAY,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI,GAAG,QAAQ,GAAG,YAAY,CAAC,CAAC;AAC3G,oBAAY,WAAW,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;AAEnF,eAAO,MAAM,2BAA2B,YAAa,aAAa;;;;;;;;iBASnD,mBAAmB;4BACN,MAAM;CAEjC,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,UAAU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,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAErE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,cAAc,EACd,QAAQ,EACR,YAAY,EACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
package/out/index.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CustomEntityIndexBuilder = exports.APIError = exports.SortOrder = exports.EntityStorageBuilder = exports.FilterConditions = exports.WhereConditions = exports.startsWith = exports.GlobalStorage = exports.getStorageInstanceWithQuery = void 0;
4
4
  const entity_storage_1 = require("./entity-storage");
5
5
  const query_api_1 = require("./query-api");
6
+ const transaction_api_1 = require("./transaction-api");
6
7
  const getStorageInstanceWithQuery = (adapter) => {
7
8
  return {
8
9
  get: adapter.get.bind(adapter),
@@ -13,6 +14,7 @@ const getStorageInstanceWithQuery = (adapter) => {
13
14
  deleteSecret: adapter.deleteSecret.bind(adapter),
14
15
  bulkSet: adapter.bulkSet.bind(adapter),
15
16
  query: () => new query_api_1.DefaultQueryBuilder(adapter),
17
+ transaction: () => new transaction_api_1.DefaultTransactionBuilder(adapter),
16
18
  entity: (entityName) => new entity_storage_1.EntityStorageBuilder(entityName, adapter)
17
19
  };
18
20
  };
@@ -0,0 +1,12 @@
1
+ import { GlobalStorage } from '.';
2
+ import { KVSTransactionBuilderInterface } from './storage-adapter';
3
+ import { TransactionOptions } from './transaction-api';
4
+ export declare class KVSTransactionBuilder implements KVSTransactionBuilderInterface {
5
+ private globalStorage;
6
+ private transactionOptions;
7
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, transactionOptions?: TransactionOptions);
8
+ set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilder;
9
+ delete(key: string): KVSTransactionBuilder;
10
+ execute(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=kvs-transaction-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvs-transaction-api.d.ts","sourceRoot":"","sources":["../src/kvs-transaction-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAClC,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,qBAAsB,YAAW,8BAA8B;IAExE,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,kBAAkB;gBADlB,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,EACjD,kBAAkB,GAAE,kBAAuB;IAGrD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,qBAAqB;IAOvG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB;IAOpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KVSTransactionBuilder = void 0;
4
+ class KVSTransactionBuilder {
5
+ globalStorage;
6
+ transactionOptions;
7
+ constructor(globalStorage, transactionOptions = {}) {
8
+ this.globalStorage = globalStorage;
9
+ this.transactionOptions = transactionOptions;
10
+ }
11
+ set(key, value) {
12
+ return new KVSTransactionBuilder(this.globalStorage, {
13
+ set: [...(this.transactionOptions.set || []), { key, value }],
14
+ delete: [...(this.transactionOptions.delete || [])]
15
+ });
16
+ }
17
+ delete(key) {
18
+ return new KVSTransactionBuilder(this.globalStorage, {
19
+ set: [...(this.transactionOptions.set || [])],
20
+ delete: [...(this.transactionOptions.delete || []), { key }]
21
+ });
22
+ }
23
+ async execute() {
24
+ if (!this.transactionOptions.delete?.length && !this.transactionOptions.set?.length) {
25
+ throw new Error('Nothing to execute');
26
+ }
27
+ await this.globalStorage.transaction(this.transactionOptions);
28
+ }
29
+ }
30
+ exports.KVSTransactionBuilder = KVSTransactionBuilder;
@@ -1,12 +1,18 @@
1
1
  import { EntityStorageBuilderType } from './entity-storage';
2
+ import { CustomEntityTransactionBuilder } from './entity-storage/custom-entity-transaction-api';
2
3
  import { BeginsWithClause, BetweenClause, ExistsClause, DoesNotExistClause, GreaterThanClause, GreaterThanEqualToClause, StartsWith, NotEqualTo, In, LessThanClause, LessThanEqualToClause, ContainsClause, DoesNotContainClause, IsNotEqualToClause, EqualToClause } from './query-interfaces';
3
4
  export interface BulkItem {
4
5
  key: string;
5
6
  value: string | number | boolean | Record<string, any> | any[];
6
7
  }
8
+ export interface FailedKey {
9
+ key: string;
10
+ code: string;
11
+ message: string;
12
+ }
7
13
  export interface BulkResponse {
8
14
  savedKeys: string[];
9
- failedKeys: string[];
15
+ failedKeys: FailedKey[];
10
16
  }
11
17
  export interface StorageAdapter {
12
18
  get(key: string): Promise<any>;
@@ -29,6 +35,9 @@ export declare type SharedStorageAdapter = StorageAdapter & EntityStorageAdapter
29
35
  export interface QueryApi {
30
36
  query(): QueryBuilder;
31
37
  }
38
+ export interface TransactionApi {
39
+ transaction(): TransactionBuilder;
40
+ }
32
41
  export declare type Predicate = StartsWith | NotEqualTo | In;
33
42
  export declare type Condition = Predicate;
34
43
  export interface QueryBuilder {
@@ -38,6 +47,16 @@ export interface QueryBuilder {
38
47
  getMany(): Promise<ListResult>;
39
48
  getOne(): Promise<Result | undefined>;
40
49
  }
50
+ export interface KVSTransactionBuilderInterface {
51
+ set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilderInterface;
52
+ delete(key: string): KVSTransactionBuilderInterface;
53
+ execute(): Promise<void>;
54
+ }
55
+ export interface TransactionBuilder {
56
+ entity(name: string): CustomEntityTransactionBuilder;
57
+ set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilderInterface;
58
+ delete(key: string): KVSTransactionBuilderInterface;
59
+ }
41
60
  export declare type FilterPredicate = BetweenClause | BeginsWithClause | ExistsClause | DoesNotExistClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause | ContainsClause | DoesNotContainClause | EqualToClause | IsNotEqualToClause;
42
61
  export declare type WherePredicate = BetweenClause | BeginsWithClause | EqualToClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause;
43
62
  export interface Result<T = object> {
@@ -1 +1 @@
1
- {"version":3,"file":"storage-adapter.d.ts","sourceRoot":"","sources":["../src/storage-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,EAAE,EACF,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,aAAa,EACd,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;CAChE;AAED,MAAM,WAAW,YAAY;IAC3B,SAA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entity-transaction-api';
3
+ import { KVSTransactionBuilderInterface, TransactionBuilder } from './storage-adapter';
4
+ interface TransactionSet {
5
+ key: string;
6
+ value: string | number | boolean | Record<string, any> | any[];
7
+ }
8
+ interface TransactionDelete {
9
+ key: string;
10
+ }
11
+ export interface TransactionOptions {
12
+ set?: TransactionSet[];
13
+ delete?: TransactionDelete[];
14
+ }
15
+ export declare class DefaultTransactionBuilder implements TransactionBuilder {
16
+ private globalStorage;
17
+ private transactionOptions;
18
+ constructor(globalStorage: Pick<GlobalStorage, 'transaction'>, transactionOptions?: TransactionOptions);
19
+ entity(name: string): CustomEntityTransactionBuilder;
20
+ set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilderInterface;
21
+ delete(key: string): KVSTransactionBuilderInterface;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=transaction-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-api.d.ts","sourceRoot":"","sources":["../src/transaction-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAClC,OAAO,EACL,8BAA8B,EAE/B,MAAM,gDAAgD,CAAC;AAExD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvF,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC;CAChE;AACD,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;AACD,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,cAAc,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC9B;AAED,qBAAa,yBAA0B,YAAW,kBAAkB;IAEhE,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,kBAAkB;gBADlB,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,EACjD,kBAAkB,GAAE,kBAAuB;IAGrD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,8BAA8B;IAQpD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,8BAA8B;IAOhH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,8BAA8B;CAMpD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultTransactionBuilder = void 0;
4
+ const custom_entity_transaction_api_1 = require("./entity-storage/custom-entity-transaction-api");
5
+ const kvs_transaction_api_1 = require("./kvs-transaction-api");
6
+ class DefaultTransactionBuilder {
7
+ globalStorage;
8
+ transactionOptions;
9
+ constructor(globalStorage, transactionOptions = {}) {
10
+ this.globalStorage = globalStorage;
11
+ this.transactionOptions = transactionOptions;
12
+ }
13
+ entity(name) {
14
+ if (this.transactionOptions.delete?.length || this.transactionOptions.set?.length) {
15
+ throw new Error('Cannot set transaction for Custom entities and KVS at the same time');
16
+ }
17
+ return new custom_entity_transaction_api_1.DefaultCustomEntityTransactionBuilder(this.globalStorage, name, {});
18
+ }
19
+ set(key, value) {
20
+ return new kvs_transaction_api_1.KVSTransactionBuilder(this.globalStorage, {
21
+ set: [...(this.transactionOptions.set || []), { key, value }],
22
+ delete: [...(this.transactionOptions.delete || [])]
23
+ });
24
+ }
25
+ delete(key) {
26
+ return new kvs_transaction_api_1.KVSTransactionBuilder(this.globalStorage, {
27
+ set: [...(this.transactionOptions.set || [])],
28
+ delete: [...(this.transactionOptions.delete || []), { key }]
29
+ });
30
+ }
31
+ }
32
+ exports.DefaultTransactionBuilder = DefaultTransactionBuilder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/storage",
3
- "version": "1.5.15-experimental-1828c63",
3
+ "version": "1.5.15-experimental-204139e",
4
4
  "description": "Forge Storage methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",