@forge/storage
Advanced tools
Comparing version 1.5.15-experimental-03ab603 to 1.5.15-experimental-10722bc
@@ -260,3 +260,9 @@ "use strict"; | ||
savedKeys: ['testKey'], | ||
failedKeys: [] | ||
failedKeys: [ | ||
{ | ||
key: 'testKey2', | ||
code: 'KEY_TOO_LARGE', | ||
message: 'The provided key exceeds maximum allowed length' | ||
} | ||
] | ||
} | ||
@@ -267,6 +273,10 @@ } | ||
const globalStorage = getStorage(apiClientMock); | ||
await globalStorage.bulkSet([ | ||
const response = await globalStorage.bulkSet([ | ||
{ | ||
key: 'testKey', | ||
value: 'testValue' | ||
}, | ||
{ | ||
key: 'testKey2', | ||
value: 'testValue2' | ||
} | ||
@@ -281,2 +291,6 @@ ]); | ||
value: 'testValue' | ||
}, | ||
{ | ||
key: 'testKey2', | ||
value: 'testValue2' | ||
} | ||
@@ -287,2 +301,6 @@ ], | ||
}); | ||
expect(response).toHaveProperty('savedKeys', ['testKey']); | ||
expect(response).toHaveProperty('failedKeys', [ | ||
{ key: 'testKey2', code: 'KEY_TOO_LARGE', message: 'The provided key exceeds maximum allowed length' } | ||
]); | ||
}); | ||
@@ -289,0 +307,0 @@ it('should throw an error if the storage API returns successful = false', async () => { |
import { BulkResponse, FetchMethod } from './index'; | ||
import { CustomEntityListOptions, ListOptions } from './query-interfaces'; | ||
import { CustomEntityListOptions, FilterClause, ListOptions } from './query-interfaces'; | ||
import { BulkItem, SharedStorageAdapter } from './storage-adapter'; | ||
@@ -11,2 +11,22 @@ interface ListResults { | ||
} | ||
export declare type colorsEnum = 'or' | 'and'; | ||
declare type TransactionRequestCondition = { | ||
[key in colorsEnum]?: FilterClause[]; | ||
}; | ||
export interface TransactionRequestSet { | ||
key: string; | ||
value: string | number | boolean | Record<string, any> | any[]; | ||
entityName?: string; | ||
conditions?: TransactionRequestCondition; | ||
} | ||
export interface TransactionRequestDeleteCheck { | ||
key: string; | ||
entityName?: string; | ||
conditions?: TransactionRequestCondition; | ||
} | ||
export interface TransactionRequestInput { | ||
set?: TransactionRequestSet[]; | ||
delete?: TransactionRequestDeleteCheck[]; | ||
check?: TransactionRequestDeleteCheck[]; | ||
} | ||
export declare class GlobalStorage implements SharedStorageAdapter { | ||
@@ -21,2 +41,3 @@ private getAppContextAri; | ||
list(options: ListOptions): Promise<ListResults>; | ||
transaction(options: TransactionRequestInput, isCustomEntity?: boolean): Promise<void>; | ||
listCustomEntities(options: CustomEntityListOptions): Promise<ListResults>; | ||
@@ -23,0 +44,0 @@ set(key: string, value: any): Promise<void>; |
@@ -59,2 +59,12 @@ "use strict"; | ||
} | ||
async transaction(options, isCustomEntity) { | ||
if (isCustomEntity) { | ||
const requestBody = gql_queries_1.CustomEntityQueries.transaction(this.doGetAppContextAri(), options); | ||
await this.mutation(requestBody, 'appStorageCustomEntity', 'transactAppStoredCustomEntity'); | ||
} | ||
else { | ||
const requestBody = gql_queries_1.UntypedQueries.transaction(this.doGetAppContextAri(), options); | ||
await this.mutation(requestBody, 'appStorage', 'transactAppStoredEntity'); | ||
} | ||
} | ||
async listCustomEntities(options) { | ||
@@ -80,6 +90,5 @@ const requestBody = gql_queries_1.CustomEntityQueries.listQuery(this.doGetAppContextAri(), options); | ||
const requestBody = gql_queries_1.UntypedQueries.bulkSet(this.doGetAppContextAri(), items, false); | ||
const response = await this.mutation(requestBody, 'appStorage', 'setAppStoredEntities'); | ||
const parsedResponse = await getResponseBody(response); | ||
const failedKeys = parsedResponse.appStorage.setAppStoredEntities.failedKeys; | ||
const savedKeys = parsedResponse.appStorage.setAppStoredEntities.savedKeys; | ||
const response = await this.mutation(requestBody, 'appStorage', 'setAppStoredEntities', true); | ||
const failedKeys = response.failedKeys; | ||
const savedKeys = response.savedKeys; | ||
return { | ||
@@ -132,9 +141,12 @@ savedKeys, | ||
} | ||
async mutation(body, namespace, mutationMethod) { | ||
async mutation(body, namespace, mutationMethod, returnResponseBody) { | ||
const response = await this.apiClient(this.endpoint, this.buildRequest(body)); | ||
const { [namespace]: { [mutationMethod]: { success, errors } } } = await getResponseBody(response); | ||
assertNoErrors(errors); | ||
if (!success) { | ||
const { [namespace]: { [mutationMethod]: mutationResponse } } = await getResponseBody(response); | ||
assertNoErrors(mutationResponse.errors); | ||
if (!mutationResponse.success) { | ||
throw errors_1.APIError.forStatus(500); | ||
} | ||
if (returnResponseBody) { | ||
return mutationResponse; | ||
} | ||
return response; | ||
@@ -141,0 +153,0 @@ } |
@@ -0,1 +1,2 @@ | ||
import { TransactionRequestInput } from './global-storage'; | ||
import { CustomEntityListOptions, ListOptions } from './query-interfaces'; | ||
@@ -61,2 +62,11 @@ import { BulkItem } from './storage-adapter'; | ||
}; | ||
static transaction: (contextAri: string, items: TransactionRequestInput) => { | ||
query: string; | ||
variables: { | ||
input: { | ||
contextAri: string; | ||
items: TransactionRequestInput; | ||
}; | ||
}; | ||
}; | ||
} | ||
@@ -109,3 +119,12 @@ export declare class CustomEntityQueries { | ||
}; | ||
static transaction: (contextAri: string, items: TransactionRequestInput) => { | ||
query: string; | ||
variables: { | ||
input: { | ||
contextAri: string; | ||
items: TransactionRequestInput; | ||
}; | ||
}; | ||
}; | ||
} | ||
//# sourceMappingURL=gql-queries.d.ts.map |
@@ -53,3 +53,3 @@ "use strict"; | ||
success | ||
errors { | ||
@@ -83,3 +83,3 @@ message | ||
} | ||
cursor | ||
@@ -106,3 +106,3 @@ } | ||
} | ||
cursor | ||
@@ -127,3 +127,7 @@ } | ||
savedKeys | ||
failedKeys | ||
failedKeys { | ||
key | ||
code | ||
message | ||
} | ||
errors { | ||
@@ -148,2 +152,26 @@ message | ||
}); | ||
static transaction = (contextAri, items) => ({ | ||
query: ` | ||
mutation forge_app_setApplicationStorageTransact($input: TransactMutationInput!) { | ||
appStorage { | ||
transactAppStoredEntity(input: $input) { | ||
success | ||
errors { | ||
message | ||
extensions { | ||
errorType | ||
statusCode | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
input: { | ||
contextAri, | ||
items | ||
} | ||
} | ||
}); | ||
} | ||
@@ -174,3 +202,3 @@ exports.UntypedQueries = UntypedQueries; | ||
success | ||
errors { | ||
@@ -202,3 +230,3 @@ message | ||
success | ||
errors { | ||
@@ -242,3 +270,3 @@ message | ||
} | ||
} | ||
} | ||
`, | ||
@@ -264,3 +292,27 @@ variables: { | ||
}; | ||
static transaction = (contextAri, items) => ({ | ||
query: ` | ||
mutation forge_app_setApplicationStorageTransact($input: TransactMutationInput!) { | ||
appStorageCustomEntity { | ||
transactAppStoredCustomEntity(input: $input) { | ||
success | ||
errors { | ||
message | ||
extensions { | ||
errorType | ||
statusCode | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: { | ||
input: { | ||
contextAri, | ||
items | ||
} | ||
} | ||
}); | ||
} | ||
exports.CustomEntityQueries = CustomEntityQueries; |
@@ -5,2 +5,3 @@ import { RequestInit, Response } from 'node-fetch'; | ||
import { DefaultQueryBuilder } from './query-api'; | ||
import { DefaultTransactionBuilder } from './transaction-api'; | ||
export declare type APIResponse = Pick<Response, 'json' | 'text' | 'arrayBuffer' | 'ok' | 'status' | 'statusText'>; | ||
@@ -17,2 +18,3 @@ export declare type FetchMethod = (url: string, init: RequestInit) => Promise<APIResponse>; | ||
query: () => DefaultQueryBuilder; | ||
transaction: () => DefaultTransactionBuilder; | ||
entity: <T>(entityName: string) => EntityStorageBuilder<T>; | ||
@@ -23,8 +25,7 @@ }; | ||
export { WhereConditions, FilterConditions } from './eap/conditions'; | ||
export { QueryBuilder, QueryApi, Condition, ListResult, Predicate, Result, EntityStorageApi, WherePredicate, FilterPredicate } from './storage-adapter'; | ||
export { QueryBuilder, QueryApi, Condition, ListResult, Predicate, Result, EntityStorageApi, WherePredicate, FilterPredicate, TransactionApi, BulkItem, BulkResponse } from './storage-adapter'; | ||
export { EntityStorageBuilder, EntityStorageBuilderType } from './entity-storage'; | ||
export { Value, SortOrder } from './query-interfaces'; | ||
export { APIError } from './errors'; | ||
export { BulkItem, BulkResponse } from './storage-adapter'; | ||
export { CustomEntityIndexBuilder } from './entity-storage/query-api'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
const query_api_1 = require("./query-api"); | ||
const transaction_api_1 = require("./transaction-api"); | ||
const getStorageInstanceWithQuery = (adapter) => { | ||
@@ -17,2 +18,3 @@ return { | ||
query: () => new query_api_1.DefaultQueryBuilder(adapter), | ||
transaction: () => new transaction_api_1.DefaultTransactionBuilder(adapter), | ||
entity: (entityName) => new entity_storage_1.EntityStorageBuilder(entityName, adapter) | ||
@@ -19,0 +21,0 @@ }; |
import { EntityStorageBuilderType } from './entity-storage'; | ||
import { CustomEntityTransactionBuilder } from './entity-storage/custom-entity-transaction-api'; | ||
import { BeginsWithClause, BetweenClause, ExistsClause, DoesNotExistClause, GreaterThanClause, GreaterThanEqualToClause, StartsWith, NotEqualTo, In, LessThanClause, LessThanEqualToClause, ContainsClause, DoesNotContainClause, IsNotEqualToClause, EqualToClause } from './query-interfaces'; | ||
@@ -7,5 +8,6 @@ export interface BulkItem { | ||
} | ||
interface FailedKey { | ||
export interface FailedKey { | ||
key: string; | ||
reason: string; | ||
code: string; | ||
message: string; | ||
} | ||
@@ -37,2 +39,5 @@ export interface BulkResponse { | ||
} | ||
export interface TransactionApi { | ||
transaction(): TransactionBuilder; | ||
} | ||
export declare type Predicate = StartsWith | NotEqualTo | In; | ||
@@ -47,2 +52,13 @@ export declare type Condition = Predicate; | ||
} | ||
export interface KVSTransactionBuilderInterface { | ||
set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilderInterface; | ||
delete(key: string): KVSTransactionBuilderInterface; | ||
execute(): Promise<void>; | ||
} | ||
export interface TransactionBuilder { | ||
entity(name: string): CustomEntityTransactionBuilder; | ||
set(key: string, value: string | number | boolean | Record<string, any> | any[]): KVSTransactionBuilderInterface; | ||
delete(key: string): KVSTransactionBuilderInterface; | ||
execute(): Promise<void>; | ||
} | ||
export declare type FilterPredicate = BetweenClause | BeginsWithClause | ExistsClause | DoesNotExistClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause | ContainsClause | DoesNotContainClause | EqualToClause | IsNotEqualToClause; | ||
@@ -58,3 +74,2 @@ export declare type WherePredicate = BetweenClause | BeginsWithClause | EqualToClause | GreaterThanClause | GreaterThanEqualToClause | LessThanClause | LessThanEqualToClause; | ||
} | ||
export {}; | ||
//# sourceMappingURL=storage-adapter.d.ts.map |
{ | ||
"name": "@forge/storage", | ||
"version": "1.5.15-experimental-03ab603", | ||
"version": "1.5.15-experimental-10722bc", | ||
"description": "Forge Storage methods", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
160908
65
3307